Serialize the font index.

BUG=skia:1186
R=reed@google.com

Author: bungeman@google.com

Review URL: https://codereview.chromium.org/567013002
diff --git a/src/ports/SkFontHost_fontconfig.cpp b/src/ports/SkFontHost_fontconfig.cpp
index 57252d0..b3a893e 100644
--- a/src/ports/SkFontHost_fontconfig.cpp
+++ b/src/ports/SkFontHost_fontconfig.cpp
@@ -169,5 +169,6 @@
 void FontConfigTypeface::onGetFontDescriptor(SkFontDescriptor* desc,
                                              bool* isLocalStream) const {
     desc->setFamilyName(this->getFamilyName());
+    desc->setFontIndex(this->getIdentity().fTTCIndex);
     *isLocalStream = SkToBool(this->getLocalStream());
 }
diff --git a/src/ports/SkFontHost_linux.cpp b/src/ports/SkFontHost_linux.cpp
index 2904cac..a4202aa 100644
--- a/src/ports/SkFontHost_linux.cpp
+++ b/src/ports/SkFontHost_linux.cpp
@@ -30,9 +30,10 @@
 /** The base SkTypeface implementation for the custom font manager. */
 class SkTypeface_Custom : public SkTypeface_FreeType {
 public:
-    SkTypeface_Custom(Style style, bool isFixedPitch, bool sysFont, const SkString familyName)
+    SkTypeface_Custom(Style style, bool isFixedPitch,
+                      bool sysFont, const SkString familyName, int index)
         : INHERITED(style, SkTypefaceCache::NewFontID(), isFixedPitch)
-        , fIsSysFont(sysFont), fFamilyName(familyName)
+        , fIsSysFont(sysFont), fFamilyName(familyName), fIndex(index)
     { }
 
     bool isSysFont() const { return fIsSysFont; }
@@ -47,12 +48,16 @@
     virtual void onGetFontDescriptor(SkFontDescriptor* desc, bool* isLocal) const SK_OVERRIDE {
         desc->setFamilyName(fFamilyName.c_str());
         desc->setFontFileName(this->getUniqueString());
+        desc->setFontIndex(fIndex);
         *isLocal = !this->isSysFont();
     }
 
+    int getIndex() const { return fIndex; }
+
 private:
-    bool fIsSysFont;
-    SkString fFamilyName;
+    const bool fIsSysFont;
+    const SkString fFamilyName;
+    const int fIndex;
 
     typedef SkTypeface_FreeType INHERITED;
 };
@@ -62,7 +67,7 @@
  */
 class SkTypeface_Empty : public SkTypeface_Custom {
 public:
-    SkTypeface_Empty() : INHERITED(SkTypeface::kNormal, false, true, SkString()) {}
+    SkTypeface_Empty() : INHERITED(SkTypeface::kNormal, false, true, SkString(), 0) {}
 
     virtual const char* getUniqueString() const SK_OVERRIDE { return NULL; }
 
@@ -78,21 +83,20 @@
 public:
     SkTypeface_Stream(Style style, bool isFixedPitch, bool sysFont, const SkString familyName,
                       SkStream* stream, int ttcIndex)
-        : INHERITED(style, isFixedPitch, sysFont, familyName)
-        , fStream(SkRef(stream)), fTtcIndex(ttcIndex)
+        : INHERITED(style, isFixedPitch, sysFont, familyName, ttcIndex)
+        , fStream(SkRef(stream))
     { }
 
     virtual const char* getUniqueString() const SK_OVERRIDE { return NULL; }
 
 protected:
     virtual SkStream* onOpenStream(int* ttcIndex) const SK_OVERRIDE {
-        *ttcIndex = 0;
+        *ttcIndex = this->getIndex();
         return fStream->duplicate();
     }
 
 private:
-    SkAutoTUnref<SkStream> fStream;
-    int fTtcIndex;
+    const SkAutoTUnref<const SkStream> fStream;
 
     typedef SkTypeface_Custom INHERITED;
 };
