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

Side by Side Diff: experimental/PdfViewer/src/SkPdfContext.cpp

Issue 79933003: Restructuring of PdfViewer code. (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Respond to comments. Created 7 years 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 * 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 "SkPdfContext.h" 8 #include "SkPdfContext.h"
9 #include "SkPdfNativeTokenizer.h" 9 #include "SkPdfNativeDoc.h"
10 #include "SkPdfReporter.h"
11 #include "SkPdfTokenLooper.h"
12
13 ///////////////////////////////////////////////////////////////////////////////
14
15 class PdfMainLooper : public SkPdfTokenLooper {
16 public:
17 PdfMainLooper(SkPdfTokenLooper* parent,
18 SkPdfNativeTokenizer* tokenizer,
19 SkPdfContext* pdfContext,
20 SkCanvas* canvas)
21 : SkPdfTokenLooper(parent, tokenizer, pdfContext, canvas) {}
22
23 virtual SkPdfResult consumeToken(PdfToken& token);
24 virtual void loop();
25 };
26
27 ///////////////////////////////////////////////////////////////////////////////
10 28
11 SkPdfContext::SkPdfContext(SkPdfNativeDoc* doc) 29 SkPdfContext::SkPdfContext(SkPdfNativeDoc* doc)
12 : fPdfDoc(doc) 30 : fPdfDoc(doc)
13 , fTmpPageAllocator(new SkPdfAllocator()) { 31 {
32 SkASSERT(fPdfDoc != NULL);
14 } 33 }
15 34
16 SkPdfContext::~SkPdfContext() { 35 void SkPdfContext::parseStream(SkPdfNativeObject* stream, SkCanvas* canvas) {
17 delete fTmpPageAllocator; 36 SkPdfNativeTokenizer* tokenizer = fPdfDoc->tokenizerOfStream(stream, &fTmpPa geAllocator);
37 if (NULL == tokenizer) {
38 // Nothing to parse.
39 return;
40 }
41 PdfMainLooper looper(NULL, tokenizer, this, canvas);
42 looper.loop();
43 // FIXME (scroggo): Will restructure to put tokenizer on the stack.
44 delete tokenizer;
18 } 45 }
46
47 ///////////////////////////////////////////////////////////////////////////////
48
49 // FIXME (scroggo): This probably belongs in a debugging file.
50 // For reportRenderStats declaration.
51 #include "SkPdfRenderer.h"
52
53 // Temp code to measure what operands fail.
54 template <typename T> class SkTDictWithDefaultConstructor : public SkTDict<T> {
55 public:
56 SkTDictWithDefaultConstructor() : SkTDict<T>(10) {}
57 };
58
59 SkTDictWithDefaultConstructor<int> gRenderStats[kCount_SkPdfResult];
60
61 const char* gRenderStatsNames[kCount_SkPdfResult] = {
62 "Success",
63 "Partially implemented",
64 "Not yet implemented",
65 "Ignore Error",
66 "Error",
67 "Unsupported/Unknown"
68 };
69
70 // Declared in SkPdfRenderer.h. Should be moved to a central debugging location.
71 void reportPdfRenderStats() {
72 for (int i = 0 ; i < kCount_SkPdfResult; i++) {
73 SkTDict<int>::Iter iter(gRenderStats[i]);
74 const char* key;
75 int value = 0;
76 while ((key = iter.next(&value)) != NULL) {
77 printf("%s: %s -> count %i\n", gRenderStatsNames[i], key, value);
78 }
79 }
80 }
81
82 #include "SkPdfOps.h"
83
84 SkPdfResult PdfMainLooper::consumeToken(PdfToken& token) {
85 if (token.fType == kKeyword_TokenType && token.fKeywordLength < 256)
86 {
87 PdfOperatorRenderer pdfOperatorRenderer = NULL;
88 if (gPdfOps.find(token.fKeyword, token.fKeywordLength, &pdfOperatorRende rer) &&
89 pdfOperatorRenderer) {
90 SkPdfTokenLooper* childLooper = NULL;
91 // Main work is done by pdfOperatorRenderer(...)
92 SkPdfResult result = pdfOperatorRenderer(fPdfContext, fCanvas, &chil dLooper);
93
94 int cnt = 0;
95 gRenderStats[result].find(token.fKeyword, token.fKeywordLength, &cnt );
96 gRenderStats[result].set(token.fKeyword, token.fKeywordLength, cnt + 1);
97 if (childLooper) {
98 // FIXME (scroggo): Auto delete this.
99 childLooper->setUp(this);
100 childLooper->loop();
101 delete childLooper;
102 }
103 } else {
104 int cnt = 0;
105 gRenderStats[kUnsupported_SkPdfResult].find(token.fKeyword,
106 token.fKeywordLength,
107 &cnt);
108 gRenderStats[kUnsupported_SkPdfResult].set(token.fKeyword,
109 token.fKeywordLength,
110 cnt + 1);
111 }
112 }
113 else if (token.fType == kObject_TokenType)
114 {
115 fPdfContext->fObjectStack.push( token.fObject );
116 }
117 else {
118 // TODO(edisonn): store the keyword as a object, so we can track the loc ation in file,
119 // and report where the error was triggered
120 SkPdfReport(kCodeWarning_SkPdfIssueSeverity, kNYI_SkPdfIssue, token.fKey word, NULL,
121 fPdfContext);
122 return kIgnoreError_SkPdfResult;
123 }
124 return kOK_SkPdfResult;
125 }
126
127 void PdfMainLooper::loop() {
128 PdfToken token;
129 // readToken defined in SkPdfTokenLooper.h
130 // FIXME (scroggo): Remove readToken (which just calls fTokenizer->readToken , plus draws
131 // some debugging info with PDF_DIFF_TRACE_IN_PNG)
132 while (readToken(fTokenizer, &token)) {
133 this->consumeToken(token);
134 }
135 }
OLDNEW
« no previous file with comments | « experimental/PdfViewer/pdfparser/native/SkPdfNativeDoc.cpp ('k') | experimental/PdfViewer/src/SkPdfOps.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698