Skip to content

Commit f66df06

Browse files
committed
Don't crash when using ex units in word-spacing in letter-spacing
1 parent fb0887c commit f66df06

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

weasyprint/text.py

+6-2
Original file line numberDiff line numberDiff line change
@@ -748,14 +748,18 @@ def set_text(self, text, justify=False):
748748
self.text = bytestring.decode('utf-8')
749749
pango.pango_layout_set_text(self.layout, text, -1)
750750

751-
word_spacing = self.style['word_spacing']
751+
# Word spacing may not be set if we're trying to get word-spacing
752+
# computed value using a layout, for example if its unit is ex.
753+
word_spacing = self.style.get('word_spacing', 0)
752754
if justify:
753755
# Justification is needed when drawing text but is useless during
754756
# layout. Ignore it before layout is reactivated before the drawing
755757
# step.
756758
word_spacing += self.justification_spacing
757759

758-
letter_spacing = self.style['letter_spacing']
760+
# Letter spacing may not be set if we're trying to get letter-spacing
761+
# computed value using a layout, for example if its unit is ex.
762+
letter_spacing = self.style.get('letter_spacing', 'normal')
759763
if letter_spacing == 'normal':
760764
letter_spacing = 0
761765

0 commit comments

Comments
 (0)