| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2011 Google Inc. | 2 * Copyright 2011 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 "SkData.h" | 8 #include "SkData.h" |
| 9 #include "SkGlyphCache.h" | 9 #include "SkGlyphCache.h" |
| 10 #include "SkPaint.h" | 10 #include "SkPaint.h" |
| (...skipping 738 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 749 } | 749 } |
| 750 #endif // SK_SFNTLY_SUBSETTER | 750 #endif // SK_SFNTLY_SUBSETTER |
| 751 | 751 |
| 752 bool SkPDFType0Font::populate(const SkPDFGlyphSet* subset) { | 752 bool SkPDFType0Font::populate(const SkPDFGlyphSet* subset) { |
| 753 SkASSERT(this->canEmbed()); | 753 SkASSERT(this->canEmbed()); |
| 754 SkASSERT(this->getFontInfo()); | 754 SkASSERT(this->getFontInfo()); |
| 755 const SkAdvancedTypefaceMetrics& metrics = *(this->getFontInfo()); | 755 const SkAdvancedTypefaceMetrics& metrics = *(this->getFontInfo()); |
| 756 SkAdvancedTypefaceMetrics::FontType type = this->getType(); | 756 SkAdvancedTypefaceMetrics::FontType type = this->getType(); |
| 757 SkTypeface* face = this->typeface(); | 757 SkTypeface* face = this->typeface(); |
| 758 SkASSERT(face); | 758 SkASSERT(face); |
| 759 const char* name = metrics.fFontName.c_str(); | 759 const SkString& name = metrics.fFontName; |
| 760 | 760 |
| 761 auto descriptor = sk_make_sp<SkPDFDict>("FontDescriptor"); | 761 auto descriptor = sk_make_sp<SkPDFDict>("FontDescriptor"); |
| 762 add_common_font_descriptor_entries(descriptor.get(), metrics, 0); | 762 add_common_font_descriptor_entries(descriptor.get(), metrics, 0); |
| 763 switch (type) { | 763 switch (type) { |
| 764 case SkAdvancedTypefaceMetrics::kTrueType_Font: { | 764 case SkAdvancedTypefaceMetrics::kTrueType_Font: { |
| 765 int ttcIndex; | 765 int ttcIndex; |
| 766 std::unique_ptr<SkStreamAsset> fontAsset(face->openStream(&ttcIndex)
); | 766 std::unique_ptr<SkStreamAsset> fontAsset(face->openStream(&ttcIndex)
); |
| 767 SkASSERT(fontAsset); | 767 SkASSERT(fontAsset); |
| 768 if (!fontAsset) { | 768 if (!fontAsset) { |
| 769 return false; | 769 return false; |
| 770 } | 770 } |
| 771 size_t fontSize = fontAsset->getLength(); | 771 size_t fontSize = fontAsset->getLength(); |
| 772 SkASSERT(fontSize > 0); | 772 SkASSERT(fontSize > 0); |
| 773 if (fontSize == 0) { | 773 if (fontSize == 0) { |
| 774 return false; | 774 return false; |
| 775 } | 775 } |
| 776 | 776 |
| 777 #ifdef SK_SFNTLY_SUBSETTER | 777 #ifdef SK_SFNTLY_SUBSETTER |
| 778 if (this->canSubset() && subset) { | 778 if (this->canSubset() && subset) { |
| 779 // Generate glyph id array. in format needed by sfntly | 779 // Generate glyph id array. in format needed by sfntly |
| 780 SkTDArray<uint32_t> glyphIDs; | 780 SkTDArray<uint32_t> glyphIDs; |
| 781 if (subset) { | 781 if (subset) { |
| 782 if (!subset->has(0)) { | 782 if (!subset->has(0)) { |
| 783 glyphIDs.push(0); // Always include glyph 0. | 783 glyphIDs.push(0); // Always include glyph 0. |
| 784 } | 784 } |
| 785 subset->exportTo(&glyphIDs); | 785 subset->exportTo(&glyphIDs); |
| 786 } | 786 } |
| 787 sk_sp<SkPDFObject> subsetStream = get_subset_font_stream( | 787 sk_sp<SkPDFObject> subsetStream = get_subset_font_stream( |
| 788 std::move(fontAsset), glyphIDs, name); | 788 std::move(fontAsset), glyphIDs, name.c_str()); |
| 789 if (subsetStream) { | 789 if (subsetStream) { |
| 790 descriptor->insertObjRef("FontFile2", std::move(subsetStream
)); | 790 descriptor->insertObjRef("FontFile2", std::move(subsetStream
)); |
| 791 break; | 791 break; |
| 792 } | 792 } |
| 793 // If subsetting fails, fall back to original font data. | 793 // If subsetting fails, fall back to original font data. |
| 794 fontAsset.reset(face->openStream(&ttcIndex)); | 794 fontAsset.reset(face->openStream(&ttcIndex)); |
| 795 } | 795 } |
| 796 #endif // SK_SFNTLY_SUBSETTER | 796 #endif // SK_SFNTLY_SUBSETTER |
| 797 auto fontStream = sk_make_sp<SkPDFSharedStream>(std::move(fontAsset)
); | 797 auto fontStream = sk_make_sp<SkPDFSharedStream>(std::move(fontAsset)
); |
| 798 fontStream->dict()->insertInt("Length1", fontSize); | 798 fontStream->dict()->insertInt("Length1", fontSize); |
| (...skipping 390 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1189 } | 1189 } |
| 1190 return *canon->fCanEmbedTypeface.set(id, canEmbed); | 1190 return *canon->fCanEmbedTypeface.set(id, canEmbed); |
| 1191 } | 1191 } |
| 1192 | 1192 |
| 1193 void SkPDFFont::drop() { | 1193 void SkPDFFont::drop() { |
| 1194 fTypeface = nullptr; | 1194 fTypeface = nullptr; |
| 1195 fFontInfo = nullptr; | 1195 fFontInfo = nullptr; |
| 1196 fDescriptor = nullptr; | 1196 fDescriptor = nullptr; |
| 1197 this->SkPDFDict::drop(); | 1197 this->SkPDFDict::drop(); |
| 1198 } | 1198 } |
| OLD | NEW |