From 2be7eeef688e8e5546aae9540683e37fa994927f Mon Sep 17 00:00:00 2001 From: Raph Levien Date: Wed, 29 Jul 2015 13:03:50 -0700 Subject: [PATCH] Improve fallback where explicit variant is not given In computing scores for which fallback font to choose, a match of a variant given explicitly in the xml config file scores higher than a family with no explicit variant. One consequence is that U+2010 HYPHEN is chosen from the Naskh Arabic font in the fallback case. This patch scores families with no variants as a match (effectively the same as if the xml file specified both variants). Thus, it will choose the first matching font (Roboto), which is a better choice. This patch also revises the list of "sticky" characters to include various hyphens, so Arabic (and potentially other scripts) text that includes hyphens can access the script-specific variants matched to the underlying text. Bug: 22824219 Change-Id: I6ec1043037f89cad50ca99ac24c473395546bcdf --- engine/src/flutter/libs/minikin/FontCollection.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/engine/src/flutter/libs/minikin/FontCollection.cpp b/engine/src/flutter/libs/minikin/FontCollection.cpp index e3911c5bd3..b4bfe313ba 100644 --- a/engine/src/flutter/libs/minikin/FontCollection.cpp +++ b/engine/src/flutter/libs/minikin/FontCollection.cpp @@ -122,7 +122,7 @@ FontFamily* FontCollection::getFamilyForChar(uint32_t ch, return family; } int score = lang.match(family->lang()) * 2; - if (variant != 0 && variant == family->variant()) { + if (family->variant() == 0 || family->variant() == variant) { score++; } if (score > bestScore) { @@ -152,10 +152,13 @@ const uint32_t NBSP = 0xa0; const uint32_t ZWJ = 0x200c; const uint32_t ZWNJ = 0x200d; const uint32_t KEYCAP = 0x20e3; +const uint32_t HYPHEN = 0x2010; +const uint32_t NB_HYPHEN = 0x2011; // Characters where we want to continue using existing font run instead of // recomputing the best match in the fallback list. -static const uint32_t stickyWhitelist[] = { '!', ',', '.', ':', ';', '?', NBSP, ZWJ, ZWNJ, KEYCAP }; +static const uint32_t stickyWhitelist[] = { '!', ',', '-', '.', ':', ';', '?', NBSP, ZWJ, ZWNJ, + KEYCAP, HYPHEN, NB_HYPHEN }; static bool isStickyWhitelisted(uint32_t c) { for (size_t i = 0; i < sizeof(stickyWhitelist) / sizeof(stickyWhitelist[0]); i++) {