Skip to content

Commit

Permalink
Split replaced_min_content_width and replaced_max_content_width
Browse files Browse the repository at this point in the history
Fix #576.
  • Loading branch information
liZe committed Feb 15, 2018
1 parent 1b62ca5 commit 981045d
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion weasyprint/layout/preferred.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ def max_content_width(context, box, outer=True):
return inline_max_content_width(
context, box, outer, is_line_start=True)
elif isinstance(box, boxes.ReplacedBox):
return replaced_min_content_width(box, outer)
return replaced_max_content_width(box, outer)
else:
raise TypeError(
'max-content width for %s not handled yet' % type(box).__name__)
Expand Down Expand Up @@ -624,6 +624,28 @@ def replaced_min_content_width(box, outer=True):
return adjust(box, outer, width)


def replaced_max_content_width(box, outer=True):
"""Return the max-content width for an ``InlineReplacedBox``."""
width = box.style['width']
if width == 'auto':
height = box.style['height']
if height == 'auto' or height.unit == '%':
height = 'auto'
else:
assert height.unit == 'px'
height = height.value
image = box.replacement
iwidth, iheight = image.get_intrinsic_size(
box.style['image_resolution'], box.style['font_size'])
width, _ = default_image_sizing(
iwidth, iheight, image.intrinsic_ratio, 'auto', height,
default_width=300, default_height=150)
else:
assert width.unit == 'px'
width = width.value
return adjust(box, outer, width)


def trailing_whitespace_size(context, box):
"""Return the size of the trailing whitespace of ``box``."""
from .inlines import split_text_box, split_first_line
Expand Down

0 comments on commit 981045d

Please sign in to comment.