diff options
author | Tor Andersson <tor.andersson@artifex.com> | 2016-10-10 16:45:39 +0200 |
---|---|---|
committer | Tor Andersson <tor.andersson@artifex.com> | 2016-10-12 14:45:42 +0200 |
commit | 69de38b8f7aecb43589d58b94e354bc0e622739e (patch) | |
tree | 8a189bfc9c9556a816f6d334122d408c0983f667 /source/html | |
parent | e06eef11c974e38e12c808f95b3987fc41da3f02 (diff) | |
download | mupdf-69de38b8f7aecb43589d58b94e354bc0e622739e.tar.xz |
Split fz_html into fz_html and fz_html_box for nodes.
Removes the need to carry fz_pool along in all boxes.
Diffstat (limited to 'source/html')
-rw-r--r-- | source/html/epub-doc.c | 30 | ||||
-rw-r--r-- | source/html/html-doc.c | 24 | ||||
-rw-r--r-- | source/html/html-layout.c | 126 |
3 files changed, 94 insertions, 86 deletions
diff --git a/source/html/epub-doc.c b/source/html/epub-doc.c index d9b0a0c9..246e343a 100644 --- a/source/html/epub-doc.c +++ b/source/html/epub-doc.c @@ -23,7 +23,7 @@ struct epub_chapter_s int start; float page_w, page_h, em; float page_margin[4]; - fz_html *box; + fz_html *html; epub_chapter *next; }; @@ -50,7 +50,7 @@ find_anchor_flow(fz_html_flow *flow, const char *anchor, float page_h, int *page } static int -find_anchor(fz_html *box, const char *anchor, float page_h, int *page) +find_anchor(fz_html_box *box, const char *anchor, float page_h, int *page) { while (box) { @@ -86,7 +86,7 @@ epub_update_link_dests(fz_context *ctx, epub_document *doc, fz_outline *node) if (s) { /* Search for a matching fragment */ - if (find_anchor(ch->box, s+1, ch->page_h, &node->dest.ld.gotor.page)) + if (find_anchor(ch->html->root, s+1, ch->page_h, &node->dest.ld.gotor.page)) continue; } break; @@ -108,14 +108,14 @@ epub_layout(fz_context *ctx, fz_document *doc_, float w, float h, float em) { ch->start = count; ch->em = em; - ch->page_margin[T] = fz_from_css_number(ch->box->style.margin[T], em, em); - ch->page_margin[B] = fz_from_css_number(ch->box->style.margin[B], em, em); - ch->page_margin[L] = fz_from_css_number(ch->box->style.margin[L], em, em); - ch->page_margin[R] = fz_from_css_number(ch->box->style.margin[R], em, em); + ch->page_margin[T] = fz_from_css_number(ch->html->root->style.margin[T], em, em); + ch->page_margin[B] = fz_from_css_number(ch->html->root->style.margin[B], em, em); + ch->page_margin[L] = fz_from_css_number(ch->html->root->style.margin[L], em, em); + ch->page_margin[R] = fz_from_css_number(ch->html->root->style.margin[R], em, em); ch->page_w = w - ch->page_margin[L] - ch->page_margin[R]; ch->page_h = h - ch->page_margin[T] - ch->page_margin[B]; - fz_layout_html(ctx, ch->box, ch->page_w, ch->page_h, ch->em); - count += ceilf(ch->box->h / ch->page_h); + fz_layout_html(ctx, ch->html, ch->page_w, ch->page_h, ch->em); + count += ceilf(ch->html->root->h / ch->page_h); } epub_update_link_dests(ctx, doc, doc->outline); @@ -128,7 +128,7 @@ epub_count_pages(fz_context *ctx, fz_document *doc_) epub_chapter *ch; int count = 0; for (ch = doc->spine; ch; ch = ch->next) - count += ceilf(ch->box->h / ch->page_h); + count += ceilf(ch->html->root->h / ch->page_h); return count; } @@ -148,7 +148,7 @@ epub_bound_page(fz_context *ctx, fz_page *page_, fz_rect *bbox) for (ch = doc->spine; ch; ch = ch->next) { - int cn = ceilf(ch->box->h / ch->page_h); + int cn = ceilf(ch->html->root->h / ch->page_h); if (n < count + cn) { bbox->x0 = 0; @@ -176,11 +176,11 @@ epub_run_page(fz_context *ctx, fz_page *page_, fz_device *dev, const fz_matrix * for (ch = doc->spine; ch; ch = ch->next) { - int cn = ceilf(ch->box->h / ch->page_h); + int cn = ceilf(ch->html->root->h / ch->page_h); if (n < count + cn) { fz_pre_translate(&local_ctm, ch->page_margin[L], ch->page_margin[T]); - fz_draw_html(ctx, dev, &local_ctm, ch->box, (n-count) * ch->page_h, (n-count+1) * ch->page_h); + fz_draw_html(ctx, dev, &local_ctm, ch->html, (n-count) * ch->page_h, (n-count+1) * ch->page_h); break; } count += cn; @@ -209,7 +209,7 @@ epub_drop_document(fz_context *ctx, fz_document *doc_) while (ch) { next = ch->next; - fz_drop_html(ctx, ch->box); + fz_drop_html(ctx, ch->html); fz_free(ctx, ch->path); fz_free(ctx, ch); ch = next; @@ -268,7 +268,7 @@ epub_parse_chapter(fz_context *ctx, epub_document *doc, const char *path) ch = fz_malloc_struct(ctx, epub_chapter); ch->path = fz_strdup(ctx, path); - ch->box = fz_parse_html(ctx, doc->set, zip, base_uri, buf, fz_user_css(ctx)); + ch->html = fz_parse_html(ctx, doc->set, zip, base_uri, buf, fz_user_css(ctx)); ch->next = NULL; fz_drop_buffer(ctx, buf); diff --git a/source/html/html-doc.c b/source/html/html-doc.c index 90de5c82..12d2cecd 100644 --- a/source/html/html-doc.c +++ b/source/html/html-doc.c @@ -12,7 +12,7 @@ struct html_document_s fz_html_font_set *set; float page_w, page_h, em; float page_margin[4]; - fz_html *box; + fz_html *html; }; struct html_page_s @@ -27,7 +27,7 @@ htdoc_drop_document(fz_context *ctx, fz_document *doc_) { html_document *doc = (html_document*)doc_; fz_drop_archive(ctx, doc->zip); - fz_drop_html(ctx, doc->box); + fz_drop_html(ctx, doc->html); fz_drop_html_font_set(ctx, doc->set); } @@ -35,7 +35,7 @@ static int htdoc_count_pages(fz_context *ctx, fz_document *doc_) { html_document *doc = (html_document*)doc_; - int count = ceilf(doc->box->h / doc->page_h); + int count = ceilf(doc->html->root->h / doc->page_h); return count; } @@ -44,19 +44,19 @@ htdoc_layout(fz_context *ctx, fz_document *doc_, float w, float h, float em) { html_document *doc = (html_document*)doc_; - if (doc->box) + if (doc->html && doc->html->root) { - doc->page_margin[T] = fz_from_css_number(doc->box->style.margin[T], em, em); - doc->page_margin[B] = fz_from_css_number(doc->box->style.margin[B], em, em); - doc->page_margin[L] = fz_from_css_number(doc->box->style.margin[L], em, em); - doc->page_margin[R] = fz_from_css_number(doc->box->style.margin[R], em, em); + doc->page_margin[T] = fz_from_css_number(doc->html->root->style.margin[T], em, em); + doc->page_margin[B] = fz_from_css_number(doc->html->root->style.margin[B], em, em); + doc->page_margin[L] = fz_from_css_number(doc->html->root->style.margin[L], em, em); + doc->page_margin[R] = fz_from_css_number(doc->html->root->style.margin[R], em, em); } doc->page_w = w - doc->page_margin[L] - doc->page_margin[R]; doc->page_h = h - doc->page_margin[T] - doc->page_margin[B]; doc->em = em; - fz_layout_html(ctx, doc->box, doc->page_w, doc->page_h, doc->em); + fz_layout_html(ctx, doc->html, doc->page_w, doc->page_h, doc->em); } static void @@ -86,7 +86,7 @@ htdoc_run_page(fz_context *ctx, fz_page *page_, fz_device *dev, const fz_matrix fz_pre_translate(&local_ctm, doc->page_margin[L], doc->page_margin[T]); - fz_draw_html(ctx, dev, &local_ctm, doc->box, n * doc->page_h, (n+1) * doc->page_h); + fz_draw_html(ctx, dev, &local_ctm, doc->html, n * doc->page_h, (n+1) * doc->page_h); } static fz_page * @@ -133,7 +133,7 @@ htdoc_open_document_with_stream(fz_context *ctx, fz_stream *file) fz_try(ctx) { fz_write_buffer_byte(ctx, buf, 0); - doc->box = fz_parse_html(ctx, doc->set, doc->zip, ".", buf, fz_user_css(ctx)); + doc->html = fz_parse_html(ctx, doc->set, doc->zip, ".", buf, fz_user_css(ctx)); } fz_always(ctx) fz_drop_buffer(ctx, buf); @@ -168,7 +168,7 @@ htdoc_open_document(fz_context *ctx, const char *filename) fz_try(ctx) { fz_write_buffer_byte(ctx, buf, 0); - doc->box = fz_parse_html(ctx, doc->set, doc->zip, ".", buf, fz_user_css(ctx)); + doc->html = fz_parse_html(ctx, doc->set, doc->zip, ".", buf, fz_user_css(ctx)); } fz_always(ctx) fz_drop_buffer(ctx, buf); diff --git a/source/html/html-layout.c b/source/html/html-layout.c index 57023724..34d6f8ac 100644 --- a/source/html/html-layout.c +++ b/source/html/html-layout.c @@ -148,7 +148,7 @@ static void fz_drop_html_flow(fz_context *ctx, fz_html_flow *flow) } } -static fz_html_flow *add_flow(fz_context *ctx, fz_pool *pool, fz_html *top, fz_html *inline_box, int type) +static fz_html_flow *add_flow(fz_context *ctx, fz_pool *pool, fz_html_box *top, fz_html_box *inline_box, int type) { fz_html_flow *flow = fz_pool_alloc(ctx, pool, sizeof *flow); flow->type = type; @@ -162,28 +162,28 @@ static fz_html_flow *add_flow(fz_context *ctx, fz_pool *pool, fz_html *top, fz_h return flow; } -static void add_flow_space(fz_context *ctx, fz_pool *pool, fz_html *top, fz_html *inline_box) +static void add_flow_space(fz_context *ctx, fz_pool *pool, fz_html_box *top, fz_html_box *inline_box) { fz_html_flow *flow = add_flow(ctx, pool, top, inline_box, FLOW_SPACE); flow->expand = 1; } -static void add_flow_break(fz_context *ctx, fz_pool *pool, fz_html *top, fz_html *inline_box) +static void add_flow_break(fz_context *ctx, fz_pool *pool, fz_html_box *top, fz_html_box *inline_box) { (void)add_flow(ctx, pool, top, inline_box, FLOW_BREAK); } -static void add_flow_sbreak(fz_context *ctx, fz_pool *pool, fz_html *top, fz_html *inline_box) +static void add_flow_sbreak(fz_context *ctx, fz_pool *pool, fz_html_box *top, fz_html_box *inline_box) { (void)add_flow(ctx, pool, top, inline_box, FLOW_SBREAK); } -static void add_flow_shyphen(fz_context *ctx, fz_pool *pool, fz_html *top, fz_html *inline_box) +static void add_flow_shyphen(fz_context *ctx, fz_pool *pool, fz_html_box *top, fz_html_box *inline_box) { (void)add_flow(ctx, pool, top, inline_box, FLOW_SHYPHEN); } -static void add_flow_word(fz_context *ctx, fz_pool *pool, fz_html *top, fz_html *inline_box, const char *a, const char *b, int lang) +static void add_flow_word(fz_context *ctx, fz_pool *pool, fz_html_box *top, fz_html_box *inline_box, const char *a, const char *b, int lang) { fz_html_flow *flow = add_flow(ctx, pool, top, inline_box, FLOW_WORD); flow->content.text = fz_pool_alloc(ctx, pool, b - a + 1); @@ -192,13 +192,13 @@ static void add_flow_word(fz_context *ctx, fz_pool *pool, fz_html *top, fz_html flow->markup_lang = lang; } -static void add_flow_image(fz_context *ctx, fz_pool *pool, fz_html *top, fz_html *inline_box, fz_image *img) +static void add_flow_image(fz_context *ctx, fz_pool *pool, fz_html_box *top, fz_html_box *inline_box, fz_image *img) { fz_html_flow *flow = add_flow(ctx, pool, top, inline_box, FLOW_IMAGE); flow->content.image = fz_keep_image(ctx, img); } -static void add_flow_anchor(fz_context *ctx, fz_pool *pool, fz_html *top, fz_html *inline_box, const char *anchor) +static void add_flow_anchor(fz_context *ctx, fz_pool *pool, fz_html_box *top, fz_html_box *inline_box, const char *anchor) { fz_html_flow *flow = add_flow(ctx, pool, top, inline_box, FLOW_ANCHOR); size_t len = strlen(anchor)+1; @@ -233,7 +233,7 @@ static fz_html_flow *split_flow(fz_context *ctx, fz_pool *pool, fz_html_flow *fl return new_flow; } -static void flush_space(fz_context *ctx, fz_html *flow, fz_html *inline_box, int lang, struct genstate *g) +static void flush_space(fz_context *ctx, fz_html_box *flow, fz_html_box *inline_box, int lang, struct genstate *g) { static const char *space = " "; int bsp = inline_box->style.white_space & WS_ALLOW_BREAK_SPACE; @@ -287,9 +287,9 @@ static const char *pairbrk[29] = "_^^%%%^^^_______%%__^^^_____%", /* RI regional indicator */ }; -static void generate_text(fz_context *ctx, fz_html *box, const char *text, int lang, struct genstate *g) +static void generate_text(fz_context *ctx, fz_html_box *box, const char *text, int lang, struct genstate *g) { - fz_html *flow; + fz_html_box *flow; fz_pool *pool = g->pool; int collapse = box->style.white_space & WS_COLLAPSE; int bsp = box->style.white_space & WS_ALLOW_BREAK_SPACE; @@ -425,18 +425,18 @@ static fz_image *load_html_image(fz_context *ctx, fz_archive *zip, const char *b return img; } -static void generate_anchor(fz_context *ctx, fz_html *box, const char *id, struct genstate *g) +static void generate_anchor(fz_context *ctx, fz_html_box *box, const char *id, struct genstate *g) { fz_pool *pool = g->pool; - fz_html *flow = box; + fz_html_box *flow = box; while (flow->type != BOX_FLOW) flow = flow->up; add_flow_anchor(ctx, pool, flow, box, id); } -static void generate_image(fz_context *ctx, fz_html *box, fz_image *img, struct genstate *g) +static void generate_image(fz_context *ctx, fz_html_box *box, fz_image *img, struct genstate *g) { - fz_html *flow = box; + fz_html_box *flow = box; fz_pool *pool = g->pool; while (flow->type != BOX_FLOW) flow = flow->up; @@ -467,7 +467,7 @@ static void generate_image(fz_context *ctx, fz_html *box, fz_image *img, struct g->at_bol = 0; } -static void init_box(fz_context *ctx, fz_html *box, fz_bidi_direction markup_dir) +static void init_box(fz_context *ctx, fz_html_box *box, fz_bidi_direction markup_dir) { box->type = BOX_BLOCK; box->x = box->y = 0; @@ -485,31 +485,31 @@ static void init_box(fz_context *ctx, fz_html *box, fz_bidi_direction markup_dir fz_default_css_style(ctx, &box->style); } -static void fz_drop_html_box(fz_context *ctx, fz_html *box) +static void fz_drop_html_box(fz_context *ctx, fz_html_box *box) { while (box) { - fz_html *next = box->next; + fz_html_box *next = box->next; fz_drop_html_flow(ctx, box->flow_head); fz_drop_html_box(ctx, box->down); box = next; } } -void fz_drop_html(fz_context *ctx, fz_html *box) +void fz_drop_html(fz_context *ctx, fz_html *html) { - fz_drop_html_box(ctx, box); - fz_drop_pool(ctx, box->pool); + fz_drop_html_box(ctx, html->root); + fz_drop_pool(ctx, html->pool); } -static fz_html *new_box(fz_context *ctx, fz_pool *pool, fz_bidi_direction markup_dir) +static fz_html_box *new_box(fz_context *ctx, fz_pool *pool, fz_bidi_direction markup_dir) { - fz_html *box = fz_pool_alloc(ctx, pool, sizeof *box); + fz_html_box *box = fz_pool_alloc(ctx, pool, sizeof *box); init_box(ctx, box, markup_dir); return box; } -static void insert_box(fz_context *ctx, fz_html *box, int type, fz_html *top) +static void insert_box(fz_context *ctx, fz_html_box *box, int type, fz_html_box *top) { box->type = type; @@ -529,7 +529,7 @@ static void insert_box(fz_context *ctx, fz_html *box, int type, fz_html *top) } } -static fz_html *insert_block_box(fz_context *ctx, fz_html *box, fz_html *top) +static fz_html_box *insert_block_box(fz_context *ctx, fz_html_box *box, fz_html_box *top) { if (top->type == BOX_BLOCK) { @@ -550,7 +550,7 @@ static fz_html *insert_block_box(fz_context *ctx, fz_html *box, fz_html *top) return top; } -static fz_html *insert_break_box(fz_context *ctx, fz_html *box, fz_html *top) +static fz_html_box *insert_break_box(fz_context *ctx, fz_html_box *box, fz_html_box *top) { if (top->type == BOX_BLOCK) { @@ -571,7 +571,7 @@ static fz_html *insert_break_box(fz_context *ctx, fz_html *box, fz_html *top) return top; } -static void insert_inline_box(fz_context *ctx, fz_html *box, fz_html *top, int markup_dir, struct genstate *g) +static void insert_inline_box(fz_context *ctx, fz_html_box *box, fz_html_box *top, int markup_dir, struct genstate *g) { if (top->type == BOX_BLOCK) { @@ -581,7 +581,7 @@ static void insert_inline_box(fz_context *ctx, fz_html *box, fz_html *top, int m } else { - fz_html *flow = new_box(ctx, g->pool, markup_dir); + fz_html_box *flow = new_box(ctx, g->pool, markup_dir); flow->is_first_flow = !top->last; insert_box(ctx, flow, BOX_FLOW, top); insert_box(ctx, box, BOX_INLINE, flow); @@ -598,11 +598,11 @@ static void insert_inline_box(fz_context *ctx, fz_html *box, fz_html *top, int m } } -static void generate_boxes(fz_context *ctx, fz_xml *node, fz_html *top, +static void generate_boxes(fz_context *ctx, fz_xml *node, fz_html_box *top, fz_css_match *up_match, int list_counter, int markup_dir, int markup_lang, struct genstate *g) { fz_css_match match; - fz_html *box; + fz_html_box *box; const char *tag; int display; @@ -622,7 +622,7 @@ static void generate_boxes(fz_context *ctx, fz_xml *node, fz_html *top, { if (top->type == BOX_INLINE) { - fz_html *flow = top; + fz_html_box *flow = top; while (flow->type != BOX_FLOW) flow = flow->up; add_flow_break(ctx, g->pool, flow, top); @@ -656,7 +656,7 @@ static void generate_boxes(fz_context *ctx, fz_xml *node, fz_html *top, fz_image *img = fz_tree_lookup(ctx, g->images, src+1); if (display == DIS_BLOCK) { - fz_html *imgbox; + fz_html_box *imgbox; box = new_box(ctx, g->pool, markup_dir); fz_apply_css_style(ctx, g->set, &box->style, &match); top = insert_block_box(ctx, box, top); @@ -1042,7 +1042,7 @@ static float measure_line(fz_html_flow *node, fz_html_flow *end, float *baseline return h; } -static void layout_line(fz_context *ctx, float indent, float page_w, float line_w, int align, fz_html_flow *start, fz_html_flow *end, fz_html *box, float baseline, float line_h) +static void layout_line(fz_context *ctx, float indent, float page_w, float line_w, int align, fz_html_flow *start, fz_html_flow *end, fz_html_box *box, float baseline, float line_h) { float x = box->x + indent; float y = box->y + box->h; @@ -1173,7 +1173,7 @@ static void layout_line(fz_context *ctx, float indent, float page_w, float line_ fz_free(ctx, reorder); } -static void find_accumulated_margins(fz_context *ctx, fz_html *box, float *w, float *h) +static void find_accumulated_margins(fz_context *ctx, fz_html_box *box, float *w, float *h) { while (box) { @@ -1186,7 +1186,7 @@ static void find_accumulated_margins(fz_context *ctx, fz_html *box, float *w, fl } } -static void flush_line(fz_context *ctx, fz_html *box, float page_h, float page_w, float line_w, int align, float indent, fz_html_flow *a, fz_html_flow *b) +static void flush_line(fz_context *ctx, fz_html_box *box, float page_h, float page_w, float line_w, int align, float indent, fz_html_flow *a, fz_html_flow *b) { float avail, line_h, baseline; avail = page_h - fmodf(box->y + box->h, page_h); @@ -1197,7 +1197,7 @@ static void flush_line(fz_context *ctx, fz_html *box, float page_h, float page_w box->h += line_h; } -static void layout_flow_inline(fz_context *ctx, fz_html *box, fz_html *top) +static void layout_flow_inline(fz_context *ctx, fz_html_box *box, fz_html_box *top) { while (box) { @@ -1208,7 +1208,7 @@ static void layout_flow_inline(fz_context *ctx, fz_html *box, fz_html *top) } } -static void layout_flow(fz_context *ctx, fz_html *box, fz_html *top, float page_h, hb_buffer_t *hb_buf) +static void layout_flow(fz_context *ctx, fz_html_box *box, fz_html_box *top, float page_h, hb_buffer_t *hb_buf) { fz_html_flow *node, *line, *candidate; float line_w, candidate_w, indent, break_w, nonbreak_w; @@ -1327,7 +1327,7 @@ static void layout_flow(fz_context *ctx, fz_html *box, fz_html *top, float page_ } } -static int layout_block_page_break(fz_context *ctx, fz_html *box, float page_h, float vertical, int page_break) +static int layout_block_page_break(fz_context *ctx, fz_html_box *box, float page_h, float vertical, int page_break) { if (page_break == PB_ALWAYS || page_break == PB_LEFT || page_break == PB_RIGHT) { @@ -1346,9 +1346,9 @@ static int layout_block_page_break(fz_context *ctx, fz_html *box, float page_h, return 0; } -static float layout_block(fz_context *ctx, fz_html *box, fz_html *top, float page_h, float vertical, hb_buffer_t *hb_buf) +static float layout_block(fz_context *ctx, fz_html_box *box, fz_html_box *top, float page_h, float vertical, hb_buffer_t *hb_buf) { - fz_html *child; + fz_html_box *child; int first; fz_css_style *style = &box->style; @@ -1461,7 +1461,7 @@ static float layout_block(fz_context *ctx, fz_html *box, fz_html *top, float pag return vertical; } -static void draw_flow_box(fz_context *ctx, fz_html *box, float page_top, float page_bot, fz_device *dev, const fz_matrix *ctm, hb_buffer_t *hb_buf) +static void draw_flow_box(fz_context *ctx, fz_html_box *box, float page_top, float page_bot, fz_device *dev, const fz_matrix *ctm, hb_buffer_t *hb_buf) { fz_html_flow *node; fz_text *text; @@ -1725,7 +1725,7 @@ static void format_list_number(fz_context *ctx, int type, int x, char *buf, int } } -static fz_html_flow *find_list_mark_anchor(fz_context *ctx, fz_html *box) +static fz_html_flow *find_list_mark_anchor(fz_context *ctx, fz_html_box *box) { /* find first flow node in <li> tag */ while (box) @@ -1737,7 +1737,7 @@ static fz_html_flow *find_list_mark_anchor(fz_context *ctx, fz_html *box) return NULL; } -static void draw_list_mark(fz_context *ctx, fz_html *box, float page_top, float page_bot, fz_device *dev, const fz_matrix *ctm, int n) +static void draw_list_mark(fz_context *ctx, fz_html_box *box, float page_top, float page_bot, fz_device *dev, const fz_matrix *ctm, int n) { fz_font *font; fz_text *text; @@ -1807,7 +1807,7 @@ static void draw_list_mark(fz_context *ctx, fz_html *box, float page_top, float fz_rethrow(ctx); } -static void draw_block_box(fz_context *ctx, fz_html *box, float page_top, float page_bot, fz_device *dev, const fz_matrix *ctm, hb_buffer_t *hb_buf) +static void draw_block_box(fz_context *ctx, fz_html_box *box, float page_top, float page_bot, fz_device *dev, const fz_matrix *ctm, hb_buffer_t *hb_buf) { float x0, y0, x1, y1; @@ -1850,7 +1850,7 @@ static void draw_block_box(fz_context *ctx, fz_html *box, float page_top, float } void -fz_draw_html(fz_context *ctx, fz_device *dev, const fz_matrix *ctm, fz_html *box, float page_top, float page_bot) +fz_draw_html(fz_context *ctx, fz_device *dev, const fz_matrix *ctm, fz_html *html, float page_top, float page_bot) { fz_matrix local_ctm = *ctm; hb_buffer_t *hb_buf = NULL; @@ -1867,7 +1867,7 @@ fz_draw_html(fz_context *ctx, fz_device *dev, const fz_matrix *ctm, fz_html *box hb_unlock(ctx); unlocked = 1; fz_pre_translate(&local_ctm, 0, -page_top); - draw_block_box(ctx, box, page_top, page_bot, dev, &local_ctm, hb_buf); + draw_block_box(ctx, html->root, page_top, page_bot, dev, &local_ctm, hb_buf); } fz_always(ctx) { @@ -2068,8 +2068,8 @@ fz_print_html_flow(fz_context *ctx, fz_html_flow *flow, fz_html_flow *end) } } -void -fz_print_html(fz_context *ctx, fz_html *box, int pstyle, int level) +static void +fz_print_html_box(fz_context *ctx, fz_html_box *box, int pstyle, int level) { while (box) { @@ -2093,7 +2093,7 @@ fz_print_html(fz_context *ctx, fz_html *box, int pstyle, int level) if (pstyle && !box->flow_head) fz_print_css_style(ctx, &box->style, box->type, level+1); - fz_print_html(ctx, box->down, pstyle, level+1); + fz_print_html_box(ctx, box->down, pstyle, level+1); if (box->flow_head) { @@ -2114,8 +2114,15 @@ fz_print_html(fz_context *ctx, fz_html *box, int pstyle, int level) } void -fz_layout_html(fz_context *ctx, fz_html *box, float w, float h, float em) +fz_print_html(fz_context *ctx, fz_html *html, int pstyle) { + fz_print_html_box(ctx, html->root, pstyle, 0); +} + +void +fz_layout_html(fz_context *ctx, fz_html *html, float w, float h, float em) +{ + fz_html_box *box = html->root; hb_buffer_t *hb_buf = NULL; int unlocked = 0; @@ -2286,7 +2293,7 @@ detect_flow_directionality(fz_context *ctx, fz_pool *pool, uni_buf *buffer, fz_b } static void -detect_box_directionality(fz_context *ctx, fz_pool *pool, uni_buf *buffer, fz_html *box) +detect_box_directionality(fz_context *ctx, fz_pool *pool, uni_buf *buffer, fz_html_box *box) { while (box) { @@ -2298,7 +2305,7 @@ detect_box_directionality(fz_context *ctx, fz_pool *pool, uni_buf *buffer, fz_ht } static void -detect_directionality(fz_context *ctx, fz_pool *pool, fz_html *box) +detect_directionality(fz_context *ctx, fz_pool *pool, fz_html_box *box) { uni_buf buffer = { NULL }; @@ -2315,7 +2322,7 @@ fz_parse_html(fz_context *ctx, fz_html_font_set *set, fz_archive *zip, const cha { fz_xml *xml; fz_css_match match; - fz_html *box; + fz_html *html; struct genstate g; g.pool = fz_new_pool(ctx); @@ -2350,23 +2357,24 @@ fz_parse_html(fz_context *ctx, fz_html_font_set *set, fz_archive *zip, const cha fz_add_css_font_faces(ctx, g.set, g.zip, g.base_uri, g.css); /* load @font-face fonts into font set */ - box = new_box(ctx, g.pool, DEFAULT_DIR); - box->pool = g.pool; + html = fz_malloc_struct(ctx, fz_html); + html->pool = g.pool; + html->root = new_box(ctx, g.pool, DEFAULT_DIR); match.up = NULL; match.count = 0; fz_match_css_at_page(ctx, &match, g.css); - fz_apply_css_style(ctx, g.set, &box->style, &match); + fz_apply_css_style(ctx, g.set, &html->root->style, &match); // TODO: transfer page margins out of this hacky box - generate_boxes(ctx, xml, box, &match, 0, DEFAULT_DIR, FZ_LANG_UNSET, &g); + generate_boxes(ctx, xml, html->root, &match, 0, DEFAULT_DIR, FZ_LANG_UNSET, &g); fz_drop_css(ctx, g.css); fz_drop_xml(ctx, xml); - detect_directionality(ctx, g.pool, box); + detect_directionality(ctx, g.pool, html->root); fz_drop_tree(ctx, g.images, (void(*)(fz_context*,void*))fz_drop_image); - return box; + return html; } |