Skip to content

Commit

Permalink
Revert "Change table and table-* elements' style before creating Styl…
Browse files Browse the repository at this point in the history
…eDicts"

This reverts commit ca8bc3e.

The main change is the creation of StyleDicts removed from style_for, for
memory consumption problems.
  • Loading branch information
liZe committed Aug 2, 2017
1 parent c779977 commit 84bdee1
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 19 deletions.
26 changes: 11 additions & 15 deletions weasyprint/css/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,10 @@ class StyleDict(dict):

# TODO: this dict should be frozen, but modification is currently
# authorized for some corner cases when building the structure:
# - table wrapping,
# - border modification for tables with collapsing borders, and
# - viewport overflow.
# - wrapping tables,
# - removing paddings and margins from tables,
# - modifying borders for table cells with collapsing borders, and
# - setting viewports and pages overflow.

# TODO: We should remove that. Some attributes (eg. "clear") exist as
# dict methods and can only be accessed with getitem.
Expand All @@ -97,10 +98,10 @@ def inherit_from(self):
"""
if '_inherited_style' not in self.__dict__:
self._inherited_style = type(self)(computed_from_cascaded(
self._inherited_style = computed_from_cascaded(
cascaded={}, parent_style=self,
# Only by non-inherited properties, eg `content: attr(href)`
element=None))
element=None)
self._inherited_style.anonymous = True
return self._inherited_style

Expand Down Expand Up @@ -535,7 +536,7 @@ def computed_from_cascaded(element, cascaded, parent_style, pseudo_type=None,
for side in ('top', 'bottom', 'left', 'right'):
computed['border_%s_width' % side] = 0
computed['outline_width'] = 0
return computed
return StyleDict(computed)

# Handle inheritance and initial values
specified = {}
Expand Down Expand Up @@ -566,9 +567,9 @@ def computed_from_cascaded(element, cascaded, parent_style, pseudo_type=None,

specified[name] = value

return computed_values.compute(
return StyleDict(computed_values.compute(
element, pseudo_type, specified, computed, parent_style, root_style,
base_url)
base_url))


def preprocess_stylesheet(device_media_type, base_url, stylesheet_rules,
Expand Down Expand Up @@ -846,8 +847,7 @@ 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, update=None,
__get=computed_styles.get):
def style_for(element, pseudo_type=None, __get=computed_styles.get):
"""
Convenience function to get the computed styles for an element.
"""
Expand All @@ -865,11 +865,7 @@ def style_for(element, pseudo_type=None, update=None,
# 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)
return style

return style_for
4 changes: 2 additions & 2 deletions weasyprint/formatting_structure/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ def build_formatting_structure(element_tree, style_for, get_image_from_uri,
box, = box_list
else:
# No root element
def root_style_for(element, pseudo_type=None, update=None):
style = style_for(element, pseudo_type, update)
def root_style_for(element, pseudo_type=None):
style = style_for(element, pseudo_type)
if style:
if element.parent is None:
style.display = 'block'
Expand Down
4 changes: 2 additions & 2 deletions weasyprint/layout/pages.py
Original file line number Diff line number Diff line change
Expand Up @@ -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, update={
'overflow': root_box.viewport_overflow})
style = context.style_for(page_type)
style['overflow'] = root_box.viewport_overflow
page = boxes.PageBox(page_type, style)

device_size = page.style.size
Expand Down

0 comments on commit 84bdee1

Please sign in to comment.