OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2009 The Android Open Source Project | 2 * Copyright 2009 The Android Open Source Project |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #include "SkFontLCDConfig.h" | 8 #include "SkFontLCDConfig.h" |
9 #include "SkLazyPtr.h" | |
10 | 9 |
11 static SkFontLCDConfig::LCDOrientation gLCDOrientation = SkFontLCDConfig::kHoriz
ontal_LCDOrientation; | 10 static SkFontLCDConfig::LCDOrientation gLCDOrientation = SkFontLCDConfig::kHoriz
ontal_LCDOrientation; |
12 static SkFontLCDConfig::LCDOrder gLCDOrder = SkFontLCDConfig::kRGB_LCDOrder; | 11 static SkFontLCDConfig::LCDOrder gLCDOrder = SkFontLCDConfig::kRGB_LCDOrder; |
13 | 12 |
14 SkFontLCDConfig::LCDOrientation SkFontLCDConfig::GetSubpixelOrientation() { | 13 SkFontLCDConfig::LCDOrientation SkFontLCDConfig::GetSubpixelOrientation() { |
15 return gLCDOrientation; | 14 return gLCDOrientation; |
16 } | 15 } |
17 | 16 |
18 void SkFontLCDConfig::SetSubpixelOrientation(LCDOrientation orientation) { | 17 void SkFontLCDConfig::SetSubpixelOrientation(LCDOrientation orientation) { |
19 gLCDOrientation = orientation; | 18 gLCDOrientation = orientation; |
(...skipping 20 matching lines...) Expand all Loading... |
40 SkFontLCDConfig::SetSubpixelOrientation((SkFontLCDConfig::LCDOrientation)ori
entation); | 39 SkFontLCDConfig::SetSubpixelOrientation((SkFontLCDConfig::LCDOrientation)ori
entation); |
41 } | 40 } |
42 | 41 |
43 SkFontHost::LCDOrder SkFontHost::GetSubpixelOrder() { | 42 SkFontHost::LCDOrder SkFontHost::GetSubpixelOrder() { |
44 return (SkFontHost::LCDOrder)SkFontLCDConfig::GetSubpixelOrder(); | 43 return (SkFontHost::LCDOrder)SkFontLCDConfig::GetSubpixelOrder(); |
45 } | 44 } |
46 | 45 |
47 void SkFontHost::SetSubpixelOrder(LCDOrder order) { | 46 void SkFontHost::SetSubpixelOrder(LCDOrder order) { |
48 SkFontLCDConfig::SetSubpixelOrder((SkFontLCDConfig::LCDOrder)order); | 47 SkFontLCDConfig::SetSubpixelOrder((SkFontLCDConfig::LCDOrder)order); |
49 } | 48 } |
50 | |
51 /////////////////////////////////////////////////////////////////////////////// | |
52 /////////////////////////////////////////////////////////////////////////////// | |
53 | |
54 #include "SkFontStyle.h" | |
55 | |
56 SkFontStyle::SkFontStyle() { | |
57 fUnion.fU32 = 0; | |
58 fUnion.fR.fWeight = kNormal_Weight; | |
59 fUnion.fR.fWidth = kNormal_Width; | |
60 fUnion.fR.fSlant = kUpright_Slant; | |
61 } | |
62 | |
63 SkFontStyle::SkFontStyle(int weight, int width, Slant slant) { | |
64 fUnion.fU32 = 0; | |
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); | |
68 } | |
69 | |
70 SkFontStyle::SkFontStyle(unsigned oldStyle) { | |
71 fUnion.fU32 = 0; | |
72 fUnion.fR.fWeight = (oldStyle & SkTypeface::kBold) ? SkFontStyle::kBold_Weig
ht | |
73 : SkFontStyle::kNormal_We
ight; | |
74 fUnion.fR.fWidth = SkFontStyle::kNormal_Width; | |
75 fUnion.fR.fSlant = (oldStyle & SkTypeface::kItalic) ? SkFontStyle::kItalic_S
lant | |
76 : SkFontStyle::kUpright_
Slant; | |
77 } | |
78 | |
79 #include "SkFontMgr.h" | |
80 | |
81 class SkEmptyFontStyleSet : public SkFontStyleSet { | |
82 public: | |
83 int count() SK_OVERRIDE { return 0; } | |
84 void getStyle(int, SkFontStyle*, SkString*) SK_OVERRIDE { | |
85 SkDEBUGFAIL("SkFontStyleSet::getStyle called on empty set"); | |
86 } | |
87 SkTypeface* createTypeface(int index) SK_OVERRIDE { | |
88 SkDEBUGFAIL("SkFontStyleSet::createTypeface called on empty set"); | |
89 return NULL; | |
90 } | |
91 SkTypeface* matchStyle(const SkFontStyle&) SK_OVERRIDE { | |
92 return NULL; | |
93 } | |
94 }; | |
95 | |
96 SkFontStyleSet* SkFontStyleSet::CreateEmpty() { | |
97 return SkNEW(SkEmptyFontStyleSet); | |
98 } | |
99 | |
100 /////////////////////////////////////////////////////////////////////////////// | |
101 | |
102 class SkEmptyFontMgr : public SkFontMgr { | |
103 protected: | |
104 int onCountFamilies() const SK_OVERRIDE { | |
105 return 0; | |
106 } | |
107 void onGetFamilyName(int index, SkString* familyName) const SK_OVERRIDE { | |
108 SkDEBUGFAIL("onGetFamilyName called with bad index"); | |
109 } | |
110 SkFontStyleSet* onCreateStyleSet(int index) const SK_OVERRIDE { | |
111 SkDEBUGFAIL("onCreateStyleSet called with bad index"); | |
112 return NULL; | |
113 } | |
114 SkFontStyleSet* onMatchFamily(const char[]) const SK_OVERRIDE { | |
115 return SkFontStyleSet::CreateEmpty(); | |
116 } | |
117 | |
118 virtual SkTypeface* onMatchFamilyStyle(const char[], | |
119 const SkFontStyle&) const SK_OVERRIDE
{ | |
120 return NULL; | |
121 } | |
122 virtual SkTypeface* onMatchFamilyStyleCharacter(const char familyName[], | |
123 const SkFontStyle& style, | |
124 const char* bcp47[], | |
125 int bcp47Count, | |
126 SkUnichar character) const S
K_OVERRIDE { | |
127 return NULL; | |
128 } | |
129 virtual SkTypeface* onMatchFaceStyle(const SkTypeface*, | |
130 const SkFontStyle&) const SK_OVERRIDE { | |
131 return NULL; | |
132 } | |
133 SkTypeface* onCreateFromData(SkData*, int) const SK_OVERRIDE { | |
134 return NULL; | |
135 } | |
136 SkTypeface* onCreateFromStream(SkStream*, int) const SK_OVERRIDE { | |
137 return NULL; | |
138 } | |
139 SkTypeface* onCreateFromFile(const char[], int) const SK_OVERRIDE { | |
140 return NULL; | |
141 } | |
142 SkTypeface* onLegacyCreateTypeface(const char [], unsigned) const SK_OVERRID
E { | |
143 return NULL; | |
144 } | |
145 }; | |
146 | |
147 static SkFontStyleSet* emptyOnNull(SkFontStyleSet* fsset) { | |
148 if (NULL == fsset) { | |
149 fsset = SkFontStyleSet::CreateEmpty(); | |
150 } | |
151 return fsset; | |
152 } | |
153 | |
154 int SkFontMgr::countFamilies() const { | |
155 return this->onCountFamilies(); | |
156 } | |
157 | |
158 void SkFontMgr::getFamilyName(int index, SkString* familyName) const { | |
159 this->onGetFamilyName(index, familyName); | |
160 } | |
161 | |
162 SkFontStyleSet* SkFontMgr::createStyleSet(int index) const { | |
163 return emptyOnNull(this->onCreateStyleSet(index)); | |
164 } | |
165 | |
166 SkFontStyleSet* SkFontMgr::matchFamily(const char familyName[]) const { | |
167 return emptyOnNull(this->onMatchFamily(familyName)); | |
168 } | |
169 | |
170 SkTypeface* SkFontMgr::matchFamilyStyle(const char familyName[], | |
171 const SkFontStyle& fs) const { | |
172 return this->onMatchFamilyStyle(familyName, fs); | |
173 } | |
174 | |
175 SkTypeface* SkFontMgr::matchFamilyStyleCharacter(const char familyName[], const
SkFontStyle& style, | |
176 const char* bcp47[], int bcp47C
ount, | |
177 SkUnichar character) const { | |
178 return this->onMatchFamilyStyleCharacter(familyName, style, bcp47, bcp47Coun
t, character); | |
179 } | |
180 | |
181 SkTypeface* SkFontMgr::matchFaceStyle(const SkTypeface* face, | |
182 const SkFontStyle& fs) const { | |
183 return this->onMatchFaceStyle(face, fs); | |
184 } | |
185 | |
186 SkTypeface* SkFontMgr::createFromData(SkData* data, int ttcIndex) const { | |
187 if (NULL == data) { | |
188 return NULL; | |
189 } | |
190 return this->onCreateFromData(data, ttcIndex); | |
191 } | |
192 | |
193 SkTypeface* SkFontMgr::createFromStream(SkStream* stream, int ttcIndex) const { | |
194 if (NULL == stream) { | |
195 return NULL; | |
196 } | |
197 return this->onCreateFromStream(stream, ttcIndex); | |
198 } | |
199 | |
200 SkTypeface* SkFontMgr::createFromFile(const char path[], int ttcIndex) const { | |
201 if (NULL == path) { | |
202 return NULL; | |
203 } | |
204 return this->onCreateFromFile(path, ttcIndex); | |
205 } | |
206 | |
207 SkTypeface* SkFontMgr::legacyCreateTypeface(const char familyName[], | |
208 unsigned styleBits) const { | |
209 return this->onLegacyCreateTypeface(familyName, styleBits); | |
210 } | |
211 | |
212 // As a template argument this must have external linkage. | |
213 SkFontMgr* sk_fontmgr_create_default() { | |
214 SkFontMgr* fm = SkFontMgr::Factory(); | |
215 return fm ? fm : SkNEW(SkEmptyFontMgr); | |
216 } | |
217 | |
218 SK_DECLARE_STATIC_LAZY_PTR(SkFontMgr, singleton, sk_fontmgr_create_default); | |
219 | |
220 SkFontMgr* SkFontMgr::RefDefault() { | |
221 return SkRef(singleton.get()); | |
222 } | |
OLD | NEW |