diff options
author | Raph Levien <raph@google.com> | 2014-08-26 22:08:58 -0700 |
---|---|---|
committer | Raph Levien <raph@google.com> | 2014-08-26 22:20:16 -0700 |
commit | 997c799e3ec6bf8adf687e29670d23d91e0f5fee (patch) | |
tree | 22a2b71d1eaa186f1d0d6349271998c5c124175b | |
parent | 56c7fb8c0633f1b02115bb4370854016f8c84fb4 (diff) | |
download | android_frameworks_minikin-997c799e3ec6bf8adf687e29670d23d91e0f5fee.tar.gz android_frameworks_minikin-997c799e3ec6bf8adf687e29670d23d91e0f5fee.tar.bz2 android_frameworks_minikin-997c799e3ec6bf8adf687e29670d23d91e0f5fee.zip |
Try Unicode decomposition for selecting fallback font
This patch finds an appropriate fallback font in the case where no font
directly maps the requested character, but a font does exist for the
character's canonical decomposition. This yields correct rendering of
compatibility characters such as U+FA70.
Bug: 15816880
Bug: 16856221
Change-Id: Idff8ed6b942fec992a0815a32028b95af091d0ee
-rw-r--r-- | libs/minikin/FontCollection.cpp | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/libs/minikin/FontCollection.cpp b/libs/minikin/FontCollection.cpp index 009584e..ca5b1d1 100644 --- a/libs/minikin/FontCollection.cpp +++ b/libs/minikin/FontCollection.cpp @@ -19,6 +19,9 @@ #define LOG_TAG "Minikin" #include <cutils/log.h> +#include "unicode/unistr.h" +#include "unicode/unorm2.h" + #include "MinikinInternal.h" #include <minikin/CmapCoverage.h> #include <minikin/FontCollection.h> @@ -143,7 +146,18 @@ const FontCollection::FontInstance* FontCollection::getInstanceForChar(uint32_t } } } - if (bestInstance == NULL) { + if (bestInstance == NULL && !mInstanceVec.empty()) { + UErrorCode errorCode = U_ZERO_ERROR; + const UNormalizer2* normalizer = unorm2_getNFDInstance(&errorCode); + if (U_SUCCESS(errorCode)) { + UChar decomposed[4]; + int len = unorm2_getRawDecomposition(normalizer, ch, decomposed, 4, &errorCode); + if (U_SUCCESS(errorCode) && len > 0) { + int off = 0; + U16_NEXT_UNSAFE(decomposed, off, ch); + return getInstanceForChar(ch, lang, variant); + } + } bestInstance = &mInstances[0]; } return bestInstance; |