summaryrefslogtreecommitdiff
path: root/source/html
diff options
context:
space:
mode:
authorTor Andersson <tor.andersson@artifex.com>2014-11-14 11:15:58 +0100
committerTor Andersson <tor.andersson@artifex.com>2014-12-03 12:25:52 +0100
commitb3a9f7e5d838e095a5cf4f6d73a73316089190ec (patch)
tree96b8677b4d7d39037d007f2a1aa9e43972e32488 /source/html
parent8758df6c290525eb2246977d84816d171e95309b (diff)
downloadmupdf-b3a9f7e5d838e095a5cf4f6d73a73316089190ec.tar.xz
html: Only draw the boxes and lines if they're on the current page.
Diffstat (limited to 'source/html')
-rw-r--r--source/html/css-parse.c2
-rw-r--r--source/html/handler.c2
-rw-r--r--source/html/layout.c20
3 files changed, 15 insertions, 9 deletions
diff --git a/source/html/css-parse.c b/source/html/css-parse.c
index 63abee42..1708f550 100644
--- a/source/html/css-parse.c
+++ b/source/html/css-parse.c
@@ -759,7 +759,7 @@ struct rule *fz_parse_css_file(fz_context *ctx, struct rule *chain, const char *
{
buf = fz_read_all(stm, 0);
fz_write_buffer_byte(ctx, buf, 0);
- chain = fz_parse_css(ctx, chain, buf->data);
+ chain = fz_parse_css(ctx, chain, (char*)buf->data);
}
fz_always(ctx)
{
diff --git a/source/html/handler.c b/source/html/handler.c
index 6b19304b..c3f9c3df 100644
--- a/source/html/handler.c
+++ b/source/html/handler.c
@@ -48,7 +48,7 @@ html_run_page(html_document *doc, html_page *page, fz_device *dev, const fz_matr
{
int n = ((intptr_t)page) - 1;
printf("html: run page %d\n", n);
- html_run_box(doc->ctx, doc->box, n * doc->page_h, dev, ctm);
+ html_run_box(doc->ctx, doc->box, n * doc->page_h, (n+1) * doc->page_h, dev, ctm);
}
html_document *
diff --git a/source/html/layout.c b/source/html/layout.c
index 00ad79f6..9533e634 100644
--- a/source/html/layout.c
+++ b/source/html/layout.c
@@ -495,7 +495,7 @@ static void print_box(fz_context *ctx, struct box *box, int level)
}
static void
-draw_flow_box(fz_context *ctx, struct box *box, fz_device *dev, const fz_matrix *ctm)
+draw_flow_box(fz_context *ctx, struct box *box, float page_top, float page_bot, fz_device *dev, const fz_matrix *ctm)
{
struct flow *node;
fz_text *text;
@@ -509,6 +509,9 @@ draw_flow_box(fz_context *ctx, struct box *box, fz_device *dev, const fz_matrix
for (node = box->flow_head; node; node = node->next)
{
+ if (node->y > page_bot || node->y + node->h < page_top)
+ continue;
+
if (node->type == FLOW_WORD)
{
fz_scale(&trm, node->em, -node->em);
@@ -533,7 +536,7 @@ draw_flow_box(fz_context *ctx, struct box *box, fz_device *dev, const fz_matrix
}
static void
-draw_block_box(fz_context *ctx, struct box *box, fz_device *dev, const fz_matrix *ctm)
+draw_block_box(fz_context *ctx, struct box *box, float page_top, float page_bot, fz_device *dev, const fz_matrix *ctm)
{
fz_path *path;
float black[1];
@@ -549,6 +552,9 @@ draw_block_box(fz_context *ctx, struct box *box, fz_device *dev, const fz_matrix
x1 = box->x + box->w + box->padding[RIGHT];
y1 = box->y + box->h + box->padding[BOTTOM];
+ if (y0 > page_bot || y1 < page_top)
+ return;
+
path = fz_new_path(ctx);
fz_moveto(ctx, path, x0, y0);
fz_lineto(ctx, path, x1, y0);
@@ -564,18 +570,18 @@ draw_block_box(fz_context *ctx, struct box *box, fz_device *dev, const fz_matrix
{
switch (box->type)
{
- case BOX_BLOCK: draw_block_box(ctx, box, dev, ctm); break;
- case BOX_FLOW: draw_flow_box(ctx, box, dev, ctm); break;
+ case BOX_BLOCK: draw_block_box(ctx, box, page_top, page_bot, dev, ctm); break;
+ case BOX_FLOW: draw_flow_box(ctx, box, page_top, page_bot, dev, ctm); break;
}
}
}
void
-html_run_box(fz_context *ctx, struct box *box, float offset, fz_device *dev, const fz_matrix *inctm)
+html_run_box(fz_context *ctx, struct box *box, float page_top, float page_bot, fz_device *dev, const fz_matrix *inctm)
{
fz_matrix ctm = *inctm;
- fz_pre_translate(&ctm, 0, -offset);
- draw_block_box(ctx, box, dev, &ctm);
+ fz_pre_translate(&ctm, 0, -page_top);
+ draw_block_box(ctx, box, page_top, page_bot, dev, &ctm);
}
static char *concat_text(fz_context *ctx, fz_xml *root)