summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/mupdf/html.h1
-rw-r--r--source/html/html-layout.c18
2 files changed, 13 insertions, 6 deletions
diff --git a/include/mupdf/html.h b/include/mupdf/html.h
index 546a4fbb..afa203ec 100644
--- a/include/mupdf/html.h
+++ b/include/mupdf/html.h
@@ -174,6 +174,7 @@ struct fz_html_s
float em;
fz_html *up, *down, *last, *next;
fz_html_flow *flow_head, **flow_tail;
+ fz_bidi_direction flow_dir;
fz_css_style style;
int list_item;
int is_first_flow; /* for text-indent */
diff --git a/source/html/html-layout.c b/source/html/html-layout.c
index 1d9885b6..6366f5cc 100644
--- a/source/html/html-layout.c
+++ b/source/html/html-layout.c
@@ -297,6 +297,7 @@ static void init_box(fz_context *ctx, fz_html *box)
box->flow_head = NULL;
box->flow_tail = &box->flow_head;
+ box->flow_dir = BIDI_NEUTRAL;
fz_default_css_style(ctx, &box->style);
}
@@ -709,6 +710,14 @@ static void layout_flow(fz_context *ctx, fz_html *box, fz_html *top, float em, f
indent = box->is_first_flow ? fz_from_css_number(top->style.text_indent, em, top->w) : 0;
align = top->style.text_align;
+ if (box->flow_dir == BIDI_RIGHT_TO_LEFT)
+ {
+ if (align == TA_LEFT)
+ align = TA_RIGHT;
+ else if (align == TA_RIGHT)
+ align = TA_LEFT;
+ }
+
box->x = top->x;
box->y = top->y + top->h;
box->w = top->w;
@@ -1554,12 +1563,11 @@ static void newFragCb(const uint32_t *fragment,
}
static void
-detect_flow_directionality(fz_context *ctx, fz_pool *pool, uni_buf *buffer, fz_html_flow *flow)
+detect_flow_directionality(fz_context *ctx, fz_pool *pool, uni_buf *buffer, fz_bidi_direction *baseDir, fz_html_flow *flow)
{
fz_html_flow *end = flow;
const char *text;
bidi_data data;
- fz_bidi_direction baseDir = -1;
/* Stage 1: Gather the text from the flow up into a single buffer */
buffer->len = 0;
@@ -1613,7 +1621,7 @@ detect_flow_directionality(fz_context *ctx, fz_pool *pool, uni_buf *buffer, fz_h
data.pool = pool;
data.flow = flow;
data.buffer = buffer;
- fz_bidi_fragment_text(ctx, buffer->data, buffer->len, &baseDir, &newFragCb, &data, 0 /* Flags */);
+ fz_bidi_fragment_text(ctx, buffer->data, buffer->len, baseDir, &newFragCb, &data, 0 /* Flags */);
}
static void
@@ -1622,9 +1630,7 @@ detect_box_directionality(fz_context *ctx, fz_pool *pool, uni_buf *buffer, fz_ht
while (box)
{
if (box->flow_head)
- {
- detect_flow_directionality(ctx, pool, buffer, box->flow_head);
- }
+ detect_flow_directionality(ctx, pool, buffer, &box->flow_dir, box->flow_head);
detect_box_directionality(ctx, pool, buffer, box->down);
box = box->next;
}