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

Side by Side Diff: experimental/PdfViewer/pdfparser/native/SkPdfNativeTokenizer.cpp

Issue 23456022: pdfviewer: (part 1) store the offset of the location of object in file/stream. In order to use the … (Closed) Base URL: http://skia.googlecode.com/svn/trunk/
Patch Set: Created 7 years, 3 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
« no previous file with comments | « experimental/PdfViewer/pdfparser/native/SkPdfNativeTokenizer.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "SkPdfNativeTokenizer.h" 8 #include "SkPdfNativeTokenizer.h"
9 #include "SkPdfNativeObject.h" 9 #include "SkPdfNativeObject.h"
10 #include "SkPdfConfig.h" 10 #include "SkPdfConfig.h"
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
128 } 128 }
129 129
130 while (start < end && !isPdfWhiteSpaceOrPdfDelimiter(*start)) { 130 while (start < end && !isPdfWhiteSpaceOrPdfDelimiter(*start)) {
131 TRACE_TK(*start); 131 TRACE_TK(*start);
132 start++; 132 start++;
133 } 133 }
134 return start; 134 return start;
135 } 135 }
136 136
137 // last elem has to be ] 137 // last elem has to be ]
138 static const unsigned char* readArray(int level, const unsigned char* start, con st unsigned char* end, SkPdfNativeObject* array, SkPdfAllocator* allocator, SkPd fNativeDoc* doc) { 138 static const unsigned char* readArray(int level, const unsigned char* start, con st unsigned char* end, SkPdfNativeObject* array, SkPdfAllocator* allocator, SkPd fNativeDoc* doc GET_TRACK_STREAM) {
139 SkPdfNativeObject::makeEmptyArray(array PUT_TRACK_STREAM(start, start));
140
139 if (allocator == NULL) { 141 if (allocator == NULL) {
140 // TODO(edisonn): report/warning error 142 // TODO(edisonn): report/warning error
141 return end; 143 return end;
142 } 144 }
143 145
144 TRACE_INDENT(level, "Array"); 146 TRACE_INDENT(level, "Array");
145 while (start < end) { 147 while (start < end) {
146 // skip white spaces 148 // skip white spaces
147 start = skipPdfWhiteSpaces(level + 1, start, end); 149 start = skipPdfWhiteSpaces(level + 1, start, end);
148 150
149 const unsigned char* endOfToken = endOfPdfToken(level + 1, start, end); 151 const unsigned char* endOfToken = endOfPdfToken(level + 1, start, end);
150 152
151 if (endOfToken == start) { 153 if (endOfToken == start) {
152 // TODO(edisonn): report error in pdf file (end of stream with ] for end of aray 154 // TODO(edisonn): report error in pdf file (end of stream with ] for end of aray
153 return start; 155 return start;
154 } 156 }
155 157
156 if (endOfToken == start + 1 && *start == kClosedSquareBracket_PdfDelimit er) { 158 if (endOfToken == start + 1 && *start == kClosedSquareBracket_PdfDelimit er) {
157 return endOfToken; 159 return endOfToken;
158 } 160 }
159 161
160 SkPdfNativeObject* newObj = allocator->allocObject(); 162 SkPdfNativeObject* newObj = allocator->allocObject();
161 start = nextObject(level + 1, start, end, newObj, allocator, doc); 163 start = nextObject(level + 1, start, end, newObj, allocator, doc PUT_TRA CK_STREAM_ARGS);
162 // TODO(edisonn): perf/memory: put the variables on the stack, and flush them on the array only when 164 // TODO(edisonn): perf/memory: put the variables on the stack, and flush them on the array only when
163 // we are sure they are not references! 165 // we are sure they are not references!
164 if (newObj->isKeywordReference() && array->size() >= 2 && array->objAtAI ndex(array->size() - 1)->isInteger() && array->objAtAIndex(array->size() - 2)->i sInteger()) { 166 if (newObj->isKeywordReference() && array->size() >= 2 && array->objAtAI ndex(array->size() - 1)->isInteger() && array->objAtAIndex(array->size() - 2)->i sInteger()) {
165 SkPdfNativeObject* gen = array->removeLastInArray(); 167 SkPdfNativeObject* gen = array->removeLastInArray();
166 SkPdfNativeObject* id = array->removeLastInArray(); 168 SkPdfNativeObject* id = array->removeLastInArray();
167 newObj->reset(); 169
168 SkPdfNativeObject::makeReference((unsigned int)id->intValue(), (unsi gned int)gen->intValue(), newObj); 170 SkPdfNativeObject::resetAndMakeReference((unsigned int)id->intValue( ), (unsigned int)gen->intValue(), newObj PUT_TRACK_PARAMETERS_OBJ2(id, newObj));
171
169 } 172 }
170 array->appendInArray(newObj); 173 array->appendInArray(newObj);
171 } 174 }
172 // TODO(edisonn): report not reached, we should never get here 175 // TODO(edisonn): report not reached, we should never get here
173 // TODO(edisonn): there might be a bug here, enable an assert and run it on files 176 // TODO(edisonn): there might be a bug here, enable an assert and run it on files
174 // or it might be that the files were actually corrupted 177 // or it might be that the files were actually corrupted
175 return start; 178 return start;
176 } 179 }
177 180
178 // When we read strings we will rewrite the string so we will reuse the memory 181 // When we read strings we will rewrite the string so we will reuse the memory
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
298 return in; // consumed already ) at the end of the string 301 return in; // consumed already ) at the end of the string
299 } else { 302 } else {
300 return start + (out - (const unsigned char*)NULL); // return where the s tring would end if we reuse the string 303 return start + (out - (const unsigned char*)NULL); // return where the s tring would end if we reuse the string
301 } 304 }
302 } 305 }
303 306
304 static int readStringLength(int level, const unsigned char* start, const unsigne d char* end) { 307 static int readStringLength(int level, const unsigned char* start, const unsigne d char* end) {
305 return readString(level, start, end, NULL) - start; 308 return readString(level, start, end, NULL) - start;
306 } 309 }
307 310
308 static const unsigned char* readString(int level, const unsigned char* start, co nst unsigned char* end, SkPdfNativeObject* str, SkPdfAllocator* allocator) { 311 static const unsigned char* readString(int level, const unsigned char* start, co nst unsigned char* end, SkPdfNativeObject* str, SkPdfAllocator* allocator GET_TR ACK_STREAM) {
309 if (!allocator) { 312 if (!allocator) {
310 return end; 313 return end;
311 } 314 }
312 int outLength = readStringLength(level, start, end); 315 int outLength = readStringLength(level, start, end);
313 // TODO(edisonn): optimize the allocation, don't allocate new string, but pu t it in a preallocated buffer 316 // TODO(edisonn): optimize the allocation, don't allocate new string, but pu t it in a preallocated buffer
314 unsigned char* out = (unsigned char*)allocator->alloc(outLength); 317 unsigned char* out = (unsigned char*)allocator->alloc(outLength);
315 start = readString(level, start, end, out); 318 const unsigned char* now = readString(level, start, end, out);
316 SkPdfNativeObject::makeString(out, out + outLength, str); 319 SkPdfNativeObject::makeString(out, out + outLength, str PUT_TRACK_STREAM(sta rt, now));
317 TRACE_STRING(out, out + outLength); 320 TRACE_STRING(out, out + outLength);
318 return start; // consumed already ) at the end of the string 321 return now; // consumed already ) at the end of the string
319 } 322 }
320 323
321 static const unsigned char* readHexString(int level, const unsigned char* start, const unsigned char* end, unsigned char* out) { 324 static const unsigned char* readHexString(int level, const unsigned char* start, const unsigned char* end, unsigned char* out) {
322 TRACE_INDENT(level, "HexString"); 325 TRACE_INDENT(level, "HexString");
323 bool hasOut = (out != NULL); 326 bool hasOut = (out != NULL);
324 const unsigned char* in = start; 327 const unsigned char* in = start;
325 328
326 unsigned char code = 0; 329 unsigned char code = 0;
327 330
328 while (in < end) { 331 while (in < end) {
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
445 return in; // consumed already > at the end of the string 448 return in; // consumed already > at the end of the string
446 } else { 449 } else {
447 return start + (out - (const unsigned char*)NULL); // return where the s tring would end if we reuse the string 450 return start + (out - (const unsigned char*)NULL); // return where the s tring would end if we reuse the string
448 } 451 }
449 } 452 }
450 453
451 static int readHexStringLength(int level, const unsigned char* start, const unsi gned char* end) { 454 static int readHexStringLength(int level, const unsigned char* start, const unsi gned char* end) {
452 return readHexString(level, start, end, NULL) - start; 455 return readHexString(level, start, end, NULL) - start;
453 } 456 }
454 457
455 static const unsigned char* readHexString(int level, const unsigned char* start, const unsigned char* end, SkPdfNativeObject* str, SkPdfAllocator* allocator) { 458 static const unsigned char* readHexString(int level, const unsigned char* start, const unsigned char* end, SkPdfNativeObject* str, SkPdfAllocator* allocator GET _TRACK_STREAM) {
456 if (!allocator) { 459 if (!allocator) {
457 return end; 460 return end;
458 } 461 }
459 int outLength = readHexStringLength(level, start, end); 462 int outLength = readHexStringLength(level, start, end);
460 // TODO(edisonn): optimize the allocation, don't allocate new string, but pu t it in a preallocated buffer 463 // TODO(edisonn): optimize the allocation, don't allocate new string, but pu t it in a preallocated buffer
461 unsigned char* out = (unsigned char*)allocator->alloc(outLength); 464 unsigned char* out = (unsigned char*)allocator->alloc(outLength);
462 start = readHexString(level, start, end, out); 465 const unsigned char* now = readHexString(level, start, end, out);
463 SkPdfNativeObject::makeHexString(out, out + outLength, str); 466 SkPdfNativeObject::makeHexString(out, out + outLength, str PUT_TRACK_STREAM( start, now));
464 TRACE_HEXSTRING(out, out + outLength); 467 TRACE_HEXSTRING(out, out + outLength);
465 return start; // consumed already > at the end of the string 468 return now; // consumed already > at the end of the string
466 } 469 }
467 470
468 // TODO(edisonn): before PDF 1.2 name could not have special characters, add ver sion parameter 471 // TODO(edisonn): before PDF 1.2 name could not have special characters, add ver sion parameter
469 static const unsigned char* readName(int level, const unsigned char* start, cons t unsigned char* end, unsigned char* out) { 472 static const unsigned char* readName(int level, const unsigned char* start, cons t unsigned char* end, unsigned char* out) {
470 TRACE_INDENT(level, "Name"); 473 TRACE_INDENT(level, "Name");
471 bool hasOut = (out != NULL); 474 bool hasOut = (out != NULL);
472 const unsigned char* in = start; 475 const unsigned char* in = start;
473 476
474 unsigned char code = 0; 477 unsigned char code = 0;
475 478
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
570 return in; 573 return in;
571 } else { 574 } else {
572 return start + (out - (const unsigned char*)NULL); // return where the s tring would end if we reuse the string 575 return start + (out - (const unsigned char*)NULL); // return where the s tring would end if we reuse the string
573 } 576 }
574 } 577 }
575 578
576 static int readNameLength(int level, const unsigned char* start, const unsigned char* end) { 579 static int readNameLength(int level, const unsigned char* start, const unsigned char* end) {
577 return readName(level, start, end, NULL) - start; 580 return readName(level, start, end, NULL) - start;
578 } 581 }
579 582
580 static const unsigned char* readName(int level, const unsigned char* start, cons t unsigned char* end, SkPdfNativeObject* name, SkPdfAllocator* allocator) { 583 static const unsigned char* readName(int level, const unsigned char* start, cons t unsigned char* end, SkPdfNativeObject* name, SkPdfAllocator* allocator GET_TRA CK_STREAM) {
581 if (!allocator) { 584 if (!allocator) {
582 return end; 585 return end;
583 } 586 }
584 int outLength = readNameLength(level, start, end); 587 int outLength = readNameLength(level, start, end);
585 // TODO(edisonn): optimize the allocation, don't allocate new string, but pu t it in a preallocated buffer 588 // TODO(edisonn): optimize the allocation, don't allocate new string, but pu t it in a preallocated buffer
586 unsigned char* out = (unsigned char*)allocator->alloc(outLength); 589 unsigned char* out = (unsigned char*)allocator->alloc(outLength);
587 start = readName(level, start, end, out); 590 const unsigned char* now = readName(level, start, end, out);
588 SkPdfNativeObject::makeName(out, out + outLength, name); 591 SkPdfNativeObject::makeName(out, out + outLength, name PUT_TRACK_STREAM(star t, now));
589 TRACE_NAME(out, out + outLength); 592 TRACE_NAME(out, out + outLength);
590 return start; 593 return now;
591 } 594 }
592 595
593 // TODO(edisonn): pdf spec let Length to be an indirect object define after the stream 596 // TODO(edisonn): pdf spec let Length to be an indirect object define after the stream
594 // that makes for an interesting scenario, where the stream itself contains ends tream, together 597 // that makes for an interesting scenario, where the stream itself contains ends tream, together
595 // with a reference object with the length, but the real length object would be somewhere else 598 // with a reference object with the length, but the real length object would be somewhere else
596 // it could confuse the parser 599 // it could confuse the parser
597 /*example: 600 /*example:
598 601
599 7 0 obj 602 7 0 obj
600 << /length 8 0 R>> 603 << /length 8 0 R>>
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
716 if (*(endstream-2) == kCR_PdfWhiteSpace) length--; 719 if (*(endstream-2) == kCR_PdfWhiteSpace) length--;
717 inlineImage->addStream(start, (size_t)length); 720 inlineImage->addStream(start, (size_t)length);
718 } else { 721 } else {
719 // TODO(edisonn): report error in inline image stream (ID-EI) section 722 // TODO(edisonn): report error in inline image stream (ID-EI) section
720 // TODO(edisonn): based on filter, try to ignore a missing EI, and read data properly 723 // TODO(edisonn): based on filter, try to ignore a missing EI, and read data properly
721 return end; 724 return end;
722 } 725 }
723 return endEI; 726 return endEI;
724 } 727 }
725 728
726 static const unsigned char* readDictionary(int level, const unsigned char* start , const unsigned char* end, SkPdfNativeObject* dict, SkPdfAllocator* allocator, SkPdfNativeDoc* doc) { 729 static const unsigned char* readDictionary(int level, const unsigned char* start , const unsigned char* end, SkPdfNativeObject* dict, SkPdfAllocator* allocator, SkPdfNativeDoc* doc GET_TRACK_STREAM) {
727 if (allocator == NULL) { 730 if (allocator == NULL) {
728 // TODO(edisonn): report/warning error 731 // TODO(edisonn): report/warning error
729 return end; 732 return end;
730 } 733 }
731 TRACE_INDENT(level, "Dictionary"); 734 TRACE_INDENT(level, "Dictionary");
732 SkPdfNativeObject::makeEmptyDictionary(dict); 735 SkPdfNativeObject::makeEmptyDictionary(dict PUT_TRACK_STREAM(start, start));
733 736
734 start = skipPdfWhiteSpaces(level, start, end); 737 start = skipPdfWhiteSpaces(level, start, end);
735 SkPdfAllocator tmpStorage; // keys will be stored in dict, we can free them immediately after set. 738 SkPdfAllocator tmpStorage; // keys will be stored in dict, we can free them immediately after set.
736 739
737 while (start < end && *start == kNamed_PdfDelimiter) { 740 while (start < end && *start == kNamed_PdfDelimiter) {
738 SkPdfNativeObject key; 741 SkPdfNativeObject key;
739 //*start = '\0'; 742 //*start = '\0';
740 start++; 743 start++;
741 start = readName(level + 1, start, end, &key, &tmpStorage); 744 start = readName(level + 1, start, end, &key, &tmpStorage PUT_TRACK_STRE AM_ARGS);
742 start = skipPdfWhiteSpaces(level + 1, start, end); 745 start = skipPdfWhiteSpaces(level + 1, start, end);
743 746
744 if (start < end) { 747 if (start < end) {
745 SkPdfNativeObject* value = allocator->allocObject(); 748 SkPdfNativeObject* value = allocator->allocObject();
746 start = nextObject(level + 1, start, end, value, allocator, doc); 749 start = nextObject(level + 1, start, end, value, allocator, doc PUT_ TRACK_STREAM_ARGS);
747 750
748 start = skipPdfWhiteSpaces(level + 1, start, end); 751 start = skipPdfWhiteSpaces(level + 1, start, end);
749 752
750 if (start < end) { 753 if (start < end) {
751 // seems we have an indirect reference 754 // seems we have an indirect reference
752 if (isPdfDigit(*start)) { 755 if (isPdfDigit(*start)) {
753 SkPdfNativeObject generation; 756 SkPdfNativeObject generation;
754 start = nextObject(level + 1, start, end, &generation, alloc ator, doc); 757 start = nextObject(level + 1, start, end, &generation, alloc ator, doc PUT_TRACK_STREAM_ARGS);
755 758
756 SkPdfNativeObject keywordR; 759 SkPdfNativeObject keywordR;
757 start = nextObject(level + 1, start, end, &keywordR, allocat or, doc); 760 start = nextObject(level + 1, start, end, &keywordR, allocat or, doc PUT_TRACK_STREAM_ARGS);
758 761
759 if (value->isInteger() && generation.isInteger() && keywordR .isKeywordReference()) { 762 if (value->isInteger() && generation.isInteger() && keywordR .isKeywordReference()) {
760 int64_t id = value->intValue(); 763 int64_t id = value->intValue();
761 value->reset(); 764 SkPdfNativeObject::resetAndMakeReference((unsigned int)i d, (unsigned int)generation.intValue(), value PUT_TRACK_PARAMETERS_OBJ2(value, & generation));
762 SkPdfNativeObject::makeReference((unsigned int)id, (unsi gned int)generation.intValue(), value);
763 dict->set(&key, value); 765 dict->set(&key, value);
764 } else { 766 } else {
765 // error, ignore 767 // error, ignore
766 dict->set(&key, value); 768 dict->set(&key, value);
767 } 769 }
768 } else { 770 } else {
769 // next elem is not a digit, but it might not be / either! 771 // next elem is not a digit, but it might not be / either!
770 dict->set(&key, value); 772 dict->set(&key, value);
771 } 773 }
772 } else { 774 } else {
(...skipping 16 matching lines...) Expand all
789 // TODO(edisonn): report/warning 791 // TODO(edisonn): report/warning
790 } 792 }
791 //*start = '\0'; 793 //*start = '\0';
792 start++; // skip > 794 start++; // skip >
793 if (*start != kClosedInequityBracket_PdfDelimiter) { 795 if (*start != kClosedInequityBracket_PdfDelimiter) {
794 // TODO(edisonn): report/warning 796 // TODO(edisonn): report/warning
795 } 797 }
796 //*start = '\0'; 798 //*start = '\0';
797 start++; // skip > 799 start++; // skip >
798 800
801 STORE_TRACK_PARAMETER_OFFSET_END(dict,start);
802
799 start = readStream(level, start, end, dict, doc); 803 start = readStream(level, start, end, dict, doc);
800 804
801 return start; 805 return start;
802 } 806 }
803 807
804 const unsigned char* nextObject(int level, const unsigned char* start, const uns igned char* end, SkPdfNativeObject* token, SkPdfAllocator* allocator, SkPdfNativ eDoc* doc) { 808 const unsigned char* nextObject(int level, const unsigned char* start, const uns igned char* end, SkPdfNativeObject* token, SkPdfAllocator* allocator, SkPdfNativ eDoc* doc GET_TRACK_STREAM) {
805 const unsigned char* current; 809 const unsigned char* current;
806 810
807 // skip white spaces 811 // skip white spaces
808 start = skipPdfWhiteSpaces(level, start, end); 812 start = skipPdfWhiteSpaces(level, start, end);
809 813
810 current = endOfPdfToken(level, start, end); 814 current = endOfPdfToken(level, start, end);
811 815
812 // no token, len would be 0 816 // no token, len would be 0
813 if (current == start) { 817 if (current == start) {
814 return NULL; 818 return NULL;
815 } 819 }
816 820
817 int tokenLen = current - start; 821 int tokenLen = current - start;
818 822
819 if (tokenLen == 1) { 823 if (tokenLen == 1) {
820 // start array 824 // start array
821 switch (*start) { 825 switch (*start) {
822 case kOpenedSquareBracket_PdfDelimiter: 826 case kOpenedSquareBracket_PdfDelimiter:
823 //*start = '\0'; 827 //*start = '\0';
824 SkPdfNativeObject::makeEmptyArray(token); 828 return readArray(level + 1, current, end, token, allocator, doc PUT_TRACK_STREAM_ARGS);
825 return readArray(level + 1, current, end, token, allocator, doc) ;
826 829
827 case kOpenedRoundBracket_PdfDelimiter: 830 case kOpenedRoundBracket_PdfDelimiter:
828 //*start = '\0'; 831 //*start = '\0';
829 return readString(level, start + 1, end, token, allocator); 832 return readString(level, start + 1, end, token, allocator PUT_TR ACK_STREAM_ARGS);
830 833
831 case kOpenedInequityBracket_PdfDelimiter: 834 case kOpenedInequityBracket_PdfDelimiter:
832 //*start = '\0'; 835 //*start = '\0';
833 if (end > start + 1 && start[1] == kOpenedInequityBracket_PdfDel imiter) { 836 if (end > start + 1 && start[1] == kOpenedInequityBracket_PdfDel imiter) {
834 //start[1] = '\0'; // optional 837 //start[1] = '\0'; // optional
835 // TODO(edisonn): pass here the length somehow? 838 // TODO(edisonn): pass here the length somehow?
836 return readDictionary(level + 1, start + 2, end, token, allo cator, doc); // skip << 839 return readDictionary(level + 1, start + 2, end, token, allo cator, doc PUT_TRACK_STREAM_ARGS); // skip <<
837 } else { 840 } else {
838 return readHexString(level, start + 1, end, token, allocator ); // skip < 841 return readHexString(level, start + 1, end, token, allocator PUT_TRACK_STREAM_ARGS); // skip <
839 } 842 }
840 843
841 case kNamed_PdfDelimiter: 844 case kNamed_PdfDelimiter:
842 //*start = '\0'; 845 //*start = '\0';
843 return readName(level, start + 1, end, token, allocator); 846 return readName(level, start + 1, end, token, allocator PUT_TRAC K_STREAM_ARGS);
844 847
845 // TODO(edisonn): what to do curly brackets? read spec! 848 // TODO(edisonn): what to do curly brackets? read spec!
846 case kOpenedCurlyBracket_PdfDelimiter: 849 case kOpenedCurlyBracket_PdfDelimiter:
847 default: 850 default:
848 break; 851 break;
849 } 852 }
850 853
851 SkASSERT(!isPdfWhiteSpace(*start)); 854 SkASSERT(!isPdfWhiteSpace(*start));
852 if (isPdfDelimiter(*start)) { 855 if (isPdfDelimiter(*start)) {
853 // TODO(edisonn): how stream ] } > ) will be handled? 856 // TODO(edisonn): how stream ] } > ) will be handled?
854 // for now ignore, and it will become a keyword to be ignored 857 // for now ignore, and it will become a keyword to be ignored
855 } 858 }
856 } 859 }
857 860
858 if (tokenLen == 4 && start[0] == 'n' && start[1] == 'u' && start[2] == 'l' & & start[3] == 'l') { 861 if (tokenLen == 4 && start[0] == 'n' && start[1] == 'u' && start[2] == 'l' & & start[3] == 'l') {
859 SkPdfNativeObject::makeNull(token); 862 SkPdfNativeObject::makeNull(token PUT_TRACK_STREAM(start, start + 4));
860 return current; 863 return current;
861 } 864 }
862 865
863 if (tokenLen == 4 && start[0] == 't' && start[1] == 'r' && start[2] == 'u' & & start[3] == 'e') { 866 if (tokenLen == 4 && start[0] == 't' && start[1] == 'r' && start[2] == 'u' & & start[3] == 'e') {
864 SkPdfNativeObject::makeBoolean(true, token); 867 SkPdfNativeObject::makeBoolean(true, token PUT_TRACK_STREAM(start, start + 4));
865 return current; 868 return current;
866 } 869 }
867 870
868 if (tokenLen == 5 && start[0] == 'f' && start[1] == 'a' && start[2] == 'l' & & start[3] == 's' && start[4] == 'e') { 871 if (tokenLen == 5 && start[0] == 'f' && start[1] == 'a' && start[2] == 'l' & & start[3] == 's' && start[4] == 'e') {
869 SkPdfNativeObject::makeBoolean(false, token); 872 SkPdfNativeObject::makeBoolean(false, token PUT_TRACK_STREAM(start, star t + 5));
870 return current; 873 return current;
871 } 874 }
872 875
873 if (isPdfNumeric(*start)) { 876 if (isPdfNumeric(*start)) {
874 SkPdfNativeObject::makeNumeric(start, current, token); 877 SkPdfNativeObject::makeNumeric(start, current, token PUT_TRACK_STREAM(st art, current));
875 } else { 878 } else {
876 SkPdfNativeObject::makeKeyword(start, current, token); 879 SkPdfNativeObject::makeKeyword(start, current, token PUT_TRACK_STREAM(st art, current));
877 } 880 }
878 return current; 881 return current;
879 } 882 }
880 883
881 SkPdfNativeObject* SkPdfAllocator::allocBlock() { 884 SkPdfNativeObject* SkPdfAllocator::allocBlock() {
882 fSizeInBytes += BUFFER_SIZE * sizeof(SkPdfNativeObject); 885 fSizeInBytes += BUFFER_SIZE * sizeof(SkPdfNativeObject);
883 return new SkPdfNativeObject[BUFFER_SIZE]; 886 return new SkPdfNativeObject[BUFFER_SIZE];
884 } 887 }
885 888
886 SkPdfAllocator::~SkPdfAllocator() { 889 SkPdfAllocator::~SkPdfAllocator() {
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
943 static int read_op = 0; 946 static int read_op = 0;
944 #endif 947 #endif
945 token->fKeyword = NULL; 948 token->fKeyword = NULL;
946 token->fObject = NULL; 949 token->fObject = NULL;
947 950
948 fUncompressedStream = skipPdfWhiteSpaces(0, fUncompressedStream, fUncompress edStreamEnd); 951 fUncompressedStream = skipPdfWhiteSpaces(0, fUncompressedStream, fUncompress edStreamEnd);
949 if (fUncompressedStream >= fUncompressedStreamEnd) { 952 if (fUncompressedStream >= fUncompressedStreamEnd) {
950 return false; 953 return false;
951 } 954 }
952 955
953 fUncompressedStream = nextObject(0, fUncompressedStream, fUncompressedStream End, &obj, fAllocator, fDoc); 956 fUncompressedStream = nextObject(0, fUncompressedStream, fUncompressedStream End, &obj, fAllocator, fDoc PUT_TRACK_STREAM_ARGS_EXPL2(fStreamId, fUncompressed StreamStart));
954 957
955 // If it is a keyword, we will only get the pointer of the string 958 // If it is a keyword, we will only get the pointer of the string
956 if (obj.type() == SkPdfNativeObject::kKeyword_PdfObjectType) { 959 if (obj.type() == SkPdfNativeObject::kKeyword_PdfObjectType) {
957 token->fKeyword = obj.c_str(); 960 token->fKeyword = obj.c_str();
958 token->fKeywordLength = obj.lenstr(); 961 token->fKeywordLength = obj.lenstr();
959 token->fType = kKeyword_TokenType; 962 token->fType = kKeyword_TokenType;
960 } else { 963 } else {
961 SkPdfNativeObject* pobj = fAllocator->allocObject(); 964 SkPdfNativeObject* pobj = fAllocator->allocObject();
962 *pobj = obj; 965 *pobj = obj;
963 token->fObject = pobj; 966 token->fObject = pobj;
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
1078 } 1081 }
1079 1082
1080 SkPdfImageDictionary* SkPdfNativeTokenizer::readInlineImage() { 1083 SkPdfImageDictionary* SkPdfNativeTokenizer::readInlineImage() {
1081 // BI already processed 1084 // BI already processed
1082 fUncompressedStream = skipPdfWhiteSpaces(0, fUncompressedStream, fUncompress edStreamEnd); 1085 fUncompressedStream = skipPdfWhiteSpaces(0, fUncompressedStream, fUncompress edStreamEnd);
1083 if (fUncompressedStream >= fUncompressedStreamEnd) { 1086 if (fUncompressedStream >= fUncompressedStreamEnd) {
1084 return NULL; 1087 return NULL;
1085 } 1088 }
1086 1089
1087 SkPdfImageDictionary* inlineImage = (SkPdfImageDictionary*)fAllocator->alloc Object(); 1090 SkPdfImageDictionary* inlineImage = (SkPdfImageDictionary*)fAllocator->alloc Object();
1088 SkPdfNativeObject::makeEmptyDictionary(inlineImage); 1091 SkPdfNativeObject::makeEmptyDictionary(inlineImage PUT_TRACK_STREAM_ARGS_EXP L(fStreamId, fUncompressedStream - fUncompressedStreamStart, fUncompressedStream - fUncompressedStreamStart));
1089 1092
1090 while (fUncompressedStream < fUncompressedStreamEnd) { 1093 while (fUncompressedStream < fUncompressedStreamEnd) {
1091 SkPdfNativeObject* key = fAllocator->allocObject(); 1094 SkPdfNativeObject* key = fAllocator->allocObject();
1092 fUncompressedStream = nextObject(0, fUncompressedStream, fUncompressedSt reamEnd, key, fAllocator, fDoc); 1095 fUncompressedStream = nextObject(0, fUncompressedStream, fUncompressedSt reamEnd, key, fAllocator, fDoc PUT_TRACK_STREAM_ARGS_EXPL2(fStreamId, fUncompres sedStreamStart));
1093 1096
1094 if (key->isKeyword() && key->lenstr() == 2 && key->c_str()[0] == 'I' && key->c_str()[1] == 'D') { // ID 1097 if (key->isKeyword() && key->lenstr() == 2 && key->c_str()[0] == 'I' && key->c_str()[1] == 'D') { // ID
1095 fUncompressedStream = readInlineImageStream(0, fUncompressedStream, fUncompressedStreamEnd, inlineImage, fDoc); 1098 fUncompressedStream = readInlineImageStream(0, fUncompressedStream, fUncompressedStreamEnd, inlineImage, fDoc);
1096 return inlineImage; 1099 return inlineImage;
1097 } else { 1100 } else {
1098 SkPdfNativeObject* obj = fAllocator->allocObject(); 1101 SkPdfNativeObject* obj = fAllocator->allocObject();
1099 fUncompressedStream = nextObject(0, fUncompressedStream, fUncompress edStreamEnd, obj, fAllocator, fDoc); 1102 fUncompressedStream = nextObject(0, fUncompressedStream, fUncompress edStreamEnd, obj, fAllocator, fDoc PUT_TRACK_STREAM_ARGS_EXPL2(fStreamId, fUncom pressedStreamStart));
1100 // TODO(edisonn): perf maybe we should not expand abreviation like t his 1103 // TODO(edisonn): perf maybe we should not expand abreviation like t his
1101 inlineImage->set(inlineImageKeyAbbreviationExpand(key), 1104 inlineImage->set(inlineImageKeyAbbreviationExpand(key),
1102 inlineImageValueAbbreviationExpand(obj)); 1105 inlineImageValueAbbreviationExpand(obj));
1103 } 1106 }
1104 } 1107 }
1105 // TODO(edisonn): report end of data with inline image without an EI 1108 // TODO(edisonn): report end of data with inline image without an EI
1106 return inlineImage; 1109 return inlineImage;
1107 } 1110 }
OLDNEW
« no previous file with comments | « experimental/PdfViewer/pdfparser/native/SkPdfNativeTokenizer.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698