| 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 358 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 369 int width = map_ranges(style.width(), widthRanges, SK_ARRAY_COUNT(widthRange
s)); | 369 int width = map_ranges(style.width(), widthRanges, SK_ARRAY_COUNT(widthRange
s)); |
| 370 | 370 |
| 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(SkStreamAsset* stream, int index, const SkFixed* axes, int
axesCount, |
| 380 const SkFontStyle& style, bool fixedWidth) |
| 380 : INHERITED(style, SkTypefaceCache::NewFontID(), fixedWidth) | 381 : INHERITED(style, SkTypefaceCache::NewFontID(), fixedWidth) |
| 381 , fStream(stream) | 382 , fStream(stream) |
| 382 , fIndex(index) | 383 , fIndex(index) |
| 384 , fAxes(axes, axesCount) |
| 383 { }; | 385 { }; |
| 384 | 386 |
| 385 void onGetFamilyName(SkString* familyName) const override { | 387 void onGetFamilyName(SkString* familyName) const override { |
| 386 familyName->reset(); | 388 familyName->reset(); |
| 387 } | 389 } |
| 388 | 390 |
| 389 void onGetFontDescriptor(SkFontDescriptor* desc, bool* serialize) const over
ride { | 391 void onGetFontDescriptor(SkFontDescriptor* desc, bool* serialize) const over
ride { |
| 390 desc->setFontIndex(fIndex); | |
| 391 *serialize = true; | 392 *serialize = true; |
| 392 } | 393 } |
| 393 | 394 |
| 394 SkStreamAsset* onOpenStream(int* ttcIndex) const override { | 395 SkStreamAsset* onOpenStream(int* ttcIndex) const override { |
| 395 *ttcIndex = fIndex; | 396 *ttcIndex = fIndex; |
| 396 return fStream->duplicate(); | 397 return fStream->duplicate(); |
| 397 } | 398 } |
| 398 | 399 |
| 400 SkFontData* onCreateFontData() const override { |
| 401 return new SkFontData(fStream->duplicate(), fIndex, fAxes.count(), fAxes
.begin()); |
| 402 } |
| 403 |
| 399 private: | 404 private: |
| 400 SkAutoTDelete<SkStreamAsset> fStream; | 405 const SkAutoTDelete<const SkStreamAsset> fStream; |
| 401 int fIndex; | 406 const int fIndex; |
| 407 const SkSTArray<4, SkFixed, true> fAxes; |
| 402 | 408 |
| 403 typedef SkTypeface_FreeType INHERITED; | 409 typedef SkTypeface_FreeType INHERITED; |
| 404 }; | 410 }; |
| 405 | 411 |
| 406 class SkTypeface_fontconfig : public SkTypeface_FreeType { | 412 class SkTypeface_fontconfig : public SkTypeface_FreeType { |
| 407 public: | 413 public: |
| 408 /** @param pattern takes ownership of the reference. */ | 414 /** @param pattern takes ownership of the reference. */ |
| 409 static SkTypeface_fontconfig* Create(FcPattern* pattern) { | 415 static SkTypeface_fontconfig* Create(FcPattern* pattern) { |
| 410 return SkNEW_ARGS(SkTypeface_fontconfig, (pattern)); | 416 return SkNEW_ARGS(SkTypeface_fontconfig, (pattern)); |
| 411 } | 417 } |
| 412 mutable SkAutoFcPattern fPattern; | 418 mutable SkAutoFcPattern fPattern; |
| 413 | 419 |
| 414 void onGetFamilyName(SkString* familyName) const override { | 420 void onGetFamilyName(SkString* familyName) const override { |
| 415 *familyName = get_string(fPattern, FC_FAMILY); | 421 *familyName = get_string(fPattern, FC_FAMILY); |
| 416 } | 422 } |
| 417 | 423 |
| 418 void onGetFontDescriptor(SkFontDescriptor* desc, bool* serialize) const over
ride { | 424 void onGetFontDescriptor(SkFontDescriptor* desc, bool* serialize) const over
ride { |
| 419 FCLocker lock; | 425 FCLocker lock; |
| 420 desc->setFamilyName(get_string(fPattern, FC_FAMILY)); | 426 desc->setFamilyName(get_string(fPattern, FC_FAMILY)); |
| 421 desc->setFullName(get_string(fPattern, FC_FULLNAME)); | 427 desc->setFullName(get_string(fPattern, FC_FULLNAME)); |
| 422 desc->setPostscriptName(get_string(fPattern, FC_POSTSCRIPT_NAME)); | 428 desc->setPostscriptName(get_string(fPattern, FC_POSTSCRIPT_NAME)); |
| 423 desc->setFontIndex(get_int(fPattern, FC_INDEX, 0)); | |
| 424 *serialize = false; | 429 *serialize = false; |
| 425 } | 430 } |
| 426 | 431 |
| 427 SkStreamAsset* onOpenStream(int* ttcIndex) const override { | 432 SkStreamAsset* onOpenStream(int* ttcIndex) const override { |
| 428 FCLocker lock; | 433 FCLocker lock; |
| 429 *ttcIndex = get_int(fPattern, FC_INDEX, 0); | 434 *ttcIndex = get_int(fPattern, FC_INDEX, 0); |
| 430 return SkStream::NewFromFile(get_string(fPattern, FC_FILE)); | 435 return SkStream::NewFromFile(get_string(fPattern, FC_FILE)); |
| 431 } | 436 } |
| 432 | 437 |
| 433 virtual ~SkTypeface_fontconfig() { | 438 virtual ~SkTypeface_fontconfig() { |
| (...skipping 381 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 815 | 820 |
| 816 SkTypeface* onCreateFromStream(SkStreamAsset* bareStream, int ttcIndex) cons
t override { | 821 SkTypeface* onCreateFromStream(SkStreamAsset* bareStream, int ttcIndex) cons
t override { |
| 817 SkAutoTDelete<SkStreamAsset> stream(bareStream); | 822 SkAutoTDelete<SkStreamAsset> stream(bareStream); |
| 818 const size_t length = stream->getLength(); | 823 const size_t length = stream->getLength(); |
| 819 if (length <= 0 || (1u << 30) < length) { | 824 if (length <= 0 || (1u << 30) < length) { |
| 820 return NULL; | 825 return NULL; |
| 821 } | 826 } |
| 822 | 827 |
| 823 SkFontStyle style; | 828 SkFontStyle style; |
| 824 bool isFixedWidth = false; | 829 bool isFixedWidth = false; |
| 825 if (!fScanner.scanFont(stream, ttcIndex, NULL, &style, &isFixedWidth)) { | 830 if (!fScanner.scanFont(stream, ttcIndex, NULL, &style, &isFixedWidth, NU
LL)) { |
| 826 return NULL; | 831 return NULL; |
| 827 } | 832 } |
| 828 | 833 |
| 829 return SkNEW_ARGS(SkTypeface_stream, (style, isFixedWidth, ttcIndex, | 834 return SkNEW_ARGS(SkTypeface_stream, (stream.detach(), ttcIndex, NULL, 0
, |
| 830 static_cast<SkStreamAsset*>(stream
.detach()))); | 835 style, isFixedWidth)); |
| 831 } | 836 } |
| 832 | 837 |
| 833 SkTypeface* onCreateFromData(SkData* data, int ttcIndex) const override { | 838 SkTypeface* onCreateFromData(SkData* data, int ttcIndex) const override { |
| 834 return this->createFromStream(SkNEW_ARGS(SkMemoryStream, (data)), ttcInd
ex); | 839 return this->createFromStream(SkNEW_ARGS(SkMemoryStream, (data)), ttcInd
ex); |
| 835 } | 840 } |
| 836 | 841 |
| 837 SkTypeface* onCreateFromFile(const char path[], int ttcIndex) const override
{ | 842 SkTypeface* onCreateFromFile(const char path[], int ttcIndex) const override
{ |
| 838 return this->createFromStream(SkStream::NewFromFile(path), ttcIndex); | 843 return this->createFromStream(SkStream::NewFromFile(path), ttcIndex); |
| 839 } | 844 } |
| 840 | 845 |
| 846 SkTypeface* onCreateFromFontData(SkFontData* fontData) const override { |
| 847 SkAutoTDelete<SkStreamAsset> stream(fontData->detachStream()); |
| 848 const size_t length = stream->getLength(); |
| 849 if (length <= 0 || (1u << 30) < length) { |
| 850 return NULL; |
| 851 } |
| 852 |
| 853 const int ttcIndex = fontData->getIndex(); |
| 854 SkFontStyle style; |
| 855 bool isFixedWidth = false; |
| 856 if (!fScanner.scanFont(stream, ttcIndex, NULL, &style, &isFixedWidth, NU
LL)) { |
| 857 return NULL; |
| 858 } |
| 859 |
| 860 return SkNEW_ARGS(SkTypeface_stream, (stream.detach(), ttcIndex, |
| 861 fontData->getAxis(), fontData->get
AxisCount(), |
| 862 style, isFixedWidth)); |
| 863 } |
| 864 |
| 841 virtual SkTypeface* onLegacyCreateTypeface(const char familyName[], | 865 virtual SkTypeface* onLegacyCreateTypeface(const char familyName[], |
| 842 unsigned styleBits) const overrid
e { | 866 unsigned styleBits) const overrid
e { |
| 843 bool bold = styleBits & SkTypeface::kBold; | 867 bool bold = styleBits & SkTypeface::kBold; |
| 844 bool italic = styleBits & SkTypeface::kItalic; | 868 bool italic = styleBits & SkTypeface::kItalic; |
| 845 SkFontStyle style = SkFontStyle(bold ? SkFontStyle::kBold_Weight | 869 SkFontStyle style = SkFontStyle(bold ? SkFontStyle::kBold_Weight |
| 846 : SkFontStyle::kNormal_Weight, | 870 : SkFontStyle::kNormal_Weight, |
| 847 SkFontStyle::kNormal_Width, | 871 SkFontStyle::kNormal_Width, |
| 848 italic ? SkFontStyle::kItalic_Slant | 872 italic ? SkFontStyle::kItalic_Slant |
| 849 : SkFontStyle::kUpright_Slant); | 873 : SkFontStyle::kUpright_Slant); |
| 850 SkAutoTUnref<SkTypeface> typeface(this->matchFamilyStyle(familyName, sty
le)); | 874 SkAutoTUnref<SkTypeface> typeface(this->matchFamilyStyle(familyName, sty
le)); |
| 851 if (typeface.get()) { | 875 if (typeface.get()) { |
| 852 return typeface.detach(); | 876 return typeface.detach(); |
| 853 } | 877 } |
| 854 | 878 |
| 855 return this->matchFamilyStyle(NULL, style); | 879 return this->matchFamilyStyle(NULL, style); |
| 856 } | 880 } |
| 857 }; | 881 }; |
| 858 | 882 |
| 859 SkFontMgr* SkFontMgr::Factory() { | 883 SkFontMgr* SkFontMgr::Factory() { |
| 860 return SkNEW(SkFontMgr_fontconfig); | 884 return SkNEW(SkFontMgr_fontconfig); |
| 861 } | 885 } |
| OLD | NEW |