diff options
-rw-r--r-- | gyp/core.gypi | 2 | ||||
-rw-r--r-- | src/core/SkFontHost.cpp | 174 | ||||
-rw-r--r-- | src/core/SkFontMgr.cpp | 157 | ||||
-rw-r--r-- | src/core/SkFontStyle.cpp | 33 |
4 files changed, 192 insertions, 174 deletions
diff --git a/gyp/core.gypi b/gyp/core.gypi index e7738af8bb..48228515fb 100644 --- a/gyp/core.gypi +++ b/gyp/core.gypi @@ -94,6 +94,8 @@ '<(skia_src_path)/core/SkFloatBits.cpp', '<(skia_src_path)/core/SkFont.cpp', '<(skia_src_path)/core/SkFontHost.cpp', + '<(skia_src_path)/core/SkFontMgr.cpp', + '<(skia_src_path)/core/SkFontStyle.cpp', '<(skia_src_path)/core/SkFontDescriptor.cpp', '<(skia_src_path)/core/SkFontDescriptor.h', '<(skia_src_path)/core/SkFontStream.cpp', diff --git a/src/core/SkFontHost.cpp b/src/core/SkFontHost.cpp index 8092a590c2..4f0dc8637d 100644 --- a/src/core/SkFontHost.cpp +++ b/src/core/SkFontHost.cpp @@ -6,7 +6,6 @@ */ #include "SkFontLCDConfig.h" -#include "SkLazyPtr.h" static SkFontLCDConfig::LCDOrientation gLCDOrientation = SkFontLCDConfig::kHorizontal_LCDOrientation; static SkFontLCDConfig::LCDOrder gLCDOrder = SkFontLCDConfig::kRGB_LCDOrder; @@ -47,176 +46,3 @@ SkFontHost::LCDOrder SkFontHost::GetSubpixelOrder() { void SkFontHost::SetSubpixelOrder(LCDOrder order) { SkFontLCDConfig::SetSubpixelOrder((SkFontLCDConfig::LCDOrder)order); } - -/////////////////////////////////////////////////////////////////////////////// -/////////////////////////////////////////////////////////////////////////////// - -#include "SkFontStyle.h" - -SkFontStyle::SkFontStyle() { - fUnion.fU32 = 0; - fUnion.fR.fWeight = kNormal_Weight; - fUnion.fR.fWidth = kNormal_Width; - fUnion.fR.fSlant = kUpright_Slant; -} - -SkFontStyle::SkFontStyle(int weight, int width, Slant slant) { - fUnion.fU32 = 0; - fUnion.fR.fWeight = SkPin32(weight, kThin_Weight, kBlack_Weight); - fUnion.fR.fWidth = SkPin32(width, kUltraCondensed_Width, kUltaExpanded_Width); - fUnion.fR.fSlant = SkPin32(slant, kUpright_Slant, kItalic_Slant); -} - -SkFontStyle::SkFontStyle(unsigned oldStyle) { - fUnion.fU32 = 0; - fUnion.fR.fWeight = (oldStyle & SkTypeface::kBold) ? SkFontStyle::kBold_Weight - : SkFontStyle::kNormal_Weight; - fUnion.fR.fWidth = SkFontStyle::kNormal_Width; - fUnion.fR.fSlant = (oldStyle & SkTypeface::kItalic) ? SkFontStyle::kItalic_Slant - : SkFontStyle::kUpright_Slant; -} - -#include "SkFontMgr.h" - -class SkEmptyFontStyleSet : public SkFontStyleSet { -public: - int count() SK_OVERRIDE { return 0; } - void getStyle(int, SkFontStyle*, SkString*) SK_OVERRIDE { - SkDEBUGFAIL("SkFontStyleSet::getStyle called on empty set"); - } - SkTypeface* createTypeface(int index) SK_OVERRIDE { - SkDEBUGFAIL("SkFontStyleSet::createTypeface called on empty set"); - return NULL; - } - SkTypeface* matchStyle(const SkFontStyle&) SK_OVERRIDE { - return NULL; - } -}; - -SkFontStyleSet* SkFontStyleSet::CreateEmpty() { - return SkNEW(SkEmptyFontStyleSet); -} - -/////////////////////////////////////////////////////////////////////////////// - -class SkEmptyFontMgr : public SkFontMgr { -protected: - int onCountFamilies() const SK_OVERRIDE { - return 0; - } - void onGetFamilyName(int index, SkString* familyName) const SK_OVERRIDE { - SkDEBUGFAIL("onGetFamilyName called with bad index"); - } - SkFontStyleSet* onCreateStyleSet(int index) const SK_OVERRIDE { - SkDEBUGFAIL("onCreateStyleSet called with bad index"); - return NULL; - } - SkFontStyleSet* onMatchFamily(const char[]) const SK_OVERRIDE { - return SkFontStyleSet::CreateEmpty(); - } - - virtual SkTypeface* onMatchFamilyStyle(const char[], - const SkFontStyle&) const SK_OVERRIDE { - return NULL; - } - virtual SkTypeface* onMatchFamilyStyleCharacter(const char familyName[], - const SkFontStyle& style, - const char* bcp47[], - int bcp47Count, - SkUnichar character) const SK_OVERRIDE { - return NULL; - } - virtual SkTypeface* onMatchFaceStyle(const SkTypeface*, - const SkFontStyle&) const SK_OVERRIDE { - return NULL; - } - SkTypeface* onCreateFromData(SkData*, int) const SK_OVERRIDE { - return NULL; - } - SkTypeface* onCreateFromStream(SkStream*, int) const SK_OVERRIDE { - return NULL; - } - SkTypeface* onCreateFromFile(const char[], int) const SK_OVERRIDE { - return NULL; - } - SkTypeface* onLegacyCreateTypeface(const char [], unsigned) const SK_OVERRIDE { - return NULL; - } -}; - -static SkFontStyleSet* emptyOnNull(SkFontStyleSet* fsset) { - if (NULL == fsset) { - fsset = SkFontStyleSet::CreateEmpty(); - } - return fsset; -} - -int SkFontMgr::countFamilies() const { - return this->onCountFamilies(); -} - -void SkFontMgr::getFamilyName(int index, SkString* familyName) const { - this->onGetFamilyName(index, familyName); -} - -SkFontStyleSet* SkFontMgr::createStyleSet(int index) const { - return emptyOnNull(this->onCreateStyleSet(index)); -} - -SkFontStyleSet* SkFontMgr::matchFamily(const char familyName[]) const { - return emptyOnNull(this->onMatchFamily(familyName)); -} - -SkTypeface* SkFontMgr::matchFamilyStyle(const char familyName[], - const SkFontStyle& fs) const { - return this->onMatchFamilyStyle(familyName, fs); -} - -SkTypeface* SkFontMgr::matchFamilyStyleCharacter(const char familyName[], const SkFontStyle& style, - const char* bcp47[], int bcp47Count, - SkUnichar character) const { - return this->onMatchFamilyStyleCharacter(familyName, style, bcp47, bcp47Count, character); -} - -SkTypeface* SkFontMgr::matchFaceStyle(const SkTypeface* face, - const SkFontStyle& fs) const { - return this->onMatchFaceStyle(face, fs); -} - -SkTypeface* SkFontMgr::createFromData(SkData* data, int ttcIndex) const { - if (NULL == data) { - return NULL; - } - return this->onCreateFromData(data, ttcIndex); -} - -SkTypeface* SkFontMgr::createFromStream(SkStream* stream, int ttcIndex) const { - if (NULL == stream) { - return NULL; - } - return this->onCreateFromStream(stream, ttcIndex); -} - -SkTypeface* SkFontMgr::createFromFile(const char path[], int ttcIndex) const { - if (NULL == path) { - return NULL; - } - return this->onCreateFromFile(path, ttcIndex); -} - -SkTypeface* SkFontMgr::legacyCreateTypeface(const char familyName[], - unsigned styleBits) const { - return this->onLegacyCreateTypeface(familyName, styleBits); -} - -// As a template argument this must have external linkage. -SkFontMgr* sk_fontmgr_create_default() { - SkFontMgr* fm = SkFontMgr::Factory(); - return fm ? fm : SkNEW(SkEmptyFontMgr); -} - -SK_DECLARE_STATIC_LAZY_PTR(SkFontMgr, singleton, sk_fontmgr_create_default); - -SkFontMgr* SkFontMgr::RefDefault() { - return SkRef(singleton.get()); -} diff --git a/src/core/SkFontMgr.cpp b/src/core/SkFontMgr.cpp new file mode 100644 index 0000000000..ca29e293ef --- /dev/null +++ b/src/core/SkFontMgr.cpp @@ -0,0 +1,157 @@ +/* + * Copyright 2015 Google Inc. + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#include "SkFontMgr.h" +#include "SkLazyPtr.h" +#include "SkTypes.h" + +class SkFontStyle; +class SkStream; +class SkTypeface; + +class SkEmptyFontStyleSet : public SkFontStyleSet { +public: + int count() SK_OVERRIDE { return 0; } + void getStyle(int, SkFontStyle*, SkString*) SK_OVERRIDE { + SkDEBUGFAIL("SkFontStyleSet::getStyle called on empty set"); + } + SkTypeface* createTypeface(int index) SK_OVERRIDE { + SkDEBUGFAIL("SkFontStyleSet::createTypeface called on empty set"); + return NULL; + } + SkTypeface* matchStyle(const SkFontStyle&) SK_OVERRIDE { + return NULL; + } +}; + +SkFontStyleSet* SkFontStyleSet::CreateEmpty() { + return SkNEW(SkEmptyFontStyleSet); +} + +/////////////////////////////////////////////////////////////////////////////// + +class SkEmptyFontMgr : public SkFontMgr { +protected: + int onCountFamilies() const SK_OVERRIDE { + return 0; + } + void onGetFamilyName(int index, SkString* familyName) const SK_OVERRIDE { + SkDEBUGFAIL("onGetFamilyName called with bad index"); + } + SkFontStyleSet* onCreateStyleSet(int index) const SK_OVERRIDE { + SkDEBUGFAIL("onCreateStyleSet called with bad index"); + return NULL; + } + SkFontStyleSet* onMatchFamily(const char[]) const SK_OVERRIDE { + return SkFontStyleSet::CreateEmpty(); + } + + virtual SkTypeface* onMatchFamilyStyle(const char[], + const SkFontStyle&) const SK_OVERRIDE { + return NULL; + } + virtual SkTypeface* onMatchFamilyStyleCharacter(const char familyName[], + const SkFontStyle& style, + const char* bcp47[], + int bcp47Count, + SkUnichar character) const SK_OVERRIDE { + return NULL; + } + virtual SkTypeface* onMatchFaceStyle(const SkTypeface*, + const SkFontStyle&) const SK_OVERRIDE { + return NULL; + } + SkTypeface* onCreateFromData(SkData*, int) const SK_OVERRIDE { + return NULL; + } + SkTypeface* onCreateFromStream(SkStream*, int) const SK_OVERRIDE { + return NULL; + } + SkTypeface* onCreateFromFile(const char[], int) const SK_OVERRIDE { + return NULL; + } + SkTypeface* onLegacyCreateTypeface(const char [], unsigned) const SK_OVERRIDE { + return NULL; + } +}; + +static SkFontStyleSet* emptyOnNull(SkFontStyleSet* fsset) { + if (NULL == fsset) { + fsset = SkFontStyleSet::CreateEmpty(); + } + return fsset; +} + +int SkFontMgr::countFamilies() const { + return this->onCountFamilies(); +} + +void SkFontMgr::getFamilyName(int index, SkString* familyName) const { + this->onGetFamilyName(index, familyName); +} + +SkFontStyleSet* SkFontMgr::createStyleSet(int index) const { + return emptyOnNull(this->onCreateStyleSet(index)); +} + +SkFontStyleSet* SkFontMgr::matchFamily(const char familyName[]) const { + return emptyOnNull(this->onMatchFamily(familyName)); +} + +SkTypeface* SkFontMgr::matchFamilyStyle(const char familyName[], + const SkFontStyle& fs) const { + return this->onMatchFamilyStyle(familyName, fs); +} + +SkTypeface* SkFontMgr::matchFamilyStyleCharacter(const char familyName[], const SkFontStyle& style, + const char* bcp47[], int bcp47Count, + SkUnichar character) const { + return this->onMatchFamilyStyleCharacter(familyName, style, bcp47, bcp47Count, character); +} + +SkTypeface* SkFontMgr::matchFaceStyle(const SkTypeface* face, + const SkFontStyle& fs) const { + return this->onMatchFaceStyle(face, fs); +} + +SkTypeface* SkFontMgr::createFromData(SkData* data, int ttcIndex) const { + if (NULL == data) { + return NULL; + } + return this->onCreateFromData(data, ttcIndex); +} + +SkTypeface* SkFontMgr::createFromStream(SkStream* stream, int ttcIndex) const { + if (NULL == stream) { + return NULL; + } + return this->onCreateFromStream(stream, ttcIndex); +} + +SkTypeface* SkFontMgr::createFromFile(const char path[], int ttcIndex) const { + if (NULL == path) { + return NULL; + } + return this->onCreateFromFile(path, ttcIndex); +} + +SkTypeface* SkFontMgr::legacyCreateTypeface(const char familyName[], + unsigned styleBits) const { + return this->onLegacyCreateTypeface(familyName, styleBits); +} + +// As a template argument this must have external linkage. +SkFontMgr* sk_fontmgr_create_default() { + SkFontMgr* fm = SkFontMgr::Factory(); + return fm ? fm : SkNEW(SkEmptyFontMgr); +} + +SK_DECLARE_STATIC_LAZY_PTR(SkFontMgr, singleton, sk_fontmgr_create_default); + +SkFontMgr* SkFontMgr::RefDefault() { + return SkRef(singleton.get()); +} diff --git a/src/core/SkFontStyle.cpp b/src/core/SkFontStyle.cpp new file mode 100644 index 0000000000..285d17a2b0 --- /dev/null +++ b/src/core/SkFontStyle.cpp @@ -0,0 +1,33 @@ +/* + * Copyright 2015 Google Inc. + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#include "SkFontStyle.h" +#include "SkTypeface.h" +#include "SkTypes.h" + +SkFontStyle::SkFontStyle() { + fUnion.fU32 = 0; + fUnion.fR.fWeight = kNormal_Weight; + fUnion.fR.fWidth = kNormal_Width; + fUnion.fR.fSlant = kUpright_Slant; +} + +SkFontStyle::SkFontStyle(int weight, int width, Slant slant) { + fUnion.fU32 = 0; + fUnion.fR.fWeight = SkPin32(weight, kThin_Weight, kBlack_Weight); + fUnion.fR.fWidth = SkPin32(width, kUltraCondensed_Width, kUltaExpanded_Width); + fUnion.fR.fSlant = SkPin32(slant, kUpright_Slant, kItalic_Slant); +} + +SkFontStyle::SkFontStyle(unsigned oldStyle) { + fUnion.fU32 = 0; + fUnion.fR.fWeight = (oldStyle & SkTypeface::kBold) ? SkFontStyle::kBold_Weight + : SkFontStyle::kNormal_Weight; + fUnion.fR.fWidth = SkFontStyle::kNormal_Width; + fUnion.fR.fSlant = (oldStyle & SkTypeface::kItalic) ? SkFontStyle::kItalic_Slant + : SkFontStyle::kUpright_Slant; +} |