From 981045d6618c20e076390def227532de091f9b7b Mon Sep 17 00:00:00 2001 From: Guillaume Ayoub Date: Fri, 16 Feb 2018 00:54:34 +0100 Subject: [PATCH] Split replaced_min_content_width and replaced_max_content_width Fix #576. --- weasyprint/layout/preferred.py | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/weasyprint/layout/preferred.py b/weasyprint/layout/preferred.py index 4af6b6a3..eb11cca9 100644 --- a/weasyprint/layout/preferred.py +++ b/weasyprint/layout/preferred.py @@ -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