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 <ctype.h> | 8 #include <ctype.h> |
9 | 9 |
10 #include "SkData.h" | 10 #include "SkData.h" |
(...skipping 320 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
331 Data* defaultAdvance) { | 331 Data* defaultAdvance) { |
332 SkPDFArray* result = new SkPDFArray(); | 332 SkPDFArray* result = new SkPDFArray(); |
333 for (; advanceInfo != nullptr; advanceInfo = advanceInfo->fNext.get()) { | 333 for (; advanceInfo != nullptr; advanceInfo = advanceInfo->fNext.get()) { |
334 switch (advanceInfo->fType) { | 334 switch (advanceInfo->fType) { |
335 case SkAdvancedTypefaceMetrics::WidthRange::kDefault: { | 335 case SkAdvancedTypefaceMetrics::WidthRange::kDefault: { |
336 SkASSERT(advanceInfo->fAdvance.count() == 1); | 336 SkASSERT(advanceInfo->fAdvance.count() == 1); |
337 *defaultAdvance = advanceInfo->fAdvance[0]; | 337 *defaultAdvance = advanceInfo->fAdvance[0]; |
338 break; | 338 break; |
339 } | 339 } |
340 case SkAdvancedTypefaceMetrics::WidthRange::kRange: { | 340 case SkAdvancedTypefaceMetrics::WidthRange::kRange: { |
341 SkAutoTUnref<SkPDFArray> advanceArray(new SkPDFArray()); | 341 sk_sp<SkPDFArray> advanceArray(new SkPDFArray()); |
342 for (int j = 0; j < advanceInfo->fAdvance.count(); j++) | 342 for (int j = 0; j < advanceInfo->fAdvance.count(); j++) |
343 appendAdvance(advanceInfo->fAdvance[j], emSize, | 343 appendAdvance(advanceInfo->fAdvance[j], emSize, |
344 advanceArray.get()); | 344 advanceArray.get()); |
345 result->appendInt(advanceInfo->fStartId); | 345 result->appendInt(advanceInfo->fStartId); |
346 result->appendObject(advanceArray.release()); | 346 result->appendObject(advanceArray.release()); |
347 break; | 347 break; |
348 } | 348 } |
349 case SkAdvancedTypefaceMetrics::WidthRange::kRun: { | 349 case SkAdvancedTypefaceMetrics::WidthRange::kRun: { |
350 SkASSERT(advanceInfo->fAdvance.count() == 1); | 350 SkASSERT(advanceInfo->fAdvance.count() == 1); |
351 result->appendInt(advanceInfo->fStartId); | 351 result->appendInt(advanceInfo->fStartId); |
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
567 uint16_t lastGlyphID) { | 567 uint16_t lastGlyphID) { |
568 SkDynamicMemoryWStream cmap; | 568 SkDynamicMemoryWStream cmap; |
569 if (multiByteGlyphs) { | 569 if (multiByteGlyphs) { |
570 append_tounicode_header(&cmap, firstGlyphID, lastGlyphID); | 570 append_tounicode_header(&cmap, firstGlyphID, lastGlyphID); |
571 } else { | 571 } else { |
572 append_tounicode_header(&cmap, 1, lastGlyphID - firstGlyphID + 1); | 572 append_tounicode_header(&cmap, 1, lastGlyphID - firstGlyphID + 1); |
573 } | 573 } |
574 append_cmap_sections(glyphToUnicode, subset, &cmap, multiByteGlyphs, | 574 append_cmap_sections(glyphToUnicode, subset, &cmap, multiByteGlyphs, |
575 firstGlyphID, lastGlyphID); | 575 firstGlyphID, lastGlyphID); |
576 append_cmap_footer(&cmap); | 576 append_cmap_footer(&cmap); |
577 SkAutoTUnref<SkData> cmapData(cmap.copyToData()); | 577 sk_sp<SkData> cmapData(cmap.copyToData()); |
578 return new SkPDFStream(cmapData.get()); | 578 return new SkPDFStream(cmapData.get()); |
579 } | 579 } |
580 | 580 |
581 #if defined (SK_SFNTLY_SUBSETTER) | 581 #if defined (SK_SFNTLY_SUBSETTER) |
582 static void sk_delete_array(const void* ptr, void*) { | 582 static void sk_delete_array(const void* ptr, void*) { |
583 // Use C-style cast to cast away const and cast type simultaneously. | 583 // Use C-style cast to cast away const and cast type simultaneously. |
584 delete[] (unsigned char*)ptr; | 584 delete[] (unsigned char*)ptr; |
585 } | 585 } |
586 #endif | 586 #endif |
587 | 587 |
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
799 SkASSERT(canon); | 799 SkASSERT(canon); |
800 SkAutoResolveDefaultTypeface autoResolve(typeface); | 800 SkAutoResolveDefaultTypeface autoResolve(typeface); |
801 typeface = autoResolve.get(); | 801 typeface = autoResolve.get(); |
802 const uint32_t fontID = typeface->uniqueID(); | 802 const uint32_t fontID = typeface->uniqueID(); |
803 | 803 |
804 SkPDFFont* relatedFont; | 804 SkPDFFont* relatedFont; |
805 if (SkPDFFont* pdfFont = canon->findFont(fontID, glyphID, &relatedFont)) { | 805 if (SkPDFFont* pdfFont = canon->findFont(fontID, glyphID, &relatedFont)) { |
806 return SkRef(pdfFont); | 806 return SkRef(pdfFont); |
807 } | 807 } |
808 | 808 |
809 SkAutoTUnref<const SkAdvancedTypefaceMetrics> fontMetrics; | 809 sk_sp<const SkAdvancedTypefaceMetrics> fontMetrics; |
810 SkPDFDict* relatedFontDescriptor = nullptr; | 810 SkPDFDict* relatedFontDescriptor = nullptr; |
811 if (relatedFont) { | 811 if (relatedFont) { |
812 fontMetrics.reset(SkSafeRef(relatedFont->fontInfo())); | 812 fontMetrics.reset(SkSafeRef(relatedFont->fontInfo())); |
813 relatedFontDescriptor = relatedFont->getFontDescriptor(); | 813 relatedFontDescriptor = relatedFont->getFontDescriptor(); |
814 | 814 |
815 // This only is to catch callers who pass invalid glyph ids. | 815 // This only is to catch callers who pass invalid glyph ids. |
816 // If glyph id is invalid, then we will create duplicate entries | 816 // If glyph id is invalid, then we will create duplicate entries |
817 // for TrueType fonts. | 817 // for TrueType fonts. |
818 SkAdvancedTypefaceMetrics::FontType fontType = | 818 SkAdvancedTypefaceMetrics::FontType fontType = |
819 fontMetrics.get() ? fontMetrics.get()->fType : | 819 fontMetrics.get() ? fontMetrics.get()->fType : |
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1012 SkASSERT(fPopulated); | 1012 SkASSERT(fPopulated); |
1013 return INHERITED::emitObject(stream, objNumMap, substitutes); | 1013 return INHERITED::emitObject(stream, objNumMap, substitutes); |
1014 } | 1014 } |
1015 #endif | 1015 #endif |
1016 | 1016 |
1017 bool SkPDFType0Font::populate(const SkPDFGlyphSet* subset) { | 1017 bool SkPDFType0Font::populate(const SkPDFGlyphSet* subset) { |
1018 insertName("Subtype", "Type0"); | 1018 insertName("Subtype", "Type0"); |
1019 insertName("BaseFont", fontInfo()->fFontName); | 1019 insertName("BaseFont", fontInfo()->fFontName); |
1020 insertName("Encoding", "Identity-H"); | 1020 insertName("Encoding", "Identity-H"); |
1021 | 1021 |
1022 SkAutoTUnref<SkPDFCIDFont> newCIDFont( | 1022 sk_sp<SkPDFCIDFont> newCIDFont( |
1023 new SkPDFCIDFont(fontInfo(), typeface(), subset)); | 1023 new SkPDFCIDFont(fontInfo(), typeface(), subset)); |
1024 SkAutoTUnref<SkPDFArray> descendantFonts(new SkPDFArray()); | 1024 sk_sp<SkPDFArray> descendantFonts(new SkPDFArray()); |
1025 descendantFonts->appendObjRef(newCIDFont.release()); | 1025 descendantFonts->appendObjRef(newCIDFont.release()); |
1026 this->insertObject("DescendantFonts", descendantFonts.release()); | 1026 this->insertObject("DescendantFonts", descendantFonts.release()); |
1027 | 1027 |
1028 this->populateToUnicodeTable(subset); | 1028 this->populateToUnicodeTable(subset); |
1029 | 1029 |
1030 SkDEBUGCODE(fPopulated = true); | 1030 SkDEBUGCODE(fPopulated = true); |
1031 return true; | 1031 return true; |
1032 } | 1032 } |
1033 | 1033 |
1034 /////////////////////////////////////////////////////////////////////////////// | 1034 /////////////////////////////////////////////////////////////////////////////// |
1035 // class SkPDFCIDFont | 1035 // class SkPDFCIDFont |
1036 /////////////////////////////////////////////////////////////////////////////// | 1036 /////////////////////////////////////////////////////////////////////////////// |
1037 | 1037 |
1038 SkPDFCIDFont::SkPDFCIDFont(const SkAdvancedTypefaceMetrics* info, | 1038 SkPDFCIDFont::SkPDFCIDFont(const SkAdvancedTypefaceMetrics* info, |
1039 SkTypeface* typeface, | 1039 SkTypeface* typeface, |
1040 const SkPDFGlyphSet* subset) | 1040 const SkPDFGlyphSet* subset) |
1041 : SkPDFFont(info, typeface, nullptr) { | 1041 : SkPDFFont(info, typeface, nullptr) { |
1042 this->populate(subset); | 1042 this->populate(subset); |
1043 } | 1043 } |
1044 | 1044 |
1045 SkPDFCIDFont::~SkPDFCIDFont() {} | 1045 SkPDFCIDFont::~SkPDFCIDFont() {} |
1046 | 1046 |
1047 bool SkPDFCIDFont::addFontDescriptor(int16_t defaultWidth, | 1047 bool SkPDFCIDFont::addFontDescriptor(int16_t defaultWidth, |
1048 const SkTDArray<uint32_t>* subset) { | 1048 const SkTDArray<uint32_t>* subset) { |
1049 SkAutoTUnref<SkPDFDict> descriptor(new SkPDFDict("FontDescriptor")); | 1049 sk_sp<SkPDFDict> descriptor(new SkPDFDict("FontDescriptor")); |
1050 setFontDescriptor(descriptor.get()); | 1050 setFontDescriptor(descriptor.get()); |
1051 if (!addCommonFontDescriptorEntries(defaultWidth)) { | 1051 if (!addCommonFontDescriptorEntries(defaultWidth)) { |
1052 this->insertObjRef("FontDescriptor", descriptor.release()); | 1052 this->insertObjRef("FontDescriptor", descriptor.release()); |
1053 return false; | 1053 return false; |
1054 } | 1054 } |
1055 SkASSERT(this->canEmbed()); | 1055 SkASSERT(this->canEmbed()); |
1056 | 1056 |
1057 switch (getType()) { | 1057 switch (getType()) { |
1058 case SkAdvancedTypefaceMetrics::kTrueType_Font: { | 1058 case SkAdvancedTypefaceMetrics::kTrueType_Font: { |
1059 size_t fontSize = 0; | 1059 size_t fontSize = 0; |
1060 #if defined(SK_SFNTLY_SUBSETTER) | 1060 #if defined(SK_SFNTLY_SUBSETTER) |
1061 if (this->canSubset()) { | 1061 if (this->canSubset()) { |
1062 SkAutoTUnref<SkPDFStream> fontStream; | 1062 sk_sp<SkPDFStream> fontStream; |
1063 SkPDFStream* rawStream = nullptr; | 1063 SkPDFStream* rawStream = nullptr; |
1064 fontSize = get_subset_font_stream(fontInfo()->fFontName.c_str(), | 1064 fontSize = get_subset_font_stream(fontInfo()->fFontName.c_str(), |
1065 typeface(), | 1065 typeface(), |
1066 *subset, | 1066 *subset, |
1067 &rawStream); | 1067 &rawStream); |
1068 if (rawStream) { | 1068 if (rawStream) { |
1069 fontStream.reset(rawStream); | 1069 fontStream.reset(rawStream); |
1070 fontStream->insertInt("Length1", fontSize); | 1070 fontStream->insertInt("Length1", fontSize); |
1071 descriptor->insertObjRef("FontFile2", fontStream.release()); | 1071 descriptor->insertObjRef("FontFile2", fontStream.release()); |
1072 break; | 1072 break; |
1073 } | 1073 } |
1074 } | 1074 } |
1075 #endif | 1075 #endif |
1076 SkAutoTUnref<SkPDFSharedStream> fontStream; | 1076 sk_sp<SkPDFSharedStream> fontStream; |
1077 SkAutoTDelete<SkStreamAsset> fontData( | 1077 SkAutoTDelete<SkStreamAsset> fontData( |
1078 this->typeface()->openStream(nullptr)); | 1078 this->typeface()->openStream(nullptr)); |
1079 SkASSERT(fontData); | 1079 SkASSERT(fontData); |
1080 fontSize = fontData->getLength(); | 1080 fontSize = fontData->getLength(); |
1081 SkASSERT(fontSize > 0); | 1081 SkASSERT(fontSize > 0); |
1082 fontStream.reset(new SkPDFSharedStream(fontData.detach())); | 1082 fontStream.reset(new SkPDFSharedStream(fontData.detach())); |
1083 fontStream->dict()->insertInt("Length1", fontSize); | 1083 fontStream->dict()->insertInt("Length1", fontSize); |
1084 descriptor->insertObjRef("FontFile2", fontStream.release()); | 1084 descriptor->insertObjRef("FontFile2", fontStream.release()); |
1085 break; | 1085 break; |
1086 } | 1086 } |
1087 case SkAdvancedTypefaceMetrics::kCFF_Font: | 1087 case SkAdvancedTypefaceMetrics::kCFF_Font: |
1088 case SkAdvancedTypefaceMetrics::kType1CID_Font: { | 1088 case SkAdvancedTypefaceMetrics::kType1CID_Font: { |
1089 SkAutoTUnref<SkPDFSharedStream> fontStream( | 1089 sk_sp<SkPDFSharedStream> fontStream( |
1090 new SkPDFSharedStream(this->typeface()->openStream(nullptr))
); | 1090 new SkPDFSharedStream(this->typeface()->openStream(nullptr))
); |
1091 | 1091 |
1092 if (getType() == SkAdvancedTypefaceMetrics::kCFF_Font) { | 1092 if (getType() == SkAdvancedTypefaceMetrics::kCFF_Font) { |
1093 fontStream->dict()->insertName("Subtype", "Type1C"); | 1093 fontStream->dict()->insertName("Subtype", "Type1C"); |
1094 } else { | 1094 } else { |
1095 fontStream->dict()->insertName("Subtype", "CIDFontType0c"); | 1095 fontStream->dict()->insertName("Subtype", "CIDFontType0c"); |
1096 } | 1096 } |
1097 descriptor->insertObjRef("FontFile3", fontStream.release()); | 1097 descriptor->insertObjRef("FontFile3", fontStream.release()); |
1098 break; | 1098 break; |
1099 } | 1099 } |
(...skipping 16 matching lines...) Expand all Loading... |
1116 } | 1116 } |
1117 subset->exportTo(&glyphIDs); | 1117 subset->exportTo(&glyphIDs); |
1118 } | 1118 } |
1119 | 1119 |
1120 SkTypeface::PerGlyphInfo info; | 1120 SkTypeface::PerGlyphInfo info; |
1121 info = SkTypeface::kGlyphNames_PerGlyphInfo; | 1121 info = SkTypeface::kGlyphNames_PerGlyphInfo; |
1122 info = SkTBitOr<SkTypeface::PerGlyphInfo>( | 1122 info = SkTBitOr<SkTypeface::PerGlyphInfo>( |
1123 info, SkTypeface::kHAdvance_PerGlyphInfo); | 1123 info, SkTypeface::kHAdvance_PerGlyphInfo); |
1124 uint32_t* glyphs = (glyphIDs.count() == 0) ? nullptr : glyphIDs.begin(); | 1124 uint32_t* glyphs = (glyphIDs.count() == 0) ? nullptr : glyphIDs.begin(); |
1125 uint32_t glyphsCount = glyphs ? glyphIDs.count() : 0; | 1125 uint32_t glyphsCount = glyphs ? glyphIDs.count() : 0; |
1126 SkAutoTUnref<const SkAdvancedTypefaceMetrics> fontMetrics( | 1126 sk_sp<const SkAdvancedTypefaceMetrics> fontMetrics( |
1127 typeface()->getAdvancedTypefaceMetrics(info, glyphs, glyphsCount)); | 1127 typeface()->getAdvancedTypefaceMetrics(info, glyphs, glyphsCount)); |
1128 setFontInfo(fontMetrics.get()); | 1128 setFontInfo(fontMetrics.get()); |
1129 addFontDescriptor(0, &glyphIDs); | 1129 addFontDescriptor(0, &glyphIDs); |
1130 } else { | 1130 } else { |
1131 // Other CID fonts | 1131 // Other CID fonts |
1132 addFontDescriptor(0, nullptr); | 1132 addFontDescriptor(0, nullptr); |
1133 } | 1133 } |
1134 | 1134 |
1135 insertName("BaseFont", fontInfo()->fFontName); | 1135 insertName("BaseFont", fontInfo()->fFontName); |
1136 | 1136 |
1137 if (getType() == SkAdvancedTypefaceMetrics::kType1CID_Font) { | 1137 if (getType() == SkAdvancedTypefaceMetrics::kType1CID_Font) { |
1138 insertName("Subtype", "CIDFontType0"); | 1138 insertName("Subtype", "CIDFontType0"); |
1139 } else if (getType() == SkAdvancedTypefaceMetrics::kTrueType_Font) { | 1139 } else if (getType() == SkAdvancedTypefaceMetrics::kTrueType_Font) { |
1140 insertName("Subtype", "CIDFontType2"); | 1140 insertName("Subtype", "CIDFontType2"); |
1141 insertName("CIDToGIDMap", "Identity"); | 1141 insertName("CIDToGIDMap", "Identity"); |
1142 } else { | 1142 } else { |
1143 SkASSERT(false); | 1143 SkASSERT(false); |
1144 } | 1144 } |
1145 | 1145 |
1146 SkAutoTUnref<SkPDFDict> sysInfo(new SkPDFDict); | 1146 sk_sp<SkPDFDict> sysInfo(new SkPDFDict); |
1147 sysInfo->insertString("Registry", "Adobe"); | 1147 sysInfo->insertString("Registry", "Adobe"); |
1148 sysInfo->insertString("Ordering", "Identity"); | 1148 sysInfo->insertString("Ordering", "Identity"); |
1149 sysInfo->insertInt("Supplement", 0); | 1149 sysInfo->insertInt("Supplement", 0); |
1150 this->insertObject("CIDSystemInfo", sysInfo.release()); | 1150 this->insertObject("CIDSystemInfo", sysInfo.release()); |
1151 | 1151 |
1152 if (fontInfo()->fGlyphWidths.get()) { | 1152 if (fontInfo()->fGlyphWidths.get()) { |
1153 int16_t defaultWidth = 0; | 1153 int16_t defaultWidth = 0; |
1154 SkAutoTUnref<SkPDFArray> widths( | 1154 sk_sp<SkPDFArray> widths( |
1155 composeAdvanceData(fontInfo()->fGlyphWidths.get(), | 1155 composeAdvanceData(fontInfo()->fGlyphWidths.get(), |
1156 fontInfo()->fEmSize, &appendWidth, | 1156 fontInfo()->fEmSize, &appendWidth, |
1157 &defaultWidth)); | 1157 &defaultWidth)); |
1158 if (widths->size()) | 1158 if (widths->size()) |
1159 this->insertObject("W", widths.release()); | 1159 this->insertObject("W", widths.release()); |
1160 if (defaultWidth != 0) { | 1160 if (defaultWidth != 0) { |
1161 this->insertScalar( | 1161 this->insertScalar( |
1162 "DW", | 1162 "DW", |
1163 scaleFromFontUnits(defaultWidth, fontInfo()->fEmSize)); | 1163 scaleFromFontUnits(defaultWidth, fontInfo()->fEmSize)); |
1164 } | 1164 } |
1165 } | 1165 } |
1166 if (fontInfo()->fVerticalMetrics.get()) { | 1166 if (fontInfo()->fVerticalMetrics.get()) { |
1167 struct SkAdvancedTypefaceMetrics::VerticalMetric defaultAdvance; | 1167 struct SkAdvancedTypefaceMetrics::VerticalMetric defaultAdvance; |
1168 defaultAdvance.fVerticalAdvance = 0; | 1168 defaultAdvance.fVerticalAdvance = 0; |
1169 defaultAdvance.fOriginXDisp = 0; | 1169 defaultAdvance.fOriginXDisp = 0; |
1170 defaultAdvance.fOriginYDisp = 0; | 1170 defaultAdvance.fOriginYDisp = 0; |
1171 SkAutoTUnref<SkPDFArray> advances( | 1171 sk_sp<SkPDFArray> advances( |
1172 composeAdvanceData(fontInfo()->fVerticalMetrics.get(), | 1172 composeAdvanceData(fontInfo()->fVerticalMetrics.get(), |
1173 fontInfo()->fEmSize, &appendVerticalAdvance, | 1173 fontInfo()->fEmSize, &appendVerticalAdvance, |
1174 &defaultAdvance)); | 1174 &defaultAdvance)); |
1175 if (advances->size()) | 1175 if (advances->size()) |
1176 this->insertObject("W2", advances.release()); | 1176 this->insertObject("W2", advances.release()); |
1177 if (defaultAdvance.fVerticalAdvance || | 1177 if (defaultAdvance.fVerticalAdvance || |
1178 defaultAdvance.fOriginXDisp || | 1178 defaultAdvance.fOriginXDisp || |
1179 defaultAdvance.fOriginYDisp) { | 1179 defaultAdvance.fOriginYDisp) { |
1180 this->insertObject("DW2", | 1180 this->insertObject("DW2", |
1181 appendVerticalAdvance(defaultAdvance, | 1181 appendVerticalAdvance(defaultAdvance, |
(...skipping 18 matching lines...) Expand all Loading... |
1200 } | 1200 } |
1201 | 1201 |
1202 SkPDFType1Font::~SkPDFType1Font() {} | 1202 SkPDFType1Font::~SkPDFType1Font() {} |
1203 | 1203 |
1204 bool SkPDFType1Font::addFontDescriptor(int16_t defaultWidth) { | 1204 bool SkPDFType1Font::addFontDescriptor(int16_t defaultWidth) { |
1205 if (SkPDFDict* descriptor = getFontDescriptor()) { | 1205 if (SkPDFDict* descriptor = getFontDescriptor()) { |
1206 this->insertObjRef("FontDescriptor", SkRef(descriptor)); | 1206 this->insertObjRef("FontDescriptor", SkRef(descriptor)); |
1207 return true; | 1207 return true; |
1208 } | 1208 } |
1209 | 1209 |
1210 SkAutoTUnref<SkPDFDict> descriptor(new SkPDFDict("FontDescriptor")); | 1210 sk_sp<SkPDFDict> descriptor(new SkPDFDict("FontDescriptor")); |
1211 setFontDescriptor(descriptor.get()); | 1211 setFontDescriptor(descriptor.get()); |
1212 | 1212 |
1213 int ttcIndex; | 1213 int ttcIndex; |
1214 size_t header SK_INIT_TO_AVOID_WARNING; | 1214 size_t header SK_INIT_TO_AVOID_WARNING; |
1215 size_t data SK_INIT_TO_AVOID_WARNING; | 1215 size_t data SK_INIT_TO_AVOID_WARNING; |
1216 size_t trailer SK_INIT_TO_AVOID_WARNING; | 1216 size_t trailer SK_INIT_TO_AVOID_WARNING; |
1217 SkAutoTDelete<SkStream> rawFontData(typeface()->openStream(&ttcIndex)); | 1217 SkAutoTDelete<SkStream> rawFontData(typeface()->openStream(&ttcIndex)); |
1218 SkAutoTUnref<SkData> fontData(handle_type1_stream(rawFontData.get(), &header
, | 1218 sk_sp<SkData> fontData(handle_type1_stream(rawFontData.get(), &header, |
1219 &data, &trailer)); | 1219 &data, &trailer)); |
1220 if (fontData.get() == nullptr) { | 1220 if (fontData.get() == nullptr) { |
1221 return false; | 1221 return false; |
1222 } | 1222 } |
1223 SkASSERT(this->canEmbed()); | 1223 SkASSERT(this->canEmbed()); |
1224 SkAutoTUnref<SkPDFStream> fontStream(new SkPDFStream(fontData.get())); | 1224 sk_sp<SkPDFStream> fontStream(new SkPDFStream(fontData.get())); |
1225 fontStream->insertInt("Length1", header); | 1225 fontStream->insertInt("Length1", header); |
1226 fontStream->insertInt("Length2", data); | 1226 fontStream->insertInt("Length2", data); |
1227 fontStream->insertInt("Length3", trailer); | 1227 fontStream->insertInt("Length3", trailer); |
1228 descriptor->insertObjRef("FontFile", fontStream.release()); | 1228 descriptor->insertObjRef("FontFile", fontStream.release()); |
1229 | 1229 |
1230 this->insertObjRef("FontDescriptor", descriptor.release()); | 1230 this->insertObjRef("FontDescriptor", descriptor.release()); |
1231 | 1231 |
1232 return addCommonFontDescriptorEntries(defaultWidth); | 1232 return addCommonFontDescriptorEntries(defaultWidth); |
1233 } | 1233 } |
1234 | 1234 |
(...skipping 26 matching lines...) Expand all Loading... |
1261 if (!addFontDescriptor(defaultWidth)) { | 1261 if (!addFontDescriptor(defaultWidth)) { |
1262 return false; | 1262 return false; |
1263 } | 1263 } |
1264 | 1264 |
1265 insertName("Subtype", "Type1"); | 1265 insertName("Subtype", "Type1"); |
1266 insertName("BaseFont", fontInfo()->fFontName); | 1266 insertName("BaseFont", fontInfo()->fFontName); |
1267 | 1267 |
1268 addWidthInfoFromRange(defaultWidth, widthRangeEntry); | 1268 addWidthInfoFromRange(defaultWidth, widthRangeEntry); |
1269 | 1269 |
1270 | 1270 |
1271 SkAutoTUnref<SkPDFArray> encDiffs(new SkPDFArray); | 1271 sk_sp<SkPDFArray> encDiffs(new SkPDFArray); |
1272 encDiffs->reserve(lastGlyphID() - firstGlyphID() + 2); | 1272 encDiffs->reserve(lastGlyphID() - firstGlyphID() + 2); |
1273 encDiffs->appendInt(1); | 1273 encDiffs->appendInt(1); |
1274 for (int gID = firstGlyphID(); gID <= lastGlyphID(); gID++) { | 1274 for (int gID = firstGlyphID(); gID <= lastGlyphID(); gID++) { |
1275 encDiffs->appendName(fontInfo()->fGlyphNames->get()[gID].c_str()); | 1275 encDiffs->appendName(fontInfo()->fGlyphNames->get()[gID].c_str()); |
1276 } | 1276 } |
1277 | 1277 |
1278 SkAutoTUnref<SkPDFDict> encoding(new SkPDFDict("Encoding")); | 1278 sk_sp<SkPDFDict> encoding(new SkPDFDict("Encoding")); |
1279 encoding->insertObject("Differences", encDiffs.release()); | 1279 encoding->insertObject("Differences", encDiffs.release()); |
1280 this->insertObject("Encoding", encoding.release()); | 1280 this->insertObject("Encoding", encoding.release()); |
1281 return true; | 1281 return true; |
1282 } | 1282 } |
1283 | 1283 |
1284 void SkPDFType1Font::addWidthInfoFromRange( | 1284 void SkPDFType1Font::addWidthInfoFromRange( |
1285 int16_t defaultWidth, | 1285 int16_t defaultWidth, |
1286 const SkAdvancedTypefaceMetrics::WidthRange* widthRangeEntry) { | 1286 const SkAdvancedTypefaceMetrics::WidthRange* widthRangeEntry) { |
1287 SkAutoTUnref<SkPDFArray> widthArray(new SkPDFArray()); | 1287 sk_sp<SkPDFArray> widthArray(new SkPDFArray()); |
1288 int firstChar = 0; | 1288 int firstChar = 0; |
1289 if (widthRangeEntry) { | 1289 if (widthRangeEntry) { |
1290 const uint16_t emSize = fontInfo()->fEmSize; | 1290 const uint16_t emSize = fontInfo()->fEmSize; |
1291 int startIndex = firstGlyphID() - widthRangeEntry->fStartId; | 1291 int startIndex = firstGlyphID() - widthRangeEntry->fStartId; |
1292 int endIndex = startIndex + lastGlyphID() - firstGlyphID() + 1; | 1292 int endIndex = startIndex + lastGlyphID() - firstGlyphID() + 1; |
1293 if (startIndex < 0) | 1293 if (startIndex < 0) |
1294 startIndex = 0; | 1294 startIndex = 0; |
1295 if (endIndex > widthRangeEntry->fAdvance.count()) | 1295 if (endIndex > widthRangeEntry->fAdvance.count()) |
1296 endIndex = widthRangeEntry->fAdvance.count(); | 1296 endIndex = widthRangeEntry->fAdvance.count(); |
1297 if (widthRangeEntry->fStartId == 0) { | 1297 if (widthRangeEntry->fStartId == 0) { |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1336 } | 1336 } |
1337 | 1337 |
1338 adjustGlyphRangeForSingleByteEncoding(glyphID); | 1338 adjustGlyphRangeForSingleByteEncoding(glyphID); |
1339 | 1339 |
1340 insertName("Subtype", "Type3"); | 1340 insertName("Subtype", "Type3"); |
1341 // Flip about the x-axis and scale by 1/1000. | 1341 // Flip about the x-axis and scale by 1/1000. |
1342 SkMatrix fontMatrix; | 1342 SkMatrix fontMatrix; |
1343 fontMatrix.setScale(SkScalarInvert(1000), -SkScalarInvert(1000)); | 1343 fontMatrix.setScale(SkScalarInvert(1000), -SkScalarInvert(1000)); |
1344 this->insertObject("FontMatrix", SkPDFUtils::MatrixToArray(fontMatrix)); | 1344 this->insertObject("FontMatrix", SkPDFUtils::MatrixToArray(fontMatrix)); |
1345 | 1345 |
1346 SkAutoTUnref<SkPDFDict> charProcs(new SkPDFDict); | 1346 sk_sp<SkPDFDict> charProcs(new SkPDFDict); |
1347 SkAutoTUnref<SkPDFDict> encoding(new SkPDFDict("Encoding")); | 1347 sk_sp<SkPDFDict> encoding(new SkPDFDict("Encoding")); |
1348 | 1348 |
1349 SkAutoTUnref<SkPDFArray> encDiffs(new SkPDFArray); | 1349 sk_sp<SkPDFArray> encDiffs(new SkPDFArray); |
1350 encDiffs->reserve(lastGlyphID() - firstGlyphID() + 2); | 1350 encDiffs->reserve(lastGlyphID() - firstGlyphID() + 2); |
1351 encDiffs->appendInt(1); | 1351 encDiffs->appendInt(1); |
1352 | 1352 |
1353 SkAutoTUnref<SkPDFArray> widthArray(new SkPDFArray()); | 1353 sk_sp<SkPDFArray> widthArray(new SkPDFArray()); |
1354 | 1354 |
1355 SkIRect bbox = SkIRect::MakeEmpty(); | 1355 SkIRect bbox = SkIRect::MakeEmpty(); |
1356 for (int gID = firstGlyphID(); gID <= lastGlyphID(); gID++) { | 1356 for (int gID = firstGlyphID(); gID <= lastGlyphID(); gID++) { |
1357 SkString characterName; | 1357 SkString characterName; |
1358 characterName.printf("gid%d", gID); | 1358 characterName.printf("gid%d", gID); |
1359 encDiffs->appendName(characterName.c_str()); | 1359 encDiffs->appendName(characterName.c_str()); |
1360 | 1360 |
1361 const SkGlyph& glyph = cache->getGlyphIDMetrics(gID); | 1361 const SkGlyph& glyph = cache->getGlyphIDMetrics(gID); |
1362 widthArray->appendScalar(SkFixedToScalar(glyph.fAdvanceX)); | 1362 widthArray->appendScalar(SkFixedToScalar(glyph.fAdvanceX)); |
1363 SkIRect glyphBBox = SkIRect::MakeXYWH(glyph.fLeft, glyph.fTop, | 1363 SkIRect glyphBBox = SkIRect::MakeXYWH(glyph.fLeft, glyph.fTop, |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1417 } | 1417 } |
1418 | 1418 |
1419 // Since getAdvancedTypefaceMetrics is expensive, cache the result. | 1419 // Since getAdvancedTypefaceMetrics is expensive, cache the result. |
1420 bool SkPDFFont::CanEmbedTypeface(SkTypeface* typeface, SkPDFCanon* canon) { | 1420 bool SkPDFFont::CanEmbedTypeface(SkTypeface* typeface, SkPDFCanon* canon) { |
1421 SkAutoResolveDefaultTypeface face(typeface); | 1421 SkAutoResolveDefaultTypeface face(typeface); |
1422 uint32_t id = face->uniqueID(); | 1422 uint32_t id = face->uniqueID(); |
1423 if (bool* value = canon->fCanEmbedTypeface.find(id)) { | 1423 if (bool* value = canon->fCanEmbedTypeface.find(id)) { |
1424 return *value; | 1424 return *value; |
1425 } | 1425 } |
1426 bool canEmbed = true; | 1426 bool canEmbed = true; |
1427 SkAutoTUnref<const SkAdvancedTypefaceMetrics> fontMetrics( | 1427 sk_sp<const SkAdvancedTypefaceMetrics> fontMetrics( |
1428 face->getAdvancedTypefaceMetrics( | 1428 face->getAdvancedTypefaceMetrics( |
1429 SkTypeface::kNo_PerGlyphInfo, nullptr, 0)); | 1429 SkTypeface::kNo_PerGlyphInfo, nullptr, 0)); |
1430 if (fontMetrics) { | 1430 if (fontMetrics) { |
1431 canEmbed = !SkToBool( | 1431 canEmbed = !SkToBool( |
1432 fontMetrics->fFlags & | 1432 fontMetrics->fFlags & |
1433 SkAdvancedTypefaceMetrics::kNotEmbeddable_FontFlag); | 1433 SkAdvancedTypefaceMetrics::kNotEmbeddable_FontFlag); |
1434 } | 1434 } |
1435 return *canon->fCanEmbedTypeface.set(id, canEmbed); | 1435 return *canon->fCanEmbedTypeface.set(id, canEmbed); |
1436 } | 1436 } |
OLD | NEW |