mirror of
https://github.com/Kozea/WeasyPrint.git
synced 2024-09-11 20:47:56 +03:00
Clean code style
Mainly keep the 79-character limit and add spaces around operators.
This commit is contained in:
parent
cf815043b9
commit
8c7dbb1176
@ -71,7 +71,8 @@ def text(svg, node, font_size):
|
||||
# Get textLength and lengthAdjust, if specified
|
||||
text_length = 0
|
||||
if 'textLength' in node.attrib:
|
||||
text_length = size(normalize(node.attrib['textLength']), font_size, svg.inner_width)
|
||||
text_length = size(
|
||||
normalize(node.attrib['textLength']), font_size, svg.inner_width)
|
||||
length_adjust = node.attrib.get('lengthAdjust')
|
||||
# any invalid lengthAdjust value reverts to the default 'spacing'
|
||||
if length_adjust not in ['spacing', 'spacingAndGlyphs']:
|
||||
@ -83,15 +84,16 @@ def text(svg, node, font_size):
|
||||
# calculate the number of spaces to be considered for the text
|
||||
# only deduct 0.5 and not 1 since the last letter has a half-space
|
||||
# towards the end of the text element
|
||||
spaces_count = (len(node.text) - 0.5)
|
||||
spaces_count = len(node.text) - 0.5
|
||||
# only adjust letter spacing to fit textLength if:
|
||||
# - lengthAdjust is set to 'spacing'
|
||||
# - text is longer than 1 glyph
|
||||
if length_adjust == 'spacing' and len(node.text) > 1:
|
||||
# browsers interpret letter-spacing as a negative offset when textLength is set,
|
||||
# so doing the same here
|
||||
# browsers interpret letter-spacing as a negative offset when
|
||||
# textLength is set, so doing the same here
|
||||
# TODO: check if that behaviour is according to specs
|
||||
letter_spacing = round((text_length - width - letter_spacing) / spaces_count)
|
||||
letter_spacing = round(
|
||||
(text_length - width - letter_spacing) / spaces_count)
|
||||
if length_adjust == 'spacingAndGlyphs':
|
||||
# scale letter_spacing up/down to textLength
|
||||
width_with_spacing = width + spaces_count * letter_spacing
|
||||
@ -100,7 +102,7 @@ def text(svg, node, font_size):
|
||||
# - deducting the scaled letter_spacing from textLength
|
||||
# - dividing the calculated value by the original width
|
||||
spaceless_text_length = text_length - spaces_count * letter_spacing
|
||||
scale_x = spaceless_text_length/width
|
||||
scale_x = spaceless_text_length / width
|
||||
|
||||
# Align text box horizontally
|
||||
x_align = 0
|
||||
|
Loading…
Reference in New Issue
Block a user