summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBehdad Esfahbod <behdad@google.com>2014-08-08 15:25:57 -0400
committerBehdad Esfahbod <behdad@google.com>2014-08-08 15:37:28 -0400
commitf952161b874fd2e9af474b9fd2ebcca1f3bb4555 (patch)
tree0a9cffec483320f1bf1af221038377a7ea67e485
parent5986f6048ae21e0ec094c1f2ca0169d0ca6ec6b5 (diff)
downloadandroid_frameworks_minikin-f952161b874fd2e9af474b9fd2ebcca1f3bb4555.tar.gz
android_frameworks_minikin-f952161b874fd2e9af474b9fd2ebcca1f3bb4555.tar.bz2
android_frameworks_minikin-f952161b874fd2e9af474b9fd2ebcca1f3bb4555.zip
Choose same font for Emoji keycap and its base character
The U+20E3 COMBINING KEYCAP is used in our fonts to generate an emoji rendering of ASCII numbers and letters through GSUB. For that to work we need to choose the same (Emoji) font for the character coming *before* the COMBINING KEYCAP character. This is a special-case of a broader need to choose fonts per grapheme cluster as opposed to per character, but for now, special-case U+20E3. Bug: 7557244 Change-Id: I958e5a01068df8495bbb9bc3b9ed871cea1838b6
-rw-r--r--libs/minikin/FontCollection.cpp19
1 files changed, 17 insertions, 2 deletions
diff --git a/libs/minikin/FontCollection.cpp b/libs/minikin/FontCollection.cpp
index a6977fd..009584e 100644
--- a/libs/minikin/FontCollection.cpp
+++ b/libs/minikin/FontCollection.cpp
@@ -152,9 +152,11 @@ const FontCollection::FontInstance* FontCollection::getInstanceForChar(uint32_t
const uint32_t NBSP = 0xa0;
const uint32_t ZWJ = 0x200c;
const uint32_t ZWNJ = 0x200d;
+const uint32_t KEYCAP = 0x20e3;
+
// 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 };
+static const uint32_t stickyWhitelist[] = { '!', ',', '.', ':', ';', '?', NBSP, ZWJ, ZWNJ, KEYCAP };
static bool isStickyWhitelisted(uint32_t c) {
for (size_t i = 0; i < sizeof(stickyWhitelist) / sizeof(stickyWhitelist[0]); i++) {
@@ -185,6 +187,19 @@ void FontCollection::itemize(const uint16_t *string, size_t string_size, FontSty
|| !(isStickyWhitelisted(ch) && lastInstance->mCoverage->get(ch))) {
const FontInstance* instance = getInstanceForChar(ch, lang, variant);
if (i == 0 || instance != lastInstance) {
+ size_t start = i;
+ // Workaround for Emoji keycap until we implement per-cluster font
+ // selection: if keycap is found in a different font that also
+ // supports previous char, attach previous char to the new run.
+ // Only handles non-surrogate characters.
+ // Bug 7557244.
+ if (ch == KEYCAP && i && instance && instance->mCoverage->get(string[i - 1])) {
+ run->end--;
+ if (run->start == run->end) {
+ result->pop_back();
+ }
+ start--;
+ }
Run dummy;
result->push_back(dummy);
run = &result->back();
@@ -194,7 +209,7 @@ void FontCollection::itemize(const uint16_t *string, size_t string_size, FontSty
run->fakedFont = instance->mFamily->getClosestMatch(style);
}
lastInstance = instance;
- run->start = i;
+ run->start = start;
}
}
run->end = i + nShorts;