Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Shrink min-max-height and -width according to box-sizing #823

Merged
merged 1 commit into from
Mar 14, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 29 additions & 10 deletions weasyprint/layout/percentages.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,20 +106,39 @@ def resolve_percentages(box, containing_block, main_flex_direction=None):
prop = 'border_{0}_width'.format(side)
setattr(box, prop, box.style[prop])

# Shrink *content* widths and heights according to box-sizing
# Thanks heavens and the spec: Our validator rejects negative values
# for padding and border-width
if box.style['box_sizing'] == 'border-box':
if box.width != 'auto':
box.width -= (box.padding_left + box.padding_right +
box.border_left_width + box.border_right_width)
if box.height != 'auto':
box.height -= (box.padding_top + box.padding_bottom +
box.border_top_width + box.border_bottom_width)
deltahorz = (box.padding_left + box.padding_right +
box.border_left_width + box.border_right_width)
deltavert = (box.padding_top + box.padding_bottom +
box.border_top_width + box.border_bottom_width)
elif box.style['box_sizing'] == 'padding-box':
if box.width != 'auto':
box.width -= box.padding_left + box.padding_right
if box.height != 'auto':
box.height -= box.padding_top + box.padding_bottom
deltahorz = box.padding_left + box.padding_right
deltavert = box.padding_top + box.padding_bottom
else:
assert box.style['box_sizing'] == 'content-box'
deltahorz = 0
deltavert = 0

# Keep at least min_* >= 0 to prevent funny output in case box.width or
# box.height become negative.
# Restricting max_* seems reasonable, too.
if deltahorz > 0:
if box.width != 'auto':
box.width -= deltahorz
if box.max_width != float('inf'):
box.max_width = max(0, box.max_width-deltahorz)
if box.min_width != 'auto':
box.min_width = max(0, box.min_width-deltahorz)
if deltavert > 0:
if box.height != 'auto':
box.height -= deltavert
if box.max_height != float('inf'):
box.max_height = max(0, box.max_height-deltahorz)
if box.min_height != 'auto':
box.min_height = max(0, box.min_height-deltahorz)


def resolve_radii_percentages(box):
Expand Down