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

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

Issue 21096006: pdfviewer: load files with missing xref (we need in order to help with testing, as most good pdfx i… (Closed) Base URL: http://skia.googlecode.com/svn/trunk/
Patch Set: Created 7 years, 4 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
OLDNEW
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 #include "SkPdfImageDictionary_autogen.h" 7 #include "SkPdfImageDictionary_autogen.h"
8 8
9 // TODO(edisonn): perf!!! 9 // TODO(edisonn): perf!!!
10 // there could be 0s between start and end! but not in the needle. 10 // there could be 0s between start and end! but not in the needle.
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
76 76
77 #else 77 #else
78 #define TRACE_INDENT(level,type) 78 #define TRACE_INDENT(level,type)
79 #define TRACE_COMMENT(ch) 79 #define TRACE_COMMENT(ch)
80 #define TRACE_TK(ch) 80 #define TRACE_TK(ch)
81 #define TRACE_NAME(start,end) 81 #define TRACE_NAME(start,end)
82 #define TRACE_STRING(start,end) 82 #define TRACE_STRING(start,end)
83 #define TRACE_HEXSTRING(start,end) 83 #define TRACE_HEXSTRING(start,end)
84 #endif 84 #endif
85 85
86 static const unsigned char* skipPdfWhiteSpaces(int level, const unsigned char* s tart, const unsigned char* end) { 86 const unsigned char* skipPdfWhiteSpaces(int level, const unsigned char* start, c onst unsigned char* end) {
87 TRACE_INDENT(level, "White Space"); 87 TRACE_INDENT(level, "White Space");
88 while (start < end && isPdfWhiteSpace(*start)) { 88 while (start < end && (isPdfWhiteSpace(*start) || *start == kComment_PdfDeli miter)) {
89 TRACE_COMMENT(*start); 89 TRACE_COMMENT(*start);
90 if (*start == kComment_PdfDelimiter) { 90 if (*start == kComment_PdfDelimiter) {
91 // skip the comment until end of line 91 // skip the comment until end of line
92 while (start < end && !isPdfEOL(*start)) { 92 while (start < end && !isPdfEOL(*start)) {
93 //*start = '\0'; 93 //*start = '\0';
94 start++; 94 start++;
95 TRACE_COMMENT(*start); 95 TRACE_COMMENT(*start);
96 } 96 }
97 } else { 97 } else {
98 //*start = '\0'; 98 //*start = '\0';
99 start++; 99 start++;
100 } 100 }
101 } 101 }
102 return start; 102 return start;
103 } 103 }
104 104
105 // TODO(edisonn) '(' can be used, will it break the string a delimiter or space inside () ? 105 // TODO(edisonn) '(' can be used, will it break the string a delimiter or space inside () ?
106 static const unsigned char* endOfPdfToken(int level, const unsigned char* start, const unsigned char* end) { 106 const unsigned char* endOfPdfToken(int level, const unsigned char* start, const unsigned char* end) {
107 //int opened brackets 107 //int opened brackets
108 //TODO(edisonn): what out for special chars, like \n, \032 108 //TODO(edisonn): what out for special chars, like \n, \032
109 TRACE_INDENT(level, "Token"); 109 TRACE_INDENT(level, "Token");
110 110
111 SkASSERT(!isPdfWhiteSpace(*start)); 111 SkASSERT(!isPdfWhiteSpace(*start));
112 112
113 if (start < end && isPdfDelimiter(*start)) { 113 if (start < end && isPdfDelimiter(*start)) {
114 TRACE_TK(*start); 114 TRACE_TK(*start);
115 start++; 115 start++;
116 return start; 116 return start;
(...skipping 512 matching lines...) Expand 10 before | Expand all | Expand 10 after
629 int64_t length = -1; 629 int64_t length = -1;
630 630
631 // TODO(edisonn): very basic implementation 631 // TODO(edisonn): very basic implementation
632 if (stream->has_Length() && stream->Length(doc) > 0) { 632 if (stream->has_Length() && stream->Length(doc) > 0) {
633 length = stream->Length(doc); 633 length = stream->Length(doc);
634 } 634 }
635 635
636 // TODO(edisonn): laod external streams 636 // TODO(edisonn): laod external streams
637 // TODO(edisonn): look at the last filter, to determione how to deal with po ssible issue 637 // TODO(edisonn): look at the last filter, to determione how to deal with po ssible issue
638 638
639
640 if (length >= 0) {
641 const unsigned char* endstream = start + length;
642
643 if (endstream[0] == kCR_PdfWhiteSpace && endstream[1] == kLF_PdfWhiteSpa ce) {
644 endstream += 2;
645 } else if (endstream[0] == kLF_PdfWhiteSpace) {
646 endstream += 1;
647 }
648
649 if (strncmp((const char*)endstream, "endstream", strlen("endstream")) != 0) {
650 length = -1;
651 }
652 }
653
639 if (length < 0) { 654 if (length < 0) {
640 // scan the buffer, until we find first endstream 655 // scan the buffer, until we find first endstream
641 // TODO(edisonn): all buffers must have a 0 at the end now, 656 // TODO(edisonn): all buffers must have a 0 at the end now,
642 const unsigned char* endstream = (const unsigned char*)strrstrk((char*)s tart, (char*)end, "endstream"); 657 const unsigned char* endstream = (const unsigned char*)strrstrk((char*)s tart, (char*)end, "endstream");
643 658
644 if (endstream) { 659 if (endstream) {
645 length = endstream - start; 660 length = endstream - start;
646 if (*(endstream-1) == kLF_PdfWhiteSpace) length--; 661 if (*(endstream-1) == kLF_PdfWhiteSpace) length--;
647 if (*(endstream-2) == kCR_PdfWhiteSpace) length--; 662 if (*(endstream-2) == kCR_PdfWhiteSpace) length--;
648 } 663 }
(...skipping 420 matching lines...) Expand 10 before | Expand all | Expand 10 after
1069 SkPdfObject* obj = fAllocator->allocObject(); 1084 SkPdfObject* obj = fAllocator->allocObject();
1070 fUncompressedStream = nextObject(0, fUncompressedStream, fUncompress edStreamEnd, obj, fAllocator, fDoc); 1085 fUncompressedStream = nextObject(0, fUncompressedStream, fUncompress edStreamEnd, obj, fAllocator, fDoc);
1071 // TODO(edisonn): perf maybe we should not expand abreviation like t his 1086 // TODO(edisonn): perf maybe we should not expand abreviation like t his
1072 inlineImage->set(inlineImageKeyAbbreviationExpand(key), 1087 inlineImage->set(inlineImageKeyAbbreviationExpand(key),
1073 inlineImageValueAbbreviationExpand(obj)); 1088 inlineImageValueAbbreviationExpand(obj));
1074 } 1089 }
1075 } 1090 }
1076 // TODO(edisonn): report end of data with inline image without an EI 1091 // TODO(edisonn): report end of data with inline image without an EI
1077 return inlineImage; 1092 return inlineImage;
1078 } 1093 }
OLDNEW
« no previous file with comments | « experimental/PdfViewer/pdfparser/native/SkPdfNativeTokenizer.h ('k') | experimental/PdfViewer/pdfparser/native/SkPdfObject.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698