@@ -101,8 +105,8 @@
 class SkTypeface_File : public SkTypeface_Custom {
 public:
     SkTypeface_File(Style style, bool isFixedPitch, bool sysFont, const SkString familyName,
-                    const char path[])
-        : INHERITED(style, isFixedPitch, sysFont, familyName)
+                    const char path[], int index)
+        : INHERITED(style, isFixedPitch, sysFont, familyName, index)
         , fPath(path)
     { }
 
@@ -116,7 +120,7 @@
 
 protected:
     virtual SkStream* onOpenStream(int* ttcIndex) const SK_OVERRIDE {
-        *ttcIndex = 0;
+        *ttcIndex = this->getIndex();
         return SkStream::NewFromFile(fPath.c_str());
     }
 
@@ -343,7 +347,7 @@
                                                 isFixedPitch,
                                                 true,  // system-font (cannot delete)
                                                 realname,
-                                                filename.c_str()));
+                                                filename.c_str(), 0));
 
             SkFontStyleSet_Custom* addTo = this->onMatchFamily(realname.c_str());
             if (NULL == addTo) {
diff --git a/src/ports/SkFontMgr_android.cpp b/src/ports/SkFontMgr_android.cpp
index 2fee735..5e93bf8 100644
--- a/src/ports/SkFontMgr_android.cpp
+++ b/src/ports/SkFontMgr_android.cpp
@@ -81,6 +81,7 @@
         SkASSERT(serialize);
         desc->setFamilyName(fFamilyName.c_str());
         desc->setFontFileName(fPathName.c_str());
+        desc->setFontIndex(fIndex);
         *serialize = false;
     }
     virtual SkStream* onOpenStream(int* ttcIndex) const SK_OVERRIDE {
diff --git a/src/ports/SkFontMgr_fontconfig.cpp b/src/ports/SkFontMgr_fontconfig.cpp
index f4cae23..00b962a 100644
--- a/src/ports/SkFontMgr_fontconfig.cpp
+++ b/src/ports/SkFontMgr_fontconfig.cpp
@@ -394,7 +394,7 @@
     }
 
     virtual void onGetFontDescriptor(SkFontDescriptor* desc, bool* serialize) const SK_OVERRIDE {
-        desc->setStyle(this->style());
+        desc->setFontIndex(fIndex);
         *serialize = true;
     }
 
@@ -425,10 +425,10 @@
     virtual void onGetFontDescriptor(SkFontDescriptor* desc, bool* serialize) const SK_OVERRIDE {
         FCLocker lock;
         desc->setFamilyName(get_string(fPattern, FC_FAMILY));
-        desc->setFontFileName(get_string(fPattern, FC_FILE));
         desc->setFullName(get_string(fPattern, FC_FULLNAME));
         desc->setPostscriptName(get_string(fPattern, FC_POSTSCRIPT_NAME));
-        desc->setStyle(this->style());
+        desc->setFontFileName(get_string(fPattern, FC_FILE));
+        desc->setFontIndex(get_int(fPattern, FC_INDEX, 0));
         *serialize = false;
     }
 
diff --git a/src/ports/SkTypeface_win_dw.cpp b/src/ports/SkTypeface_win_dw.cpp
index 9c2b41d..8b9ed16 100644
--- a/src/ports/SkTypeface_win_dw.cpp
+++ b/src/ports/SkTypeface_win_dw.cpp
@@ -42,6 +42,7 @@
     sk_get_locale_string(familyNames.get(), NULL/*fMgr->fLocaleName.get()*/, &utf8FamilyName);
 
     desc->setFamilyName(utf8FamilyName.c_str());
+    desc->setFontIndex(fDWriteFontFace->GetIndex());
     *isLocalStream = SkToBool(fDWriteFontFileLoader.get());
 }