1
1
mirror of https://github.com/Kozea/WeasyPrint.git synced 2024-10-05 08:27:22 +03:00

Allow updated values in style_for

This commit is contained in:
Guillaume Ayoub 2017-08-01 09:53:30 +02:00
parent 6ed7e59aa9
commit 7d0add7b91
2 changed files with 20 additions and 14 deletions

View File

@ -858,23 +858,29 @@ def get_all_computed_styles(html, user_stylesheets=None,
base_url=html.base_url)
# This is mostly useful to make pseudo_type optional.
def style_for(element, pseudo_type=None, __get=computed_styles.get):
def style_for(element, pseudo_type=None, update=None,
__get=computed_styles.get):
"""
Convenience function to get the computed styles for an element.
"""
style = __get((element, pseudo_type))
if style and 'table' in style['display']:
if (style['display'] in ('table', 'inline-table') and
style['border_collapse'] == 'collapse'):
# Padding do not apply
for side in ['top', 'bottom', 'left', 'right']:
style['padding_' + side] = computed_values.ZERO_PIXELS
if (style['display'].startswith('table-') and
style['display'] != 'table-caption'):
# Margins do not apply
for side in ['top', 'bottom', 'left', 'right']:
style['margin_' + side] = computed_values.ZERO_PIXELS
if style:
if 'table' in style['display']:
if (style['display'] in ('table', 'inline-table') and
style['border_collapse'] == 'collapse'):
# Padding do not apply
for side in ['top', 'bottom', 'left', 'right']:
style['padding_' + side] = computed_values.ZERO_PIXELS
if (style['display'].startswith('table-') and
style['display'] != 'table-caption'):
# Margins do not apply
for side in ['top', 'bottom', 'left', 'right']:
style['margin_' + side] = computed_values.ZERO_PIXELS
if update:
style.update(update)
elif update:
style = dict(update)
return style and StyleDict(style)

View File

@ -482,8 +482,8 @@ def make_page(context, root_box, page_type, resume_at, content_empty,
"""
# Overflow value propagated from the root or <body>.
style = context.style_for(page_type).copy(
{'overflow': root_box.viewport_overflow})
style = context.style_for(page_type, update={
'overflow': root_box.viewport_overflow})
page = boxes.PageBox(page_type, style)
device_size = page.style.size