| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2006 The Android Open Source Project | 2 * Copyright 2006 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 "SkFontHost_FreeType_common.h" | 8 #include "SkFontHost_FreeType_common.h" |
| 9 #include "SkFontDescriptor.h" | 9 #include "SkFontDescriptor.h" |
| 10 #include "SkFontMgr.h" | 10 #include "SkFontMgr.h" |
| (...skipping 21 matching lines...) Expand all Loading... |
| 32 | 32 |
| 33 bool isSysFont() const { return fIsSysFont; } | 33 bool isSysFont() const { return fIsSysFont; } |
| 34 | 34 |
| 35 protected: | 35 protected: |
| 36 void onGetFamilyName(SkString* familyName) const override { | 36 void onGetFamilyName(SkString* familyName) const override { |
| 37 *familyName = fFamilyName; | 37 *familyName = fFamilyName; |
| 38 } | 38 } |
| 39 | 39 |
| 40 void onGetFontDescriptor(SkFontDescriptor* desc, bool* isLocal) const overri
de { | 40 void onGetFontDescriptor(SkFontDescriptor* desc, bool* isLocal) const overri
de { |
| 41 desc->setFamilyName(fFamilyName.c_str()); | 41 desc->setFamilyName(fFamilyName.c_str()); |
| 42 desc->setFontIndex(fIndex); |
| 42 *isLocal = !this->isSysFont(); | 43 *isLocal = !this->isSysFont(); |
| 43 } | 44 } |
| 44 | 45 |
| 45 int getIndex() const { return fIndex; } | 46 int getIndex() const { return fIndex; } |
| 46 | 47 |
| 47 private: | 48 private: |
| 48 const bool fIsSysFont; | 49 const bool fIsSysFont; |
| 49 const SkString fFamilyName; | 50 const SkString fFamilyName; |
| 50 const int fIndex; | 51 const int fIndex; |
| 51 | 52 |
| (...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 298 | 299 |
| 299 SkTypeface* onCreateFromStream(SkStreamAsset* bareStream, int ttcIndex) cons
t override { | 300 SkTypeface* onCreateFromStream(SkStreamAsset* bareStream, int ttcIndex) cons
t override { |
| 300 SkAutoTDelete<SkStreamAsset> stream(bareStream); | 301 SkAutoTDelete<SkStreamAsset> stream(bareStream); |
| 301 if (NULL == stream || stream->getLength() <= 0) { | 302 if (NULL == stream || stream->getLength() <= 0) { |
| 302 return NULL; | 303 return NULL; |
| 303 } | 304 } |
| 304 | 305 |
| 305 bool isFixedPitch; | 306 bool isFixedPitch; |
| 306 SkFontStyle style; | 307 SkFontStyle style; |
| 307 SkString name; | 308 SkString name; |
| 308 if (fScanner.scanFont(stream, ttcIndex, &name, &style, &isFixedPitch, NU
LL)) { | 309 if (fScanner.scanFont(stream, ttcIndex, &name, &style, &isFixedPitch)) { |
| 309 return SkNEW_ARGS(SkTypeface_Stream, (style, isFixedPitch, false, na
me, | 310 return SkNEW_ARGS(SkTypeface_Stream, (style, isFixedPitch, false, na
me, |
| 310 stream.detach(), ttcIndex)); | 311 stream.detach(), ttcIndex)); |
| 311 } else { | 312 } else { |
| 312 return NULL; | 313 return NULL; |
| 313 } | 314 } |
| 314 } | 315 } |
| 315 | 316 |
| 316 SkTypeface* onCreateFromFile(const char path[], int ttcIndex) const override
{ | 317 SkTypeface* onCreateFromFile(const char path[], int ttcIndex) const override
{ |
| 317 SkAutoTDelete<SkStreamAsset> stream(SkStream::NewFromFile(path)); | 318 SkAutoTDelete<SkStreamAsset> stream(SkStream::NewFromFile(path)); |
| 318 return stream.get() ? this->createFromStream(stream.detach(), ttcIndex)
: NULL; | 319 return stream.get() ? this->createFromStream(stream.detach(), ttcIndex)
: NULL; |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 397 int numFaces; | 398 int numFaces; |
| 398 if (!scanner.recognizedFont(stream, &numFaces)) { | 399 if (!scanner.recognizedFont(stream, &numFaces)) { |
| 399 SkDebugf("---- failed to open <%s> as a font\n", filename.c_str(
)); | 400 SkDebugf("---- failed to open <%s> as a font\n", filename.c_str(
)); |
| 400 continue; | 401 continue; |
| 401 } | 402 } |
| 402 | 403 |
| 403 for (int faceIndex = 0; faceIndex < numFaces; ++faceIndex) { | 404 for (int faceIndex = 0; faceIndex < numFaces; ++faceIndex) { |
| 404 bool isFixedPitch; | 405 bool isFixedPitch; |
| 405 SkString realname; | 406 SkString realname; |
| 406 SkFontStyle style = SkFontStyle(); // avoid uninitialized warnin
g | 407 SkFontStyle style = SkFontStyle(); // avoid uninitialized warnin
g |
| 407 if (!scanner.scanFont(stream, faceIndex, &realname, &style, &isF
ixedPitch, NULL)) { | 408 if (!scanner.scanFont(stream, faceIndex, &realname, &style, &isF
ixedPitch)) { |
| 408 SkDebugf("---- failed to open <%s> <%d> as a font\n", | 409 SkDebugf("---- failed to open <%s> <%d> as a font\n", |
| 409 filename.c_str(), faceIndex); | 410 filename.c_str(), faceIndex); |
| 410 continue; | 411 continue; |
| 411 } | 412 } |
| 412 | 413 |
| 413 SkTypeface_Custom* tf = SkNEW_ARGS(SkTypeface_File, ( | 414 SkTypeface_Custom* tf = SkNEW_ARGS(SkTypeface_File, ( |
| 414 style, | 415 style, |
| 415 isFixedPitch, | 416 isFixedPitch, |
| 416 true, // system-font (canno
t delete) | 417 true, // system-font (canno
t delete) |
| 417 realname, | 418 realname, |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 483 int numFaces; | 484 int numFaces; |
| 484 if (!scanner.recognizedFont(stream, &numFaces)) { | 485 if (!scanner.recognizedFont(stream, &numFaces)) { |
| 485 SkDebugf("---- failed to open <%d> as a font\n", index); | 486 SkDebugf("---- failed to open <%d> as a font\n", index); |
| 486 return; | 487 return; |
| 487 } | 488 } |
| 488 | 489 |
| 489 for (int faceIndex = 0; faceIndex < numFaces; ++faceIndex) { | 490 for (int faceIndex = 0; faceIndex < numFaces; ++faceIndex) { |
| 490 bool isFixedPitch; | 491 bool isFixedPitch; |
| 491 SkString realname; | 492 SkString realname; |
| 492 SkFontStyle style = SkFontStyle(); // avoid uninitialized warning | 493 SkFontStyle style = SkFontStyle(); // avoid uninitialized warning |
| 493 if (!scanner.scanFont(stream, faceIndex, &realname, &style, &isFixed
Pitch, NULL)) { | 494 if (!scanner.scanFont(stream, faceIndex, &realname, &style, &isFixed
Pitch)) { |
| 494 SkDebugf("---- failed to open <%d> <%d> as a font\n", index, fac
eIndex); | 495 SkDebugf("---- failed to open <%d> <%d> as a font\n", index, fac
eIndex); |
| 495 return; | 496 return; |
| 496 } | 497 } |
| 497 | 498 |
| 498 SkTypeface_Custom* tf = SkNEW_ARGS(SkTypeface_Stream, ( | 499 SkTypeface_Custom* tf = SkNEW_ARGS(SkTypeface_Stream, ( |
| 499 style, | 500 style, |
| 500 isFixedPitch, | 501 isFixedPitch, |
| 501 true, // system-font (cannot de
lete) | 502 true, // system-font (cannot de
lete) |
| 502 realname, | 503 realname, |
| 503 stream.detach(), | 504 stream.detach(), |
| (...skipping 21 matching lines...) Expand all Loading... |
| 525 #else | 526 #else |
| 526 | 527 |
| 527 #ifndef SK_FONT_FILE_PREFIX | 528 #ifndef SK_FONT_FILE_PREFIX |
| 528 # define SK_FONT_FILE_PREFIX "/usr/share/fonts/" | 529 # define SK_FONT_FILE_PREFIX "/usr/share/fonts/" |
| 529 #endif | 530 #endif |
| 530 SkFontMgr* SkFontMgr::Factory() { | 531 SkFontMgr* SkFontMgr::Factory() { |
| 531 return new SkFontMgr_Custom(DirectorySystemFontLoader(SK_FONT_FILE_PREFIX)); | 532 return new SkFontMgr_Custom(DirectorySystemFontLoader(SK_FONT_FILE_PREFIX)); |
| 532 } | 533 } |
| 533 | 534 |
| 534 #endif | 535 #endif |
| OLD | NEW |