aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/core/SkTypeface.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/core/SkTypeface.cpp')
-rw-r--r--src/core/SkTypeface.cpp28
1 files changed, 20 insertions, 8 deletions
diff --git a/src/core/SkTypeface.cpp b/src/core/SkTypeface.cpp
index 0f5d70b1a8..342c41553d 100644
--- a/src/core/SkTypeface.cpp
+++ b/src/core/SkTypeface.cpp
@@ -143,6 +143,11 @@ SkTypeface* SkTypeface::CreateFromStream(SkStreamAsset* stream, int index) {
return fm->createFromStream(stream, index);
}
+SkTypeface* SkTypeface::CreateFromFontData(SkFontData* data) {
+ SkAutoTUnref<SkFontMgr> fm(SkFontMgr::RefDefault());
+ return fm->createFromFontData(data);
+}
+
SkTypeface* SkTypeface::CreateFromFile(const char path[], int index) {
SkAutoTUnref<SkFontMgr> fm(SkFontMgr::RefDefault());
return fm->createFromFile(path, index);
@@ -157,9 +162,7 @@ void SkTypeface::serialize(SkWStream* wstream) const {
// Embed font data if it's a local font.
if (isLocal && !desc.hasFontData()) {
- int ttcIndex;
- desc.setFontData(this->onOpenStream(&ttcIndex));
- desc.setFontIndex(ttcIndex);
+ desc.setFontData(this->onCreateFontData());
}
desc.serialize(wstream);
}
@@ -171,18 +174,16 @@ void SkTypeface::serializeForcingEmbedding(SkWStream* wstream) const {
// Always embed font data.
if (!desc.hasFontData()) {
- int ttcIndex;
- desc.setFontData(this->onOpenStream(&ttcIndex));
- desc.setFontIndex(ttcIndex);
+ desc.setFontData(this->onCreateFontData());
}
desc.serialize(wstream);
}
SkTypeface* SkTypeface::Deserialize(SkStream* stream) {
SkFontDescriptor desc(stream);
- SkStreamAsset* data = desc.transferFontData();
+ SkFontData* data = desc.detachFontData();
if (data) {
- SkTypeface* typeface = SkTypeface::CreateFromStream(data, desc.getFontIndex());
+ SkTypeface* typeface = SkTypeface::CreateFromFontData(data);
if (typeface) {
return typeface;
}
@@ -218,6 +219,17 @@ SkStreamAsset* SkTypeface::openStream(int* ttcIndex) const {
return this->onOpenStream(ttcIndex);
}
+SkFontData* SkTypeface::createFontData() const {
+ return this->onCreateFontData();
+}
+
+// This implementation is temporary until this method can be made pure virtual.
+SkFontData* SkTypeface::onCreateFontData() const {
+ int index;
+ SkAutoTDelete<SkStreamAsset> stream(this->onOpenStream(&index));
+ return new SkFontData(stream.detach(), index, NULL, 0);
+};
+
int SkTypeface::charsToGlyphs(const void* chars, Encoding encoding,
uint16_t glyphs[], int glyphCount) const {
if (glyphCount <= 0) {