summaryrefslogtreecommitdiff
path: root/source/html
diff options
context:
space:
mode:
authorTor Andersson <tor.andersson@artifex.com>2014-11-11 17:25:07 +0100
committerTor Andersson <tor.andersson@artifex.com>2014-12-03 12:25:51 +0100
commitd8699f7f7a5ee7192e1e437eaffa75f415204073 (patch)
treeb7f1c6b8752c1609d6ff8c8fc6c9be94d69b86fa /source/html
parent7cb2a64e678f0179cb75d2de0321d5d4ca35183f (diff)
downloadmupdf-d8699f7f7a5ee7192e1e437eaffa75f415204073.tar.xz
html: Collapse adjacent top/bottom margins.
Diffstat (limited to 'source/html')
-rw-r--r--source/html/layout.c29
1 files changed, 24 insertions, 5 deletions
diff --git a/source/html/layout.c b/source/html/layout.c
index 9fd22094..84c02e3d 100644
--- a/source/html/layout.c
+++ b/source/html/layout.c
@@ -317,9 +317,11 @@ static void layout_flow(fz_context *ctx, struct box *box, struct box *top, float
}
}
-static void layout_block(fz_context *ctx, struct box *box, struct box *top, float em)
+static void layout_block(fz_context *ctx, struct box *box, struct box *top, float em, float top_collapse_margin)
{
struct box *child;
+ float box_collapse_margin;
+ float bottom;
em = from_number(box->style.font_size, em, em);
@@ -333,7 +335,14 @@ static void layout_block(fz_context *ctx, struct box *box, struct box *top, floa
box->padding[2] = from_number(box->style.padding[2], em, top->w);
box->padding[3] = from_number(box->style.padding[3], em, top->w);
- // TODO: collapse vertical margins
+ // TODO: collapse top/top and bottom/bottom margins
+
+ box_collapse_margin = 0;
+
+ if (box->margin[TOP] > top_collapse_margin)
+ box->margin[TOP] -= top_collapse_margin;
+ else
+ box->margin[TOP] = 0;
box->x = top->x + box->margin[LEFT] + box->padding[LEFT];
box->y = top->y + top->h + box->margin[TOP] + box->padding[TOP];
@@ -343,10 +352,20 @@ static void layout_block(fz_context *ctx, struct box *box, struct box *top, floa
for (child = box->down; child; child = child->next)
{
if (child->type == BOX_BLOCK)
- layout_block(ctx, child, box, em);
+ {
+ layout_block(ctx, child, box, em, box_collapse_margin);
+ box->h += child->h + child->padding[TOP] + child->padding[BOTTOM] + child->margin[TOP] + child->margin[BOTTOM];
+ box_collapse_margin = child->margin[BOTTOM];
+ }
else if (child->type == BOX_FLOW)
+ {
layout_flow(ctx, child, box, em);
- box->h += child->h + child->padding[TOP] + child->padding[BOTTOM] + child->margin[TOP] + child->margin[BOTTOM];
+ if (child->h > 0)
+ {
+ box->h += child->h;
+ box_collapse_margin = 0;
+ }
+ }
}
}
@@ -574,7 +593,7 @@ html_layout_document(html_document *doc, float w, float h)
generate_boxes(doc->ctx, doc->xml, root_box, css, &style);
- layout_block(doc->ctx, root_box, win_box, 12);
+ layout_block(doc->ctx, root_box, win_box, 12, 0);
print_box(doc->ctx, root_box, 0);