Merge "DO NOT MERGE Han Preference" into jb-mr1-dev

This commit is contained in:
Victoria Lease
2012-08-20 13:11:43 -07:00
committed by Android (Google) Code Review
7 changed files with 74 additions and 174 deletions

View File

@@ -22,6 +22,7 @@
#include "jni.h" #include "jni.h"
#include "GraphicsJNI.h" #include "GraphicsJNI.h"
#include <android_runtime/AndroidRuntime.h> #include <android_runtime/AndroidRuntime.h>
#include <ScopedUtfChars.h>
#include "SkBlurDrawLooper.h" #include "SkBlurDrawLooper.h"
#include "SkColorFilter.h" #include "SkColorFilter.h"
@@ -30,6 +31,7 @@
#include "SkShader.h" #include "SkShader.h"
#include "SkTypeface.h" #include "SkTypeface.h"
#include "SkXfermode.h" #include "SkXfermode.h"
#include "unicode/uloc.h"
#include "unicode/ushape.h" #include "unicode/ushape.h"
#include "TextLayout.h" #include "TextLayout.h"
@@ -254,11 +256,51 @@ public:
obj->setTextAlign(align); 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) { static void setTextLocale(JNIEnv* env, jobject clazz, SkPaint* obj, jstring locale) {
const char* localeArray = env->GetStringUTFChars(locale, NULL); ScopedUtfChars localeChars(env, locale);
SkString skLocale(localeArray); char langTag[ULOC_FULLNAME_CAPACITY];
obj->setTextLocale(skLocale); toLanguageTag(langTag, ULOC_FULLNAME_CAPACITY, localeChars.c_str());
env->ReleaseStringUTFChars(locale, localeArray); obj->setLanguage(SkLanguage(langTag));
} }
static jfloat getTextSize(JNIEnv* env, jobject paint) { static jfloat getTextSize(JNIEnv* env, jobject paint) {

View File

@@ -19,6 +19,7 @@
#include "TextLayoutCache.h" #include "TextLayoutCache.h"
#include "TextLayout.h" #include "TextLayout.h"
#include "SkFontHost.h" #include "SkFontHost.h"
#include "SkTypeface_android.h"
#include <unicode/unistr.h> #include <unicode/unistr.h>
#include <unicode/normlzr.h> #include <unicode/normlzr.h>
#include <unicode/uchar.h> #include <unicode/uchar.h>
@@ -224,7 +225,7 @@ void TextLayoutCache::dumpCacheStats() {
*/ */
TextLayoutCacheKey::TextLayoutCacheKey(): text(NULL), start(0), count(0), contextCount(0), TextLayoutCacheKey::TextLayoutCacheKey(): text(NULL), start(0), count(0), contextCount(0),
dirFlags(0), typeface(NULL), textSize(0), textSkewX(0), textScaleX(0), flags(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, TextLayoutCacheKey::TextLayoutCacheKey(const SkPaint* paint, const UChar* text,
@@ -237,6 +238,8 @@ TextLayoutCacheKey::TextLayoutCacheKey(const SkPaint* paint, const UChar* text,
textScaleX = paint->getTextScaleX(); textScaleX = paint->getTextScaleX();
flags = paint->getFlags(); flags = paint->getFlags();
hinting = paint->getHinting(); hinting = paint->getHinting();
variant = paint->getFontVariant();
language = paint->getLanguage();
} }
TextLayoutCacheKey::TextLayoutCacheKey(const TextLayoutCacheKey& other) : TextLayoutCacheKey::TextLayoutCacheKey(const TextLayoutCacheKey& other) :
@@ -251,7 +254,9 @@ TextLayoutCacheKey::TextLayoutCacheKey(const TextLayoutCacheKey& other) :
textSkewX(other.textSkewX), textSkewX(other.textSkewX),
textScaleX(other.textScaleX), textScaleX(other.textScaleX),
flags(other.flags), flags(other.flags),
hinting(other.hinting) { hinting(other.hinting),
variant(other.variant),
language(other.language) {
if (other.text) { if (other.text) {
textCopy.setTo(other.text, other.contextCount); textCopy.setTo(other.text, other.contextCount);
} }
@@ -288,6 +293,12 @@ int TextLayoutCacheKey::compare(const TextLayoutCacheKey& lhs, const TextLayoutC
deltaInt = lhs.dirFlags - rhs.dirFlags; deltaInt = lhs.dirFlags - rhs.dirFlags;
if (deltaInt) return (deltaInt); 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)); 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.setTextScaleX(paint->getTextScaleX());
mShapingPaint.setFlags(paint->getFlags()); mShapingPaint.setFlags(paint->getFlags());
mShapingPaint.setHinting(paint->getHinting()); 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 // Split the BiDi run into Script runs. Harfbuzz will populate the pos, length and script
// into the shaperItem // into the shaperItem

View File

@@ -32,7 +32,7 @@
#include <SkTemplates.h> #include <SkTemplates.h>
#include <SkUtils.h> #include <SkUtils.h>
#include <SkAutoKern.h> #include <SkAutoKern.h>
#include "SkTypeface_android.h" #include <SkLanguage.h>
#include <unicode/ubidi.h> #include <unicode/ubidi.h>
#include <unicode/ushape.h> #include <unicode/ushape.h>
@@ -102,6 +102,8 @@ private:
SkScalar textScaleX; SkScalar textScaleX;
uint32_t flags; uint32_t flags;
SkPaint::Hinting hinting; SkPaint::Hinting hinting;
SkPaint::FontVariant variant;
SkLanguage language;
inline const UChar* getText() const { return text ? text : textCopy.string(); } inline const UChar* getText() const { return text ? text : textCopy.string(); }

View File

@@ -76,14 +76,6 @@ LOCAL_MODULE_TAGS := optional
LOCAL_MODULE_PATH := $(TARGET_OUT)/fonts LOCAL_MODULE_PATH := $(TARGET_OUT)/fonts
include $(BUILD_PREBUILT) 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 droidsans_fallback_src := DroidSansFallbackFull.ttf
extra_font_files := \ extra_font_files := \
DroidSans.ttf \ DroidSans.ttf \
@@ -91,8 +83,7 @@ extra_font_files := \
DroidSansEthiopic-Regular.ttf \ DroidSansEthiopic-Regular.ttf \
DroidSansTamil-Regular.ttf \ DroidSansTamil-Regular.ttf \
DroidSansTamil-Bold.ttf \ DroidSansTamil-Bold.ttf \
MTLmr3m.ttf \ MTLmr3m.ttf
fallback_fonts-ja.xml
endif # SMALLER_FONT_FOOTPRINT endif # SMALLER_FONT_FOOTPRINT
################################ ################################

View File

@@ -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>

View File

@@ -24,12 +24,9 @@
Han languages (Chinese, Japanese, and Korean) share a common range of unicode characters; 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. 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 Language-specific ordering can be configured by adding a BCP 47-style "lang" attribute to
of the filename (e.g. /system/etc/fallback_fonts-ja.xml). When no region code is used, a "file" element; fonts matching the language of text being drawn will be prioritised over
as with this example, all regions are matched. Use separate files for each supported locale. all others.
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> <familyset>
<family> <family>
@@ -106,7 +103,7 @@
</family> </family>
<family> <family>
<fileset> <fileset>
<file>MTLmr3m.ttf</file> <file lang="ja">MTLmr3m.ttf</file>
</fileset> </fileset>
</family> </family>
<!-- <!--

View File

@@ -7,8 +7,7 @@
that in your makefile, this directory should be referenced as $(TARGET_COPY_OUT_VENDOR)/etc/: that in your makefile, this directory should be referenced as $(TARGET_COPY_OUT_VENDOR)/etc/:
PRODUCT_COPY_FILES += \ PRODUCT_COPY_FILES += \
frameworks/base/data/fonts/vendor_fonts.xml:$(TARGET_COPY_OUT_VENDOR)/etc/fallback_fonts.xml \ 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
For example, vendors might want to build configurations for locales that are 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 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; 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. 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 Language-specific ordering can be configured by adding a BCP 47-style "lang" attribute to
of the filename (e.g. /vendor/etc/fallback_fonts-ja.xml). When no region code is used, a "file" element; fonts matching the language of text being drawn will be prioritised over
as with this example, all regions are matched. Use separate files for each supported locale. all others.
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>
The sample configuration below is an example of how one might provide two families of fonts 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. that get inserted at the first and second (0 and 1) position in the overall fallback fonts.
@@ -82,4 +58,4 @@
</fileset> </fileset>
</family> </family>
</familyset> </familyset>
--> --->