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
This commit is contained in:
Raph Levien
2015-07-29 13:03:50 -07:00
parent 322e328216
commit 2be7eeef68

View File

@@ -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++) {