Index: src/ports/SkFontMgr_fontconfig.cpp |
diff --git a/src/ports/SkFontMgr_fontconfig.cpp b/src/ports/SkFontMgr_fontconfig.cpp |
index f03e5acaf1382d50fc6ababd4d682f7cabacd632..3baec41cb541d0a0a5b2a40f9423f35431cd14e3 100644 |
--- a/src/ports/SkFontMgr_fontconfig.cpp |
+++ b/src/ports/SkFontMgr_fontconfig.cpp |
@@ -375,11 +375,10 @@ static void fcpattern_from_skfontstyle(SkFontStyle style, FcPattern* pattern) { |
class SkTypeface_stream : public SkTypeface_FreeType { |
public: |
- /** @param stream does not take ownership of the reference, does take ownership of the stream.*/ |
- SkTypeface_stream(const SkFontStyle& style, bool fixedWidth, int index, SkStreamAsset* stream) |
+ /** @param data takes ownership of the font data.*/ |
+ SkTypeface_stream(SkFontData* data, const SkFontStyle& style, bool fixedWidth) |
: INHERITED(style, SkTypefaceCache::NewFontID(), fixedWidth) |
- , fStream(stream) |
- , fIndex(index) |
+ , fData(data) |
{ }; |
void onGetFamilyName(SkString* familyName) const override { |
@@ -387,18 +386,20 @@ public: |
} |
void onGetFontDescriptor(SkFontDescriptor* desc, bool* serialize) const override { |
- desc->setFontIndex(fIndex); |
*serialize = true; |
} |
SkStreamAsset* onOpenStream(int* ttcIndex) const override { |
- *ttcIndex = fIndex; |
- return fStream->duplicate(); |
+ *ttcIndex = fData->getIndex(); |
+ return fData->duplicateStream(); |
+ } |
+ |
+ SkFontData* onCreateFontData() const override { |
+ return new SkFontData(*fData.get()); |
} |
private: |
- SkAutoTDelete<SkStreamAsset> fStream; |
- int fIndex; |
+ const SkAutoTDelete<const SkFontData> fData; |
typedef SkTypeface_FreeType INHERITED; |
}; |
@@ -420,7 +421,6 @@ public: |
desc->setFamilyName(get_string(fPattern, FC_FAMILY)); |
desc->setFullName(get_string(fPattern, FC_FULLNAME)); |
desc->setPostscriptName(get_string(fPattern, FC_POSTSCRIPT_NAME)); |
- desc->setFontIndex(get_int(fPattern, FC_INDEX, 0)); |
*serialize = false; |
} |
@@ -822,12 +822,12 @@ protected: |
SkFontStyle style; |
bool isFixedWidth = false; |
- if (!fScanner.scanFont(stream, ttcIndex, NULL, &style, &isFixedWidth)) { |
+ if (!fScanner.scanFont(stream, ttcIndex, NULL, &style, &isFixedWidth, NULL)) { |
return NULL; |
} |
- return SkNEW_ARGS(SkTypeface_stream, (style, isFixedWidth, ttcIndex, |
- static_cast<SkStreamAsset*>(stream.detach()))); |
+ return SkNEW_ARGS(SkTypeface_stream, (new SkFontData(stream.detach(), ttcIndex, NULL, 0), |
+ style, isFixedWidth)); |
} |
SkTypeface* onCreateFromData(SkData* data, int ttcIndex) const override { |
@@ -838,6 +838,23 @@ protected: |
return this->createFromStream(SkStream::NewFromFile(path), ttcIndex); |
} |
+ SkTypeface* onCreateFromFontData(SkFontData* fontData) const override { |
+ SkStreamAsset* stream(fontData->getStream()); |
+ const size_t length = stream->getLength(); |
+ if (length <= 0 || (1u << 30) < length) { |
+ return NULL; |
+ } |
+ |
+ const int ttcIndex = fontData->getIndex(); |
+ SkFontStyle style; |
+ bool isFixedWidth = false; |
+ if (!fScanner.scanFont(stream, ttcIndex, NULL, &style, &isFixedWidth, NULL)) { |
+ return NULL; |
+ } |
+ |
+ return SkNEW_ARGS(SkTypeface_stream, (fontData, style, isFixedWidth)); |
+ } |
+ |
virtual SkTypeface* onLegacyCreateTypeface(const char familyName[], |
unsigned styleBits) const override { |
bool bold = styleBits & SkTypeface::kBold; |