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 "SkPdfNativeTokenizer.h" |
(...skipping 318 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
329 token.fKeywordLength==sizeof(keyword)-1 &&
\ | 329 token.fKeywordLength==sizeof(keyword)-1 &&
\ |
330 strncmp(token.fKeyword, keyword, sizeof(ke
yword)-1) == 0) | 330 strncmp(token.fKeyword, keyword, sizeof(ke
yword)-1) == 0) |
331 | 331 |
332 SkPdfToUnicode::SkPdfToUnicode(SkPdfNativeDoc* parsed, SkPdfStream* stream) : fP
arsed(parsed) { | 332 SkPdfToUnicode::SkPdfToUnicode(SkPdfNativeDoc* parsed, SkPdfStream* stream) : fP
arsed(parsed) { |
333 fCMapEncoding = NULL; | 333 fCMapEncoding = NULL; |
334 fCMapEncodingFlag = NULL; | 334 fCMapEncodingFlag = NULL; |
335 | 335 |
336 if (stream) { | 336 if (stream) { |
337 // 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 |
338 // freed after the page is done drawing. | 338 // freed after the page is done drawing. |
339 SkPdfNativeTokenizer* tokenizer = fParsed->tokenizerOfStream(stream, par
sed->allocator()); | 339 SkPdfNativeTokenizer tokenizer(stream, parsed->allocator(), parsed); |
340 PdfToken token; | 340 PdfToken token; |
341 | 341 |
342 fCMapEncoding = new unsigned short[256 * 256]; | 342 fCMapEncoding = new unsigned short[256 * 256]; |
343 fCMapEncodingFlag = new unsigned char[256 * 256]; | 343 fCMapEncodingFlag = new unsigned char[256 * 256]; |
344 for (int i = 0 ; i < 256 * 256; i++) { | 344 for (int i = 0 ; i < 256 * 256; i++) { |
345 fCMapEncoding[i] = i; | 345 fCMapEncoding[i] = i; |
346 fCMapEncodingFlag[i] = 0; | 346 fCMapEncodingFlag[i] = 0; |
347 } | 347 } |
348 | 348 |
349 // TODO(edisonn): deal with multibyte character, or longer strings. | 349 // TODO(edisonn): deal with multibyte character, or longer strings. |
350 // Right now we deal with up 2 characters, e.g. <0020> but not longer li
ke <00660066006C> | 350 // Right now we deal with up 2 characters, e.g. <0020> but not longer li
ke <00660066006C> |
351 //2 beginbfrange | 351 //2 beginbfrange |
352 //<0000> <005E> <0020> | 352 //<0000> <005E> <0020> |
353 //<005F> <0061> [<00660066> <00660069> <00660066006C>] | 353 //<005F> <0061> [<00660066> <00660069> <00660066006C>] |
354 | 354 |
355 while (tokenizer->readToken(&token)) { | 355 while (tokenizer.readToken(&token)) { |
356 | 356 |
357 if (tokenIsKeyword(token, "begincodespacerange")) { | 357 if (tokenIsKeyword(token, "begincodespacerange")) { |
358 while (tokenizer->readToken(&token) && | 358 while (tokenizer.readToken(&token) && |
359 !tokenIsKeyword(token, "endcodespacerange")) { | 359 !tokenIsKeyword(token, "endcodespacerange")) { |
360 // tokenizer->PutBack(token); | 360 // tokenizer.PutBack(token); |
361 // tokenizer->readToken(&token); | 361 // tokenizer.readToken(&token); |
362 // TODO(edisonn): check token type! ignore/report errors. | 362 // TODO(edisonn): check token type! ignore/report errors. |
363 int start = skstoi(token.fObject); | 363 int start = skstoi(token.fObject); |
364 tokenizer->readToken(&token); | 364 tokenizer.readToken(&token); |
365 int end = skstoi(token.fObject); | 365 int end = skstoi(token.fObject); |
366 for (int i = start; i <= end; i++) { | 366 for (int i = start; i <= end; i++) { |
367 fCMapEncodingFlag[i] |= 1; | 367 fCMapEncodingFlag[i] |= 1; |
368 } | 368 } |
369 } | 369 } |
370 } | 370 } |
371 | 371 |
372 if (tokenIsKeyword(token, "beginbfchar")) { | 372 if (tokenIsKeyword(token, "beginbfchar")) { |
373 while (tokenizer->readToken(&token) && !tokenIsKeyword(token, "e
ndbfchar")) { | 373 while (tokenizer.readToken(&token) && !tokenIsKeyword(token, "en
dbfchar")) { |
374 // tokenizer->PutBack(token); | 374 // tokenizer.PutBack(token); |
375 // tokenizer->readToken(&token); | 375 // tokenizer.readToken(&token); |
376 int from = skstoi(token.fObject); | 376 int from = skstoi(token.fObject); |
377 tokenizer->readToken(&token); | 377 tokenizer.readToken(&token); |
378 int to = skstoi(token.fObject); | 378 int to = skstoi(token.fObject); |
379 | 379 |
380 fCMapEncodingFlag[from] |= 2; | 380 fCMapEncodingFlag[from] |= 2; |
381 fCMapEncoding[from] = to; | 381 fCMapEncoding[from] = to; |
382 } | 382 } |
383 } | 383 } |
384 | 384 |
385 if (tokenIsKeyword(token, "beginbfrange")) { | 385 if (tokenIsKeyword(token, "beginbfrange")) { |
386 while (tokenizer->readToken(&token) && !tokenIsKeyword(token, "e
ndbfrange")) { | 386 while (tokenizer.readToken(&token) && !tokenIsKeyword(token, "en
dbfrange")) { |
387 // tokenizer->PutBack(token); | 387 // tokenizer.PutBack(token); |
388 // tokenizer->readToken(&token); | 388 // tokenizer.readToken(&token); |
389 int start = skstoi(token.fObject); | 389 int start = skstoi(token.fObject); |
390 tokenizer->readToken(&token); | 390 tokenizer.readToken(&token); |
391 int end = skstoi(token.fObject); | 391 int end = skstoi(token.fObject); |
392 | 392 |
393 | 393 |
394 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. | 395 // do not putback, we will reuse the read. See next commente
d read. |
396 // tokenizer->PutBack(token); | 396 // tokenizer.PutBack(token); |
397 | 397 |
398 // TODO(edisonn): read spec: any string or only hex string? | 398 // TODO(edisonn): read spec: any string or only hex string? |
399 if (token.fType == kObject_TokenType && token.fObject->isAny
String()) { | 399 if (token.fType == kObject_TokenType && token.fObject->isAny
String()) { |
400 // tokenizer->readToken(&token); | 400 // tokenizer.readToken(&token); |
401 int value = skstoi(token.fObject); | 401 int value = skstoi(token.fObject); |
402 | 402 |
403 for (int i = start; i <= end; i++) { | 403 for (int i = start; i <= end; i++) { |
404 fCMapEncodingFlag[i] |= 2; | 404 fCMapEncodingFlag[i] |= 2; |
405 fCMapEncoding[i] = value; | 405 fCMapEncoding[i] = value; |
406 value++; | 406 value++; |
407 // 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 |
408 } | 408 } |
409 | 409 |
410 // read one string | 410 // read one string |
411 } else if (token.fType == kObject_TokenType && token.fObject
->isArray()) { | 411 } else if (token.fType == kObject_TokenType && token.fObject
->isArray()) { |
412 // tokenizer->readToken(&token); | 412 // tokenizer.readToken(&token); |
413 // read array | 413 // read array |
414 for (unsigned int i = 0; i < token.fObject->size(); i++)
{ | 414 for (unsigned int i = 0; i < token.fObject->size(); i++)
{ |
415 fCMapEncodingFlag[start + i] |= 2; | 415 fCMapEncodingFlag[start + i] |= 2; |
416 fCMapEncoding[start + i] = skstoi((*token.fObject)[i
]); | 416 fCMapEncoding[start + i] = skstoi((*token.fObject)[i
]); |
417 } | 417 } |
418 } else { | 418 } else { |
419 tokenizer->PutBack(token); | 419 tokenizer.PutBack(token); |
420 } | 420 } |
421 } | 421 } |
422 } | 422 } |
423 } | 423 } |
424 } | 424 } |
425 } | 425 } |
426 | 426 |
427 SkPdfType0Font::SkPdfType0Font(SkPdfNativeDoc* doc, SkPdfType0FontDictionary* di
ct) { | 427 SkPdfType0Font::SkPdfType0Font(SkPdfNativeDoc* doc, SkPdfType0FontDictionary* di
ct) { |
428 fBaseFont = fontFromName(doc, dict, dict->BaseFont(doc).c_str()); | 428 fBaseFont = fontFromName(doc, dict, dict->BaseFont(doc).c_str()); |
429 fEncoding = NULL; | 429 fEncoding = NULL; |
(...skipping 29 matching lines...) Expand all Loading... |
459 encoding = NULL; | 459 encoding = NULL; |
460 } | 460 } |
461 | 461 |
462 #ifdef PDF_TRACE | 462 #ifdef PDF_TRACE |
463 if (encoding == NULL) { | 463 if (encoding == NULL) { |
464 printf("Encoding not found: %s\n", name); | 464 printf("Encoding not found: %s\n", name); |
465 } | 465 } |
466 #endif | 466 #endif |
467 return encoding; | 467 return encoding; |
468 } | 468 } |
OLD | NEW |