Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(72)

Side by Side Diff: src/pdf/SkPDFFont.cpp

Issue 2219733004: SkPDF: Stop using kHAdvance_PerGlyphInfo (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: 2016-08-05 (Friday) 16:11:24 EDT Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/pdf/SkPDFDevice.cpp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 283 matching lines...) Expand 10 before | Expand all | Expand 10 after
294 static sk_sp<SkPDFArray> makeFontBBox(SkIRect glyphBBox, uint16_t emSize) { 294 static sk_sp<SkPDFArray> makeFontBBox(SkIRect glyphBBox, uint16_t emSize) {
295 auto bbox = sk_make_sp<SkPDFArray>(); 295 auto bbox = sk_make_sp<SkPDFArray>();
296 bbox->reserve(4); 296 bbox->reserve(4);
297 bbox->appendScalar(scaleFromFontUnits(glyphBBox.fLeft, emSize)); 297 bbox->appendScalar(scaleFromFontUnits(glyphBBox.fLeft, emSize));
298 bbox->appendScalar(scaleFromFontUnits(glyphBBox.fBottom, emSize)); 298 bbox->appendScalar(scaleFromFontUnits(glyphBBox.fBottom, emSize));
299 bbox->appendScalar(scaleFromFontUnits(glyphBBox.fRight, emSize)); 299 bbox->appendScalar(scaleFromFontUnits(glyphBBox.fRight, emSize));
300 bbox->appendScalar(scaleFromFontUnits(glyphBBox.fTop, emSize)); 300 bbox->appendScalar(scaleFromFontUnits(glyphBBox.fTop, emSize));
301 return bbox; 301 return bbox;
302 } 302 }
303 303
304 static void appendWidth(const int16_t& width, uint16_t emSize, 304 sk_sp<SkPDFArray> composeAdvanceData(
305 SkPDFArray* array) { 305 const SkSinglyLinkedList<SkAdvancedTypefaceMetrics::WidthRange>& advance Info,
306 array->appendScalar(scaleFromFontUnits(width, emSize));
307 }
308
309 static void appendVerticalAdvance(
310 const SkAdvancedTypefaceMetrics::VerticalMetric& advance,
311 uint16_t emSize, SkPDFArray* array) {
312 appendWidth(advance.fVerticalAdvance, emSize, array);
313 appendWidth(advance.fOriginXDisp, emSize, array);
314 appendWidth(advance.fOriginYDisp, emSize, array);
315 }
316
317 template <typename Data>
318 SkPDFArray* composeAdvanceData(
319 const SkSinglyLinkedList<
320 SkAdvancedTypefaceMetrics::AdvanceMetric<Data>>& advanceInfo,
321 uint16_t emSize, 306 uint16_t emSize,
322 void (*appendAdvance)(const Data& advance, 307 int16_t* defaultAdvance) {
323 uint16_t emSize, 308 auto result = sk_make_sp<SkPDFArray>();
324 SkPDFArray* array), 309 for (const SkAdvancedTypefaceMetrics::WidthRange& range : advanceInfo) {
325 Data* defaultAdvance) {
326 SkPDFArray* result = new SkPDFArray();
327 for (const SkAdvancedTypefaceMetrics::AdvanceMetric<Data>& range :
328 advanceInfo) {
329 switch (range.fType) { 310 switch (range.fType) {
330 case SkAdvancedTypefaceMetrics::AdvanceMetric<Data>::kDefault: { 311 case SkAdvancedTypefaceMetrics::WidthRange::kDefault: {
331 SkASSERT(range.fAdvance.count() == 1); 312 SkASSERT(range.fAdvance.count() == 1);
332 *defaultAdvance = range.fAdvance[0]; 313 *defaultAdvance = range.fAdvance[0];
333 break; 314 break;
334 } 315 }
335 case SkAdvancedTypefaceMetrics::AdvanceMetric<Data>::kRange: { 316 case SkAdvancedTypefaceMetrics::WidthRange::kRange: {
336 auto advanceArray = sk_make_sp<SkPDFArray>(); 317 auto advanceArray = sk_make_sp<SkPDFArray>();
337 for (int j = 0; j < range.fAdvance.count(); j++) 318 for (int j = 0; j < range.fAdvance.count(); j++)
338 appendAdvance(range.fAdvance[j], emSize, 319 advanceArray->appendScalar(
339 advanceArray.get()); 320 scaleFromFontUnits(range.fAdvance[j], emSize));
340 result->appendInt(range.fStartId); 321 result->appendInt(range.fStartId);
341 result->appendObject(std::move(advanceArray)); 322 result->appendObject(std::move(advanceArray));
342 break; 323 break;
343 } 324 }
344 case SkAdvancedTypefaceMetrics::AdvanceMetric<Data>::kRun: { 325 case SkAdvancedTypefaceMetrics::WidthRange::kRun: {
345 SkASSERT(range.fAdvance.count() == 1); 326 SkASSERT(range.fAdvance.count() == 1);
346 result->appendInt(range.fStartId); 327 result->appendInt(range.fStartId);
347 result->appendInt(range.fEndId); 328 result->appendInt(range.fEndId);
348 appendAdvance(range.fAdvance[0], emSize, result); 329 result->appendScalar(
330 scaleFromFontUnits(range.fAdvance[0], emSize));
349 break; 331 break;
350 } 332 }
351 } 333 }
352 } 334 }
353 return result; 335 return result;
354 } 336 }
355 337
356 } // namespace 338 } // namespace
357 339
358 static void append_tounicode_header(SkDynamicMemoryWStream* cmap, 340 static void append_tounicode_header(SkDynamicMemoryWStream* cmap,
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
486 // overlap, but succeeding maps supersede preceding maps." 468 // overlap, but succeeding maps supersede preceding maps."
487 // 469 //
488 // In case of searching text in PDF, bfrange will have higher precedence so 470 // In case of searching text in PDF, bfrange will have higher precedence so
489 // typing char id 0x0014 in search box will get glyph id 0x0004 first. However, 471 // typing char id 0x0014 in search box will get glyph id 0x0004 first. However,
490 // the spec does not mention how will this kind of conflict being resolved. 472 // the spec does not mention how will this kind of conflict being resolved.
491 // 473 //
492 // For the worst case (having 65536 continuous unicode and we use every other 474 // For the worst case (having 65536 continuous unicode and we use every other
493 // one of them), the possible savings by aggressive optimization is 416KB 475 // one of them), the possible savings by aggressive optimization is 416KB
494 // pre-compressed and does not provide enough motivation for implementation. 476 // pre-compressed and does not provide enough motivation for implementation.
495 477
496 // FIXME: this should be in a header so that it is separately testable 478 // TODO(halcanary): this should be in a header so that it is separately testable
497 // ( see caller in tests/ToUnicode.cpp ) 479 // ( see caller in tests/ToUnicode.cpp )
498 void append_cmap_sections(const SkTDArray<SkUnichar>& glyphToUnicode, 480 void append_cmap_sections(const SkTDArray<SkUnichar>& glyphToUnicode,
499 const SkPDFGlyphSet* subset, 481 const SkPDFGlyphSet* subset,
500 SkDynamicMemoryWStream* cmap, 482 SkDynamicMemoryWStream* cmap,
501 bool multiByteGlyphs, 483 bool multiByteGlyphs,
502 uint16_t firstGlyphID, 484 uint16_t firstGlyphID,
503 uint16_t lastGlyphID); 485 uint16_t lastGlyphID);
504 486
505 void append_cmap_sections(const SkTDArray<SkUnichar>& glyphToUnicode, 487 void append_cmap_sections(const SkTDArray<SkUnichar>& glyphToUnicode,
506 const SkPDFGlyphSet* subset, 488 const SkPDFGlyphSet* subset,
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after
726 // for TrueType fonts. 708 // for TrueType fonts.
727 SkAdvancedTypefaceMetrics::FontType fontType = 709 SkAdvancedTypefaceMetrics::FontType fontType =
728 fontMetrics.get() ? fontMetrics.get()->fType : 710 fontMetrics.get() ? fontMetrics.get()->fType :
729 SkAdvancedTypefaceMetrics::kOther_Font; 711 SkAdvancedTypefaceMetrics::kOther_Font;
730 712
731 if (fontType == SkAdvancedTypefaceMetrics::kType1CID_Font || 713 if (fontType == SkAdvancedTypefaceMetrics::kType1CID_Font ||
732 fontType == SkAdvancedTypefaceMetrics::kTrueType_Font) { 714 fontType == SkAdvancedTypefaceMetrics::kTrueType_Font) {
733 return SkRef(relatedFont); 715 return SkRef(relatedFont);
734 } 716 }
735 } else { 717 } else {
736 SkTypeface::PerGlyphInfo info; 718 SkTypeface::PerGlyphInfo info =
737 info = SkTypeface::kGlyphNames_PerGlyphInfo; 719 SkTBitOr(SkTypeface::kGlyphNames_PerGlyphInfo,
738 info = SkTBitOr<SkTypeface::PerGlyphInfo>( 720 SkTypeface::kToUnicode_PerGlyphInfo);
739 info, SkTypeface::kToUnicode_PerGlyphInfo);
740 #if !defined (SK_SFNTLY_SUBSETTER)
741 info = SkTBitOr<SkTypeface::PerGlyphInfo>(
742 info, SkTypeface::kHAdvance_PerGlyphInfo);
743 #endif
744 fontMetrics.reset( 721 fontMetrics.reset(
745 typeface->getAdvancedTypefaceMetrics(info, nullptr, 0)); 722 typeface->getAdvancedTypefaceMetrics(info, nullptr, 0));
746 #if defined (SK_SFNTLY_SUBSETTER)
747 if (fontMetrics.get() &&
748 fontMetrics->fType != SkAdvancedTypefaceMetrics::kTrueType_Font) {
749 // Font does not support subsetting, get new info with advance.
750 info = SkTBitOr<SkTypeface::PerGlyphInfo>(
751 info, SkTypeface::kHAdvance_PerGlyphInfo);
752 fontMetrics.reset(
753 typeface->getAdvancedTypefaceMetrics(info, nullptr, 0));
754 }
755 #endif
756 } 723 }
757 724
758 SkPDFFont* font = SkPDFFont::Create(canon, fontMetrics.get(), typeface, 725 SkPDFFont* font = SkPDFFont::Create(canon, fontMetrics.get(), typeface,
759 glyphID, relatedFontDescriptor); 726 glyphID, relatedFontDescriptor);
760 canon->addFont(font, fontID, font->fFirstGlyphID); 727 canon->addFont(font, fontID, font->fFirstGlyphID);
761 return font; 728 return font;
762 } 729 }
763 730
764 SkPDFFont* SkPDFFont::getFontSubset(const SkPDFGlyphSet*) { 731 SkPDFFont* SkPDFFont::getFontSubset(const SkPDFGlyphSet*) {
765 return nullptr; // Default: no support. 732 return nullptr; // Default: no support.
(...skipping 300 matching lines...) Expand 10 before | Expand all | Expand 10 after
1066 descriptor->insertObjRef("FontFile3", std::move(fontStream)); 1033 descriptor->insertObjRef("FontFile3", std::move(fontStream));
1067 break; 1034 break;
1068 } 1035 }
1069 default: 1036 default:
1070 SkASSERT(false); 1037 SkASSERT(false);
1071 } 1038 }
1072 this->insertObjRef("FontDescriptor", std::move(descriptor)); 1039 this->insertObjRef("FontDescriptor", std::move(descriptor));
1073 return true; 1040 return true;
1074 } 1041 }
1075 1042
1043 void set_glyph_widths(SkTypeface* tf,
1044 const SkTDArray<uint32_t>* glyphIDs,
1045 SkAdvancedTypefaceMetrics* dst) {
1046 SkPaint tmpPaint;
1047 tmpPaint.setHinting(SkPaint::kNo_Hinting);
1048 tmpPaint.setTypeface(sk_ref_sp(tf));
1049 tmpPaint.setTextSize((SkScalar)tf->getUnitsPerEm());
1050 SkAutoGlyphCache autoGlyphCache(tmpPaint, nullptr, nullptr);
1051 SkGlyphCache* glyphCache = autoGlyphCache.get();
1052 SkAdvancedTypefaceMetrics::GetAdvance advanceFn =
1053 [glyphCache](int gid, int16_t* advance) {
1054 *advance = (int16_t)glyphCache->getGlyphIDAdvance(gid).fAdvanceX;
1055 return true;
1056 };
1057 if (!glyphIDs || glyphIDs->isEmpty()) {
1058 dst->setGlyphWidths(tf->countGlyphs(), nullptr, 0, advanceFn);
1059 } else {
1060 dst->setGlyphWidths(tf->countGlyphs(),
1061 glyphIDs->begin(),
1062 glyphIDs->count(), advanceFn);
1063 }
1064 }
1065
1076 bool SkPDFCIDFont::populate(const SkPDFGlyphSet* subset) { 1066 bool SkPDFCIDFont::populate(const SkPDFGlyphSet* subset) {
1077 // Generate new font metrics with advance info for true type fonts. 1067 // Generate new font metrics with advance info for true type fonts.
1068 // Generate glyph id array.
1069 SkTDArray<uint32_t> glyphIDs;
1070 if (subset) {
1071 if (!subset->has(0)) {
1072 glyphIDs.push(0); // Always include glyph 0.
1073 }
1074 subset->exportTo(&glyphIDs);
1075 }
1078 if (fontInfo()->fType == SkAdvancedTypefaceMetrics::kTrueType_Font) { 1076 if (fontInfo()->fType == SkAdvancedTypefaceMetrics::kTrueType_Font) {
1079 // Generate glyph id array. 1077 SkTypeface::PerGlyphInfo info = SkTypeface::kGlyphNames_PerGlyphInfo;
1080 SkTDArray<uint32_t> glyphIDs;
1081 if (subset) {
1082 // Always include glyph 0.
1083 if (!subset->has(0)) {
1084 glyphIDs.push(0);
1085 }
1086 subset->exportTo(&glyphIDs);
1087 }
1088
1089 SkTypeface::PerGlyphInfo info;
1090 info = SkTypeface::kGlyphNames_PerGlyphInfo;
1091 info = SkTBitOr<SkTypeface::PerGlyphInfo>(
1092 info, SkTypeface::kHAdvance_PerGlyphInfo);
1093 uint32_t* glyphs = (glyphIDs.count() == 0) ? nullptr : glyphIDs.begin(); 1078 uint32_t* glyphs = (glyphIDs.count() == 0) ? nullptr : glyphIDs.begin();
1094 uint32_t glyphsCount = glyphs ? glyphIDs.count() : 0; 1079 uint32_t glyphsCount = glyphs ? glyphIDs.count() : 0;
1095 sk_sp<const SkAdvancedTypefaceMetrics> fontMetrics( 1080 sk_sp<const SkAdvancedTypefaceMetrics> fontMetrics(
1096 typeface()->getAdvancedTypefaceMetrics(info, glyphs, glyphsCount)); 1081 typeface()->getAdvancedTypefaceMetrics(info, glyphs, glyphsCount));
1097 setFontInfo(fontMetrics.get()); 1082 setFontInfo(fontMetrics.get());
1098 addFontDescriptor(0, &glyphIDs); 1083 addFontDescriptor(0, &glyphIDs);
1099 } else { 1084 } else {
1100 // Other CID fonts 1085 // Other CID fonts
1101 addFontDescriptor(0, nullptr); 1086 addFontDescriptor(0, nullptr);
1102 } 1087 }
1103 1088
1104 insertName("BaseFont", fontInfo()->fFontName); 1089 insertName("BaseFont", fontInfo()->fFontName);
1105 1090
1106 if (getType() == SkAdvancedTypefaceMetrics::kType1CID_Font) { 1091 if (getType() == SkAdvancedTypefaceMetrics::kType1CID_Font) {
1107 insertName("Subtype", "CIDFontType0"); 1092 insertName("Subtype", "CIDFontType0");
1108 } else if (getType() == SkAdvancedTypefaceMetrics::kTrueType_Font) { 1093 } else if (getType() == SkAdvancedTypefaceMetrics::kTrueType_Font) {
1109 insertName("Subtype", "CIDFontType2"); 1094 insertName("Subtype", "CIDFontType2");
1110 insertName("CIDToGIDMap", "Identity"); 1095 insertName("CIDToGIDMap", "Identity");
1111 } else { 1096 } else {
1112 SkASSERT(false); 1097 SkASSERT(false);
1113 } 1098 }
1114 1099
1115 auto sysInfo = sk_make_sp<SkPDFDict>(); 1100 auto sysInfo = sk_make_sp<SkPDFDict>();
1116 sysInfo->insertString("Registry", "Adobe"); 1101 sysInfo->insertString("Registry", "Adobe");
1117 sysInfo->insertString("Ordering", "Identity"); 1102 sysInfo->insertString("Ordering", "Identity");
1118 sysInfo->insertInt("Supplement", 0); 1103 sysInfo->insertInt("Supplement", 0);
1119 this->insertObject("CIDSystemInfo", std::move(sysInfo)); 1104 this->insertObject("CIDSystemInfo", std::move(sysInfo));
1120 1105
1121 if (!fontInfo()->fGlyphWidths.empty()) { 1106 SkAdvancedTypefaceMetrics tmpMetrics;
1122 int16_t defaultWidth = 0; 1107 set_glyph_widths(this->typeface(), &glyphIDs, &tmpMetrics);
1123 sk_sp<SkPDFArray> widths(composeAdvanceData( 1108 int16_t defaultWidth = 0;
1124 fontInfo()->fGlyphWidths, fontInfo()->fEmSize, &appendWidth, 1109 uint16_t emSize = (uint16_t)this->fontInfo()->fEmSize;
1125 &defaultWidth)); 1110 sk_sp<SkPDFArray> widths = composeAdvanceData(
1126 if (widths->size()) { 1111 tmpMetrics.fGlyphWidths, emSize, &defaultWidth);
1127 this->insertObject("W", std::move(widths)); 1112 if (widths->size()) {
1128 } 1113 this->insertObject("W", std::move(widths));
1129 this->insertScalar(
1130 "DW", scaleFromFontUnits(defaultWidth, fontInfo()->fEmSize));
1131 }
1132 if (!fontInfo()->fVerticalMetrics.empty()) {
1133 struct SkAdvancedTypefaceMetrics::VerticalMetric defaultAdvance;
1134 defaultAdvance.fVerticalAdvance = 0;
1135 defaultAdvance.fOriginXDisp = 0;
1136 defaultAdvance.fOriginYDisp = 0;
1137 sk_sp<SkPDFArray> advances(composeAdvanceData(
1138 fontInfo()->fVerticalMetrics, fontInfo()->fEmSize,
1139 &appendVerticalAdvance, &defaultAdvance));
1140 if (advances->size())
1141 this->insertObject("W2", std::move(advances));
1142 if (defaultAdvance.fVerticalAdvance ||
1143 defaultAdvance.fOriginXDisp ||
1144 defaultAdvance.fOriginYDisp) {
1145 auto array = sk_make_sp<SkPDFArray>();
1146 appendVerticalAdvance(defaultAdvance,
1147 fontInfo()->fEmSize,
1148 array.get());
1149 this->insertObject("DW2", std::move(array));
1150 }
1151 } 1114 }
1152 1115
1116 this->insertScalar(
1117 "DW", scaleFromFontUnits(defaultWidth, emSize));
1153 return true; 1118 return true;
1154 } 1119 }
1155 1120
1156 /////////////////////////////////////////////////////////////////////////////// 1121 ///////////////////////////////////////////////////////////////////////////////
1157 // class SkPDFType1Font 1122 // class SkPDFType1Font
1158 /////////////////////////////////////////////////////////////////////////////// 1123 ///////////////////////////////////////////////////////////////////////////////
1159 1124
1160 SkPDFType1Font::SkPDFType1Font(const SkAdvancedTypefaceMetrics* info, 1125 SkPDFType1Font::SkPDFType1Font(const SkAdvancedTypefaceMetrics* info,
1161 SkTypeface* typeface, 1126 SkTypeface* typeface,
1162 uint16_t glyphID, 1127 uint16_t glyphID,
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
1198 fontStream->dict()->insertInt("Length3", trailer); 1163 fontStream->dict()->insertInt("Length3", trailer);
1199 descriptor->insertObjRef("FontFile", std::move(fontStream)); 1164 descriptor->insertObjRef("FontFile", std::move(fontStream));
1200 1165
1201 this->insertObjRef("FontDescriptor", std::move(descriptor)); 1166 this->insertObjRef("FontDescriptor", std::move(descriptor));
1202 1167
1203 return addCommonFontDescriptorEntries(defaultWidth); 1168 return addCommonFontDescriptorEntries(defaultWidth);
1204 } 1169 }
1205 1170
1206 bool SkPDFType1Font::populate(int16_t glyphID) { 1171 bool SkPDFType1Font::populate(int16_t glyphID) {
1207 SkASSERT(fontInfo()->fVerticalMetrics.empty()); 1172 SkASSERT(fontInfo()->fVerticalMetrics.empty());
1208 SkASSERT(!fontInfo()->fGlyphWidths.empty()); 1173 SkASSERT(fontInfo()->fGlyphWidths.empty());
1209 1174
1210 adjustGlyphRangeForSingleByteEncoding(glyphID); 1175 adjustGlyphRangeForSingleByteEncoding(glyphID);
1211 1176
1212 int16_t defaultWidth = 0; 1177 int16_t defaultWidth = 0;
1213 const SkAdvancedTypefaceMetrics::WidthRange* widthRangeEntry = nullptr; 1178 const SkAdvancedTypefaceMetrics::WidthRange* widthRangeEntry = nullptr;
1214 for (const auto& widthEntry : fontInfo()->fGlyphWidths) { 1179 {
1215 switch (widthEntry.fType) { 1180 SkAdvancedTypefaceMetrics tmpMetrics;
1216 case SkAdvancedTypefaceMetrics::WidthRange::kDefault: 1181 set_glyph_widths(this->typeface(), nullptr, &tmpMetrics);
1217 defaultWidth = widthEntry.fAdvance[0]; 1182 for (const auto& widthEntry : tmpMetrics.fGlyphWidths) {
1218 break; 1183 switch (widthEntry.fType) {
1219 case SkAdvancedTypefaceMetrics::WidthRange::kRun: 1184 case SkAdvancedTypefaceMetrics::WidthRange::kDefault:
1220 SkASSERT(false); 1185 defaultWidth = widthEntry.fAdvance[0];
1221 break; 1186 break;
1222 case SkAdvancedTypefaceMetrics::WidthRange::kRange: 1187 case SkAdvancedTypefaceMetrics::WidthRange::kRun:
1223 SkASSERT(widthRangeEntry == nullptr); 1188 SkASSERT(false);
1224 widthRangeEntry = &widthEntry; 1189 break;
1225 break; 1190 case SkAdvancedTypefaceMetrics::WidthRange::kRange:
1191 SkASSERT(widthRangeEntry == nullptr);
1192 widthRangeEntry = &widthEntry;
1193 break;
1194 }
1226 } 1195 }
1227 } 1196 }
1228 1197
1229 if (!addFontDescriptor(defaultWidth)) { 1198 if (!addFontDescriptor(defaultWidth)) {
1230 return false; 1199 return false;
1231 } 1200 }
1232 1201
1233 insertName("Subtype", "Type1"); 1202 insertName("Subtype", "Type1");
1234 insertName("BaseFont", fontInfo()->fFontName); 1203 insertName("BaseFont", fontInfo()->fFontName);
1235 1204
1236 addWidthInfoFromRange(defaultWidth, widthRangeEntry); 1205 addWidthInfoFromRange(defaultWidth, widthRangeEntry);
1237
1238
1239 auto encDiffs = sk_make_sp<SkPDFArray>(); 1206 auto encDiffs = sk_make_sp<SkPDFArray>();
1240 encDiffs->reserve(lastGlyphID() - firstGlyphID() + 2); 1207 encDiffs->reserve(lastGlyphID() - firstGlyphID() + 2);
1241 encDiffs->appendInt(1); 1208 encDiffs->appendInt(1);
1242 for (int gID = firstGlyphID(); gID <= lastGlyphID(); gID++) { 1209 for (int gID = firstGlyphID(); gID <= lastGlyphID(); gID++) {
1243 encDiffs->appendName(fontInfo()->fGlyphNames->get()[gID].c_str()); 1210 encDiffs->appendName(fontInfo()->fGlyphNames->get()[gID].c_str());
1244 } 1211 }
1245 1212
1246 auto encoding = sk_make_sp<SkPDFDict>("Encoding"); 1213 auto encoding = sk_make_sp<SkPDFDict>("Encoding");
1247 encoding->insertObject("Differences", std::move(encDiffs)); 1214 encoding->insertObject("Differences", std::move(encDiffs));
1248 this->insertObject("Encoding", std::move(encoding)); 1215 this->insertObject("Encoding", std::move(encoding));
1249 return true; 1216 return true;
1250 } 1217 }
1251 1218
1252 void SkPDFType1Font::addWidthInfoFromRange( 1219 void SkPDFType1Font::addWidthInfoFromRange(
1253 int16_t defaultWidth, 1220 int16_t defaultWidth,
1254 const SkAdvancedTypefaceMetrics::WidthRange* widthRangeEntry) { 1221 const SkAdvancedTypefaceMetrics::WidthRange* widthRangeEntry) {
1255 auto widthArray = sk_make_sp<SkPDFArray>(); 1222 auto widthArray = sk_make_sp<SkPDFArray>();
1256 int firstChar = 0; 1223 int firstChar = 0;
1257 if (widthRangeEntry) { 1224 if (widthRangeEntry) {
1258 const uint16_t emSize = fontInfo()->fEmSize; 1225 const uint16_t emSize = fontInfo()->fEmSize;
1259 int startIndex = firstGlyphID() - widthRangeEntry->fStartId; 1226 int startIndex = firstGlyphID() - widthRangeEntry->fStartId;
1260 int endIndex = startIndex + lastGlyphID() - firstGlyphID() + 1; 1227 int endIndex = startIndex + lastGlyphID() - firstGlyphID() + 1;
1261 if (startIndex < 0) 1228 if (startIndex < 0)
1262 startIndex = 0; 1229 startIndex = 0;
1263 if (endIndex > widthRangeEntry->fAdvance.count()) 1230 if (endIndex > widthRangeEntry->fAdvance.count())
1264 endIndex = widthRangeEntry->fAdvance.count(); 1231 endIndex = widthRangeEntry->fAdvance.count();
1265 if (widthRangeEntry->fStartId == 0) { 1232 if (widthRangeEntry->fStartId == 0) {
1266 appendWidth(widthRangeEntry->fAdvance[0], emSize, widthArray.get()); 1233 widthArray->appendScalar(
1234 scaleFromFontUnits(widthRangeEntry->fAdvance[0], emSize));
1267 } else { 1235 } else {
1268 firstChar = startIndex + widthRangeEntry->fStartId; 1236 firstChar = startIndex + widthRangeEntry->fStartId;
1269 } 1237 }
1270 for (int i = startIndex; i < endIndex; i++) { 1238 for (int i = startIndex; i < endIndex; i++) {
1271 appendWidth(widthRangeEntry->fAdvance[i], emSize, widthArray.get()); 1239 widthArray->appendScalar(
1240 scaleFromFontUnits(widthRangeEntry->fAdvance[i], emSize));
1272 } 1241 }
1273 } else { 1242 } else {
1274 appendWidth(defaultWidth, 1000, widthArray.get()); 1243 widthArray->appendScalar(
1244 scaleFromFontUnits(defaultWidth, 1000));
1275 } 1245 }
1276 this->insertInt("FirstChar", firstChar); 1246 this->insertInt("FirstChar", firstChar);
1277 this->insertInt("LastChar", firstChar + widthArray->size() - 1); 1247 this->insertInt("LastChar", firstChar + widthArray->size() - 1);
1278 this->insertObject("Widths", std::move(widthArray)); 1248 this->insertObject("Widths", std::move(widthArray));
1279 } 1249 }
1280 1250
1281 /////////////////////////////////////////////////////////////////////////////// 1251 ///////////////////////////////////////////////////////////////////////////////
1282 // class SkPDFType3Font 1252 // class SkPDFType3Font
1283 /////////////////////////////////////////////////////////////////////////////// 1253 ///////////////////////////////////////////////////////////////////////////////
1284 1254
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
1400 } 1370 }
1401 return *canon->fCanEmbedTypeface.set(id, canEmbed); 1371 return *canon->fCanEmbedTypeface.set(id, canEmbed);
1402 } 1372 }
1403 1373
1404 void SkPDFFont::drop() { 1374 void SkPDFFont::drop() {
1405 fTypeface = nullptr; 1375 fTypeface = nullptr;
1406 fFontInfo = nullptr; 1376 fFontInfo = nullptr;
1407 fDescriptor = nullptr; 1377 fDescriptor = nullptr;
1408 this->SkPDFDict::drop(); 1378 this->SkPDFDict::drop();
1409 } 1379 }
OLDNEW
« no previous file with comments | « src/pdf/SkPDFDevice.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698