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_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) {