Skip to content

Commit e752cb3

Browse files
committed
Allow calc for more properties
1 parent 66928ce commit e752cb3

File tree

2 files changed

+51
-17
lines changed

2 files changed

+51
-17
lines changed

tests/css/test_math.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -340,3 +340,36 @@ def test_math_image_min_content_auto_width_height_calc():
340340
min-width: calc(10% + 1em);
341341
">
342342
''')
343+
344+
345+
@assert_no_logs
346+
def test_math_table_margin():
347+
render_pages('<table style="margin: calc(1em + 10%)">')
348+
349+
350+
@assert_no_logs
351+
def test_math_grid_padding():
352+
render_pages('''
353+
<article style="display: grid">
354+
<div style="box-sizing: border-box; border: 1px solid;
355+
padding: calc(2px + 10%); width: 7px">a</div>
356+
</article>
357+
''')
358+
359+
360+
@assert_no_logs
361+
def test_math_table_column():
362+
render_pages('''
363+
<table style="width: 200px">
364+
<colgroup style="width: calc(1em + 10%)">
365+
<col />
366+
</colgroup>
367+
<col style="width: calc(1em + 10%)" />
368+
<tbody>
369+
<tr>
370+
<td>a</td>
371+
<td>a</td>
372+
</tr>
373+
</tbody>
374+
</table>
375+
''')

weasyprint/layout/preferred.py

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ def _block_content_width(context, box, function, outer):
109109

110110
for value in ('padding_left', 'padding_right'):
111111
style_value = box.style[value]
112-
if style_value != 'auto':
112+
if style_value != 'auto' and not check_math(style_value):
113113
if style_value.unit.lower() == 'px':
114114
width -= style_value.value
115115
else:
@@ -175,7 +175,7 @@ def margin_width(box, width, left=True, right=True):
175175
(['margin_right', 'padding_right'] if right else [])
176176
):
177177
style_value = box.style[value]
178-
if style_value != 'auto':
178+
if style_value != 'auto' and not check_math(style_value):
179179
if style_value.unit.lower() == 'px':
180180
width += style_value.value
181181
else:
@@ -263,7 +263,7 @@ def inline_max_content_width(context, box, outer=True, is_line_start=False):
263263
def column_group_content_width(context, box):
264264
"""Return the *-content width for a ``TableColumnGroupBox``."""
265265
width = box.style['width']
266-
if width == 'auto' or width.unit == '%':
266+
if width == 'auto' or check_math(width) or width.unit == '%':
267267
width = 0
268268
else:
269269
assert width.unit.lower() == 'px'
@@ -597,21 +597,22 @@ def get_percentage_contribution(origin_cell, origin, max_content_width):
597597
# Define constrainedness
598598
constrainedness = [False for i in range(grid_width)]
599599
for i in range(grid_width):
600-
if (column_groups[i] and column_groups[i].style['width'] != 'auto' and
601-
column_groups[i].style['width'].unit != '%'):
602-
constrainedness[i] = True
603-
continue
604-
if (columns[i] and columns[i].style['width'] != 'auto' and
605-
columns[i].style['width'].unit != '%'):
606-
constrainedness[i] = True
607-
continue
608-
for cell in zipped_grid[i]:
609-
if (cell and cell.colspan == 1 and
610-
cell.style['width'] != 'auto' and
611-
not check_math(cell.style['width']) and
612-
cell.style['width'].unit != '%'):
600+
if column_groups[i]:
601+
width = column_groups[i].style['width']
602+
if width != 'auto' and not check_math(width) and width.unit != '%':
613603
constrainedness[i] = True
614-
break
604+
continue
605+
if columns[i]:
606+
width = columns[i].style['width']
607+
if width != 'auto' and not check_math(width) and width.unit != '%':
608+
constrainedness[i] = True
609+
continue
610+
for cell in zipped_grid[i]:
611+
if cell and cell.colspan == 1:
612+
width = cell.style['width']
613+
if width != 'auto' and not check_math(width) and width.unit != '%':
614+
constrainedness[i] = True
615+
break
615616

616617
intrinsic_percentages = [
617618
min(percentage, 100 - sum(intrinsic_percentages[:i]))

0 commit comments

Comments
 (0)