mirror of
https://github.com/Kozea/WeasyPrint.git
synced 2024-10-05 08:27:22 +03:00
Refuse too many "normal" values in font expander
This commit is contained in:
parent
8b2b25f702
commit
d24211d82a
@ -456,14 +456,13 @@ def expand_font(name, tokens):
|
||||
|
||||
# Make `tokens` a stack
|
||||
tokens = list(reversed(tokens))
|
||||
# Values for font-style font-variant and font-weight can come in any
|
||||
# order and are all optional.
|
||||
while tokens:
|
||||
# Values for font-style, font-variant-caps, font-weight and font-stretch
|
||||
# can come in any order and are all optional.
|
||||
for _ in range(4):
|
||||
token = tokens.pop()
|
||||
if get_keyword(token) == 'normal':
|
||||
# Just ignore 'normal' keywords. Unspecified properties will get
|
||||
# their initial token, which is 'normal' for all three here.
|
||||
# TODO: fail if there is too many 'normal' values?
|
||||
# their initial token, which is 'normal' for all four here.
|
||||
continue
|
||||
|
||||
if font_style([token]) is not None:
|
||||
@ -475,10 +474,15 @@ def expand_font(name, tokens):
|
||||
elif font_stretch([token]) is not None:
|
||||
suffix = '-stretch'
|
||||
else:
|
||||
# We’re done with these three, continue with font-size
|
||||
# We’re done with these four, continue with font-size
|
||||
break
|
||||
yield suffix, [token]
|
||||
|
||||
if not tokens:
|
||||
raise InvalidValues
|
||||
else:
|
||||
token = tokens.pop()
|
||||
|
||||
# Then font-size is mandatory
|
||||
# Latest `token` from the loop.
|
||||
if font_size([token]) is None:
|
||||
|
@ -572,7 +572,6 @@ def test_font():
|
||||
assert expand_to_dict(
|
||||
'font: small-caps condensed normal 700 large serif'
|
||||
) == {
|
||||
# 'font_style': 'normal', XXX shouldn’t this be here?
|
||||
'font_stretch': 'condensed',
|
||||
'font_variant_caps': 'small-caps',
|
||||
'font_weight': 700,
|
||||
@ -587,6 +586,10 @@ def test_font():
|
||||
assert_invalid('font: 12px')
|
||||
assert_invalid('font: 12px/foo serif')
|
||||
assert_invalid('font: 12px "Invalid" family')
|
||||
assert_invalid('font: normal normal normal normal normal large serif')
|
||||
assert_invalid('font: normal small-caps italic 700 condensed large serif')
|
||||
assert_invalid('font: small-caps italic 700 normal condensed large serif')
|
||||
assert_invalid('font: small-caps italic 700 condensed normal large serif')
|
||||
|
||||
|
||||
@assert_no_logs
|
||||
|
Loading…
Reference in New Issue
Block a user