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 304 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
315 static void appendVerticalAdvance( | 315 static void appendVerticalAdvance( |
316 const SkAdvancedTypefaceMetrics::VerticalMetric& advance, | 316 const SkAdvancedTypefaceMetrics::VerticalMetric& advance, |
317 uint16_t emSize, SkPDFArray* array) { | 317 uint16_t emSize, SkPDFArray* array) { |
318 appendWidth(advance.fVerticalAdvance, emSize, array); | 318 appendWidth(advance.fVerticalAdvance, emSize, array); |
319 appendWidth(advance.fOriginXDisp, emSize, array); | 319 appendWidth(advance.fOriginXDisp, emSize, array); |
320 appendWidth(advance.fOriginYDisp, emSize, array); | 320 appendWidth(advance.fOriginYDisp, emSize, array); |
321 } | 321 } |
322 | 322 |
323 template <typename Data> | 323 template <typename Data> |
324 SkPDFArray* composeAdvanceData( | 324 SkPDFArray* composeAdvanceData( |
325 SkAdvancedTypefaceMetrics::AdvanceMetric<Data>* advanceInfo, | 325 const SkSinglyLinkedList< |
| 326 SkAdvancedTypefaceMetrics::AdvanceMetric<Data>>& advanceInfo, |
326 uint16_t emSize, | 327 uint16_t emSize, |
327 void (*appendAdvance)(const Data& advance, uint16_t emSize, | 328 void (*appendAdvance)(const Data& advance, |
| 329 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 (const SkAdvancedTypefaceMetrics::AdvanceMetric<Data>& range : |
332 switch (advanceInfo->fType) { | 334 advanceInfo) { |
333 case SkAdvancedTypefaceMetrics::WidthRange::kDefault: { | 335 switch (range.fType) { |
334 SkASSERT(advanceInfo->fAdvance.count() == 1); | 336 case SkAdvancedTypefaceMetrics::AdvanceMetric<Data>::kDefault: { |
335 *defaultAdvance = advanceInfo->fAdvance[0]; | 337 SkASSERT(range.fAdvance.count() == 1); |
| 338 *defaultAdvance = range.fAdvance[0]; |
336 break; | 339 break; |
337 } | 340 } |
338 case SkAdvancedTypefaceMetrics::WidthRange::kRange: { | 341 case SkAdvancedTypefaceMetrics::AdvanceMetric<Data>::kRange: { |
339 auto advanceArray = sk_make_sp<SkPDFArray>(); | 342 auto advanceArray = sk_make_sp<SkPDFArray>(); |
340 for (int j = 0; j < advanceInfo->fAdvance.count(); j++) | 343 for (int j = 0; j < range.fAdvance.count(); j++) |
341 appendAdvance(advanceInfo->fAdvance[j], emSize, | 344 appendAdvance(range.fAdvance[j], emSize, |
342 advanceArray.get()); | 345 advanceArray.get()); |
343 result->appendInt(advanceInfo->fStartId); | 346 result->appendInt(range.fStartId); |
344 result->appendObject(std::move(advanceArray)); | 347 result->appendObject(std::move(advanceArray)); |
345 break; | 348 break; |
346 } | 349 } |
347 case SkAdvancedTypefaceMetrics::WidthRange::kRun: { | 350 case SkAdvancedTypefaceMetrics::AdvanceMetric<Data>::kRun: { |
348 SkASSERT(advanceInfo->fAdvance.count() == 1); | 351 SkASSERT(range.fAdvance.count() == 1); |
349 result->appendInt(advanceInfo->fStartId); | 352 result->appendInt(range.fStartId); |
350 result->appendInt(advanceInfo->fEndId); | 353 result->appendInt(range.fEndId); |
351 appendAdvance(advanceInfo->fAdvance[0], emSize, result); | 354 appendAdvance(range.fAdvance[0], emSize, result); |
352 break; | 355 break; |
353 } | 356 } |
354 } | 357 } |
355 } | 358 } |
356 return result; | 359 return result; |
357 } | 360 } |
358 | 361 |
359 } // namespace | 362 } // namespace |
360 | 363 |
361 static void append_tounicode_header(SkDynamicMemoryWStream* cmap, | 364 static void append_tounicode_header(SkDynamicMemoryWStream* cmap, |
(...skipping 777 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1139 } else { | 1142 } else { |
1140 SkASSERT(false); | 1143 SkASSERT(false); |
1141 } | 1144 } |
1142 | 1145 |
1143 auto sysInfo = sk_make_sp<SkPDFDict>(); | 1146 auto sysInfo = sk_make_sp<SkPDFDict>(); |
1144 sysInfo->insertString("Registry", "Adobe"); | 1147 sysInfo->insertString("Registry", "Adobe"); |
1145 sysInfo->insertString("Ordering", "Identity"); | 1148 sysInfo->insertString("Ordering", "Identity"); |
1146 sysInfo->insertInt("Supplement", 0); | 1149 sysInfo->insertInt("Supplement", 0); |
1147 this->insertObject("CIDSystemInfo", std::move(sysInfo)); | 1150 this->insertObject("CIDSystemInfo", std::move(sysInfo)); |
1148 | 1151 |
1149 if (fontInfo()->fGlyphWidths.get()) { | 1152 if (!fontInfo()->fGlyphWidths.empty()) { |
1150 int16_t defaultWidth = 0; | 1153 int16_t defaultWidth = 0; |
1151 sk_sp<SkPDFArray> widths( | 1154 sk_sp<SkPDFArray> widths(composeAdvanceData( |
1152 composeAdvanceData(fontInfo()->fGlyphWidths.get(), | 1155 fontInfo()->fGlyphWidths, fontInfo()->fEmSize, &appendWidth, |
1153 fontInfo()->fEmSize, &appendWidth, | 1156 &defaultWidth)); |
1154 &defaultWidth)); | |
1155 if (widths->size()) | 1157 if (widths->size()) |
1156 this->insertObject("W", std::move(widths)); | 1158 this->insertObject("W", std::move(widths)); |
1157 if (defaultWidth != 0) { | 1159 if (defaultWidth != 0) { |
1158 this->insertScalar( | 1160 this->insertScalar( |
1159 "DW", | 1161 "DW", |
1160 scaleFromFontUnits(defaultWidth, fontInfo()->fEmSize)); | 1162 scaleFromFontUnits(defaultWidth, fontInfo()->fEmSize)); |
1161 } | 1163 } |
1162 } | 1164 } |
1163 if (fontInfo()->fVerticalMetrics.get()) { | 1165 if (!fontInfo()->fVerticalMetrics.empty()) { |
1164 struct SkAdvancedTypefaceMetrics::VerticalMetric defaultAdvance; | 1166 struct SkAdvancedTypefaceMetrics::VerticalMetric defaultAdvance; |
1165 defaultAdvance.fVerticalAdvance = 0; | 1167 defaultAdvance.fVerticalAdvance = 0; |
1166 defaultAdvance.fOriginXDisp = 0; | 1168 defaultAdvance.fOriginXDisp = 0; |
1167 defaultAdvance.fOriginYDisp = 0; | 1169 defaultAdvance.fOriginYDisp = 0; |
1168 sk_sp<SkPDFArray> advances( | 1170 sk_sp<SkPDFArray> advances(composeAdvanceData( |
1169 composeAdvanceData(fontInfo()->fVerticalMetrics.get(), | 1171 fontInfo()->fVerticalMetrics, fontInfo()->fEmSize, |
1170 fontInfo()->fEmSize, &appendVerticalAdvance, | 1172 &appendVerticalAdvance, &defaultAdvance)); |
1171 &defaultAdvance)); | |
1172 if (advances->size()) | 1173 if (advances->size()) |
1173 this->insertObject("W2", std::move(advances)); | 1174 this->insertObject("W2", std::move(advances)); |
1174 if (defaultAdvance.fVerticalAdvance || | 1175 if (defaultAdvance.fVerticalAdvance || |
1175 defaultAdvance.fOriginXDisp || | 1176 defaultAdvance.fOriginXDisp || |
1176 defaultAdvance.fOriginYDisp) { | 1177 defaultAdvance.fOriginYDisp) { |
1177 auto array = sk_make_sp<SkPDFArray>(); | 1178 auto array = sk_make_sp<SkPDFArray>(); |
1178 appendVerticalAdvance(defaultAdvance, | 1179 appendVerticalAdvance(defaultAdvance, |
1179 fontInfo()->fEmSize, | 1180 fontInfo()->fEmSize, |
1180 array.get()); | 1181 array.get()); |
1181 this->insertObject("DW2", std::move(array)); | 1182 this->insertObject("DW2", std::move(array)); |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1230 fontStream->insertInt("Length2", data); | 1231 fontStream->insertInt("Length2", data); |
1231 fontStream->insertInt("Length3", trailer); | 1232 fontStream->insertInt("Length3", trailer); |
1232 descriptor->insertObjRef("FontFile", std::move(fontStream)); | 1233 descriptor->insertObjRef("FontFile", std::move(fontStream)); |
1233 | 1234 |
1234 this->insertObjRef("FontDescriptor", std::move(descriptor)); | 1235 this->insertObjRef("FontDescriptor", std::move(descriptor)); |
1235 | 1236 |
1236 return addCommonFontDescriptorEntries(defaultWidth); | 1237 return addCommonFontDescriptorEntries(defaultWidth); |
1237 } | 1238 } |
1238 | 1239 |
1239 bool SkPDFType1Font::populate(int16_t glyphID) { | 1240 bool SkPDFType1Font::populate(int16_t glyphID) { |
1240 SkASSERT(!fontInfo()->fVerticalMetrics.get()); | 1241 SkASSERT(fontInfo()->fVerticalMetrics.empty()); |
1241 SkASSERT(fontInfo()->fGlyphWidths.get()); | 1242 SkASSERT(!fontInfo()->fGlyphWidths.empty()); |
1242 | 1243 |
1243 adjustGlyphRangeForSingleByteEncoding(glyphID); | 1244 adjustGlyphRangeForSingleByteEncoding(glyphID); |
1244 | 1245 |
1245 int16_t defaultWidth = 0; | 1246 int16_t defaultWidth = 0; |
1246 const SkAdvancedTypefaceMetrics::WidthRange* widthRangeEntry = nullptr; | 1247 const SkAdvancedTypefaceMetrics::WidthRange* widthRangeEntry = nullptr; |
1247 const SkAdvancedTypefaceMetrics::WidthRange* widthEntry; | 1248 for (const auto& widthEntry : fontInfo()->fGlyphWidths) { |
1248 for (widthEntry = fontInfo()->fGlyphWidths.get(); | 1249 switch (widthEntry.fType) { |
1249 widthEntry != nullptr; | |
1250 widthEntry = widthEntry->fNext.get()) { | |
1251 switch (widthEntry->fType) { | |
1252 case SkAdvancedTypefaceMetrics::WidthRange::kDefault: | 1250 case SkAdvancedTypefaceMetrics::WidthRange::kDefault: |
1253 defaultWidth = widthEntry->fAdvance[0]; | 1251 defaultWidth = widthEntry.fAdvance[0]; |
1254 break; | 1252 break; |
1255 case SkAdvancedTypefaceMetrics::WidthRange::kRun: | 1253 case SkAdvancedTypefaceMetrics::WidthRange::kRun: |
1256 SkASSERT(false); | 1254 SkASSERT(false); |
1257 break; | 1255 break; |
1258 case SkAdvancedTypefaceMetrics::WidthRange::kRange: | 1256 case SkAdvancedTypefaceMetrics::WidthRange::kRange: |
1259 SkASSERT(widthRangeEntry == nullptr); | 1257 SkASSERT(widthRangeEntry == nullptr); |
1260 widthRangeEntry = widthEntry; | 1258 widthRangeEntry = &widthEntry; |
1261 break; | 1259 break; |
1262 } | 1260 } |
1263 } | 1261 } |
1264 | 1262 |
1265 if (!addFontDescriptor(defaultWidth)) { | 1263 if (!addFontDescriptor(defaultWidth)) { |
1266 return false; | 1264 return false; |
1267 } | 1265 } |
1268 | 1266 |
1269 insertName("Subtype", "Type1"); | 1267 insertName("Subtype", "Type1"); |
1270 insertName("BaseFont", fontInfo()->fFontName); | 1268 insertName("BaseFont", fontInfo()->fFontName); |
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1438 } | 1436 } |
1439 return *canon->fCanEmbedTypeface.set(id, canEmbed); | 1437 return *canon->fCanEmbedTypeface.set(id, canEmbed); |
1440 } | 1438 } |
1441 | 1439 |
1442 void SkPDFFont::drop() { | 1440 void SkPDFFont::drop() { |
1443 fTypeface = nullptr; | 1441 fTypeface = nullptr; |
1444 fFontInfo = nullptr; | 1442 fFontInfo = nullptr; |
1445 fDescriptor = nullptr; | 1443 fDescriptor = nullptr; |
1446 this->SkPDFDict::drop(); | 1444 this->SkPDFDict::drop(); |
1447 } | 1445 } |
OLD | NEW |