Skip to content

Commit

Permalink
Don't crash with object-fit: non images with no intrinsic size
Browse files Browse the repository at this point in the history
  • Loading branch information
liZe committed Sep 10, 2019
1 parent c790ff2 commit d63eac3
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions weasyprint/layout/replaced.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,11 @@ def replacedbox_layout(box):
position = box.style['object_position']

image = box.replacement
iwidth, iheight = image.get_intrinsic_size(
intrinsic_width, intrinsic_height = image.get_intrinsic_size(
box.style['image_resolution'], box.style['font_size'])
if None in (intrinsic_width, intrinsic_height):
intrinsic_width, intrinsic_height = contain_constraint_image_sizing(
box.width, box.height, box.replacement.intrinsic_ratio)

if object_fit == 'fill':
draw_width, draw_height = box.width, box.height
Expand All @@ -105,11 +108,11 @@ def replacedbox_layout(box):
box.width, box.height, box.replacement.intrinsic_ratio)
else:
assert object_fit == 'none', object_fit
draw_width, draw_height = iwidth, iheight
draw_width, draw_height = intrinsic_width, intrinsic_height

if object_fit == 'scale-down':
draw_width = min(draw_width, iwidth)
draw_height = min(draw_height, iheight)
draw_width = min(draw_width, intrinsic_width)
draw_height = min(draw_height, intrinsic_height)

origin_x, position_x, origin_y, position_y = position[0]
ref_x = box.width - draw_width
Expand Down

0 comments on commit d63eac3

Please sign in to comment.