Index: src/ports/SkFontConfigInterface_android.cpp |
=================================================================== |
--- src/ports/SkFontConfigInterface_android.cpp (revision 11394) |
+++ src/ports/SkFontConfigInterface_android.cpp (working copy) |
@@ -68,6 +68,8 @@ |
FontRecID fFontRecID[FONT_STYLE_COUNT]; |
bool fIsFallbackFont; |
SkPaintOptionsAndroid fPaintOptions; |
+ // To allow fallback fonts to be identified by family names. |
+ SkString fPseudoFamilyName; |
}; |
@@ -195,6 +197,12 @@ |
bool find_name_and_attributes(SkStream* stream, SkString* name, |
SkTypeface::Style* style, bool* isFixedWidth); |
+static void setPseudoFamilyName(FamilyRecID familyRecID, FamilyRec* familyRec) { |
+ SkString pseudoFamilyName("##"); |
+ pseudoFamilyName.appendHex(static_cast<uint32_t>(familyRecID) ^ reinterpret_cast<uint32_t>(familyRec)); |
+ familyRec->fPseudoFamilyName = pseudoFamilyName; |
+} |
+ |
/////////////////////////////////////////////////////////////////////////////// |
SkFontConfigInterfaceAndroid::SkFontConfigInterfaceAndroid(SkTDArray<FontFamily*>& fontFamilies) : |
@@ -266,6 +274,12 @@ |
// if this is a fallback font then add it to the appropriate fallback chains |
if (familyRec->fIsFallbackFont) { |
addFallbackFamily(familyRecID); |
+ // create a unique pseudo family name for the fallback family and |
+ // add the fallback font into the name dictionary. This is needed |
+ // by getFallbackFamilyNameForChar() so that fallback families can be |
+ // requested by the pseudo family names of the fonts they contain. |
+ setPseudoFamilyName(familyRecID, familyRec); |
+ insert_into_name_dict(fFamilyNameDict, familyRec->fPseudoFamilyName.c_str(), familyRecID); |
} |
} else if (familyRec->fPaintOptions != family->fFontFiles[j]->fPaintOptions) { |
SkDebugf("Every font file within a family must have identical" |
@@ -280,13 +294,6 @@ |
fontRecID)); |
} |
familyRec->fFontRecID[fontRec.fStyle] = fontRecID; |
- |
- // add the fallback file name to the name dictionary. This is needed |
- // by getFallbackFamilyNameForChar() so that fallback families can be |
- // requested by the filenames of the fonts they contain. |
- if (familyRec && familyRec->fIsFallbackFont) { |
- insert_into_name_dict(fFamilyNameDict, fontRec.fFileName.c_str(), familyRecID); |
- } |
} |
// add the names that map to this family to the dictionary for easy lookup |
@@ -522,6 +529,9 @@ |
FontRecID fontRecID = find_best_style(fFontFamilies[familyRecID], SkTypeface::kNormal); |
SkTypeface* face = this->getTypefaceForFontRec(fontRecID); |
+ FontRecID fontRecID = find_best_style(familyRec, SkTypeface::kNormal); |
+ SkTypeface* face = getTypefaceForFontRec(fontRecID); |
+ |
SkPaint paint; |
paint.setTypeface(face); |
paint.setTextEncoding(SkPaint::kUTF32_TextEncoding); |
@@ -529,7 +539,7 @@ |
uint16_t glyphID; |
paint.textToGlyphs(&uni, sizeof(uni), &glyphID); |
if (glyphID != 0) { |
- name->set(fFonts[fontRecID].fFileName); |
+ name->set(familyRec.fPseudoFamilyName); |
return true; |
} |
} |