From fe7fd1c1794c1d24152dedb82312a1dc2333ffa7 Mon Sep 17 00:00:00 2001 From: Guillaume Ayoub Date: Sat, 14 Mar 2020 15:00:25 +0100 Subject: [PATCH] =?UTF-8?q?Don=E2=80=99t=20crash=20on=20absolute=20SVG=20f?= =?UTF-8?q?iles=20with=20no=20intrinsic=20size?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fix #1050. --- weasyprint/layout/blocks.py | 10 ++++++++-- weasyprint/tests/test_layout/test_image.py | 10 ++++++++++ 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/weasyprint/layout/blocks.py b/weasyprint/layout/blocks.py index f137080de..b2561ec9d 100644 --- a/weasyprint/layout/blocks.py +++ b/weasyprint/layout/blocks.py @@ -164,7 +164,13 @@ def block_replaced_box_layout(box, containing_block): def block_level_width(box, containing_block): """Set the ``box`` width.""" # 'cb' stands for 'containing block' - cb_width = containing_block.width + if isinstance(containing_block, boxes.Box): + cb_width = containing_block.width + direction = containing_block.style['direction'] + else: + cb_width = containing_block[0] + # TODO: what is the real text direction? + direction = 'ltr' # http://www.w3.org/TR/CSS21/visudet.html#blockwidth @@ -196,7 +202,7 @@ def block_level_width(box, containing_block): margin_r = box.margin_right = 0 if width != 'auto' and margin_l != 'auto' and margin_r != 'auto': # The equation is over-constrained. - if containing_block.style['direction'] == 'rtl' and not box.is_column: + if direction == 'rtl' and not box.is_column: box.position_x += ( cb_width - paddings_plus_borders - width - margin_r - margin_l) # Do nothing in ltr. diff --git a/weasyprint/tests/test_layout/test_image.py b/weasyprint/tests/test_layout/test_image.py index b4dea719e..fef65fbdf 100644 --- a/weasyprint/tests/test_layout/test_image.py +++ b/weasyprint/tests/test_layout/test_image.py @@ -319,6 +319,16 @@ def test_images_17(): assert img.height == 150 +@assert_no_logs +def test_images_18(): + # Test regression: https://github.com/Kozea/WeasyPrint/issues/1050 + page, = parse(''' + ''') + + @assert_no_logs def test_linear_gradient(): red = (1, 0, 0, 1)