diff --git a/weasyprint/layout/percent.py b/weasyprint/layout/percent.py index f60e50a1..c2f405f0 100644 --- a/weasyprint/layout/percent.py +++ b/weasyprint/layout/percent.py @@ -96,9 +96,9 @@ def resolve_percentages(box, containing_block, main_flex_direction=None): # Used value == computed value for side in ('top', 'right', 'bottom', 'left'): prop = f'border_{side}_width' - if collapse and f'collapse_{prop}' in box.style: - setattr(box, prop, box.style[f'collapse_{prop}']) - else: + # border-{side}-width would have been resolved + # during border conflict resolution for collapsed-borders + if not (collapse and hasattr(box, prop)): setattr(box, prop, box.style[prop]) # Shrink *content* widths and heights according to box-sizing diff --git a/weasyprint/layout/preferred.py b/weasyprint/layout/preferred.py index 34ca1f7a..58d1a76f 100644 --- a/weasyprint/layout/preferred.py +++ b/weasyprint/layout/preferred.py @@ -149,13 +149,13 @@ def margin_width(box, width, left=True, right=True): collapse = box.style['border_collapse'] == 'collapse' if left: - if collapse and 'collapse_border_left_width' in box.style: - width += box.style['collapse_border_left_width'] + if collapse and hasattr(box, 'border_left_width'): + width += box.border_left_width else: width += box.style['border_left_width'] if right: - if collapse and 'collapse_border_right_width' in box.style: - width += box.style['collapse_border_right_width'] + if collapse and hasattr(box, 'border_right_width'): + width += box.border_right_width else: width += box.style['border_right_width'] diff --git a/weasyprint/layout/table.py b/weasyprint/layout/table.py index 7e25a730..abadbf90 100644 --- a/weasyprint/layout/table.py +++ b/weasyprint/layout/table.py @@ -1080,7 +1080,8 @@ def collapse_table_borders(table): # the correct widths on each box. The actual border grid will be # painted separately. def set_transparent_border(box, side, twice_width): - box.style[f'collapse_border_{side}_width'] = twice_width / 2 + prop = f'border_{side}_width' + setattr(box, prop, twice_width / 2) def remove_borders(box): set_transparent_border(box, 'top', 0)