From a5f282cac059b279823520ae3e3dfd2138a1fe23 Mon Sep 17 00:00:00 2001 From: Tor Andersson Date: Wed, 12 Nov 2014 02:24:39 +0100 Subject: html: Collapse top/top and bottom/bottom margins. --- source/html/layout.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) (limited to 'source/html/layout.c') diff --git a/source/html/layout.c b/source/html/layout.c index 84c02e3d..6d9753ba 100644 --- a/source/html/layout.c +++ b/source/html/layout.c @@ -335,9 +335,10 @@ 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 top/top and bottom/bottom margins - - box_collapse_margin = 0; + if (box->padding[TOP] == 0) + box_collapse_margin = box->margin[TOP]; + else + box_collapse_margin = 0; if (box->margin[TOP] > top_collapse_margin) box->margin[TOP] -= top_collapse_margin; @@ -367,6 +368,16 @@ static void layout_block(fz_context *ctx, struct box *box, struct box *top, floa } } } + + if (box->padding[BOTTOM] == 0) + { + if (box->margin[BOTTOM] > 0) + { + box->h -= box_collapse_margin; + if (box->margin[BOTTOM] < box_collapse_margin) + box->margin[BOTTOM] = box_collapse_margin; + } + } } static void indent(int level) -- cgit v1.2.3