mirror of
https://github.com/Kozea/WeasyPrint.git
synced 2024-10-05 00:21:15 +03:00
Do not 'compute' most initial values.
This commit is contained in:
parent
47074ae6f4
commit
065a9a4f04
@ -40,6 +40,7 @@ function for each step:
|
||||
|
||||
"""
|
||||
|
||||
import re
|
||||
import logging
|
||||
|
||||
from lxml import cssselect
|
||||
@ -73,6 +74,11 @@ PAGE_PSEUDOCLASS_SPECIFICITY = {
|
||||
':first': 10,
|
||||
}
|
||||
|
||||
# A test function that returns True if the given property name has an
|
||||
# initial value that is not always the same when computed.
|
||||
RE_INITIAL_NOT_COMPUTED = re.compile(
|
||||
'^(display|border_[a-z]+_(width|color))$').match
|
||||
|
||||
|
||||
class StyleDict(object):
|
||||
"""A mapping (dict-like) that allows attribute access to values.
|
||||
@ -450,9 +456,10 @@ def computed_from_cascaded(element, cascaded, parent_style, pseudo_type=None):
|
||||
keyword = 'initial'
|
||||
|
||||
if keyword == 'initial':
|
||||
# Some initial values are the same when computed.
|
||||
# TODO: Add them to the ``computed`` dict?
|
||||
value = initial
|
||||
if not RE_INITIAL_NOT_COMPUTED(name):
|
||||
# The value is the same as when computed
|
||||
computed[name] = value
|
||||
elif keyword == 'inherit':
|
||||
value = parent_style[name]
|
||||
# Values in parent_style are already computed.
|
||||
|
@ -63,6 +63,7 @@ BORDER_WIDTH_KEYWORDS = {
|
||||
'medium': 3,
|
||||
'thick': 5,
|
||||
}
|
||||
assert INITIAL_VALUES['border_top_width'] == BORDER_WIDTH_KEYWORDS['medium']
|
||||
|
||||
# http://www.w3.org/TR/CSS21/fonts.html#propdef-font-weight
|
||||
FONT_WEIGHT_RELATIVE = dict(
|
||||
|
@ -45,10 +45,10 @@ INITIAL_VALUES = {
|
||||
'border_right_style': 'none',
|
||||
'border_bottom_style': 'none',
|
||||
'border_left_style': 'none',
|
||||
'border_top_width': 'medium',
|
||||
'border_right_width': 'medium',
|
||||
'border_bottom_width': 'medium',
|
||||
'border_left_width': 'medium',
|
||||
'border_top_width': 3, # Computed value for 'medium'
|
||||
'border_right_width': 3,
|
||||
'border_bottom_width': 3,
|
||||
'border_left_width': 3,
|
||||
'bottom': 'auto',
|
||||
'caption_side': 'top',
|
||||
'clear': 'none',
|
||||
|
@ -97,7 +97,7 @@ def test_expand_borders():
|
||||
'border_top_color': 'red',
|
||||
}
|
||||
assert expand_to_dict('border_top', 'solid') == {
|
||||
'border_top_width': 'medium',
|
||||
'border_top_width': 3,
|
||||
'border_top_style': 'solid',
|
||||
'border_top_color': 'currentColor',
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user