Use different unique identifier for a fallback family.

BUG=chromium:266412
R=mtklein@google.com, reed@google.com

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

git-svn-id: http://skia.googlecode.com/svn/trunk@11451 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/src/ports/SkFontConfigInterface_android.cpp b/src/ports/SkFontConfigInterface_android.cpp
index 3a4c02e..7382d00 100644
--- a/src/ports/SkFontConfigInterface_android.cpp
+++ b/src/ports/SkFontConfigInterface_android.cpp
@@ -67,6 +67,7 @@
     static const int FONT_STYLE_COUNT = 4;
     FontRecID fFontRecID[FONT_STYLE_COUNT];
     bool fIsFallbackFont;
+    SkString fFallbackName;
     SkPaintOptionsAndroid fPaintOptions;
 };
 
@@ -263,10 +264,6 @@
                 familyRec->fIsFallbackFont = family->fIsFallbackFont;
                 familyRec->fPaintOptions = family->fFontFiles[j]->fPaintOptions;
 
-                // if this is a fallback font then add it to the appropriate fallback chains
-                if (familyRec->fIsFallbackFont) {
-                    addFallbackFamily(familyRecID);
-                }
             } else if (familyRec->fPaintOptions != family->fFontFiles[j]->fPaintOptions) {
                 SkDebugf("Every font file within a family must have identical"
                          "language and variant attributes");
@@ -280,28 +277,26 @@
                             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
-        if (familyRec && !familyRec->fIsFallbackFont) {
-            SkTDArray<const char*> names = family->fNames;
-            if (names.isEmpty()) {
-                SkDEBUGFAIL("ERROR: non-fallback font with no name");
-                continue;
-            }
+        if (familyRec) {
+            if (familyRec->fIsFallbackFont) {
+                // add the font to the appropriate fallback chains and also insert a
+                // unique name into the familyNameDict for internal usage
+                addFallbackFamily(familyRecID);
+            } else {
+                // add the names that map to this family to the dictionary for easy lookup
+                const SkTDArray<const char*>& names = family->fNames;
+                if (names.isEmpty()) {
+                    SkDEBUGFAIL("ERROR: non-fallback font with no name");
+                    continue;
+                }
 
-            for (int i = 0; i < names.count(); i++) {
-                insert_into_name_dict(fFamilyNameDict, names[i], familyRecID);
+                for (int i = 0; i < names.count(); i++) {
+                    insert_into_name_dict(fFamilyNameDict, names[i], familyRecID);
+                }
             }
         }
-
     }
 
     DEBUG_FONT(("---- We have %d system fonts", fFonts.count()));
@@ -341,9 +336,16 @@
 
 void SkFontConfigInterfaceAndroid::addFallbackFamily(FamilyRecID familyRecID) {
     SkASSERT(familyRecID < fFontFamilies.count());
-    const FamilyRec& familyRec = fFontFamilies[familyRecID];
+    FamilyRec& familyRec = fFontFamilies[familyRecID];
     SkASSERT(familyRec.fIsFallbackFont);
 
+    // add the fallback family to the name dictionary.  This is
+    // needed by getFallbackFamilyNameForChar() so that fallback
+    // families can be identified by a unique name. The unique
+    // identifier that we've chosen is the familyID in hex (e.g. '0F##fallback').
+    familyRec.fFallbackName.printf("%.2x##fallback", familyRecID);
+    insert_into_name_dict(fFamilyNameDict, familyRec.fFallbackName.c_str(), familyRecID);
+
     // add to the default fallback list
     fDefaultFallbackList.push(familyRecID);
 
@@ -529,7 +531,7 @@
         uint16_t glyphID;
         paint.textToGlyphs(&uni, sizeof(uni), &glyphID);
         if (glyphID != 0) {
-            name->set(fFonts[fontRecID].fFileName);
+            name->set(fFontFamilies[familyRecID].fFallbackName);
             return true;
         }
     }