From 08b1a57826fdcf1386b26b25cbb23b82b4a51be4 Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Sat, 27 Jul 2019 13:46:06 -0400 Subject: Fix some issues with hyphens We were inserting hyphens after spaces, and in some other places where they are not desirable. Fix this by looking at the characters on both sides of the break when deciding whether to insert a hyphen. --- pango/pango-layout.c | 55 +++++++++++++++++++++++++++++++++++----------------- 1 file changed, 37 insertions(+), 18 deletions(-) diff --git a/pango/pango-layout.c b/pango/pango-layout.c index 1cc1100c..53e39c1b 100644 --- a/pango/pango-layout.c +++ b/pango/pango-layout.c @@ -3424,40 +3424,59 @@ get_need_hyphen (PangoItem *item, { int i; const char *p; + gboolean prev_space; + gboolean prev_hyphen; for (i = 0, p = text + item->offset; i < item->num_chars; i++, p = g_utf8_next_char (p)) { gunichar wc = g_utf8_get_char (p); - switch (g_unichar_type(wc)) + gboolean space; + gboolean hyphen; + + switch (g_unichar_type (wc)) { case G_UNICODE_SPACE_SEPARATOR: case G_UNICODE_LINE_SEPARATOR: case G_UNICODE_PARAGRAPH_SEPARATOR: - need_hyphen[i] = FALSE; + space = TRUE; break; case G_UNICODE_CONTROL: if (wc == '\t' || wc == '\n' || wc == '\r' || wc == '\f') - need_hyphen[i] = FALSE; + space = TRUE; else - need_hyphen[i] = TRUE; + space = FALSE; break; default: - if (wc == '-' || /* Hyphen-minus */ - wc == 0x058a || /* Armenian hyphen */ - wc == 0x1400 || /* Canadian syllabics hyphen */ - wc == 0x1806 || /* Mongolian todo hyphen */ - wc == 0x2010 || /* Hyphen */ - wc == 0x2027 || /* Hyphenation point */ - wc == 0x2e17 || /* Double oblique hyphen */ - wc == 0x2e40 || /* Double hyphen */ - wc == 0x30a0 || /* Katakana-Hiragana double hyphen */ - wc == 0xfe63 || /* Small hyphen-minus */ - wc == 0xff0d) /* Fullwidth hyphen-minus */ - need_hyphen[i] = FALSE; - else - need_hyphen[i] = TRUE; + space = FALSE; break; } + + if (wc == '-' || /* Hyphen-minus */ + wc == 0x058a || /* Armenian hyphen */ + wc == 0x1400 || /* Canadian syllabics hyphen */ + wc == 0x1806 || /* Mongolian todo hyphen */ + wc == 0x2010 || /* Hyphen */ + wc == 0x2027 || /* Hyphenation point */ + wc == 0x2e17 || /* Double oblique hyphen */ + wc == 0x2e40 || /* Double hyphen */ + wc == 0x30a0 || /* Katakana-Hiragana double hyphen */ + wc == 0xfe63 || /* Small hyphen-minus */ + wc == 0xff0d) /* Fullwidth hyphen-minus */ + hyphen = TRUE; + else + hyphen = FALSE; + + if (i == 0) + need_hyphen[i] = FALSE; + else if (prev_space || space) + need_hyphen[i] = FALSE; + else if (prev_hyphen || hyphen) + need_hyphen[i] = FALSE; + else + need_hyphen[i] = TRUE; + + prev_space = space; + prev_hyphen = hyphen; } } -- cgit v1.2.1