summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--core/jni/android/graphics/Paint.cpp50
-rw-r--r--core/jni/android/graphics/TextLayoutCache.cpp17
-rw-r--r--core/jni/android/graphics/TextLayoutCache.h4
-rw-r--r--data/fonts/Android.mk11
-rw-r--r--data/fonts/fallback_fonts-ja.xml121
-rw-r--r--data/fonts/fallback_fonts.xml11
-rw-r--r--data/fonts/vendor_fonts.xml34
7 files changed, 74 insertions, 174 deletions
diff --git a/core/jni/android/graphics/Paint.cpp b/core/jni/android/graphics/Paint.cpp
index a65262c..edc9732 100644
--- a/core/jni/android/graphics/Paint.cpp
+++ b/core/jni/android/graphics/Paint.cpp
@@ -22,6 +22,7 @@
#include "jni.h"
#include "GraphicsJNI.h"
#include <android_runtime/AndroidRuntime.h>
+#include <ScopedUtfChars.h>
#include "SkBlurDrawLooper.h"
#include "SkColorFilter.h"
@@ -30,6 +31,7 @@
#include "SkShader.h"
#include "SkTypeface.h"
#include "SkXfermode.h"
+#include "unicode/uloc.h"
#include "unicode/ushape.h"
#include "TextLayout.h"
@@ -254,11 +256,51 @@ public:
obj->setTextAlign(align);
}
+ // generate bcp47 identifier for the supplied locale
+ static void toLanguageTag(char* output, size_t outSize,
+ const char* locale) {
+ if (output == NULL || outSize <= 0) {
+ return;
+ }
+ if (locale == NULL) {
+ output[0] = '\0';
+ return;
+ }
+ char canonicalChars[ULOC_FULLNAME_CAPACITY];
+ UErrorCode uErr = U_ZERO_ERROR;
+ uloc_canonicalize(locale, canonicalChars, ULOC_FULLNAME_CAPACITY,
+ &uErr);
+ if (U_SUCCESS(uErr)) {
+ char likelyChars[ULOC_FULLNAME_CAPACITY];
+ uErr = U_ZERO_ERROR;
+ uloc_addLikelySubtags(canonicalChars, likelyChars,
+ ULOC_FULLNAME_CAPACITY, &uErr);
+ if (U_SUCCESS(uErr)) {
+ uErr = U_ZERO_ERROR;
+ uloc_toLanguageTag(likelyChars, output, outSize, FALSE, &uErr);
+ if (U_SUCCESS(uErr)) {
+ return;
+ } else {
+ ALOGD("uloc_toLanguageTag(\"%s\") failed: %s", likelyChars,
+ u_errorName(uErr));
+ }
+ } else {
+ ALOGD("uloc_addLikelySubtags(\"%s\") failed: %s",
+ canonicalChars, u_errorName(uErr));
+ }
+ } else {
+ ALOGD("uloc_canonicalize(\"%s\") failed: %s", locale,
+ u_errorName(uErr));
+ }
+ // unable to build a proper language identifier
+ output[0] = '\0';
+ }
+
static void setTextLocale(JNIEnv* env, jobject clazz, SkPaint* obj, jstring locale) {
- const char* localeArray = env->GetStringUTFChars(locale, NULL);
- SkString skLocale(localeArray);
- obj->setTextLocale(skLocale);
- env->ReleaseStringUTFChars(locale, localeArray);
+ ScopedUtfChars localeChars(env, locale);
+ char langTag[ULOC_FULLNAME_CAPACITY];
+ toLanguageTag(langTag, ULOC_FULLNAME_CAPACITY, localeChars.c_str());
+ obj->setLanguage(SkLanguage(langTag));
}
static jfloat getTextSize(JNIEnv* env, jobject paint) {
diff --git a/core/jni/android/graphics/TextLayoutCache.cpp b/core/jni/android/graphics/TextLayoutCache.cpp
index 9b9b991..7abfcf1 100644
--- a/core/jni/android/graphics/TextLayoutCache.cpp
+++ b/core/jni/android/graphics/TextLayoutCache.cpp
@@ -19,6 +19,7 @@
#include "TextLayoutCache.h"
#include "TextLayout.h"
#include "SkFontHost.h"
+#include "SkTypeface_android.h"
#include <unicode/unistr.h>
#include <unicode/normlzr.h>
#include <unicode/uchar.h>
@@ -224,7 +225,7 @@ void TextLayoutCache::dumpCacheStats() {
*/
TextLayoutCacheKey::TextLayoutCacheKey(): text(NULL), start(0), count(0), contextCount(0),
dirFlags(0), typeface(NULL), textSize(0), textSkewX(0), textScaleX(0), flags(0),
- hinting(SkPaint::kNo_Hinting) {
+ hinting(SkPaint::kNo_Hinting), variant(SkPaint::kDefault_Variant), language() {
}
TextLayoutCacheKey::TextLayoutCacheKey(const SkPaint* paint, const UChar* text,
@@ -237,6 +238,8 @@ TextLayoutCacheKey::TextLayoutCacheKey(const SkPaint* paint, const UChar* text,
textScaleX = paint->getTextScaleX();
flags = paint->getFlags();
hinting = paint->getHinting();
+ variant = paint->getFontVariant();
+ language = paint->getLanguage();
}
TextLayoutCacheKey::TextLayoutCacheKey(const TextLayoutCacheKey& other) :
@@ -251,7 +254,9 @@ TextLayoutCacheKey::TextLayoutCacheKey(const TextLayoutCacheKey& other) :
textSkewX(other.textSkewX),
textScaleX(other.textScaleX),
flags(other.flags),
- hinting(other.hinting) {
+ hinting(other.hinting),
+ variant(other.variant),
+ language(other.language) {
if (other.text) {
textCopy.setTo(other.text, other.contextCount);
}
@@ -288,6 +293,12 @@ int TextLayoutCacheKey::compare(const TextLayoutCacheKey& lhs, const TextLayoutC
deltaInt = lhs.dirFlags - rhs.dirFlags;
if (deltaInt) return (deltaInt);
+ deltaInt = lhs.variant - rhs.variant;
+ if (deltaInt) return (deltaInt);
+
+ if (lhs.language < rhs.language) return -1;
+ if (lhs.language > rhs.language) return +1;
+
return memcmp(lhs.getText(), rhs.getText(), lhs.contextCount * sizeof(UChar));
}
@@ -615,6 +626,8 @@ void TextLayoutShaper::computeRunValues(const SkPaint* paint, const UChar* chars
mShapingPaint.setTextScaleX(paint->getTextScaleX());
mShapingPaint.setFlags(paint->getFlags());
mShapingPaint.setHinting(paint->getHinting());
+ mShapingPaint.setFontVariant(paint->getFontVariant());
+ mShapingPaint.setLanguage(paint->getLanguage());
// Split the BiDi run into Script runs. Harfbuzz will populate the pos, length and script
// into the shaperItem
diff --git a/core/jni/android/graphics/TextLayoutCache.h b/core/jni/android/graphics/TextLayoutCache.h
index f007f9a..64b33a0 100644
--- a/core/jni/android/graphics/TextLayoutCache.h
+++ b/core/jni/android/graphics/TextLayoutCache.h
@@ -32,7 +32,7 @@
#include <SkTemplates.h>
#include <SkUtils.h>
#include <SkAutoKern.h>
-#include "SkTypeface_android.h"
+#include <SkLanguage.h>
#include <unicode/ubidi.h>
#include <unicode/ushape.h>
@@ -102,6 +102,8 @@ private:
SkScalar textScaleX;
uint32_t flags;
SkPaint::Hinting hinting;
+ SkPaint::FontVariant variant;
+ SkLanguage language;
inline const UChar* getText() const { return text ? text : textCopy.string(); }
diff --git a/data/fonts/Android.mk b/data/fonts/Android.mk
index 3d6c9d3..7bc172c 100644
--- a/data/fonts/Android.mk
+++ b/data/fonts/Android.mk
@@ -76,14 +76,6 @@ LOCAL_MODULE_TAGS := optional
LOCAL_MODULE_PATH := $(TARGET_OUT)/fonts
include $(BUILD_PREBUILT)
-include $(CLEAR_VARS)
-LOCAL_MODULE := fallback_fonts-ja.xml
-LOCAL_SRC_FILES := $(LOCAL_MODULE)
-LOCAL_MODULE_CLASS := ETC
-LOCAL_MODULE_TAGS := optional
-LOCAL_MODULE_PATH := $(TARGET_OUT_ETC)
-include $(BUILD_PREBUILT)
-
droidsans_fallback_src := DroidSansFallbackFull.ttf
extra_font_files := \
DroidSans.ttf \
@@ -91,8 +83,7 @@ extra_font_files := \
DroidSansEthiopic-Regular.ttf \
DroidSansTamil-Regular.ttf \
DroidSansTamil-Bold.ttf \
- MTLmr3m.ttf \
- fallback_fonts-ja.xml
+ MTLmr3m.ttf
endif # SMALLER_FONT_FOOTPRINT
################################
diff --git a/data/fonts/fallback_fonts-ja.xml b/data/fonts/fallback_fonts-ja.xml
deleted file mode 100644
index 82e3a38..0000000
--- a/data/fonts/fallback_fonts-ja.xml
+++ /dev/null
@@ -1,121 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!--
- Fallback Fonts
-
- This file specifies the fonts, and the priority order, that will be searched for any
- glyphs not handled by the default fonts specified in /system/etc/system_fonts.xml.
- Each entry consists of a family tag and a list of files (file names) which support that
- family. The fonts for each family are listed in the order of the styles that they
- handle (the order is: regular, bold, italic, and bold-italic). The order in which the
- families are listed in this file represents the order in which these fallback fonts
- will be searched for glyphs that are not supported by the default system fonts (which are
- found in /system/etc/system_fonts.xml).
-
- Note that there is not nameset for fallback fonts, unlike the fonts specified in
- system_fonts.xml. The ability to support specific names in fallback fonts may be supported
- in the future. For now, the lack of files entries here is an indicator to the system that
- these are fallback fonts, instead of default named system fonts.
-
- There is another optional file in /vendor/etc/fallback_fonts.xml. That file can be used to
- provide references to other font families that should be used in addition to the default
- fallback fonts. That file can also specify the order in which the fallback fonts should be
- searched, to ensure that a vendor-provided font will be used before another fallback font
- which happens to handle the same glyph.
-
- Han languages (Chinese, Japanese, and Korean) share a common range of unicode characters;
- their ordering in the fallback or vendor files gives priority to the first in the list.
- Locale-specific ordering can be configured by adding language and region codes to the end
- of the filename (e.g. /system/etc/fallback_fonts-ja.xml). When no region code is used,
- as with this example, all regions are matched. Use separate files for each supported locale.
- The standard fallback file (fallback_fonts.xml) is used when a locale does not have its own
- file. All fallback files must contain the same complete set of fonts; only their ordering
- can differ.
--->
-<familyset>
- <family>
- <fileset>
- <file variant="elegant">DroidNaskh-Regular.ttf</file>
- </fileset>
- </family>
- <family>
- <fileset>
- <file variant="compact">DroidNaskh-Regular-SystemUI.ttf</file>
- </fileset>
- </family>
- <family>
- <fileset>
- <file>DroidSansEthiopic-Regular.ttf</file>
- </fileset>
- </family>
- <family>
- <fileset>
- <file>DroidSansHebrew-Regular.ttf</file>
- <file>DroidSansHebrew-Bold.ttf</file>
- </fileset>
- </family>
- <family>
- <fileset>
- <file>DroidSansThai.ttf</file>
- </fileset>
- </family>
- <family>
- <fileset>
- <file>DroidSansArmenian.ttf</file>
- </fileset>
- </family>
- <family>
- <fileset>
- <file>DroidSansGeorgian.ttf</file>
- </fileset>
- </family>
- <family>
- <fileset>
- <file>DroidSansDevanagari-Regular.ttf</file>
- </fileset>
- </family>
- <family>
- <fileset>
- <file>DroidSansTamil-Regular.ttf</file>
- <file>DroidSansTamil-Bold.ttf</file>
- </fileset>
- </family>
- <family>
- <fileset>
- <file>AnjaliNewLipi-light.ttf</file>
- </fileset>
- </family>
- <family>
- <fileset>
- <file>Lohit-Bengali.ttf</file>
- </fileset>
- </family>
- <family>
- <fileset>
- <file>Lohit-Kannada.ttf</file>
- </fileset>
- </family>
- <family>
- <fileset>
- <file>AndroidEmoji.ttf</file>
- </fileset>
- </family>
- <family>
- <fileset>
- <file>MTLmr3m.ttf</file>
- </fileset>
- </family>
- <family>
- <fileset>
- <file>DroidSansFallback.ttf</file>
- </fileset>
- </family>
- <!--
- Fonts below this point have problematic glyphs and should not be moved
- higher in the fallback list until those glyphs have been fixed.
- -->
- <family>
- <fileset>
- <file>Lohit-Telugu.ttf</file> <!-- masks U+FFBC-10007 -->
- </fileset>
- </family>
-</familyset>
diff --git a/data/fonts/fallback_fonts.xml b/data/fonts/fallback_fonts.xml
index 758adb5..2c9a0c8 100644
--- a/data/fonts/fallback_fonts.xml
+++ b/data/fonts/fallback_fonts.xml
@@ -24,12 +24,9 @@
Han languages (Chinese, Japanese, and Korean) share a common range of unicode characters;
their ordering in the fallback or vendor files gives priority to the first in the list.
- Locale-specific ordering can be configured by adding language and region codes to the end
- of the filename (e.g. /system/etc/fallback_fonts-ja.xml). When no region code is used,
- as with this example, all regions are matched. Use separate files for each supported locale.
- The standard fallback file (fallback_fonts.xml) is used when a locale does not have its own
- file. All fallback files must contain the same complete set of fonts; only their ordering
- can differ.
+ Language-specific ordering can be configured by adding a BCP 47-style "lang" attribute to
+ a "file" element; fonts matching the language of text being drawn will be prioritised over
+ all others.
-->
<familyset>
<family>
@@ -106,7 +103,7 @@
</family>
<family>
<fileset>
- <file>MTLmr3m.ttf</file>
+ <file lang="ja">MTLmr3m.ttf</file>
</fileset>
</family>
<!--
diff --git a/data/fonts/vendor_fonts.xml b/data/fonts/vendor_fonts.xml
index 5850f94..8690ee1 100644
--- a/data/fonts/vendor_fonts.xml
+++ b/data/fonts/vendor_fonts.xml
@@ -7,8 +7,7 @@
that in your makefile, this directory should be referenced as $(TARGET_COPY_OUT_VENDOR)/etc/:
PRODUCT_COPY_FILES += \
- frameworks/base/data/fonts/vendor_fonts.xml:$(TARGET_COPY_OUT_VENDOR)/etc/fallback_fonts.xml \
- frameworks/base/data/fonts/vendor_fonts-ja.xml:$(TARGET_COPY_OUT_VENDOR)/etc/fallback_fonts-ja.xml
+ frameworks/base/data/fonts/vendor_fonts.xml:$(TARGET_COPY_OUT_VENDOR)/etc/fallback_fonts.xml
For example, vendors might want to build configurations for locales that are
better served by fonts which either handle glyphs not supported in the default fonts or which
@@ -32,32 +31,9 @@
Han languages (Chinese, Japanese, and Korean) share a common range of unicode characters;
their ordering in the fallback or vendor files gives priority to the first in the list.
- Locale-specific ordering can be configured by adding language and region codes to the end
- of the filename (e.g. /vendor/etc/fallback_fonts-ja.xml). When no region code is used,
- as with this example, all regions are matched. Use separate files for each supported locale.
- The standard fallback file (fallback_fonts.xml) is used when a locale does not have its own
- file. All fallback files must contain the same complete set of fonts; only their ordering
- can differ. For example, on a device supporting Japanese, but with English as the default,
- /vendor/etc/fallback_fonts.xml might contain:
-
- <familyset>
- <family>
- <fileset>
- <file>DroidSansJapanese.ttf</file>
- </fileset>
- </family>
- </familyset>
-
- placing the Japanese font at the end of the fallback sequence for English, with a corresponding
- /system/vendor/etc/fallback_fonts-ja.xml, placing it at the front of the list.
-
- <familyset>
- <family order="0">
- <fileset>
- <file>DroidSansJapanese.ttf</file>
- </fileset>
- </family>
- </familyset>
+ Language-specific ordering can be configured by adding a BCP 47-style "lang" attribute to
+ a "file" element; fonts matching the language of text being drawn will be prioritised over
+ all others.
The sample configuration below is an example of how one might provide two families of fonts
that get inserted at the first and second (0 and 1) position in the overall fallback fonts.
@@ -82,4 +58,4 @@
</fileset>
</family>
</familyset>
---> \ No newline at end of file
+--->