mirror of
https://github.com/Kozea/WeasyPrint.git
synced 2024-10-04 07:57:52 +03:00
Allow blink as a text-decoration value
It will only be ignored while drawing, but it doesn't harm to keep the value and makes code and tests more readable. Also use a set instead of a frozenset to store text-decoration-line, bringing more readability even if it may be a little, little, little bit slower.
This commit is contained in:
parent
f5373db74e
commit
ed2f4f384a
@ -354,8 +354,8 @@ def expand_text_decoration(base_url, name, tokens):
|
||||
|
||||
for token in tokens:
|
||||
keyword = get_keyword(token)
|
||||
if keyword in ('none', 'underline', 'overline', 'line-through',
|
||||
'blink'):
|
||||
if keyword in (
|
||||
'none', 'underline', 'overline', 'line-through', 'blink'):
|
||||
text_decoration_line.add(keyword)
|
||||
elif keyword in ('solid', 'double', 'dotted', 'dashed', 'wavy'):
|
||||
if text_decoration_style is not None:
|
||||
@ -377,8 +377,6 @@ def expand_text_decoration(base_url, name, tokens):
|
||||
text_decoration_line = 'none'
|
||||
elif not(text_decoration_line):
|
||||
text_decoration_line = 'none'
|
||||
else:
|
||||
text_decoration_line = frozenset(text_decoration_line - set(['blink']))
|
||||
|
||||
yield 'text_decoration_line', text_decoration_line
|
||||
yield 'text_decoration_color', text_decoration_color or 'currentColor'
|
||||
|
@ -980,17 +980,12 @@ def text_align(keyword):
|
||||
@property()
|
||||
def text_decoration_line(tokens):
|
||||
"""``text-decoration-line`` property validation."""
|
||||
keywords = [get_keyword(v) for v in tokens]
|
||||
if keywords == ['none']:
|
||||
keywords = {get_keyword(token) for token in tokens}
|
||||
if keywords == {'none'}:
|
||||
return 'none'
|
||||
if all(keyword in ('underline', 'overline', 'line-through', 'blink')
|
||||
for keyword in keywords):
|
||||
unique = set(keywords)
|
||||
if len(unique) == len(keywords):
|
||||
# No duplicate
|
||||
# blink is accepted but ignored
|
||||
# "Conforming user agents may simply not blink the text."
|
||||
return frozenset(unique - set(['blink']))
|
||||
allowed_values = {'underline', 'overline', 'line-through', 'blink'}
|
||||
if len(tokens) == len(keywords) and keywords.issubset(allowed_values):
|
||||
return keywords
|
||||
|
||||
|
||||
@property()
|
||||
|
@ -136,7 +136,7 @@ def test_annotate_document():
|
||||
assert li_0['margin_bottom'] == (16, 'px')
|
||||
assert li_0['margin_left'] == (32, 'px') # 4em
|
||||
|
||||
assert a['text_decoration_line'] == frozenset(['underline'])
|
||||
assert a['text_decoration_line'] == {'underline'}
|
||||
assert a['font_weight'] == 900
|
||||
assert a['font_size'] == 24 # 300% of 8px
|
||||
assert a['padding_top'] == (1, 'px')
|
||||
|
@ -132,10 +132,9 @@ def test_spacing_invalid(rule):
|
||||
@assert_no_logs
|
||||
@pytest.mark.parametrize('rule, result', (
|
||||
('text-decoration-line: none', {'text_decoration_line': 'none'}),
|
||||
('text-decoration-line: overline', {
|
||||
'text_decoration_line': frozenset(['overline'])}),
|
||||
('text-decoration-line: overline', {'text_decoration_line': {'overline'}}),
|
||||
('text-decoration-line: overline blink line-through', {
|
||||
'text_decoration_line': frozenset(['line-through', 'overline'])}),
|
||||
'text_decoration_line': {'blink', 'line-through', 'overline'}}),
|
||||
))
|
||||
def test_decoration_line(rule, result):
|
||||
assert expand_to_dict(rule) == result
|
||||
@ -163,10 +162,9 @@ TEXT_DECORATION_DEFAULT = {
|
||||
@assert_no_logs
|
||||
@pytest.mark.parametrize('rule, result', (
|
||||
('text-decoration: none', {'text_decoration_line': 'none'}),
|
||||
('text-decoration: overline', {
|
||||
'text_decoration_line': frozenset(['overline'])}),
|
||||
('text-decoration: overline', {'text_decoration_line': {'overline'}}),
|
||||
('text-decoration: overline blink line-through', {
|
||||
'text_decoration_line': frozenset(['line-through', 'overline'])}),
|
||||
'text_decoration_line': {'blink', 'line-through', 'overline'}}),
|
||||
('text-decoration: red', {'text_decoration_color': (1, 0, 0, 1)}),
|
||||
))
|
||||
def test_decoration(rule, result):
|
||||
|
Loading…
Reference in New Issue
Block a user