2 * Copyright 2009 The Android Open Source Project
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
8 #include "SkFontLCDConfig.h"
11 static SkFontLCDConfig::LCDOrientation gLCDOrientation = SkFontLCDConfig::kHorizontal_LCDOrientation;
12 static SkFontLCDConfig::LCDOrder gLCDOrder = SkFontLCDConfig::kRGB_LCDOrder;
14 SkFontLCDConfig::LCDOrientation SkFontLCDConfig::GetSubpixelOrientation() {
15 return gLCDOrientation;
18 void SkFontLCDConfig::SetSubpixelOrientation(LCDOrientation orientation) {
19 gLCDOrientation = orientation;
22 SkFontLCDConfig::LCDOrder SkFontLCDConfig::GetSubpixelOrder() {
26 void SkFontLCDConfig::SetSubpixelOrder(LCDOrder order) {
30 ///////////////////////////////////////////////////////////////////////////////
31 // Legacy wrappers : remove from SkFontHost when webkit switches to new API
33 #include "SkFontHost.h"
35 SkFontHost::LCDOrientation SkFontHost::GetSubpixelOrientation() {
36 return (SkFontHost::LCDOrientation)SkFontLCDConfig::GetSubpixelOrientation();
39 void SkFontHost::SetSubpixelOrientation(LCDOrientation orientation) {
40 SkFontLCDConfig::SetSubpixelOrientation((SkFontLCDConfig::LCDOrientation)orientation);
43 SkFontHost::LCDOrder SkFontHost::GetSubpixelOrder() {
44 return (SkFontHost::LCDOrder)SkFontLCDConfig::GetSubpixelOrder();
47 void SkFontHost::SetSubpixelOrder(LCDOrder order) {
48 SkFontLCDConfig::SetSubpixelOrder((SkFontLCDConfig::LCDOrder)order);
51 ///////////////////////////////////////////////////////////////////////////////
52 ///////////////////////////////////////////////////////////////////////////////
54 #include "SkFontStyle.h"
56 SkFontStyle::SkFontStyle() {
58 fUnion.fR.fWeight = kNormal_Weight;
59 fUnion.fR.fWidth = kNormal_Width;
60 fUnion.fR.fSlant = kUpright_Slant;
63 SkFontStyle::SkFontStyle(int weight, int width, Slant slant) {
65 fUnion.fR.fWeight = SkPin32(weight, kThin_Weight, kBlack_Weight);
66 fUnion.fR.fWidth = SkPin32(width, kUltraCondensed_Width, kUltaExpanded_Width);
67 fUnion.fR.fSlant = SkPin32(slant, kUpright_Slant, kItalic_Slant);
70 #include "SkFontMgr.h"
72 class SkEmptyFontStyleSet : public SkFontStyleSet {
74 virtual int count() SK_OVERRIDE { return 0; }
75 virtual void getStyle(int, SkFontStyle*, SkString*) SK_OVERRIDE {
76 SkDEBUGFAIL("SkFontStyleSet::getStyle called on empty set");
78 virtual SkTypeface* createTypeface(int index) SK_OVERRIDE {
79 SkDEBUGFAIL("SkFontStyleSet::createTypeface called on empty set");
82 virtual SkTypeface* matchStyle(const SkFontStyle&) SK_OVERRIDE {
87 SkFontStyleSet* SkFontStyleSet::CreateEmpty() {
88 return SkNEW(SkEmptyFontStyleSet);
91 ///////////////////////////////////////////////////////////////////////////////
93 class SkEmptyFontMgr : public SkFontMgr {
95 virtual int onCountFamilies() const SK_OVERRIDE {
98 virtual void onGetFamilyName(int index, SkString* familyName) const SK_OVERRIDE {
99 SkDEBUGFAIL("onGetFamilyName called with bad index");
101 virtual SkFontStyleSet* onCreateStyleSet(int index) const SK_OVERRIDE {
102 SkDEBUGFAIL("onCreateStyleSet called with bad index");
105 virtual SkFontStyleSet* onMatchFamily(const char[]) const SK_OVERRIDE {
106 return SkFontStyleSet::CreateEmpty();
109 virtual SkTypeface* onMatchFamilyStyle(const char[],
110 const SkFontStyle&) const SK_OVERRIDE {
113 virtual SkTypeface* onMatchFamilyStyleCharacter(const char familyName[],
114 const SkFontStyle& style,
116 uint32_t character) const SK_OVERRIDE {
119 virtual SkTypeface* onMatchFaceStyle(const SkTypeface*,
120 const SkFontStyle&) const SK_OVERRIDE {
123 virtual SkTypeface* onCreateFromData(SkData*, int) const SK_OVERRIDE {
126 virtual SkTypeface* onCreateFromStream(SkStream*, int) const SK_OVERRIDE {
129 virtual SkTypeface* onCreateFromFile(const char[], int) const SK_OVERRIDE {
132 virtual SkTypeface* onLegacyCreateTypeface(const char [], unsigned) const SK_OVERRIDE {
137 static SkFontStyleSet* emptyOnNull(SkFontStyleSet* fsset) {
139 fsset = SkFontStyleSet::CreateEmpty();
144 int SkFontMgr::countFamilies() const {
145 return this->onCountFamilies();
148 void SkFontMgr::getFamilyName(int index, SkString* familyName) const {
149 this->onGetFamilyName(index, familyName);
152 SkFontStyleSet* SkFontMgr::createStyleSet(int index) const {
153 return emptyOnNull(this->onCreateStyleSet(index));
156 SkFontStyleSet* SkFontMgr::matchFamily(const char familyName[]) const {
157 return emptyOnNull(this->onMatchFamily(familyName));
160 SkTypeface* SkFontMgr::matchFamilyStyle(const char familyName[],
161 const SkFontStyle& fs) const {
162 return this->onMatchFamilyStyle(familyName, fs);
165 SkTypeface* SkFontMgr::matchFamilyStyleCharacter(const char familyName[], const SkFontStyle& style,
166 const char bpc47[], uint32_t character) const {
167 return this->onMatchFamilyStyleCharacter(familyName, style, bpc47, character);
170 SkTypeface* SkFontMgr::matchFaceStyle(const SkTypeface* face,
171 const SkFontStyle& fs) const {
172 return this->onMatchFaceStyle(face, fs);
175 SkTypeface* SkFontMgr::createFromData(SkData* data, int ttcIndex) const {
179 return this->onCreateFromData(data, ttcIndex);
182 SkTypeface* SkFontMgr::createFromStream(SkStream* stream, int ttcIndex) const {
183 if (NULL == stream) {
186 return this->onCreateFromStream(stream, ttcIndex);
189 SkTypeface* SkFontMgr::createFromFile(const char path[], int ttcIndex) const {
193 return this->onCreateFromFile(path, ttcIndex);
196 SkTypeface* SkFontMgr::legacyCreateTypeface(const char familyName[],
197 unsigned styleBits) const {
198 return this->onLegacyCreateTypeface(familyName, styleBits);
201 SkFontMgr* SkFontMgr::CreateDefault() {
202 SkFontMgr* fm = SkFontMgr::Factory();
203 return fm ? fm : SkNEW(SkEmptyFontMgr);
206 SkFontMgr* SkFontMgr::RefDefault() {
207 SK_DECLARE_STATIC_LAZY_PTR(SkFontMgr, singleton, CreateDefault);
208 return SkRef(singleton.get());