diff --git a/weasyprint/text/ffi.py b/weasyprint/text/ffi.py index 864fb5510f..4730897bf9 100644 --- a/weasyprint/text/ffi.py +++ b/weasyprint/text/ffi.py @@ -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 ( diff --git a/weasyprint/text/line_break.py b/weasyprint/text/line_break.py index 2ea5d622d3..d5ff3877a5 100644 --- a/weasyprint/text/line_break.py +++ b/weasyprint/text/line_break.py @@ -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 @@ -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