diff options
author | bungeman <bungeman@google.com> | 2014-09-17 07:48:59 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2014-09-17 07:48:59 -0700 |
commit | b374d6a62c0259387d90cad74753d8bad9ee1bea (patch) | |
tree | fd558326c3254d6be22818cab97f18e3223669c2 /src/ports | |
parent | 3850971d54b2e07cbf69e282d1455ea1dc3333b6 (diff) |
Add onGetFamilyName to SkTypeface.
This speeds up and documents this particular feature of SkTypeface
and also frees up SkFontDescriptor to be used only in serialization.
R=reed@google.com
Author: bungeman@google.com
Review URL: https://codereview.chromium.org/574873002
Diffstat (limited to 'src/ports')
-rw-r--r-- | src/ports/SkFontConfigTypeface.h | 1 | ||||
-rw-r--r-- | src/ports/SkFontHost_fontconfig.cpp | 4 | ||||
-rw-r--r-- | src/ports/SkFontHost_linux.cpp | 4 | ||||
-rwxr-xr-x | src/ports/SkFontHost_mac.cpp | 5 | ||||
-rwxr-xr-x | src/ports/SkFontHost_win.cpp | 12 | ||||
-rw-r--r-- | src/ports/SkFontMgr_android.cpp | 6 | ||||
-rw-r--r-- | src/ports/SkFontMgr_fontconfig.cpp | 8 | ||||
-rw-r--r-- | src/ports/SkTypeface_win_dw.cpp | 16 | ||||
-rw-r--r-- | src/ports/SkTypeface_win_dw.h | 1 |
9 files changed, 44 insertions, 13 deletions
diff --git a/src/ports/SkFontConfigTypeface.h b/src/ports/SkFontConfigTypeface.h index b6f8797eb7..f62d99d2f4 100644 --- a/src/ports/SkFontConfigTypeface.h +++ b/src/ports/SkFontConfigTypeface.h @@ -65,6 +65,7 @@ protected: SkSafeRef(localStream); } + virtual void onGetFamilyName(SkString* familyName) const SK_OVERRIDE; virtual void onGetFontDescriptor(SkFontDescriptor*, bool*) const SK_OVERRIDE; virtual SkStream* onOpenStream(int* ttcIndex) const SK_OVERRIDE; diff --git a/src/ports/SkFontHost_fontconfig.cpp b/src/ports/SkFontHost_fontconfig.cpp index ace7058714..57252d0c18 100644 --- a/src/ports/SkFontHost_fontconfig.cpp +++ b/src/ports/SkFontHost_fontconfig.cpp @@ -162,6 +162,10 @@ SkStream* FontConfigTypeface::onOpenStream(int* ttcIndex) const { return stream; } +void FontConfigTypeface::onGetFamilyName(SkString* familyName) const { + *familyName = this->getFamilyName(); +} + void FontConfigTypeface::onGetFontDescriptor(SkFontDescriptor* desc, bool* isLocalStream) const { desc->setFamilyName(this->getFamilyName()); diff --git a/src/ports/SkFontHost_linux.cpp b/src/ports/SkFontHost_linux.cpp index 72a6399612..2904cac9bc 100644 --- a/src/ports/SkFontHost_linux.cpp +++ b/src/ports/SkFontHost_linux.cpp @@ -40,6 +40,10 @@ public: virtual const char* getUniqueString() const = 0; protected: + virtual void onGetFamilyName(SkString* familyName) const SK_OVERRIDE { + *familyName = fFamilyName; + } + virtual void onGetFontDescriptor(SkFontDescriptor* desc, bool* isLocal) const SK_OVERRIDE { desc->setFamilyName(fFamilyName.c_str()); desc->setFontFileName(this->getUniqueString()); diff --git a/src/ports/SkFontHost_mac.cpp b/src/ports/SkFontHost_mac.cpp index 3c73493b41..5386ac3f3e 100755 --- a/src/ports/SkFontHost_mac.cpp +++ b/src/ports/SkFontHost_mac.cpp @@ -452,6 +452,7 @@ protected: virtual int onGetUPEM() const SK_OVERRIDE; virtual SkStream* onOpenStream(int* ttcIndex) const SK_OVERRIDE; + virtual void onGetFamilyName(SkString* familyName) const SK_OVERRIDE; virtual SkTypeface::LocalizedStrings* onCreateFamilyNameIterator() const SK_OVERRIDE; virtual int onGetTableTags(SkFontTableTag tags[]) const SK_OVERRIDE; virtual size_t onGetTableData(SkFontTableTag, size_t offset, @@ -1900,6 +1901,10 @@ static const char* get_str(CFStringRef ref, SkString* str) { return str->c_str(); } +void SkTypeface_Mac::onGetFamilyName(SkString* familyName) const { + get_str(CTFontCopyFamilyName(fFontRef), familyName); +} + void SkTypeface_Mac::onGetFontDescriptor(SkFontDescriptor* desc, bool* isLocalStream) const { SkString tmpStr; diff --git a/src/ports/SkFontHost_win.cpp b/src/ports/SkFontHost_win.cpp index 6f8669e40c..1290c007a5 100755 --- a/src/ports/SkFontHost_win.cpp +++ b/src/ports/SkFontHost_win.cpp @@ -276,6 +276,7 @@ protected: uint16_t glyphs[], int glyphCount) const SK_OVERRIDE; virtual int onCountGlyphs() const SK_OVERRIDE; virtual int onGetUPEM() const SK_OVERRIDE; + virtual void onGetFamilyName(SkString* familyName) const SK_OVERRIDE; virtual SkTypeface::LocalizedStrings* onCreateFamilyNameIterator() const SK_OVERRIDE; virtual int onGetTableTags(SkFontTableTag tags[]) const SK_OVERRIDE; virtual size_t onGetTableData(SkFontTableTag, size_t offset, @@ -1761,16 +1762,14 @@ static void logfont_for_name(const char* familyName, LOGFONT* lf) { #endif } -void LogFontTypeface::onGetFontDescriptor(SkFontDescriptor* desc, - bool* isLocalStream) const { +void LogFontTypeface::onGetFamilyName(SkString* familyName) const { // Get the actual name of the typeface. The logfont may not know this. HFONT font = CreateFontIndirect(&fLogFont); HDC deviceContext = ::CreateCompatibleDC(NULL); HFONT savefont = (HFONT)SelectObject(deviceContext, font); - SkString familyName; - dcfontname_to_skstring(deviceContext, fLogFont, &familyName); + dcfontname_to_skstring(deviceContext, fLogFont, familyName); if (deviceContext) { ::SelectObject(deviceContext, savefont); @@ -1779,7 +1778,12 @@ void LogFontTypeface::onGetFontDescriptor(SkFontDescriptor* desc, if (font) { ::DeleteObject(font); } +} +void LogFontTypeface::onGetFontDescriptor(SkFontDescriptor* desc, + bool* isLocalStream) const { + SkString familyName; + this->onGetFamilyName(&familyName); desc->setFamilyName(familyName.c_str()); *isLocalStream = this->fSerializeAsStream; } diff --git a/src/ports/SkFontMgr_android.cpp b/src/ports/SkFontMgr_android.cpp index bcf544cd43..2fee7356f1 100644 --- a/src/ports/SkFontMgr_android.cpp +++ b/src/ports/SkFontMgr_android.cpp @@ -49,9 +49,11 @@ public: , fIndex(index) , fFamilyName(familyName) { } - const SkString& name() const { return fFamilyName; } - protected: + virtual void onGetFamilyName(SkString* familyName) const SK_OVERRIDE { + *familyName = fFamilyName; + } + int fIndex; SkString fFamilyName; diff --git a/src/ports/SkFontMgr_fontconfig.cpp b/src/ports/SkFontMgr_fontconfig.cpp index b8a3fe5b0d..f4cae23e03 100644 --- a/src/ports/SkFontMgr_fontconfig.cpp +++ b/src/ports/SkFontMgr_fontconfig.cpp @@ -389,6 +389,10 @@ public: , fIndex(ttcIndex) { }; + virtual void onGetFamilyName(SkString* familyName) const SK_OVERRIDE { + familyName->reset(); + } + virtual void onGetFontDescriptor(SkFontDescriptor* desc, bool* serialize) const SK_OVERRIDE { desc->setStyle(this->style()); *serialize = true; @@ -414,6 +418,10 @@ public: } mutable SkAutoFcPattern fPattern; + virtual void onGetFamilyName(SkString* familyName) const SK_OVERRIDE { + *familyName = get_string(fPattern, FC_FAMILY); + } + virtual void onGetFontDescriptor(SkFontDescriptor* desc, bool* serialize) const SK_OVERRIDE { FCLocker lock; desc->setFamilyName(get_string(fPattern, FC_FAMILY)); diff --git a/src/ports/SkTypeface_win_dw.cpp b/src/ports/SkTypeface_win_dw.cpp index 9c727e715e..9c2b41d44c 100644 --- a/src/ports/SkTypeface_win_dw.cpp +++ b/src/ports/SkTypeface_win_dw.cpp @@ -12,6 +12,7 @@ // not use GDI, undefing GetGlyphIndices makes things less confusing. #undef GetGlyphIndices +#include "SkDWrite.h" #include "SkDWriteFontFileStream.h" #include "SkFontDescriptor.h" #include "SkFontStream.h" @@ -24,20 +25,21 @@ #include "SkTypeface_win_dw.h" #include "SkUtils.h" +void DWriteFontTypeface::onGetFamilyName(SkString* familyName) const { + SkTScopedComPtr<IDWriteLocalizedStrings> familyNames; + HRV(fDWriteFontFamily->GetFamilyNames(&familyNames)); + + sk_get_locale_string(familyNames.get(), NULL/*fMgr->fLocaleName.get()*/, familyName); +} + void DWriteFontTypeface::onGetFontDescriptor(SkFontDescriptor* desc, bool* isLocalStream) const { // Get the family name. SkTScopedComPtr<IDWriteLocalizedStrings> familyNames; HRV(fDWriteFontFamily->GetFamilyNames(&familyNames)); - UINT32 familyNamesLen; - HRV(familyNames->GetStringLength(0, &familyNamesLen)); - - SkSMallocWCHAR familyName(familyNamesLen+1); - HRV(familyNames->GetString(0, familyName.get(), familyNamesLen+1)); - SkString utf8FamilyName; - HRV(sk_wchar_to_skstring(familyName.get(), familyNamesLen, &utf8FamilyName)); + sk_get_locale_string(familyNames.get(), NULL/*fMgr->fLocaleName.get()*/, &utf8FamilyName); desc->setFamilyName(utf8FamilyName.c_str()); *isLocalStream = SkToBool(fDWriteFontFileLoader.get()); diff --git a/src/ports/SkTypeface_win_dw.h b/src/ports/SkTypeface_win_dw.h index 650685825d..531dc51a11 100644 --- a/src/ports/SkTypeface_win_dw.h +++ b/src/ports/SkTypeface_win_dw.h @@ -111,6 +111,7 @@ protected: uint16_t glyphs[], int glyphCount) const SK_OVERRIDE; virtual int onCountGlyphs() const SK_OVERRIDE; virtual int onGetUPEM() const SK_OVERRIDE; + virtual void onGetFamilyName(SkString* familyName) const SK_OVERRIDE; virtual SkTypeface::LocalizedStrings* onCreateFamilyNameIterator() const SK_OVERRIDE; virtual int onGetTableTags(SkFontTableTag tags[]) const SK_OVERRIDE; virtual size_t onGetTableData(SkFontTableTag, size_t offset, |