Commit ed84b46d authored by Derek Sollenberger's avatar Derek Sollenberger
Browse files

Add new entry point that supports fallback font selection based on language.

Cherry-pick of https://code.google.com/p/skia/source/detail?r=11394

bug: 10653841
Change-Id: If50522fae5a8b749dbf97db8eca8c518cd710ebf
parent b44bc380
......@@ -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,
......
......@@ -17,10 +17,32 @@ 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.
......
......@@ -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);
/**
*
*/
......@@ -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,
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment