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 static sk_sp<SkPDFArray> makeFontBBox(SkIRect glyphBBox, uint16_t emSize) { | 300 SkPDFArray* makeFontBBox(SkIRect glyphBBox, uint16_t emSize) { |
301 auto bbox = sk_make_sp<SkPDFArray>(); | 301 SkPDFArray* bbox = new 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 std::move(bbox); | 307 return bbox; |
308 } | 308 } |
309 | 309 |
310 static void appendWidth(const int16_t& width, uint16_t emSize, | 310 SkPDFArray* 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; |
313 } | 314 } |
314 | 315 |
315 static void appendVerticalAdvance( | 316 SkPDFArray* appendVerticalAdvance( |
316 const SkAdvancedTypefaceMetrics::VerticalMetric& advance, | 317 const SkAdvancedTypefaceMetrics::VerticalMetric& advance, |
317 uint16_t emSize, SkPDFArray* array) { | 318 uint16_t emSize, SkPDFArray* array) { |
318 appendWidth(advance.fVerticalAdvance, emSize, array); | 319 appendWidth(advance.fVerticalAdvance, emSize, array); |
319 appendWidth(advance.fOriginXDisp, emSize, array); | 320 appendWidth(advance.fOriginXDisp, emSize, array); |
320 appendWidth(advance.fOriginYDisp, emSize, array); | 321 appendWidth(advance.fOriginYDisp, emSize, array); |
| 322 return array; |
321 } | 323 } |
322 | 324 |
323 template <typename Data> | 325 template <typename Data> |
324 SkPDFArray* composeAdvanceData( | 326 SkPDFArray* composeAdvanceData( |
325 SkAdvancedTypefaceMetrics::AdvanceMetric<Data>* advanceInfo, | 327 SkAdvancedTypefaceMetrics::AdvanceMetric<Data>* advanceInfo, |
326 uint16_t emSize, | 328 uint16_t emSize, |
327 void (*appendAdvance)(const Data& advance, uint16_t emSize, | 329 SkPDFArray* (*appendAdvance)(const Data& advance, uint16_t emSize, |
328 SkPDFArray* array), | 330 SkPDFArray* array), |
329 Data* defaultAdvance) { | 331 Data* defaultAdvance) { |
330 SkPDFArray* result = new SkPDFArray(); | 332 SkPDFArray* result = new SkPDFArray(); |
331 for (; advanceInfo != nullptr; advanceInfo = advanceInfo->fNext.get()) { | 333 for (; advanceInfo != nullptr; advanceInfo = advanceInfo->fNext.get()) { |
332 switch (advanceInfo->fType) { | 334 switch (advanceInfo->fType) { |
333 case SkAdvancedTypefaceMetrics::WidthRange::kDefault: { | 335 case SkAdvancedTypefaceMetrics::WidthRange::kDefault: { |
334 SkASSERT(advanceInfo->fAdvance.count() == 1); | 336 SkASSERT(advanceInfo->fAdvance.count() == 1); |
335 *defaultAdvance = advanceInfo->fAdvance[0]; | 337 *defaultAdvance = advanceInfo->fAdvance[0]; |
336 break; | 338 break; |
337 } | 339 } |
338 case SkAdvancedTypefaceMetrics::WidthRange::kRange: { | 340 case SkAdvancedTypefaceMetrics::WidthRange::kRange: { |
339 auto advanceArray = sk_make_sp<SkPDFArray>(); | 341 auto advanceArray = sk_make_sp<SkPDFArray>(); |
340 for (int j = 0; j < advanceInfo->fAdvance.count(); j++) | 342 for (int j = 0; j < advanceInfo->fAdvance.count(); j++) |
341 appendAdvance(advanceInfo->fAdvance[j], emSize, | 343 appendAdvance(advanceInfo->fAdvance[j], emSize, |
342 advanceArray.get()); | 344 advanceArray.get()); |
343 result->appendInt(advanceInfo->fStartId); | 345 result->appendInt(advanceInfo->fStartId); |
344 result->appendObject(std::move(advanceArray)); | 346 result->appendObject(advanceArray.release()); |
345 break; | 347 break; |
346 } | 348 } |
347 case SkAdvancedTypefaceMetrics::WidthRange::kRun: { | 349 case SkAdvancedTypefaceMetrics::WidthRange::kRun: { |
348 SkASSERT(advanceInfo->fAdvance.count() == 1); | 350 SkASSERT(advanceInfo->fAdvance.count() == 1); |
349 result->appendInt(advanceInfo->fStartId); | 351 result->appendInt(advanceInfo->fStartId); |
350 result->appendInt(advanceInfo->fEndId); | 352 result->appendInt(advanceInfo->fEndId); |
351 appendAdvance(advanceInfo->fAdvance[0], emSize, result); | 353 appendAdvance(advanceInfo->fAdvance[0], emSize, result); |
352 break; | 354 break; |
353 } | 355 } |
354 } | 356 } |
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
550 } | 552 } |
551 } | 553 } |
552 } | 554 } |
553 | 555 |
554 // The spec requires all bfchar entries for a font must come before bfrange | 556 // The spec requires all bfchar entries for a font must come before bfrange |
555 // entries. | 557 // entries. |
556 append_bfchar_section(bfcharEntries, cmap); | 558 append_bfchar_section(bfcharEntries, cmap); |
557 append_bfrange_section(bfrangeEntries, cmap); | 559 append_bfrange_section(bfrangeEntries, cmap); |
558 } | 560 } |
559 | 561 |
560 static sk_sp<SkPDFStream> generate_tounicode_cmap( | 562 static SkPDFStream* generate_tounicode_cmap( |
561 const SkTDArray<SkUnichar>& glyphToUnicode, | 563 const SkTDArray<SkUnichar>& glyphToUnicode, |
562 const SkPDFGlyphSet* subset, | 564 const SkPDFGlyphSet* subset, |
563 bool multiByteGlyphs, | 565 bool multiByteGlyphs, |
564 uint16_t firstGlyphID, | 566 uint16_t firstGlyphID, |
565 uint16_t lastGlyphID) { | 567 uint16_t lastGlyphID) { |
566 SkDynamicMemoryWStream cmap; | 568 SkDynamicMemoryWStream cmap; |
567 if (multiByteGlyphs) { | 569 if (multiByteGlyphs) { |
568 append_tounicode_header(&cmap, firstGlyphID, lastGlyphID); | 570 append_tounicode_header(&cmap, firstGlyphID, lastGlyphID); |
569 } else { | 571 } else { |
570 append_tounicode_header(&cmap, 1, lastGlyphID - firstGlyphID + 1); | 572 append_tounicode_header(&cmap, 1, lastGlyphID - firstGlyphID + 1); |
571 } | 573 } |
572 append_cmap_sections(glyphToUnicode, subset, &cmap, multiByteGlyphs, | 574 append_cmap_sections(glyphToUnicode, subset, &cmap, multiByteGlyphs, |
573 firstGlyphID, lastGlyphID); | 575 firstGlyphID, lastGlyphID); |
574 append_cmap_footer(&cmap); | 576 append_cmap_footer(&cmap); |
575 sk_sp<SkData> cmapData(cmap.copyToData()); | 577 sk_sp<SkData> cmapData(cmap.copyToData()); |
576 return sk_make_sp<SkPDFStream>(cmapData.get()); | 578 return new SkPDFStream(cmapData.get()); |
577 } | 579 } |
578 | 580 |
579 #if defined (SK_SFNTLY_SUBSETTER) | 581 #if defined (SK_SFNTLY_SUBSETTER) |
580 static void sk_delete_array(const void* ptr, void*) { | 582 static void sk_delete_array(const void* ptr, void*) { |
581 // 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. |
582 delete[] (unsigned char*)ptr; | 584 delete[] (unsigned char*)ptr; |
583 } | 585 } |
584 #endif | 586 #endif |
585 | 587 |
586 #if defined(SK_SFNTLY_SUBSETTER) | 588 #if defined(SK_SFNTLY_SUBSETTER) |
(...skipping 426 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1013 #endif | 1015 #endif |
1014 | 1016 |
1015 bool SkPDFType0Font::populate(const SkPDFGlyphSet* subset) { | 1017 bool SkPDFType0Font::populate(const SkPDFGlyphSet* subset) { |
1016 insertName("Subtype", "Type0"); | 1018 insertName("Subtype", "Type0"); |
1017 insertName("BaseFont", fontInfo()->fFontName); | 1019 insertName("BaseFont", fontInfo()->fFontName); |
1018 insertName("Encoding", "Identity-H"); | 1020 insertName("Encoding", "Identity-H"); |
1019 | 1021 |
1020 sk_sp<SkPDFCIDFont> newCIDFont( | 1022 sk_sp<SkPDFCIDFont> newCIDFont( |
1021 new SkPDFCIDFont(fontInfo(), typeface(), subset)); | 1023 new SkPDFCIDFont(fontInfo(), typeface(), subset)); |
1022 auto descendantFonts = sk_make_sp<SkPDFArray>(); | 1024 auto descendantFonts = sk_make_sp<SkPDFArray>(); |
1023 descendantFonts->appendObjRef(std::move(newCIDFont)); | 1025 descendantFonts->appendObjRef(newCIDFont.release()); |
1024 this->insertObject("DescendantFonts", std::move(descendantFonts)); | 1026 this->insertObject("DescendantFonts", descendantFonts.release()); |
1025 | 1027 |
1026 this->populateToUnicodeTable(subset); | 1028 this->populateToUnicodeTable(subset); |
1027 | 1029 |
1028 SkDEBUGCODE(fPopulated = true); | 1030 SkDEBUGCODE(fPopulated = true); |
1029 return true; | 1031 return true; |
1030 } | 1032 } |
1031 | 1033 |
1032 /////////////////////////////////////////////////////////////////////////////// | 1034 /////////////////////////////////////////////////////////////////////////////// |
1033 // class SkPDFCIDFont | 1035 // class SkPDFCIDFont |
1034 /////////////////////////////////////////////////////////////////////////////// | 1036 /////////////////////////////////////////////////////////////////////////////// |
1035 | 1037 |
1036 SkPDFCIDFont::SkPDFCIDFont(const SkAdvancedTypefaceMetrics* info, | 1038 SkPDFCIDFont::SkPDFCIDFont(const SkAdvancedTypefaceMetrics* info, |
1037 SkTypeface* typeface, | 1039 SkTypeface* typeface, |
1038 const SkPDFGlyphSet* subset) | 1040 const SkPDFGlyphSet* subset) |
1039 : SkPDFFont(info, typeface, nullptr) { | 1041 : SkPDFFont(info, typeface, nullptr) { |
1040 this->populate(subset); | 1042 this->populate(subset); |
1041 } | 1043 } |
1042 | 1044 |
1043 SkPDFCIDFont::~SkPDFCIDFont() {} | 1045 SkPDFCIDFont::~SkPDFCIDFont() {} |
1044 | 1046 |
1045 bool SkPDFCIDFont::addFontDescriptor(int16_t defaultWidth, | 1047 bool SkPDFCIDFont::addFontDescriptor(int16_t defaultWidth, |
1046 const SkTDArray<uint32_t>* subset) { | 1048 const SkTDArray<uint32_t>* subset) { |
1047 auto descriptor = sk_make_sp<SkPDFDict>("FontDescriptor"); | 1049 auto descriptor = sk_make_sp<SkPDFDict>("FontDescriptor"); |
1048 setFontDescriptor(descriptor.get()); | 1050 setFontDescriptor(descriptor.get()); |
1049 if (!addCommonFontDescriptorEntries(defaultWidth)) { | 1051 if (!addCommonFontDescriptorEntries(defaultWidth)) { |
1050 this->insertObjRef("FontDescriptor", std::move(descriptor)); | 1052 this->insertObjRef("FontDescriptor", descriptor.release()); |
1051 return false; | 1053 return false; |
1052 } | 1054 } |
1053 SkASSERT(this->canEmbed()); | 1055 SkASSERT(this->canEmbed()); |
1054 | 1056 |
1055 switch (getType()) { | 1057 switch (getType()) { |
1056 case SkAdvancedTypefaceMetrics::kTrueType_Font: { | 1058 case SkAdvancedTypefaceMetrics::kTrueType_Font: { |
1057 size_t fontSize = 0; | 1059 size_t fontSize = 0; |
1058 #if defined(SK_SFNTLY_SUBSETTER) | 1060 #if defined(SK_SFNTLY_SUBSETTER) |
1059 if (this->canSubset()) { | 1061 if (this->canSubset()) { |
1060 sk_sp<SkPDFStream> fontStream; | 1062 sk_sp<SkPDFStream> fontStream; |
1061 SkPDFStream* rawStream = nullptr; | 1063 SkPDFStream* rawStream = nullptr; |
1062 fontSize = get_subset_font_stream(fontInfo()->fFontName.c_str(), | 1064 fontSize = get_subset_font_stream(fontInfo()->fFontName.c_str(), |
1063 typeface(), | 1065 typeface(), |
1064 *subset, | 1066 *subset, |
1065 &rawStream); | 1067 &rawStream); |
1066 if (rawStream) { | 1068 if (rawStream) { |
1067 fontStream.reset(rawStream); | 1069 fontStream.reset(rawStream); |
1068 fontStream->insertInt("Length1", fontSize); | 1070 fontStream->insertInt("Length1", fontSize); |
1069 descriptor->insertObjRef("FontFile2", std::move(fontStream))
; | 1071 descriptor->insertObjRef("FontFile2", fontStream.release()); |
1070 break; | 1072 break; |
1071 } | 1073 } |
1072 } | 1074 } |
1073 #endif | 1075 #endif |
1074 sk_sp<SkPDFSharedStream> fontStream; | 1076 sk_sp<SkPDFSharedStream> fontStream; |
1075 SkAutoTDelete<SkStreamAsset> fontData( | 1077 SkAutoTDelete<SkStreamAsset> fontData( |
1076 this->typeface()->openStream(nullptr)); | 1078 this->typeface()->openStream(nullptr)); |
1077 SkASSERT(fontData); | 1079 SkASSERT(fontData); |
1078 fontSize = fontData->getLength(); | 1080 fontSize = fontData->getLength(); |
1079 SkASSERT(fontSize > 0); | 1081 SkASSERT(fontSize > 0); |
1080 fontStream.reset(new SkPDFSharedStream(fontData.detach())); | 1082 fontStream.reset(new SkPDFSharedStream(fontData.detach())); |
1081 fontStream->dict()->insertInt("Length1", fontSize); | 1083 fontStream->dict()->insertInt("Length1", fontSize); |
1082 descriptor->insertObjRef("FontFile2", std::move(fontStream)); | 1084 descriptor->insertObjRef("FontFile2", fontStream.release()); |
1083 break; | 1085 break; |
1084 } | 1086 } |
1085 case SkAdvancedTypefaceMetrics::kCFF_Font: | 1087 case SkAdvancedTypefaceMetrics::kCFF_Font: |
1086 case SkAdvancedTypefaceMetrics::kType1CID_Font: { | 1088 case SkAdvancedTypefaceMetrics::kType1CID_Font: { |
1087 sk_sp<SkPDFSharedStream> fontStream( | 1089 sk_sp<SkPDFSharedStream> fontStream( |
1088 new SkPDFSharedStream(this->typeface()->openStream(nullptr))
); | 1090 new SkPDFSharedStream(this->typeface()->openStream(nullptr))
); |
1089 | 1091 |
1090 if (getType() == SkAdvancedTypefaceMetrics::kCFF_Font) { | 1092 if (getType() == SkAdvancedTypefaceMetrics::kCFF_Font) { |
1091 fontStream->dict()->insertName("Subtype", "Type1C"); | 1093 fontStream->dict()->insertName("Subtype", "Type1C"); |
1092 } else { | 1094 } else { |
1093 fontStream->dict()->insertName("Subtype", "CIDFontType0c"); | 1095 fontStream->dict()->insertName("Subtype", "CIDFontType0c"); |
1094 } | 1096 } |
1095 descriptor->insertObjRef("FontFile3", std::move(fontStream)); | 1097 descriptor->insertObjRef("FontFile3", fontStream.release()); |
1096 break; | 1098 break; |
1097 } | 1099 } |
1098 default: | 1100 default: |
1099 SkASSERT(false); | 1101 SkASSERT(false); |
1100 } | 1102 } |
1101 this->insertObjRef("FontDescriptor", std::move(descriptor)); | 1103 this->insertObjRef("FontDescriptor", descriptor.release()); |
1102 return true; | 1104 return true; |
1103 } | 1105 } |
1104 | 1106 |
1105 bool SkPDFCIDFont::populate(const SkPDFGlyphSet* subset) { | 1107 bool SkPDFCIDFont::populate(const SkPDFGlyphSet* subset) { |
1106 // Generate new font metrics with advance info for true type fonts. | 1108 // Generate new font metrics with advance info for true type fonts. |
1107 if (fontInfo()->fType == SkAdvancedTypefaceMetrics::kTrueType_Font) { | 1109 if (fontInfo()->fType == SkAdvancedTypefaceMetrics::kTrueType_Font) { |
1108 // Generate glyph id array. | 1110 // Generate glyph id array. |
1109 SkTDArray<uint32_t> glyphIDs; | 1111 SkTDArray<uint32_t> glyphIDs; |
1110 if (subset) { | 1112 if (subset) { |
1111 // Always include glyph 0. | 1113 // Always include glyph 0. |
(...skipping 26 matching lines...) Expand all Loading... |
1138 insertName("Subtype", "CIDFontType2"); | 1140 insertName("Subtype", "CIDFontType2"); |
1139 insertName("CIDToGIDMap", "Identity"); | 1141 insertName("CIDToGIDMap", "Identity"); |
1140 } else { | 1142 } else { |
1141 SkASSERT(false); | 1143 SkASSERT(false); |
1142 } | 1144 } |
1143 | 1145 |
1144 auto sysInfo = sk_make_sp<SkPDFDict>(); | 1146 auto sysInfo = sk_make_sp<SkPDFDict>(); |
1145 sysInfo->insertString("Registry", "Adobe"); | 1147 sysInfo->insertString("Registry", "Adobe"); |
1146 sysInfo->insertString("Ordering", "Identity"); | 1148 sysInfo->insertString("Ordering", "Identity"); |
1147 sysInfo->insertInt("Supplement", 0); | 1149 sysInfo->insertInt("Supplement", 0); |
1148 this->insertObject("CIDSystemInfo", std::move(sysInfo)); | 1150 this->insertObject("CIDSystemInfo", sysInfo.release()); |
1149 | 1151 |
1150 if (fontInfo()->fGlyphWidths.get()) { | 1152 if (fontInfo()->fGlyphWidths.get()) { |
1151 int16_t defaultWidth = 0; | 1153 int16_t defaultWidth = 0; |
1152 sk_sp<SkPDFArray> widths( | 1154 sk_sp<SkPDFArray> widths( |
1153 composeAdvanceData(fontInfo()->fGlyphWidths.get(), | 1155 composeAdvanceData(fontInfo()->fGlyphWidths.get(), |
1154 fontInfo()->fEmSize, &appendWidth, | 1156 fontInfo()->fEmSize, &appendWidth, |
1155 &defaultWidth)); | 1157 &defaultWidth)); |
1156 if (widths->size()) | 1158 if (widths->size()) |
1157 this->insertObject("W", std::move(widths)); | 1159 this->insertObject("W", widths.release()); |
1158 if (defaultWidth != 0) { | 1160 if (defaultWidth != 0) { |
1159 this->insertScalar( | 1161 this->insertScalar( |
1160 "DW", | 1162 "DW", |
1161 scaleFromFontUnits(defaultWidth, fontInfo()->fEmSize)); | 1163 scaleFromFontUnits(defaultWidth, fontInfo()->fEmSize)); |
1162 } | 1164 } |
1163 } | 1165 } |
1164 if (fontInfo()->fVerticalMetrics.get()) { | 1166 if (fontInfo()->fVerticalMetrics.get()) { |
1165 struct SkAdvancedTypefaceMetrics::VerticalMetric defaultAdvance; | 1167 struct SkAdvancedTypefaceMetrics::VerticalMetric defaultAdvance; |
1166 defaultAdvance.fVerticalAdvance = 0; | 1168 defaultAdvance.fVerticalAdvance = 0; |
1167 defaultAdvance.fOriginXDisp = 0; | 1169 defaultAdvance.fOriginXDisp = 0; |
1168 defaultAdvance.fOriginYDisp = 0; | 1170 defaultAdvance.fOriginYDisp = 0; |
1169 sk_sp<SkPDFArray> advances( | 1171 sk_sp<SkPDFArray> advances( |
1170 composeAdvanceData(fontInfo()->fVerticalMetrics.get(), | 1172 composeAdvanceData(fontInfo()->fVerticalMetrics.get(), |
1171 fontInfo()->fEmSize, &appendVerticalAdvance, | 1173 fontInfo()->fEmSize, &appendVerticalAdvance, |
1172 &defaultAdvance)); | 1174 &defaultAdvance)); |
1173 if (advances->size()) | 1175 if (advances->size()) |
1174 this->insertObject("W2", std::move(advances)); | 1176 this->insertObject("W2", advances.release()); |
1175 if (defaultAdvance.fVerticalAdvance || | 1177 if (defaultAdvance.fVerticalAdvance || |
1176 defaultAdvance.fOriginXDisp || | 1178 defaultAdvance.fOriginXDisp || |
1177 defaultAdvance.fOriginYDisp) { | 1179 defaultAdvance.fOriginYDisp) { |
1178 auto array = sk_make_sp<SkPDFArray>(); | 1180 this->insertObject("DW2", |
1179 appendVerticalAdvance(defaultAdvance, | 1181 appendVerticalAdvance(defaultAdvance, |
1180 fontInfo()->fEmSize, | 1182 fontInfo()->fEmSize, |
1181 array.get()); | 1183 new SkPDFArray)); |
1182 this->insertObject("DW2", std::move(array)); | |
1183 } | 1184 } |
1184 } | 1185 } |
1185 | 1186 |
1186 return true; | 1187 return true; |
1187 } | 1188 } |
1188 | 1189 |
1189 /////////////////////////////////////////////////////////////////////////////// | 1190 /////////////////////////////////////////////////////////////////////////////// |
1190 // class SkPDFType1Font | 1191 // class SkPDFType1Font |
1191 /////////////////////////////////////////////////////////////////////////////// | 1192 /////////////////////////////////////////////////////////////////////////////// |
1192 | 1193 |
1193 SkPDFType1Font::SkPDFType1Font(const SkAdvancedTypefaceMetrics* info, | 1194 SkPDFType1Font::SkPDFType1Font(const SkAdvancedTypefaceMetrics* info, |
1194 SkTypeface* typeface, | 1195 SkTypeface* typeface, |
1195 uint16_t glyphID, | 1196 uint16_t glyphID, |
1196 SkPDFDict* relatedFontDescriptor) | 1197 SkPDFDict* relatedFontDescriptor) |
1197 : SkPDFFont(info, typeface, relatedFontDescriptor) { | 1198 : SkPDFFont(info, typeface, relatedFontDescriptor) { |
1198 this->populate(glyphID); | 1199 this->populate(glyphID); |
1199 } | 1200 } |
1200 | 1201 |
1201 SkPDFType1Font::~SkPDFType1Font() {} | 1202 SkPDFType1Font::~SkPDFType1Font() {} |
1202 | 1203 |
1203 bool SkPDFType1Font::addFontDescriptor(int16_t defaultWidth) { | 1204 bool SkPDFType1Font::addFontDescriptor(int16_t defaultWidth) { |
1204 if (SkPDFDict* descriptor = getFontDescriptor()) { | 1205 if (SkPDFDict* descriptor = getFontDescriptor()) { |
1205 this->insertObjRef("FontDescriptor", | 1206 this->insertObjRef("FontDescriptor", SkRef(descriptor)); |
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", std::move(fontStream)); | 1228 descriptor->insertObjRef("FontFile", fontStream.release()); |
1229 | 1229 |
1230 this->insertObjRef("FontDescriptor", std::move(descriptor)); | 1230 this->insertObjRef("FontDescriptor", descriptor.release()); |
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", std::move(encDiffs)); | 1279 encoding->insertObject("Differences", encDiffs.release()); |
1280 this->insertObject("Encoding", std::move(encoding)); | 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 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", std::move(widthArray)); | 1310 this->insertObject("Widths", widthArray.release()); |
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( | 1379 charProcs->insertObjRef(characterName, |
1380 characterName, sk_make_sp<SkPDFStream>(glyphStream.get())); | 1380 new SkPDFStream(glyphStream.get())); |
1381 } | 1381 } |
1382 | 1382 |
1383 encoding->insertObject("Differences", std::move(encDiffs)); | 1383 encoding->insertObject("Differences", encDiffs.release()); |
1384 | 1384 |
1385 this->insertObject("CharProcs", std::move(charProcs)); | 1385 this->insertObject("CharProcs", charProcs.release()); |
1386 this->insertObject("Encoding", std::move(encoding)); | 1386 this->insertObject("Encoding", encoding.release()); |
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", std::move(widthArray)); | 1391 this->insertObject("Widths", widthArray.release()); |
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 |