Split replaced_min_content_width and replaced_max_content_width

Fix #576.
This commit is contained in:
Guillaume Ayoub 2018-02-16 00:54:34 +01:00
parent 1b62ca5db8
commit 981045d661
1 changed files with 23 additions and 1 deletions

View File

@ -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__)
@ -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