1
1
mirror of https://github.com/Kozea/WeasyPrint.git synced 2024-10-04 07:57:52 +03:00

Merge branch '53.x'

This commit is contained in:
Guillaume Ayoub 2021-10-13 22:16:07 +02:00
commit 482dc6bf1e
2 changed files with 27 additions and 8 deletions

View File

@ -40,6 +40,21 @@ def test_kerning_default():
assert span2.width == 1.5 * 16
@assert_no_logs
def test_ligatures_word_space():
# Kerning and ligatures are on for text with increased word spacing
# https://github.com/Kozea/WeasyPrint/issues/1469
page, = render_pages('''
<style>
@font-face { src: url(weasyprint.otf); font-family: weasyprint }
body { font-family: weasyprint; word-spacing: 1em; width: 10em }
</style>
aa liga aa''')
html, = page.children
body, = html.children
assert len(body.children) == 1
@assert_no_logs
def test_kerning_deactivate():
# Deactivate kerning

View File

@ -212,9 +212,7 @@ class Layout:
if letter_spacing == 'normal':
letter_spacing = 0
if text and (word_spacing != 0 or letter_spacing != 0):
letter_spacing = units_from_double(letter_spacing)
space_spacing = units_from_double(word_spacing) + letter_spacing
if self.text and (word_spacing or letter_spacing):
attr_list = pango.pango_layout_get_attributes(self.layout)
if not attr_list:
# TODO: list should be freed
@ -226,11 +224,17 @@ class Layout:
attr.start_index, attr.end_index = start, end
pango.pango_attr_list_change(attr_list, attr)
add_attr(0, len(bytestring), letter_spacing)
position = bytestring.find(b' ')
while position != -1:
add_attr(position, position + 1, space_spacing)
position = bytestring.find(b' ', position + 1)
if letter_spacing:
letter_spacing = units_from_double(letter_spacing)
add_attr(0, len(bytestring), letter_spacing)
if word_spacing:
space_spacing = (
units_from_double(word_spacing) + letter_spacing)
position = bytestring.find(b' ')
while position != -1:
add_attr(position, position + 1, space_spacing)
position = bytestring.find(b' ', position + 1)
pango.pango_layout_set_attributes(self.layout, attr_list)