Skip to content

Commit

Permalink
Set SVG ratio when width and height are 0
Browse files Browse the repository at this point in the history
  • Loading branch information
grewn0uille committed Oct 28, 2021
1 parent eebb6e5 commit abd54c4
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
23 changes: 23 additions & 0 deletions tests/draw/svg/test_shapes.py
Original file line number Diff line number Diff line change
Expand Up @@ -419,3 +419,26 @@ def test_rect_stroke_zero():
stroke-width="0" stroke="red" fill="none" />
</svg>
''')


@assert_no_logs
def test_rect_width_height_zero():
assert_pixels('rect_fill', 9, 9, '''
_________
_________
_________
_________
_________
_________
_________
_________
_________
''', '''
<style>
@page { size: 9px }
svg { display: block }
</style>
<svg width="0" height="0" xmlns="http://www.w3.org/2000/svg">
<rect x="2" y="2" width="5" height="5" fill="red" />
</svg>
''')
2 changes: 2 additions & 0 deletions weasyprint/images.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ def get_intrinsic_size(self, image_resolution, font_size):
ratio = None
elif width and height:
ratio = width / height
else:
ratio = 1
return width, height, ratio

def draw(self, stream, concrete_width, concrete_height, image_rendering):
Expand Down

0 comments on commit abd54c4

Please sign in to comment.