OLD | NEW |
1 | 1 |
2 #include "SkPdfNativeTokenizer.h" | 2 #include "SkPdfNativeTokenizer.h" |
3 #include "SkPdfObject.h" | 3 #include "SkPdfObject.h" |
4 #include "SkPdfConfig.h" | 4 #include "SkPdfConfig.h" |
5 | 5 |
6 #include "SkPdfStreamCommonDictionary_autogen.h" | 6 #include "SkPdfStreamCommonDictionary_autogen.h" |
7 | 7 |
8 static unsigned char* skipPdfWhiteSpaces(unsigned char* start, unsigned char* en
d) { | 8 static unsigned char* skipPdfWhiteSpaces(unsigned char* start, unsigned char* en
d) { |
9 while (start < end && isPdfWhiteSpace(*start)) { | 9 while (start < end && isPdfWhiteSpace(*start)) { |
10 if (*start == kComment_PdfDelimiter) { | 10 if (*start == kComment_PdfDelimiter) { |
(...skipping 633 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
644 | 644 |
645 if (isPdfNumeric(*start)) { | 645 if (isPdfNumeric(*start)) { |
646 SkPdfObject::makeNumeric(start, current, token); | 646 SkPdfObject::makeNumeric(start, current, token); |
647 } else { | 647 } else { |
648 SkPdfObject::makeKeyword(start, current, token); | 648 SkPdfObject::makeKeyword(start, current, token); |
649 } | 649 } |
650 return current; | 650 return current; |
651 } | 651 } |
652 | 652 |
653 SkPdfObject* SkPdfAllocator::allocBlock() { | 653 SkPdfObject* SkPdfAllocator::allocBlock() { |
| 654 fSizeInBytes += BUFFER_SIZE * sizeof(SkPdfObject); |
654 return new SkPdfObject[BUFFER_SIZE]; | 655 return new SkPdfObject[BUFFER_SIZE]; |
655 } | 656 } |
656 | 657 |
657 SkPdfAllocator::~SkPdfAllocator() { | 658 SkPdfAllocator::~SkPdfAllocator() { |
658 for (int i = 0 ; i < fHandles.count(); i++) { | 659 for (int i = 0 ; i < fHandles.count(); i++) { |
659 free(fHandles[i]); | 660 free(fHandles[i]); |
660 } | 661 } |
661 for (int i = 0 ; i < fHistory.count(); i++) { | 662 for (int i = 0 ; i < fHistory.count(); i++) { |
662 for (int j = 0 ; j < BUFFER_SIZE; j++) { | 663 for (int j = 0 ; j < BUFFER_SIZE; j++) { |
663 fHistory[i][j].reset(); | 664 fHistory[i][j].reset(); |
664 } | 665 } |
665 delete[] fHistory[i]; | 666 delete[] fHistory[i]; |
666 } | 667 } |
667 for (int j = 0 ; j < BUFFER_SIZE; j++) { | 668 for (int j = 0 ; j < BUFFER_SIZE; j++) { |
668 fCurrent[j].reset(); | 669 fCurrent[j].reset(); |
669 } | 670 } |
670 delete[] fCurrent; | 671 delete[] fCurrent; |
671 } | 672 } |
672 | 673 |
673 SkPdfObject* SkPdfAllocator::allocObject() { | 674 SkPdfObject* SkPdfAllocator::allocObject() { |
674 if (fCurrentUsed >= BUFFER_SIZE) { | 675 if (fCurrentUsed >= BUFFER_SIZE) { |
675 fHistory.push(fCurrent); | 676 fHistory.push(fCurrent); |
676 fCurrent = allocBlock(); | 677 fCurrent = allocBlock(); |
677 fCurrentUsed = 0; | 678 fCurrentUsed = 0; |
| 679 fSizeInBytes += sizeof(SkPdfObject*); |
678 } | 680 } |
679 fCurrentUsed++; | 681 fCurrentUsed++; |
680 return &fCurrent[fCurrentUsed - 1]; | 682 return &fCurrent[fCurrentUsed - 1]; |
681 } | 683 } |
682 | 684 |
683 // TODO(edisonn): perf: do no copy the buffers, but use them, and mark cache the
result, so there is no need of a second pass | 685 // TODO(edisonn): perf: do no copy the buffers, but use them, and mark cache the
result, so there is no need of a second pass |
684 SkPdfNativeTokenizer::SkPdfNativeTokenizer(SkPdfObject* objWithStream, const SkP
dfMapper* mapper, SkPdfAllocator* allocator, SkNativeParsedPDF* doc) : fDoc(doc)
, fMapper(mapper), fAllocator(allocator), fUncompressedStream(NULL), fUncompress
edStreamEnd(NULL), fEmpty(false), fHasPutBack(false) { | 686 SkPdfNativeTokenizer::SkPdfNativeTokenizer(SkPdfObject* objWithStream, const SkP
dfMapper* mapper, SkPdfAllocator* allocator, SkNativeParsedPDF* doc) : fDoc(doc)
, fMapper(mapper), fAllocator(allocator), fUncompressedStream(NULL), fUncompress
edStreamEnd(NULL), fEmpty(false), fHasPutBack(false) { |
685 unsigned char* buffer = NULL; | 687 unsigned char* buffer = NULL; |
686 size_t len = 0; | 688 size_t len = 0; |
687 objWithStream->GetFilteredStreamRef(&buffer, &len, fAllocator); | 689 objWithStream->GetFilteredStreamRef(&buffer, &len, fAllocator); |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
767 if (fEmpty) { | 769 if (fEmpty) { |
768 #ifdef PDF_TRACE | 770 #ifdef PDF_TRACE |
769 printf("EMPTY TOKENIZER\n"); | 771 printf("EMPTY TOKENIZER\n"); |
770 #endif | 772 #endif |
771 return false; | 773 return false; |
772 } | 774 } |
773 | 775 |
774 return readTokenCore(token); | 776 return readTokenCore(token); |
775 } | 777 } |
776 | 778 |
OLD | NEW |