From 829f28371c4c4926965a5dbaec256f7e76e415f8 Mon Sep 17 00:00:00 2001 From: Roozbeh Pournader Date: Wed, 15 Mar 2017 14:13:58 -0700 Subject: [PATCH] Fallback from script-specific hyphens to normal hyphen first The previous code fell back directly from a script-specific hyphen to the ASCII hyphen-minus if the font didn't support the script-specific hyphen. Now we try the Unicode hyphen (U+2010) first before trying the ASCII hyphen-minus. Bug: 36201363 Test: Not needed Change-Id: I374234fd73fab7edd990ea86f8937c38761c90bf --- libs/minikin/Layout.cpp | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/libs/minikin/Layout.cpp b/libs/minikin/Layout.cpp index 4032d4c9432..0a318bdccd7 100644 --- a/libs/minikin/Layout.cpp +++ b/libs/minikin/Layout.cpp @@ -736,12 +736,22 @@ static void addFeatures(const string &str, vector* features) { } } +static const hb_codepoint_t CHAR_HYPHEN = 0x2010; /* HYPHEN */ + static inline hb_codepoint_t determineHyphenChar(hb_codepoint_t preferredHyphen, hb_font_t* font) { - if (preferredHyphen == 0x2010 /* HYPHEN */ - || preferredHyphen == 0x058A /* ARMENIAN_HYPHEN */ + hb_codepoint_t glyph; + if (preferredHyphen == 0x058A /* ARMENIAN_HYPHEN */ || preferredHyphen == 0x05BE /* HEBREW PUNCTUATION MAQAF */ || preferredHyphen == 0x1400 /* CANADIAN SYLLABIC HYPHEN */) { - hb_codepoint_t glyph; + if (hb_font_get_nominal_glyph(font, preferredHyphen, &glyph)) { + return preferredHyphen; + } else { + // The original hyphen requested was not supported. Let's try and see if the + // Unicode hyphen is supported. + preferredHyphen = CHAR_HYPHEN; + } + } + if (preferredHyphen == CHAR_HYPHEN) { /* HYPHEN */ // Fallback to ASCII HYPHEN-MINUS if the font didn't have a glyph for the preferred hyphen. // Note that we intentionally don't do anything special if the font doesn't have a // HYPHEN-MINUS either, so a tofu could be shown, hinting towards something missing.