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 "SkOnce.h" |
9 | 10 |
10 static SkFontLCDConfig::LCDOrientation gLCDOrientation = SkFontLCDConfig::kHoriz
ontal_LCDOrientation; | 11 static SkFontLCDConfig::LCDOrientation gLCDOrientation = SkFontLCDConfig::kHoriz
ontal_LCDOrientation; |
11 static SkFontLCDConfig::LCDOrder gLCDOrder = SkFontLCDConfig::kRGB_LCDOrder; | 12 static SkFontLCDConfig::LCDOrder gLCDOrder = SkFontLCDConfig::kRGB_LCDOrder; |
12 | 13 |
13 SkFontLCDConfig::LCDOrientation SkFontLCDConfig::GetSubpixelOrientation() { | 14 SkFontLCDConfig::LCDOrientation SkFontLCDConfig::GetSubpixelOrientation() { |
14 return gLCDOrientation; | 15 return gLCDOrientation; |
15 } | 16 } |
16 | 17 |
17 void SkFontLCDConfig::SetSubpixelOrientation(LCDOrientation orientation) { | 18 void SkFontLCDConfig::SetSubpixelOrientation(LCDOrientation orientation) { |
18 gLCDOrientation = orientation; | 19 gLCDOrientation = orientation; |
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
183 return NULL; | 184 return NULL; |
184 } | 185 } |
185 return this->onCreateFromFile(path, ttcIndex); | 186 return this->onCreateFromFile(path, ttcIndex); |
186 } | 187 } |
187 | 188 |
188 SkTypeface* SkFontMgr::legacyCreateTypeface(const char familyName[], | 189 SkTypeface* SkFontMgr::legacyCreateTypeface(const char familyName[], |
189 unsigned styleBits) { | 190 unsigned styleBits) { |
190 return this->onLegacyCreateTypeface(familyName, styleBits); | 191 return this->onLegacyCreateTypeface(familyName, styleBits); |
191 } | 192 } |
192 | 193 |
| 194 void set_up_default(SkFontMgr** singleton) { |
| 195 *singleton = SkFontMgr::Factory(); |
| 196 } |
| 197 |
193 SkFontMgr* SkFontMgr::RefDefault() { | 198 SkFontMgr* SkFontMgr::RefDefault() { |
194 static SkFontMgr* gFM; | 199 static SkFontMgr* gFM = NULL; |
195 if (NULL == gFM) { | 200 SK_DECLARE_STATIC_ONCE(once); |
196 gFM = SkFontMgr::Factory(); | 201 SkOnce(&once, set_up_default, &gFM); |
197 // we never want to return NULL | |
198 if (NULL == gFM) { | |
199 gFM = SkNEW(SkEmptyFontMgr); | |
200 } | |
201 } | |
202 return SkRef(gFM); | 202 return SkRef(gFM); |
203 } | 203 } |
204 | 204 |
205 ////////////////////////////////////////////////////////////////////////// | 205 ////////////////////////////////////////////////////////////////////////// |
206 | 206 |
207 #ifdef SK_FONTHOST_USES_FONTMGR | |
208 | |
209 #if 0 | 207 #if 0 |
210 static SkFontStyle TypefaceStyleBitsToFontStyle(SkTypeface::Style styleBits) { | 208 static SkFontStyle TypefaceStyleBitsToFontStyle(SkTypeface::Style styleBits) { |
211 SkFontStyle::Weight weight = (styleBits & SkTypeface::kBold) ? | 209 SkFontStyle::Weight weight = (styleBits & SkTypeface::kBold) ? |
212 SkFontStyle::kBold_Weight : | 210 SkFontStyle::kBold_Weight : |
213 SkFontStyle::kNormal_Weight; | 211 SkFontStyle::kNormal_Weight; |
214 SkFontStyle::Width width = SkFontStyle::kNormal_Width; | 212 SkFontStyle::Width width = SkFontStyle::kNormal_Width; |
215 SkFontStyle::Slant slant = (styleBits & SkTypeface::kItalic) ? | 213 SkFontStyle::Slant slant = (styleBits & SkTypeface::kItalic) ? |
216 SkFontStyle::kUpright_Slant : | 214 SkFontStyle::kUpright_Slant : |
217 SkFontStyle::kItalic_Slant; | 215 SkFontStyle::kItalic_Slant; |
218 return SkFontStyle(weight, width, slant); | 216 return SkFontStyle(weight, width, slant); |
219 } | 217 } |
220 #endif | 218 #endif |
221 | 219 |
222 SkTypeface* SkFontHost::CreateTypeface(const SkTypeface* familyFace, | 220 SkTypeface* SkFontHost::CreateTypeface(const SkTypeface* familyFace, |
223 const char familyName[], | 221 const char familyName[], |
224 SkTypeface::Style style) { | 222 SkTypeface::Style style) { |
| 223 SkAutoTUnref<SkFontMgr> fm(SkFontMgr::RefDefault()); |
225 if (familyFace) { | 224 if (familyFace) { |
226 return familyFace->refMatchingStyle(style); | 225 bool bold = style & SkTypeface::kBold; |
| 226 bool italic = style & SkTypeface::kItalic; |
| 227 SkFontStyle newStyle = SkFontStyle(bold ? SkFontStyle::kBold_Weight |
| 228 : SkFontStyle::kNormal_Weight, |
| 229 SkFontStyle::kNormal_Width, |
| 230 italic ? SkFontStyle::kItalic_Slant |
| 231 : SkFontStyle::kUpright_Slant)
; |
| 232 return fm->matchFaceStyle(familyFace, newStyle); |
227 } else { | 233 } else { |
228 SkAutoTUnref<SkFontMgr> fm(SkFontMgr::RefDefault()); | |
229 return fm->legacyCreateTypeface(familyName, style); | 234 return fm->legacyCreateTypeface(familyName, style); |
230 } | 235 } |
231 } | 236 } |
232 | 237 |
233 SkTypeface* SkFontHost::CreateTypefaceFromFile(const char path[]) { | 238 SkTypeface* SkFontHost::CreateTypefaceFromFile(const char path[]) { |
234 SkAutoTUnref<SkFontMgr> fm(SkFontMgr::RefDefault()); | 239 SkAutoTUnref<SkFontMgr> fm(SkFontMgr::RefDefault()); |
235 return fm->createFromFile(path); | 240 return fm->createFromFile(path); |
236 } | 241 } |
237 | 242 |
238 SkTypeface* SkFontHost::CreateTypefaceFromStream(SkStream* stream) { | 243 SkTypeface* SkFontHost::CreateTypefaceFromStream(SkStream* stream) { |
239 SkAutoTUnref<SkFontMgr> fm(SkFontMgr::RefDefault()); | 244 SkAutoTUnref<SkFontMgr> fm(SkFontMgr::RefDefault()); |
240 return fm->createFromStream(stream); | 245 return fm->createFromStream(stream); |
241 } | 246 } |
242 | |
243 #endif | |
OLD | NEW |