Skip to content

Commit abd54c4

Browse files
committed
Set SVG ratio when width and height are 0
1 parent eebb6e5 commit abd54c4

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

tests/draw/svg/test_shapes.py

+23
Original file line numberDiff line numberDiff line change
@@ -419,3 +419,26 @@ def test_rect_stroke_zero():
419419
stroke-width="0" stroke="red" fill="none" />
420420
</svg>
421421
''')
422+
423+
424+
@assert_no_logs
425+
def test_rect_width_height_zero():
426+
assert_pixels('rect_fill', 9, 9, '''
427+
_________
428+
_________
429+
_________
430+
_________
431+
_________
432+
_________
433+
_________
434+
_________
435+
_________
436+
''', '''
437+
<style>
438+
@page { size: 9px }
439+
svg { display: block }
440+
</style>
441+
<svg width="0" height="0" xmlns="http://www.w3.org/2000/svg">
442+
<rect x="2" y="2" width="5" height="5" fill="red" />
443+
</svg>
444+
''')

weasyprint/images.py

+2
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,8 @@ def get_intrinsic_size(self, image_resolution, font_size):
8181
ratio = None
8282
elif width and height:
8383
ratio = width / height
84+
else:
85+
ratio = 1
8486
return width, height, ratio
8587

8688
def draw(self, stream, concrete_width, concrete_height, image_rendering):

0 commit comments

Comments
 (0)