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 | 8 |
9 #ifndef SkPdfParser_DEFINED | 9 #ifndef SkPdfParser_DEFINED |
10 #define SkPdfParser_DEFINED | 10 #define SkPdfParser_DEFINED |
11 | 11 |
12 #include "SkPdfBasics.h" | 12 #include "SkPdfBasics.h" |
13 #include "SkPdfNativeTokenizer.h" | 13 #include "SkPdfNativeTokenizer.h" |
14 | 14 |
15 extern "C" PdfContext* gPdfContext; | 15 extern "C" PdfContext* gPdfContext; |
16 extern "C" SkBitmap* gDumpBitmap; | 16 extern "C" SkBitmap* gDumpBitmap; |
17 extern "C" SkCanvas* gDumpCanvas; | 17 extern "C" SkCanvas* gDumpCanvas; |
18 | 18 |
19 // TODO(edisonn): Document PdfTokenLooper and subclasses. | 19 class SkCanvas; |
20 class PdfTokenLooper { | 20 class SkNativeParsedPDF; |
21 protected: | |
22 PdfTokenLooper* fParent; | |
23 SkPdfNativeTokenizer* fTokenizer; | |
24 PdfContext* fPdfContext; | |
25 SkCanvas* fCanvas; | |
26 | |
27 public: | |
28 PdfTokenLooper(PdfTokenLooper* parent, | |
29 SkPdfNativeTokenizer* tokenizer, | |
30 PdfContext* pdfContext, | |
31 SkCanvas* canvas) | |
32 : fParent(parent), fTokenizer(tokenizer), fPdfContext(pdfContext), fCanv
as(canvas) {} | |
33 | |
34 virtual ~PdfTokenLooper() {} | |
35 | |
36 virtual PdfResult consumeToken(PdfToken& token) = 0; | |
37 virtual void loop() = 0; | |
38 | |
39 void setUp(PdfTokenLooper* parent) { | |
40 fParent = parent; | |
41 fTokenizer = parent->fTokenizer; | |
42 fPdfContext = parent->fPdfContext; | |
43 fCanvas = parent->fCanvas; | |
44 } | |
45 }; | |
46 | |
47 class PdfMainLooper : public PdfTokenLooper { | |
48 public: | |
49 PdfMainLooper(PdfTokenLooper* parent, | |
50 SkPdfNativeTokenizer* tokenizer, | |
51 PdfContext* pdfContext, | |
52 SkCanvas* canvas) | |
53 : PdfTokenLooper(parent, tokenizer, pdfContext, canvas) {} | |
54 | |
55 virtual PdfResult consumeToken(PdfToken& token); | |
56 virtual void loop(); | |
57 }; | |
58 | |
59 class PdfInlineImageLooper : public PdfTokenLooper { | |
60 public: | |
61 PdfInlineImageLooper() | |
62 : PdfTokenLooper(NULL, NULL, NULL, NULL) {} | |
63 | |
64 virtual PdfResult consumeToken(PdfToken& token); | |
65 virtual void loop(); | |
66 PdfResult done(); | |
67 }; | |
68 | |
69 class PdfCompatibilitySectionLooper : public PdfTokenLooper { | |
70 public: | |
71 PdfCompatibilitySectionLooper() | |
72 : PdfTokenLooper(NULL, NULL, NULL, NULL) {} | |
73 | |
74 virtual PdfResult consumeToken(PdfToken& token); | |
75 virtual void loop(); | |
76 }; | |
77 | 21 |
78 // TODO(edisonn): move in another file | 22 // TODO(edisonn): move in another file |
79 class SkPdfViewer : public SkRefCnt { | 23 class SkPdfRenderer : public SkRefCnt { |
| 24 SkNativeParsedPDF* fPdfDoc; |
80 public: | 25 public: |
| 26 SkPdfRenderer() : fPdfDoc(NULL) {} |
| 27 virtual ~SkPdfRenderer() {unload();} |
81 | 28 |
82 bool load(const SkString inputFileName, SkPicture* out); | 29 // TODO(edisonn): add options to render forms, or not |
83 bool write(void*) const { return false; } | 30 bool renderPage(int page, SkCanvas* canvas) const; |
| 31 |
| 32 bool load(const SkString inputFileName); |
| 33 bool loaded() const {return fPdfDoc != NULL;} |
| 34 int pages() const; |
| 35 void unload(); |
| 36 SkRect MediaBox(int page) const; |
84 }; | 37 }; |
85 | 38 |
86 void reportPdfRenderStats(); | 39 void reportPdfRenderStats(); |
87 | 40 |
88 #endif // SkPdfParser_DEFINED | 41 #endif // SkPdfParser_DEFINED |
OLD | NEW |