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 282 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
293 virtual SkTypeface* onCreateFromStream(SkStream* stream, int ttcIndex) const
SK_OVERRIDE { | 293 virtual SkTypeface* onCreateFromStream(SkStream* stream, int ttcIndex) const
SK_OVERRIDE { |
294 const size_t length = stream->getLength(); | 294 const size_t length = stream->getLength(); |
295 if (!length) { | 295 if (!length) { |
296 return NULL; | 296 return NULL; |
297 } | 297 } |
298 if (length >= 1024 * 1024 * 1024) { | 298 if (length >= 1024 * 1024 * 1024) { |
299 return NULL; // don't accept too large fonts (>= 1GB) for safety. | 299 return NULL; // don't accept too large fonts (>= 1GB) for safety. |
300 } | 300 } |
301 | 301 |
302 // TODO should the caller give us the style or should we get it from fre
etype? | 302 // TODO should the caller give us the style or should we get it from fre
etype? |
303 SkFontStyle style; | 303 SkTypeface::Style style = SkTypeface::kNormal; |
304 bool isFixedWidth = false; | 304 bool isFixedWidth = false; |
305 if (!SkTypeface_FreeType::ScanFont(stream, 0, NULL, &style, &isFixedWidt
h)) { | 305 if (!SkTypeface_FreeType::ScanFont(stream, 0, NULL, &style, &isFixedWidt
h)) { |
306 return NULL; | 306 return NULL; |
307 } | 307 } |
308 | 308 |
309 SkTypeface* face = FontConfigTypeface::Create(style, isFixedWidth, strea
m); | 309 SkTypeface* face = FontConfigTypeface::Create(style, isFixedWidth, strea
m); |
310 return face; | 310 return face; |
311 } | 311 } |
312 | 312 |
313 virtual SkTypeface* onCreateFromFile(const char path[], int ttcIndex) const
SK_OVERRIDE { | 313 virtual SkTypeface* onCreateFromFile(const char path[], int ttcIndex) const
SK_OVERRIDE { |
314 SkAutoTUnref<SkStream> stream(SkStream::NewFromFile(path)); | 314 SkAutoTUnref<SkStream> stream(SkStream::NewFromFile(path)); |
315 return stream.get() ? this->createFromStream(stream, ttcIndex) : NULL; | 315 return stream.get() ? this->createFromStream(stream, ttcIndex) : NULL; |
316 } | 316 } |
317 | 317 |
318 virtual SkTypeface* onLegacyCreateTypeface(const char familyName[], | 318 virtual SkTypeface* onLegacyCreateTypeface(const char familyName[], |
319 unsigned styleBits) const SK_OVER
RIDE { | 319 unsigned styleBits) const SK_OVER
RIDE { |
320 FCLocker lock; | 320 FCLocker lock; |
321 return FontConfigTypeface::LegacyCreateTypeface(NULL, familyName, | 321 return FontConfigTypeface::LegacyCreateTypeface(NULL, familyName, |
322 (SkTypeface::Style)styleBits); | 322 (SkTypeface::Style)styleBits); |
323 } | 323 } |
324 }; | 324 }; |
325 | 325 |
326 SkFontMgr* SkFontMgr::Factory() { | 326 SkFontMgr* SkFontMgr::Factory() { |
327 SkFontConfigInterface* fci = RefFCI(); | 327 SkFontConfigInterface* fci = RefFCI(); |
328 return fci ? SkNEW_ARGS(SkFontMgr_fontconfig, (fci)) : NULL; | 328 return fci ? SkNEW_ARGS(SkFontMgr_fontconfig, (fci)) : NULL; |
329 } | 329 } |
OLD | NEW |