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

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

Issue 1110533002: SkPDF: clean up uses of deprecated calls in SkPDFFont (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: detach Created 5 years, 7 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 | « no previous file | 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 326 matching lines...) Expand 10 before | Expand all | Expand 10 after
337 SkASSERT(advanceInfo->fAdvance.count() == 1); 337 SkASSERT(advanceInfo->fAdvance.count() == 1);
338 *defaultAdvance = advanceInfo->fAdvance[0]; 338 *defaultAdvance = advanceInfo->fAdvance[0];
339 break; 339 break;
340 } 340 }
341 case SkAdvancedTypefaceMetrics::WidthRange::kRange: { 341 case SkAdvancedTypefaceMetrics::WidthRange::kRange: {
342 SkAutoTUnref<SkPDFArray> advanceArray(new SkPDFArray()); 342 SkAutoTUnref<SkPDFArray> advanceArray(new SkPDFArray());
343 for (int j = 0; j < advanceInfo->fAdvance.count(); j++) 343 for (int j = 0; j < advanceInfo->fAdvance.count(); j++)
344 appendAdvance(advanceInfo->fAdvance[j], emSize, 344 appendAdvance(advanceInfo->fAdvance[j], emSize,
345 advanceArray.get()); 345 advanceArray.get());
346 result->appendInt(advanceInfo->fStartId); 346 result->appendInt(advanceInfo->fStartId);
347 result->append(advanceArray.get()); 347 result->appendObject(advanceArray.detach());
348 break; 348 break;
349 } 349 }
350 case SkAdvancedTypefaceMetrics::WidthRange::kRun: { 350 case SkAdvancedTypefaceMetrics::WidthRange::kRun: {
351 SkASSERT(advanceInfo->fAdvance.count() == 1); 351 SkASSERT(advanceInfo->fAdvance.count() == 1);
352 result->appendInt(advanceInfo->fStartId); 352 result->appendInt(advanceInfo->fStartId);
353 result->appendInt(advanceInfo->fEndId); 353 result->appendInt(advanceInfo->fEndId);
354 appendAdvance(advanceInfo->fAdvance[0], emSize, result); 354 appendAdvance(advanceInfo->fAdvance[0], emSize, result);
355 break; 355 break;
356 } 356 }
357 } 357 }
(...skipping 595 matching lines...) Expand 10 before | Expand all | Expand 10 after
953 fDescriptor->insertScalar("Ascent", 953 fDescriptor->insertScalar("Ascent",
954 scaleFromFontUnits(fFontInfo->fAscent, emSize)); 954 scaleFromFontUnits(fFontInfo->fAscent, emSize));
955 fDescriptor->insertScalar("Descent", 955 fDescriptor->insertScalar("Descent",
956 scaleFromFontUnits(fFontInfo->fDescent, emSize)); 956 scaleFromFontUnits(fFontInfo->fDescent, emSize));
957 fDescriptor->insertScalar("StemV", 957 fDescriptor->insertScalar("StemV",
958 scaleFromFontUnits(fFontInfo->fStemV, emSize)); 958 scaleFromFontUnits(fFontInfo->fStemV, emSize));
959 959
960 fDescriptor->insertScalar("CapHeight", 960 fDescriptor->insertScalar("CapHeight",
961 scaleFromFontUnits(fFontInfo->fCapHeight, emSize)); 961 scaleFromFontUnits(fFontInfo->fCapHeight, emSize));
962 fDescriptor->insertInt("ItalicAngle", fFontInfo->fItalicAngle); 962 fDescriptor->insertInt("ItalicAngle", fFontInfo->fItalicAngle);
963 fDescriptor->insert("FontBBox", makeFontBBox(fFontInfo->fBBox, 963 fDescriptor->insertObject(
964 fFontInfo->fEmSize))->unref(); 964 "FontBBox", makeFontBBox(fFontInfo->fBBox, fFontInfo->fEmSize));
965 965
966 if (defaultWidth > 0) { 966 if (defaultWidth > 0) {
967 fDescriptor->insertScalar("MissingWidth", 967 fDescriptor->insertScalar("MissingWidth",
968 scaleFromFontUnits(defaultWidth, emSize)); 968 scaleFromFontUnits(defaultWidth, emSize));
969 } 969 }
970 return true; 970 return true;
971 } 971 }
972 972
973 void SkPDFFont::adjustGlyphRangeForSingleByteEncoding(uint16_t glyphID) { 973 void SkPDFFont::adjustGlyphRangeForSingleByteEncoding(uint16_t glyphID) {
974 // Single byte glyph encoding supports a max of 255 glyphs. 974 // Single byte glyph encoding supports a max of 255 glyphs.
975 fFirstGlyphID = glyphID - (glyphID - 1) % 255; 975 fFirstGlyphID = glyphID - (glyphID - 1) % 255;
976 if (fLastGlyphID > fFirstGlyphID + 255 - 1) { 976 if (fLastGlyphID > fFirstGlyphID + 255 - 1) {
977 fLastGlyphID = fFirstGlyphID + 255 - 1; 977 fLastGlyphID = fFirstGlyphID + 255 - 1;
978 } 978 }
979 } 979 }
980 980
981 void SkPDFFont::populateToUnicodeTable(const SkPDFGlyphSet* subset) { 981 void SkPDFFont::populateToUnicodeTable(const SkPDFGlyphSet* subset) {
982 if (fFontInfo == NULL || fFontInfo->fGlyphToUnicode.begin() == NULL) { 982 if (fFontInfo == NULL || fFontInfo->fGlyphToUnicode.begin() == NULL) {
983 return; 983 return;
984 } 984 }
985 SkAutoTUnref<SkPDFStream> pdfCmap( 985 this->insertObjRef("ToUnicode",
986 generate_tounicode_cmap(fFontInfo->fGlyphToUnicode, subset, 986 generate_tounicode_cmap(fFontInfo->fGlyphToUnicode,
987 multiByteGlyphs(), firstGlyphID(), 987 subset,
988 lastGlyphID())); 988 multiByteGlyphs(),
989 insert("ToUnicode", new SkPDFObjRef(pdfCmap.get()))->unref(); 989 firstGlyphID(),
990 lastGlyphID()));
990 } 991 }
991 992
992 /////////////////////////////////////////////////////////////////////////////// 993 ///////////////////////////////////////////////////////////////////////////////
993 // class SkPDFType0Font 994 // class SkPDFType0Font
994 /////////////////////////////////////////////////////////////////////////////// 995 ///////////////////////////////////////////////////////////////////////////////
995 996
996 SkPDFType0Font::SkPDFType0Font(const SkAdvancedTypefaceMetrics* info, 997 SkPDFType0Font::SkPDFType0Font(const SkAdvancedTypefaceMetrics* info,
997 SkTypeface* typeface) 998 SkTypeface* typeface)
998 : SkPDFFont(info, typeface, NULL) { 999 : SkPDFFont(info, typeface, NULL) {
999 SkDEBUGCODE(fPopulated = false); 1000 SkDEBUGCODE(fPopulated = false);
(...skipping 24 matching lines...) Expand all
1024 #endif 1025 #endif
1025 1026
1026 bool SkPDFType0Font::populate(const SkPDFGlyphSet* subset) { 1027 bool SkPDFType0Font::populate(const SkPDFGlyphSet* subset) {
1027 insertName("Subtype", "Type0"); 1028 insertName("Subtype", "Type0");
1028 insertName("BaseFont", fontInfo()->fFontName); 1029 insertName("BaseFont", fontInfo()->fFontName);
1029 insertName("Encoding", "Identity-H"); 1030 insertName("Encoding", "Identity-H");
1030 1031
1031 SkAutoTUnref<SkPDFCIDFont> newCIDFont( 1032 SkAutoTUnref<SkPDFCIDFont> newCIDFont(
1032 new SkPDFCIDFont(fontInfo(), typeface(), subset)); 1033 new SkPDFCIDFont(fontInfo(), typeface(), subset));
1033 SkAutoTUnref<SkPDFArray> descendantFonts(new SkPDFArray()); 1034 SkAutoTUnref<SkPDFArray> descendantFonts(new SkPDFArray());
1034 descendantFonts->append(new SkPDFObjRef(newCIDFont.get()))->unref(); 1035 descendantFonts->appendObjRef(newCIDFont.detach());
1035 insert("DescendantFonts", descendantFonts.get()); 1036 this->insertObject("DescendantFonts", descendantFonts.detach());
1036 1037
1037 populateToUnicodeTable(subset); 1038 populateToUnicodeTable(subset);
1038 1039
1039 SkDEBUGCODE(fPopulated = true); 1040 SkDEBUGCODE(fPopulated = true);
1040 return true; 1041 return true;
1041 } 1042 }
1042 1043
1043 /////////////////////////////////////////////////////////////////////////////// 1044 ///////////////////////////////////////////////////////////////////////////////
1044 // class SkPDFCIDFont 1045 // class SkPDFCIDFont
1045 /////////////////////////////////////////////////////////////////////////////// 1046 ///////////////////////////////////////////////////////////////////////////////
1046 1047
1047 SkPDFCIDFont::SkPDFCIDFont(const SkAdvancedTypefaceMetrics* info, 1048 SkPDFCIDFont::SkPDFCIDFont(const SkAdvancedTypefaceMetrics* info,
1048 SkTypeface* typeface, 1049 SkTypeface* typeface,
1049 const SkPDFGlyphSet* subset) 1050 const SkPDFGlyphSet* subset)
1050 : SkPDFFont(info, typeface, NULL) { 1051 : SkPDFFont(info, typeface, NULL) {
1051 populate(subset); 1052 populate(subset);
1052 } 1053 }
1053 1054
1054 SkPDFCIDFont::~SkPDFCIDFont() {} 1055 SkPDFCIDFont::~SkPDFCIDFont() {}
1055 1056
1056 bool SkPDFCIDFont::addFontDescriptor(int16_t defaultWidth, 1057 bool SkPDFCIDFont::addFontDescriptor(int16_t defaultWidth,
1057 const SkTDArray<uint32_t>* subset) { 1058 const SkTDArray<uint32_t>* subset) {
1058 SkAutoTUnref<SkPDFDict> descriptor(new SkPDFDict("FontDescriptor")); 1059 SkAutoTUnref<SkPDFDict> descriptor(new SkPDFDict("FontDescriptor"));
1059 setFontDescriptor(descriptor.get()); 1060 setFontDescriptor(descriptor.get());
1060 insert("FontDescriptor", new SkPDFObjRef(descriptor.get()))->unref();
1061 if (!addCommonFontDescriptorEntries(defaultWidth)) { 1061 if (!addCommonFontDescriptorEntries(defaultWidth)) {
1062 this->insertObjRef("FontDescriptor", descriptor.detach());
1062 return false; 1063 return false;
1063 } 1064 }
1064 if (!canEmbed()) { 1065 if (!canEmbed()) {
1066 this->insertObjRef("FontDescriptor", descriptor.detach());
1065 return true; 1067 return true;
1066 } 1068 }
1067 1069
1068 switch (getType()) { 1070 switch (getType()) {
1069 case SkAdvancedTypefaceMetrics::kTrueType_Font: { 1071 case SkAdvancedTypefaceMetrics::kTrueType_Font: {
1070 SkAutoTUnref<SkPDFStream> fontStream; 1072 SkAutoTUnref<SkPDFStream> fontStream;
1071 size_t fontSize = 0; 1073 size_t fontSize = 0;
1072 if (canSubset()) { 1074 if (canSubset()) {
1073 SkPDFStream* rawStream = NULL; 1075 SkPDFStream* rawStream = NULL;
1074 fontSize = get_subset_font_stream(fontInfo()->fFontName.c_str(), 1076 fontSize = get_subset_font_stream(fontInfo()->fFontName.c_str(),
1075 typeface(), 1077 typeface(),
1076 *subset, 1078 *subset,
1077 &rawStream); 1079 &rawStream);
1078 fontStream.reset(rawStream); 1080 fontStream.reset(rawStream);
1079 } else { 1081 } else {
1080 int ttcIndex; 1082 int ttcIndex;
1081 SkAutoTDelete<SkStream> fontData( 1083 SkAutoTDelete<SkStream> fontData(
1082 typeface()->openStream(&ttcIndex)); 1084 typeface()->openStream(&ttcIndex));
1083 fontStream.reset(new SkPDFStream(fontData.get())); 1085 fontStream.reset(new SkPDFStream(fontData.get()));
1084 fontSize = fontData->getLength(); 1086 fontSize = fontData->getLength();
1085 } 1087 }
1086 SkASSERT(fontSize); 1088 SkASSERT(fontSize);
1087 SkASSERT(fontStream.get()); 1089 SkASSERT(fontStream.get());
1088 1090
1089 fontStream->insertInt("Length1", fontSize); 1091 fontStream->insertInt("Length1", fontSize);
1090 descriptor->insert("FontFile2", 1092 descriptor->insertObjRef("FontFile2", fontStream.detach());
1091 new SkPDFObjRef(fontStream.get()))->unref();
1092 break; 1093 break;
1093 } 1094 }
1094 case SkAdvancedTypefaceMetrics::kCFF_Font: 1095 case SkAdvancedTypefaceMetrics::kCFF_Font:
1095 case SkAdvancedTypefaceMetrics::kType1CID_Font: { 1096 case SkAdvancedTypefaceMetrics::kType1CID_Font: {
1096 int ttcIndex; 1097 int ttcIndex;
1097 SkAutoTDelete<SkStream> fontData(typeface()->openStream(&ttcIndex)); 1098 SkAutoTDelete<SkStream> fontData(typeface()->openStream(&ttcIndex));
1098 SkAutoTUnref<SkPDFStream> fontStream( 1099 SkAutoTUnref<SkPDFStream> fontStream(
1099 new SkPDFStream(fontData.get())); 1100 new SkPDFStream(fontData.get()));
1100 1101
1101 if (getType() == SkAdvancedTypefaceMetrics::kCFF_Font) { 1102 if (getType() == SkAdvancedTypefaceMetrics::kCFF_Font) {
1102 fontStream->insertName("Subtype", "Type1C"); 1103 fontStream->insertName("Subtype", "Type1C");
1103 } else { 1104 } else {
1104 fontStream->insertName("Subtype", "CIDFontType0c"); 1105 fontStream->insertName("Subtype", "CIDFontType0c");
1105 } 1106 }
1106 descriptor->insert("FontFile3", 1107 descriptor->insertObjRef("FontFile3", fontStream.detach());
1107 new SkPDFObjRef(fontStream.get()))->unref();
1108 break; 1108 break;
1109 } 1109 }
1110 default: 1110 default:
1111 SkASSERT(false); 1111 SkASSERT(false);
1112 } 1112 }
1113 this->insertObjRef("FontDescriptor", descriptor.detach());
1113 return true; 1114 return true;
1114 } 1115 }
1115 1116
1116 bool SkPDFCIDFont::populate(const SkPDFGlyphSet* subset) { 1117 bool SkPDFCIDFont::populate(const SkPDFGlyphSet* subset) {
1117 // Generate new font metrics with advance info for true type fonts. 1118 // Generate new font metrics with advance info for true type fonts.
1118 if (fontInfo()->fType == SkAdvancedTypefaceMetrics::kTrueType_Font) { 1119 if (fontInfo()->fType == SkAdvancedTypefaceMetrics::kTrueType_Font) {
1119 // Generate glyph id array. 1120 // Generate glyph id array.
1120 SkTDArray<uint32_t> glyphIDs; 1121 SkTDArray<uint32_t> glyphIDs;
1121 if (subset) { 1122 if (subset) {
1122 // Always include glyph 0. 1123 // Always include glyph 0.
(...skipping 23 matching lines...) Expand all
1146 if (getType() == SkAdvancedTypefaceMetrics::kType1CID_Font) { 1147 if (getType() == SkAdvancedTypefaceMetrics::kType1CID_Font) {
1147 insertName("Subtype", "CIDFontType0"); 1148 insertName("Subtype", "CIDFontType0");
1148 } else if (getType() == SkAdvancedTypefaceMetrics::kTrueType_Font) { 1149 } else if (getType() == SkAdvancedTypefaceMetrics::kTrueType_Font) {
1149 insertName("Subtype", "CIDFontType2"); 1150 insertName("Subtype", "CIDFontType2");
1150 insertName("CIDToGIDMap", "Identity"); 1151 insertName("CIDToGIDMap", "Identity");
1151 } else { 1152 } else {
1152 SkASSERT(false); 1153 SkASSERT(false);
1153 } 1154 }
1154 1155
1155 SkAutoTUnref<SkPDFDict> sysInfo(new SkPDFDict); 1156 SkAutoTUnref<SkPDFDict> sysInfo(new SkPDFDict);
1156 sysInfo->insert("Registry", new SkPDFString("Adobe"))->unref(); 1157 sysInfo->insertString("Registry", "Adobe");
1157 sysInfo->insert("Ordering", new SkPDFString("Identity"))->unref(); 1158 sysInfo->insertString("Ordering", "Identity");
1158 sysInfo->insertInt("Supplement", 0); 1159 sysInfo->insertInt("Supplement", 0);
1159 insert("CIDSystemInfo", sysInfo.get()); 1160 this->insertObject("CIDSystemInfo", sysInfo.detach());
1160 1161
1161 if (fontInfo()->fGlyphWidths.get()) { 1162 if (fontInfo()->fGlyphWidths.get()) {
1162 int16_t defaultWidth = 0; 1163 int16_t defaultWidth = 0;
1163 SkAutoTUnref<SkPDFArray> widths( 1164 SkAutoTUnref<SkPDFArray> widths(
1164 composeAdvanceData(fontInfo()->fGlyphWidths.get(), 1165 composeAdvanceData(fontInfo()->fGlyphWidths.get(),
1165 fontInfo()->fEmSize, &appendWidth, 1166 fontInfo()->fEmSize, &appendWidth,
1166 &defaultWidth)); 1167 &defaultWidth));
1167 if (widths->size()) 1168 if (widths->size())
1168 insert("W", widths.get()); 1169 this->insertObject("W", widths.detach());
1169 if (defaultWidth != 0) { 1170 if (defaultWidth != 0) {
1170 insertScalar("DW", scaleFromFontUnits(defaultWidth, 1171 this->insertScalar(
1171 fontInfo()->fEmSize)); 1172 "DW",
1173 scaleFromFontUnits(defaultWidth, fontInfo()->fEmSize));
1172 } 1174 }
1173 } 1175 }
1174 if (fontInfo()->fVerticalMetrics.get()) { 1176 if (fontInfo()->fVerticalMetrics.get()) {
1175 struct SkAdvancedTypefaceMetrics::VerticalMetric defaultAdvance; 1177 struct SkAdvancedTypefaceMetrics::VerticalMetric defaultAdvance;
1176 defaultAdvance.fVerticalAdvance = 0; 1178 defaultAdvance.fVerticalAdvance = 0;
1177 defaultAdvance.fOriginXDisp = 0; 1179 defaultAdvance.fOriginXDisp = 0;
1178 defaultAdvance.fOriginYDisp = 0; 1180 defaultAdvance.fOriginYDisp = 0;
1179 SkAutoTUnref<SkPDFArray> advances( 1181 SkAutoTUnref<SkPDFArray> advances(
1180 composeAdvanceData(fontInfo()->fVerticalMetrics.get(), 1182 composeAdvanceData(fontInfo()->fVerticalMetrics.get(),
1181 fontInfo()->fEmSize, &appendVerticalAdvance, 1183 fontInfo()->fEmSize, &appendVerticalAdvance,
1182 &defaultAdvance)); 1184 &defaultAdvance));
1183 if (advances->size()) 1185 if (advances->size())
1184 insert("W2", advances.get()); 1186 this->insertObject("W2", advances.detach());
1185 if (defaultAdvance.fVerticalAdvance || 1187 if (defaultAdvance.fVerticalAdvance ||
1186 defaultAdvance.fOriginXDisp || 1188 defaultAdvance.fOriginXDisp ||
1187 defaultAdvance.fOriginYDisp) { 1189 defaultAdvance.fOriginYDisp) {
1188 insert("DW2", appendVerticalAdvance(defaultAdvance, 1190 this->insertObject("DW2",
1189 fontInfo()->fEmSize, 1191 appendVerticalAdvance(defaultAdvance,
1190 new SkPDFArray))->unref(); 1192 fontInfo()->fEmSize,
1193 new SkPDFArray));
1191 } 1194 }
1192 } 1195 }
1193 1196
1194 return true; 1197 return true;
1195 } 1198 }
1196 1199
1197 /////////////////////////////////////////////////////////////////////////////// 1200 ///////////////////////////////////////////////////////////////////////////////
1198 // class SkPDFType1Font 1201 // class SkPDFType1Font
1199 /////////////////////////////////////////////////////////////////////////////// 1202 ///////////////////////////////////////////////////////////////////////////////
1200 1203
1201 SkPDFType1Font::SkPDFType1Font(const SkAdvancedTypefaceMetrics* info, 1204 SkPDFType1Font::SkPDFType1Font(const SkAdvancedTypefaceMetrics* info,
1202 SkTypeface* typeface, 1205 SkTypeface* typeface,
1203 uint16_t glyphID, 1206 uint16_t glyphID,
1204 SkPDFDict* relatedFontDescriptor) 1207 SkPDFDict* relatedFontDescriptor)
1205 : SkPDFFont(info, typeface, relatedFontDescriptor) { 1208 : SkPDFFont(info, typeface, relatedFontDescriptor) {
1206 populate(glyphID); 1209 populate(glyphID);
1207 } 1210 }
1208 1211
1209 SkPDFType1Font::~SkPDFType1Font() {} 1212 SkPDFType1Font::~SkPDFType1Font() {}
1210 1213
1211 bool SkPDFType1Font::addFontDescriptor(int16_t defaultWidth) { 1214 bool SkPDFType1Font::addFontDescriptor(int16_t defaultWidth) {
1212 if (getFontDescriptor() != NULL) { 1215 if (SkPDFDict* descriptor = getFontDescriptor()) {
1213 SkPDFDict* descriptor = getFontDescriptor(); 1216 this->insertObjRef("FontDescriptor", SkRef(descriptor));
1214 insert("FontDescriptor", new SkPDFObjRef(descriptor))->unref();
1215 return true; 1217 return true;
1216 } 1218 }
1217 1219
1218 SkAutoTUnref<SkPDFDict> descriptor(new SkPDFDict("FontDescriptor")); 1220 SkAutoTUnref<SkPDFDict> descriptor(new SkPDFDict("FontDescriptor"));
1219 setFontDescriptor(descriptor.get()); 1221 setFontDescriptor(descriptor.get());
1220 1222
1221 int ttcIndex; 1223 int ttcIndex;
1222 size_t header SK_INIT_TO_AVOID_WARNING; 1224 size_t header SK_INIT_TO_AVOID_WARNING;
1223 size_t data SK_INIT_TO_AVOID_WARNING; 1225 size_t data SK_INIT_TO_AVOID_WARNING;
1224 size_t trailer SK_INIT_TO_AVOID_WARNING; 1226 size_t trailer SK_INIT_TO_AVOID_WARNING;
1225 SkAutoTDelete<SkStream> rawFontData(typeface()->openStream(&ttcIndex)); 1227 SkAutoTDelete<SkStream> rawFontData(typeface()->openStream(&ttcIndex));
1226 SkAutoTUnref<SkData> fontData(handle_type1_stream(rawFontData.get(), &header , 1228 SkAutoTUnref<SkData> fontData(handle_type1_stream(rawFontData.get(), &header ,
1227 &data, &trailer)); 1229 &data, &trailer));
1228 if (fontData.get() == NULL) { 1230 if (fontData.get() == NULL) {
1229 return false; 1231 return false;
1230 } 1232 }
1231 if (canEmbed()) { 1233 if (canEmbed()) {
1232 SkAutoTUnref<SkPDFStream> fontStream(new SkPDFStream(fontData.get())); 1234 SkAutoTUnref<SkPDFStream> fontStream(new SkPDFStream(fontData.get()));
1233 fontStream->insertInt("Length1", header); 1235 fontStream->insertInt("Length1", header);
1234 fontStream->insertInt("Length2", data); 1236 fontStream->insertInt("Length2", data);
1235 fontStream->insertInt("Length3", trailer); 1237 fontStream->insertInt("Length3", trailer);
1236 descriptor->insert("FontFile", 1238 descriptor->insertObjRef("FontFile", fontStream.detach());
1237 new SkPDFObjRef(fontStream.get()))->unref();
1238 } 1239 }
1239 1240
1240 insert("FontDescriptor", new SkPDFObjRef(descriptor.get()))->unref(); 1241 this->insertObjRef("FontDescriptor", descriptor.detach());
1241 1242
1242 return addCommonFontDescriptorEntries(defaultWidth); 1243 return addCommonFontDescriptorEntries(defaultWidth);
1243 } 1244 }
1244 1245
1245 bool SkPDFType1Font::populate(int16_t glyphID) { 1246 bool SkPDFType1Font::populate(int16_t glyphID) {
1246 SkASSERT(!fontInfo()->fVerticalMetrics.get()); 1247 SkASSERT(!fontInfo()->fVerticalMetrics.get());
1247 SkASSERT(fontInfo()->fGlyphWidths.get()); 1248 SkASSERT(fontInfo()->fGlyphWidths.get());
1248 1249
1249 adjustGlyphRangeForSingleByteEncoding(glyphID); 1250 adjustGlyphRangeForSingleByteEncoding(glyphID);
1250 1251
(...skipping 19 matching lines...) Expand all
1270 1271
1271 if (!addFontDescriptor(defaultWidth)) { 1272 if (!addFontDescriptor(defaultWidth)) {
1272 return false; 1273 return false;
1273 } 1274 }
1274 1275
1275 insertName("Subtype", "Type1"); 1276 insertName("Subtype", "Type1");
1276 insertName("BaseFont", fontInfo()->fFontName); 1277 insertName("BaseFont", fontInfo()->fFontName);
1277 1278
1278 addWidthInfoFromRange(defaultWidth, widthRangeEntry); 1279 addWidthInfoFromRange(defaultWidth, widthRangeEntry);
1279 1280
1280 SkAutoTUnref<SkPDFDict> encoding(new SkPDFDict("Encoding"));
1281 insert("Encoding", encoding.get());
1282 1281
1283 SkAutoTUnref<SkPDFArray> encDiffs(new SkPDFArray); 1282 SkAutoTUnref<SkPDFArray> encDiffs(new SkPDFArray);
1284 encoding->insert("Differences", encDiffs.get());
1285
1286 encDiffs->reserve(lastGlyphID() - firstGlyphID() + 2); 1283 encDiffs->reserve(lastGlyphID() - firstGlyphID() + 2);
1287 encDiffs->appendInt(1); 1284 encDiffs->appendInt(1);
1288 for (int gID = firstGlyphID(); gID <= lastGlyphID(); gID++) { 1285 for (int gID = firstGlyphID(); gID <= lastGlyphID(); gID++) {
1289 encDiffs->appendName(fontInfo()->fGlyphNames->get()[gID].c_str()); 1286 encDiffs->appendName(fontInfo()->fGlyphNames->get()[gID].c_str());
1290 } 1287 }
1291 1288
1289 SkAutoTUnref<SkPDFDict> encoding(new SkPDFDict("Encoding"));
1290 encoding->insertObject("Differences", encDiffs.detach());
1291 this->insertObject("Encoding", encoding.detach());
1292 return true; 1292 return true;
1293 } 1293 }
1294 1294
1295 void SkPDFType1Font::addWidthInfoFromRange( 1295 void SkPDFType1Font::addWidthInfoFromRange(
1296 int16_t defaultWidth, 1296 int16_t defaultWidth,
1297 const SkAdvancedTypefaceMetrics::WidthRange* widthRangeEntry) { 1297 const SkAdvancedTypefaceMetrics::WidthRange* widthRangeEntry) {
1298 SkAutoTUnref<SkPDFArray> widthArray(new SkPDFArray()); 1298 SkAutoTUnref<SkPDFArray> widthArray(new SkPDFArray());
1299 int firstChar = 0; 1299 int firstChar = 0;
1300 if (widthRangeEntry) { 1300 if (widthRangeEntry) {
1301 const uint16_t emSize = fontInfo()->fEmSize; 1301 const uint16_t emSize = fontInfo()->fEmSize;
1302 int startIndex = firstGlyphID() - widthRangeEntry->fStartId; 1302 int startIndex = firstGlyphID() - widthRangeEntry->fStartId;
1303 int endIndex = startIndex + lastGlyphID() - firstGlyphID() + 1; 1303 int endIndex = startIndex + lastGlyphID() - firstGlyphID() + 1;
1304 if (startIndex < 0) 1304 if (startIndex < 0)
1305 startIndex = 0; 1305 startIndex = 0;
1306 if (endIndex > widthRangeEntry->fAdvance.count()) 1306 if (endIndex > widthRangeEntry->fAdvance.count())
1307 endIndex = widthRangeEntry->fAdvance.count(); 1307 endIndex = widthRangeEntry->fAdvance.count();
1308 if (widthRangeEntry->fStartId == 0) { 1308 if (widthRangeEntry->fStartId == 0) {
1309 appendWidth(widthRangeEntry->fAdvance[0], emSize, widthArray.get()); 1309 appendWidth(widthRangeEntry->fAdvance[0], emSize, widthArray.get());
1310 } else { 1310 } else {
1311 firstChar = startIndex + widthRangeEntry->fStartId; 1311 firstChar = startIndex + widthRangeEntry->fStartId;
1312 } 1312 }
1313 for (int i = startIndex; i < endIndex; i++) { 1313 for (int i = startIndex; i < endIndex; i++) {
1314 appendWidth(widthRangeEntry->fAdvance[i], emSize, widthArray.get()); 1314 appendWidth(widthRangeEntry->fAdvance[i], emSize, widthArray.get());
1315 } 1315 }
1316 } else { 1316 } else {
1317 appendWidth(defaultWidth, 1000, widthArray.get()); 1317 appendWidth(defaultWidth, 1000, widthArray.get());
1318 } 1318 }
1319 insertInt("FirstChar", firstChar); 1319 this->insertInt("FirstChar", firstChar);
1320 insertInt("LastChar", firstChar + widthArray->size() - 1); 1320 this->insertInt("LastChar", firstChar + widthArray->size() - 1);
1321 insert("Widths", widthArray.get()); 1321 this->insertObject("Widths", widthArray.detach());
1322 } 1322 }
1323 1323
1324 /////////////////////////////////////////////////////////////////////////////// 1324 ///////////////////////////////////////////////////////////////////////////////
1325 // class SkPDFType3Font 1325 // class SkPDFType3Font
1326 /////////////////////////////////////////////////////////////////////////////// 1326 ///////////////////////////////////////////////////////////////////////////////
1327 1327
1328 SkPDFType3Font::SkPDFType3Font(const SkAdvancedTypefaceMetrics* info, 1328 SkPDFType3Font::SkPDFType3Font(const SkAdvancedTypefaceMetrics* info,
1329 SkTypeface* typeface, 1329 SkTypeface* typeface,
1330 uint16_t glyphID) 1330 uint16_t glyphID)
1331 : SkPDFFont(info, typeface, NULL) { 1331 : SkPDFFont(info, typeface, NULL) {
(...skipping 12 matching lines...) Expand all
1344 if (lastGlyphID() == 0) { 1344 if (lastGlyphID() == 0) {
1345 setLastGlyphID(cache->getGlyphCount() - 1); 1345 setLastGlyphID(cache->getGlyphCount() - 1);
1346 } 1346 }
1347 1347
1348 adjustGlyphRangeForSingleByteEncoding(glyphID); 1348 adjustGlyphRangeForSingleByteEncoding(glyphID);
1349 1349
1350 insertName("Subtype", "Type3"); 1350 insertName("Subtype", "Type3");
1351 // Flip about the x-axis and scale by 1/1000. 1351 // Flip about the x-axis and scale by 1/1000.
1352 SkMatrix fontMatrix; 1352 SkMatrix fontMatrix;
1353 fontMatrix.setScale(SkScalarInvert(1000), -SkScalarInvert(1000)); 1353 fontMatrix.setScale(SkScalarInvert(1000), -SkScalarInvert(1000));
1354 insert("FontMatrix", SkPDFUtils::MatrixToArray(fontMatrix))->unref(); 1354 this->insertObject("FontMatrix", SkPDFUtils::MatrixToArray(fontMatrix));
1355 1355
1356 SkAutoTUnref<SkPDFDict> charProcs(new SkPDFDict); 1356 SkAutoTUnref<SkPDFDict> charProcs(new SkPDFDict);
1357 insert("CharProcs", charProcs.get());
1358
1359 SkAutoTUnref<SkPDFDict> encoding(new SkPDFDict("Encoding")); 1357 SkAutoTUnref<SkPDFDict> encoding(new SkPDFDict("Encoding"));
1360 insert("Encoding", encoding.get());
1361 1358
1362 SkAutoTUnref<SkPDFArray> encDiffs(new SkPDFArray); 1359 SkAutoTUnref<SkPDFArray> encDiffs(new SkPDFArray);
1363 encoding->insert("Differences", encDiffs.get());
1364 encDiffs->reserve(lastGlyphID() - firstGlyphID() + 2); 1360 encDiffs->reserve(lastGlyphID() - firstGlyphID() + 2);
1365 encDiffs->appendInt(1); 1361 encDiffs->appendInt(1);
1366 1362
1367 SkAutoTUnref<SkPDFArray> widthArray(new SkPDFArray()); 1363 SkAutoTUnref<SkPDFArray> widthArray(new SkPDFArray());
1368 1364
1369 SkIRect bbox = SkIRect::MakeEmpty(); 1365 SkIRect bbox = SkIRect::MakeEmpty();
1370 for (int gID = firstGlyphID(); gID <= lastGlyphID(); gID++) { 1366 for (int gID = firstGlyphID(); gID <= lastGlyphID(); gID++) {
1371 SkString characterName; 1367 SkString characterName;
1372 characterName.printf("gid%d", gID); 1368 characterName.printf("gid%d", gID);
1373 encDiffs->appendName(characterName.c_str()); 1369 encDiffs->appendName(characterName.c_str());
(...skipping 13 matching lines...) Expand all
1387 SkPDFUtils::PaintPath(paint.getStyle(), path->getFillType(), 1383 SkPDFUtils::PaintPath(paint.getStyle(), path->getFillType(),
1388 &content); 1384 &content);
1389 } 1385 }
1390 SkAutoTDelete<SkMemoryStream> glyphStream(new SkMemoryStream()); 1386 SkAutoTDelete<SkMemoryStream> glyphStream(new SkMemoryStream());
1391 glyphStream->setData(content.copyToData())->unref(); 1387 glyphStream->setData(content.copyToData())->unref();
1392 1388
1393 charProcs->insertObjRef(characterName, 1389 charProcs->insertObjRef(characterName,
1394 new SkPDFStream(glyphStream.get())); 1390 new SkPDFStream(glyphStream.get()));
1395 } 1391 }
1396 1392
1397 insert("FontBBox", makeFontBBox(bbox, 1000))->unref(); 1393 encoding->insertObject("Differences", encDiffs.detach());
1398 insertInt("FirstChar", 1); 1394
1399 insertInt("LastChar", lastGlyphID() - firstGlyphID() + 1); 1395 this->insertObject("CharProcs", charProcs.detach());
1400 insert("Widths", widthArray.get()); 1396 this->insertObject("Encoding", encoding.detach());
1401 insertName("CIDToGIDMap", "Identity"); 1397
1398 this->insertObject("FontBBox", makeFontBBox(bbox, 1000));
1399 this->insertInt("FirstChar", 1);
1400 this->insertInt("LastChar", lastGlyphID() - firstGlyphID() + 1);
1401 this->insertObject("Widths", widthArray.detach());
1402 this->insertName("CIDToGIDMap", "Identity");
1402 1403
1403 populateToUnicodeTable(NULL); 1404 populateToUnicodeTable(NULL);
1404 return true; 1405 return true;
1405 } 1406 }
1406 1407
1407 SkPDFFont::Match SkPDFFont::IsMatch(SkPDFFont* existingFont, 1408 SkPDFFont::Match SkPDFFont::IsMatch(SkPDFFont* existingFont,
1408 uint32_t existingFontID, 1409 uint32_t existingFontID,
1409 uint16_t existingGlyphID, 1410 uint16_t existingGlyphID,
1410 uint32_t searchFontID, 1411 uint32_t searchFontID,
1411 uint16_t searchGlyphID) { 1412 uint16_t searchGlyphID) {
1412 if (existingFontID != searchFontID) { 1413 if (existingFontID != searchFontID) {
1413 return SkPDFFont::kNot_Match; 1414 return SkPDFFont::kNot_Match;
1414 } 1415 }
1415 if (existingGlyphID == 0 || searchGlyphID == 0) { 1416 if (existingGlyphID == 0 || searchGlyphID == 0) {
1416 return SkPDFFont::kExact_Match; 1417 return SkPDFFont::kExact_Match;
1417 } 1418 }
1418 if (existingFont != NULL) { 1419 if (existingFont != NULL) {
1419 return (existingFont->fFirstGlyphID <= searchGlyphID && 1420 return (existingFont->fFirstGlyphID <= searchGlyphID &&
1420 searchGlyphID <= existingFont->fLastGlyphID) 1421 searchGlyphID <= existingFont->fLastGlyphID)
1421 ? SkPDFFont::kExact_Match 1422 ? SkPDFFont::kExact_Match
1422 : SkPDFFont::kRelated_Match; 1423 : SkPDFFont::kRelated_Match;
1423 } 1424 }
1424 return (existingGlyphID == searchGlyphID) ? SkPDFFont::kExact_Match 1425 return (existingGlyphID == searchGlyphID) ? SkPDFFont::kExact_Match
1425 : SkPDFFont::kRelated_Match; 1426 : SkPDFFont::kRelated_Match;
1426 } 1427 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698