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

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: 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 this->insertObjRef("FontDescriptor", SkRef(descriptor.get()));
tomhudson 2015/05/01 15:06:20 Minor frustration: while reviewing it's easy to do
hal.canary 2015/05/05 17:17:24 I'll try to fix.
1061 if (!addCommonFontDescriptorEntries(defaultWidth)) { 1062 if (!addCommonFontDescriptorEntries(defaultWidth)) {
1062 return false; 1063 return false;
1063 } 1064 }
1064 if (!canEmbed()) { 1065 if (!canEmbed()) {
1065 return true; 1066 return true;
1066 } 1067 }
1067 1068
1068 switch (getType()) { 1069 switch (getType()) {
1069 case SkAdvancedTypefaceMetrics::kTrueType_Font: { 1070 case SkAdvancedTypefaceMetrics::kTrueType_Font: {
1070 SkAutoTUnref<SkPDFStream> fontStream; 1071 SkAutoTUnref<SkPDFStream> fontStream;
1071 size_t fontSize = 0; 1072 size_t fontSize = 0;
1072 if (canSubset()) { 1073 if (canSubset()) {
1073 SkPDFStream* rawStream = NULL; 1074 SkPDFStream* rawStream = NULL;
1074 fontSize = get_subset_font_stream(fontInfo()->fFontName.c_str(), 1075 fontSize = get_subset_font_stream(fontInfo()->fFontName.c_str(),
1075 typeface(), 1076 typeface(),
1076 *subset, 1077 *subset,
1077 &rawStream); 1078 &rawStream);
1078 fontStream.reset(rawStream); 1079 fontStream.reset(rawStream);
1079 } else { 1080 } else {
1080 int ttcIndex; 1081 int ttcIndex;
1081 SkAutoTDelete<SkStream> fontData( 1082 SkAutoTDelete<SkStream> fontData(
1082 typeface()->openStream(&ttcIndex)); 1083 typeface()->openStream(&ttcIndex));
1083 fontStream.reset(new SkPDFStream(fontData.get())); 1084 fontStream.reset(new SkPDFStream(fontData.get()));
1084 fontSize = fontData->getLength(); 1085 fontSize = fontData->getLength();
1085 } 1086 }
1086 SkASSERT(fontSize); 1087 SkASSERT(fontSize);
1087 SkASSERT(fontStream.get()); 1088 SkASSERT(fontStream.get());
1088 1089
1089 fontStream->insertInt("Length1", fontSize); 1090 fontStream->insertInt("Length1", fontSize);
1090 descriptor->insert("FontFile2", 1091 descriptor->insertObjRef("FontFile2", fontStream.detach());
1091 new SkPDFObjRef(fontStream.get()))->unref();
1092 break; 1092 break;
1093 } 1093 }
1094 case SkAdvancedTypefaceMetrics::kCFF_Font: 1094 case SkAdvancedTypefaceMetrics::kCFF_Font:
1095 case SkAdvancedTypefaceMetrics::kType1CID_Font: { 1095 case SkAdvancedTypefaceMetrics::kType1CID_Font: {
1096 int ttcIndex; 1096 int ttcIndex;
1097 SkAutoTDelete<SkStream> fontData(typeface()->openStream(&ttcIndex)); 1097 SkAutoTDelete<SkStream> fontData(typeface()->openStream(&ttcIndex));
1098 SkAutoTUnref<SkPDFStream> fontStream( 1098 SkAutoTUnref<SkPDFStream> fontStream(
1099 new SkPDFStream(fontData.get())); 1099 new SkPDFStream(fontData.get()));
1100 1100
1101 if (getType() == SkAdvancedTypefaceMetrics::kCFF_Font) { 1101 if (getType() == SkAdvancedTypefaceMetrics::kCFF_Font) {
1102 fontStream->insertName("Subtype", "Type1C"); 1102 fontStream->insertName("Subtype", "Type1C");
1103 } else { 1103 } else {
1104 fontStream->insertName("Subtype", "CIDFontType0c"); 1104 fontStream->insertName("Subtype", "CIDFontType0c");
1105 } 1105 }
1106 descriptor->insert("FontFile3", 1106 descriptor->insertObjRef("FontFile3", fontStream.detach());
1107 new SkPDFObjRef(fontStream.get()))->unref();
1108 break; 1107 break;
1109 } 1108 }
1110 default: 1109 default:
1111 SkASSERT(false); 1110 SkASSERT(false);
1112 } 1111 }
1113 return true; 1112 return true;
1114 } 1113 }
1115 1114
1116 bool SkPDFCIDFont::populate(const SkPDFGlyphSet* subset) { 1115 bool SkPDFCIDFont::populate(const SkPDFGlyphSet* subset) {
1117 // Generate new font metrics with advance info for true type fonts. 1116 // Generate new font metrics with advance info for true type fonts.
(...skipping 28 matching lines...) Expand all
1146 if (getType() == SkAdvancedTypefaceMetrics::kType1CID_Font) { 1145 if (getType() == SkAdvancedTypefaceMetrics::kType1CID_Font) {
1147 insertName("Subtype", "CIDFontType0"); 1146 insertName("Subtype", "CIDFontType0");
1148 } else if (getType() == SkAdvancedTypefaceMetrics::kTrueType_Font) { 1147 } else if (getType() == SkAdvancedTypefaceMetrics::kTrueType_Font) {
1149 insertName("Subtype", "CIDFontType2"); 1148 insertName("Subtype", "CIDFontType2");
1150 insertName("CIDToGIDMap", "Identity"); 1149 insertName("CIDToGIDMap", "Identity");
1151 } else { 1150 } else {
1152 SkASSERT(false); 1151 SkASSERT(false);
1153 } 1152 }
1154 1153
1155 SkAutoTUnref<SkPDFDict> sysInfo(new SkPDFDict); 1154 SkAutoTUnref<SkPDFDict> sysInfo(new SkPDFDict);
1156 sysInfo->insert("Registry", new SkPDFString("Adobe"))->unref(); 1155 sysInfo->insertString("Registry", "Adobe");
1157 sysInfo->insert("Ordering", new SkPDFString("Identity"))->unref(); 1156 sysInfo->insertString("Ordering", "Identity");
1158 sysInfo->insertInt("Supplement", 0); 1157 sysInfo->insertInt("Supplement", 0);
1159 insert("CIDSystemInfo", sysInfo.get()); 1158 this->insertObject("CIDSystemInfo", sysInfo.detach());
1160 1159
1161 if (fontInfo()->fGlyphWidths.get()) { 1160 if (fontInfo()->fGlyphWidths.get()) {
1162 int16_t defaultWidth = 0; 1161 int16_t defaultWidth = 0;
1163 SkAutoTUnref<SkPDFArray> widths( 1162 SkAutoTUnref<SkPDFArray> widths(
1164 composeAdvanceData(fontInfo()->fGlyphWidths.get(), 1163 composeAdvanceData(fontInfo()->fGlyphWidths.get(),
1165 fontInfo()->fEmSize, &appendWidth, 1164 fontInfo()->fEmSize, &appendWidth,
1166 &defaultWidth)); 1165 &defaultWidth));
1167 if (widths->size()) 1166 if (widths->size())
1168 insert("W", widths.get()); 1167 this->insertObject("W", widths.detach());
tomhudson 2015/05/01 15:06:20 It's a bit weird seeing a *conditional* detach(),
hal.canary 2015/05/05 17:17:24 Acknowledged.
1169 if (defaultWidth != 0) { 1168 if (defaultWidth != 0) {
1170 insertScalar("DW", scaleFromFontUnits(defaultWidth, 1169 this->insertScalar(
1171 fontInfo()->fEmSize)); 1170 "DW",
1171 scaleFromFontUnits(defaultWidth, fontInfo()->fEmSize));
1172 } 1172 }
1173 } 1173 }
1174 if (fontInfo()->fVerticalMetrics.get()) { 1174 if (fontInfo()->fVerticalMetrics.get()) {
1175 struct SkAdvancedTypefaceMetrics::VerticalMetric defaultAdvance; 1175 struct SkAdvancedTypefaceMetrics::VerticalMetric defaultAdvance;
1176 defaultAdvance.fVerticalAdvance = 0; 1176 defaultAdvance.fVerticalAdvance = 0;
1177 defaultAdvance.fOriginXDisp = 0; 1177 defaultAdvance.fOriginXDisp = 0;
1178 defaultAdvance.fOriginYDisp = 0; 1178 defaultAdvance.fOriginYDisp = 0;
1179 SkAutoTUnref<SkPDFArray> advances( 1179 SkAutoTUnref<SkPDFArray> advances(
1180 composeAdvanceData(fontInfo()->fVerticalMetrics.get(), 1180 composeAdvanceData(fontInfo()->fVerticalMetrics.get(),
1181 fontInfo()->fEmSize, &appendVerticalAdvance, 1181 fontInfo()->fEmSize, &appendVerticalAdvance,
1182 &defaultAdvance)); 1182 &defaultAdvance));
1183 if (advances->size()) 1183 if (advances->size())
1184 insert("W2", advances.get()); 1184 this->insertObject("W2", advances.detach());
1185 if (defaultAdvance.fVerticalAdvance || 1185 if (defaultAdvance.fVerticalAdvance ||
1186 defaultAdvance.fOriginXDisp || 1186 defaultAdvance.fOriginXDisp ||
1187 defaultAdvance.fOriginYDisp) { 1187 defaultAdvance.fOriginYDisp) {
1188 insert("DW2", appendVerticalAdvance(defaultAdvance, 1188 this->insertObject("DW2",
1189 fontInfo()->fEmSize, 1189 appendVerticalAdvance(defaultAdvance,
1190 new SkPDFArray))->unref(); 1190 fontInfo()->fEmSize,
1191 new SkPDFArray));
1191 } 1192 }
1192 } 1193 }
1193 1194
1194 return true; 1195 return true;
1195 } 1196 }
1196 1197
1197 /////////////////////////////////////////////////////////////////////////////// 1198 ///////////////////////////////////////////////////////////////////////////////
1198 // class SkPDFType1Font 1199 // class SkPDFType1Font
1199 /////////////////////////////////////////////////////////////////////////////// 1200 ///////////////////////////////////////////////////////////////////////////////
1200 1201
1201 SkPDFType1Font::SkPDFType1Font(const SkAdvancedTypefaceMetrics* info, 1202 SkPDFType1Font::SkPDFType1Font(const SkAdvancedTypefaceMetrics* info,
1202 SkTypeface* typeface, 1203 SkTypeface* typeface,
1203 uint16_t glyphID, 1204 uint16_t glyphID,
1204 SkPDFDict* relatedFontDescriptor) 1205 SkPDFDict* relatedFontDescriptor)
1205 : SkPDFFont(info, typeface, relatedFontDescriptor) { 1206 : SkPDFFont(info, typeface, relatedFontDescriptor) {
1206 populate(glyphID); 1207 populate(glyphID);
1207 } 1208 }
1208 1209
1209 SkPDFType1Font::~SkPDFType1Font() {} 1210 SkPDFType1Font::~SkPDFType1Font() {}
1210 1211
1211 bool SkPDFType1Font::addFontDescriptor(int16_t defaultWidth) { 1212 bool SkPDFType1Font::addFontDescriptor(int16_t defaultWidth) {
1212 if (getFontDescriptor() != NULL) { 1213 if (SkPDFDict* descriptor = getFontDescriptor()) {
1213 SkPDFDict* descriptor = getFontDescriptor(); 1214 this->insertObjRef("FontDescriptor", SkRef(descriptor));
1214 insert("FontDescriptor", new SkPDFObjRef(descriptor))->unref();
1215 return true; 1215 return true;
1216 } 1216 }
1217 1217
1218 SkAutoTUnref<SkPDFDict> descriptor(new SkPDFDict("FontDescriptor")); 1218 SkAutoTUnref<SkPDFDict> descriptor(new SkPDFDict("FontDescriptor"));
1219 setFontDescriptor(descriptor.get()); 1219 setFontDescriptor(descriptor.get());
1220 1220
1221 int ttcIndex; 1221 int ttcIndex;
1222 size_t header SK_INIT_TO_AVOID_WARNING; 1222 size_t header SK_INIT_TO_AVOID_WARNING;
1223 size_t data SK_INIT_TO_AVOID_WARNING; 1223 size_t data SK_INIT_TO_AVOID_WARNING;
1224 size_t trailer SK_INIT_TO_AVOID_WARNING; 1224 size_t trailer SK_INIT_TO_AVOID_WARNING;
1225 SkAutoTDelete<SkStream> rawFontData(typeface()->openStream(&ttcIndex)); 1225 SkAutoTDelete<SkStream> rawFontData(typeface()->openStream(&ttcIndex));
1226 SkAutoTUnref<SkData> fontData(handle_type1_stream(rawFontData.get(), &header , 1226 SkAutoTUnref<SkData> fontData(handle_type1_stream(rawFontData.get(), &header ,
1227 &data, &trailer)); 1227 &data, &trailer));
1228 if (fontData.get() == NULL) { 1228 if (fontData.get() == NULL) {
1229 return false; 1229 return false;
1230 } 1230 }
1231 if (canEmbed()) { 1231 if (canEmbed()) {
1232 SkAutoTUnref<SkPDFStream> fontStream(new SkPDFStream(fontData.get())); 1232 SkAutoTUnref<SkPDFStream> fontStream(new SkPDFStream(fontData.get()));
tomhudson 2015/05/01 15:06:20 Not detach()ing the fontData?
hal.canary 2015/05/05 17:17:24 The SkPDFStream interface has not changed yet.
1233 fontStream->insertInt("Length1", header); 1233 fontStream->insertInt("Length1", header);
1234 fontStream->insertInt("Length2", data); 1234 fontStream->insertInt("Length2", data);
1235 fontStream->insertInt("Length3", trailer); 1235 fontStream->insertInt("Length3", trailer);
1236 descriptor->insert("FontFile", 1236 descriptor->insertObjRef("FontFile", fontStream.detach());
1237 new SkPDFObjRef(fontStream.get()))->unref();
1238 } 1237 }
1239 1238
1240 insert("FontDescriptor", new SkPDFObjRef(descriptor.get()))->unref(); 1239 this->insertObjRef("FontDescriptor", descriptor.detach());
1241 1240
1242 return addCommonFontDescriptorEntries(defaultWidth); 1241 return addCommonFontDescriptorEntries(defaultWidth);
1243 } 1242 }
1244 1243
1245 bool SkPDFType1Font::populate(int16_t glyphID) { 1244 bool SkPDFType1Font::populate(int16_t glyphID) {
1246 SkASSERT(!fontInfo()->fVerticalMetrics.get()); 1245 SkASSERT(!fontInfo()->fVerticalMetrics.get());
1247 SkASSERT(fontInfo()->fGlyphWidths.get()); 1246 SkASSERT(fontInfo()->fGlyphWidths.get());
1248 1247
1249 adjustGlyphRangeForSingleByteEncoding(glyphID); 1248 adjustGlyphRangeForSingleByteEncoding(glyphID);
1250 1249
(...skipping 19 matching lines...) Expand all
1270 1269
1271 if (!addFontDescriptor(defaultWidth)) { 1270 if (!addFontDescriptor(defaultWidth)) {
1272 return false; 1271 return false;
1273 } 1272 }
1274 1273
1275 insertName("Subtype", "Type1"); 1274 insertName("Subtype", "Type1");
1276 insertName("BaseFont", fontInfo()->fFontName); 1275 insertName("BaseFont", fontInfo()->fFontName);
1277 1276
1278 addWidthInfoFromRange(defaultWidth, widthRangeEntry); 1277 addWidthInfoFromRange(defaultWidth, widthRangeEntry);
1279 1278
1280 SkAutoTUnref<SkPDFDict> encoding(new SkPDFDict("Encoding"));
1281 insert("Encoding", encoding.get());
1282 1279
1283 SkAutoTUnref<SkPDFArray> encDiffs(new SkPDFArray); 1280 SkAutoTUnref<SkPDFArray> encDiffs(new SkPDFArray);
1284 encoding->insert("Differences", encDiffs.get());
1285
1286 encDiffs->reserve(lastGlyphID() - firstGlyphID() + 2); 1281 encDiffs->reserve(lastGlyphID() - firstGlyphID() + 2);
1287 encDiffs->appendInt(1); 1282 encDiffs->appendInt(1);
1288 for (int gID = firstGlyphID(); gID <= lastGlyphID(); gID++) { 1283 for (int gID = firstGlyphID(); gID <= lastGlyphID(); gID++) {
1289 encDiffs->appendName(fontInfo()->fGlyphNames->get()[gID].c_str()); 1284 encDiffs->appendName(fontInfo()->fGlyphNames->get()[gID].c_str());
1290 } 1285 }
1291 1286
1287 SkAutoTUnref<SkPDFDict> encoding(new SkPDFDict("Encoding"));
1288 encoding->insertObject("Differences", encDiffs.detach());
1289 this->insertObject("Encoding", encoding.detach());
1292 return true; 1290 return true;
1293 } 1291 }
1294 1292
1295 void SkPDFType1Font::addWidthInfoFromRange( 1293 void SkPDFType1Font::addWidthInfoFromRange(
1296 int16_t defaultWidth, 1294 int16_t defaultWidth,
1297 const SkAdvancedTypefaceMetrics::WidthRange* widthRangeEntry) { 1295 const SkAdvancedTypefaceMetrics::WidthRange* widthRangeEntry) {
1298 SkAutoTUnref<SkPDFArray> widthArray(new SkPDFArray()); 1296 SkAutoTUnref<SkPDFArray> widthArray(new SkPDFArray());
1299 int firstChar = 0; 1297 int firstChar = 0;
1300 if (widthRangeEntry) { 1298 if (widthRangeEntry) {
1301 const uint16_t emSize = fontInfo()->fEmSize; 1299 const uint16_t emSize = fontInfo()->fEmSize;
1302 int startIndex = firstGlyphID() - widthRangeEntry->fStartId; 1300 int startIndex = firstGlyphID() - widthRangeEntry->fStartId;
1303 int endIndex = startIndex + lastGlyphID() - firstGlyphID() + 1; 1301 int endIndex = startIndex + lastGlyphID() - firstGlyphID() + 1;
1304 if (startIndex < 0) 1302 if (startIndex < 0)
1305 startIndex = 0; 1303 startIndex = 0;
1306 if (endIndex > widthRangeEntry->fAdvance.count()) 1304 if (endIndex > widthRangeEntry->fAdvance.count())
1307 endIndex = widthRangeEntry->fAdvance.count(); 1305 endIndex = widthRangeEntry->fAdvance.count();
1308 if (widthRangeEntry->fStartId == 0) { 1306 if (widthRangeEntry->fStartId == 0) {
1309 appendWidth(widthRangeEntry->fAdvance[0], emSize, widthArray.get()); 1307 appendWidth(widthRangeEntry->fAdvance[0], emSize, widthArray.get());
1310 } else { 1308 } else {
1311 firstChar = startIndex + widthRangeEntry->fStartId; 1309 firstChar = startIndex + widthRangeEntry->fStartId;
1312 } 1310 }
1313 for (int i = startIndex; i < endIndex; i++) { 1311 for (int i = startIndex; i < endIndex; i++) {
1314 appendWidth(widthRangeEntry->fAdvance[i], emSize, widthArray.get()); 1312 appendWidth(widthRangeEntry->fAdvance[i], emSize, widthArray.get());
1315 } 1313 }
1316 } else { 1314 } else {
1317 appendWidth(defaultWidth, 1000, widthArray.get()); 1315 appendWidth(defaultWidth, 1000, widthArray.get());
1318 } 1316 }
1319 insertInt("FirstChar", firstChar); 1317 this->insertInt("FirstChar", firstChar);
1320 insertInt("LastChar", firstChar + widthArray->size() - 1); 1318 this->insertInt("LastChar", firstChar + widthArray->size() - 1);
1321 insert("Widths", widthArray.get()); 1319 this->insertObject("Widths", widthArray.detach());
1322 } 1320 }
1323 1321
1324 /////////////////////////////////////////////////////////////////////////////// 1322 ///////////////////////////////////////////////////////////////////////////////
1325 // class SkPDFType3Font 1323 // class SkPDFType3Font
1326 /////////////////////////////////////////////////////////////////////////////// 1324 ///////////////////////////////////////////////////////////////////////////////
1327 1325
1328 SkPDFType3Font::SkPDFType3Font(const SkAdvancedTypefaceMetrics* info, 1326 SkPDFType3Font::SkPDFType3Font(const SkAdvancedTypefaceMetrics* info,
1329 SkTypeface* typeface, 1327 SkTypeface* typeface,
1330 uint16_t glyphID) 1328 uint16_t glyphID)
1331 : SkPDFFont(info, typeface, NULL) { 1329 : SkPDFFont(info, typeface, NULL) {
(...skipping 12 matching lines...) Expand all
1344 if (lastGlyphID() == 0) { 1342 if (lastGlyphID() == 0) {
1345 setLastGlyphID(cache->getGlyphCount() - 1); 1343 setLastGlyphID(cache->getGlyphCount() - 1);
1346 } 1344 }
1347 1345
1348 adjustGlyphRangeForSingleByteEncoding(glyphID); 1346 adjustGlyphRangeForSingleByteEncoding(glyphID);
1349 1347
1350 insertName("Subtype", "Type3"); 1348 insertName("Subtype", "Type3");
1351 // Flip about the x-axis and scale by 1/1000. 1349 // Flip about the x-axis and scale by 1/1000.
1352 SkMatrix fontMatrix; 1350 SkMatrix fontMatrix;
1353 fontMatrix.setScale(SkScalarInvert(1000), -SkScalarInvert(1000)); 1351 fontMatrix.setScale(SkScalarInvert(1000), -SkScalarInvert(1000));
1354 insert("FontMatrix", SkPDFUtils::MatrixToArray(fontMatrix))->unref(); 1352 this->insertObject("FontMatrix", SkPDFUtils::MatrixToArray(fontMatrix));
1355 1353
1356 SkAutoTUnref<SkPDFDict> charProcs(new SkPDFDict); 1354 SkAutoTUnref<SkPDFDict> charProcs(new SkPDFDict);
1357 insert("CharProcs", charProcs.get());
1358
1359 SkAutoTUnref<SkPDFDict> encoding(new SkPDFDict("Encoding")); 1355 SkAutoTUnref<SkPDFDict> encoding(new SkPDFDict("Encoding"));
1360 insert("Encoding", encoding.get());
1361 1356
1362 SkAutoTUnref<SkPDFArray> encDiffs(new SkPDFArray); 1357 SkAutoTUnref<SkPDFArray> encDiffs(new SkPDFArray);
1363 encoding->insert("Differences", encDiffs.get());
1364 encDiffs->reserve(lastGlyphID() - firstGlyphID() + 2); 1358 encDiffs->reserve(lastGlyphID() - firstGlyphID() + 2);
1365 encDiffs->appendInt(1); 1359 encDiffs->appendInt(1);
1366 1360
1367 SkAutoTUnref<SkPDFArray> widthArray(new SkPDFArray()); 1361 SkAutoTUnref<SkPDFArray> widthArray(new SkPDFArray());
1368 1362
1369 SkIRect bbox = SkIRect::MakeEmpty(); 1363 SkIRect bbox = SkIRect::MakeEmpty();
1370 for (int gID = firstGlyphID(); gID <= lastGlyphID(); gID++) { 1364 for (int gID = firstGlyphID(); gID <= lastGlyphID(); gID++) {
1371 SkString characterName; 1365 SkString characterName;
1372 characterName.printf("gid%d", gID); 1366 characterName.printf("gid%d", gID);
1373 encDiffs->appendName(characterName.c_str()); 1367 encDiffs->appendName(characterName.c_str());
(...skipping 13 matching lines...) Expand all
1387 SkPDFUtils::PaintPath(paint.getStyle(), path->getFillType(), 1381 SkPDFUtils::PaintPath(paint.getStyle(), path->getFillType(),
1388 &content); 1382 &content);
1389 } 1383 }
1390 SkAutoTDelete<SkMemoryStream> glyphStream(new SkMemoryStream()); 1384 SkAutoTDelete<SkMemoryStream> glyphStream(new SkMemoryStream());
1391 glyphStream->setData(content.copyToData())->unref(); 1385 glyphStream->setData(content.copyToData())->unref();
1392 1386
1393 charProcs->insertObjRef(characterName, 1387 charProcs->insertObjRef(characterName,
1394 new SkPDFStream(glyphStream.get())); 1388 new SkPDFStream(glyphStream.get()));
1395 } 1389 }
1396 1390
1397 insert("FontBBox", makeFontBBox(bbox, 1000))->unref(); 1391 encoding->insertObject("Differences", encDiffs.detach());
1398 insertInt("FirstChar", 1); 1392
1399 insertInt("LastChar", lastGlyphID() - firstGlyphID() + 1); 1393 this->insertObject("CharProcs", charProcs.detach());
1400 insert("Widths", widthArray.get()); 1394 this->insertObject("Encoding", encoding.detach());
1401 insertName("CIDToGIDMap", "Identity"); 1395
1396 this->insertObject("FontBBox", makeFontBBox(bbox, 1000));
1397 this->insertInt("FirstChar", 1);
1398 this->insertInt("LastChar", lastGlyphID() - firstGlyphID() + 1);
1399 this->insertObject("Widths", widthArray.detach());
1400 this->insertName("CIDToGIDMap", "Identity");
1402 1401
1403 populateToUnicodeTable(NULL); 1402 populateToUnicodeTable(NULL);
1404 return true; 1403 return true;
1405 } 1404 }
1406 1405
1407 SkPDFFont::Match SkPDFFont::IsMatch(SkPDFFont* existingFont, 1406 SkPDFFont::Match SkPDFFont::IsMatch(SkPDFFont* existingFont,
1408 uint32_t existingFontID, 1407 uint32_t existingFontID,
1409 uint16_t existingGlyphID, 1408 uint16_t existingGlyphID,
1410 uint32_t searchFontID, 1409 uint32_t searchFontID,
1411 uint16_t searchGlyphID) { 1410 uint16_t searchGlyphID) {
1412 if (existingFontID != searchFontID) { 1411 if (existingFontID != searchFontID) {
1413 return SkPDFFont::kNot_Match; 1412 return SkPDFFont::kNot_Match;
1414 } 1413 }
1415 if (existingGlyphID == 0 || searchGlyphID == 0) { 1414 if (existingGlyphID == 0 || searchGlyphID == 0) {
1416 return SkPDFFont::kExact_Match; 1415 return SkPDFFont::kExact_Match;
1417 } 1416 }
1418 if (existingFont != NULL) { 1417 if (existingFont != NULL) {
1419 return (existingFont->fFirstGlyphID <= searchGlyphID && 1418 return (existingFont->fFirstGlyphID <= searchGlyphID &&
1420 searchGlyphID <= existingFont->fLastGlyphID) 1419 searchGlyphID <= existingFont->fLastGlyphID)
1421 ? SkPDFFont::kExact_Match 1420 ? SkPDFFont::kExact_Match
1422 : SkPDFFont::kRelated_Match; 1421 : SkPDFFont::kRelated_Match;
1423 } 1422 }
1424 return (existingGlyphID == searchGlyphID) ? SkPDFFont::kExact_Match 1423 return (existingGlyphID == searchGlyphID) ? SkPDFFont::kExact_Match
1425 : SkPDFFont::kRelated_Match; 1424 : SkPDFFont::kRelated_Match;
1426 } 1425 }
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