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

Side by Side Diff: experimental/PdfViewer/pdfparser/podofo/SkPdfPodofoTokenizer.cpp

Issue 18518005: RIP podofo (Closed) Base URL: http://skia.googlecode.com/svn/trunk/
Patch Set: Created 7 years, 5 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
(Empty)
1 #include "SkPdfPodofoTokenizer.h"
2
3 #include "SkTypes.h"
4 #include "SkPdfStream_autogen.h"
5 #include "SkPdfMapper_autogen.h"
6
7 #include "podofo.h"
8
9 // maps to a null doc, if the code asks for it, we should err/crash.
10 SkPdfMapper gNullMapper(NULL);
11
12 SkPdfPodofoTokenizer::SkPdfPodofoTokenizer(const SkPodofoParsedPDF* parser, PoDo Fo::PdfContentsTokenizer* tokenizer)
13 : fMapper(parser->mapper()), fDoc(parser->podofo()), fTokenizer(tokenizer), fUncompressedStream(NULL), fUncompressedStreamLength(0), fEmpty(false), fHasPutB ack(false) {}
14
15 SkPdfPodofoTokenizer::SkPdfPodofoTokenizer(const SkPdfObject* objWithStream) : f Mapper(&gNullMapper), fDoc(NULL), fTokenizer(NULL), fUncompressedStream(NULL), f UncompressedStreamLength(0), fEmpty(false), fHasPutBack(false) {
16 fUncompressedStream = NULL;
17 fUncompressedStreamLength = 0;
18
19 fDoc = NULL;
20
21 SkPdfStream* stream = NULL;
22 if (objWithStream &&
23 objWithStream->doc()->mapper()->mapStream(objWithStream, &stream) &&
24 stream->GetFilteredCopy(&fUncompressedStream, &fUncompressedStreamLe ngth) &&
25 fUncompressedStream != NULL &&
26 fUncompressedStreamLength != 0) {
27 fTokenizer = new PoDoFo::PdfContentsTokenizer(fUncompressedStream, fUnco mpressedStreamLength);
28 fDoc = objWithStream->doc()->podofo();
29 } else {
30 fEmpty = true;
31 }
32 }
33
34 SkPdfPodofoTokenizer::SkPdfPodofoTokenizer(const char* buffer, int len) : fMappe r(&gNullMapper), fDoc(NULL), fTokenizer(NULL), fUncompressedStream(NULL), fUncom pressedStreamLength(0), fEmpty(false), fHasPutBack(false) {
35 try {
36 fTokenizer = new PoDoFo::PdfContentsTokenizer(buffer, len);
37 } catch (PoDoFo::PdfError& e) {
38 fEmpty = true;
39 }
40 }
41
42 SkPdfPodofoTokenizer::~SkPdfPodofoTokenizer() {
43 free(fUncompressedStream);
44 }
45
46 bool SkPdfPodofoTokenizer::readTokenCore(PdfToken* token) {
47 PoDoFo::PdfVariant var;
48 PoDoFo::EPdfContentsType type;
49
50 token->fKeyword = NULL;
51 token->fObject = NULL;
52
53 bool ret = fTokenizer->ReadNext(type, token->fKeyword, var);
54
55 if (!ret) return ret;
56
57 switch (type) {
58 case PoDoFo::ePdfContentsType_Keyword:
59 token->fType = kKeyword_TokenType;
60 break;
61
62 case PoDoFo::ePdfContentsType_Variant: {
63 token->fType = kObject_TokenType;
64 PoDoFo::PdfObject* obj = new PoDoFo::PdfObject(var);
65 fMapper->mapObject(obj, &token->fObject);
66 }
67 break;
68
69 case PoDoFo::ePdfContentsType_ImageData:
70 token->fType = kImageData_TokenType;
71 // TODO(edisonn): inline images seem to work without it
72 break;
73 }
74 #ifdef PDF_TRACE
75 std::string str;
76 if (token->fObject) {
77 token->fObject->podofo()->ToString(str);
78 }
79 printf("%s %s\n", token->fType == kKeyword_TokenType ? "Keyword" : token->fT ype == kObject_TokenType ? "Object" : "ImageData", token->fKeyword ? token->fKey word : str.c_str());
80 #endif
81 return ret;
82 }
83
84 void SkPdfPodofoTokenizer::PutBack(PdfToken token) {
85 SkASSERT(!fHasPutBack);
86 fHasPutBack = true;
87 fPutBack = token;
88 }
89
90 bool SkPdfPodofoTokenizer::readToken(PdfToken* token) {
91 if (fHasPutBack) {
92 *token = fPutBack;
93 fHasPutBack = false;
94 return true;
95 }
96
97 if (fEmpty) {
98 return false;
99 }
100
101 return readTokenCore(token);
102 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698