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 sk_sp<SkPDFArray> advanceArray(new SkPDFArray()); | 341 auto advanceArray = sk_make_sp<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 662 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 sk_sp<SkPDFCIDFont> newCIDFont( | 1022 sk_sp<SkPDFCIDFont> newCIDFont( |
1023 new SkPDFCIDFont(fontInfo(), typeface(), subset)); | 1023 new SkPDFCIDFont(fontInfo(), typeface(), subset)); |
1024 sk_sp<SkPDFArray> descendantFonts(new SkPDFArray()); | 1024 auto descendantFonts = sk_make_sp<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 sk_sp<SkPDFDict> descriptor(new SkPDFDict("FontDescriptor")); | 1049 auto descriptor = sk_make_sp<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; |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 sk_sp<SkPDFDict> sysInfo(new SkPDFDict); | 1146 auto sysInfo = sk_make_sp<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 sk_sp<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, |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after 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 sk_sp<SkPDFDict> descriptor(new 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 sk_sp<SkPDFStream> fontStream(new 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", 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 sk_sp<SkPDFArray> encDiffs(new 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 sk_sp<SkPDFDict> encoding(new SkPDFDict("Encoding")); | 1278 auto encoding = sk_make_sp<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 sk_sp<SkPDFArray> widthArray(new 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) { |
(...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 sk_sp<SkPDFDict> charProcs(new SkPDFDict); | 1346 auto charProcs = sk_make_sp<SkPDFDict>(); |
1347 sk_sp<SkPDFDict> encoding(new SkPDFDict("Encoding")); | 1347 auto encoding = sk_make_sp<SkPDFDict>("Encoding"); |
1348 | 1348 |
1349 sk_sp<SkPDFArray> encDiffs(new SkPDFArray); | 1349 auto encDiffs = sk_make_sp<SkPDFArray>(); |
1350 encDiffs->reserve(lastGlyphID() - firstGlyphID() + 2); | 1350 encDiffs->reserve(lastGlyphID() - firstGlyphID() + 2); |
1351 encDiffs->appendInt(1); | 1351 encDiffs->appendInt(1); |
1352 | 1352 |
1353 sk_sp<SkPDFArray> widthArray(new SkPDFArray()); | 1353 auto widthArray = sk_make_sp<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 63 matching lines...) Expand 10 before | Expand all | Expand 10 after 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 |