| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2013 Google Inc. | 2 * Copyright 2013 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 "SkPdfFont.h" | 8 #include "SkPdfFont.h" |
| 9 | 9 |
| 10 #include "SkPdfNativeTokenizer.h" |
| 10 #include "SkStream.h" | 11 #include "SkStream.h" |
| 11 #include "SkTypeface.h" | 12 #include "SkTypeface.h" |
| 12 #include "SkPdfNativeTokenizer.h" | |
| 13 | 13 |
| 14 SkTDict<SkPdfStandardFontEntry>& getStandardFonts() { | 14 SkTDict<SkPdfStandardFontEntry>& getStandardFonts() { |
| 15 static SkTDict<SkPdfStandardFontEntry> gPdfStandardFonts(100); | 15 static SkTDict<SkPdfStandardFontEntry> gPdfStandardFonts(100); |
| 16 | 16 |
| 17 // TODO (edisonn): , vs - ? what does it mean? | 17 // TODO (edisonn): , vs - ? what does it mean? |
| 18 // TODO (edisonn): MT, PS, Oblique=italic?, ... what does it mean? | 18 // TODO (edisonn): MT, PS, Oblique=italic?, ... what does it mean? |
| 19 if (gPdfStandardFonts.count() == 0) { | 19 if (gPdfStandardFonts.count() == 0) { |
| 20 gPdfStandardFonts.set("Arial", SkPdfStandardFontEntry("Arial", false, fa
lse)); | 20 gPdfStandardFonts.set("Arial", SkPdfStandardFontEntry("Arial", false, fa
lse)); |
| 21 gPdfStandardFonts.set("Arial,Bold", SkPdfStandardFontEntry("Arial", true
, false)); | 21 gPdfStandardFonts.set("Arial,Bold", SkPdfStandardFontEntry("Arial", true
, false)); |
| 22 gPdfStandardFonts.set("Arial,BoldItalic", SkPdfStandardFontEntry("Arial"
, true, true)); | 22 gPdfStandardFonts.set("Arial,BoldItalic", SkPdfStandardFontEntry("Arial"
, true, true)); |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 88 gPdfStandardFonts.set("DejaVuSansMono-Bold", SkPdfStandardFontEntry("Dej
aVuSans Mono", true, false)); | 88 gPdfStandardFonts.set("DejaVuSansMono-Bold", SkPdfStandardFontEntry("Dej
aVuSans Mono", true, false)); |
| 89 gPdfStandardFonts.set("DejaVuSansMono-Oblique", SkPdfStandardFontEntry("
DejaVuSans Mono", false, true)); | 89 gPdfStandardFonts.set("DejaVuSansMono-Oblique", SkPdfStandardFontEntry("
DejaVuSans Mono", false, true)); |
| 90 gPdfStandardFonts.set("Georgia-Bold", SkPdfStandardFontEntry("Georgia",
true, false)); | 90 gPdfStandardFonts.set("Georgia-Bold", SkPdfStandardFontEntry("Georgia",
true, false)); |
| 91 gPdfStandardFonts.set("Georgia-BoldItalic", SkPdfStandardFontEntry("Geor
gia", true, true)); | 91 gPdfStandardFonts.set("Georgia-BoldItalic", SkPdfStandardFontEntry("Geor
gia", true, true)); |
| 92 gPdfStandardFonts.set("Georgia-Italic", SkPdfStandardFontEntry("Georgia"
, false, true)); | 92 gPdfStandardFonts.set("Georgia-Italic", SkPdfStandardFontEntry("Georgia"
, false, true)); |
| 93 gPdfStandardFonts.set("TrebuchetMS", SkPdfStandardFontEntry("Trebuchet M
S", false, false)); | 93 gPdfStandardFonts.set("TrebuchetMS", SkPdfStandardFontEntry("Trebuchet M
S", false, false)); |
| 94 gPdfStandardFonts.set("TrebuchetMS-Bold", SkPdfStandardFontEntry("Trebuc
het MS", true, false)); | 94 gPdfStandardFonts.set("TrebuchetMS-Bold", SkPdfStandardFontEntry("Trebuc
het MS", true, false)); |
| 95 gPdfStandardFonts.set("Verdana-Bold", SkPdfStandardFontEntry("Verdana",
true, false)); | 95 gPdfStandardFonts.set("Verdana-Bold", SkPdfStandardFontEntry("Verdana",
true, false)); |
| 96 gPdfStandardFonts.set("WenQuanYiMicroHei", SkPdfStandardFontEntry("WenQu
anYi Micro Hei", false, false)); | 96 gPdfStandardFonts.set("WenQuanYiMicroHei", SkPdfStandardFontEntry("WenQu
anYi Micro Hei", false, false)); |
| 97 | 97 |
| 98 // TODO(edisonn): list all phonts available, builf post script name as i
n pdf spec | 98 // TODO(edisonn): list all fonts available, buil post script name as in
pdf spec |
| 99 // TODO(edisonn): Does it work in all OSs ? |
| 99 /* | 100 /* |
| 100 * The PostScript name for the value of BaseFontis determined in one of
two ways: | 101 * The PostScript name for the value of BaseFontis determined in one of
two ways: |
| 101 • Use the PostScript name that is an optional entry in the “name” table of the | 102 • Use the PostScript name that is an optional entry in the “name” table of the |
| 102 TrueType font itself. | 103 TrueType font itself. |
| 103 • In the absence of such an entry in the “name” table, derive a PostScript name | 104 • In the absence of such an entry in the “name” table, derive a PostScript name |
| 104 from the name by which the font is known in the host operating system: on a | 105 from the name by which the font is known in the host operating system: on a |
| 105 Windows system, it is based on the lfFaceName field in a LOGFONT structure; in | 106 Windows system, it is based on the lfFaceName field in a LOGFONT structure; in |
| 106 the Mac OS, it is based on the name of the FONDresource. If the name contains | 107 the Mac OS, it is based on the name of the FONDresource. If the name contains |
| 107 any spaces, the spaces are removed. | 108 any spaces, the spaces are removed. |
| 108 If the font in a source document uses a bold or italic style, but there is no fo
nt | 109 If the font in a source document uses a bold or italic style, but there is no fo
nt |
| 109 data for that style, the host operating system will synthesize the style. In thi
s case, | 110 data for that style, the host operating system will synthesize the style. In thi
s case, |
| 110 a comma and the style name (one of Bold, Italic, or BoldItalic) are appended to
the | 111 a comma and the style name (one of Bold, Italic, or BoldItalic) are appended to
the |
| 111 font name. For example, for a TrueType font that is a bold variant of the New | 112 font name. For example, for a TrueType font that is a bold variant of the New |
| 112 */ | 113 */ |
| 113 | 114 |
| 114 /* | 115 /* |
| 115 * If the value of Subtype is MMType1. | 116 * If the value of Subtype is MMType1. |
| 116 • If the PostScript name of the instance contains spaces, the spaces are replace
d | 117 • If the PostScript name of the instance contains spaces, the spaces are replace
d |
| 117 by underscores in the value of BaseFont. For instance, as illustrated in Example | 118 by underscores in the value of BaseFont. For instance, as illustrated in Example |
| 118 5.7, the name “MinionMM 366 465 11 ” (which ends with a space character) | 119 5.7, the name “MinionMM 366 465 11 ” (which ends with a space character) |
| 119 becomes /MinionMM_366_465_11_. | 120 becomes /MinionMM_366_465_11_. |
| 120 */ | 121 */ |
| 121 | |
| 122 // might not work on all oses ? | |
| 123 // | |
| 124 | |
| 125 } | 122 } |
| 126 | 123 |
| 127 return gPdfStandardFonts; | 124 return gPdfStandardFonts; |
| 128 } | 125 } |
| 129 | 126 |
| 130 SkTypeface* SkTypefaceFromPdfStandardFont(const char* fontName, bool bold, bool
italic) { | 127 SkTypeface* SkTypefaceFromPdfStandardFont(const char* fontName, bool bold, bool
italic) { |
| 131 SkTDict<SkPdfStandardFontEntry>& standardFontMap = getStandardFonts(); | 128 SkTDict<SkPdfStandardFontEntry>& standardFontMap = getStandardFonts(); |
| 132 | 129 |
| 133 SkTypeface* typeface = NULL; | 130 SkTypeface* typeface = NULL; |
| 134 SkPdfStandardFontEntry fontData; | 131 SkPdfStandardFontEntry fontData; |
| (...skipping 13 matching lines...) Expand all Loading... |
| 148 fontName, | 145 fontName, |
| 149 SkTypeface::kNormal); | 146 SkTypeface::kNormal); |
| 150 } | 147 } |
| 151 | 148 |
| 152 if (typeface) { | 149 if (typeface) { |
| 153 typeface->ref(); | 150 typeface->ref(); |
| 154 } | 151 } |
| 155 return typeface; | 152 return typeface; |
| 156 } | 153 } |
| 157 | 154 |
| 158 SkPdfFont* SkPdfFont::fontFromFontDescriptor(SkPdfNativeDoc* doc, SkPdfFontDescr
iptorDictionary* fd, bool loadFromName) { | 155 SkPdfFont* SkPdfFont::fontFromFontDescriptor(SkPdfNativeDoc* doc, SkPdfFontDescr
iptorDictionary* fd, |
| 159 // TODO(edisonn): partial implementation ... also const handling ... | 156 bool loadFromName) { |
| 157 // TODO(edisonn): partial implementation. |
| 160 // Only one, at most be available | 158 // Only one, at most be available |
| 161 SkPdfStream* pdfStream = NULL; | 159 SkPdfStream* pdfStream = NULL; |
| 162 if (fd->has_FontFile()) { | 160 if (fd->has_FontFile()) { |
| 163 pdfStream = fd->FontFile(doc); | 161 pdfStream = fd->FontFile(doc); |
| 164 } else if (fd->has_FontFile2()) { | 162 } else if (fd->has_FontFile2()) { |
| 165 pdfStream = fd->FontFile2(doc); | 163 pdfStream = fd->FontFile2(doc); |
| 166 } if (fd->has_FontFile3()) { | 164 } if (fd->has_FontFile3()) { |
| 167 pdfStream = fd->FontFile3(doc); | 165 pdfStream = fd->FontFile3(doc); |
| 168 } else { | 166 } else { |
| 169 if (loadFromName) { | 167 if (loadFromName) { |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 226 } | 224 } |
| 227 | 225 |
| 228 // TODO(edisonn): warning/report issue | 226 // TODO(edisonn): warning/report issue |
| 229 return SkPdfFont::Default(); | 227 return SkPdfFont::Default(); |
| 230 } | 228 } |
| 231 | 229 |
| 232 SkPdfFont* SkPdfFont::fontFromPdfDictionaryOnce(SkPdfNativeDoc* doc, SkPdfFontDi
ctionary* dict) { | 230 SkPdfFont* SkPdfFont::fontFromPdfDictionaryOnce(SkPdfNativeDoc* doc, SkPdfFontDi
ctionary* dict) { |
| 233 // TODO(edisonn): keep the type in a smart way in the SkPdfNativeObject | 231 // TODO(edisonn): keep the type in a smart way in the SkPdfNativeObject |
| 234 // 1) flag, isResolved (1bit): reset at reset, add/remove/update (array) and
set(dict) | 232 // 1) flag, isResolved (1bit): reset at reset, add/remove/update (array) and
set(dict) |
| 235 // in a tree like structure, 3-4 bits for all the datatypes inheriting from
obj (int, real, ...) | 233 // in a tree like structure, 3-4 bits for all the datatypes inheriting from
obj (int, real, ...) |
| 236 // if is a dict, reserveve a few bytes to encode type of dict, and so on lik
e in a tree | 234 // if is a dict, reserve a few bytes to encode type of dict, and so on like
in a tree |
| 237 // issue: type can be determined from context! atribute night be missing/wro
ng | 235 // issue: type can be determined from context! atribute night be missing/wro
ng |
| 238 switch (doc->mapper()->mapFontDictionary(dict)) { | 236 switch (doc->mapper()->mapFontDictionary(dict)) { |
| 239 case kType0FontDictionary_SkPdfNativeObjectType: | 237 case kType0FontDictionary_SkPdfNativeObjectType: |
| 240 return fontFromType0FontDictionary(doc, dict->asType0FontDictionary(
)); | 238 return fontFromType0FontDictionary(doc, dict->asType0FontDictionary(
)); |
| 241 | 239 |
| 242 case kTrueTypeFontDictionary_SkPdfNativeObjectType: | 240 case kTrueTypeFontDictionary_SkPdfNativeObjectType: |
| 243 return fontFromTrueTypeFontDictionary(doc, dict->asTrueTypeFontDicti
onary()); | 241 return fontFromTrueTypeFontDictionary(doc, dict->asTrueTypeFontDicti
onary()); |
| 244 | 242 |
| 245 case kType1FontDictionary_SkPdfNativeObjectType: | 243 case kType1FontDictionary_SkPdfNativeObjectType: |
| 246 return fontFromType1FontDictionary(doc, dict->asType1FontDictionary(
)); | 244 return fontFromType1FontDictionary(doc, dict->asType1FontDictionary(
)); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 263 } | 261 } |
| 264 | 262 |
| 265 if (!dict->hasData(SkPdfNativeObject::kFont_Data)) { | 263 if (!dict->hasData(SkPdfNativeObject::kFont_Data)) { |
| 266 dict->setData(fontFromPdfDictionaryOnce(doc, dict), SkPdfNativeObject::k
Font_Data); | 264 dict->setData(fontFromPdfDictionaryOnce(doc, dict), SkPdfNativeObject::k
Font_Data); |
| 267 } | 265 } |
| 268 return (SkPdfFont*)dict->data(SkPdfNativeObject::kFont_Data); | 266 return (SkPdfFont*)dict->data(SkPdfNativeObject::kFont_Data); |
| 269 } | 267 } |
| 270 | 268 |
| 271 | 269 |
| 272 | 270 |
| 273 SkPdfType0Font* SkPdfFont::fontFromType0FontDictionary(SkPdfNativeDoc* doc, SkPd
fType0FontDictionary* dict) { | 271 SkPdfType0Font* SkPdfFont::fontFromType0FontDictionary(SkPdfNativeDoc* doc, |
| 272 SkPdfType0FontDictionary*
dict) { |
| 274 if (dict == NULL) { | 273 if (dict == NULL) { |
| 275 return NULL; // default one? | 274 return NULL; // default one? |
| 276 } | 275 } |
| 277 | 276 |
| 278 return new SkPdfType0Font(doc, dict); | 277 return new SkPdfType0Font(doc, dict); |
| 279 } | 278 } |
| 280 | 279 |
| 281 SkPdfType1Font* SkPdfFont:: fontFromType1FontDictionary(SkPdfNativeDoc* doc, SkP
dfType1FontDictionary* dict) { | 280 SkPdfType1Font* SkPdfFont:: fontFromType1FontDictionary(SkPdfNativeDoc* doc, |
| 281 SkPdfType1FontDictionary
* dict) { |
| 282 if (dict == NULL) { | 282 if (dict == NULL) { |
| 283 return NULL; // default one? | 283 return NULL; // default one? |
| 284 } | 284 } |
| 285 | 285 |
| 286 return new SkPdfType1Font(doc, dict); | 286 return new SkPdfType1Font(doc, dict); |
| 287 } | 287 } |
| 288 | 288 |
| 289 SkPdfType3Font* SkPdfFont::fontFromType3FontDictionary(SkPdfNativeDoc* doc, SkPd
fType3FontDictionary* dict) { | 289 SkPdfType3Font* SkPdfFont::fontFromType3FontDictionary(SkPdfNativeDoc* doc, |
| 290 SkPdfType3FontDictionary*
dict) { |
| 290 if (dict == NULL) { | 291 if (dict == NULL) { |
| 291 return NULL; // default one? | 292 return NULL; // default one? |
| 292 } | 293 } |
| 293 | 294 |
| 294 | 295 |
| 295 | 296 |
| 296 return new SkPdfType3Font(doc, dict); | 297 return new SkPdfType3Font(doc, dict); |
| 297 } | 298 } |
| 298 | 299 |
| 299 SkPdfTrueTypeFont* SkPdfFont::fontFromTrueTypeFontDictionary(SkPdfNativeDoc* doc
, SkPdfTrueTypeFontDictionary* dict) { | 300 SkPdfTrueTypeFont* SkPdfFont::fontFromTrueTypeFontDictionary(SkPdfNativeDoc* doc
, |
| 301 SkPdfTrueTypeFontDi
ctionary* dict) { |
| 300 if (dict == NULL) { | 302 if (dict == NULL) { |
| 301 return NULL; // default one? | 303 return NULL; // default one? |
| 302 } | 304 } |
| 303 | 305 |
| 304 return new SkPdfTrueTypeFont(doc, dict); | 306 return new SkPdfTrueTypeFont(doc, dict); |
| 305 } | 307 } |
| 306 | 308 |
| 307 SkPdfMultiMasterFont* SkPdfFont::fontFromMultiMasterFontDictionary(SkPdfNativeDo
c* doc, SkPdfMultiMasterFontDictionary* dict) { | 309 SkPdfMultiMasterFont* SkPdfFont::fontFromMultiMasterFontDictionary( |
| 310 SkPdfNativeDoc* doc, SkPdfMultiMasterFontDictionary* dict) { |
| 308 if (dict == NULL) { | 311 if (dict == NULL) { |
| 309 return NULL; // default one? | 312 return NULL; // default one? |
| 310 } | 313 } |
| 311 | 314 |
| 312 return new SkPdfMultiMasterFont(doc, dict); | 315 return new SkPdfMultiMasterFont(doc, dict); |
| 313 } | 316 } |
| 314 | 317 |
| 315 static int skstoi(const SkPdfNativeObject* str) { | 318 static int skstoi(const SkPdfNativeObject* str) { |
| 316 // TODO(edisonn): report err of it is not a (hex) string | 319 // TODO(edisonn): report err of it is not a (hex) string |
| 317 int ret = 0; | 320 int ret = 0; |
| 318 for (unsigned int i = 0 ; i < str->lenstr(); i++) { | 321 for (unsigned int i = 0 ; i < str->lenstr(); i++) { |
| 319 ret = (ret << 8) + ((unsigned char*)str->c_str())[i]; | 322 ret = (ret << 8) + ((unsigned char*)str->c_str())[i]; |
| 320 } | 323 } |
| 321 // TODO(edisonn): character larger than 0x0000ffff not supported right now. | 324 // TODO(edisonn): character larger than 0x0000ffff not supported right now. |
| 322 return ret & 0x0000ffff; | 325 return ret & 0x0000ffff; |
| 323 } | 326 } |
| 324 | 327 |
| 325 #define tokenIsKeyword(token,keyword) (token.fType == kKeyword_TokenType && toke
n.fKeywordLength==sizeof(keyword)-1 && strncmp(token.fKeyword, keyword, sizeof(k
eyword)-1) == 0) | 328 #define tokenIsKeyword(token,keyword) (token.fType == kKeyword_TokenType && \ |
| 329 token.fKeywordLength==sizeof(keyword)-1 &&
\ |
| 330 strncmp(token.fKeyword, keyword, sizeof(ke
yword)-1) == 0) |
| 326 | 331 |
| 327 SkPdfToUnicode::SkPdfToUnicode(SkPdfNativeDoc* parsed, SkPdfStream* stream) : fP
arsed(parsed) { | 332 SkPdfToUnicode::SkPdfToUnicode(SkPdfNativeDoc* parsed, SkPdfStream* stream) : fP
arsed(parsed) { |
| 328 fCMapEncoding = NULL; | 333 fCMapEncoding = NULL; |
| 329 fCMapEncodingFlag = NULL; | 334 fCMapEncodingFlag = NULL; |
| 330 | 335 |
| 331 if (stream) { | 336 if (stream) { |
| 332 // Since font will be cached, the font has to sit in the per doc allocat
or, not to be | 337 // Since font will be cached, the font has to sit in the per doc allocat
or, not to be |
| 333 // freed after the page is done drawing. | 338 // freed after the page is done drawing. |
| 334 SkPdfNativeTokenizer* tokenizer = fParsed->tokenizerOfStream(stream, par
sed->allocator()); | 339 SkPdfNativeTokenizer* tokenizer = fParsed->tokenizerOfStream(stream, par
sed->allocator()); |
| 335 PdfToken token; | 340 PdfToken token; |
| 336 | 341 |
| 337 fCMapEncoding = new unsigned short[256 * 256]; | 342 fCMapEncoding = new unsigned short[256 * 256]; |
| 338 fCMapEncodingFlag = new unsigned char[256 * 256]; | 343 fCMapEncodingFlag = new unsigned char[256 * 256]; |
| 339 for (int i = 0 ; i < 256 * 256; i++) { | 344 for (int i = 0 ; i < 256 * 256; i++) { |
| 340 fCMapEncoding[i] = i; | 345 fCMapEncoding[i] = i; |
| 341 fCMapEncodingFlag[i] = 0; | 346 fCMapEncodingFlag[i] = 0; |
| 342 } | 347 } |
| 343 | 348 |
| 344 // TODO(edisonn): deal with multibyte character, or longer strings. | 349 // TODO(edisonn): deal with multibyte character, or longer strings. |
| 345 // Ritght now we deal with up 2 characters, e.g. <0020> but not longer l
ike <00660066006C> | 350 // Right now we deal with up 2 characters, e.g. <0020> but not longer li
ke <00660066006C> |
| 346 //2 beginbfrange | 351 //2 beginbfrange |
| 347 //<0000> <005E> <0020> | 352 //<0000> <005E> <0020> |
| 348 //<005F> <0061> [<00660066> <00660069> <00660066006C>] | 353 //<005F> <0061> [<00660066> <00660069> <00660066006C>] |
| 349 | 354 |
| 350 while (tokenizer->readToken(&token)) { | 355 while (tokenizer->readToken(&token)) { |
| 351 | 356 |
| 352 // TODO(edisonn): perf, macro that would make equal first for token.
fKeywordLength with sizeof(keyword), instead od strlen, make sure it is keyword,
not a char* | |
| 353 if (tokenIsKeyword(token, "begincodespacerange")) { | 357 if (tokenIsKeyword(token, "begincodespacerange")) { |
| 354 while (tokenizer->readToken(&token) && !tokenIsKeyword(token, "e
ndcodespacerange")) { | 358 while (tokenizer->readToken(&token) && |
| 359 !tokenIsKeyword(token, "endcodespacerange")) { |
| 355 // tokenizer->PutBack(token); | 360 // tokenizer->PutBack(token); |
| 356 // tokenizer->readToken(&token); | 361 // tokenizer->readToken(&token); |
| 357 // TODO(edisonn): check token type! ignore/report errors. | 362 // TODO(edisonn): check token type! ignore/report errors. |
| 358 int start = skstoi(token.fObject); | 363 int start = skstoi(token.fObject); |
| 359 tokenizer->readToken(&token); | 364 tokenizer->readToken(&token); |
| 360 int end = skstoi(token.fObject); | 365 int end = skstoi(token.fObject); |
| 361 for (int i = start; i <= end; i++) { | 366 for (int i = start; i <= end; i++) { |
| 362 fCMapEncodingFlag[i] |= 1; | 367 fCMapEncodingFlag[i] |= 1; |
| 363 } | 368 } |
| 364 } | 369 } |
| (...skipping 15 matching lines...) Expand all Loading... |
| 380 if (tokenIsKeyword(token, "beginbfrange")) { | 385 if (tokenIsKeyword(token, "beginbfrange")) { |
| 381 while (tokenizer->readToken(&token) && !tokenIsKeyword(token, "e
ndbfrange")) { | 386 while (tokenizer->readToken(&token) && !tokenIsKeyword(token, "e
ndbfrange")) { |
| 382 // tokenizer->PutBack(token); | 387 // tokenizer->PutBack(token); |
| 383 // tokenizer->readToken(&token); | 388 // tokenizer->readToken(&token); |
| 384 int start = skstoi(token.fObject); | 389 int start = skstoi(token.fObject); |
| 385 tokenizer->readToken(&token); | 390 tokenizer->readToken(&token); |
| 386 int end = skstoi(token.fObject); | 391 int end = skstoi(token.fObject); |
| 387 | 392 |
| 388 | 393 |
| 389 tokenizer->readToken(&token); // [ or just an array directly
? | 394 tokenizer->readToken(&token); // [ or just an array directly
? |
| 395 // do not putback, we will reuse the read. See next commente
d read. |
| 390 // tokenizer->PutBack(token); | 396 // tokenizer->PutBack(token); |
| 391 | 397 |
| 392 // TODO(edisonn): read spec: any string or only hex string? | 398 // TODO(edisonn): read spec: any string or only hex string? |
| 393 if (token.fType == kObject_TokenType && token.fObject->isAny
String()) { | 399 if (token.fType == kObject_TokenType && token.fObject->isAny
String()) { |
| 394 // tokenizer->readToken(&token); | 400 // tokenizer->readToken(&token); |
| 395 int value = skstoi(token.fObject); | 401 int value = skstoi(token.fObject); |
| 396 | 402 |
| 397 for (int i = start; i <= end; i++) { | 403 for (int i = start; i <= end; i++) { |
| 398 fCMapEncodingFlag[i] |= 2; | 404 fCMapEncodingFlag[i] |= 2; |
| 399 fCMapEncoding[i] = value; | 405 fCMapEncoding[i] = value; |
| 400 value++; | 406 value++; |
| 401 // if i != end, verify last byte id not if, ignore/r
eport error | 407 // if i != end, verify last byte id not if, ignore/r
eport error |
| 402 } | 408 } |
| 403 | 409 |
| 404 // read one string | 410 // read one string |
| 405 } else if (token.fType == kObject_TokenType && token.fObject
->isArray()) { | 411 } else if (token.fType == kObject_TokenType && token.fObject
->isArray()) { |
| 406 // tokenizer->readToken(&token); | 412 // tokenizer->readToken(&token); |
| 413 // read array |
| 407 for (unsigned int i = 0; i < token.fObject->size(); i++)
{ | 414 for (unsigned int i = 0; i < token.fObject->size(); i++)
{ |
| 408 fCMapEncodingFlag[start + i] |= 2; | 415 fCMapEncodingFlag[start + i] |= 2; |
| 409 fCMapEncoding[start + i] = skstoi((*token.fObject)[i
]); | 416 fCMapEncoding[start + i] = skstoi((*token.fObject)[i
]); |
| 410 } | 417 } |
| 411 // read array | 418 } else { |
| 419 tokenizer->PutBack(token); |
| 412 } | 420 } |
| 413 | |
| 414 //fCMapEncodingFlag[from] = 1; | |
| 415 //fCMapEncoding[from] = to; | |
| 416 } | 421 } |
| 417 } | 422 } |
| 418 } | 423 } |
| 419 } | 424 } |
| 420 } | 425 } |
| 421 | 426 |
| 422 | |
| 423 SkPdfType0Font::SkPdfType0Font(SkPdfNativeDoc* doc, SkPdfType0FontDictionary* di
ct) { | 427 SkPdfType0Font::SkPdfType0Font(SkPdfNativeDoc* doc, SkPdfType0FontDictionary* di
ct) { |
| 424 fBaseFont = fontFromName(doc, dict, dict->BaseFont(doc).c_str()); | 428 fBaseFont = fontFromName(doc, dict, dict->BaseFont(doc).c_str()); |
| 425 fEncoding = NULL; | 429 fEncoding = NULL; |
| 426 | 430 |
| 427 if (dict->has_Encoding()) { | 431 if (dict->has_Encoding()) { |
| 428 if (dict->isEncodingAName(doc)) { | 432 if (dict->isEncodingAName(doc)) { |
| 429 fEncoding = SkPdfEncoding::fromName(dict->getEncodingAsName(doc).c_s
tr()); | 433 fEncoding = SkPdfEncoding::fromName(dict->getEncodingAsName(doc).c_s
tr()); |
| 430 } else if (dict->isEncodingAStream(doc)) { | 434 } else if (dict->isEncodingAStream(doc)) { |
| 435 // TODO(edisonn): NYI |
| 431 //fEncoding = loadEncodingFromStream(dict->getEncodingAsStream()); | 436 //fEncoding = loadEncodingFromStream(dict->getEncodingAsStream()); |
| 432 } else { | 437 } else { |
| 433 // TODO(edisonn): error ... warning .. assert? | 438 // TODO(edisonn): error ... warning .. assert? |
| 434 } | 439 } |
| 435 } | 440 } |
| 436 | 441 |
| 437 if (dict->has_ToUnicode()) { | 442 if (dict->has_ToUnicode()) { |
| 438 fToUnicode = new SkPdfToUnicode(doc, dict->ToUnicode(doc)); | 443 fToUnicode = new SkPdfToUnicode(doc, dict->ToUnicode(doc)); |
| 439 } | 444 } |
| 440 } | 445 } |
| 441 | 446 |
| 442 SkTDict<SkPdfEncoding*>& getStandardEncodings() { | 447 SkTDict<SkPdfEncoding*>& getStandardEncodings() { |
| 443 static SkTDict<SkPdfEncoding*> encodings(10); | 448 static SkTDict<SkPdfEncoding*> encodings(10); |
| 444 if (encodings.count() == 0) { | 449 if (encodings.count() == 0) { |
| 445 encodings.set("Identity-H", SkPdfIdentityHEncoding::instance()); | 450 encodings.set("Identity-H", SkPdfIdentityHEncoding::instance()); |
| 446 } | 451 } |
| 447 | 452 |
| 448 return encodings; | 453 return encodings; |
| 449 } | 454 } |
| 450 | 455 |
| 451 SkPdfEncoding* SkPdfEncoding::fromName(const char* name) { | 456 SkPdfEncoding* SkPdfEncoding::fromName(const char* name) { |
| 452 SkPdfEncoding* encoding = NULL; | 457 SkPdfEncoding* encoding = NULL; |
| 453 if (!getStandardEncodings().find(name, &encoding)) { | 458 if (!getStandardEncodings().find(name, &encoding)) { |
| 454 // TODO(edisonn): if the function return false, and we a guaranteed that
the value is not | |
| 455 // changed, delete this set to null | |
| 456 encoding = NULL; | 459 encoding = NULL; |
| 457 } | 460 } |
| 458 | 461 |
| 459 #ifdef PDF_TRACE | 462 #ifdef PDF_TRACE |
| 460 if (encoding == NULL) { | 463 if (encoding == NULL) { |
| 461 printf("Encoding not found: %s\n", name); | 464 printf("Encoding not found: %s\n", name); |
| 462 } | 465 } |
| 463 #endif | 466 #endif |
| 464 return encoding; | 467 return encoding; |
| 465 } | 468 } |
| OLD | NEW |