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 265 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
276 *trimmedMatches.append() = match[i]; | 276 *trimmedMatches.append() = match[i]; |
277 } | 277 } |
278 } | 278 } |
279 | 279 |
280 SkFontStyleSet_FC* sset = SkNEW_ARGS(SkFontStyleSet_FC, | 280 SkFontStyleSet_FC* sset = SkNEW_ARGS(SkFontStyleSet_FC, |
281 (trimmedMatches.begin(), | 281 (trimmedMatches.begin(), |
282 trimmedMatches.count())); | 282 trimmedMatches.count())); |
283 return sset; | 283 return sset; |
284 } | 284 } |
285 | 285 |
286 virtual SkTypeface* onMatchFamilyStyle(const char familyName[], | 286 SkTypeface* onMatchFamilyStyle(const char familyName[], |
287 const SkFontStyle&) const override {
return NULL; } | 287 const SkFontStyle&) const override { return N
ULL; } |
288 virtual SkTypeface* onMatchFamilyStyleCharacter(const char familyName[], con
st SkFontStyle&, | 288 SkTypeface* onMatchFamilyStyleCharacter(const char familyName[], const SkFon
tStyle&, |
289 const char* bcp47[], int bcp
47Count, | 289 const char* bcp47[], int bcp47Count, |
290 SkUnichar character) const o
verride { | 290 SkUnichar character) const override
{ |
291 return NULL; | 291 return NULL; |
292 } | 292 } |
293 virtual SkTypeface* onMatchFaceStyle(const SkTypeface*, | 293 SkTypeface* onMatchFaceStyle(const SkTypeface*, |
294 const SkFontStyle&) const override { re
turn NULL; } | 294 const SkFontStyle&) const override { return NUL
L; } |
295 | 295 |
296 SkTypeface* onCreateFromData(SkData*, int ttcIndex) const override { return
NULL; } | 296 SkTypeface* onCreateFromData(SkData*, int ttcIndex) const override { return
NULL; } |
297 | 297 |
298 SkTypeface* onCreateFromStream(SkStreamAsset* bareStream, int ttcIndex) cons
t override { | 298 SkTypeface* onCreateFromStream(SkStreamAsset* bareStream, int ttcIndex) cons
t override { |
299 SkAutoTDelete<SkStreamAsset> stream(bareStream); | 299 SkAutoTDelete<SkStreamAsset> stream(bareStream); |
300 const size_t length = stream->getLength(); | 300 const size_t length = stream->getLength(); |
301 if (!length) { | 301 if (!length) { |
302 return NULL; | 302 return NULL; |
303 } | 303 } |
304 if (length >= 1024 * 1024 * 1024) { | 304 if (length >= 1024 * 1024 * 1024) { |
305 return NULL; // don't accept too large fonts (>= 1GB) for safety. | 305 return NULL; // don't accept too large fonts (>= 1GB) for safety. |
306 } | 306 } |
307 | 307 |
308 // TODO should the caller give us the style or should we get it from fre
etype? | 308 // TODO should the caller give us the style or should we get it from fre
etype? |
309 SkFontStyle style; | 309 SkFontStyle style; |
310 bool isFixedWidth = false; | 310 bool isFixedWidth = false; |
311 if (!fScanner.scanFont(stream, 0, NULL, &style, &isFixedWidth)) { | 311 if (!fScanner.scanFont(stream, 0, NULL, &style, &isFixedWidth)) { |
312 return NULL; | 312 return NULL; |
313 } | 313 } |
314 | 314 |
315 SkTypeface* face = FontConfigTypeface::Create(style, isFixedWidth, strea
m.detach()); | 315 SkTypeface* face = FontConfigTypeface::Create(style, isFixedWidth, strea
m.detach()); |
316 return face; | 316 return face; |
317 } | 317 } |
318 | 318 |
319 SkTypeface* onCreateFromFile(const char path[], int ttcIndex) const override
{ | 319 SkTypeface* onCreateFromFile(const char path[], int ttcIndex) const override
{ |
320 SkAutoTDelete<SkStreamAsset> stream(SkStream::NewFromFile(path)); | 320 SkAutoTDelete<SkStreamAsset> stream(SkStream::NewFromFile(path)); |
321 return stream.get() ? this->createFromStream(stream.detach(), ttcIndex)
: NULL; | 321 return stream.get() ? this->createFromStream(stream.detach(), ttcIndex)
: NULL; |
322 } | 322 } |
323 | 323 |
324 virtual SkTypeface* onLegacyCreateTypeface(const char familyName[], | 324 SkTypeface* onLegacyCreateTypeface(const char familyName[], |
325 unsigned styleBits) const overrid
e { | 325 unsigned styleBits) const override { |
326 FCLocker lock; | 326 FCLocker lock; |
327 return FontConfigTypeface::LegacyCreateTypeface(familyName, (SkTypeface:
:Style)styleBits); | 327 return FontConfigTypeface::LegacyCreateTypeface(familyName, (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 |