diff --git a/weasyprint/css/__init__.py b/weasyprint/css/__init__.py index 0bcc4ff8..13677375 100644 --- a/weasyprint/css/__init__.py +++ b/weasyprint/css/__init__.py @@ -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) diff --git a/weasyprint/layout/pages.py b/weasyprint/layout/pages.py index 972c1da1..aa732f72 100644 --- a/weasyprint/layout/pages.py +++ b/weasyprint/layout/pages.py @@ -482,8 +482,8 @@ def make_page(context, root_box, page_type, resume_at, content_empty, """ # Overflow value propagated from the root or . - 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