| OLD | NEW |
| 1 #include "SkPdfFont.h" | 1 #include "SkPdfFont.h" |
| 2 | 2 |
| 3 #include "SkStream.h" | 3 #include "SkStream.h" |
| 4 #include "SkTypeface.h" | 4 #include "SkTypeface.h" |
| 5 #include "SkPdfNativeTokenizer.h" | 5 #include "SkPdfNativeTokenizer.h" |
| 6 | 6 |
| 7 std::map<std::string, SkPdfStandardFontEntry>& getStandardFonts() { | 7 std::map<std::string, SkPdfStandardFontEntry>& getStandardFonts() { |
| 8 static std::map<std::string, SkPdfStandardFontEntry> gPdfStandardFonts; | 8 static std::map<std::string, SkPdfStandardFontEntry> gPdfStandardFonts; |
| 9 | 9 |
| 10 // TODO (edisonn): , vs - ? what does it mean? | 10 // TODO (edisonn): , vs - ? what does it mean? |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 141 fontName, | 141 fontName, |
| 142 SkTypeface::kNormal); | 142 SkTypeface::kNormal); |
| 143 } | 143 } |
| 144 | 144 |
| 145 if (typeface) { | 145 if (typeface) { |
| 146 typeface->ref(); | 146 typeface->ref(); |
| 147 } | 147 } |
| 148 return typeface; | 148 return typeface; |
| 149 } | 149 } |
| 150 | 150 |
| 151 SkPdfFont* SkPdfFont::fontFromFontDescriptor(SkNativeParsedPDF* doc, SkPdfFontDe
scriptorDictionary* fd, bool loadFromName) { | 151 SkPdfFont* SkPdfFont::fontFromFontDescriptor(SkPdfNativeDoc* doc, SkPdfFontDescr
iptorDictionary* fd, bool loadFromName) { |
| 152 // TODO(edisonn): partial implementation ... also const handling ... | 152 // TODO(edisonn): partial implementation ... also const handling ... |
| 153 // Only one, at most be available | 153 // Only one, at most be available |
| 154 SkPdfStream* pdfStream = NULL; | 154 SkPdfStream* pdfStream = NULL; |
| 155 if (fd->has_FontFile()) { | 155 if (fd->has_FontFile()) { |
| 156 pdfStream = fd->FontFile(doc); | 156 pdfStream = fd->FontFile(doc); |
| 157 } else if (fd->has_FontFile2()) { | 157 } else if (fd->has_FontFile2()) { |
| 158 pdfStream = fd->FontFile2(doc); | 158 pdfStream = fd->FontFile2(doc); |
| 159 } if (fd->has_FontFile3()) { | 159 } if (fd->has_FontFile3()) { |
| 160 pdfStream = fd->FontFile3(doc); | 160 pdfStream = fd->FontFile3(doc); |
| 161 } else { | 161 } else { |
| (...skipping 19 matching lines...) Expand all Loading... |
| 181 if (face == NULL) { | 181 if (face == NULL) { |
| 182 // TODO(edisonn): report warning to be used in testing. | 182 // TODO(edisonn): report warning to be used in testing. |
| 183 return NULL; | 183 return NULL; |
| 184 } | 184 } |
| 185 | 185 |
| 186 face->ref(); | 186 face->ref(); |
| 187 | 187 |
| 188 return new SkPdfStandardFont(face); | 188 return new SkPdfStandardFont(face); |
| 189 } | 189 } |
| 190 | 190 |
| 191 SkPdfFont* fontFromName(SkNativeParsedPDF* doc, SkPdfObject* obj, const char* fo
ntName) { | 191 SkPdfFont* fontFromName(SkPdfNativeDoc* doc, SkPdfNativeObject* obj, const char*
fontName) { |
| 192 SkTypeface* typeface = SkTypefaceFromPdfStandardFont(fontName, false, false)
; | 192 SkTypeface* typeface = SkTypefaceFromPdfStandardFont(fontName, false, false)
; |
| 193 if (typeface != NULL) { | 193 if (typeface != NULL) { |
| 194 return new SkPdfStandardFont(typeface); | 194 return new SkPdfStandardFont(typeface); |
| 195 } | 195 } |
| 196 | 196 |
| 197 // TODO(edisonn): perf - make a map | 197 // TODO(edisonn): perf - make a map |
| 198 for (unsigned int i = 0 ; i < doc->objects(); i++) { | 198 for (unsigned int i = 0 ; i < doc->objects(); i++) { |
| 199 SkPdfObject* obj = doc->object(i); | 199 SkPdfNativeObject* obj = doc->object(i); |
| 200 if (!obj || !obj->isDictionary()) { | 200 if (!obj || !obj->isDictionary()) { |
| 201 continue; | 201 continue; |
| 202 } | 202 } |
| 203 | 203 |
| 204 SkPdfFontDescriptorDictionary* fd = obj->asDictionary()->asFontDescripto
rDictionary(); | 204 SkPdfFontDescriptorDictionary* fd = obj->asDictionary()->asFontDescripto
rDictionary(); |
| 205 | 205 |
| 206 if (!fd->valid()) { | 206 if (!fd->valid()) { |
| 207 continue; | 207 continue; |
| 208 } | 208 } |
| 209 | 209 |
| 210 if (fd->has_FontName() && fd->FontName(doc) == fontName) { | 210 if (fd->has_FontName() && fd->FontName(doc) == fontName) { |
| 211 SkPdfFont* font = SkPdfFont::fontFromFontDescriptor(doc, fd, false); | 211 SkPdfFont* font = SkPdfFont::fontFromFontDescriptor(doc, fd, false); |
| 212 if (font) { | 212 if (font) { |
| 213 return font; | 213 return font; |
| 214 } else { | 214 } else { |
| 215 // failed to load font descriptor | 215 // failed to load font descriptor |
| 216 break; | 216 break; |
| 217 } | 217 } |
| 218 } | 218 } |
| 219 } | 219 } |
| 220 | 220 |
| 221 // TODO(edisonn): warning/report issue | 221 // TODO(edisonn): warning/report issue |
| 222 return SkPdfFont::Default(); | 222 return SkPdfFont::Default(); |
| 223 } | 223 } |
| 224 | 224 |
| 225 SkPdfFont* SkPdfFont::fontFromPdfDictionaryOnce(SkNativeParsedPDF* doc, SkPdfFon
tDictionary* dict) { | 225 SkPdfFont* SkPdfFont::fontFromPdfDictionaryOnce(SkPdfNativeDoc* doc, SkPdfFontDi
ctionary* dict) { |
| 226 // TODO(edisonn): keep the type in a smart way in the SkPdfObject | 226 // TODO(edisonn): keep the type in a smart way in the SkPdfNativeObject |
| 227 // 1) flag, isResolved (1bit): reset at reset, add/remove/update (array) and
set(dict) | 227 // 1) flag, isResolved (1bit): reset at reset, add/remove/update (array) and
set(dict) |
| 228 // in a tree like structure, 3-4 bits for all the datatypes inheriting from
obj (int, real, ...) | 228 // in a tree like structure, 3-4 bits for all the datatypes inheriting from
obj (int, real, ...) |
| 229 // if is a dict, reserveve a few bytes to encode type of dict, and so on lik
e in a tree | 229 // if is a dict, reserveve a few bytes to encode type of dict, and so on lik
e in a tree |
| 230 // issue: type can be determined from context! atribute night be missing/wro
ng | 230 // issue: type can be determined from context! atribute night be missing/wro
ng |
| 231 switch (doc->mapper()->mapFontDictionary(dict)) { | 231 switch (doc->mapper()->mapFontDictionary(dict)) { |
| 232 case kType0FontDictionary_SkPdfObjectType: | 232 case kType0FontDictionary_SkPdfNativeObjectType: |
| 233 return fontFromType0FontDictionary(doc, dict->asType0FontDictionary(
)); | 233 return fontFromType0FontDictionary(doc, dict->asType0FontDictionary(
)); |
| 234 | 234 |
| 235 case kTrueTypeFontDictionary_SkPdfObjectType: | 235 case kTrueTypeFontDictionary_SkPdfNativeObjectType: |
| 236 return fontFromTrueTypeFontDictionary(doc, dict->asTrueTypeFontDicti
onary()); | 236 return fontFromTrueTypeFontDictionary(doc, dict->asTrueTypeFontDicti
onary()); |
| 237 | 237 |
| 238 case kType1FontDictionary_SkPdfObjectType: | 238 case kType1FontDictionary_SkPdfNativeObjectType: |
| 239 return fontFromType1FontDictionary(doc, dict->asType1FontDictionary(
)); | 239 return fontFromType1FontDictionary(doc, dict->asType1FontDictionary(
)); |
| 240 | 240 |
| 241 case kMultiMasterFontDictionary_SkPdfObjectType: | 241 case kMultiMasterFontDictionary_SkPdfNativeObjectType: |
| 242 return fontFromMultiMasterFontDictionary(doc, dict->asMultiMasterFon
tDictionary()); | 242 return fontFromMultiMasterFontDictionary(doc, dict->asMultiMasterFon
tDictionary()); |
| 243 | 243 |
| 244 case kType3FontDictionary_SkPdfObjectType: | 244 case kType3FontDictionary_SkPdfNativeObjectType: |
| 245 return fontFromType3FontDictionary(doc, dict->asType3FontDictionary(
)); | 245 return fontFromType3FontDictionary(doc, dict->asType3FontDictionary(
)); |
| 246 | 246 |
| 247 default: | 247 default: |
| 248 // TODO(edisonn): report error? | 248 // TODO(edisonn): report error? |
| 249 return NULL; | 249 return NULL; |
| 250 } | 250 } |
| 251 } | 251 } |
| 252 | 252 |
| 253 SkPdfFont* SkPdfFont::fontFromPdfDictionary(SkNativeParsedPDF* doc, SkPdfFontDic
tionary* dict) { | 253 SkPdfFont* SkPdfFont::fontFromPdfDictionary(SkPdfNativeDoc* doc, SkPdfFontDictio
nary* dict) { |
| 254 if (dict == NULL) { | 254 if (dict == NULL) { |
| 255 return NULL; // TODO(edisonn): report default one? | 255 return NULL; // TODO(edisonn): report default one? |
| 256 } | 256 } |
| 257 | 257 |
| 258 if (!dict->hasData(SkPdfObject::kFont_Data)) { | 258 if (!dict->hasData(SkPdfNativeObject::kFont_Data)) { |
| 259 dict->setData(fontFromPdfDictionaryOnce(doc, dict), SkPdfObject::kFont_D
ata); | 259 dict->setData(fontFromPdfDictionaryOnce(doc, dict), SkPdfNativeObject::k
Font_Data); |
| 260 } | 260 } |
| 261 return (SkPdfFont*)dict->data(SkPdfObject::kFont_Data); | 261 return (SkPdfFont*)dict->data(SkPdfNativeObject::kFont_Data); |
| 262 } | 262 } |
| 263 | 263 |
| 264 | 264 |
| 265 | 265 |
| 266 SkPdfType0Font* SkPdfFont::fontFromType0FontDictionary(SkNativeParsedPDF* doc, S
kPdfType0FontDictionary* dict) { | 266 SkPdfType0Font* SkPdfFont::fontFromType0FontDictionary(SkPdfNativeDoc* doc, SkPd
fType0FontDictionary* dict) { |
| 267 if (dict == NULL) { | 267 if (dict == NULL) { |
| 268 return NULL; // default one? | 268 return NULL; // default one? |
| 269 } | 269 } |
| 270 | 270 |
| 271 return new SkPdfType0Font(doc, dict); | 271 return new SkPdfType0Font(doc, dict); |
| 272 } | 272 } |
| 273 | 273 |
| 274 SkPdfType1Font* SkPdfFont:: fontFromType1FontDictionary(SkNativeParsedPDF* doc,
SkPdfType1FontDictionary* dict) { | 274 SkPdfType1Font* SkPdfFont:: fontFromType1FontDictionary(SkPdfNativeDoc* doc, SkP
dfType1FontDictionary* dict) { |
| 275 if (dict == NULL) { | 275 if (dict == NULL) { |
| 276 return NULL; // default one? | 276 return NULL; // default one? |
| 277 } | 277 } |
| 278 | 278 |
| 279 return new SkPdfType1Font(doc, dict); | 279 return new SkPdfType1Font(doc, dict); |
| 280 } | 280 } |
| 281 | 281 |
| 282 SkPdfType3Font* SkPdfFont::fontFromType3FontDictionary(SkNativeParsedPDF* doc, S
kPdfType3FontDictionary* dict) { | 282 SkPdfType3Font* SkPdfFont::fontFromType3FontDictionary(SkPdfNativeDoc* doc, SkPd
fType3FontDictionary* dict) { |
| 283 if (dict == NULL) { | 283 if (dict == NULL) { |
| 284 return NULL; // default one? | 284 return NULL; // default one? |
| 285 } | 285 } |
| 286 | 286 |
| 287 | 287 |
| 288 | 288 |
| 289 return new SkPdfType3Font(doc, dict); | 289 return new SkPdfType3Font(doc, dict); |
| 290 } | 290 } |
| 291 | 291 |
| 292 SkPdfTrueTypeFont* SkPdfFont::fontFromTrueTypeFontDictionary(SkNativeParsedPDF*
doc, SkPdfTrueTypeFontDictionary* dict) { | 292 SkPdfTrueTypeFont* SkPdfFont::fontFromTrueTypeFontDictionary(SkPdfNativeDoc* doc
, SkPdfTrueTypeFontDictionary* dict) { |
| 293 if (dict == NULL) { | 293 if (dict == NULL) { |
| 294 return NULL; // default one? | 294 return NULL; // default one? |
| 295 } | 295 } |
| 296 | 296 |
| 297 return new SkPdfTrueTypeFont(doc, dict); | 297 return new SkPdfTrueTypeFont(doc, dict); |
| 298 } | 298 } |
| 299 | 299 |
| 300 SkPdfMultiMasterFont* SkPdfFont::fontFromMultiMasterFontDictionary(SkNativeParse
dPDF* doc, SkPdfMultiMasterFontDictionary* dict) { | 300 SkPdfMultiMasterFont* SkPdfFont::fontFromMultiMasterFontDictionary(SkPdfNativeDo
c* doc, SkPdfMultiMasterFontDictionary* dict) { |
| 301 if (dict == NULL) { | 301 if (dict == NULL) { |
| 302 return NULL; // default one? | 302 return NULL; // default one? |
| 303 } | 303 } |
| 304 | 304 |
| 305 return new SkPdfMultiMasterFont(doc, dict); | 305 return new SkPdfMultiMasterFont(doc, dict); |
| 306 } | 306 } |
| 307 | 307 |
| 308 static int skstoi(const SkPdfObject* str) { | 308 static int skstoi(const SkPdfNativeObject* str) { |
| 309 // TODO(edisonn): report err of it is not a (hex) string | 309 // TODO(edisonn): report err of it is not a (hex) string |
| 310 int ret = 0; | 310 int ret = 0; |
| 311 for (unsigned int i = 0 ; i < str->lenstr(); i++) { | 311 for (unsigned int i = 0 ; i < str->lenstr(); i++) { |
| 312 ret = (ret << 8) + ((unsigned char*)str->c_str())[i]; | 312 ret = (ret << 8) + ((unsigned char*)str->c_str())[i]; |
| 313 } | 313 } |
| 314 // TODO(edisonn): character larger than 0x0000ffff not supported right now. | 314 // TODO(edisonn): character larger than 0x0000ffff not supported right now. |
| 315 return ret & 0x0000ffff; | 315 return ret & 0x0000ffff; |
| 316 } | 316 } |
| 317 | 317 |
| 318 #define tokenIsKeyword(token,keyword) (token.fType == kKeyword_TokenType && toke
n.fKeywordLength==sizeof(keyword)-1 && strncmp(token.fKeyword, keyword, sizeof(k
eyword)-1) == 0) | 318 #define tokenIsKeyword(token,keyword) (token.fType == kKeyword_TokenType && toke
n.fKeywordLength==sizeof(keyword)-1 && strncmp(token.fKeyword, keyword, sizeof(k
eyword)-1) == 0) |
| 319 | 319 |
| 320 SkPdfToUnicode::SkPdfToUnicode(SkNativeParsedPDF* parsed, SkPdfStream* stream) :
fParsed(parsed) { | 320 SkPdfToUnicode::SkPdfToUnicode(SkPdfNativeDoc* parsed, SkPdfStream* stream) : fP
arsed(parsed) { |
| 321 fCMapEncoding = NULL; | 321 fCMapEncoding = NULL; |
| 322 fCMapEncodingFlag = NULL; | 322 fCMapEncodingFlag = NULL; |
| 323 | 323 |
| 324 if (stream) { | 324 if (stream) { |
| 325 // Since font will be cached, the font has to sit in the per doc allocat
or, not to be | 325 // Since font will be cached, the font has to sit in the per doc allocat
or, not to be |
| 326 // freed after the page is done drawing. | 326 // freed after the page is done drawing. |
| 327 SkPdfNativeTokenizer* tokenizer = fParsed->tokenizerOfStream(stream, par
sed->allocator()); | 327 SkPdfNativeTokenizer* tokenizer = fParsed->tokenizerOfStream(stream, par
sed->allocator()); |
| 328 PdfToken token; | 328 PdfToken token; |
| 329 | 329 |
| 330 fCMapEncoding = new unsigned short[256 * 256]; | 330 fCMapEncoding = new unsigned short[256 * 256]; |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 406 | 406 |
| 407 //fCMapEncodingFlag[from] = 1; | 407 //fCMapEncodingFlag[from] = 1; |
| 408 //fCMapEncoding[from] = to; | 408 //fCMapEncoding[from] = to; |
| 409 } | 409 } |
| 410 } | 410 } |
| 411 } | 411 } |
| 412 } | 412 } |
| 413 } | 413 } |
| 414 | 414 |
| 415 | 415 |
| 416 SkPdfType0Font::SkPdfType0Font(SkNativeParsedPDF* doc, SkPdfType0FontDictionary*
dict) { | 416 SkPdfType0Font::SkPdfType0Font(SkPdfNativeDoc* doc, SkPdfType0FontDictionary* di
ct) { |
| 417 fBaseFont = fontFromName(doc, dict, dict->BaseFont(doc).c_str()); | 417 fBaseFont = fontFromName(doc, dict, dict->BaseFont(doc).c_str()); |
| 418 fEncoding = NULL; | 418 fEncoding = NULL; |
| 419 | 419 |
| 420 if (dict->has_Encoding()) { | 420 if (dict->has_Encoding()) { |
| 421 if (dict->isEncodingAName(doc)) { | 421 if (dict->isEncodingAName(doc)) { |
| 422 fEncoding = SkPdfEncoding::fromName(dict->getEncodingAsName(doc).c_s
tr()); | 422 fEncoding = SkPdfEncoding::fromName(dict->getEncodingAsName(doc).c_s
tr()); |
| 423 } else if (dict->isEncodingAStream(doc)) { | 423 } else if (dict->isEncodingAStream(doc)) { |
| 424 //fEncoding = loadEncodingFromStream(dict->getEncodingAsStream()); | 424 //fEncoding = loadEncodingFromStream(dict->getEncodingAsStream()); |
| 425 } else { | 425 } else { |
| 426 // TODO(edisonn): error ... warning .. assert? | 426 // TODO(edisonn): error ... warning .. assert? |
| (...skipping 18 matching lines...) Expand all Loading... |
| 445 SkPdfEncoding* SkPdfEncoding::fromName(const char* name) { | 445 SkPdfEncoding* SkPdfEncoding::fromName(const char* name) { |
| 446 SkPdfEncoding* encoding = getStandardEncodings()[name]; | 446 SkPdfEncoding* encoding = getStandardEncodings()[name]; |
| 447 | 447 |
| 448 #ifdef PDF_TRACE | 448 #ifdef PDF_TRACE |
| 449 if (encoding == NULL) { | 449 if (encoding == NULL) { |
| 450 printf("Encoding not found: %s\n", name); | 450 printf("Encoding not found: %s\n", name); |
| 451 } | 451 } |
| 452 #endif | 452 #endif |
| 453 return encoding; | 453 return encoding; |
| 454 } | 454 } |
| OLD | NEW |