Mark fallback fonts in new Android font config parser

The new Android fonts.xml format doesn't explicitly tag fallback
fonts, or separate them from system fonts by putting them in a
separate file. We're assuming that any nameless font is a fallback
font.

Adds a unit test to track that we see as many fallback fonts as
expected when parsing a file.

BUG=chromium:400801
R=bungeman@google.com, djsollen@google.com, tomhudson@google.com

Author: tomhudson@chromium.org

Review URL: https://codereview.chromium.org/468893002
diff --git a/src/ports/SkFontConfigParser_android.cpp b/src/ports/SkFontConfigParser_android.cpp
index 6e87270..e9c912f 100644
--- a/src/ports/SkFontConfigParser_android.cpp
+++ b/src/ports/SkFontConfigParser_android.cpp
@@ -91,7 +91,9 @@
 
 void familyElementHandler(FontFamily* family, const char** attributes) {
     // A non-fallback <family> tag must have a canonical name attribute.
-    // A (fallback) <family> tag may have lang and variant attributes.
+    // A fallback <family> tag has no name, and may have lang and variant
+    // attributes.
+    family->fIsFallbackFont = true;
     for (size_t i = 0; attributes[i] != NULL &&
                        attributes[i+1] != NULL; i += 2) {
         const char* name = attributes[i];
@@ -101,6 +103,7 @@
         if (nameLen == 4 && !strncmp("name", name, nameLen)) {
             SkAutoAsciiToLC tolc(value);
             family->fNames.push_back().set(tolc.lc());
+            family->fIsFallbackFont = false;
         } else if (nameLen == 4 && !strncmp("lang", name, nameLen)) {
             family->fLanguage = SkLanguage (value);
         } else if (nameLen == 7 && !strncmp("variant", name, nameLen)) {
diff --git a/tests/FontConfigParser.cpp b/tests/FontConfigParser.cpp
index 8ca7556..86b2b1d 100644
--- a/tests/FontConfigParser.cpp
+++ b/tests/FontConfigParser.cpp
@@ -9,6 +9,16 @@
 #include "SkFontConfigParser_android.h"
 #include "Test.h"
 
+int CountFallbacks(SkTDArray<FontFamily*> fontFamilies) {
+    int countOfFallbackFonts = 0;
+    for (int i = 0; i < fontFamilies.count(); i++) {
+        if (fontFamilies[i]->fIsFallbackFont) {
+            countOfFallbackFonts++;
+        }
+    }
+    return countOfFallbackFonts;
+}
+
 void ValidateLoadedFonts(SkTDArray<FontFamily*> fontFamilies,
                          skiatest::Reporter* reporter) {
     REPORTER_ASSERT(reporter, fontFamilies[0]->fNames.count() == 5);
@@ -17,7 +27,6 @@
                     !strcmp(fontFamilies[0]->fFonts[0].fFileName.c_str(),
                             "Roboto-Regular.ttf"));
     REPORTER_ASSERT(reporter, !fontFamilies[0]->fIsFallbackFont);
-
 }
 
 void DumpLoadedFonts(SkTDArray<FontFamily*> fontFamilies) {
@@ -59,6 +68,7 @@
 
     if (preV17FontFamilies.count() > 0) {
         REPORTER_ASSERT(reporter, preV17FontFamilies.count() == 14);
+        REPORTER_ASSERT(reporter, CountFallbacks(preV17FontFamilies) == 10);
 
         DumpLoadedFonts(preV17FontFamilies);
         ValidateLoadedFonts(preV17FontFamilies, reporter);
@@ -74,6 +84,7 @@
 
     if (v17FontFamilies.count() > 0) {
         REPORTER_ASSERT(reporter, v17FontFamilies.count() == 41);
+        REPORTER_ASSERT(reporter, CountFallbacks(v17FontFamilies) == 31);
 
         DumpLoadedFonts(v17FontFamilies);
         ValidateLoadedFonts(v17FontFamilies, reporter);
@@ -89,6 +100,7 @@
 
     if (v22FontFamilies.count() > 0) {
         REPORTER_ASSERT(reporter, v22FontFamilies.count() == 53);
+        REPORTER_ASSERT(reporter, CountFallbacks(v22FontFamilies) == 42);
 
         DumpLoadedFonts(v22FontFamilies);
         ValidateLoadedFonts(v22FontFamilies, reporter);