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 279 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
290 content->writeDecAsText(box.fLeft); | 290 content->writeDecAsText(box.fLeft); |
291 content->writeText(" "); | 291 content->writeText(" "); |
292 content->writeDecAsText(box.fTop); | 292 content->writeDecAsText(box.fTop); |
293 content->writeText(" "); | 293 content->writeText(" "); |
294 content->writeDecAsText(box.fRight); | 294 content->writeDecAsText(box.fRight); |
295 content->writeText(" "); | 295 content->writeText(" "); |
296 content->writeDecAsText(box.fBottom); | 296 content->writeDecAsText(box.fBottom); |
297 content->writeText(" d1\n"); | 297 content->writeText(" d1\n"); |
298 } | 298 } |
299 | 299 |
300 SkPDFArray* makeFontBBox(SkIRect glyphBBox, uint16_t emSize) { | 300 static sk_sp<SkPDFArray> makeFontBBox(SkIRect glyphBBox, uint16_t emSize) { |
301 SkPDFArray* bbox = new SkPDFArray; | 301 auto bbox = sk_make_sp<SkPDFArray>(); |
302 bbox->reserve(4); | 302 bbox->reserve(4); |
303 bbox->appendScalar(scaleFromFontUnits(glyphBBox.fLeft, emSize)); | 303 bbox->appendScalar(scaleFromFontUnits(glyphBBox.fLeft, emSize)); |
304 bbox->appendScalar(scaleFromFontUnits(glyphBBox.fBottom, emSize)); | 304 bbox->appendScalar(scaleFromFontUnits(glyphBBox.fBottom, emSize)); |
305 bbox->appendScalar(scaleFromFontUnits(glyphBBox.fRight, emSize)); | 305 bbox->appendScalar(scaleFromFontUnits(glyphBBox.fRight, emSize)); |
306 bbox->appendScalar(scaleFromFontUnits(glyphBBox.fTop, emSize)); | 306 bbox->appendScalar(scaleFromFontUnits(glyphBBox.fTop, emSize)); |
307 return bbox; | 307 return bbox; |
308 } | 308 } |
309 | 309 |
310 SkPDFArray* appendWidth(const int16_t& width, uint16_t emSize, | 310 static void appendWidth(const int16_t& width, uint16_t emSize, |
311 SkPDFArray* array) { | 311 SkPDFArray* array) { |
312 array->appendScalar(scaleFromFontUnits(width, emSize)); | 312 array->appendScalar(scaleFromFontUnits(width, emSize)); |
313 return array; | |
314 } | 313 } |
315 | 314 |
316 SkPDFArray* appendVerticalAdvance( | 315 static void appendVerticalAdvance( |
317 const SkAdvancedTypefaceMetrics::VerticalMetric& advance, | 316 const SkAdvancedTypefaceMetrics::VerticalMetric& advance, |
318 uint16_t emSize, SkPDFArray* array) { | 317 uint16_t emSize, SkPDFArray* array) { |
319 appendWidth(advance.fVerticalAdvance, emSize, array); | 318 appendWidth(advance.fVerticalAdvance, emSize, array); |
320 appendWidth(advance.fOriginXDisp, emSize, array); | 319 appendWidth(advance.fOriginXDisp, emSize, array); |
321 appendWidth(advance.fOriginYDisp, emSize, array); | 320 appendWidth(advance.fOriginYDisp, emSize, array); |
322 return array; | |
323 } | 321 } |
324 | 322 |
325 template <typename Data> | 323 template <typename Data> |
326 SkPDFArray* composeAdvanceData( | 324 SkPDFArray* composeAdvanceData( |
327 SkAdvancedTypefaceMetrics::AdvanceMetric<Data>* advanceInfo, | 325 SkAdvancedTypefaceMetrics::AdvanceMetric<Data>* advanceInfo, |
328 uint16_t emSize, | 326 uint16_t emSize, |
329 SkPDFArray* (*appendAdvance)(const Data& advance, uint16_t emSize, | 327 void (*appendAdvance)(const Data& advance, uint16_t emSize, |
330 SkPDFArray* array), | 328 SkPDFArray* array), |
331 Data* defaultAdvance) { | 329 Data* defaultAdvance) { |
332 SkPDFArray* result = new SkPDFArray(); | 330 SkPDFArray* result = new SkPDFArray(); |
333 for (; advanceInfo != nullptr; advanceInfo = advanceInfo->fNext.get()) { | 331 for (; advanceInfo != nullptr; advanceInfo = advanceInfo->fNext.get()) { |
334 switch (advanceInfo->fType) { | 332 switch (advanceInfo->fType) { |
335 case SkAdvancedTypefaceMetrics::WidthRange::kDefault: { | 333 case SkAdvancedTypefaceMetrics::WidthRange::kDefault: { |
336 SkASSERT(advanceInfo->fAdvance.count() == 1); | 334 SkASSERT(advanceInfo->fAdvance.count() == 1); |
337 *defaultAdvance = advanceInfo->fAdvance[0]; | 335 *defaultAdvance = advanceInfo->fAdvance[0]; |
338 break; | 336 break; |
339 } | 337 } |
340 case SkAdvancedTypefaceMetrics::WidthRange::kRange: { | 338 case SkAdvancedTypefaceMetrics::WidthRange::kRange: { |
341 auto advanceArray = sk_make_sp<SkPDFArray>(); | 339 auto advanceArray = sk_make_sp<SkPDFArray>(); |
342 for (int j = 0; j < advanceInfo->fAdvance.count(); j++) | 340 for (int j = 0; j < advanceInfo->fAdvance.count(); j++) |
343 appendAdvance(advanceInfo->fAdvance[j], emSize, | 341 appendAdvance(advanceInfo->fAdvance[j], emSize, |
344 advanceArray.get()); | 342 advanceArray.get()); |
345 result->appendInt(advanceInfo->fStartId); | 343 result->appendInt(advanceInfo->fStartId); |
346 result->appendObject(advanceArray.release()); | 344 result->appendObject(std::move(advanceArray)); |
347 break; | 345 break; |
348 } | 346 } |
349 case SkAdvancedTypefaceMetrics::WidthRange::kRun: { | 347 case SkAdvancedTypefaceMetrics::WidthRange::kRun: { |
350 SkASSERT(advanceInfo->fAdvance.count() == 1); | 348 SkASSERT(advanceInfo->fAdvance.count() == 1); |
351 result->appendInt(advanceInfo->fStartId); | 349 result->appendInt(advanceInfo->fStartId); |
352 result->appendInt(advanceInfo->fEndId); | 350 result->appendInt(advanceInfo->fEndId); |
353 appendAdvance(advanceInfo->fAdvance[0], emSize, result); | 351 appendAdvance(advanceInfo->fAdvance[0], emSize, result); |
354 break; | 352 break; |
355 } | 353 } |
356 } | 354 } |
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
552 } | 550 } |
553 } | 551 } |
554 } | 552 } |
555 | 553 |
556 // The spec requires all bfchar entries for a font must come before bfrange | 554 // The spec requires all bfchar entries for a font must come before bfrange |
557 // entries. | 555 // entries. |
558 append_bfchar_section(bfcharEntries, cmap); | 556 append_bfchar_section(bfcharEntries, cmap); |
559 append_bfrange_section(bfrangeEntries, cmap); | 557 append_bfrange_section(bfrangeEntries, cmap); |
560 } | 558 } |
561 | 559 |
562 static SkPDFStream* generate_tounicode_cmap( | 560 static sk_sp<SkPDFStream> generate_tounicode_cmap( |
563 const SkTDArray<SkUnichar>& glyphToUnicode, | 561 const SkTDArray<SkUnichar>& glyphToUnicode, |
564 const SkPDFGlyphSet* subset, | 562 const SkPDFGlyphSet* subset, |
565 bool multiByteGlyphs, | 563 bool multiByteGlyphs, |
566 uint16_t firstGlyphID, | 564 uint16_t firstGlyphID, |
567 uint16_t lastGlyphID) { | 565 uint16_t lastGlyphID) { |
568 SkDynamicMemoryWStream cmap; | 566 SkDynamicMemoryWStream cmap; |
569 if (multiByteGlyphs) { | 567 if (multiByteGlyphs) { |
570 append_tounicode_header(&cmap, firstGlyphID, lastGlyphID); | 568 append_tounicode_header(&cmap, firstGlyphID, lastGlyphID); |
571 } else { | 569 } else { |
572 append_tounicode_header(&cmap, 1, lastGlyphID - firstGlyphID + 1); | 570 append_tounicode_header(&cmap, 1, lastGlyphID - firstGlyphID + 1); |
573 } | 571 } |
574 append_cmap_sections(glyphToUnicode, subset, &cmap, multiByteGlyphs, | 572 append_cmap_sections(glyphToUnicode, subset, &cmap, multiByteGlyphs, |
575 firstGlyphID, lastGlyphID); | 573 firstGlyphID, lastGlyphID); |
576 append_cmap_footer(&cmap); | 574 append_cmap_footer(&cmap); |
577 sk_sp<SkData> cmapData(cmap.copyToData()); | 575 sk_sp<SkData> cmapData(cmap.copyToData()); |
578 return new SkPDFStream(cmapData.get()); | 576 return sk_make_sp<SkPDFStream>(cmapData.get()); |
579 } | 577 } |
580 | 578 |
581 #if defined (SK_SFNTLY_SUBSETTER) | 579 #if defined (SK_SFNTLY_SUBSETTER) |
582 static void sk_delete_array(const void* ptr, void*) { | 580 static void sk_delete_array(const void* ptr, void*) { |
583 // Use C-style cast to cast away const and cast type simultaneously. | 581 // Use C-style cast to cast away const and cast type simultaneously. |
584 delete[] (unsigned char*)ptr; | 582 delete[] (unsigned char*)ptr; |
585 } | 583 } |
586 #endif | 584 #endif |
587 | 585 |
588 #if defined(SK_SFNTLY_SUBSETTER) | 586 #if defined(SK_SFNTLY_SUBSETTER) |
(...skipping 426 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1015 #endif | 1013 #endif |
1016 | 1014 |
1017 bool SkPDFType0Font::populate(const SkPDFGlyphSet* subset) { | 1015 bool SkPDFType0Font::populate(const SkPDFGlyphSet* subset) { |
1018 insertName("Subtype", "Type0"); | 1016 insertName("Subtype", "Type0"); |
1019 insertName("BaseFont", fontInfo()->fFontName); | 1017 insertName("BaseFont", fontInfo()->fFontName); |
1020 insertName("Encoding", "Identity-H"); | 1018 insertName("Encoding", "Identity-H"); |
1021 | 1019 |
1022 sk_sp<SkPDFCIDFont> newCIDFont( | 1020 sk_sp<SkPDFCIDFont> newCIDFont( |
1023 new SkPDFCIDFont(fontInfo(), typeface(), subset)); | 1021 new SkPDFCIDFont(fontInfo(), typeface(), subset)); |
1024 auto descendantFonts = sk_make_sp<SkPDFArray>(); | 1022 auto descendantFonts = sk_make_sp<SkPDFArray>(); |
1025 descendantFonts->appendObjRef(newCIDFont.release()); | 1023 descendantFonts->appendObjRef(std::move(newCIDFont)); |
1026 this->insertObject("DescendantFonts", descendantFonts.release()); | 1024 this->insertObject("DescendantFonts", std::move(descendantFonts)); |
1027 | 1025 |
1028 this->populateToUnicodeTable(subset); | 1026 this->populateToUnicodeTable(subset); |
1029 | 1027 |
1030 SkDEBUGCODE(fPopulated = true); | 1028 SkDEBUGCODE(fPopulated = true); |
1031 return true; | 1029 return true; |
1032 } | 1030 } |
1033 | 1031 |
1034 /////////////////////////////////////////////////////////////////////////////// | 1032 /////////////////////////////////////////////////////////////////////////////// |
1035 // class SkPDFCIDFont | 1033 // class SkPDFCIDFont |
1036 /////////////////////////////////////////////////////////////////////////////// | 1034 /////////////////////////////////////////////////////////////////////////////// |
1037 | 1035 |
1038 SkPDFCIDFont::SkPDFCIDFont(const SkAdvancedTypefaceMetrics* info, | 1036 SkPDFCIDFont::SkPDFCIDFont(const SkAdvancedTypefaceMetrics* info, |
1039 SkTypeface* typeface, | 1037 SkTypeface* typeface, |
1040 const SkPDFGlyphSet* subset) | 1038 const SkPDFGlyphSet* subset) |
1041 : SkPDFFont(info, typeface, nullptr) { | 1039 : SkPDFFont(info, typeface, nullptr) { |
1042 this->populate(subset); | 1040 this->populate(subset); |
1043 } | 1041 } |
1044 | 1042 |
1045 SkPDFCIDFont::~SkPDFCIDFont() {} | 1043 SkPDFCIDFont::~SkPDFCIDFont() {} |
1046 | 1044 |
1047 bool SkPDFCIDFont::addFontDescriptor(int16_t defaultWidth, | 1045 bool SkPDFCIDFont::addFontDescriptor(int16_t defaultWidth, |
1048 const SkTDArray<uint32_t>* subset) { | 1046 const SkTDArray<uint32_t>* subset) { |
1049 auto descriptor = sk_make_sp<SkPDFDict>("FontDescriptor"); | 1047 auto descriptor = sk_make_sp<SkPDFDict>("FontDescriptor"); |
1050 setFontDescriptor(descriptor.get()); | 1048 setFontDescriptor(descriptor.get()); |
1051 if (!addCommonFontDescriptorEntries(defaultWidth)) { | 1049 if (!addCommonFontDescriptorEntries(defaultWidth)) { |
1052 this->insertObjRef("FontDescriptor", descriptor.release()); | 1050 this->insertObjRef("FontDescriptor", std::move(descriptor)); |
1053 return false; | 1051 return false; |
1054 } | 1052 } |
1055 SkASSERT(this->canEmbed()); | 1053 SkASSERT(this->canEmbed()); |
1056 | 1054 |
1057 switch (getType()) { | 1055 switch (getType()) { |
1058 case SkAdvancedTypefaceMetrics::kTrueType_Font: { | 1056 case SkAdvancedTypefaceMetrics::kTrueType_Font: { |
1059 size_t fontSize = 0; | 1057 size_t fontSize = 0; |
1060 #if defined(SK_SFNTLY_SUBSETTER) | 1058 #if defined(SK_SFNTLY_SUBSETTER) |
1061 if (this->canSubset()) { | 1059 if (this->canSubset()) { |
1062 sk_sp<SkPDFStream> fontStream; | 1060 sk_sp<SkPDFStream> fontStream; |
1063 SkPDFStream* rawStream = nullptr; | 1061 SkPDFStream* rawStream = nullptr; |
1064 fontSize = get_subset_font_stream(fontInfo()->fFontName.c_str(), | 1062 fontSize = get_subset_font_stream(fontInfo()->fFontName.c_str(), |
1065 typeface(), | 1063 typeface(), |
1066 *subset, | 1064 *subset, |
1067 &rawStream); | 1065 &rawStream); |
1068 if (rawStream) { | 1066 if (rawStream) { |
1069 fontStream.reset(rawStream); | 1067 fontStream.reset(rawStream); |
1070 fontStream->insertInt("Length1", fontSize); | 1068 fontStream->insertInt("Length1", fontSize); |
1071 descriptor->insertObjRef("FontFile2", fontStream.release()); | 1069 descriptor->insertObjRef("FontFile2", std::move(fontStream))
; |
1072 break; | 1070 break; |
1073 } | 1071 } |
1074 } | 1072 } |
1075 #endif | 1073 #endif |
1076 sk_sp<SkPDFSharedStream> fontStream; | 1074 sk_sp<SkPDFSharedStream> fontStream; |
1077 SkAutoTDelete<SkStreamAsset> fontData( | 1075 SkAutoTDelete<SkStreamAsset> fontData( |
1078 this->typeface()->openStream(nullptr)); | 1076 this->typeface()->openStream(nullptr)); |
1079 SkASSERT(fontData); | 1077 SkASSERT(fontData); |
1080 fontSize = fontData->getLength(); | 1078 fontSize = fontData->getLength(); |
1081 SkASSERT(fontSize > 0); | 1079 SkASSERT(fontSize > 0); |
1082 fontStream.reset(new SkPDFSharedStream(fontData.detach())); | 1080 fontStream.reset(new SkPDFSharedStream(fontData.detach())); |
1083 fontStream->dict()->insertInt("Length1", fontSize); | 1081 fontStream->dict()->insertInt("Length1", fontSize); |
1084 descriptor->insertObjRef("FontFile2", fontStream.release()); | 1082 descriptor->insertObjRef("FontFile2", std::move(fontStream)); |
1085 break; | 1083 break; |
1086 } | 1084 } |
1087 case SkAdvancedTypefaceMetrics::kCFF_Font: | 1085 case SkAdvancedTypefaceMetrics::kCFF_Font: |
1088 case SkAdvancedTypefaceMetrics::kType1CID_Font: { | 1086 case SkAdvancedTypefaceMetrics::kType1CID_Font: { |
1089 sk_sp<SkPDFSharedStream> fontStream( | 1087 sk_sp<SkPDFSharedStream> fontStream( |
1090 new SkPDFSharedStream(this->typeface()->openStream(nullptr))
); | 1088 new SkPDFSharedStream(this->typeface()->openStream(nullptr))
); |
1091 | 1089 |
1092 if (getType() == SkAdvancedTypefaceMetrics::kCFF_Font) { | 1090 if (getType() == SkAdvancedTypefaceMetrics::kCFF_Font) { |
1093 fontStream->dict()->insertName("Subtype", "Type1C"); | 1091 fontStream->dict()->insertName("Subtype", "Type1C"); |
1094 } else { | 1092 } else { |
1095 fontStream->dict()->insertName("Subtype", "CIDFontType0c"); | 1093 fontStream->dict()->insertName("Subtype", "CIDFontType0c"); |
1096 } | 1094 } |
1097 descriptor->insertObjRef("FontFile3", fontStream.release()); | 1095 descriptor->insertObjRef("FontFile3", std::move(fontStream)); |
1098 break; | 1096 break; |
1099 } | 1097 } |
1100 default: | 1098 default: |
1101 SkASSERT(false); | 1099 SkASSERT(false); |
1102 } | 1100 } |
1103 this->insertObjRef("FontDescriptor", descriptor.release()); | 1101 this->insertObjRef("FontDescriptor", std::move(descriptor)); |
1104 return true; | 1102 return true; |
1105 } | 1103 } |
1106 | 1104 |
1107 bool SkPDFCIDFont::populate(const SkPDFGlyphSet* subset) { | 1105 bool SkPDFCIDFont::populate(const SkPDFGlyphSet* subset) { |
1108 // Generate new font metrics with advance info for true type fonts. | 1106 // Generate new font metrics with advance info for true type fonts. |
1109 if (fontInfo()->fType == SkAdvancedTypefaceMetrics::kTrueType_Font) { | 1107 if (fontInfo()->fType == SkAdvancedTypefaceMetrics::kTrueType_Font) { |
1110 // Generate glyph id array. | 1108 // Generate glyph id array. |
1111 SkTDArray<uint32_t> glyphIDs; | 1109 SkTDArray<uint32_t> glyphIDs; |
1112 if (subset) { | 1110 if (subset) { |
1113 // Always include glyph 0. | 1111 // Always include glyph 0. |
(...skipping 26 matching lines...) Expand all Loading... |
1140 insertName("Subtype", "CIDFontType2"); | 1138 insertName("Subtype", "CIDFontType2"); |
1141 insertName("CIDToGIDMap", "Identity"); | 1139 insertName("CIDToGIDMap", "Identity"); |
1142 } else { | 1140 } else { |
1143 SkASSERT(false); | 1141 SkASSERT(false); |
1144 } | 1142 } |
1145 | 1143 |
1146 auto sysInfo = sk_make_sp<SkPDFDict>(); | 1144 auto sysInfo = sk_make_sp<SkPDFDict>(); |
1147 sysInfo->insertString("Registry", "Adobe"); | 1145 sysInfo->insertString("Registry", "Adobe"); |
1148 sysInfo->insertString("Ordering", "Identity"); | 1146 sysInfo->insertString("Ordering", "Identity"); |
1149 sysInfo->insertInt("Supplement", 0); | 1147 sysInfo->insertInt("Supplement", 0); |
1150 this->insertObject("CIDSystemInfo", sysInfo.release()); | 1148 this->insertObject("CIDSystemInfo", std::move(sysInfo)); |
1151 | 1149 |
1152 if (fontInfo()->fGlyphWidths.get()) { | 1150 if (fontInfo()->fGlyphWidths.get()) { |
1153 int16_t defaultWidth = 0; | 1151 int16_t defaultWidth = 0; |
1154 sk_sp<SkPDFArray> widths( | 1152 sk_sp<SkPDFArray> widths( |
1155 composeAdvanceData(fontInfo()->fGlyphWidths.get(), | 1153 composeAdvanceData(fontInfo()->fGlyphWidths.get(), |
1156 fontInfo()->fEmSize, &appendWidth, | 1154 fontInfo()->fEmSize, &appendWidth, |
1157 &defaultWidth)); | 1155 &defaultWidth)); |
1158 if (widths->size()) | 1156 if (widths->size()) |
1159 this->insertObject("W", widths.release()); | 1157 this->insertObject("W", std::move(widths)); |
1160 if (defaultWidth != 0) { | 1158 if (defaultWidth != 0) { |
1161 this->insertScalar( | 1159 this->insertScalar( |
1162 "DW", | 1160 "DW", |
1163 scaleFromFontUnits(defaultWidth, fontInfo()->fEmSize)); | 1161 scaleFromFontUnits(defaultWidth, fontInfo()->fEmSize)); |
1164 } | 1162 } |
1165 } | 1163 } |
1166 if (fontInfo()->fVerticalMetrics.get()) { | 1164 if (fontInfo()->fVerticalMetrics.get()) { |
1167 struct SkAdvancedTypefaceMetrics::VerticalMetric defaultAdvance; | 1165 struct SkAdvancedTypefaceMetrics::VerticalMetric defaultAdvance; |
1168 defaultAdvance.fVerticalAdvance = 0; | 1166 defaultAdvance.fVerticalAdvance = 0; |
1169 defaultAdvance.fOriginXDisp = 0; | 1167 defaultAdvance.fOriginXDisp = 0; |
1170 defaultAdvance.fOriginYDisp = 0; | 1168 defaultAdvance.fOriginYDisp = 0; |
1171 sk_sp<SkPDFArray> advances( | 1169 sk_sp<SkPDFArray> advances( |
1172 composeAdvanceData(fontInfo()->fVerticalMetrics.get(), | 1170 composeAdvanceData(fontInfo()->fVerticalMetrics.get(), |
1173 fontInfo()->fEmSize, &appendVerticalAdvance, | 1171 fontInfo()->fEmSize, &appendVerticalAdvance, |
1174 &defaultAdvance)); | 1172 &defaultAdvance)); |
1175 if (advances->size()) | 1173 if (advances->size()) |
1176 this->insertObject("W2", advances.release()); | 1174 this->insertObject("W2", std::move(advances)); |
1177 if (defaultAdvance.fVerticalAdvance || | 1175 if (defaultAdvance.fVerticalAdvance || |
1178 defaultAdvance.fOriginXDisp || | 1176 defaultAdvance.fOriginXDisp || |
1179 defaultAdvance.fOriginYDisp) { | 1177 defaultAdvance.fOriginYDisp) { |
1180 this->insertObject("DW2", | 1178 auto array = sk_make_sp<SkPDFArray>(); |
1181 appendVerticalAdvance(defaultAdvance, | 1179 appendVerticalAdvance(defaultAdvance, |
1182 fontInfo()->fEmSize, | 1180 fontInfo()->fEmSize, |
1183 new SkPDFArray)); | 1181 array.get()); |
| 1182 this->insertObject("DW2", std::move(array)); |
1184 } | 1183 } |
1185 } | 1184 } |
1186 | 1185 |
1187 return true; | 1186 return true; |
1188 } | 1187 } |
1189 | 1188 |
1190 /////////////////////////////////////////////////////////////////////////////// | 1189 /////////////////////////////////////////////////////////////////////////////// |
1191 // class SkPDFType1Font | 1190 // class SkPDFType1Font |
1192 /////////////////////////////////////////////////////////////////////////////// | 1191 /////////////////////////////////////////////////////////////////////////////// |
1193 | 1192 |
1194 SkPDFType1Font::SkPDFType1Font(const SkAdvancedTypefaceMetrics* info, | 1193 SkPDFType1Font::SkPDFType1Font(const SkAdvancedTypefaceMetrics* info, |
1195 SkTypeface* typeface, | 1194 SkTypeface* typeface, |
1196 uint16_t glyphID, | 1195 uint16_t glyphID, |
1197 SkPDFDict* relatedFontDescriptor) | 1196 SkPDFDict* relatedFontDescriptor) |
1198 : SkPDFFont(info, typeface, relatedFontDescriptor) { | 1197 : SkPDFFont(info, typeface, relatedFontDescriptor) { |
1199 this->populate(glyphID); | 1198 this->populate(glyphID); |
1200 } | 1199 } |
1201 | 1200 |
1202 SkPDFType1Font::~SkPDFType1Font() {} | 1201 SkPDFType1Font::~SkPDFType1Font() {} |
1203 | 1202 |
1204 bool SkPDFType1Font::addFontDescriptor(int16_t defaultWidth) { | 1203 bool SkPDFType1Font::addFontDescriptor(int16_t defaultWidth) { |
1205 if (SkPDFDict* descriptor = getFontDescriptor()) { | 1204 if (SkPDFDict* descriptor = getFontDescriptor()) { |
1206 this->insertObjRef("FontDescriptor", SkRef(descriptor)); | 1205 this->insertObjRef("FontDescriptor", |
| 1206 sk_sp<SkPDFDict>(SkRef(descriptor))); |
1207 return true; | 1207 return true; |
1208 } | 1208 } |
1209 | 1209 |
1210 auto descriptor = sk_make_sp<SkPDFDict>("FontDescriptor"); | 1210 auto descriptor = sk_make_sp<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 sk_sp<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 auto fontStream = sk_make_sp<SkPDFStream>(fontData.get()); | 1224 auto fontStream = sk_make_sp<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", std::move(fontStream)); |
1229 | 1229 |
1230 this->insertObjRef("FontDescriptor", descriptor.release()); | 1230 this->insertObjRef("FontDescriptor", std::move(descriptor)); |
1231 | 1231 |
1232 return addCommonFontDescriptorEntries(defaultWidth); | 1232 return addCommonFontDescriptorEntries(defaultWidth); |
1233 } | 1233 } |
1234 | 1234 |
1235 bool SkPDFType1Font::populate(int16_t glyphID) { | 1235 bool SkPDFType1Font::populate(int16_t glyphID) { |
1236 SkASSERT(!fontInfo()->fVerticalMetrics.get()); | 1236 SkASSERT(!fontInfo()->fVerticalMetrics.get()); |
1237 SkASSERT(fontInfo()->fGlyphWidths.get()); | 1237 SkASSERT(fontInfo()->fGlyphWidths.get()); |
1238 | 1238 |
1239 adjustGlyphRangeForSingleByteEncoding(glyphID); | 1239 adjustGlyphRangeForSingleByteEncoding(glyphID); |
1240 | 1240 |
(...skipping 28 matching lines...) Expand all Loading... |
1269 | 1269 |
1270 | 1270 |
1271 auto encDiffs = sk_make_sp<SkPDFArray>(); | 1271 auto encDiffs = sk_make_sp<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 auto encoding = sk_make_sp<SkPDFDict>("Encoding"); | 1278 auto encoding = sk_make_sp<SkPDFDict>("Encoding"); |
1279 encoding->insertObject("Differences", encDiffs.release()); | 1279 encoding->insertObject("Differences", std::move(encDiffs)); |
1280 this->insertObject("Encoding", encoding.release()); | 1280 this->insertObject("Encoding", std::move(encoding)); |
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 auto widthArray = sk_make_sp<SkPDFArray>(); | 1287 auto widthArray = sk_make_sp<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) { |
1298 appendWidth(widthRangeEntry->fAdvance[0], emSize, widthArray.get()); | 1298 appendWidth(widthRangeEntry->fAdvance[0], emSize, widthArray.get()); |
1299 } else { | 1299 } else { |
1300 firstChar = startIndex + widthRangeEntry->fStartId; | 1300 firstChar = startIndex + widthRangeEntry->fStartId; |
1301 } | 1301 } |
1302 for (int i = startIndex; i < endIndex; i++) { | 1302 for (int i = startIndex; i < endIndex; i++) { |
1303 appendWidth(widthRangeEntry->fAdvance[i], emSize, widthArray.get()); | 1303 appendWidth(widthRangeEntry->fAdvance[i], emSize, widthArray.get()); |
1304 } | 1304 } |
1305 } else { | 1305 } else { |
1306 appendWidth(defaultWidth, 1000, widthArray.get()); | 1306 appendWidth(defaultWidth, 1000, widthArray.get()); |
1307 } | 1307 } |
1308 this->insertInt("FirstChar", firstChar); | 1308 this->insertInt("FirstChar", firstChar); |
1309 this->insertInt("LastChar", firstChar + widthArray->size() - 1); | 1309 this->insertInt("LastChar", firstChar + widthArray->size() - 1); |
1310 this->insertObject("Widths", widthArray.release()); | 1310 this->insertObject("Widths", std::move(widthArray)); |
1311 } | 1311 } |
1312 | 1312 |
1313 /////////////////////////////////////////////////////////////////////////////// | 1313 /////////////////////////////////////////////////////////////////////////////// |
1314 // class SkPDFType3Font | 1314 // class SkPDFType3Font |
1315 /////////////////////////////////////////////////////////////////////////////// | 1315 /////////////////////////////////////////////////////////////////////////////// |
1316 | 1316 |
1317 SkPDFType3Font::SkPDFType3Font(const SkAdvancedTypefaceMetrics* info, | 1317 SkPDFType3Font::SkPDFType3Font(const SkAdvancedTypefaceMetrics* info, |
1318 SkTypeface* typeface, | 1318 SkTypeface* typeface, |
1319 uint16_t glyphID) | 1319 uint16_t glyphID) |
1320 : SkPDFFont(info, typeface, nullptr) { | 1320 : SkPDFFont(info, typeface, nullptr) { |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1369 &content); | 1369 &content); |
1370 const SkPath* path = cache->findPath(glyph); | 1370 const SkPath* path = cache->findPath(glyph); |
1371 if (path) { | 1371 if (path) { |
1372 SkPDFUtils::EmitPath(*path, paint.getStyle(), &content); | 1372 SkPDFUtils::EmitPath(*path, paint.getStyle(), &content); |
1373 SkPDFUtils::PaintPath(paint.getStyle(), path->getFillType(), | 1373 SkPDFUtils::PaintPath(paint.getStyle(), path->getFillType(), |
1374 &content); | 1374 &content); |
1375 } | 1375 } |
1376 SkAutoTDelete<SkMemoryStream> glyphStream(new SkMemoryStream()); | 1376 SkAutoTDelete<SkMemoryStream> glyphStream(new SkMemoryStream()); |
1377 glyphStream->setData(content.copyToData())->unref(); | 1377 glyphStream->setData(content.copyToData())->unref(); |
1378 | 1378 |
1379 charProcs->insertObjRef(characterName, | 1379 charProcs->insertObjRef( |
1380 new SkPDFStream(glyphStream.get())); | 1380 characterName, sk_make_sp<SkPDFStream>(glyphStream.get())); |
1381 } | 1381 } |
1382 | 1382 |
1383 encoding->insertObject("Differences", encDiffs.release()); | 1383 encoding->insertObject("Differences", std::move(encDiffs)); |
1384 | 1384 |
1385 this->insertObject("CharProcs", charProcs.release()); | 1385 this->insertObject("CharProcs", std::move(charProcs)); |
1386 this->insertObject("Encoding", encoding.release()); | 1386 this->insertObject("Encoding", std::move(encoding)); |
1387 | 1387 |
1388 this->insertObject("FontBBox", makeFontBBox(bbox, 1000)); | 1388 this->insertObject("FontBBox", makeFontBBox(bbox, 1000)); |
1389 this->insertInt("FirstChar", 1); | 1389 this->insertInt("FirstChar", 1); |
1390 this->insertInt("LastChar", lastGlyphID() - firstGlyphID() + 1); | 1390 this->insertInt("LastChar", lastGlyphID() - firstGlyphID() + 1); |
1391 this->insertObject("Widths", widthArray.release()); | 1391 this->insertObject("Widths", std::move(widthArray)); |
1392 this->insertName("CIDToGIDMap", "Identity"); | 1392 this->insertName("CIDToGIDMap", "Identity"); |
1393 | 1393 |
1394 this->populateToUnicodeTable(nullptr); | 1394 this->populateToUnicodeTable(nullptr); |
1395 return true; | 1395 return true; |
1396 } | 1396 } |
1397 | 1397 |
1398 SkPDFFont::Match SkPDFFont::IsMatch(SkPDFFont* existingFont, | 1398 SkPDFFont::Match SkPDFFont::IsMatch(SkPDFFont* existingFont, |
1399 uint32_t existingFontID, | 1399 uint32_t existingFontID, |
1400 uint16_t existingGlyphID, | 1400 uint16_t existingGlyphID, |
1401 uint32_t searchFontID, | 1401 uint32_t searchFontID, |
(...skipping 25 matching lines...) Expand all Loading... |
1427 sk_sp<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 |