diff options
author | Tor Andersson <tor.andersson@artifex.com> | 2014-10-23 16:13:42 +0200 |
---|---|---|
committer | Tor Andersson <tor.andersson@artifex.com> | 2014-12-03 12:25:51 +0100 |
commit | 7159498b095238ca8c8c87cc99d83c46fc5cd19b (patch) | |
tree | 389dc2016150d5e96d2231f19787b1ca8f9b9964 /source | |
parent | 5dc64869a5e3bdf851d82ff445b32b609084931b (diff) | |
download | mupdf-7159498b095238ca8c8c87cc99d83c46fc5cd19b.tar.xz |
html: Apply margins.
Diffstat (limited to 'source')
-rw-r--r-- | source/html/css-apply.c | 30 | ||||
-rw-r--r-- | source/html/layout.c | 34 |
2 files changed, 43 insertions, 21 deletions
diff --git a/source/html/css-apply.c b/source/html/css-apply.c index 9a73ee2a..a99eed2b 100644 --- a/source/html/css-apply.c +++ b/source/html/css-apply.c @@ -706,15 +706,15 @@ get_style_property_display(struct style *node) if (value) { if (!strcmp(value->data, "none")) - return NONE; + return DIS_NONE; if (!strcmp(value->data, "inline")) - return INLINE; + return DIS_INLINE; if (!strcmp(value->data, "block")) - return BLOCK; + return DIS_BLOCK; if (!strcmp(value->data, "list-item")) - return LIST_ITEM; + return DIS_LIST_ITEM; } - return INLINE; + return DIS_INLINE; } static float @@ -768,34 +768,34 @@ compute_style(struct computed_style *style, struct style *node, float width) memset(style, 0, sizeof *style); - style->position = STATIC; - style->text_align = LEFT; + style->position = POS_STATIC; + style->text_align = TA_LEFT; style->font_size = 12; value = get_style_property(node, "position"); if (value) { if (!strcmp(value->data, "static")) - style->position = STATIC; + style->position = POS_STATIC; if (!strcmp(value->data, "relative")) - style->position = RELATIVE; + style->position = POS_RELATIVE; if (!strcmp(value->data, "absolute")) - style->position = ABSOLUTE; + style->position = POS_ABSOLUTE; if (!strcmp(value->data, "fixed")) - style->position = FIXED; + style->position = POS_FIXED; } value = get_style_property(node, "text-align"); if (value) { if (!strcmp(value->data, "left")) - style->text_align = LEFT; + style->text_align = TA_LEFT; if (!strcmp(value->data, "right")) - style->text_align = RIGHT; + style->text_align = TA_RIGHT; if (!strcmp(value->data, "center")) - style->text_align = CENTER; + style->text_align = TA_CENTER; if (!strcmp(value->data, "justify")) - style->text_align = JUSTIFY; + style->text_align = TA_JUSTIFY; } value = get_style_property(node, "vertical-align"); diff --git a/source/html/layout.c b/source/html/layout.c index 2960de73..6b2c7d44 100644 --- a/source/html/layout.c +++ b/source/html/layout.c @@ -157,13 +157,13 @@ static void generate_boxes(fz_context *ctx, fz_xml *node, struct box *top, struc // TOOD: <br> // TODO: <img> - if (display != NONE) + if (display != DIS_NONE) { - if (display == BLOCK) + if (display == DIS_BLOCK) { top = insert_block_box(ctx, box, top); } - else if (display == INLINE) + else if (display == DIS_INLINE) { insert_inline_box(ctx, box, top); } @@ -190,14 +190,27 @@ static void layout_inline(fz_context *ctx, struct box *box, struct box *top) { struct computed_style style; struct box *child; + const char *s; compute_style(&style, &box->style, top->w); + box->x = top->x + top->w; box->y = top->y; box->h = style.font_size; + box->w = 0; + + s = fz_xml_text(box->node); + if (s) + { + box->w += strlen(s) * 0.5 * style.font_size; + } + for (child = box->down; child; child = child->next) { layout_inline(ctx, child, top); + if (child->h > box->h) + box->h = child->h; + top->w += child->w; } } @@ -208,13 +221,17 @@ static void layout_anonymous(fz_context *ctx, struct box *box, struct box *top) compute_style(&style, &box->style, top->w); + box->x = top->x; box->y = top->y + top->h; box->h = 0; + box->w = 0; + for (child = box->down; child; child = child->next) { layout_inline(ctx, child, box); if (child->h > box->h) box->h = child->h; + box->w += child->w; } } @@ -225,8 +242,11 @@ static void layout_block(fz_context *ctx, struct box *box, struct box *top) compute_style(&style, &box->style, top->w); - box->y = top->y + top->h; + box->x = top->x + style.margin[LEFT]; + box->y = top->y + top->h + style.margin[TOP]; + box->w = top->w - (style.margin[LEFT] + style.margin[RIGHT]); box->h = 0; + for (child = box->down; child; child = child->next) { if (child->type == BOX_BLOCK) @@ -235,6 +255,8 @@ static void layout_block(fz_context *ctx, struct box *box, struct box *top) layout_anonymous(ctx, child, box); box->h += child->h; } + + box->h += style.margin[BOTTOM]; } static void indent(int level) @@ -246,7 +268,7 @@ static void print_box(fz_context *ctx, struct box *box, int level) { while (box) { - printf("%-5d", (int)box->y); + printf("%-5d %-5d", (int)box->x, (int)box->y); indent(level); switch (box->type) { @@ -346,7 +368,7 @@ html_layout_document(html_document *doc, float w, float h) css = fz_parse_css(doc->ctx, NULL, default_css); css = load_css(doc->ctx, css, doc->root); -// print_rules(css); + print_rules(css); root_box = new_box(doc->ctx, NULL, NULL); generate_boxes(doc->ctx, doc->root, root_box, css); |