Make the use of fallback fonts in Android a runtime decision.

R=reed@google.com

Review URL: https://codereview.chromium.org/14972022

git-svn-id: http://skia.googlecode.com/svn/trunk@9168 2bbb7eff-a529-9590-31e7-b0007b416f81
This commit is contained in:
djsollen@google.com 2013-05-16 18:38:43 +00:00
parent 8371e704b7
commit 9401deeb10
3 changed files with 21 additions and 7 deletions

View File

@ -61,16 +61,20 @@ class SkPaintOptionsAndroid {
public: public:
SkPaintOptionsAndroid() { SkPaintOptionsAndroid() {
fFontVariant = kDefault_Variant; fFontVariant = kDefault_Variant;
fUseFontFallbacks = false;
} }
SkPaintOptionsAndroid& operator=(const SkPaintOptionsAndroid& b) { SkPaintOptionsAndroid& operator=(const SkPaintOptionsAndroid& b) {
fLanguage = b.fLanguage; fLanguage = b.fLanguage;
fFontVariant = b.fFontVariant; fFontVariant = b.fFontVariant;
fUseFontFallbacks = b.fUseFontFallbacks;
return *this; return *this;
} }
bool operator!=(const SkPaintOptionsAndroid& b) const { bool operator!=(const SkPaintOptionsAndroid& b) const {
return fLanguage != b.fLanguage || fFontVariant != b.fFontVariant; return fLanguage != b.fLanguage ||
fFontVariant != b.fFontVariant ||
fUseFontFallbacks != b.fUseFontFallbacks;
} }
void flatten(SkFlattenableWriteBuffer&) const; void flatten(SkFlattenableWriteBuffer&) const;
@ -108,9 +112,16 @@ public:
fFontVariant = fontVariant; fFontVariant = fontVariant;
} }
bool isUsingFontFallbacks() const { return fUseFontFallbacks; }
void setUseFontFallbacks(bool useFontFallbacks) {
fUseFontFallbacks = useFontFallbacks;
}
private: private:
SkLanguage fLanguage; SkLanguage fLanguage;
FontVariant fFontVariant; FontVariant fFontVariant;
bool fUseFontFallbacks;
}; };
#endif // #ifdef SK_BUILD_FOR_ANDROID #endif // #ifdef SK_BUILD_FOR_ANDROID

View File

@ -30,6 +30,7 @@ SkLanguage SkLanguage::getParent() const {
void SkPaintOptionsAndroid::flatten(SkFlattenableWriteBuffer& buffer) const { void SkPaintOptionsAndroid::flatten(SkFlattenableWriteBuffer& buffer) const {
buffer.writeUInt(fFontVariant); buffer.writeUInt(fFontVariant);
buffer.writeString(fLanguage.getTag().c_str()); buffer.writeString(fLanguage.getTag().c_str());
buffer.writeBool(fUseFontFallbacks);
} }
void SkPaintOptionsAndroid::unflatten(SkFlattenableReadBuffer& buffer) { void SkPaintOptionsAndroid::unflatten(SkFlattenableReadBuffer& buffer) {
@ -37,6 +38,7 @@ void SkPaintOptionsAndroid::unflatten(SkFlattenableReadBuffer& buffer) {
char* tag = buffer.readString(); char* tag = buffer.readString();
fLanguage = SkLanguage(tag); fLanguage = SkLanguage(tag);
sk_free(tag); sk_free(tag);
fUseFontFallbacks = buffer.readBool();
} }
#endif #endif

View File

@ -803,13 +803,14 @@ SkTypeface* SkFontHost::CreateTypeface(const SkTypeface* familyFace,
SkTypeface* SkAndroidNextLogicalTypeface(SkFontID currFontID, SkFontID origFontID, SkTypeface* SkAndroidNextLogicalTypeface(SkFontID currFontID, SkFontID origFontID,
const SkPaintOptionsAndroid& options) { const SkPaintOptionsAndroid& options) {
#if !defined(SK_BUILD_FOR_ANDROID_FRAMEWORK) // Skia does not support font fallback by default for ndk applications. This
// Skia does not support font fallback for ndk applications in order to // enables clients such as WebKit to customize their font selection. In any
// enable clients such as WebKit to customize their font selection. // case clients can use GetFallbackFamilyNameForChar() to get the fallback
// Clients can use GetFallbackFamilyNameForChar() to get the fallback
// font for individual characters. // font for individual characters.
return NULL; if (!options.isUsingFontFallbacks()) {
#endif return NULL;
}
SkAutoMutexAcquire ac(gFamilyHeadAndNameListMutex); SkAutoMutexAcquire ac(gFamilyHeadAndNameListMutex);
load_system_fonts(); load_system_fonts();