aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--include/core/SkPaintOptionsAndroid.h2
-rw-r--r--include/ports/SkTypeface_android.h24
-rw-r--r--src/ports/SkFontConfigInterface_android.cpp28
3 files changed, 46 insertions, 8 deletions
diff --git a/include/core/SkPaintOptionsAndroid.h b/include/core/SkPaintOptionsAndroid.h
index 78e43868c0..1bb29f4760 100644
--- a/include/core/SkPaintOptionsAndroid.h
+++ b/include/core/SkPaintOptionsAndroid.h
@@ -94,7 +94,7 @@ public:
enum FontVariant {
- kDefault_Variant = 0x01, // Currently setting yourself to Default gives you Compact Variant
+ kDefault_Variant = 0x01,
kCompact_Variant = 0x02,
kElegant_Variant = 0x04,
kLast_Variant = kElegant_Variant,
diff --git a/include/ports/SkTypeface_android.h b/include/ports/SkTypeface_android.h
index 655670fb6b..1ee923c4e6 100644
--- a/include/ports/SkTypeface_android.h
+++ b/include/ports/SkTypeface_android.h
@@ -17,11 +17,33 @@ class SkPaintOptionsAndroid;
/**
* Get the family name of the font in the fallback font list containing
- * the specified character. if no font is found, returns false.
+ * the specified character using the system's default language. This function
+ * also assumes the only families with the elegant or default variants will be
+ * returned.
+ *
+ * @param uni The unicode character to use for the lookup.
+ * @param name The family name of the font file containing the unicode character
+ * in the default language
+ * @return true if a font is found and false otherwise
*/
SK_API bool SkGetFallbackFamilyNameForChar(SkUnichar uni, SkString* name);
/**
+ * Get the family name of the font in the fallback font list containing
+ * the specified character taking into account the provided language. This
+ * function also assumes the only families with the elegant or default variants
+ * will be returned.
+ *
+ * @param uni The unicode character to use for the lookup.
+ * @param lang The null terminated string representing the BCP 47 language
+ * identifier for the preferred language
+ * @param name The family name of the font file containing the unicode character
+ * in the preferred language
+ * @return true if a font is found and false otherwise
+ */
+SK_API bool SkGetFallbackFamilyNameForChar(SkUnichar uni, const char* lang, SkString* name);
+
+/**
* For test only.
* Load font config from given xml files, instead of those from Android system.
*/
diff --git a/src/ports/SkFontConfigInterface_android.cpp b/src/ports/SkFontConfigInterface_android.cpp
index f56308dda9..3a4c02e539 100644
--- a/src/ports/SkFontConfigInterface_android.cpp
+++ b/src/ports/SkFontConfigInterface_android.cpp
@@ -95,7 +95,7 @@ public:
* Get the family name of the font in the default fallback font list that
* contains the specified chararacter. if no font is found, returns false.
*/
- bool getFallbackFamilyNameForChar(SkUnichar uni, SkString* name);
+ bool getFallbackFamilyNameForChar(SkUnichar uni, const char* lang, SkString* name);
/**
*
*/
@@ -246,10 +246,10 @@ SkFontConfigInterfaceAndroid::SkFontConfigInterfaceAndroid(SkTDArray<FontFamily*
if (fontRec.fIsValid) {
DEBUG_FONT(("---- SystemFonts[%d][%d] fallback=%d file=%s",
- i, fFonts.count() - 1, fontRec.fIsFallbackFont, filename.c_str()));
+ i, fFonts.count() - 1, family->fIsFallbackFont, filename.c_str()));
} else {
DEBUG_FONT(("---- SystemFonts[%d][%d] fallback=%d file=%s (INVALID)",
- i, fFonts.count() - 1, fontRec.fIsFallbackFont, filename.c_str()));
+ i, fFonts.count() - 1, family->fIsFallbackFont, filename.c_str()));
continue;
}
@@ -505,10 +505,20 @@ SkTypeface* SkFontConfigInterfaceAndroid::getTypefaceForFontRec(FontRecID fontRe
return face;
}
-bool SkFontConfigInterfaceAndroid::getFallbackFamilyNameForChar(SkUnichar uni, SkString* name) {
- FallbackFontList* fallbackFontList = this->getCurrentLocaleFallbackFontList();
+bool SkFontConfigInterfaceAndroid::getFallbackFamilyNameForChar(SkUnichar uni,
+ const char* lang,
+ SkString* name) {
+ FallbackFontList* fallbackFontList = this->findFallbackFontList(lang);
for (int i = 0; i < fallbackFontList->count(); i++) {
FamilyRecID familyRecID = fallbackFontList->getAt(i);
+
+ // if it is not one of the accepted variants then move to the next family
+ int32_t acceptedVariants = SkPaintOptionsAndroid::kDefault_Variant |
+ SkPaintOptionsAndroid::kElegant_Variant;
+ if (!(fFontFamilies[familyRecID].fPaintOptions.getFontVariant() & acceptedVariants)) {
+ continue;
+ }
+
FontRecID fontRecID = find_best_style(fFontFamilies[familyRecID], SkTypeface::kNormal);
SkTypeface* face = this->getTypefaceForFontRec(fontRecID);
@@ -663,8 +673,14 @@ SkTypeface* SkFontConfigInterfaceAndroid::nextLogicalTypeface(SkFontID currFontI
///////////////////////////////////////////////////////////////////////////////
bool SkGetFallbackFamilyNameForChar(SkUnichar uni, SkString* name) {
+ SkString locale = SkFontConfigParser::GetLocale();
+ SkFontConfigInterfaceAndroid* fontConfig = getSingletonInterface();
+ return fontConfig->getFallbackFamilyNameForChar(uni, locale.c_str(), name);
+}
+
+bool SkGetFallbackFamilyNameForChar(SkUnichar uni, const char* lang, SkString* name) {
SkFontConfigInterfaceAndroid* fontConfig = getSingletonInterface();
- return fontConfig->getFallbackFamilyNameForChar(uni, name);
+ return fontConfig->getFallbackFamilyNameForChar(uni, lang, name);
}
void SkUseTestFontConfigFile(const char* mainconf, const char* fallbackconf,