Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright 2014 Google Inc. | 2 * Copyright 2014 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 "SkDataTable.h" | 8 #include "SkDataTable.h" |
| 9 #include "SkFontDescriptor.h" | 9 #include "SkFontDescriptor.h" |
| 10 #include "SkFontHost_FreeType_common.h" | 10 #include "SkFontHost_FreeType_common.h" |
| (...skipping 360 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 371 FcPatternAddInteger(pattern, FC_WEIGHT, weight); | 371 FcPatternAddInteger(pattern, FC_WEIGHT, weight); |
| 372 FcPatternAddInteger(pattern, FC_WIDTH, width); | 372 FcPatternAddInteger(pattern, FC_WIDTH, width); |
| 373 FcPatternAddInteger(pattern, FC_SLANT, style.isItalic() ? FC_SLANT_ITALIC : FC_SLANT_ROMAN); | 373 FcPatternAddInteger(pattern, FC_SLANT, style.isItalic() ? FC_SLANT_ITALIC : FC_SLANT_ROMAN); |
| 374 } | 374 } |
| 375 | 375 |
| 376 class SkTypeface_stream : public SkTypeface_FreeType { | 376 class SkTypeface_stream : public SkTypeface_FreeType { |
| 377 public: | 377 public: |
| 378 /** @param stream does not take ownership of the reference, does take owners hip of the stream.*/ | 378 /** @param stream does not take ownership of the reference, does take owners hip of the stream.*/ |
| 379 SkTypeface_stream(const SkFontStyle& style, bool fixedWidth, int index, SkSt reamAsset* stream) | 379 SkTypeface_stream(const SkFontStyle& style, bool fixedWidth, int index, SkSt reamAsset* stream) |
| 380 : INHERITED(style, SkTypefaceCache::NewFontID(), fixedWidth) | 380 : INHERITED(style, SkTypefaceCache::NewFontID(), fixedWidth) |
| 381 , fStream(SkRef(stream)) | 381 , fStream(stream) |
| 382 , fIndex(index) | 382 , fIndex(index) |
| 383 { }; | 383 { }; |
| 384 | 384 |
| 385 void onGetFamilyName(SkString* familyName) const SK_OVERRIDE { | 385 void onGetFamilyName(SkString* familyName) const SK_OVERRIDE { |
| 386 familyName->reset(); | 386 familyName->reset(); |
| 387 } | 387 } |
| 388 | 388 |
| 389 void onGetFontDescriptor(SkFontDescriptor* desc, bool* serialize) const SK_O VERRIDE { | 389 void onGetFontDescriptor(SkFontDescriptor* desc, bool* serialize) const SK_O VERRIDE { |
| 390 desc->setFontIndex(fIndex); | 390 desc->setFontIndex(fIndex); |
| 391 *serialize = true; | 391 *serialize = true; |
| 392 } | 392 } |
| 393 | 393 |
| 394 SkStream* onOpenStream(int* ttcIndex) const SK_OVERRIDE { | 394 SkStream* onOpenStream(int* ttcIndex) const SK_OVERRIDE { |
| 395 *ttcIndex = fIndex; | 395 *ttcIndex = fIndex; |
| 396 return fStream->duplicate(); | 396 return fStream->duplicate(); |
| 397 } | 397 } |
| 398 | 398 |
| 399 private: | 399 private: |
| 400 SkAutoTUnref<SkStreamAsset> fStream; | 400 SkAutoTDelete<SkStreamAsset> fStream; |
| 401 int fIndex; | 401 int fIndex; |
| 402 | 402 |
| 403 typedef SkTypeface_FreeType INHERITED; | 403 typedef SkTypeface_FreeType INHERITED; |
| 404 }; | 404 }; |
| 405 | 405 |
| 406 class SkTypeface_fontconfig : public SkTypeface_FreeType { | 406 class SkTypeface_fontconfig : public SkTypeface_FreeType { |
| 407 public: | 407 public: |
| 408 /** @param pattern takes ownership of the reference. */ | 408 /** @param pattern takes ownership of the reference. */ |
| 409 static SkTypeface_fontconfig* Create(FcPattern* pattern) { | 409 static SkTypeface_fontconfig* Create(FcPattern* pattern) { |
| 410 return SkNEW_ARGS(SkTypeface_fontconfig, (pattern)); | 410 return SkNEW_ARGS(SkTypeface_fontconfig, (pattern)); |
| (...skipping 401 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 812 /** @param stream does not take ownership of the reference. */ | 812 /** @param stream does not take ownership of the reference. */ |
| 813 SkTypeface* onCreateFromStream(SkStream* stream, int ttcIndex) const SK_OVER RIDE { | 813 SkTypeface* onCreateFromStream(SkStream* stream, int ttcIndex) const SK_OVER RIDE { |
| 814 const size_t length = stream->getLength(); | 814 const size_t length = stream->getLength(); |
| 815 if (length <= 0 || (1u << 30) < length) { | 815 if (length <= 0 || (1u << 30) < length) { |
| 816 return NULL; | 816 return NULL; |
| 817 } | 817 } |
| 818 | 818 |
| 819 SkFontStyle style; | 819 SkFontStyle style; |
| 820 bool isFixedWidth = false; | 820 bool isFixedWidth = false; |
| 821 if (!fScanner.scanFont(stream, ttcIndex, NULL, &style, &isFixedWidth)) { | 821 if (!fScanner.scanFont(stream, ttcIndex, NULL, &style, &isFixedWidth)) { |
| 822 return NULL; | 822 return NULL; |
|
bungeman-skia
2015/01/20 21:41:48
Here we need to delete the stream.
scroggo
2015/01/20 22:19:09
Done with SkAutoTDelete.
| |
| 823 } | 823 } |
| 824 | 824 |
| 825 return SkNEW_ARGS(SkTypeface_stream, (style, isFixedWidth, ttcIndex, | 825 return SkNEW_ARGS(SkTypeface_stream, (style, isFixedWidth, ttcIndex, |
| 826 static_cast<SkStreamAsset*>(stream ))); | 826 static_cast<SkStreamAsset*>(stream ))); |
| 827 } | 827 } |
| 828 | 828 |
| 829 SkTypeface* onCreateFromData(SkData* data, int ttcIndex) const SK_OVERRIDE { | 829 SkTypeface* onCreateFromData(SkData* data, int ttcIndex) const SK_OVERRIDE { |
| 830 SkAutoTUnref<SkStreamAsset> stream(SkNEW_ARGS(SkMemoryStream, (data))); | 830 return this->createFromStream(SkNEW_ARGS(SkMemoryStream, (data)), ttcInd ex); |
| 831 return this->createFromStream(stream, ttcIndex); | |
| 832 } | 831 } |
| 833 | 832 |
| 834 SkTypeface* onCreateFromFile(const char path[], int ttcIndex) const SK_OVERR IDE { | 833 SkTypeface* onCreateFromFile(const char path[], int ttcIndex) const SK_OVERR IDE { |
| 835 SkAutoTUnref<SkStreamAsset> stream(SkStream::NewFromFile(path)); | 834 return this->createFromStream(SkStream::NewFromFile(path), ttcIndex); |
| 836 return this->createFromStream(stream, ttcIndex); | |
| 837 } | 835 } |
| 838 | 836 |
| 839 virtual SkTypeface* onLegacyCreateTypeface(const char familyName[], | 837 virtual SkTypeface* onLegacyCreateTypeface(const char familyName[], |
| 840 unsigned styleBits) const SK_OVER RIDE { | 838 unsigned styleBits) const SK_OVER RIDE { |
| 841 bool bold = styleBits & SkTypeface::kBold; | 839 bool bold = styleBits & SkTypeface::kBold; |
| 842 bool italic = styleBits & SkTypeface::kItalic; | 840 bool italic = styleBits & SkTypeface::kItalic; |
| 843 SkFontStyle style = SkFontStyle(bold ? SkFontStyle::kBold_Weight | 841 SkFontStyle style = SkFontStyle(bold ? SkFontStyle::kBold_Weight |
| 844 : SkFontStyle::kNormal_Weight, | 842 : SkFontStyle::kNormal_Weight, |
| 845 SkFontStyle::kNormal_Width, | 843 SkFontStyle::kNormal_Width, |
| 846 italic ? SkFontStyle::kItalic_Slant | 844 italic ? SkFontStyle::kItalic_Slant |
| 847 : SkFontStyle::kUpright_Slant); | 845 : SkFontStyle::kUpright_Slant); |
| 848 SkAutoTUnref<SkTypeface> typeface(this->matchFamilyStyle(familyName, sty le)); | 846 SkAutoTUnref<SkTypeface> typeface(this->matchFamilyStyle(familyName, sty le)); |
| 849 if (typeface.get()) { | 847 if (typeface.get()) { |
| 850 return typeface.detach(); | 848 return typeface.detach(); |
| 851 } | 849 } |
| 852 | 850 |
| 853 return this->matchFamilyStyle(NULL, style); | 851 return this->matchFamilyStyle(NULL, style); |
| 854 } | 852 } |
| 855 }; | 853 }; |
| 856 | 854 |
| 857 SkFontMgr* SkFontMgr::Factory() { | 855 SkFontMgr* SkFontMgr::Factory() { |
| 858 return SkNEW(SkFontMgr_fontconfig); | 856 return SkNEW(SkFontMgr_fontconfig); |
| 859 } | 857 } |
| OLD | NEW |