[gs-commits] mupdf 1.16.1.47 Remove a pointer from fz_html_box.
[email protected] (Robin Watts) Mon, 30 Sep 2019 15:22:27 +0000 (UTC)
| Newsgroups | gmane.comp.printing.ghostscript.cvs |
|---|---|
| Message-ID | <[email protected]> |
commit c5d72ebb766c4ad7a557631d00bc9e51f2d738d9 Author: Robin Watts <[email protected]> Date: Fri Sep 27 18:53:48 2019 +0100 Remove a pointer from fz_html_box. We only use the ->last pointer during construction. With care we can use ->next instead. diff --git a/source/html/html-imp.h b/source/html/html-imp.h index 62cdc03..212a382 100644 --- a/source/html/html-imp.h +++ b/source/html/html-imp.h @@ -213,7 +213,11 @@ struct fz_html_box_s float margin[4]; float border[4]; float em; - fz_html_box *up, *down, *last, *next; + /* During construction, 'next' plays double duty; as well + * as its normal meaning of 'next sibling', the last sibling + * has next meaning "the last of my children". We correct + * this as a post-processing pass after construction. */ + fz_html_box *up, *down, *next; fz_html_flow *flow_head, **flow_tail; char *id, *href; fz_css_style style; diff --git a/source/html/html-parse.c b/source/html/html-parse.c index 1f7dd13..c4ab017 100644 --- a/source/html/html-parse.c +++ b/source/html/html-parse.c @@ -477,7 +477,6 @@ static void init_box(fz_context *ctx, fz_html_box *box, fz_bidi_direction markup box->w = box->b = 0; box->up = NULL; - box->last = NULL; box->down = NULL; box->next = NULL; @@ -523,14 +522,17 @@ static void insert_box(fz_context *ctx, fz_html_box *box, int type, fz_html_box if (top) { - if (!top->last) + /* Here 'next' really means 'last of my children'. This will + * be fixed up in a pass at the end of parsing. */ + if (!top->next) { - top->down = top->last = box; + top->down = top->next = box; } else { - top->last->next = box; - top->last = box; + top->next->next = box; + /* Here next actually means next */ + top->next = box; } } } @@ -625,14 +627,15 @@ static void insert_inline_box(fz_context *ctx, fz_html_box *box, fz_html_box *to while (top->type != BOX_BLOCK && top->type != BOX_TABLE_CELL) top = top->up; - if (top->last && top->last->type == BOX_FLOW) + /* Here 'next' actually means 'last of my children' */ + if (top->next && top->next->type == BOX_FLOW) { - insert_box(ctx, box, BOX_INLINE, top->last); + insert_box(ctx, box, BOX_INLINE, top->next); } else { fz_html_box *flow = new_box(ctx, g->pool, markup_dir); - flow->is_first_flow = !top->last; + flow->is_first_flow = !top->next; insert_box(ctx, flow, BOX_FLOW, top); insert_box(ctx, box, BOX_INLINE, flow); g->at_bol = 1; @@ -1201,6 +1204,25 @@ detect_directionality(fz_context *ctx, fz_pool *pool, fz_html_box *box) fz_rethrow(ctx); } +/* Here we look for places where box->next actually means + * 'the last of my children', and correct it by setting + * next == NULL. We can spot these because box->next->up == box. */ +static void +fix_nexts(fz_html_box *box) +{ + while (box) + { + if (box->down) + fix_nexts(box->down); + if (box->next && box->next->up == box) + { + box->next = NULL; + break; + } + box = box->next; + } +} + fz_html * fz_parse_html(fz_context *ctx, fz_html_font_set *set, fz_archive *zip, const char *base_uri, fz_buffer *buf, const char *user_css) { @@ -1288,6 +1310,7 @@ fz_parse_html(fz_context *ctx, fz_html_font_set *set, fz_archive *zip, const cha // TODO: transfer page margins out of this hacky box generate_boxes(ctx, root, html->root, &match, 0, 0, DEFAULT_DIR, FZ_LANG_UNSET, &g); + fix_nexts(html->root); detect_directionality(ctx, g.pool, html->root); http://git.ghostscript.com/?p=mupdf.git;a=commit;h=c5d72ebb766c4ad7a557631d00bc9e51f2d738d9 -- MuPDF library Artifex Software, Inc.