| 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.h" | 8 #include "SkFontHost.h" |
| 9 #include "SkFontHost_FreeType_common.h" | 9 #include "SkFontHost_FreeType_common.h" |
| 10 #include "SkFontDescriptor.h" | 10 #include "SkFontDescriptor.h" |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 66 /** The empty SkTypeface implementation for the custom font manager. | 66 /** The empty SkTypeface implementation for the custom font manager. |
| 67 * Used as the last resort fallback typeface. | 67 * Used as the last resort fallback typeface. |
| 68 */ | 68 */ |
| 69 class SkTypeface_Empty : public SkTypeface_Custom { | 69 class SkTypeface_Empty : public SkTypeface_Custom { |
| 70 public: | 70 public: |
| 71 SkTypeface_Empty() : INHERITED(SkFontStyle(), false, true, SkString(), 0) {} | 71 SkTypeface_Empty() : INHERITED(SkFontStyle(), false, true, SkString(), 0) {} |
| 72 | 72 |
| 73 const char* getUniqueString() const SK_OVERRIDE { return NULL; } | 73 const char* getUniqueString() const SK_OVERRIDE { return NULL; } |
| 74 | 74 |
| 75 protected: | 75 protected: |
| 76 SkStream* onOpenStream(int*) const SK_OVERRIDE { return NULL; } | 76 SkStreamAsset* onOpenStream(int*) const SK_OVERRIDE { return NULL; } |
| 77 | 77 |
| 78 private: | 78 private: |
| 79 typedef SkTypeface_Custom INHERITED; | 79 typedef SkTypeface_Custom INHERITED; |
| 80 }; | 80 }; |
| 81 | 81 |
| 82 /** The stream SkTypeface implementation for the custom font manager. */ | 82 /** The stream SkTypeface implementation for the custom font manager. */ |
| 83 class SkTypeface_Stream : public SkTypeface_Custom { | 83 class SkTypeface_Stream : public SkTypeface_Custom { |
| 84 public: | 84 public: |
| 85 SkTypeface_Stream(const SkFontStyle& style, bool isFixedPitch, bool sysFont, | 85 SkTypeface_Stream(const SkFontStyle& style, bool isFixedPitch, bool sysFont, |
| 86 const SkString familyName, SkStream* stream, int index) | 86 const SkString familyName, SkStreamAsset* stream, int inde
x) |
| 87 : INHERITED(style, isFixedPitch, sysFont, familyName, index) | 87 : INHERITED(style, isFixedPitch, sysFont, familyName, index) |
| 88 , fStream(stream) | 88 , fStream(stream) |
| 89 { } | 89 { } |
| 90 | 90 |
| 91 const char* getUniqueString() const SK_OVERRIDE { return NULL; } | 91 const char* getUniqueString() const SK_OVERRIDE { return NULL; } |
| 92 | 92 |
| 93 protected: | 93 protected: |
| 94 SkStream* onOpenStream(int* ttcIndex) const SK_OVERRIDE { | 94 SkStreamAsset* onOpenStream(int* ttcIndex) const SK_OVERRIDE { |
| 95 *ttcIndex = this->getIndex(); | 95 *ttcIndex = this->getIndex(); |
| 96 return fStream->duplicate(); | 96 return fStream->duplicate(); |
| 97 } | 97 } |
| 98 | 98 |
| 99 private: | 99 private: |
| 100 const SkAutoTDelete<const SkStream> fStream; | 100 const SkAutoTDelete<const SkStreamAsset> fStream; |
| 101 | 101 |
| 102 typedef SkTypeface_Custom INHERITED; | 102 typedef SkTypeface_Custom INHERITED; |
| 103 }; | 103 }; |
| 104 | 104 |
| 105 // This configuration option is useful if we need to open and hold handles to | 105 // This configuration option is useful if we need to open and hold handles to |
| 106 // all found system font data (e.g., for skfiddle, where the application can't | 106 // all found system font data (e.g., for skfiddle, where the application can't |
| 107 // access the filesystem to read fonts on demand) | 107 // access the filesystem to read fonts on demand) |
| 108 | 108 |
| 109 SK_CONF_DECLARE(bool, c_CustomTypefaceRetain, "fonts.customFont.retainAllData",
false, | 109 SK_CONF_DECLARE(bool, c_CustomTypefaceRetain, "fonts.customFont.retainAllData",
false, |
| 110 "Retain the open stream for each found font on the system."); | 110 "Retain the open stream for each found font on the system."); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 121 | 121 |
| 122 const char* getUniqueString() const SK_OVERRIDE { | 122 const char* getUniqueString() const SK_OVERRIDE { |
| 123 const char* str = strrchr(fPath.c_str(), '/'); | 123 const char* str = strrchr(fPath.c_str(), '/'); |
| 124 if (str) { | 124 if (str) { |
| 125 str += 1; // skip the '/' | 125 str += 1; // skip the '/' |
| 126 } | 126 } |
| 127 return str; | 127 return str; |
| 128 } | 128 } |
| 129 | 129 |
| 130 protected: | 130 protected: |
| 131 SkStream* onOpenStream(int* ttcIndex) const SK_OVERRIDE { | 131 SkStreamAsset* onOpenStream(int* ttcIndex) const SK_OVERRIDE { |
| 132 *ttcIndex = this->getIndex(); | 132 *ttcIndex = this->getIndex(); |
| 133 if (fStream.get()) { | 133 if (fStream.get()) { |
| 134 return fStream->duplicate(); | 134 return fStream->duplicate(); |
| 135 } else { | 135 } else { |
| 136 return SkStream::NewFromFile(fPath.c_str()); | 136 return SkStream::NewFromFile(fPath.c_str()); |
| 137 } | 137 } |
| 138 } | 138 } |
| 139 | 139 |
| 140 private: | 140 private: |
| 141 SkString fPath; | 141 SkString fPath; |
| (...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 279 } | 279 } |
| 280 } | 280 } |
| 281 } | 281 } |
| 282 return NULL; | 282 return NULL; |
| 283 } | 283 } |
| 284 | 284 |
| 285 SkTypeface* onCreateFromData(SkData* data, int ttcIndex) const SK_OVERRIDE { | 285 SkTypeface* onCreateFromData(SkData* data, int ttcIndex) const SK_OVERRIDE { |
| 286 return this->createFromStream(new SkMemoryStream(data), ttcIndex); | 286 return this->createFromStream(new SkMemoryStream(data), ttcIndex); |
| 287 } | 287 } |
| 288 | 288 |
| 289 SkTypeface* onCreateFromStream(SkStream* stream, int ttcIndex) const SK_OVER
RIDE { | 289 SkTypeface* onCreateFromStream(SkStreamAsset* bareStream, int ttcIndex) cons
t SK_OVERRIDE { |
| 290 SkAutoTDelete<SkStream> streamDeleter(stream); | 290 SkAutoTDelete<SkStreamAsset> stream(bareStream); |
| 291 if (NULL == stream || stream->getLength() <= 0) { | 291 if (NULL == stream || stream->getLength() <= 0) { |
| 292 return NULL; | 292 return NULL; |
| 293 } | 293 } |
| 294 | 294 |
| 295 bool isFixedPitch; | 295 bool isFixedPitch; |
| 296 SkFontStyle style; | 296 SkFontStyle style; |
| 297 SkString name; | 297 SkString name; |
| 298 if (fScanner.scanFont(stream, ttcIndex, &name, &style, &isFixedPitch)) { | 298 if (fScanner.scanFont(stream, ttcIndex, &name, &style, &isFixedPitch)) { |
| 299 return SkNEW_ARGS(SkTypeface_Stream, (style, isFixedPitch, false, na
me, | 299 return SkNEW_ARGS(SkTypeface_Stream, (style, isFixedPitch, false, na
me, |
| 300 streamDeleter.detach(), ttcInd
ex)); | 300 stream.detach(), ttcIndex)); |
| 301 } else { | 301 } else { |
| 302 return NULL; | 302 return NULL; |
| 303 } | 303 } |
| 304 } | 304 } |
| 305 | 305 |
| 306 SkTypeface* onCreateFromFile(const char path[], int ttcIndex) const SK_OVERR
IDE { | 306 SkTypeface* onCreateFromFile(const char path[], int ttcIndex) const SK_OVERR
IDE { |
| 307 SkAutoTDelete<SkStream> stream(SkStream::NewFromFile(path)); | 307 SkAutoTDelete<SkStreamAsset> stream(SkStream::NewFromFile(path)); |
| 308 return stream.get() ? this->createFromStream(stream.detach(), ttcIndex)
: NULL; | 308 return stream.get() ? this->createFromStream(stream.detach(), ttcIndex)
: NULL; |
| 309 } | 309 } |
| 310 | 310 |
| 311 virtual SkTypeface* onLegacyCreateTypeface(const char familyName[], | 311 virtual SkTypeface* onLegacyCreateTypeface(const char familyName[], |
| 312 unsigned styleBits) const SK_OVER
RIDE | 312 unsigned styleBits) const SK_OVER
RIDE |
| 313 { | 313 { |
| 314 SkTypeface::Style oldStyle = (SkTypeface::Style)styleBits; | 314 SkTypeface::Style oldStyle = (SkTypeface::Style)styleBits; |
| 315 SkFontStyle style = SkFontStyle(oldStyle & SkTypeface::kBold | 315 SkFontStyle style = SkFontStyle(oldStyle & SkTypeface::kBold |
| 316 ? SkFontStyle::kBold_Weight | 316 ? SkFontStyle::kBold_Weight |
| 317 : SkFontStyle::kNormal_Weight, | 317 : SkFontStyle::kNormal_Weight, |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 430 | 430 |
| 431 SkTArray<SkAutoTUnref<SkFontStyleSet_Custom>, true> fFamilies; | 431 SkTArray<SkAutoTUnref<SkFontStyleSet_Custom>, true> fFamilies; |
| 432 SkFontStyleSet_Custom* gDefaultFamily; | 432 SkFontStyleSet_Custom* gDefaultFamily; |
| 433 SkTypeface* gDefaultNormal; | 433 SkTypeface* gDefaultNormal; |
| 434 SkTypeface_FreeType::Scanner fScanner; | 434 SkTypeface_FreeType::Scanner fScanner; |
| 435 }; | 435 }; |
| 436 | 436 |
| 437 SkFontMgr* SkFontMgr::Factory() { | 437 SkFontMgr* SkFontMgr::Factory() { |
| 438 return new SkFontMgr_Custom(SK_FONT_FILE_PREFIX); | 438 return new SkFontMgr_Custom(SK_FONT_FILE_PREFIX); |
| 439 } | 439 } |
| OLD | NEW |