summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTor Andersson <tor.andersson@artifex.com>2016-01-20 15:58:08 +0100
committerTor Andersson <tor.andersson@artifex.com>2016-01-20 16:34:52 +0100
commit835036fc550af059f2bc067fc39465a9bfda7c2f (patch)
treeea3c68e6457b1732f33c4f62e51e1d866aeeefc8
parent54b039c006c8f7eb0f6cd81800f2167c3ba228eb (diff)
downloadmupdf-835036fc550af059f2bc067fc39465a9bfda7c2f.tar.xz
epub: Adjust text-align based on paragraph directionality.
In RTL context, text-align: left should be right, and vice versa. Since we currently ignore the dir="xxx" HTML attributes and CSS properties, always pick up the directionality from the text as if dir="auto".
-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;
}