From 0042b9c2a2e6fe954cdfbcd5a5b7449cdf41a4c3 Mon Sep 17 00:00:00 2001 From: "reed@google.com" Date: Thu, 21 Mar 2013 20:16:04 +0000 Subject: override SkTypeface::onOpenStream() note: getTables APIs are not overridden yet, causing them to take the slow openstream case each time. We should fix this, since openStream for windows itself is slow (not native). Review URL: https://codereview.chromium.org/12941006 git-svn-id: http://skia.googlecode.com/svn/trunk@8306 2bbb7eff-a529-9590-31e7-b0007b416f81 --- src/ports/SkFontHost_win.cpp | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/src/ports/SkFontHost_win.cpp b/src/ports/SkFontHost_win.cpp index 76edd76c27..7040f7cb8b 100755 --- a/src/ports/SkFontHost_win.cpp +++ b/src/ports/SkFontHost_win.cpp @@ -210,6 +210,7 @@ public: } protected: + virtual SkStream* onOpenStream(int* ttcIndex) const SK_OVERRIDE; virtual SkScalerContext* onCreateScalerContext(const SkDescriptor*) const SK_OVERRIDE; virtual void onFilterRec(SkScalerContextRec*) const SK_OVERRIDE; virtual SkAdvancedTypefaceMetrics* onGetAdvancedTypefaceMetrics( @@ -1321,11 +1322,14 @@ void SkFontHost::Serialize(const SkTypeface* rawFace, SkWStream* stream) { if (face->fSerializeAsStream) { // store the entire font in the fontData - SkAutoTUnref fontStream(SkFontHost::OpenStream(face->uniqueID())); - const uint32_t length = fontStream->getLength(); - - stream->writePackedUInt(length); - stream->writeStream(fontStream, length); + SkAutoTUnref fontStream(face->openStream(NULL)); + if (fontStream.get()) { + const uint32_t length = fontStream->getLength(); + stream->writePackedUInt(length); + stream->writeStream(fontStream, length); + } else { + stream->writePackedUInt(0); + } } else { stream->writePackedUInt(0); } @@ -1588,11 +1592,12 @@ SkTypeface* SkFontHost::CreateTypefaceFromStream(SkStream* stream) { return SkCreateFontMemResourceTypefaceFromLOGFONT(lf, fontReference); } -SkStream* SkFontHost::OpenStream(SkFontID uniqueID) { +SkStream* LogFontTypeface::onOpenStream(int* ttcIndex) const { + *ttcIndex = 0; + const DWORD kTTCTag = SkEndian_SwapBE32(SkSetFourByteTag('t', 't', 'c', 'f')); - LOGFONT lf; - GetLogFontByID(uniqueID, &lf); + LOGFONT lf = fLogFont; HDC hdc = ::CreateCompatibleDC(NULL); HFONT font = CreateFontIndirect(&lf); @@ -1625,7 +1630,13 @@ SkStream* SkFontHost::OpenStream(SkFontID uniqueID) { return stream; } +SkStream* SkFontHost::OpenStream(SkFontID uniqueID) { + SkTypeface* typeface = SkTypefaceCache::FindByID(uniqueID); + return typeface ? typeface->openStream(NULL) : NULL; +} + size_t SkFontHost::GetFileName(SkFontID fontID, char path[], size_t length, int32_t* index) { + SkASSERT(!"SkFontHost::GetFileName is DEPRECATED\n"); return 0; } -- cgit v1.2.3