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

Side by Side Diff: experimental/PdfViewer/SkPdfFont.cpp

Issue 17748002: Basic support for Type3 Fonts in Pdf + various refactorings (Closed) Base URL: http://skia.googlecode.com/svn/trunk/
Patch Set: Created 7 years, 6 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 | Annotate | Revision Log
OLDNEW
1 #include "SkPdfFont.h" 1 #include "SkPdfFont.h"
2 2
3 std::map<std::string, SkPdfStandardFontEntry>& getStandardFonts() { 3 std::map<std::string, SkPdfStandardFontEntry>& getStandardFonts() {
4 static std::map<std::string, SkPdfStandardFontEntry> gPdfStandardFonts; 4 static std::map<std::string, SkPdfStandardFontEntry> gPdfStandardFonts;
5 5
6 // TODO (edisonn): , vs - ? what does it mean? 6 // TODO (edisonn): , vs - ? what does it mean?
7 // TODO (edisonn): MT, PS, Oblique=italic?, ... what does it mean? 7 // TODO (edisonn): MT, PS, Oblique=italic?, ... what does it mean?
8 if (gPdfStandardFonts.empty()) { 8 if (gPdfStandardFonts.empty()) {
9 gPdfStandardFonts["Arial"] = {"Arial", false, false}; 9 gPdfStandardFonts["Arial"] = {"Arial", false, false};
10 gPdfStandardFonts["Arial,Bold"] = {"Arial", true, false}; 10 gPdfStandardFonts["Arial,Bold"] = {"Arial", true, false};
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
63 gPdfStandardFonts["TimesNewRomanPS-Italic"] = {"Times New Roman", false, true}; 63 gPdfStandardFonts["TimesNewRomanPS-Italic"] = {"Times New Roman", false, true};
64 gPdfStandardFonts["TimesNewRomanPS-ItalicMT"] = {"Times New Roman", fals e, true}; 64 gPdfStandardFonts["TimesNewRomanPS-ItalicMT"] = {"Times New Roman", fals e, true};
65 gPdfStandardFonts["TimesNewRomanPSMT"] = {"Times New Roman", false, fals e}; 65 gPdfStandardFonts["TimesNewRomanPSMT"] = {"Times New Roman", false, fals e};
66 gPdfStandardFonts["Symbol"] = {"Symbol", false, false}; 66 gPdfStandardFonts["Symbol"] = {"Symbol", false, false};
67 gPdfStandardFonts["ZapfDingbats"] = {"ZapfDingbats", false, false}; 67 gPdfStandardFonts["ZapfDingbats"] = {"ZapfDingbats", false, false};
68 68
69 // TODO(edisonn): these are hacks. Load Post Script font name. 69 // TODO(edisonn): these are hacks. Load Post Script font name.
70 // see FT_Get_Postscript_Name 70 // see FT_Get_Postscript_Name
71 // Font config is not using it, yet. 71 // Font config is not using it, yet.
72 //https://bugs.freedesktop.org/show_bug.cgi?id=18095 72 //https://bugs.freedesktop.org/show_bug.cgi?id=18095
73
73 gPdfStandardFonts["Arial-Black"] = {"Arial", true, false}; 74 gPdfStandardFonts["Arial-Black"] = {"Arial", true, false};
74 gPdfStandardFonts["DejaVuSans"] = {"DejaVu Sans", false, false}; 75 gPdfStandardFonts["DejaVuSans"] = {"DejaVu Sans", false, false};
75 gPdfStandardFonts["DejaVuSansMono"] = {"DejaVuSans Mono", false, false}; 76 gPdfStandardFonts["DejaVuSansMono"] = {"DejaVuSans Mono", false, false};
76 gPdfStandardFonts["DejaVuSansMono-Bold"] = {"DejaVuSans Mono", true, fal se}; 77 gPdfStandardFonts["DejaVuSansMono-Bold"] = {"DejaVuSans Mono", true, fal se};
77 gPdfStandardFonts["DejaVuSansMono-Oblique"] = {"DejaVuSans Mono", false, true}; 78 gPdfStandardFonts["DejaVuSansMono-Oblique"] = {"DejaVuSans Mono", false, true};
78 gPdfStandardFonts["Georgia-Bold"] = {"Georgia", true, false}; 79 gPdfStandardFonts["Georgia-Bold"] = {"Georgia", true, false};
79 gPdfStandardFonts["Georgia-BoldItalic"] = {"Georgia", true, true}; 80 gPdfStandardFonts["Georgia-BoldItalic"] = {"Georgia", true, true};
80 gPdfStandardFonts["Georgia-Italic"] = {"Georgia", false, true}; 81 gPdfStandardFonts["Georgia-Italic"] = {"Georgia", false, true};
81 gPdfStandardFonts["TrebuchetMS"] = {"Trebuchet MS", false, false}; 82 gPdfStandardFonts["TrebuchetMS"] = {"Trebuchet MS", false, false};
82 gPdfStandardFonts["TrebuchetMS-Bold"] = {"Trebuchet MS", true, false}; 83 gPdfStandardFonts["TrebuchetMS-Bold"] = {"Trebuchet MS", true, false};
83 gPdfStandardFonts["Verdana-Bold"] = {"Verdana", true, false}; 84 gPdfStandardFonts["Verdana-Bold"] = {"Verdana", true, false};
84 gPdfStandardFonts["WenQuanYiMicroHei"] = {"WenQuanYi Micro Hei", false, false}; 85 gPdfStandardFonts["WenQuanYiMicroHei"] = {"WenQuanYi Micro Hei", false, false};
86
87 // TODO(edisonn): list all phonts available, builf post script name as i n pdf spec
88 /*
89 * The PostScript name for the value of BaseFontis determined in one of two ways:
90 • Use the PostScript name that is an optional entry in the “name” table of the
91 TrueType font itself.
92 • In the absence of such an entry in the “name” table, derive a PostScript name
93 from the name by which the font is known in the host operating system: on a
94 Windows system, it is based on the lfFaceName field in a LOGFONT structure; in
95 the Mac OS, it is based on the name of the FONDresource. If the name contains
96 any spaces, the spaces are removed.
97 If the font in a source document uses a bold or italic style, but there is no fo nt
98 data for that style, the host operating system will synthesize the style. In thi s case,
99 a comma and the style name (one of Bold, Italic, or BoldItalic) are appended to the
100 font name. For example, for a TrueType font that is a bold variant of the New
101 */
102
103 /*
104 * If the value of Subtype is MMType1.
105 • If the PostScript name of the instance contains spaces, the spaces are replace d
106 by underscores in the value of BaseFont. For instance, as illustrated in Example
107 5.7, the name “MinionMM 366 465 11 ” (which ends with a space character)
108 becomes /MinionMM_366_465_11_.
109 */
110
111 // might not work on all oses ?
112 //
113
85 } 114 }
86 115
87 return gPdfStandardFonts; 116 return gPdfStandardFonts;
88 } 117 }
89 118
90 SkTypeface* SkTypefaceFromPdfStandardFont(const char* fontName, bool bold, bool italic) { 119 SkTypeface* SkTypefaceFromPdfStandardFont(const char* fontName, bool bold, bool italic) {
91 std::map<std::string, SkPdfStandardFontEntry>& standardFontMap = getStandard Fonts(); 120 std::map<std::string, SkPdfStandardFontEntry>& standardFontMap = getStandard Fonts();
92 121
93 SkTypeface* typeface = NULL; 122 SkTypeface* typeface = NULL;
94 if (standardFontMap.find(fontName) != standardFontMap.end()) { 123 if (standardFontMap.find(fontName) != standardFontMap.end()) {
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
171 } 200 }
172 201
173 return new SkPdfType1Font(dict); 202 return new SkPdfType1Font(dict);
174 } 203 }
175 204
176 SkPdfType3Font* SkPdfFont::fontFromType3FontDictionary(SkPdfType3FontDictionary* dict) { 205 SkPdfType3Font* SkPdfFont::fontFromType3FontDictionary(SkPdfType3FontDictionary* dict) {
177 if (dict == NULL) { 206 if (dict == NULL) {
178 return NULL; // default one? 207 return NULL; // default one?
179 } 208 }
180 209
210
211
181 return new SkPdfType3Font(dict); 212 return new SkPdfType3Font(dict);
182 } 213 }
183 214
184 SkPdfTrueTypeFont* SkPdfFont::fontFromTrueTypeFontDictionary(SkPdfTrueTypeFontDi ctionary* dict) { 215 SkPdfTrueTypeFont* SkPdfFont::fontFromTrueTypeFontDictionary(SkPdfTrueTypeFontDi ctionary* dict) {
185 if (dict == NULL) { 216 if (dict == NULL) {
186 return NULL; // default one? 217 return NULL; // default one?
187 } 218 }
188 219
189 return new SkPdfTrueTypeFont(dict); 220 return new SkPdfTrueTypeFont(dict);
190 } 221 }
(...skipping 15 matching lines...) Expand all
206 } 237 }
207 238
208 static int skstoi(const SkPdfString* str) { 239 static int skstoi(const SkPdfString* str) {
209 int ret = 0; 240 int ret = 0;
210 for (int i = 0 ; i < str->podofo()->GetString().GetLength(); i++) { 241 for (int i = 0 ; i < str->podofo()->GetString().GetLength(); i++) {
211 ret = (ret << 8) + ((unsigned char*)str->podofo()->GetString().GetString ())[i]; 242 ret = (ret << 8) + ((unsigned char*)str->podofo()->GetString().GetString ())[i];
212 } 243 }
213 return ret; 244 return ret;
214 } 245 }
215 246
216 SkPdfType0Font::SkPdfType0Font(SkPdfType0FontDictionary* dict) { 247 SkPdfToUnicode::SkPdfToUnicode(const SkPdfStream* stream) {
217 fBaseFont = SkPdfFontFromName(dict, dict->BaseFont().c_str());
218
219 // TODO(edisonn): load encoding, let it now to be Identity-H by default
220 if (dict->has_Encoding()) {
221 if (dict->isEncodingAName()) {
222 //report encoding not supported
223 //fEncoding = loadEncodingFromName(dict->getEncodingAsName().c_str() );
224 } else if (dict->isEncodingAStream()) {
225 //fEncoding = loadEncodingFromStream(dict->getEncodingAsStream());
226 } else {
227 // error
228 }
229 }
230
231 fCMapEncoding = NULL; 248 fCMapEncoding = NULL;
232 fCMapEncodingFlag = NULL; 249 fCMapEncodingFlag = NULL;
233 250
234 if (dict->has_ToUnicode()) { 251 if (stream) {
235 const SkPdfStream* stream = dict->ToUnicode();
236 SkPdfTokenizer tokenizer(stream); 252 SkPdfTokenizer tokenizer(stream);
237 PdfToken token; 253 PdfToken token;
238 254
239 fCMapEncoding = new unsigned short[256 * 256]; 255 fCMapEncoding = new unsigned short[256 * 256];
240 fCMapEncodingFlag = new unsigned char[256 * 256]; 256 fCMapEncodingFlag = new unsigned char[256 * 256];
241 for (int i = 0 ; i < 256 * 256; i++) { 257 for (int i = 0 ; i < 256 * 256; i++) {
242 fCMapEncoding[i] = i; 258 fCMapEncoding[i] = i;
243 fCMapEncodingFlag[i] = 0; 259 fCMapEncodingFlag[i] = 0;
244 } 260 }
245 261
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
311 // read array 327 // read array
312 } 328 }
313 329
314 //fCMapEncodingFlag[from] = 1; 330 //fCMapEncodingFlag[from] = 1;
315 //fCMapEncoding[from] = to; 331 //fCMapEncoding[from] = to;
316 } 332 }
317 } 333 }
318 } 334 }
319 } 335 }
320 } 336 }
337
338
339 SkPdfType0Font::SkPdfType0Font(SkPdfType0FontDictionary* dict) {
340 fBaseFont = SkPdfFontFromName(dict, dict->BaseFont().c_str());
341 fEncoding = NULL;
342
343 if (dict->has_Encoding()) {
344 if (dict->isEncodingAName()) {
345 fEncoding = SkPdfEncoding::fromName(dict->getEncodingAsName().c_str( ));
346 } else if (dict->isEncodingAStream()) {
347 //fEncoding = loadEncodingFromStream(dict->getEncodingAsStream());
348 } else {
349 // TODO(edisonn): error ... warning .. assert?
350 }
351 }
352
353 if (dict->has_ToUnicode()) {
354 fToUnicode = new SkPdfToUnicode(dict->ToUnicode());
355 }
356 }
357
358 std::map<std::string, SkPdfEncoding*>& getStandardEncodings() {
359 static std::map<std::string, SkPdfEncoding*> encodings;
360 if (encodings.empty()) {
361 encodings["Identity-H"] = SkPdfIdentityHEncoding::instance();
362 }
363
364 return encodings;
365 }
366
367
368 SkPdfEncoding* SkPdfEncoding::fromName(const char* name) {
369 SkPdfEncoding* encoding = getStandardEncodings()[name];
370
371 #ifdef PDF_TRACE
372 if (encoding == NULL) {
373 printf("Encoding not found: %s\n", name);
374 }
375 #endif
376 return encoding;
377 }
OLDNEW
« no previous file with comments | « experimental/PdfViewer/SkPdfFont.h ('k') | experimental/PdfViewer/SkPdfFontDescriptorDictionary_autogen.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698