diff options
author | 2013-08-01 22:29:43 +0000 | |
---|---|---|
committer | 2013-08-01 22:29:43 +0000 | |
commit | ddc218e508c4cdd16ff3461498cbbc2b5189b2be (patch) | |
tree | b7e828ff67a84857463dc01daafb1f68324099a8 | |
parent | 35a20a16ddcb07bd8d847cfca8f7713d0ac93f3f (diff) |
Implement onGetTableTags and onGetTableData on Windows.
Implements these and removes default implementation, making the
declaration in SkTypeface pure virtual.
Review URL: https://codereview.chromium.org/20672004
git-svn-id: http://skia.googlecode.com/svn/trunk@10500 2bbb7eff-a529-9590-31e7-b0007b416f81
-rw-r--r-- | include/core/SkTypeface.h | 12 | ||||
-rw-r--r-- | src/core/SkTypeface.cpp | 16 | ||||
-rw-r--r-- | src/ports/SkFontConfigTypeface.h | 3 | ||||
-rw-r--r-- | src/ports/SkFontHost_FreeType.cpp | 58 | ||||
-rw-r--r-- | src/ports/SkFontHost_FreeType_common.h | 4 | ||||
-rw-r--r-- | src/ports/SkFontHost_fontconfig.cpp | 18 |
6 files changed, 64 insertions, 47 deletions
diff --git a/include/core/SkTypeface.h b/include/core/SkTypeface.h index 44abdd3b3a..3cfa6ac3c6 100644 --- a/include/core/SkTypeface.h +++ b/include/core/SkTypeface.h @@ -22,6 +22,7 @@ class SkAdvancedTypefaceMetrics; class SkWStream; typedef uint32_t SkFontID; +/** Machine endian. */ typedef uint32_t SkFontTableTag; /** \class SkTypeface @@ -294,16 +295,11 @@ protected: virtual int onGetUPEM() const = 0; - virtual int onGetTableTags(SkFontTableTag tags[]) const; + virtual int onGetTableTags(SkFontTableTag tags[]) const = 0; virtual size_t onGetTableData(SkFontTableTag, size_t offset, - size_t length, void* data) const; + size_t length, void* data) const = 0; - // TODO: make this pure-virtual when all ports have overridden it - virtual SkTypeface* onRefMatchingStyle(Style styleBits) const { - SkASSERT(0); - this->ref(); - return const_cast<SkTypeface*>(this); - } + virtual SkTypeface* onRefMatchingStyle(Style styleBits) const = 0; private: SkFontID fUniqueID; diff --git a/src/core/SkTypeface.cpp b/src/core/SkTypeface.cpp index 2d0471837e..34ff853c5c 100644 --- a/src/core/SkTypeface.cpp +++ b/src/core/SkTypeface.cpp @@ -8,7 +8,6 @@ #include "SkAdvancedTypefaceMetrics.h" #include "SkFontDescriptor.h" #include "SkFontHost.h" -#include "SkFontStream.h" #include "SkStream.h" #include "SkTypeface.h" @@ -224,18 +223,3 @@ int SkTypeface::onCharsToGlyphs(const void* chars, Encoding encoding, } return 0; } - -int SkTypeface::onGetTableTags(SkFontTableTag tags[]) const { - int ttcIndex; - SkAutoTUnref<SkStream> stream(this->openStream(&ttcIndex)); - return stream.get() ? SkFontStream::GetTableTags(stream, ttcIndex, tags) : 0; -} - -size_t SkTypeface::onGetTableData(SkFontTableTag tag, size_t offset, - size_t length, void* data) const { - int ttcIndex; - SkAutoTUnref<SkStream> stream(this->openStream(&ttcIndex)); - return stream.get() - ? SkFontStream::GetTableData(stream, ttcIndex, tag, offset, length, data) - : 0; -} diff --git a/src/ports/SkFontConfigTypeface.h b/src/ports/SkFontConfigTypeface.h index e9f9a13c1e..e1b6c18227 100644 --- a/src/ports/SkFontConfigTypeface.h +++ b/src/ports/SkFontConfigTypeface.h @@ -55,9 +55,6 @@ public: protected: friend class SkFontHost; // hack until we can make public versions - virtual int onGetTableTags(SkFontTableTag tags[]) const SK_OVERRIDE; - virtual size_t onGetTableData(SkFontTableTag, size_t offset, - size_t length, void* data) const SK_OVERRIDE; virtual void onGetFontDescriptor(SkFontDescriptor*, bool*) const SK_OVERRIDE; virtual SkStream* onOpenStream(int* ttcIndex) const SK_OVERRIDE; virtual SkTypeface* onRefMatchingStyle(Style) const SK_OVERRIDE; diff --git a/src/ports/SkFontHost_FreeType.cpp b/src/ports/SkFontHost_FreeType.cpp index d5a435d423..f94ac82ca7 100644 --- a/src/ports/SkFontHost_FreeType.cpp +++ b/src/ports/SkFontHost_FreeType.cpp @@ -203,8 +203,6 @@ private: /////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////// -#include "SkStream.h" - struct SkFaceRec { SkFaceRec* fNext; FT_Face fFace; @@ -1404,6 +1402,62 @@ int SkTypeface_FreeType::onCountGlyphs() const { return fGlyphCount; } +int SkTypeface_FreeType::onGetTableTags(SkFontTableTag tags[]) const { + AutoFTAccess fta(this); + FT_Face face = fta.face(); + + FT_ULong tableCount = 0; + FT_Error error; + + // When 'tag' is NULL, returns number of tables in 'length'. + error = FT_Sfnt_Table_Info(face, 0, NULL, &tableCount); + if (error) { + return 0; + } + + if (tags) { + for (FT_ULong tableIndex = 0; tableIndex < tableCount; ++tableIndex) { + FT_ULong tableTag; + FT_ULong tablelength; + error = FT_Sfnt_Table_Info(face, tableIndex, &tableTag, &tablelength); + if (error) { + return 0; + } + tags[tableIndex] = static_cast<SkFontTableTag>(tableTag); + } + } + return tableCount; +} + +size_t SkTypeface_FreeType::onGetTableData(SkFontTableTag tag, size_t offset, + size_t length, void* data) const +{ + AutoFTAccess fta(this); + FT_Face face = fta.face(); + + FT_ULong tableLength = 0; + FT_Error error; + + // When 'length' is 0 it is overwritten with the full table length; 'offset' is ignored. + error = FT_Load_Sfnt_Table(face, tag, 0, NULL, &tableLength); + if (error) { + return 0; + } + + if (offset > tableLength) { + return 0; + } + FT_ULong size = SkTMin(length, tableLength - offset); + if (NULL != data) { + error = FT_Load_Sfnt_Table(face, tag, offset, reinterpret_cast<FT_Byte*>(data), &size); + if (error) { + return 0; + } + } + + return size; +} + /////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////// diff --git a/src/ports/SkFontHost_FreeType_common.h b/src/ports/SkFontHost_FreeType_common.h index 6bd3532d66..d3df9ce85b 100644 --- a/src/ports/SkFontHost_FreeType_common.h +++ b/src/ports/SkFontHost_FreeType_common.h @@ -64,6 +64,10 @@ protected: int glyphCount) const SK_OVERRIDE; virtual int onCountGlyphs() const SK_OVERRIDE; + virtual int onGetTableTags(SkFontTableTag tags[]) const SK_OVERRIDE; + virtual size_t onGetTableData(SkFontTableTag, size_t offset, + size_t length, void* data) const SK_OVERRIDE; + private: mutable int fGlyphCount; diff --git a/src/ports/SkFontHost_fontconfig.cpp b/src/ports/SkFontHost_fontconfig.cpp index 2826c6e783..1625b8aa81 100644 --- a/src/ports/SkFontHost_fontconfig.cpp +++ b/src/ports/SkFontHost_fontconfig.cpp @@ -184,24 +184,6 @@ SkStream* FontConfigTypeface::onOpenStream(int* ttcIndex) const { return stream; } -int FontConfigTypeface::onGetTableTags(SkFontTableTag tags[]) const { - int ttcIndex; - SkAutoTUnref<SkStream> stream(this->openStream(&ttcIndex)); - return stream.get() - ? SkFontStream::GetTableTags(stream, ttcIndex, tags) - : 0; -} - -size_t FontConfigTypeface::onGetTableData(SkFontTableTag tag, size_t offset, - size_t length, void* data) const { - int ttcIndex; - SkAutoTUnref<SkStream> stream(this->openStream(&ttcIndex)); - return stream.get() - ? SkFontStream::GetTableData(stream, ttcIndex, - tag, offset, length, data) - : 0; -} - void FontConfigTypeface::onGetFontDescriptor(SkFontDescriptor* desc, bool* isLocalStream) const { desc->setFamilyName(this->getFamilyName()); |