@@ -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):
263263def 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 ]))
@@ -679,7 +680,8 @@ def get_percentage_contribution(origin_cell, origin, max_content_width):
679680 sum (max_content_widths ), large_percentage_contribution ,
680681 * small_percentage_contributions ]))
681682
682- if table .style ['width' ] != 'auto' and table .style ['width' ].unit .lower () == 'px' :
683+ width = table .style ['width' ]
684+ if width != 'auto' and not check_math (width ) and width .unit .lower () == 'px' :
683685 # "percentages on the following properties are treated instead as
684686 # though they were the following: width: auto"
685687 # https://dbaron.org/css/intrinsic/#outer-intrinsic
@@ -714,12 +716,16 @@ def replaced_min_content_width(box, outer=True):
714716 width = box .style ['width' ]
715717 if width == 'auto' :
716718 height = box .style ['height' ]
717- if height == 'auto' or height .unit == '%' :
719+ if height == 'auto' or check_math ( height ) or height .unit == '%' :
718720 height = 'auto'
719721 else :
720722 assert height .unit .lower () == 'px'
721723 height = height .value
722- if box .style ['max_width' ] != 'auto' and box .style ['max_width' ].unit == '%' :
724+ unknown_max_width = (
725+ box .style ['max_width' ] != 'auto' and
726+ not check_math (box .style ['max_width' ]) and
727+ box .style ['max_width' ].unit == '%' )
728+ if unknown_max_width :
723729 # See https://drafts.csswg.org/css-sizing/#intrinsic-contribution
724730 width = 0
725731 else :
@@ -730,7 +736,7 @@ def replaced_min_content_width(box, outer=True):
730736 width , _ = default_image_sizing (
731737 intrinsic_width , intrinsic_height , intrinsic_ratio , 'auto' ,
732738 height , default_width = 0 , default_height = 0 )
733- elif box .style ['width' ].unit == '%' :
739+ elif check_math ( box . style [ 'width' ]) or box .style ['width' ].unit == '%' :
734740 # See https://drafts.csswg.org/css-sizing/#intrinsic-contribution
735741 width = 0
736742 else :
@@ -744,7 +750,7 @@ def replaced_max_content_width(box, outer=True):
744750 width = box .style ['width' ]
745751 if width == 'auto' :
746752 height = box .style ['height' ]
747- if height == 'auto' or height .unit == '%' :
753+ if height == 'auto' or check_math ( height ) or height .unit == '%' :
748754 height = 'auto'
749755 else :
750756 assert height .unit .lower () == 'px'
@@ -756,7 +762,7 @@ def replaced_max_content_width(box, outer=True):
756762 width , _ = default_image_sizing (
757763 intrinsic_width , intrinsic_height , intrinsic_ratio , 'auto' , height ,
758764 default_width = 300 , default_height = 150 )
759- elif box .style ['width' ].unit == '%' :
765+ elif check_math ( box . style [ 'width' ]) or box .style ['width' ].unit == '%' :
760766 # See https://drafts.csswg.org/css-sizing/#intrinsic-contribution
761767 width = 0
762768 else :
0 commit comments