OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2013 Google Inc. | 2 * Copyright 2013 Google Inc. |
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 "SkFontMgr.h" | 8 #include "SkFontMgr.h" |
9 #include "SkFontStyle.h" | 9 #include "SkFontStyle.h" |
10 #include "SkFontConfigInterface.h" | 10 #include "SkFontConfigInterface.h" |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
135 | 135 |
136 *count = iter - firstIter; | 136 *count = iter - firstIter; |
137 return firstIter; | 137 return firstIter; |
138 } | 138 } |
139 | 139 |
140 class SkFontStyleSet_FC : public SkFontStyleSet { | 140 class SkFontStyleSet_FC : public SkFontStyleSet { |
141 public: | 141 public: |
142 SkFontStyleSet_FC(FcPattern** matches, int count); | 142 SkFontStyleSet_FC(FcPattern** matches, int count); |
143 virtual ~SkFontStyleSet_FC(); | 143 virtual ~SkFontStyleSet_FC(); |
144 | 144 |
145 virtual int count() SK_OVERRIDE { return fRecCount; } | 145 int count() SK_OVERRIDE { return fRecCount; } |
146 virtual void getStyle(int index, SkFontStyle*, SkString* style) SK_OVERRIDE; | 146 void getStyle(int index, SkFontStyle*, SkString* style) SK_OVERRIDE; |
147 virtual SkTypeface* createTypeface(int index) SK_OVERRIDE; | 147 SkTypeface* createTypeface(int index) SK_OVERRIDE; |
148 virtual SkTypeface* matchStyle(const SkFontStyle& pattern) SK_OVERRIDE; | 148 SkTypeface* matchStyle(const SkFontStyle& pattern) SK_OVERRIDE; |
149 | 149 |
150 private: | 150 private: |
151 struct Rec { | 151 struct Rec { |
152 SkString fStyleName; | 152 SkString fStyleName; |
153 SkString fFileName; | 153 SkString fFileName; |
154 SkFontStyle fStyle; | 154 SkFontStyle fStyle; |
155 }; | 155 }; |
156 Rec* fRecs; | 156 Rec* fRecs; |
157 int fRecCount; | 157 int fRecCount; |
158 }; | 158 }; |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
219 public: | 219 public: |
220 SkFontMgr_fontconfig(SkFontConfigInterface* fci) | 220 SkFontMgr_fontconfig(SkFontConfigInterface* fci) |
221 : fFCI(fci) | 221 : fFCI(fci) |
222 , fFamilyNames(fFCI->getFamilyNames()) {} | 222 , fFamilyNames(fFCI->getFamilyNames()) {} |
223 | 223 |
224 virtual ~SkFontMgr_fontconfig() { | 224 virtual ~SkFontMgr_fontconfig() { |
225 SkSafeUnref(fFamilyNames); | 225 SkSafeUnref(fFamilyNames); |
226 } | 226 } |
227 | 227 |
228 protected: | 228 protected: |
229 virtual int onCountFamilies() const SK_OVERRIDE { | 229 int onCountFamilies() const SK_OVERRIDE { |
230 return fFamilyNames->count(); | 230 return fFamilyNames->count(); |
231 } | 231 } |
232 | 232 |
233 virtual void onGetFamilyName(int index, SkString* familyName) const SK_OVERR
IDE { | 233 void onGetFamilyName(int index, SkString* familyName) const SK_OVERRIDE { |
234 familyName->set(fFamilyNames->atStr(index)); | 234 familyName->set(fFamilyNames->atStr(index)); |
235 } | 235 } |
236 | 236 |
237 virtual SkFontStyleSet* onCreateStyleSet(int index) const SK_OVERRIDE { | 237 SkFontStyleSet* onCreateStyleSet(int index) const SK_OVERRIDE { |
238 return this->onMatchFamily(fFamilyNames->atStr(index)); | 238 return this->onMatchFamily(fFamilyNames->atStr(index)); |
239 } | 239 } |
240 | 240 |
241 virtual SkFontStyleSet* onMatchFamily(const char familyName[]) const SK_OVER
RIDE { | 241 SkFontStyleSet* onMatchFamily(const char familyName[]) const SK_OVERRIDE { |
242 FCLocker lock; | 242 FCLocker lock; |
243 | 243 |
244 FcPattern* pattern = FcPatternCreate(); | 244 FcPattern* pattern = FcPatternCreate(); |
245 | 245 |
246 FcPatternAddString(pattern, FC_FAMILY, (FcChar8*)familyName); | 246 FcPatternAddString(pattern, FC_FAMILY, (FcChar8*)familyName); |
247 #if 0 | 247 #if 0 |
248 FcPatternAddBool(pattern, FC_SCALABLE, FcTrue); | 248 FcPatternAddBool(pattern, FC_SCALABLE, FcTrue); |
249 #endif | 249 #endif |
250 FcConfigSubstitute(NULL, pattern, FcMatchPattern); | 250 FcConfigSubstitute(NULL, pattern, FcMatchPattern); |
251 FcDefaultSubstitute(pattern); | 251 FcDefaultSubstitute(pattern); |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
286 virtual SkTypeface* onMatchFamilyStyle(const char familyName[], | 286 virtual SkTypeface* onMatchFamilyStyle(const char familyName[], |
287 const SkFontStyle&) const SK_OVERRIDE
{ return NULL; } | 287 const SkFontStyle&) const SK_OVERRIDE
{ return NULL; } |
288 virtual SkTypeface* onMatchFamilyStyleCharacter(const char familyName[], con
st SkFontStyle&, | 288 virtual SkTypeface* onMatchFamilyStyleCharacter(const char familyName[], con
st SkFontStyle&, |
289 const char* bcp47[], int bcp
47Count, | 289 const char* bcp47[], int bcp
47Count, |
290 SkUnichar character) const S
K_OVERRIDE { | 290 SkUnichar character) const S
K_OVERRIDE { |
291 return NULL; | 291 return NULL; |
292 } | 292 } |
293 virtual SkTypeface* onMatchFaceStyle(const SkTypeface*, | 293 virtual SkTypeface* onMatchFaceStyle(const SkTypeface*, |
294 const SkFontStyle&) const SK_OVERRIDE {
return NULL; } | 294 const SkFontStyle&) const SK_OVERRIDE {
return NULL; } |
295 | 295 |
296 virtual SkTypeface* onCreateFromData(SkData*, int ttcIndex) const SK_OVERRID
E { return NULL; } | 296 SkTypeface* onCreateFromData(SkData*, int ttcIndex) const SK_OVERRIDE { retu
rn NULL; } |
297 | 297 |
298 virtual SkTypeface* onCreateFromStream(SkStream* stream, int ttcIndex) const
SK_OVERRIDE { | 298 SkTypeface* onCreateFromStream(SkStream* stream, int ttcIndex) const SK_OVER
RIDE { |
299 const size_t length = stream->getLength(); | 299 const size_t length = stream->getLength(); |
300 if (!length) { | 300 if (!length) { |
301 return NULL; | 301 return NULL; |
302 } | 302 } |
303 if (length >= 1024 * 1024 * 1024) { | 303 if (length >= 1024 * 1024 * 1024) { |
304 return NULL; // don't accept too large fonts (>= 1GB) for safety. | 304 return NULL; // don't accept too large fonts (>= 1GB) for safety. |
305 } | 305 } |
306 | 306 |
307 // TODO should the caller give us the style or should we get it from fre
etype? | 307 // TODO should the caller give us the style or should we get it from fre
etype? |
308 SkFontStyle style; | 308 SkFontStyle style; |
309 bool isFixedWidth = false; | 309 bool isFixedWidth = false; |
310 if (!fScanner.scanFont(stream, 0, NULL, &style, &isFixedWidth)) { | 310 if (!fScanner.scanFont(stream, 0, NULL, &style, &isFixedWidth)) { |
311 return NULL; | 311 return NULL; |
312 } | 312 } |
313 | 313 |
314 SkTypeface* face = FontConfigTypeface::Create(style, isFixedWidth, strea
m); | 314 SkTypeface* face = FontConfigTypeface::Create(style, isFixedWidth, strea
m); |
315 return face; | 315 return face; |
316 } | 316 } |
317 | 317 |
318 virtual SkTypeface* onCreateFromFile(const char path[], int ttcIndex) const
SK_OVERRIDE { | 318 SkTypeface* onCreateFromFile(const char path[], int ttcIndex) const SK_OVERR
IDE { |
319 SkAutoTUnref<SkStream> stream(SkStream::NewFromFile(path)); | 319 SkAutoTUnref<SkStream> stream(SkStream::NewFromFile(path)); |
320 return stream.get() ? this->createFromStream(stream, ttcIndex) : NULL; | 320 return stream.get() ? this->createFromStream(stream, ttcIndex) : NULL; |
321 } | 321 } |
322 | 322 |
323 virtual SkTypeface* onLegacyCreateTypeface(const char familyName[], | 323 virtual SkTypeface* onLegacyCreateTypeface(const char familyName[], |
324 unsigned styleBits) const SK_OVER
RIDE { | 324 unsigned styleBits) const SK_OVER
RIDE { |
325 FCLocker lock; | 325 FCLocker lock; |
326 return FontConfigTypeface::LegacyCreateTypeface(NULL, familyName, | 326 return FontConfigTypeface::LegacyCreateTypeface(NULL, familyName, |
327 (SkTypeface::Style)styleBits); | 327 (SkTypeface::Style)styleBits); |
328 } | 328 } |
329 }; | 329 }; |
330 | 330 |
331 SkFontMgr* SkFontMgr::Factory() { | 331 SkFontMgr* SkFontMgr::Factory() { |
332 SkFontConfigInterface* fci = RefFCI(); | 332 SkFontConfigInterface* fci = RefFCI(); |
333 return fci ? SkNEW_ARGS(SkFontMgr_fontconfig, (fci)) : NULL; | 333 return fci ? SkNEW_ARGS(SkFontMgr_fontconfig, (fci)) : NULL; |
334 } | 334 } |
OLD | NEW |