diff options
author | Tor Andersson <tor.andersson@artifex.com> | 2016-04-05 20:59:10 +0200 |
---|---|---|
committer | Tor Andersson <tor.andersson@artifex.com> | 2016-04-06 00:06:45 +0200 |
commit | 791dd8c29c612965a0b5b5d8b923b8bbb12cbc10 (patch) | |
tree | 0a7a5d3cdc4a65ccf65c32bb1790e2b38805fbea | |
parent | eaaf33f161e3d010c61ae9bdb3ae5f9cd202bb88 (diff) | |
download | mupdf-791dd8c29c612965a0b5b5d8b923b8bbb12cbc10.tar.xz |
epub: Try to keep to one fz_text per paragraph.
We will need to split if the color changes, or an image is spliced in.
List item bullets also get their own fz_text element.
-rw-r--r-- | source/html/html-layout.c | 39 |
1 files changed, 34 insertions, 5 deletions
diff --git a/source/html/html-layout.c b/source/html/html-layout.c index 091ce052..435d1767 100644 --- a/source/html/html-layout.c +++ b/source/html/html-layout.c @@ -1270,9 +1270,15 @@ static void draw_flow_box(fz_context *ctx, fz_html *box, float page_top, float p fz_text *text; fz_matrix trm; float color[3]; + float prev_color[3]; /* FIXME: HB_DIRECTION_TTB? */ + text = NULL; + prev_color[0] = 0; + prev_color[1] = 0; + prev_color[2] = 0; + for (node = box->flow_head; node; node = node->next) { if (node->type == FLOW_IMAGE) @@ -1305,8 +1311,21 @@ static void draw_flow_box(fz_context *ctx, fz_html *box, float page_top, float p color[1] = node->style->color.g / 255.0f; color[2] = node->style->color.b / 255.0f; - /* TODO: reuse text object if color is unchanged */ - text = fz_new_text(ctx); + if (color[0] != prev_color[0] || color[1] != prev_color[1] || color[2] != prev_color[2]) + { + if (text) + { + fz_fill_text(ctx, dev, text, ctm, fz_device_rgb(ctx), prev_color, 1); + fz_drop_text(ctx, text); + text = NULL; + } + prev_color[0] = color[0]; + prev_color[1] = color[1]; + prev_color[2] = color[2]; + } + + if (!text) + text = fz_new_text(ctx); if (node->bidi_level & 1) x = node->x + node->w; @@ -1378,12 +1397,15 @@ static void draw_flow_box(fz_context *ctx, fz_html *box, float page_top, float p y += y_advance * node_scale; } - - fz_fill_text(ctx, dev, text, ctm, fz_device_rgb(ctx), color, 1); - fz_drop_text(ctx, text); } else if (node->type == FLOW_IMAGE) { + if (text) + { + fz_fill_text(ctx, dev, text, ctm, fz_device_rgb(ctx), color, 1); + fz_drop_text(ctx, text); + text = NULL; + } if (node->style->visibility == V_VISIBLE) { fz_matrix local_ctm = *ctm; @@ -1393,6 +1415,13 @@ static void draw_flow_box(fz_context *ctx, fz_html *box, float page_top, float p } } } + + if (text) + { + fz_fill_text(ctx, dev, text, ctm, fz_device_rgb(ctx), color, 1); + fz_drop_text(ctx, text); + text = NULL; + } } static void draw_rect(fz_context *ctx, fz_device *dev, const fz_matrix *ctm, fz_css_color color, float x0, float y0, float x1, float y1) |