From 018ff6b6a2cd11eecbf2a6ae124dae1c75047698 Mon Sep 17 00:00:00 2001 From: Guillaume Ayoub Date: Wed, 13 Mar 2024 17:01:30 +0100 Subject: [PATCH 1/4] Remove useless function --- weasyprint/draw.py | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/weasyprint/draw.py b/weasyprint/draw.py index 3f7df5991..5f8db20cf 100644 --- a/weasyprint/draw.py +++ b/weasyprint/draw.py @@ -65,14 +65,6 @@ def draw_page(page, stream): draw_stacking_context(stream, stacking_context) -def draw_box_background_and_border(stream, page, box): - if isinstance(box, boxes.TableBox): - draw_table(stream, box) - else: - draw_background(stream, box.background) - draw_border(stream, box) - - def draw_stacking_context(stream, stacking_context): """Draw a ``stacking_context`` on ``stream``.""" # See https://www.w3.org/TR/CSS2/zindex.html @@ -123,7 +115,8 @@ def draw_stacking_context(stream, stacking_context): boxes.InlineBlockBox, boxes.TableCellBox, boxes.FlexContainerBox)): # The canvas background was removed by layout_backgrounds - draw_box_background_and_border(stream, stacking_context.page, box) + draw_background(stream, box.background) + draw_border(stream, box) with stacked(stream): # dont clip the PageBox, see #35 @@ -142,8 +135,11 @@ def draw_stacking_context(stream, stacking_context): # Point 4 for block in stacking_context.block_level_boxes: - draw_box_background_and_border( - stream, stacking_context.page, block) + if isinstance(block, boxes.TableBox): + draw_table(stream, block) + else: + draw_background(stream, block.background) + draw_border(stream, block) # Point 5 for child_context in stacking_context.float_contexts: From 13e204cbfe61a7ba1e9002a570c1da805b4a8708 Mon Sep 17 00:00:00 2001 From: Guillaume Ayoub Date: Wed, 13 Mar 2024 17:25:09 +0100 Subject: [PATCH 2/4] Apply overflow to replaced boxes See: - https://github.com/w3c/csswg-drafts/issues/7058 - https://github.com/whatwg/html/pull/8028 --- weasyprint/css/html5_ua.css | 1 + weasyprint/css/tests_ua.css | 2 ++ weasyprint/draw.py | 13 ++++--------- 3 files changed, 7 insertions(+), 9 deletions(-) diff --git a/weasyprint/css/html5_ua.css b/weasyprint/css/html5_ua.css index 9bc5b0c9e..b2d32e381 100644 --- a/weasyprint/css/html5_ua.css +++ b/weasyprint/css/html5_ua.css @@ -543,6 +543,7 @@ style { display: none; } sub { font-size: smaller; line-height: normal; vertical-align: sub; } summary { display: block; /* unicode-bidi: isolate; */ } sup { font-size: smaller; line-height: normal; vertical-align: super; } +img, svg { overflow: hidden; } table { border-collapse: separate; border-color: gray; border-spacing: 2px; display: table; text-indent: 0; /* unicode-bidi: isolate; */ } diff --git a/weasyprint/css/tests_ua.css b/weasyprint/css/tests_ua.css index 49c4451c4..5c93bea99 100644 --- a/weasyprint/css/tests_ua.css +++ b/weasyprint/css/tests_ua.css @@ -34,6 +34,8 @@ h4 { bookmark-level: 4; bookmark-label: content(text) } h5 { bookmark-level: 5; bookmark-label: content(text) } h6 { bookmark-level: 6; bookmark-label: content(text) } +img, svg { overflow: hidden; } + ::marker { unicode-bidi: isolate; font-variant-numeric: tabular-nums } ::footnote-call { content: counter(footnote) } diff --git a/weasyprint/draw.py b/weasyprint/draw.py index 5f8db20cf..d0cb34446 100644 --- a/weasyprint/draw.py +++ b/weasyprint/draw.py @@ -113,7 +113,7 @@ def draw_stacking_context(stream, stacking_context): # Point 2 if isinstance(box, (boxes.BlockBox, boxes.MarginBox, boxes.InlineBlockBox, boxes.TableCellBox, - boxes.FlexContainerBox)): + boxes.FlexContainerBox, boxes.ReplacedBox)): # The canvas background was removed by layout_backgrounds draw_background(stream, box.background) draw_border(stream, box) @@ -148,14 +148,12 @@ def draw_stacking_context(stream, stacking_context): # Point 6 if isinstance(box, boxes.InlineBox): draw_inline_level(stream, stacking_context.page, box) + elif isinstance(box, boxes.ReplacedBox): + draw_replacedbox(stream, box) # Point 7 for block in [box] + stacking_context.blocks_and_cells: - if isinstance(block, boxes.ReplacedBox): - draw_background(stream, block.background) - draw_border(stream, block) - draw_replacedbox(stream, block) - elif block.children: + if block.children: if block != box: stream.begin_marked_content(block, mcid=True) if isinstance(block.children[-1], boxes.LineBox): @@ -983,9 +981,6 @@ def draw_replacedbox(stream, box): return with stacked(stream): - rounded_box_path(stream, box.rounded_content_box()) - stream.clip() - stream.end() stream.transform(e=draw_x, f=draw_y) with stacked(stream): # TODO: Use the real intrinsic size here, not affected by From f2ad6332f7e9e1dffb372641d32bf807cfba8500 Mon Sep 17 00:00:00 2001 From: Guillaume Ayoub Date: Sat, 16 Mar 2024 17:27:45 +0100 Subject: [PATCH 3/4] Fix image rendering when overflow is not set --- tests/draw/svg/test_images.py | 4 ++-- tests/draw/test_image.py | 8 +++++--- weasyprint/css/tests_ua.css | 2 -- weasyprint/draw.py | 6 +++--- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/tests/draw/svg/test_images.py b/tests/draw/svg/test_images.py index a1a68d6c5..732282989 100644 --- a/tests/draw/svg/test_images.py +++ b/tests/draw/svg/test_images.py @@ -163,7 +163,7 @@ def test_image_svg_align_slice_x(assert_pixels): ''', ''' @page { size: 8px 8px } - svg { display: block } + svg { display: block; overflow: hidden } @page { size: 8px } body { margin: 2px 0 0 2px; font-size: 0 } + img { overflow: hidden }
''' % filename) @@ -169,7 +170,8 @@ def test_resized_images(assert_pixels, filename):
''' % filename) @@ -478,7 +480,7 @@ def test_image_cover(assert_pixels): ''') @@ -489,7 +491,7 @@ def test_image_contain(assert_pixels): ''') diff --git a/weasyprint/css/tests_ua.css b/weasyprint/css/tests_ua.css index 5c93bea99..49c4451c4 100644 --- a/weasyprint/css/tests_ua.css +++ b/weasyprint/css/tests_ua.css @@ -34,8 +34,6 @@ h4 { bookmark-level: 4; bookmark-label: content(text) } h5 { bookmark-level: 5; bookmark-label: content(text) } h6 { bookmark-level: 6; bookmark-label: content(text) } -img, svg { overflow: hidden; } - ::marker { unicode-bidi: isolate; font-variant-numeric: tabular-nums } ::footnote-call { content: counter(footnote) } diff --git a/weasyprint/draw.py b/weasyprint/draw.py index d0cb34446..1f4374e96 100644 --- a/weasyprint/draw.py +++ b/weasyprint/draw.py @@ -148,12 +148,12 @@ def draw_stacking_context(stream, stacking_context): # Point 6 if isinstance(box, boxes.InlineBox): draw_inline_level(stream, stacking_context.page, box) - elif isinstance(box, boxes.ReplacedBox): - draw_replacedbox(stream, box) # Point 7 for block in [box] + stacking_context.blocks_and_cells: - if block.children: + if isinstance(block, boxes.ReplacedBox): + draw_replacedbox(stream, block) + elif block.children: if block != box: stream.begin_marked_content(block, mcid=True) if isinstance(block.children[-1], boxes.LineBox): From 0997d0c507601c9e85d0938b1b56238eea119c2c Mon Sep 17 00:00:00 2001 From: Guillaume Ayoub Date: Sat, 16 Mar 2024 17:34:48 +0100 Subject: [PATCH 4/4] Test overflowing images --- tests/draw/test_image.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/tests/draw/test_image.py b/tests/draw/test_image.py index 3738e58cf..20fef2de0 100644 --- a/tests/draw/test_image.py +++ b/tests/draw/test_image.py @@ -16,6 +16,17 @@ ________ ''' +centered_image_overflow = ''' + ________ + ________ + __rBBBBB + __BBBBBB + __BBBBBB + __BBBBBB + __BBBBBB + __BBBBBB +''' + resized_image = ''' ____________ ____________ @@ -176,6 +187,15 @@ def test_resized_images(assert_pixels, filename):
''' % filename) +def test_image_overflow(assert_pixels): + assert_pixels(centered_image_overflow, ''' + +
''') + + @assert_no_logs @pytest.mark.parametrize('viewbox, width, height', ( (None, None, None),