From 7024f63ac5fc2f322f69bd23cf83aab294335899 Mon Sep 17 00:00:00 2001 From: Guillaume Ayoub Date: Tue, 18 Feb 2025 22:10:41 +0100 Subject: [PATCH] Remove workaround for flex percentages --- weasyprint/layout/flex.py | 6 +----- weasyprint/layout/percent.py | 23 +++++++++-------------- 2 files changed, 10 insertions(+), 19 deletions(-) diff --git a/weasyprint/layout/flex.py b/weasyprint/layout/flex.py index 571299fde..5b0b9d15f 100644 --- a/weasyprint/layout/flex.py +++ b/weasyprint/layout/flex.py @@ -148,15 +148,11 @@ def flex_layout(context, box, bottom_space, skip_stack, containing_block, page_i context.running_elements[running_name][page].append(child) continue # See https://www.w3.org/TR/css-flexbox-1/#min-size-auto. - if child.style['overflow'] == 'visible': - main_flex_direction = main - else: - main_flex_direction = None if main == 'width': child_containing_block = (available_main_space, parent_box.height) else: child_containing_block = (parent_box.width, available_main_space) - percent.resolve_percentages(child, child_containing_block, main_flex_direction) + percent.resolve_percentages(child, child_containing_block) if child.is_table_wrapper: table_wrapper_width(context, child, child_containing_block) child.position_x = position_x diff --git a/weasyprint/layout/percent.py b/weasyprint/layout/percent.py index 95a91616c..e3b35858d 100644 --- a/weasyprint/layout/percent.py +++ b/weasyprint/layout/percent.py @@ -21,8 +21,7 @@ def percentage(value, refer_to): return refer_to * value.value / 100 -def resolve_one_percentage(box, property_name, refer_to, - main_flex_direction=None): +def resolve_one_percentage(box, property_name, refer_to): """Set a used length value from a computed length value. ``refer_to`` is the length for 100%. If ``refer_to`` is not a number, it @@ -35,9 +34,7 @@ def resolve_one_percentage(box, property_name, refer_to, percent = percentage(value, refer_to) setattr(box, property_name, percent) if property_name in ('min_width', 'min_height') and percent == 'auto': - if (main_flex_direction is None or - property_name != (f'min_{main_flex_direction}')): - setattr(box, property_name, 0) + setattr(box, property_name, 0) def resolve_position_percentages(box, containing_block): @@ -48,7 +45,7 @@ def resolve_position_percentages(box, containing_block): resolve_one_percentage(box, 'bottom', cb_height) -def resolve_percentages(box, containing_block, main_flex_direction=None): +def resolve_percentages(box, containing_block): """Set used values as attributes of the box object.""" if isinstance(containing_block, boxes.Box): # cb is short for containing block @@ -69,8 +66,8 @@ def resolve_percentages(box, containing_block, main_flex_direction=None): resolve_one_percentage(box, 'padding_top', maybe_height) resolve_one_percentage(box, 'padding_bottom', maybe_height) resolve_one_percentage(box, 'width', cb_width) - resolve_one_percentage(box, 'min_width', cb_width, main_flex_direction) - resolve_one_percentage(box, 'max_width', cb_width, main_flex_direction) + resolve_one_percentage(box, 'min_width', cb_width) + resolve_one_percentage(box, 'max_width', cb_width) # XXX later: top, bottom, left and right on positioned elements @@ -83,14 +80,12 @@ def resolve_percentages(box, containing_block, main_flex_direction=None): else: assert height.unit == 'px' box.height = height.value - resolve_one_percentage(box, 'min_height', 0, main_flex_direction) - resolve_one_percentage(box, 'max_height', inf, main_flex_direction) + resolve_one_percentage(box, 'min_height', 0) + resolve_one_percentage(box, 'max_height', inf) else: resolve_one_percentage(box, 'height', cb_height) - resolve_one_percentage( - box, 'min_height', cb_height, main_flex_direction) - resolve_one_percentage( - box, 'max_height', cb_height, main_flex_direction) + resolve_one_percentage(box, 'min_height', cb_height) + resolve_one_percentage(box, 'max_height', cb_height) collapse = box.style['border_collapse'] == 'collapse' # Used value == computed value