summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobin Watts <robin.watts@artifex.com>2016-01-18 19:18:45 +0000
committerRobin Watts <robin.watts@artifex.com>2016-01-18 19:31:39 +0000
commit61e63f3a680f8cfe4df040b4de5f0c5805610c29 (patch)
tree0e2bc17bba15eedb8a118aa8b950788c6a6be80b
parent5e608c0649ece27029484f388c672bed98af6e34 (diff)
downloadmupdf-61e63f3a680f8cfe4df040b4de5f0c5805610c29.tar.xz
Ensure layout honours text directional (block level).
-rw-r--r--source/html/html-layout.c39
1 files changed, 35 insertions, 4 deletions
diff --git a/source/html/html-layout.c b/source/html/html-layout.c
index 5bfcac85..f714c219 100644
--- a/source/html/html-layout.c
+++ b/source/html/html-layout.c
@@ -599,6 +599,7 @@ static void layout_line(fz_context *ctx, float indent, float page_w, float line_
float justify = 0;
float va;
int n = 0;
+ fz_html_flow *start, *mid;
if (align == TA_JUSTIFY)
{
@@ -613,8 +614,41 @@ static void layout_line(fz_context *ctx, float indent, float page_w, float line_
else if (align == TA_CENTER)
x += slop / 2;
+ /* The line data as supplied is start...end. */
+ /* We have the invariants that 1) start...mid are always laid out
+ * correctly and 2) mid..node are the most recent set of right to left
+ * blocks. */
+ start = node;
+ mid = node;
while (node != end)
{
+ float w = node->w + (node->type == FLOW_GLUE && node->expand ? justify : 0);
+ if (node->block_r2l)
+ {
+ float old_x = x;
+ if (mid != node)
+ {
+ /* We have met a r2l block, and have just had at least
+ * one other r2l block. Move all the r2l blocks that
+ * we've just had further right, and position this one
+ * on the left. */
+ fz_html_flow *temp = mid;
+ while (temp != node)
+ {
+ old_x = temp->x;
+ temp->x += w;
+ temp = temp->next;
+ }
+ }
+ node->x = old_x;
+ }
+ else
+ {
+ node->x = x;
+ mid = node->next;
+ }
+ x += w;
+
switch (node->style->vertical_align)
{
default:
@@ -628,14 +662,11 @@ static void layout_line(fz_context *ctx, float indent, float page_w, float line_
va = node->em * -0.3f;
break;
}
- node->x = x;
if (node->type == FLOW_IMAGE)
node->y = y + baseline - node->h;
else
node->y = y + baseline + va;
- x += node->w;
- if (node->type == FLOW_GLUE && node->expand)
- x += justify;
+
node = node->next;
}
}