diff options
author | Matthias Clasen <mclasen@redhat.com> | 2021-08-25 00:09:37 -0400 |
---|---|---|
committer | Matthias Clasen <mclasen@redhat.com> | 2021-08-25 00:40:17 -0400 |
commit | 2c9792d4b435e87e8616c22e1e5516d7302b06dc (patch) | |
tree | b695f35cb5977fea3f58950d2b1d9051d515c2d0 /pango/pango-layout.c | |
parent | dec273128a15821949011c66836db4f87c04a442 (diff) | |
download | pango-2c9792d4b435e87e8616c22e1e5516d7302b06dc.tar.gz |
Refine hyphenation
Replace ‧ and | with a - when we break there.
Update affected test output.
Fixes: #603
Diffstat (limited to 'pango/pango-layout.c')
-rw-r--r-- | pango/pango-layout.c | 50 |
1 files changed, 42 insertions, 8 deletions
diff --git a/pango/pango-layout.c b/pango/pango-layout.c index 4366450a..1ebe42cd 100644 --- a/pango/pango-layout.c +++ b/pango/pango-layout.c @@ -3601,7 +3601,8 @@ break_needs_hyphen (PangoLayout *layout, ParaBreakState *state, int pos) { - return layout->log_attrs[state->start_offset + pos].break_inserts_hyphen; + return layout->log_attrs[state->start_offset + pos].break_inserts_hyphen || + layout->log_attrs[state->start_offset + pos].break_removes_preceding; } static int @@ -3627,23 +3628,56 @@ find_hyphen_width (PangoItem *item) } static int +find_char_width (PangoItem *item, + gunichar wc) +{ + hb_font_t *hb_font; + hb_codepoint_t glyph; + + if (!item->analysis.font) + return 0; + + hb_font = pango_font_get_hb_font (item->analysis.font); + if (hb_font_get_nominal_glyph (hb_font, wc, &glyph)) + return hb_font_get_glyph_h_advance (hb_font, glyph); + + return 0; +} + +static inline void +ensure_hyphen_width (ParaBreakState *state) +{ + if (state->hyphen_width < 0) + { + PangoItem *item = state->items->data; + state->hyphen_width = find_hyphen_width (item); + } +} + +static int find_break_extra_width (PangoLayout *layout, ParaBreakState *state, int pos) { /* Check whether to insert a hyphen */ - if (break_needs_hyphen (layout, state, pos)) + if (layout->log_attrs[state->start_offset + pos].break_inserts_hyphen) { - if (state->hyphen_width < 0) + ensure_hyphen_width (state); + + if (layout->log_attrs[state->start_offset + pos].break_removes_preceding) { PangoItem *item = state->items->data; - state->hyphen_width = find_hyphen_width (item); - } + gunichar wc; - return state->hyphen_width; + wc = g_utf8_get_char (g_utf8_offset_to_pointer (layout->text, state->start_offset + pos - 1)); + + return state->hyphen_width - find_char_width (item, wc); + } + else + return state->hyphen_width; } - else - return 0; + + return 0; } #if 0 |