summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--source/html/html-layout.c39
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)