Skip to content

Commit

Permalink
Disable Pango hyphenation when we break words
Browse files Browse the repository at this point in the history
Related to #1520.
  • Loading branch information
liZe committed Dec 13, 2021
1 parent 6fb0269 commit e035142
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
1 change: 1 addition & 0 deletions weasyprint/text/ffi.py
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,7 @@
PangoAttrList *list, PangoAttribute *attr);
PangoAttribute * pango_attr_font_features_new (const gchar *features);
PangoAttribute * pango_attr_letter_spacing_new (int letter_spacing);
PangoAttribute * pango_attr_insert_hyphens_new (gboolean insert_hyphens);
void pango_attribute_destroy (PangoAttribute *attr);
PangoTabArray * pango_tab_array_new_with_positions (
Expand Down
11 changes: 10 additions & 1 deletion weasyprint/text/line_break.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,10 @@ def set_text(self, text, justify=False):
if letter_spacing == 'normal':
letter_spacing = 0

if self.text and (word_spacing or letter_spacing):
word_breaking = (
self.style['overflow_wrap'] in ('anywhere', 'break-word'))

if self.text and (word_spacing or letter_spacing or word_breaking):
attr_list = pango.pango_layout_get_attributes(self.layout)
if not attr_list:
# TODO: list should be freed
Expand All @@ -236,6 +239,12 @@ def add_attr(start, end, spacing):
add_attr(position, position + 1, space_spacing)
position = bytestring.find(b' ', position + 1)

if word_breaking:
# TODO: attributes should be freed
attr = pango.pango_attr_insert_hyphens_new(False)
attr.start_index, attr.end_index = 0, len(bytestring)
pango.pango_attr_list_change(attr_list, attr)

pango.pango_layout_set_attributes(self.layout, attr_list)

# Tabs width
Expand Down

0 comments on commit e035142

Please sign in to comment.