From 2e499aa93b70d14bae605b65755d7c49fa44a61b Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Sun, 14 Jul 2019 21:59:05 -0400 Subject: layout: Improve soft hyphen handling Point the item that we create for the inserted hyphen at the SHY in the paragraph text, shortening the previous run by one character. It would be nicer to not insert an extra run at all and just reshape the previous one in a way that maps the SHY to a hyphen, but that is more difficult to do as long as we are going through the shape engine API. --- pango/pango-layout.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/pango/pango-layout.c b/pango/pango-layout.c index 411eea5d..37aeed72 100644 --- a/pango/pango-layout.c +++ b/pango/pango-layout.c @@ -3432,8 +3432,12 @@ create_hyphen_run (PangoLayout *layout, run = g_slice_new (PangoGlyphItem); run->glyphs = pango_glyph_string_new (); run->item = items->data; - /* insert after item */ + + /* insert after item, use SHY as text */ run->item->offset = item->offset + item->length; + run->item->length = 2; + run->item->num_chars = 1; + g_list_free (items); pango_shape (hyphen_text, hyphen_len, &run->item->analysis, run->glyphs); @@ -3507,6 +3511,9 @@ insert_hyphen_after (PangoLayoutLine *line, PangoLayout *layout = line->layout; PangoLayoutRun *run; + /* Use the SHY as text for the hyphen run */ + item->num_chars -= 1; + item->length -= 2; run = create_hyphen_run (layout, item); line->runs = g_slist_prepend (line->runs, run); -- cgit v1.2.1