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 #include "SkCanvas.h" | 8 #include "SkCanvas.h" |
9 #include "SkDevice.h" | 9 #include "SkDevice.h" |
10 #include "SkForceLinking.h" | 10 #include "SkForceLinking.h" |
11 #include "SkGraphics.h" | 11 #include "SkGraphics.h" |
12 #include "SkImageDecoder.h" | 12 #include "SkImageDecoder.h" |
13 #include "SkImageEncoder.h" | 13 #include "SkImageEncoder.h" |
14 #include "SkOSFile.h" | 14 #include "SkOSFile.h" |
15 #include "SkPicture.h" | 15 #include "SkPicture.h" |
16 #include "SkStream.h" | 16 #include "SkStream.h" |
17 #include "SkTypeface.h" | 17 #include "SkTypeface.h" |
18 #include "SkTArray.h" | 18 #include "SkTArray.h" |
19 #include "SkTDict.h" | 19 #include "SkTDict.h" |
20 | 20 |
21 #include "SkPdfBasics.h" | 21 #include "SkPdfGraphicsState.h" |
22 #include "SkPdfNativeTokenizer.h" | 22 #include "SkPdfNativeTokenizer.h" |
23 #include <cstdio> | 23 #include <cstdio> |
24 #include <stack> | 24 #include <stack> |
25 #include <set> | 25 #include <set> |
26 | 26 |
27 extern "C" PdfContext* gPdfContext; | 27 extern "C" SkPdfContext* gPdfContext; |
28 extern "C" SkBitmap* gDumpBitmap; | 28 extern "C" SkBitmap* gDumpBitmap; |
29 extern "C" SkCanvas* gDumpCanvas; | 29 extern "C" SkCanvas* gDumpCanvas; |
30 | 30 |
31 __SK_FORCE_IMAGE_DECODER_LINKING; | 31 __SK_FORCE_IMAGE_DECODER_LINKING; |
32 | 32 |
33 // TODO(edisonn): tool, show what objects were read at least, show the ones not
even read | 33 // TODO(edisonn): tool, show what objects were read at least, show the ones not
even read |
34 // keep for each object pos in file | 34 // keep for each object pos in file |
35 // plug in for VS? syntax coloring, show selected object ... from the text, or f
rom rendered x,y | 35 // plug in for VS? syntax coloring, show selected object ... from the text, or f
rom rendered x,y |
36 | 36 |
37 // TODO(edisonn): security - validate all the user input, all pdf! | 37 // TODO(edisonn): security - validate all the user input, all pdf! |
38 | 38 |
39 // TODO(edisonn): put drawtext in #ifdefs, so comparations will ignore minor cha
nges in text positioning and font | 39 // TODO(edisonn): put drawtext in #ifdefs, so comparations will ignore minor cha
nges in text positioning and font |
40 // this way, we look more at other features and layout in diffs | 40 // this way, we look more at other features and layout in diffs |
41 | 41 |
42 // TODO(edisonn): move trace dump in the get functions, and mapper ones too so i
t ghappens automatically | 42 // TODO(edisonn): move trace dump in the get functions, and mapper ones too so i
t ghappens automatically |
43 /* | 43 /* |
44 #ifdef PDF_TRACE | 44 #ifdef PDF_TRACE |
45 std::string str; | 45 std::string str; |
46 pdfContext->fGraphicsState.fResources->native()->ToString(str); | 46 pdfContext->fGraphicsState.fResources->native()->ToString(str); |
47 printf("Print Tf Resources: %s\n", str.c_str()); | 47 printf("Print Tf Resources: %s\n", str.c_str()); |
48 #endif | 48 #endif |
49 */ | 49 */ |
50 | 50 |
51 #include "SkPdfHeaders_autogen.h" | 51 #include "SkPdfHeaders_autogen.h" |
52 #include "SkPdfMapper_autogen.h" | 52 #include "SkPdfMapper_autogen.h" |
53 #include "SkPdfRenderer.h" | 53 #include "SkPdfRenderer.h" |
54 | 54 |
55 #include "SkPdfBasics.h" | |
56 #include "SkPdfUtils.h" | 55 #include "SkPdfUtils.h" |
57 | 56 |
58 #include "SkPdfFont.h" | 57 #include "SkPdfFont.h" |
59 | 58 |
60 /* | 59 /* |
61 * TODO(edisonn): | 60 * TODO(edisonn): |
62 * - all font types and all ppdf font features | 61 * - all font types and all ppdf font features |
63 * - word spacing | 62 * - word spacing |
64 * - load font for baidu.pdf | 63 * - load font for baidu.pdf |
65 * - load font for youtube.pdf | 64 * - load font for youtube.pdf |
(...skipping 22 matching lines...) Expand all Loading... |
88 } | 87 } |
89 }; | 88 }; |
90 | 89 |
91 StringsInit gStringsInit; | 90 StringsInit gStringsInit; |
92 | 91 |
93 // TODO(edisonn): Document PdfTokenLooper and subclasses. | 92 // TODO(edisonn): Document PdfTokenLooper and subclasses. |
94 class PdfTokenLooper { | 93 class PdfTokenLooper { |
95 protected: | 94 protected: |
96 PdfTokenLooper* fParent; | 95 PdfTokenLooper* fParent; |
97 SkPdfNativeTokenizer* fTokenizer; | 96 SkPdfNativeTokenizer* fTokenizer; |
98 PdfContext* fPdfContext; | 97 SkPdfContext* fPdfContext; |
99 SkCanvas* fCanvas; | 98 SkCanvas* fCanvas; |
100 | 99 |
101 public: | 100 public: |
102 PdfTokenLooper(PdfTokenLooper* parent, | 101 PdfTokenLooper(PdfTokenLooper* parent, |
103 SkPdfNativeTokenizer* tokenizer, | 102 SkPdfNativeTokenizer* tokenizer, |
104 PdfContext* pdfContext, | 103 SkPdfContext* pdfContext, |
105 SkCanvas* canvas) | 104 SkCanvas* canvas) |
106 : fParent(parent), fTokenizer(tokenizer), fPdfContext(pdfContext), fCanv
as(canvas) {} | 105 : fParent(parent), fTokenizer(tokenizer), fPdfContext(pdfContext), fCanv
as(canvas) {} |
107 | 106 |
108 virtual ~PdfTokenLooper() {} | 107 virtual ~PdfTokenLooper() {} |
109 | 108 |
110 virtual PdfResult consumeToken(PdfToken& token) = 0; | 109 virtual SkPdfResult consumeToken(PdfToken& token) = 0; |
111 virtual void loop() = 0; | 110 virtual void loop() = 0; |
112 | 111 |
113 void setUp(PdfTokenLooper* parent) { | 112 void setUp(PdfTokenLooper* parent) { |
114 fParent = parent; | 113 fParent = parent; |
115 fTokenizer = parent->fTokenizer; | 114 fTokenizer = parent->fTokenizer; |
116 fPdfContext = parent->fPdfContext; | 115 fPdfContext = parent->fPdfContext; |
117 fCanvas = parent->fCanvas; | 116 fCanvas = parent->fCanvas; |
118 } | 117 } |
119 | 118 |
120 SkPdfNativeTokenizer* tokenizer() { return fTokenizer; } | 119 SkPdfNativeTokenizer* tokenizer() { return fTokenizer; } |
121 }; | 120 }; |
122 | 121 |
123 class PdfMainLooper : public PdfTokenLooper { | 122 class PdfMainLooper : public PdfTokenLooper { |
124 public: | 123 public: |
125 PdfMainLooper(PdfTokenLooper* parent, | 124 PdfMainLooper(PdfTokenLooper* parent, |
126 SkPdfNativeTokenizer* tokenizer, | 125 SkPdfNativeTokenizer* tokenizer, |
127 PdfContext* pdfContext, | 126 SkPdfContext* pdfContext, |
128 SkCanvas* canvas) | 127 SkCanvas* canvas) |
129 : PdfTokenLooper(parent, tokenizer, pdfContext, canvas) {} | 128 : PdfTokenLooper(parent, tokenizer, pdfContext, canvas) {} |
130 | 129 |
131 virtual PdfResult consumeToken(PdfToken& token); | 130 virtual SkPdfResult consumeToken(PdfToken& token); |
132 virtual void loop(); | 131 virtual void loop(); |
133 }; | 132 }; |
134 | 133 |
135 class PdfInlineImageLooper : public PdfTokenLooper { | 134 class PdfInlineImageLooper : public PdfTokenLooper { |
136 public: | 135 public: |
137 PdfInlineImageLooper() | 136 PdfInlineImageLooper() |
138 : PdfTokenLooper(NULL, NULL, NULL, NULL) {} | 137 : PdfTokenLooper(NULL, NULL, NULL, NULL) {} |
139 | 138 |
140 virtual PdfResult consumeToken(PdfToken& token); | 139 virtual SkPdfResult consumeToken(PdfToken& token); |
141 virtual void loop(); | 140 virtual void loop(); |
142 PdfResult done(); | 141 SkPdfResult done(); |
143 }; | 142 }; |
144 | 143 |
145 class PdfCompatibilitySectionLooper : public PdfTokenLooper { | 144 class PdfCompatibilitySectionLooper : public PdfTokenLooper { |
146 public: | 145 public: |
147 PdfCompatibilitySectionLooper() | 146 PdfCompatibilitySectionLooper() |
148 : PdfTokenLooper(NULL, NULL, NULL, NULL) {} | 147 : PdfTokenLooper(NULL, NULL, NULL, NULL) {} |
149 | 148 |
150 virtual PdfResult consumeToken(PdfToken& token); | 149 virtual SkPdfResult consumeToken(PdfToken& token); |
151 virtual void loop(); | 150 virtual void loop(); |
152 }; | 151 }; |
153 | 152 |
154 // Utilities | 153 // Utilities |
155 static void setup_bitmap(SkBitmap* bitmap, int width, int height, SkColor color
= SK_ColorWHITE) { | 154 static void setup_bitmap(SkBitmap* bitmap, int width, int height, SkColor color
= SK_ColorWHITE) { |
156 bitmap->setConfig(SkBitmap::kARGB_8888_Config, width, height); | 155 bitmap->setConfig(SkBitmap::kARGB_8888_Config, width, height); |
157 | 156 |
158 bitmap->allocPixels(); | 157 bitmap->allocPixels(); |
159 bitmap->eraseColor(color); | 158 bitmap->eraseColor(color); |
160 } | 159 } |
(...skipping 28 matching lines...) Expand all Loading... |
189 SkDoubleToScalar(1)); | 188 SkDoubleToScalar(1)); |
190 | 189 |
191 return matrix; | 190 return matrix; |
192 } | 191 } |
193 | 192 |
194 SkMatrix SkMatrixFromPdfArray(SkPdfArray* pdfArray) { | 193 SkMatrix SkMatrixFromPdfArray(SkPdfArray* pdfArray) { |
195 double array[6]; | 194 double array[6]; |
196 | 195 |
197 // TODO(edisonn): security issue, ret if size() != 6 | 196 // TODO(edisonn): security issue, ret if size() != 6 |
198 for (int i = 0; i < 6; i++) { | 197 for (int i = 0; i < 6; i++) { |
199 const SkPdfObject* elem = pdfArray->operator [](i); | 198 const SkPdfNativeObject* elem = pdfArray->operator [](i); |
200 if (elem == NULL || !elem->isNumber()) { | 199 if (elem == NULL || !elem->isNumber()) { |
201 return SkMatrix::I(); // TODO(edisonn): report issue | 200 return SkMatrix::I(); // TODO(edisonn): report issue |
202 } | 201 } |
203 array[i] = elem->numberValue(); | 202 array[i] = elem->numberValue(); |
204 } | 203 } |
205 | 204 |
206 return SkMatrixFromPdfMatrix(array); | 205 return SkMatrixFromPdfMatrix(array); |
207 } | 206 } |
208 | 207 |
209 | 208 |
210 extern "C" SkNativeParsedPDF* gDoc; | 209 extern "C" SkPdfNativeDoc* gDoc; |
211 SkBitmap* gDumpBitmap = NULL; | 210 SkBitmap* gDumpBitmap = NULL; |
212 SkCanvas* gDumpCanvas = NULL; | 211 SkCanvas* gDumpCanvas = NULL; |
213 char gLastKeyword[100] = ""; | 212 char gLastKeyword[100] = ""; |
214 int gLastOpKeyword = -1; | 213 int gLastOpKeyword = -1; |
215 char allOpWithVisualEffects[100] = ",S,s,f,F,f*,B,B*,b,b*,n,Tj,TJ,\',\",d0,d1,sh
,EI,Do,EX,"; | 214 char allOpWithVisualEffects[100] = ",S,s,f,F,f*,B,B*,b,b*,n,Tj,TJ,\',\",d0,d1,sh
,EI,Do,EX,"; |
216 int gReadOp = 0; | 215 int gReadOp = 0; |
217 | 216 |
218 | 217 |
219 #ifdef PDF_TRACE_DIFF_IN_PNG | 218 #ifdef PDF_TRACE_DIFF_IN_PNG |
220 static bool hasVisualEffect(const char* pdfOp) { | 219 static bool hasVisualEffect(const char* pdfOp) { |
221 return true; | 220 return true; |
222 if (*pdfOp == '\0') return false; | 221 if (*pdfOp == '\0') return false; |
223 | 222 |
224 char markedPdfOp[100] = ","; | 223 char markedPdfOp[100] = ","; |
225 strcat(markedPdfOp, pdfOp); | 224 strcat(markedPdfOp, pdfOp); |
226 strcat(markedPdfOp, ","); | 225 strcat(markedPdfOp, ","); |
227 | 226 |
228 return (strstr(allOpWithVisualEffects, markedPdfOp) != NULL); | 227 return (strstr(allOpWithVisualEffects, markedPdfOp) != NULL); |
229 } | 228 } |
230 #endif // PDF_TRACE_DIFF_IN_PNG | 229 #endif // PDF_TRACE_DIFF_IN_PNG |
231 | 230 |
232 | 231 |
233 | 232 |
234 // TODO(edisonn): Pass PdfContext and SkCanvasd only with the define for instrum
entation. | 233 // TODO(edisonn): Pass SkPdfContext and SkCanvasd only with the define for instr
umentation. |
235 static bool readToken(SkPdfNativeTokenizer* fTokenizer, PdfToken* token) { | 234 static bool readToken(SkPdfNativeTokenizer* fTokenizer, PdfToken* token) { |
236 bool ret = fTokenizer->readToken(token); | 235 bool ret = fTokenizer->readToken(token); |
237 | 236 |
238 gReadOp++; | 237 gReadOp++; |
239 gLastOpKeyword++; | 238 gLastOpKeyword++; |
240 #ifdef PDF_TRACE_DIFF_IN_PNG | 239 #ifdef PDF_TRACE_DIFF_IN_PNG |
241 // TODO(edisonn): compare with old bitmap, and save only new bits are availa
ble, and save | 240 // TODO(edisonn): compare with old bitmap, and save only new bits are availa
ble, and save |
242 // the numbar and name of last operation, so the file name will reflect op t
hat changed. | 241 // the numbar and name of last operation, so the file name will reflect op t
hat changed. |
243 if (gLastKeyword[0] && hasVisualEffect(gLastKeyword)) { // TODO(edisonn): a
nd has dirty bits. | 242 if (gLastKeyword[0] && hasVisualEffect(gLastKeyword)) { // TODO(edisonn): a
nd has dirty bits. |
244 gDumpCanvas->flush(); | 243 gDumpCanvas->flush(); |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
319 gLastKeyword[0] = '\0'; | 318 gLastKeyword[0] = '\0'; |
320 } | 319 } |
321 | 320 |
322 #endif | 321 #endif |
323 | 322 |
324 return ret; | 323 return ret; |
325 } | 324 } |
326 | 325 |
327 | 326 |
328 | 327 |
329 typedef PdfResult (*PdfOperatorRenderer)(PdfContext*, SkCanvas*, PdfTokenLooper*
*); | 328 typedef SkPdfResult (*PdfOperatorRenderer)(SkPdfContext*, SkCanvas*, PdfTokenLoo
per**); |
330 | 329 |
331 SkTDict<PdfOperatorRenderer> gPdfOps(100); | 330 SkTDict<PdfOperatorRenderer> gPdfOps(100); |
332 | 331 |
333 | 332 |
334 template <typename T> class SkTDictWithDefaultConstructor : public SkTDict<T> { | 333 template <typename T> class SkTDictWithDefaultConstructor : public SkTDict<T> { |
335 public: | 334 public: |
336 SkTDictWithDefaultConstructor() : SkTDict<T>(10) {} | 335 SkTDictWithDefaultConstructor() : SkTDict<T>(10) {} |
337 }; | 336 }; |
338 | 337 |
339 SkTDictWithDefaultConstructor<int> gRenderStats[kCount_PdfResult]; | 338 SkTDictWithDefaultConstructor<int> gRenderStats[kCount_SkPdfResult]; |
340 | 339 |
341 const char* gRenderStatsNames[kCount_PdfResult] = { | 340 const char* gRenderStatsNames[kCount_SkPdfResult] = { |
342 "Success", | 341 "Success", |
343 "Partially implemented", | 342 "Partially implemented", |
344 "Not yet implemented", | 343 "Not yet implemented", |
345 "Ignore Error", | 344 "Ignore Error", |
346 "Error", | 345 "Error", |
347 "Unsupported/Unknown" | 346 "Unsupported/Unknown" |
348 }; | 347 }; |
349 | 348 |
350 static PdfResult DrawText(PdfContext* pdfContext, | 349 static SkPdfResult DrawText(SkPdfContext* pdfContext, |
351 const SkPdfObject* _str, | 350 const SkPdfNativeObject* _str, |
352 SkCanvas* canvas) | 351 SkCanvas* canvas) |
353 { | 352 { |
354 | 353 |
355 SkPdfFont* skfont = pdfContext->fGraphicsState.fSkFont; | 354 SkPdfFont* skfont = pdfContext->fGraphicsState.fSkFont; |
356 if (skfont == NULL) { | 355 if (skfont == NULL) { |
357 skfont = SkPdfFont::Default(); | 356 skfont = SkPdfFont::Default(); |
358 } | 357 } |
359 | 358 |
360 | 359 |
361 if (_str == NULL || !_str->isAnyString()) { | 360 if (_str == NULL || !_str->isAnyString()) { |
362 // TODO(edisonn): report warning | 361 // TODO(edisonn): report warning |
363 return kIgnoreError_PdfResult; | 362 return kIgnoreError_SkPdfResult; |
364 } | 363 } |
365 const SkPdfString* str = (const SkPdfString*)_str; | 364 const SkPdfString* str = (const SkPdfString*)_str; |
366 | 365 |
367 SkUnencodedText binary(str); | 366 SkUnencodedText binary(str); |
368 | 367 |
369 SkDecodedText decoded; | 368 SkDecodedText decoded; |
370 | 369 |
371 if (skfont->encoding() == NULL) { | 370 if (skfont->encoding() == NULL) { |
372 // TODO(edisonn): report warning | 371 // TODO(edisonn): report warning |
373 return kNYI_PdfResult; | 372 return kNYI_SkPdfResult; |
374 } | 373 } |
375 | 374 |
376 skfont->encoding()->decodeText(binary, &decoded); | 375 skfont->encoding()->decodeText(binary, &decoded); |
377 | 376 |
378 SkPaint paint; | 377 SkPaint paint; |
379 // TODO(edisonn): when should fCurFont->GetFontSize() used? When cur is fCur
FontSize == 0? | 378 // TODO(edisonn): when should fCurFont->GetFontSize() used? When cur is fCur
FontSize == 0? |
380 // Or maybe just not call setTextSize at all? | 379 // Or maybe just not call setTextSize at all? |
381 if (pdfContext->fGraphicsState.fCurFontSize != 0) { | 380 if (pdfContext->fGraphicsState.fCurFontSize != 0) { |
382 paint.setTextSize(SkDoubleToScalar(pdfContext->fGraphicsState.fCurFontSi
ze)); | 381 paint.setTextSize(SkDoubleToScalar(pdfContext->fGraphicsState.fCurFontSi
ze)); |
383 } | 382 } |
384 | 383 |
385 // if (fCurFont && fCurFont->GetFontScale() != 0) { | 384 // if (fCurFont && fCurFont->GetFontScale() != 0) { |
386 // paint.setTextScaleX(SkFloatToScalar(fCurFont->GetFontScale() / 100.0))
; | 385 // paint.setTextScaleX(SkFloatToScalar(fCurFont->GetFontScale() / 100.0))
; |
387 // } | 386 // } |
388 | 387 |
389 pdfContext->fGraphicsState.applyGraphicsState(&paint, false); | 388 pdfContext->fGraphicsState.applyGraphicsState(&paint, false); |
390 | 389 |
391 skfont->drawText(decoded, &paint, pdfContext, canvas); | 390 skfont->drawText(decoded, &paint, pdfContext, canvas); |
392 | 391 |
393 return kOK_PdfResult; | 392 return kOK_SkPdfResult; |
394 } | 393 } |
395 | 394 |
396 // TODO(edisonn): create header files with declarations! | 395 // TODO(edisonn): create header files with declarations! |
397 PdfResult PdfOp_q(PdfContext* pdfContext, SkCanvas* canvas, PdfTokenLooper** loo
per); | 396 SkPdfResult PdfOp_q(SkPdfContext* pdfContext, SkCanvas* canvas, PdfTokenLooper**
looper); |
398 PdfResult PdfOp_Q(PdfContext* pdfContext, SkCanvas* canvas, PdfTokenLooper** loo
per); | 397 SkPdfResult PdfOp_Q(SkPdfContext* pdfContext, SkCanvas* canvas, PdfTokenLooper**
looper); |
399 PdfResult PdfOp_Tw(PdfContext* pdfContext, SkCanvas* canvas, PdfTokenLooper** lo
oper); | 398 SkPdfResult PdfOp_Tw(SkPdfContext* pdfContext, SkCanvas* canvas, PdfTokenLooper*
* looper); |
400 PdfResult PdfOp_Tc(PdfContext* pdfContext, SkCanvas* canvas, PdfTokenLooper** lo
oper); | 399 SkPdfResult PdfOp_Tc(SkPdfContext* pdfContext, SkCanvas* canvas, PdfTokenLooper*
* looper); |
401 | 400 |
402 // TODO(edisonn): perf!!! | 401 // TODO(edisonn): perf!!! |
403 | 402 |
404 static SkColorTable* getGrayColortable() { | 403 static SkColorTable* getGrayColortable() { |
405 static SkColorTable* grayColortable = NULL; | 404 static SkColorTable* grayColortable = NULL; |
406 if (grayColortable == NULL) { | 405 if (grayColortable == NULL) { |
407 SkPMColor* colors = new SkPMColor[256]; | 406 SkPMColor* colors = new SkPMColor[256]; |
408 for (int i = 0 ; i < 256; i++) { | 407 for (int i = 0 ; i < 256; i++) { |
409 colors[i] = SkPreMultiplyARGB(255, i, i, i); | 408 colors[i] = SkPreMultiplyARGB(255, i, i, i); |
410 } | 409 } |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
467 | 466 |
468 // utils | 467 // utils |
469 | 468 |
470 // TODO(edisonn): add cache, or put the bitmap property directly on the PdfObjec
t | 469 // TODO(edisonn): add cache, or put the bitmap property directly on the PdfObjec
t |
471 // TODO(edisonn): deal with colorSpaces, we could add them to SkBitmap::Config | 470 // TODO(edisonn): deal with colorSpaces, we could add them to SkBitmap::Config |
472 // TODO(edisonn): preserve A1 format that skia knows, + fast convert from 111, 2
22, 444 to closest | 471 // TODO(edisonn): preserve A1 format that skia knows, + fast convert from 111, 2
22, 444 to closest |
473 // skia format, through a table | 472 // skia format, through a table |
474 | 473 |
475 // this functions returns the image, it does not look at the smask. | 474 // this functions returns the image, it does not look at the smask. |
476 | 475 |
477 static SkBitmap* getImageFromObjectCore(PdfContext* pdfContext, SkPdfImageDictio
nary* image, bool transparencyMask) { | 476 static SkBitmap* getImageFromObjectCore(SkPdfContext* pdfContext, SkPdfImageDict
ionary* image, bool transparencyMask) { |
478 if (image == NULL || !image->hasStream()) { | 477 if (image == NULL || !image->hasStream()) { |
479 // TODO(edisonn): report warning to be used in testing. | 478 // TODO(edisonn): report warning to be used in testing. |
480 return NULL; | 479 return NULL; |
481 } | 480 } |
482 | 481 |
483 int64_t bpc = image->BitsPerComponent(pdfContext->fPdfDoc); | 482 int64_t bpc = image->BitsPerComponent(pdfContext->fPdfDoc); |
484 int64_t width = image->Width(pdfContext->fPdfDoc); | 483 int64_t width = image->Width(pdfContext->fPdfDoc); |
485 int64_t height = image->Height(pdfContext->fPdfDoc); | 484 int64_t height = image->Height(pdfContext->fPdfDoc); |
486 std::string colorSpace = "DeviceRGB"; | 485 std::string colorSpace = "DeviceRGB"; |
487 | 486 |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
586 | 585 |
587 SkBitmap* bitmap = transferImageStreamToBitmap( | 586 SkBitmap* bitmap = transferImageStreamToBitmap( |
588 (unsigned char*)uncompressedStream, uncompressedStreamLength, | 587 (unsigned char*)uncompressedStream, uncompressedStreamLength, |
589 (int)width, (int)height, bytesPerLine, | 588 (int)width, (int)height, bytesPerLine, |
590 (int)bpc, colorSpace, | 589 (int)bpc, colorSpace, |
591 transparencyMask); | 590 transparencyMask); |
592 | 591 |
593 return bitmap; | 592 return bitmap; |
594 } | 593 } |
595 | 594 |
596 static SkBitmap* getImageFromObject(PdfContext* pdfContext, SkPdfImageDictionary
* image, bool transparencyMask) { | 595 static SkBitmap* getImageFromObject(SkPdfContext* pdfContext, SkPdfImageDictiona
ry* image, bool transparencyMask) { |
597 if (!transparencyMask) { | 596 if (!transparencyMask) { |
598 if (!image->hasData(SkPdfObject::kBitmap_Data)) { | 597 if (!image->hasData(SkPdfNativeObject::kBitmap_Data)) { |
599 SkBitmap* bitmap = getImageFromObjectCore(pdfContext, image, transpa
rencyMask); | 598 SkBitmap* bitmap = getImageFromObjectCore(pdfContext, image, transpa
rencyMask); |
600 image->setData(bitmap, SkPdfObject::kBitmap_Data); | 599 image->setData(bitmap, SkPdfNativeObject::kBitmap_Data); |
601 } | 600 } |
602 return (SkBitmap*) image->data(SkPdfObject::kBitmap_Data); | 601 return (SkBitmap*) image->data(SkPdfNativeObject::kBitmap_Data); |
603 } else { | 602 } else { |
604 return getImageFromObjectCore(pdfContext, image, transparencyMask); | 603 return getImageFromObjectCore(pdfContext, image, transparencyMask); |
605 } | 604 } |
606 } | 605 } |
607 | 606 |
608 static SkBitmap* getSmaskFromObject(PdfContext* pdfContext, SkPdfImageDictionary
* obj) { | 607 static SkBitmap* getSmaskFromObject(SkPdfContext* pdfContext, SkPdfImageDictiona
ry* obj) { |
609 SkPdfImageDictionary* sMask = obj->SMask(pdfContext->fPdfDoc); | 608 SkPdfImageDictionary* sMask = obj->SMask(pdfContext->fPdfDoc); |
610 | 609 |
611 if (sMask) { | 610 if (sMask) { |
612 return getImageFromObject(pdfContext, sMask, true); | 611 return getImageFromObject(pdfContext, sMask, true); |
613 } | 612 } |
614 | 613 |
615 // TODO(edisonn): implement GS SMask. Default to empty right now. | 614 // TODO(edisonn): implement GS SMask. Default to empty right now. |
616 return pdfContext->fGraphicsState.fSMask; | 615 return pdfContext->fGraphicsState.fSMask; |
617 } | 616 } |
618 | 617 |
619 static PdfResult doXObject_Image(PdfContext* pdfContext, SkCanvas* canvas, SkPdf
ImageDictionary* skpdfimage) { | 618 static SkPdfResult doXObject_Image(SkPdfContext* pdfContext, SkCanvas* canvas, S
kPdfImageDictionary* skpdfimage) { |
620 if (skpdfimage == NULL) { | 619 if (skpdfimage == NULL) { |
621 return kIgnoreError_PdfResult; | 620 return kIgnoreError_SkPdfResult; |
622 } | 621 } |
623 | 622 |
624 SkBitmap* image = getImageFromObject(pdfContext, skpdfimage, false); | 623 SkBitmap* image = getImageFromObject(pdfContext, skpdfimage, false); |
625 SkBitmap* sMask = getSmaskFromObject(pdfContext, skpdfimage); | 624 SkBitmap* sMask = getSmaskFromObject(pdfContext, skpdfimage); |
626 | 625 |
627 canvas->save(); | 626 canvas->save(); |
628 canvas->setMatrix(pdfContext->fGraphicsState.fCTM); | 627 canvas->setMatrix(pdfContext->fGraphicsState.fCTM); |
629 | 628 |
630 SkScalar z = SkIntToScalar(0); | 629 SkScalar z = SkIntToScalar(0); |
631 SkScalar one = SkIntToScalar(1); | 630 SkScalar one = SkIntToScalar(1); |
(...skipping 29 matching lines...) Expand all Loading... |
661 canvas->drawBitmapRect(*image, dst, NULL); | 660 canvas->drawBitmapRect(*image, dst, NULL); |
662 SkPaint xfer; | 661 SkPaint xfer; |
663 // TODO(edisonn): is the blend mode specified already implicitly/explici
tly in pdf? | 662 // TODO(edisonn): is the blend mode specified already implicitly/explici
tly in pdf? |
664 xfer.setXfermodeMode(SkXfermode::kSrcOut_Mode); // SkXfermode::kSdtOut_M
ode | 663 xfer.setXfermodeMode(SkXfermode::kSrcOut_Mode); // SkXfermode::kSdtOut_M
ode |
665 canvas->drawBitmapRect(*sMask, dst, &xfer); | 664 canvas->drawBitmapRect(*sMask, dst, &xfer); |
666 canvas->restore(); | 665 canvas->restore(); |
667 } | 666 } |
668 | 667 |
669 canvas->restore(); | 668 canvas->restore(); |
670 | 669 |
671 return kPartial_PdfResult; | 670 return kPartial_SkPdfResult; |
672 } | 671 } |
673 | 672 |
674 //TODO(edisonn): options for implementing isolation and knockout | 673 //TODO(edisonn): options for implementing isolation and knockout |
675 // 1) emulate them (current solution) | 674 // 1) emulate them (current solution) |
676 // PRO: simple | 675 // PRO: simple |
677 // CON: will need to use readPixels, which means serious perf issues | 676 // CON: will need to use readPixels, which means serious perf issues |
678 // 2) Compile a plan for an array of matrixes, compose the result at the end | 677 // 2) Compile a plan for an array of matrixes, compose the result at the end |
679 // PRO: might be faster then 1, no need to readPixels | 678 // PRO: might be faster then 1, no need to readPixels |
680 // CON: multiple drawings (but on smaller areas), pay a price at loading pdf
to compute a pdf draw plan | 679 // CON: multiple drawings (but on smaller areas), pay a price at loading pdf
to compute a pdf draw plan |
681 // on average, a load with empty draw is 100ms on all the skps we have,
for complete sites | 680 // on average, a load with empty draw is 100ms on all the skps we have,
for complete sites |
682 // 3) support them natively in SkCanvas | 681 // 3) support them natively in SkCanvas |
683 // PRO: simple | 682 // PRO: simple |
684 // CON: we would still need to use a form of readPixels anyway, so perf migh
t be the same as 1) | 683 // CON: we would still need to use a form of readPixels anyway, so perf migh
t be the same as 1) |
685 // 4) compile a plan using pathops, and render once without any fancy rules with
backdrop | 684 // 4) compile a plan using pathops, and render once without any fancy rules with
backdrop |
686 // PRO: simple, fast | 685 // PRO: simple, fast |
687 // CON: pathops must be bug free first + time to compute new paths | 686 // CON: pathops must be bug free first + time to compute new paths |
688 // pay a price at loading pdf to compute a pdf draw plan | 687 // pay a price at loading pdf to compute a pdf draw plan |
689 // on average, a load with empty draw is 100ms on all the skps we have,
for complete sites | 688 // on average, a load with empty draw is 100ms on all the skps we have,
for complete sites |
690 // 5) for knockout, render the objects in reverse order, and add every object to
the clip, and any new draw will be cliped | 689 // 5) for knockout, render the objects in reverse order, and add every object to
the clip, and any new draw will be cliped |
691 | 690 |
692 | 691 |
693 // TODO(edisonn): draw plan from point! - list of draw ops of a point, like a tr
ee! | 692 // TODO(edisonn): draw plan from point! - list of draw ops of a point, like a tr
ee! |
694 // TODO(edisonn): Minimal PDF to draw some points - remove everything that it is
not needed, save pdf uncompressed | 693 // TODO(edisonn): Minimal PDF to draw some points - remove everything that it is
not needed, save pdf uncompressed |
695 | 694 |
696 | 695 |
697 | 696 |
698 static void doGroup_before(PdfContext* pdfContext, SkCanvas* canvas, SkRect bbox
, SkPdfTransparencyGroupDictionary* tgroup, bool page) { | 697 static void doGroup_before(SkPdfContext* pdfContext, SkCanvas* canvas, SkRect bb
ox, SkPdfTransparencyGroupDictionary* tgroup, bool page) { |
699 SkRect bboxOrig = bbox; | 698 SkRect bboxOrig = bbox; |
700 SkBitmap backdrop; | 699 SkBitmap backdrop; |
701 bool isolatedGroup = tgroup->I(pdfContext->fPdfDoc); | 700 bool isolatedGroup = tgroup->I(pdfContext->fPdfDoc); |
702 // bool knockoutGroup = tgroup->K(pdfContext->fPdfDoc); | 701 // bool knockoutGroup = tgroup->K(pdfContext->fPdfDoc); |
703 SkPaint paint; | 702 SkPaint paint; |
704 pdfContext->fGraphicsState.applyGraphicsState(&paint, false); | 703 pdfContext->fGraphicsState.applyGraphicsState(&paint, false); |
705 canvas->saveLayer(&bboxOrig, isolatedGroup ? &paint : NULL); | 704 canvas->saveLayer(&bboxOrig, isolatedGroup ? &paint : NULL); |
706 } | 705 } |
707 | 706 |
708 // TODO(edisonn): non isolation implemented in skia | 707 // TODO(edisonn): non isolation implemented in skia |
709 //static void doGroup_after(PdfContext* pdfContext, SkCanvas* canvas, SkRect bbo
x, SkPdfTransparencyGroupDictionary* tgroup) { | 708 //static void doGroup_after(SkPdfContext* pdfContext, SkCanvas* canvas, SkRect b
box, SkPdfTransparencyGroupDictionary* tgroup) { |
710 // if not isolated | 709 // if not isolated |
711 // canvas->drawBitmapRect(backdrop, bboxOrig, NULL); | 710 // canvas->drawBitmapRect(backdrop, bboxOrig, NULL); |
712 //} | 711 //} |
713 | 712 |
714 static PdfResult doXObject_Form(PdfContext* pdfContext, SkCanvas* canvas, SkPdfT
ype1FormDictionary* skobj) { | 713 static SkPdfResult doXObject_Form(SkPdfContext* pdfContext, SkCanvas* canvas, Sk
PdfType1FormDictionary* skobj) { |
715 if (!skobj || !skobj->hasStream()) { | 714 if (!skobj || !skobj->hasStream()) { |
716 return kIgnoreError_PdfResult; | 715 return kIgnoreError_SkPdfResult; |
717 } | 716 } |
718 | 717 |
719 if (!skobj->has_BBox()) { | 718 if (!skobj->has_BBox()) { |
720 return kIgnoreError_PdfResult; | 719 return kIgnoreError_SkPdfResult; |
721 } | 720 } |
722 | 721 |
723 PdfOp_q(pdfContext, canvas, NULL); | 722 PdfOp_q(pdfContext, canvas, NULL); |
724 | 723 |
725 | 724 |
726 if (skobj->Resources(pdfContext->fPdfDoc)) { | 725 if (skobj->Resources(pdfContext->fPdfDoc)) { |
727 pdfContext->fGraphicsState.fResources = skobj->Resources(pdfContext->fPd
fDoc); | 726 pdfContext->fGraphicsState.fResources = skobj->Resources(pdfContext->fPd
fDoc); |
728 } | 727 } |
729 | 728 |
730 SkTraceMatrix(pdfContext->fGraphicsState.fCTM, "Current matrix"); | 729 SkTraceMatrix(pdfContext->fGraphicsState.fCTM, "Current matrix"); |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
766 } | 765 } |
767 | 766 |
768 // TODO(edisonn): should we restore the variable stack at the same state? | 767 // TODO(edisonn): should we restore the variable stack at the same state? |
769 // There could be operands left, that could be consumed by a parent tokenize
r when we pop. | 768 // There could be operands left, that could be consumed by a parent tokenize
r when we pop. |
770 | 769 |
771 if (skobj->has_Group()) { | 770 if (skobj->has_Group()) { |
772 canvas->restore(); | 771 canvas->restore(); |
773 } | 772 } |
774 | 773 |
775 PdfOp_Q(pdfContext, canvas, NULL); | 774 PdfOp_Q(pdfContext, canvas, NULL); |
776 return kPartial_PdfResult; | 775 return kPartial_SkPdfResult; |
777 } | 776 } |
778 | 777 |
779 | 778 |
780 // TODO(edisonn): Extract a class like ObjWithStream | 779 // TODO(edisonn): Extract a class like ObjWithStream |
781 static PdfResult doXObject_Pattern(PdfContext* pdfContext, SkCanvas* canvas, SkP
dfType1PatternDictionary* skobj) { | 780 static SkPdfResult doXObject_Pattern(SkPdfContext* pdfContext, SkCanvas* canvas,
SkPdfType1PatternDictionary* skobj) { |
782 if (!skobj || !skobj->hasStream()) { | 781 if (!skobj || !skobj->hasStream()) { |
783 return kIgnoreError_PdfResult; | 782 return kIgnoreError_SkPdfResult; |
784 } | 783 } |
785 | 784 |
786 if (!skobj->has_BBox()) { | 785 if (!skobj->has_BBox()) { |
787 return kIgnoreError_PdfResult; | 786 return kIgnoreError_SkPdfResult; |
788 } | 787 } |
789 | 788 |
790 PdfOp_q(pdfContext, canvas, NULL); | 789 PdfOp_q(pdfContext, canvas, NULL); |
791 | 790 |
792 | 791 |
793 if (skobj->Resources(pdfContext->fPdfDoc)) { | 792 if (skobj->Resources(pdfContext->fPdfDoc)) { |
794 pdfContext->fGraphicsState.fResources = skobj->Resources(pdfContext->fPd
fDoc); | 793 pdfContext->fGraphicsState.fResources = skobj->Resources(pdfContext->fPd
fDoc); |
795 } | 794 } |
796 | 795 |
797 SkTraceMatrix(pdfContext->fGraphicsState.fContentStreamMatrix, "Current Cont
ent stream matrix"); | 796 SkTraceMatrix(pdfContext->fGraphicsState.fContentStreamMatrix, "Current Cont
ent stream matrix"); |
(...skipping 20 matching lines...) Expand all Loading... |
818 if (tokenizer != NULL) { | 817 if (tokenizer != NULL) { |
819 PdfMainLooper looper(NULL, tokenizer, pdfContext, canvas); | 818 PdfMainLooper looper(NULL, tokenizer, pdfContext, canvas); |
820 looper.loop(); | 819 looper.loop(); |
821 delete tokenizer; | 820 delete tokenizer; |
822 } | 821 } |
823 | 822 |
824 // TODO(edisonn): should we restore the variable stack at the same state? | 823 // TODO(edisonn): should we restore the variable stack at the same state? |
825 // There could be operands left, that could be consumed by a parent tokenize
r when we pop. | 824 // There could be operands left, that could be consumed by a parent tokenize
r when we pop. |
826 | 825 |
827 PdfOp_Q(pdfContext, canvas, NULL); | 826 PdfOp_Q(pdfContext, canvas, NULL); |
828 return kPartial_PdfResult; | 827 return kPartial_SkPdfResult; |
829 } | 828 } |
830 | 829 |
831 | 830 |
832 //static PdfResult doXObject_PS(PdfContext* pdfContext, SkCanvas* canvas, const
SkPdfObject* obj) { | 831 //static SkPdfResult doXObject_PS(SkPdfContext* pdfContext, SkCanvas* canvas, co
nst SkPdfNativeObject* obj) { |
833 // return kNYI_PdfResult; | 832 // return kNYI_SkPdfResult; |
834 //} | 833 //} |
835 | 834 |
836 PdfResult doType3Char(PdfContext* pdfContext, SkCanvas* canvas, const SkPdfObjec
t* skobj, SkRect bBox, SkMatrix matrix, double textSize) { | 835 SkPdfResult doType3Char(SkPdfContext* pdfContext, SkCanvas* canvas, const SkPdfN
ativeObject* skobj, SkRect bBox, SkMatrix matrix, double textSize) { |
837 if (!skobj || !skobj->hasStream()) { | 836 if (!skobj || !skobj->hasStream()) { |
838 return kIgnoreError_PdfResult; | 837 return kIgnoreError_SkPdfResult; |
839 } | 838 } |
840 | 839 |
841 PdfOp_q(pdfContext, canvas, NULL); | 840 PdfOp_q(pdfContext, canvas, NULL); |
842 | 841 |
843 pdfContext->fGraphicsState.fMatrixTm.preConcat(matrix); | 842 pdfContext->fGraphicsState.fMatrixTm.preConcat(matrix); |
844 pdfContext->fGraphicsState.fMatrixTm.preScale(SkDoubleToScalar(textSize), Sk
DoubleToScalar(textSize)); | 843 pdfContext->fGraphicsState.fMatrixTm.preScale(SkDoubleToScalar(textSize), Sk
DoubleToScalar(textSize)); |
845 pdfContext->fGraphicsState.fMatrixTlm = pdfContext->fGraphicsState.fMatrixTm
; | 844 pdfContext->fGraphicsState.fMatrixTlm = pdfContext->fGraphicsState.fMatrixTm
; |
846 | 845 |
847 pdfContext->fGraphicsState.fCTM = pdfContext->fGraphicsState.fMatrixTm; | 846 pdfContext->fGraphicsState.fCTM = pdfContext->fGraphicsState.fMatrixTm; |
848 pdfContext->fGraphicsState.fCTM.preScale(SkDoubleToScalar(1), SkDoubleToScal
ar(-1)); | 847 pdfContext->fGraphicsState.fCTM.preScale(SkDoubleToScalar(1), SkDoubleToScal
ar(-1)); |
(...skipping 19 matching lines...) Expand all Loading... |
868 if (tokenizer != NULL) { | 867 if (tokenizer != NULL) { |
869 PdfMainLooper looper(NULL, tokenizer, pdfContext, canvas); | 868 PdfMainLooper looper(NULL, tokenizer, pdfContext, canvas); |
870 looper.loop(); | 869 looper.loop(); |
871 delete tokenizer; | 870 delete tokenizer; |
872 } | 871 } |
873 | 872 |
874 // TODO(edisonn): should we restore the variable stack at the same state? | 873 // TODO(edisonn): should we restore the variable stack at the same state? |
875 // There could be operands left, that could be consumed by a parent tokenize
r when we pop. | 874 // There could be operands left, that could be consumed by a parent tokenize
r when we pop. |
876 PdfOp_Q(pdfContext, canvas, NULL); | 875 PdfOp_Q(pdfContext, canvas, NULL); |
877 | 876 |
878 return kPartial_PdfResult; | 877 return kPartial_SkPdfResult; |
879 } | 878 } |
880 | 879 |
881 | 880 |
882 // TODO(edisonn): make sure the pointer is unique | 881 // TODO(edisonn): make sure the pointer is unique |
883 std::set<const SkPdfObject*> gInRendering; | 882 std::set<const SkPdfNativeObject*> gInRendering; |
884 | 883 |
885 class CheckRecursiveRendering { | 884 class CheckRecursiveRendering { |
886 const SkPdfObject* fUniqueData; | 885 const SkPdfNativeObject* fUniqueData; |
887 public: | 886 public: |
888 CheckRecursiveRendering(const SkPdfObject* obj) : fUniqueData(obj) { | 887 CheckRecursiveRendering(const SkPdfNativeObject* obj) : fUniqueData(obj) { |
889 gInRendering.insert(obj); | 888 gInRendering.insert(obj); |
890 } | 889 } |
891 | 890 |
892 ~CheckRecursiveRendering() { | 891 ~CheckRecursiveRendering() { |
893 //SkASSERT(fObj.fInRendering); | 892 //SkASSERT(fObj.fInRendering); |
894 gInRendering.erase(fUniqueData); | 893 gInRendering.erase(fUniqueData); |
895 } | 894 } |
896 | 895 |
897 static bool IsInRendering(const SkPdfObject* obj) { | 896 static bool IsInRendering(const SkPdfNativeObject* obj) { |
898 return gInRendering.find(obj) != gInRendering.end(); | 897 return gInRendering.find(obj) != gInRendering.end(); |
899 } | 898 } |
900 }; | 899 }; |
901 | 900 |
902 static PdfResult doXObject(PdfContext* pdfContext, SkCanvas* canvas, const SkPdf
Object* obj) { | 901 static SkPdfResult doXObject(SkPdfContext* pdfContext, SkCanvas* canvas, const S
kPdfNativeObject* obj) { |
903 if (CheckRecursiveRendering::IsInRendering(obj)) { | 902 if (CheckRecursiveRendering::IsInRendering(obj)) { |
904 // Oops, corrupt PDF! | 903 // Oops, corrupt PDF! |
905 return kIgnoreError_PdfResult; | 904 return kIgnoreError_SkPdfResult; |
906 } | 905 } |
907 | 906 |
908 CheckRecursiveRendering checkRecursion(obj); | 907 CheckRecursiveRendering checkRecursion(obj); |
909 | 908 |
910 switch (pdfContext->fPdfDoc->mapper()->mapXObjectDictionary(obj)) | 909 switch (pdfContext->fPdfDoc->mapper()->mapXObjectDictionary(obj)) |
911 { | 910 { |
912 case kImageDictionary_SkPdfObjectType: | 911 case kImageDictionary_SkPdfNativeObjectType: |
913 return doXObject_Image(pdfContext, canvas, (SkPdfImageDictionary*)ob
j); | 912 return doXObject_Image(pdfContext, canvas, (SkPdfImageDictionary*)ob
j); |
914 case kType1FormDictionary_SkPdfObjectType: | 913 case kType1FormDictionary_SkPdfNativeObjectType: |
915 return doXObject_Form(pdfContext, canvas, (SkPdfType1FormDictionary*
)obj); | 914 return doXObject_Form(pdfContext, canvas, (SkPdfType1FormDictionary*
)obj); |
916 //case kObjectDictionaryXObjectPS_SkPdfObjectType: | 915 //case kObjectDictionaryXObjectPS_SkPdfNativeObjectType: |
917 //return doXObject_PS(skxobj.asPS()); | 916 //return doXObject_PS(skxobj.asPS()); |
918 default: { | 917 default: { |
919 if (pdfContext->fPdfDoc->mapper()->mapType1PatternDictionary(obj) !=
kNone_SkPdfObjectType) { | 918 if (pdfContext->fPdfDoc->mapper()->mapType1PatternDictionary(obj) !=
kNone_SkPdfNativeObjectType) { |
920 SkPdfType1PatternDictionary* pattern = (SkPdfType1PatternDiction
ary*)obj; | 919 SkPdfType1PatternDictionary* pattern = (SkPdfType1PatternDiction
ary*)obj; |
921 return doXObject_Pattern(pdfContext, canvas, pattern); | 920 return doXObject_Pattern(pdfContext, canvas, pattern); |
922 } | 921 } |
923 } | 922 } |
924 } | 923 } |
925 return kIgnoreError_PdfResult; | 924 return kIgnoreError_SkPdfResult; |
926 } | 925 } |
927 | 926 |
928 static PdfResult doPage(PdfContext* pdfContext, SkCanvas* canvas, SkPdfPageObjec
tDictionary* skobj) { | 927 static SkPdfResult doPage(SkPdfContext* pdfContext, SkCanvas* canvas, SkPdfPageO
bjectDictionary* skobj) { |
929 if (!skobj) { | 928 if (!skobj) { |
930 return kIgnoreError_PdfResult; | 929 return kIgnoreError_SkPdfResult; |
931 } | 930 } |
932 | 931 |
933 if (!skobj->isContentsAStream(pdfContext->fPdfDoc)) { | 932 if (!skobj->isContentsAStream(pdfContext->fPdfDoc)) { |
934 return kNYI_PdfResult; | 933 return kNYI_SkPdfResult; |
935 } | 934 } |
936 | 935 |
937 SkPdfStream* stream = skobj->getContentsAsStream(pdfContext->fPdfDoc); | 936 SkPdfStream* stream = skobj->getContentsAsStream(pdfContext->fPdfDoc); |
938 | 937 |
939 if (!stream) { | 938 if (!stream) { |
940 return kIgnoreError_PdfResult; | 939 return kIgnoreError_SkPdfResult; |
941 } | 940 } |
942 | 941 |
943 if (CheckRecursiveRendering::IsInRendering(skobj)) { | 942 if (CheckRecursiveRendering::IsInRendering(skobj)) { |
944 // Oops, corrupt PDF! | 943 // Oops, corrupt PDF! |
945 return kIgnoreError_PdfResult; | 944 return kIgnoreError_SkPdfResult; |
946 } | 945 } |
947 CheckRecursiveRendering checkRecursion(skobj); | 946 CheckRecursiveRendering checkRecursion(skobj); |
948 | 947 |
949 | 948 |
950 PdfOp_q(pdfContext, canvas, NULL); | 949 PdfOp_q(pdfContext, canvas, NULL); |
951 | 950 |
952 | 951 |
953 if (skobj->Resources(pdfContext->fPdfDoc)) { | 952 if (skobj->Resources(pdfContext->fPdfDoc)) { |
954 pdfContext->fGraphicsState.fResources = skobj->Resources(pdfContext->fPd
fDoc); | 953 pdfContext->fGraphicsState.fResources = skobj->Resources(pdfContext->fPd
fDoc); |
955 } | 954 } |
(...skipping 13 matching lines...) Expand all Loading... |
969 if (tokenizer != NULL) { | 968 if (tokenizer != NULL) { |
970 PdfMainLooper looper(NULL, tokenizer, pdfContext, canvas); | 969 PdfMainLooper looper(NULL, tokenizer, pdfContext, canvas); |
971 looper.loop(); | 970 looper.loop(); |
972 delete tokenizer; | 971 delete tokenizer; |
973 } | 972 } |
974 | 973 |
975 // TODO(edisonn): should we restore the variable stack at the same state? | 974 // TODO(edisonn): should we restore the variable stack at the same state? |
976 // There could be operands left, that could be consumed by a parent tokenize
r when we pop. | 975 // There could be operands left, that could be consumed by a parent tokenize
r when we pop. |
977 canvas->restore(); | 976 canvas->restore(); |
978 PdfOp_Q(pdfContext, canvas, NULL); | 977 PdfOp_Q(pdfContext, canvas, NULL); |
979 return kPartial_PdfResult; | 978 return kPartial_SkPdfResult; |
980 } | 979 } |
981 | 980 |
982 PdfResult PdfOp_q(PdfContext* pdfContext, SkCanvas* canvas, PdfTokenLooper** loo
per) { | 981 SkPdfResult PdfOp_q(SkPdfContext* pdfContext, SkCanvas* canvas, PdfTokenLooper**
looper) { |
983 pdfContext->fStateStack.push(pdfContext->fGraphicsState); | 982 pdfContext->fStateStack.push(pdfContext->fGraphicsState); |
984 canvas->save(); | 983 canvas->save(); |
985 return kOK_PdfResult; | 984 return kOK_SkPdfResult; |
986 } | 985 } |
987 | 986 |
988 PdfResult PdfOp_Q(PdfContext* pdfContext, SkCanvas* canvas, PdfTokenLooper** loo
per) { | 987 SkPdfResult PdfOp_Q(SkPdfContext* pdfContext, SkCanvas* canvas, PdfTokenLooper**
looper) { |
989 pdfContext->fGraphicsState = pdfContext->fStateStack.top(); | 988 pdfContext->fGraphicsState = pdfContext->fStateStack.top(); |
990 pdfContext->fStateStack.pop(); | 989 pdfContext->fStateStack.pop(); |
991 canvas->restore(); | 990 canvas->restore(); |
992 return kOK_PdfResult; | 991 return kOK_SkPdfResult; |
993 } | 992 } |
994 | 993 |
995 static PdfResult PdfOp_cm(PdfContext* pdfContext, SkCanvas* canvas, PdfTokenLoop
er** looper) { | 994 static SkPdfResult PdfOp_cm(SkPdfContext* pdfContext, SkCanvas* canvas, PdfToken
Looper** looper) { |
996 double array[6]; | 995 double array[6]; |
997 for (int i = 0 ; i < 6 ; i++) { | 996 for (int i = 0 ; i < 6 ; i++) { |
998 array[5 - i] = pdfContext->fObjectStack.top()->numberValue(); | 997 array[5 - i] = pdfContext->fObjectStack.top()->numberValue(); |
999 pdfContext->fObjectStack.pop(); | 998 pdfContext->fObjectStack.pop(); |
1000 } | 999 } |
1001 | 1000 |
1002 // a b | 1001 // a b |
1003 // c d | 1002 // c d |
1004 // e f | 1003 // e f |
1005 | 1004 |
(...skipping 10 matching lines...) Expand all Loading... |
1016 | 1015 |
1017 #ifdef PDF_TRACE | 1016 #ifdef PDF_TRACE |
1018 printf("cm "); | 1017 printf("cm "); |
1019 for (int i = 0 ; i < 6 ; i++) { | 1018 for (int i = 0 ; i < 6 ; i++) { |
1020 printf("%f ", array[i]); | 1019 printf("%f ", array[i]); |
1021 } | 1020 } |
1022 printf("\n"); | 1021 printf("\n"); |
1023 SkTraceMatrix(pdfContext->fGraphicsState.fCTM, "cm"); | 1022 SkTraceMatrix(pdfContext->fGraphicsState.fCTM, "cm"); |
1024 #endif | 1023 #endif |
1025 | 1024 |
1026 return kOK_PdfResult; | 1025 return kOK_SkPdfResult; |
1027 } | 1026 } |
1028 | 1027 |
1029 //leading TL Set the text leading, Tl | 1028 //leading TL Set the text leading, Tl |
1030 //, to leading, which is a number expressed in unscaled text | 1029 //, to leading, which is a number expressed in unscaled text |
1031 //space units. Text leading is used only by the T*, ', and " operators. Initial
value: 0. | 1030 //space units. Text leading is used only by the T*, ', and " operators. Initial
value: 0. |
1032 static PdfResult PdfOp_TL(PdfContext* pdfContext, SkCanvas* canvas, PdfTokenLoop
er** looper) { | 1031 static SkPdfResult PdfOp_TL(SkPdfContext* pdfContext, SkCanvas* canvas, PdfToken
Looper** looper) { |
1033 double ty = pdfContext->fObjectStack.top()->numberValue(); pdfContext->fOb
jectStack.pop(); | 1032 double ty = pdfContext->fObjectStack.top()->numberValue(); pdfContext->fOb
jectStack.pop(); |
1034 | 1033 |
1035 pdfContext->fGraphicsState.fTextLeading = ty; | 1034 pdfContext->fGraphicsState.fTextLeading = ty; |
1036 | 1035 |
1037 return kOK_PdfResult; | 1036 return kOK_SkPdfResult; |
1038 } | 1037 } |
1039 | 1038 |
1040 static PdfResult PdfOp_Td(PdfContext* pdfContext, SkCanvas* canvas, PdfTokenLoop
er** looper) { | 1039 static SkPdfResult PdfOp_Td(SkPdfContext* pdfContext, SkCanvas* canvas, PdfToken
Looper** looper) { |
1041 #ifdef PDF_TRACE | 1040 #ifdef PDF_TRACE |
1042 printf("stack size = %i\n", (int)pdfContext->fObjectStack.size()); | 1041 printf("stack size = %i\n", (int)pdfContext->fObjectStack.size()); |
1043 #endif | 1042 #endif |
1044 double ty = pdfContext->fObjectStack.top()->numberValue(); pdfContext->fObje
ctStack.pop(); | 1043 double ty = pdfContext->fObjectStack.top()->numberValue(); pdfContext->fObje
ctStack.pop(); |
1045 SkPdfObject* obj = pdfContext->fObjectStack.top(); | 1044 SkPdfNativeObject* obj = pdfContext->fObjectStack.top(); |
1046 obj = obj; | 1045 obj = obj; |
1047 double tx = pdfContext->fObjectStack.top()->numberValue(); pdfContext->fObje
ctStack.pop(); | 1046 double tx = pdfContext->fObjectStack.top()->numberValue(); pdfContext->fObje
ctStack.pop(); |
1048 | 1047 |
1049 double array[6] = {1, 0, 0, 1, tx, -ty}; | 1048 double array[6] = {1, 0, 0, 1, tx, -ty}; |
1050 SkMatrix matrix = SkMatrixFromPdfMatrix(array); | 1049 SkMatrix matrix = SkMatrixFromPdfMatrix(array); |
1051 | 1050 |
1052 pdfContext->fGraphicsState.fMatrixTm.preConcat(matrix); | 1051 pdfContext->fGraphicsState.fMatrixTm.preConcat(matrix); |
1053 pdfContext->fGraphicsState.fMatrixTlm.preConcat(matrix); | 1052 pdfContext->fGraphicsState.fMatrixTlm.preConcat(matrix); |
1054 | 1053 |
1055 return kPartial_PdfResult; | 1054 return kPartial_SkPdfResult; |
1056 } | 1055 } |
1057 | 1056 |
1058 static PdfResult PdfOp_TD(PdfContext* pdfContext, SkCanvas* canvas, PdfTokenLoop
er** looper) { | 1057 static SkPdfResult PdfOp_TD(SkPdfContext* pdfContext, SkCanvas* canvas, PdfToken
Looper** looper) { |
1059 double ty = pdfContext->fObjectStack.top()->numberValue(); pdfContext->fObje
ctStack.pop(); | 1058 double ty = pdfContext->fObjectStack.top()->numberValue(); pdfContext->fObje
ctStack.pop(); |
1060 double tx = pdfContext->fObjectStack.top()->numberValue(); pdfContext->fObje
ctStack.pop(); | 1059 double tx = pdfContext->fObjectStack.top()->numberValue(); pdfContext->fObje
ctStack.pop(); |
1061 | 1060 |
1062 // TODO(edisonn): Create factory methods or constructors so native is hidden | 1061 // TODO(edisonn): Create factory methods or constructors so native is hidden |
1063 SkPdfReal* _ty = pdfContext->fPdfDoc->createReal(-ty); | 1062 SkPdfReal* _ty = pdfContext->fPdfDoc->createReal(-ty); |
1064 pdfContext->fObjectStack.push(_ty); | 1063 pdfContext->fObjectStack.push(_ty); |
1065 | 1064 |
1066 PdfOp_TL(pdfContext, canvas, looper); | 1065 PdfOp_TL(pdfContext, canvas, looper); |
1067 | 1066 |
1068 SkPdfReal* vtx = pdfContext->fPdfDoc->createReal(tx); | 1067 SkPdfReal* vtx = pdfContext->fPdfDoc->createReal(tx); |
1069 pdfContext->fObjectStack.push(vtx); | 1068 pdfContext->fObjectStack.push(vtx); |
1070 | 1069 |
1071 SkPdfReal* vty = pdfContext->fPdfDoc->createReal(ty); | 1070 SkPdfReal* vty = pdfContext->fPdfDoc->createReal(ty); |
1072 pdfContext->fObjectStack.push(vty); | 1071 pdfContext->fObjectStack.push(vty); |
1073 | 1072 |
1074 PdfResult ret = PdfOp_Td(pdfContext, canvas, looper); | 1073 SkPdfResult ret = PdfOp_Td(pdfContext, canvas, looper); |
1075 | 1074 |
1076 // TODO(edisonn): delete all the objects after rendering was complete, in th
is way pdf is rendered faster | 1075 // TODO(edisonn): delete all the objects after rendering was complete, in th
is way pdf is rendered faster |
1077 // and the cleanup can happen while the user looks at the image | 1076 // and the cleanup can happen while the user looks at the image |
1078 | 1077 |
1079 return ret; | 1078 return ret; |
1080 } | 1079 } |
1081 | 1080 |
1082 static PdfResult PdfOp_Tm(PdfContext* pdfContext, SkCanvas* canvas, PdfTokenLoop
er** looper) { | 1081 static SkPdfResult PdfOp_Tm(SkPdfContext* pdfContext, SkCanvas* canvas, PdfToken
Looper** looper) { |
1083 double f = pdfContext->fObjectStack.top()->numberValue(); pdfContext->fObjec
tStack.pop(); | 1082 double f = pdfContext->fObjectStack.top()->numberValue(); pdfContext->fObjec
tStack.pop(); |
1084 double e = pdfContext->fObjectStack.top()->numberValue(); pdfContext->fObjec
tStack.pop(); | 1083 double e = pdfContext->fObjectStack.top()->numberValue(); pdfContext->fObjec
tStack.pop(); |
1085 double d = pdfContext->fObjectStack.top()->numberValue(); pdfContext->fObjec
tStack.pop(); | 1084 double d = pdfContext->fObjectStack.top()->numberValue(); pdfContext->fObjec
tStack.pop(); |
1086 double c = pdfContext->fObjectStack.top()->numberValue(); pdfContext->fObjec
tStack.pop(); | 1085 double c = pdfContext->fObjectStack.top()->numberValue(); pdfContext->fObjec
tStack.pop(); |
1087 double b = pdfContext->fObjectStack.top()->numberValue(); pdfContext->fObjec
tStack.pop(); | 1086 double b = pdfContext->fObjectStack.top()->numberValue(); pdfContext->fObjec
tStack.pop(); |
1088 double a = pdfContext->fObjectStack.top()->numberValue(); pdfContext->fObjec
tStack.pop(); | 1087 double a = pdfContext->fObjectStack.top()->numberValue(); pdfContext->fObjec
tStack.pop(); |
1089 | 1088 |
1090 double array[6]; | 1089 double array[6]; |
1091 array[0] = a; | 1090 array[0] = a; |
1092 array[1] = b; | 1091 array[1] = b; |
1093 array[2] = c; | 1092 array[2] = c; |
1094 array[3] = d; | 1093 array[3] = d; |
1095 array[4] = e; | 1094 array[4] = e; |
1096 array[5] = f; | 1095 array[5] = f; |
1097 | 1096 |
1098 SkMatrix matrix = SkMatrixFromPdfMatrix(array); | 1097 SkMatrix matrix = SkMatrixFromPdfMatrix(array); |
1099 matrix.postConcat(pdfContext->fGraphicsState.fCTM); | 1098 matrix.postConcat(pdfContext->fGraphicsState.fCTM); |
1100 matrix.preScale(SkDoubleToScalar(1), SkDoubleToScalar(-1)); | 1099 matrix.preScale(SkDoubleToScalar(1), SkDoubleToScalar(-1)); |
1101 | 1100 |
1102 // TODO(edisonn): Text positioning. | 1101 // TODO(edisonn): Text positioning. |
1103 pdfContext->fGraphicsState.fMatrixTm = matrix; | 1102 pdfContext->fGraphicsState.fMatrixTm = matrix; |
1104 pdfContext->fGraphicsState.fMatrixTlm = matrix;; | 1103 pdfContext->fGraphicsState.fMatrixTlm = matrix;; |
1105 | 1104 |
1106 return kPartial_PdfResult; | 1105 return kPartial_SkPdfResult; |
1107 } | 1106 } |
1108 | 1107 |
1109 //— T* Move to the start of the next line. This operator has the same effect as
the code | 1108 //— T* Move to the start of the next line. This operator has the same effect as
the code |
1110 //0 Tl Td | 1109 //0 Tl Td |
1111 //where Tl is the current leading parameter in the text state | 1110 //where Tl is the current leading parameter in the text state |
1112 static PdfResult PdfOp_T_star(PdfContext* pdfContext, SkCanvas* canvas, PdfToken
Looper** looper) { | 1111 static SkPdfResult PdfOp_T_star(SkPdfContext* pdfContext, SkCanvas* canvas, PdfT
okenLooper** looper) { |
1113 SkPdfReal* zero = pdfContext->fPdfDoc->createReal(0.0); | 1112 SkPdfReal* zero = pdfContext->fPdfDoc->createReal(0.0); |
1114 SkPdfReal* tl = pdfContext->fPdfDoc->createReal(pdfContext->fGraphicsState.f
TextLeading); | 1113 SkPdfReal* tl = pdfContext->fPdfDoc->createReal(pdfContext->fGraphicsState.f
TextLeading); |
1115 | 1114 |
1116 pdfContext->fObjectStack.push(zero); | 1115 pdfContext->fObjectStack.push(zero); |
1117 pdfContext->fObjectStack.push(tl); | 1116 pdfContext->fObjectStack.push(tl); |
1118 | 1117 |
1119 PdfResult ret = PdfOp_Td(pdfContext, canvas, looper); | 1118 SkPdfResult ret = PdfOp_Td(pdfContext, canvas, looper); |
1120 | 1119 |
1121 return ret; | 1120 return ret; |
1122 } | 1121 } |
1123 | 1122 |
1124 static PdfResult PdfOp_m(PdfContext* pdfContext, SkCanvas* canvas, PdfTokenLoope
r** looper) { | 1123 static SkPdfResult PdfOp_m(SkPdfContext* pdfContext, SkCanvas* canvas, PdfTokenL
ooper** looper) { |
1125 if (pdfContext->fGraphicsState.fPathClosed) { | 1124 if (pdfContext->fGraphicsState.fPathClosed) { |
1126 pdfContext->fGraphicsState.fPath.reset(); | 1125 pdfContext->fGraphicsState.fPath.reset(); |
1127 pdfContext->fGraphicsState.fPathClosed = false; | 1126 pdfContext->fGraphicsState.fPathClosed = false; |
1128 } | 1127 } |
1129 | 1128 |
1130 pdfContext->fGraphicsState.fCurPosY = pdfContext->fObjectStack.top()->number
Value(); pdfContext->fObjectStack.pop(); | 1129 pdfContext->fGraphicsState.fCurPosY = pdfContext->fObjectStack.top()->number
Value(); pdfContext->fObjectStack.pop(); |
1131 pdfContext->fGraphicsState.fCurPosX = pdfContext->fObjectStack.top()->number
Value(); pdfContext->fObjectStack.pop(); | 1130 pdfContext->fGraphicsState.fCurPosX = pdfContext->fObjectStack.top()->number
Value(); pdfContext->fObjectStack.pop(); |
1132 | 1131 |
1133 pdfContext->fGraphicsState.fPath.moveTo(SkDoubleToScalar(pdfContext->fGraphi
csState.fCurPosX), | 1132 pdfContext->fGraphicsState.fPath.moveTo(SkDoubleToScalar(pdfContext->fGraphi
csState.fCurPosX), |
1134 SkDoubleToScalar(pdfContext->fGraphics
State.fCurPosY)); | 1133 SkDoubleToScalar(pdfContext->fGraphics
State.fCurPosY)); |
1135 | 1134 |
1136 return kOK_PdfResult; | 1135 return kOK_SkPdfResult; |
1137 } | 1136 } |
1138 | 1137 |
1139 static PdfResult PdfOp_l(PdfContext* pdfContext, SkCanvas* canvas, PdfTokenLoope
r** looper) { | 1138 static SkPdfResult PdfOp_l(SkPdfContext* pdfContext, SkCanvas* canvas, PdfTokenL
ooper** looper) { |
1140 if (pdfContext->fGraphicsState.fPathClosed) { | 1139 if (pdfContext->fGraphicsState.fPathClosed) { |
1141 pdfContext->fGraphicsState.fPath.reset(); | 1140 pdfContext->fGraphicsState.fPath.reset(); |
1142 pdfContext->fGraphicsState.fPathClosed = false; | 1141 pdfContext->fGraphicsState.fPathClosed = false; |
1143 } | 1142 } |
1144 | 1143 |
1145 pdfContext->fGraphicsState.fCurPosY = pdfContext->fObjectStack.top()->number
Value(); pdfContext->fObjectStack.pop(); | 1144 pdfContext->fGraphicsState.fCurPosY = pdfContext->fObjectStack.top()->number
Value(); pdfContext->fObjectStack.pop(); |
1146 pdfContext->fGraphicsState.fCurPosX = pdfContext->fObjectStack.top()->number
Value(); pdfContext->fObjectStack.pop(); | 1145 pdfContext->fGraphicsState.fCurPosX = pdfContext->fObjectStack.top()->number
Value(); pdfContext->fObjectStack.pop(); |
1147 | 1146 |
1148 pdfContext->fGraphicsState.fPath.lineTo(SkDoubleToScalar(pdfContext->fGraphi
csState.fCurPosX), | 1147 pdfContext->fGraphicsState.fPath.lineTo(SkDoubleToScalar(pdfContext->fGraphi
csState.fCurPosX), |
1149 SkDoubleToScalar(pdfContext->fGraphics
State.fCurPosY)); | 1148 SkDoubleToScalar(pdfContext->fGraphics
State.fCurPosY)); |
1150 | 1149 |
1151 return kOK_PdfResult; | 1150 return kOK_SkPdfResult; |
1152 } | 1151 } |
1153 | 1152 |
1154 static PdfResult PdfOp_c(PdfContext* pdfContext, SkCanvas* canvas, PdfTokenLoope
r** looper) { | 1153 static SkPdfResult PdfOp_c(SkPdfContext* pdfContext, SkCanvas* canvas, PdfTokenL
ooper** looper) { |
1155 if (pdfContext->fGraphicsState.fPathClosed) { | 1154 if (pdfContext->fGraphicsState.fPathClosed) { |
1156 pdfContext->fGraphicsState.fPath.reset(); | 1155 pdfContext->fGraphicsState.fPath.reset(); |
1157 pdfContext->fGraphicsState.fPathClosed = false; | 1156 pdfContext->fGraphicsState.fPathClosed = false; |
1158 } | 1157 } |
1159 | 1158 |
1160 double y3 = pdfContext->fObjectStack.top()->numberValue(); pdfContext->fO
bjectStack.pop(); | 1159 double y3 = pdfContext->fObjectStack.top()->numberValue(); pdfContext->fO
bjectStack.pop(); |
1161 double x3 = pdfContext->fObjectStack.top()->numberValue(); pdfContext->fO
bjectStack.pop(); | 1160 double x3 = pdfContext->fObjectStack.top()->numberValue(); pdfContext->fO
bjectStack.pop(); |
1162 double y2 = pdfContext->fObjectStack.top()->numberValue(); pdfContext->fO
bjectStack.pop(); | 1161 double y2 = pdfContext->fObjectStack.top()->numberValue(); pdfContext->fO
bjectStack.pop(); |
1163 double x2 = pdfContext->fObjectStack.top()->numberValue(); pdfContext->fO
bjectStack.pop(); | 1162 double x2 = pdfContext->fObjectStack.top()->numberValue(); pdfContext->fO
bjectStack.pop(); |
1164 double y1 = pdfContext->fObjectStack.top()->numberValue(); pdfContext->fO
bjectStack.pop(); | 1163 double y1 = pdfContext->fObjectStack.top()->numberValue(); pdfContext->fO
bjectStack.pop(); |
1165 double x1 = pdfContext->fObjectStack.top()->numberValue(); pdfContext->fO
bjectStack.pop(); | 1164 double x1 = pdfContext->fObjectStack.top()->numberValue(); pdfContext->fO
bjectStack.pop(); |
1166 | 1165 |
1167 pdfContext->fGraphicsState.fPath.cubicTo(SkDoubleToScalar(x1), SkDoubleToSca
lar(y1), | 1166 pdfContext->fGraphicsState.fPath.cubicTo(SkDoubleToScalar(x1), SkDoubleToSca
lar(y1), |
1168 SkDoubleToScalar(x2), SkDoubleToScal
ar(y2), | 1167 SkDoubleToScalar(x2), SkDoubleToScal
ar(y2), |
1169 SkDoubleToScalar(x3), SkDoubleToScal
ar(y3)); | 1168 SkDoubleToScalar(x3), SkDoubleToScal
ar(y3)); |
1170 | 1169 |
1171 pdfContext->fGraphicsState.fCurPosX = x3; | 1170 pdfContext->fGraphicsState.fCurPosX = x3; |
1172 pdfContext->fGraphicsState.fCurPosY = y3; | 1171 pdfContext->fGraphicsState.fCurPosY = y3; |
1173 | 1172 |
1174 return kOK_PdfResult; | 1173 return kOK_SkPdfResult; |
1175 } | 1174 } |
1176 | 1175 |
1177 static PdfResult PdfOp_v(PdfContext* pdfContext, SkCanvas* canvas, PdfTokenLoope
r** looper) { | 1176 static SkPdfResult PdfOp_v(SkPdfContext* pdfContext, SkCanvas* canvas, PdfTokenL
ooper** looper) { |
1178 if (pdfContext->fGraphicsState.fPathClosed) { | 1177 if (pdfContext->fGraphicsState.fPathClosed) { |
1179 pdfContext->fGraphicsState.fPath.reset(); | 1178 pdfContext->fGraphicsState.fPath.reset(); |
1180 pdfContext->fGraphicsState.fPathClosed = false; | 1179 pdfContext->fGraphicsState.fPathClosed = false; |
1181 } | 1180 } |
1182 | 1181 |
1183 double y3 = pdfContext->fObjectStack.top()->numberValue(); pdfContext->fO
bjectStack.pop(); | 1182 double y3 = pdfContext->fObjectStack.top()->numberValue(); pdfContext->fO
bjectStack.pop(); |
1184 double x3 = pdfContext->fObjectStack.top()->numberValue(); pdfContext->fO
bjectStack.pop(); | 1183 double x3 = pdfContext->fObjectStack.top()->numberValue(); pdfContext->fO
bjectStack.pop(); |
1185 double y2 = pdfContext->fObjectStack.top()->numberValue(); pdfContext->fO
bjectStack.pop(); | 1184 double y2 = pdfContext->fObjectStack.top()->numberValue(); pdfContext->fO
bjectStack.pop(); |
1186 double x2 = pdfContext->fObjectStack.top()->numberValue(); pdfContext->fO
bjectStack.pop(); | 1185 double x2 = pdfContext->fObjectStack.top()->numberValue(); pdfContext->fO
bjectStack.pop(); |
1187 double y1 = pdfContext->fGraphicsState.fCurPosY; | 1186 double y1 = pdfContext->fGraphicsState.fCurPosY; |
1188 double x1 = pdfContext->fGraphicsState.fCurPosX; | 1187 double x1 = pdfContext->fGraphicsState.fCurPosX; |
1189 | 1188 |
1190 pdfContext->fGraphicsState.fPath.cubicTo(SkDoubleToScalar(x1), SkDoubleToSca
lar(y1), | 1189 pdfContext->fGraphicsState.fPath.cubicTo(SkDoubleToScalar(x1), SkDoubleToSca
lar(y1), |
1191 SkDoubleToScalar(x2), SkDoubleToScal
ar(y2), | 1190 SkDoubleToScalar(x2), SkDoubleToScal
ar(y2), |
1192 SkDoubleToScalar(x3), SkDoubleToScal
ar(y3)); | 1191 SkDoubleToScalar(x3), SkDoubleToScal
ar(y3)); |
1193 | 1192 |
1194 pdfContext->fGraphicsState.fCurPosX = x3; | 1193 pdfContext->fGraphicsState.fCurPosX = x3; |
1195 pdfContext->fGraphicsState.fCurPosY = y3; | 1194 pdfContext->fGraphicsState.fCurPosY = y3; |
1196 | 1195 |
1197 return kOK_PdfResult; | 1196 return kOK_SkPdfResult; |
1198 } | 1197 } |
1199 | 1198 |
1200 static PdfResult PdfOp_y(PdfContext* pdfContext, SkCanvas* canvas, PdfTokenLoope
r** looper) { | 1199 static SkPdfResult PdfOp_y(SkPdfContext* pdfContext, SkCanvas* canvas, PdfTokenL
ooper** looper) { |
1201 if (pdfContext->fGraphicsState.fPathClosed) { | 1200 if (pdfContext->fGraphicsState.fPathClosed) { |
1202 pdfContext->fGraphicsState.fPath.reset(); | 1201 pdfContext->fGraphicsState.fPath.reset(); |
1203 pdfContext->fGraphicsState.fPathClosed = false; | 1202 pdfContext->fGraphicsState.fPathClosed = false; |
1204 } | 1203 } |
1205 | 1204 |
1206 double y3 = pdfContext->fObjectStack.top()->numberValue(); pdfContext->fO
bjectStack.pop(); | 1205 double y3 = pdfContext->fObjectStack.top()->numberValue(); pdfContext->fO
bjectStack.pop(); |
1207 double x3 = pdfContext->fObjectStack.top()->numberValue(); pdfContext->fO
bjectStack.pop(); | 1206 double x3 = pdfContext->fObjectStack.top()->numberValue(); pdfContext->fO
bjectStack.pop(); |
1208 double y2 = pdfContext->fGraphicsState.fCurPosY; | 1207 double y2 = pdfContext->fGraphicsState.fCurPosY; |
1209 double x2 = pdfContext->fGraphicsState.fCurPosX; | 1208 double x2 = pdfContext->fGraphicsState.fCurPosX; |
1210 double y1 = pdfContext->fObjectStack.top()->numberValue(); pdfContext->fO
bjectStack.pop(); | 1209 double y1 = pdfContext->fObjectStack.top()->numberValue(); pdfContext->fO
bjectStack.pop(); |
1211 double x1 = pdfContext->fObjectStack.top()->numberValue(); pdfContext->fO
bjectStack.pop(); | 1210 double x1 = pdfContext->fObjectStack.top()->numberValue(); pdfContext->fO
bjectStack.pop(); |
1212 | 1211 |
1213 pdfContext->fGraphicsState.fPath.cubicTo(SkDoubleToScalar(x1), SkDoubleToSca
lar(y1), | 1212 pdfContext->fGraphicsState.fPath.cubicTo(SkDoubleToScalar(x1), SkDoubleToSca
lar(y1), |
1214 SkDoubleToScalar(x2), SkDoubleToScal
ar(y2), | 1213 SkDoubleToScalar(x2), SkDoubleToScal
ar(y2), |
1215 SkDoubleToScalar(x3), SkDoubleToScal
ar(y3)); | 1214 SkDoubleToScalar(x3), SkDoubleToScal
ar(y3)); |
1216 | 1215 |
1217 pdfContext->fGraphicsState.fCurPosX = x3; | 1216 pdfContext->fGraphicsState.fCurPosX = x3; |
1218 pdfContext->fGraphicsState.fCurPosY = y3; | 1217 pdfContext->fGraphicsState.fCurPosY = y3; |
1219 | 1218 |
1220 return kOK_PdfResult; | 1219 return kOK_SkPdfResult; |
1221 } | 1220 } |
1222 | 1221 |
1223 static PdfResult PdfOp_re(PdfContext* pdfContext, SkCanvas* canvas, PdfTokenLoop
er** looper) { | 1222 static SkPdfResult PdfOp_re(SkPdfContext* pdfContext, SkCanvas* canvas, PdfToken
Looper** looper) { |
1224 if (pdfContext->fGraphicsState.fPathClosed) { | 1223 if (pdfContext->fGraphicsState.fPathClosed) { |
1225 pdfContext->fGraphicsState.fPath.reset(); | 1224 pdfContext->fGraphicsState.fPath.reset(); |
1226 pdfContext->fGraphicsState.fPathClosed = false; | 1225 pdfContext->fGraphicsState.fPathClosed = false; |
1227 } | 1226 } |
1228 | 1227 |
1229 double height = pdfContext->fObjectStack.top()->numberValue(); pdfConte
xt->fObjectStack.pop(); | 1228 double height = pdfContext->fObjectStack.top()->numberValue(); pdfConte
xt->fObjectStack.pop(); |
1230 double width = pdfContext->fObjectStack.top()->numberValue(); pdfConte
xt->fObjectStack.pop(); | 1229 double width = pdfContext->fObjectStack.top()->numberValue(); pdfConte
xt->fObjectStack.pop(); |
1231 double y = pdfContext->fObjectStack.top()->numberValue(); pdfConte
xt->fObjectStack.pop(); | 1230 double y = pdfContext->fObjectStack.top()->numberValue(); pdfConte
xt->fObjectStack.pop(); |
1232 double x = pdfContext->fObjectStack.top()->numberValue(); pdfConte
xt->fObjectStack.pop(); | 1231 double x = pdfContext->fObjectStack.top()->numberValue(); pdfConte
xt->fObjectStack.pop(); |
1233 | 1232 |
1234 pdfContext->fGraphicsState.fPath.addRect(SkDoubleToScalar(x), SkDoubleToScal
ar(y), | 1233 pdfContext->fGraphicsState.fPath.addRect(SkDoubleToScalar(x), SkDoubleToScal
ar(y), |
1235 SkDoubleToScalar(x + width), SkDouble
ToScalar(y + height)); | 1234 SkDoubleToScalar(x + width), SkDouble
ToScalar(y + height)); |
1236 | 1235 |
1237 pdfContext->fGraphicsState.fCurPosX = x; | 1236 pdfContext->fGraphicsState.fCurPosX = x; |
1238 pdfContext->fGraphicsState.fCurPosY = y + height; | 1237 pdfContext->fGraphicsState.fCurPosY = y + height; |
1239 | 1238 |
1240 return kOK_PdfResult; | 1239 return kOK_SkPdfResult; |
1241 } | 1240 } |
1242 | 1241 |
1243 static PdfResult PdfOp_h(PdfContext* pdfContext, SkCanvas* canvas, PdfTokenLoope
r** looper) { | 1242 static SkPdfResult PdfOp_h(SkPdfContext* pdfContext, SkCanvas* canvas, PdfTokenL
ooper** looper) { |
1244 pdfContext->fGraphicsState.fPath.close(); | 1243 pdfContext->fGraphicsState.fPath.close(); |
1245 return kOK_PdfResult; | 1244 return kOK_SkPdfResult; |
1246 } | 1245 } |
1247 | 1246 |
1248 static PdfResult PdfOp_fillAndStroke(PdfContext* pdfContext, SkCanvas* canvas, b
ool fill, bool stroke, bool close, bool evenOdd) { | 1247 static SkPdfResult PdfOp_fillAndStroke(SkPdfContext* pdfContext, SkCanvas* canva
s, bool fill, bool stroke, bool close, bool evenOdd) { |
1249 SkPath path = pdfContext->fGraphicsState.fPath; | 1248 SkPath path = pdfContext->fGraphicsState.fPath; |
1250 | 1249 |
1251 if (close) { | 1250 if (close) { |
1252 path.close(); | 1251 path.close(); |
1253 } | 1252 } |
1254 | 1253 |
1255 canvas->setMatrix(pdfContext->fGraphicsState.fCTM); | 1254 canvas->setMatrix(pdfContext->fGraphicsState.fCTM); |
1256 | 1255 |
1257 SkPaint paint; | 1256 SkPaint paint; |
1258 | 1257 |
(...skipping 14 matching lines...) Expand all Loading... |
1273 // TODO(edisonn): we can use a shader here, like imageshader to
draw fast. ultimately, | 1272 // TODO(edisonn): we can use a shader here, like imageshader to
draw fast. ultimately, |
1274 // if this is not possible, and we are in rasper mode, and the c
ells don't intersect, we could even have multiple cpus. | 1273 // if this is not possible, and we are in rasper mode, and the c
ells don't intersect, we could even have multiple cpus. |
1275 | 1274 |
1276 PdfOp_q(pdfContext, canvas, NULL); | 1275 PdfOp_q(pdfContext, canvas, NULL); |
1277 | 1276 |
1278 if (evenOdd) { | 1277 if (evenOdd) { |
1279 path.setFillType(SkPath::kEvenOdd_FillType); | 1278 path.setFillType(SkPath::kEvenOdd_FillType); |
1280 } | 1279 } |
1281 canvas->clipPath(path); | 1280 canvas->clipPath(path); |
1282 | 1281 |
1283 if (pdfContext->fPdfDoc->mapper()->mapType1PatternDictionary(pdf
Context->fGraphicsState.fNonStroking.fPattern) != kNone_SkPdfObjectType) { | 1282 if (pdfContext->fPdfDoc->mapper()->mapType1PatternDictionary(pdf
Context->fGraphicsState.fNonStroking.fPattern) != kNone_SkPdfNativeObjectType) { |
1284 SkPdfType1PatternDictionary* pattern = (SkPdfType1PatternDic
tionary*)pdfContext->fGraphicsState.fNonStroking.fPattern; | 1283 SkPdfType1PatternDictionary* pattern = (SkPdfType1PatternDic
tionary*)pdfContext->fGraphicsState.fNonStroking.fPattern; |
1285 | 1284 |
1286 // TODO(edisonn): constants | 1285 // TODO(edisonn): constants |
1287 // TODO(edisonn): colored | 1286 // TODO(edisonn): colored |
1288 if (pattern->PaintType(pdfContext->fPdfDoc) == 1) { | 1287 if (pattern->PaintType(pdfContext->fPdfDoc) == 1) { |
1289 // TODO(edisonn): don't use abs, iterate as asked, if th
e cells intersect | 1288 // TODO(edisonn): don't use abs, iterate as asked, if th
e cells intersect |
1290 // it will change the result iterating in reverse | 1289 // it will change the result iterating in reverse |
1291 int xStep = abs((int)pattern->XStep(pdfContext->fPdfDoc)
); | 1290 int xStep = abs((int)pattern->XStep(pdfContext->fPdfDoc)
); |
1292 int yStep = abs((int)pattern->YStep(pdfContext->fPdfDoc)
); | 1291 int yStep = abs((int)pattern->YStep(pdfContext->fPdfDoc)
); |
1293 | 1292 |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1365 | 1364 |
1366 if (pdfContext->fGraphicsState.fHasClipPathToApply) { | 1365 if (pdfContext->fGraphicsState.fHasClipPathToApply) { |
1367 #ifndef PDF_DEBUG_NO_CLIPING | 1366 #ifndef PDF_DEBUG_NO_CLIPING |
1368 canvas->clipPath(pdfContext->fGraphicsState.fClipPath, SkRegion::kInters
ect_Op, true); | 1367 canvas->clipPath(pdfContext->fGraphicsState.fClipPath, SkRegion::kInters
ect_Op, true); |
1369 #endif | 1368 #endif |
1370 } | 1369 } |
1371 | 1370 |
1372 //pdfContext->fGraphicsState.fClipPath.reset(); | 1371 //pdfContext->fGraphicsState.fClipPath.reset(); |
1373 pdfContext->fGraphicsState.fHasClipPathToApply = false; | 1372 pdfContext->fGraphicsState.fHasClipPathToApply = false; |
1374 | 1373 |
1375 return kOK_PdfResult; | 1374 return kOK_SkPdfResult; |
1376 | 1375 |
1377 } | 1376 } |
1378 | 1377 |
1379 static PdfResult PdfOp_S(PdfContext* pdfContext, SkCanvas* canvas, PdfTokenLoope
r** looper) { | 1378 static SkPdfResult PdfOp_S(SkPdfContext* pdfContext, SkCanvas* canvas, PdfTokenL
ooper** looper) { |
1380 return PdfOp_fillAndStroke(pdfContext, canvas, false, true, false, false); | 1379 return PdfOp_fillAndStroke(pdfContext, canvas, false, true, false, false); |
1381 } | 1380 } |
1382 | 1381 |
1383 static PdfResult PdfOp_s(PdfContext* pdfContext, SkCanvas* canvas, PdfTokenLoope
r** looper) { | 1382 static SkPdfResult PdfOp_s(SkPdfContext* pdfContext, SkCanvas* canvas, PdfTokenL
ooper** looper) { |
1384 return PdfOp_fillAndStroke(pdfContext, canvas, false, true, true, false); | 1383 return PdfOp_fillAndStroke(pdfContext, canvas, false, true, true, false); |
1385 } | 1384 } |
1386 | 1385 |
1387 static PdfResult PdfOp_F(PdfContext* pdfContext, SkCanvas* canvas, PdfTokenLoope
r** looper) { | 1386 static SkPdfResult PdfOp_F(SkPdfContext* pdfContext, SkCanvas* canvas, PdfTokenL
ooper** looper) { |
1388 return PdfOp_fillAndStroke(pdfContext, canvas, true, false, false, false); | 1387 return PdfOp_fillAndStroke(pdfContext, canvas, true, false, false, false); |
1389 } | 1388 } |
1390 | 1389 |
1391 static PdfResult PdfOp_f(PdfContext* pdfContext, SkCanvas* canvas, PdfTokenLoope
r** looper) { | 1390 static SkPdfResult PdfOp_f(SkPdfContext* pdfContext, SkCanvas* canvas, PdfTokenL
ooper** looper) { |
1392 return PdfOp_fillAndStroke(pdfContext, canvas, true, false, false, false); | 1391 return PdfOp_fillAndStroke(pdfContext, canvas, true, false, false, false); |
1393 } | 1392 } |
1394 | 1393 |
1395 static PdfResult PdfOp_f_star(PdfContext* pdfContext, SkCanvas* canvas, PdfToken
Looper** looper) { | 1394 static SkPdfResult PdfOp_f_star(SkPdfContext* pdfContext, SkCanvas* canvas, PdfT
okenLooper** looper) { |
1396 return PdfOp_fillAndStroke(pdfContext, canvas, true, false, false, true); | 1395 return PdfOp_fillAndStroke(pdfContext, canvas, true, false, false, true); |
1397 } | 1396 } |
1398 | 1397 |
1399 static PdfResult PdfOp_B(PdfContext* pdfContext, SkCanvas* canvas, PdfTokenLoope
r** looper) { | 1398 static SkPdfResult PdfOp_B(SkPdfContext* pdfContext, SkCanvas* canvas, PdfTokenL
ooper** looper) { |
1400 return PdfOp_fillAndStroke(pdfContext, canvas, true, true, false, false); | 1399 return PdfOp_fillAndStroke(pdfContext, canvas, true, true, false, false); |
1401 } | 1400 } |
1402 | 1401 |
1403 static PdfResult PdfOp_B_star(PdfContext* pdfContext, SkCanvas* canvas, PdfToken
Looper** looper) { | 1402 static SkPdfResult PdfOp_B_star(SkPdfContext* pdfContext, SkCanvas* canvas, PdfT
okenLooper** looper) { |
1404 return PdfOp_fillAndStroke(pdfContext, canvas, true, true, false, true); | 1403 return PdfOp_fillAndStroke(pdfContext, canvas, true, true, false, true); |
1405 } | 1404 } |
1406 | 1405 |
1407 static PdfResult PdfOp_b(PdfContext* pdfContext, SkCanvas* canvas, PdfTokenLoope
r** looper) { | 1406 static SkPdfResult PdfOp_b(SkPdfContext* pdfContext, SkCanvas* canvas, PdfTokenL
ooper** looper) { |
1408 return PdfOp_fillAndStroke(pdfContext, canvas, true, true, true, false); | 1407 return PdfOp_fillAndStroke(pdfContext, canvas, true, true, true, false); |
1409 } | 1408 } |
1410 | 1409 |
1411 static PdfResult PdfOp_b_star(PdfContext* pdfContext, SkCanvas* canvas, PdfToken
Looper** looper) { | 1410 static SkPdfResult PdfOp_b_star(SkPdfContext* pdfContext, SkCanvas* canvas, PdfT
okenLooper** looper) { |
1412 return PdfOp_fillAndStroke(pdfContext, canvas, true, true, true, true); | 1411 return PdfOp_fillAndStroke(pdfContext, canvas, true, true, true, true); |
1413 } | 1412 } |
1414 | 1413 |
1415 static PdfResult PdfOp_n(PdfContext* pdfContext, SkCanvas* canvas, PdfTokenLoope
r** looper) { | 1414 static SkPdfResult PdfOp_n(SkPdfContext* pdfContext, SkCanvas* canvas, PdfTokenL
ooper** looper) { |
1416 canvas->setMatrix(pdfContext->fGraphicsState.fCTM); | 1415 canvas->setMatrix(pdfContext->fGraphicsState.fCTM); |
1417 if (pdfContext->fGraphicsState.fHasClipPathToApply) { | 1416 if (pdfContext->fGraphicsState.fHasClipPathToApply) { |
1418 #ifndef PDF_DEBUG_NO_CLIPING | 1417 #ifndef PDF_DEBUG_NO_CLIPING |
1419 canvas->clipPath(pdfContext->fGraphicsState.fClipPath, SkRegion::kInters
ect_Op, true); | 1418 canvas->clipPath(pdfContext->fGraphicsState.fClipPath, SkRegion::kInters
ect_Op, true); |
1420 #endif | 1419 #endif |
1421 } | 1420 } |
1422 | 1421 |
1423 //pdfContext->fGraphicsState.fClipPath.reset(); | 1422 //pdfContext->fGraphicsState.fClipPath.reset(); |
1424 pdfContext->fGraphicsState.fHasClipPathToApply = false; | 1423 pdfContext->fGraphicsState.fHasClipPathToApply = false; |
1425 | 1424 |
1426 pdfContext->fGraphicsState.fPathClosed = true; | 1425 pdfContext->fGraphicsState.fPathClosed = true; |
1427 | 1426 |
1428 return kOK_PdfResult; | 1427 return kOK_SkPdfResult; |
1429 } | 1428 } |
1430 | 1429 |
1431 static PdfResult PdfOp_BT(PdfContext* pdfContext, SkCanvas* canvas, PdfTokenLoop
er** looper) { | 1430 static SkPdfResult PdfOp_BT(SkPdfContext* pdfContext, SkCanvas* canvas, PdfToken
Looper** looper) { |
1432 pdfContext->fGraphicsState.fTextBlock = true; | 1431 pdfContext->fGraphicsState.fTextBlock = true; |
1433 SkMatrix matrix = pdfContext->fGraphicsState.fCTM; | 1432 SkMatrix matrix = pdfContext->fGraphicsState.fCTM; |
1434 matrix.preScale(SkDoubleToScalar(1), SkDoubleToScalar(-1)); | 1433 matrix.preScale(SkDoubleToScalar(1), SkDoubleToScalar(-1)); |
1435 pdfContext->fGraphicsState.fMatrixTm = matrix; | 1434 pdfContext->fGraphicsState.fMatrixTm = matrix; |
1436 pdfContext->fGraphicsState.fMatrixTlm = matrix; | 1435 pdfContext->fGraphicsState.fMatrixTlm = matrix; |
1437 | 1436 |
1438 return kPartial_PdfResult; | 1437 return kPartial_SkPdfResult; |
1439 } | 1438 } |
1440 | 1439 |
1441 static PdfResult PdfOp_ET(PdfContext* pdfContext, SkCanvas* canvas, PdfTokenLoop
er** looper) { | 1440 static SkPdfResult PdfOp_ET(SkPdfContext* pdfContext, SkCanvas* canvas, PdfToken
Looper** looper) { |
1442 if (!pdfContext->fGraphicsState.fTextBlock) { | 1441 if (!pdfContext->fGraphicsState.fTextBlock) { |
1443 return kIgnoreError_PdfResult; | 1442 return kIgnoreError_SkPdfResult; |
1444 } | 1443 } |
1445 // TODO(edisonn): anything else to be done once we are done with draw text?
Like restore stack? | 1444 // TODO(edisonn): anything else to be done once we are done with draw text?
Like restore stack? |
1446 return kOK_PdfResult; | 1445 return kOK_SkPdfResult; |
1447 } | 1446 } |
1448 | 1447 |
1449 PdfResult skpdfGraphicsStateApplyFontCore(PdfContext* pdfContext, const SkPdfObj
ect* fontName, double fontSize) { | 1448 SkPdfResult skpdfGraphicsStateApplyFontCore(SkPdfContext* pdfContext, const SkPd
fNativeObject* fontName, double fontSize) { |
1450 #ifdef PDF_TRACE | 1449 #ifdef PDF_TRACE |
1451 printf("font name: %s\n", fontName->nameValue2().c_str()); | 1450 printf("font name: %s\n", fontName->nameValue2().c_str()); |
1452 #endif | 1451 #endif |
1453 | 1452 |
1454 if (!pdfContext->fGraphicsState.fResources->Font(pdfContext->fPdfDoc)) { | 1453 if (!pdfContext->fGraphicsState.fResources->Font(pdfContext->fPdfDoc)) { |
1455 // TODO(edisonn): try to recover and draw it any way? | 1454 // TODO(edisonn): try to recover and draw it any way? |
1456 return kIgnoreError_PdfResult; | 1455 return kIgnoreError_SkPdfResult; |
1457 } | 1456 } |
1458 | 1457 |
1459 SkPdfObject* objFont = pdfContext->fGraphicsState.fResources->Font(pdfContex
t->fPdfDoc)->get(fontName); | 1458 SkPdfNativeObject* objFont = pdfContext->fGraphicsState.fResources->Font(pdf
Context->fPdfDoc)->get(fontName); |
1460 objFont = pdfContext->fPdfDoc->resolveReference(objFont); | 1459 objFont = pdfContext->fPdfDoc->resolveReference(objFont); |
1461 if (kNone_SkPdfObjectType == pdfContext->fPdfDoc->mapper()->mapFontDictionar
y(objFont)) { | 1460 if (kNone_SkPdfNativeObjectType == pdfContext->fPdfDoc->mapper()->mapFontDic
tionary(objFont)) { |
1462 // TODO(edisonn): try to recover and draw it any way? | 1461 // TODO(edisonn): try to recover and draw it any way? |
1463 return kIgnoreError_PdfResult; | 1462 return kIgnoreError_SkPdfResult; |
1464 } | 1463 } |
1465 | 1464 |
1466 SkPdfFontDictionary* fd = (SkPdfFontDictionary*)objFont; | 1465 SkPdfFontDictionary* fd = (SkPdfFontDictionary*)objFont; |
1467 | 1466 |
1468 SkPdfFont* skfont = SkPdfFont::fontFromPdfDictionary(pdfContext->fPdfDoc, fd
); | 1467 SkPdfFont* skfont = SkPdfFont::fontFromPdfDictionary(pdfContext->fPdfDoc, fd
); |
1469 | 1468 |
1470 if (skfont) { | 1469 if (skfont) { |
1471 pdfContext->fGraphicsState.fSkFont = skfont; | 1470 pdfContext->fGraphicsState.fSkFont = skfont; |
1472 } | 1471 } |
1473 pdfContext->fGraphicsState.fCurFontSize = fontSize; | 1472 pdfContext->fGraphicsState.fCurFontSize = fontSize; |
1474 return kOK_PdfResult; | 1473 return kOK_SkPdfResult; |
1475 } | 1474 } |
1476 | 1475 |
1477 //font size Tf Set the text font, Tf | 1476 //font size Tf Set the text font, Tf |
1478 //, to font and the text font size, Tfs, to size. font is the name of a | 1477 //, to font and the text font size, Tfs, to size. font is the name of a |
1479 //font resource in the Fontsubdictionary of the current resource dictionary; siz
e is | 1478 //font resource in the Fontsubdictionary of the current resource dictionary; siz
e is |
1480 //a number representing a scale factor. There is no initial value for either fon
t or | 1479 //a number representing a scale factor. There is no initial value for either fon
t or |
1481 //size; they must be specified explicitly using Tf before any text is shown. | 1480 //size; they must be specified explicitly using Tf before any text is shown. |
1482 static PdfResult PdfOp_Tf(PdfContext* pdfContext, SkCanvas* canvas, PdfTokenLoop
er** looper) { | 1481 static SkPdfResult PdfOp_Tf(SkPdfContext* pdfContext, SkCanvas* canvas, PdfToken
Looper** looper) { |
1483 double fontSize = pdfContext->fObjectStack.top()->numberValue(); pdfCont
ext->fObjectStack.pop(); | 1482 double fontSize = pdfContext->fObjectStack.top()->numberValue(); pdfCont
ext->fObjectStack.pop(); |
1484 SkPdfObject* fontName = pdfContext->fObjectStack.top();
pdfContext->fObjectStack.pop(); | 1483 SkPdfNativeObject* fontName = pdfContext->fObjectStack.top();
pdfContext->fObjectStack.pop(); |
1485 return skpdfGraphicsStateApplyFontCore(pdfContext, fontName, fontSize); | 1484 return skpdfGraphicsStateApplyFontCore(pdfContext, fontName, fontSize); |
1486 } | 1485 } |
1487 | 1486 |
1488 static PdfResult PdfOp_Tj(PdfContext* pdfContext, SkCanvas* canvas, PdfTokenLoop
er** looper) { | 1487 static SkPdfResult PdfOp_Tj(SkPdfContext* pdfContext, SkCanvas* canvas, PdfToken
Looper** looper) { |
1489 if (!pdfContext->fGraphicsState.fTextBlock) { | 1488 if (!pdfContext->fGraphicsState.fTextBlock) { |
1490 // TODO(edisonn): try to recover and draw it any way? | 1489 // TODO(edisonn): try to recover and draw it any way? |
1491 return kIgnoreError_PdfResult; | 1490 return kIgnoreError_SkPdfResult; |
1492 } | 1491 } |
1493 | 1492 |
1494 PdfResult ret = DrawText(pdfContext, | 1493 SkPdfResult ret = DrawText(pdfContext, |
1495 pdfContext->fObjectStack.top(), | 1494 pdfContext->fObjectStack.top(), |
1496 canvas); | 1495 canvas); |
1497 pdfContext->fObjectStack.pop(); | 1496 pdfContext->fObjectStack.pop(); |
1498 | 1497 |
1499 return ret; | 1498 return ret; |
1500 } | 1499 } |
1501 | 1500 |
1502 static PdfResult PdfOp_quote(PdfContext* pdfContext, SkCanvas* canvas, PdfTokenL
ooper** looper) { | 1501 static SkPdfResult PdfOp_quote(SkPdfContext* pdfContext, SkCanvas* canvas, PdfTo
kenLooper** looper) { |
1503 if (!pdfContext->fGraphicsState.fTextBlock) { | 1502 if (!pdfContext->fGraphicsState.fTextBlock) { |
1504 // TODO(edisonn): try to recover and draw it any way? | 1503 // TODO(edisonn): try to recover and draw it any way? |
1505 return kIgnoreError_PdfResult; | 1504 return kIgnoreError_SkPdfResult; |
1506 } | 1505 } |
1507 | 1506 |
1508 PdfOp_T_star(pdfContext, canvas, looper); | 1507 PdfOp_T_star(pdfContext, canvas, looper); |
1509 // Do not pop, and push, just transfer the param to Tj | 1508 // Do not pop, and push, just transfer the param to Tj |
1510 return PdfOp_Tj(pdfContext, canvas, looper); | 1509 return PdfOp_Tj(pdfContext, canvas, looper); |
1511 } | 1510 } |
1512 | 1511 |
1513 static PdfResult PdfOp_doublequote(PdfContext* pdfContext, SkCanvas* canvas, Pdf
TokenLooper** looper) { | 1512 static SkPdfResult PdfOp_doublequote(SkPdfContext* pdfContext, SkCanvas* canvas,
PdfTokenLooper** looper) { |
1514 if (!pdfContext->fGraphicsState.fTextBlock) { | 1513 if (!pdfContext->fGraphicsState.fTextBlock) { |
1515 // TODO(edisonn): try to recover and draw it any way? | 1514 // TODO(edisonn): try to recover and draw it any way? |
1516 return kIgnoreError_PdfResult; | 1515 return kIgnoreError_SkPdfResult; |
1517 } | 1516 } |
1518 | 1517 |
1519 SkPdfObject* str = pdfContext->fObjectStack.top(); pdfContext->fObject
Stack.pop(); | 1518 SkPdfNativeObject* str = pdfContext->fObjectStack.top(); pdfContext->f
ObjectStack.pop(); |
1520 SkPdfObject* ac = pdfContext->fObjectStack.top(); pdfContext->fObject
Stack.pop(); | 1519 SkPdfNativeObject* ac = pdfContext->fObjectStack.top(); pdfContext->f
ObjectStack.pop(); |
1521 SkPdfObject* aw = pdfContext->fObjectStack.top(); pdfContext->fObject
Stack.pop(); | 1520 SkPdfNativeObject* aw = pdfContext->fObjectStack.top(); pdfContext->f
ObjectStack.pop(); |
1522 | 1521 |
1523 pdfContext->fObjectStack.push(aw); | 1522 pdfContext->fObjectStack.push(aw); |
1524 PdfOp_Tw(pdfContext, canvas, looper); | 1523 PdfOp_Tw(pdfContext, canvas, looper); |
1525 | 1524 |
1526 pdfContext->fObjectStack.push(ac); | 1525 pdfContext->fObjectStack.push(ac); |
1527 PdfOp_Tc(pdfContext, canvas, looper); | 1526 PdfOp_Tc(pdfContext, canvas, looper); |
1528 | 1527 |
1529 pdfContext->fObjectStack.push(str); | 1528 pdfContext->fObjectStack.push(str); |
1530 PdfOp_quote(pdfContext, canvas, looper); | 1529 PdfOp_quote(pdfContext, canvas, looper); |
1531 | 1530 |
1532 return kPartial_PdfResult; | 1531 return kPartial_SkPdfResult; |
1533 } | 1532 } |
1534 | 1533 |
1535 static PdfResult PdfOp_TJ(PdfContext* pdfContext, SkCanvas* canvas, PdfTokenLoop
er** looper) { | 1534 static SkPdfResult PdfOp_TJ(SkPdfContext* pdfContext, SkCanvas* canvas, PdfToken
Looper** looper) { |
1536 if (!pdfContext->fGraphicsState.fTextBlock) { | 1535 if (!pdfContext->fGraphicsState.fTextBlock) { |
1537 // TODO(edisonn): try to recover and draw it any way? | 1536 // TODO(edisonn): try to recover and draw it any way? |
1538 return kIgnoreError_PdfResult; | 1537 return kIgnoreError_SkPdfResult; |
1539 } | 1538 } |
1540 | 1539 |
1541 SkPdfArray* array = (SkPdfArray*)pdfContext->fObjectStack.top(); | 1540 SkPdfArray* array = (SkPdfArray*)pdfContext->fObjectStack.top(); |
1542 pdfContext->fObjectStack.pop(); | 1541 pdfContext->fObjectStack.pop(); |
1543 | 1542 |
1544 if (!array->isArray()) { | 1543 if (!array->isArray()) { |
1545 return kIgnoreError_PdfResult; | 1544 return kIgnoreError_SkPdfResult; |
1546 } | 1545 } |
1547 | 1546 |
1548 for( int i=0; i<static_cast<int>(array->size()); i++ ) | 1547 for( int i=0; i<static_cast<int>(array->size()); i++ ) |
1549 { | 1548 { |
1550 if( (*array)[i]->isAnyString()) { | 1549 if( (*array)[i]->isAnyString()) { |
1551 SkPdfObject* obj = (*array)[i]; | 1550 SkPdfNativeObject* obj = (*array)[i]; |
1552 DrawText(pdfContext, | 1551 DrawText(pdfContext, |
1553 obj, | 1552 obj, |
1554 canvas); | 1553 canvas); |
1555 } else if ((*array)[i]->isNumber()) { | 1554 } else if ((*array)[i]->isNumber()) { |
1556 double dx = (*array)[i]->numberValue(); | 1555 double dx = (*array)[i]->numberValue(); |
1557 SkMatrix matrix; | 1556 SkMatrix matrix; |
1558 matrix.setAll(SkDoubleToScalar(1), | 1557 matrix.setAll(SkDoubleToScalar(1), |
1559 SkDoubleToScalar(0), | 1558 SkDoubleToScalar(0), |
1560 // TODO(edisonn): use writing mode, vertical/horizonta
l. | 1559 // TODO(edisonn): use writing mode, vertical/horizonta
l. |
1561 SkDoubleToScalar(-dx), // amount is substracted!!! | 1560 SkDoubleToScalar(-dx), // amount is substracted!!! |
1562 SkDoubleToScalar(0), | 1561 SkDoubleToScalar(0), |
1563 SkDoubleToScalar(1), | 1562 SkDoubleToScalar(1), |
1564 SkDoubleToScalar(0), | 1563 SkDoubleToScalar(0), |
1565 SkDoubleToScalar(0), | 1564 SkDoubleToScalar(0), |
1566 SkDoubleToScalar(0), | 1565 SkDoubleToScalar(0), |
1567 SkDoubleToScalar(1)); | 1566 SkDoubleToScalar(1)); |
1568 | 1567 |
1569 pdfContext->fGraphicsState.fMatrixTm.preConcat(matrix); | 1568 pdfContext->fGraphicsState.fMatrixTm.preConcat(matrix); |
1570 } | 1569 } |
1571 } | 1570 } |
1572 return kPartial_PdfResult; // TODO(edisonn): Implement fully DrawText befor
e returing OK. | 1571 return kPartial_SkPdfResult; // TODO(edisonn): Implement fully DrawText bef
ore returing OK. |
1573 } | 1572 } |
1574 | 1573 |
1575 static PdfResult PdfOp_CS_cs(PdfContext* pdfContext, SkCanvas* canvas, SkPdfColo
rOperator* colorOperator) { | 1574 static SkPdfResult PdfOp_CS_cs(SkPdfContext* pdfContext, SkCanvas* canvas, SkPdf
ColorOperator* colorOperator) { |
1576 SkPdfObject* name = pdfContext->fObjectStack.top(); pdfContext->fObjectSt
ack.pop(); | 1575 SkPdfNativeObject* name = pdfContext->fObjectStack.top(); pdfContext->fOb
jectStack.pop(); |
1577 | 1576 |
1578 //Next, get the ColorSpace Dictionary from the Resource Dictionary: | 1577 //Next, get the ColorSpace Dictionary from the Resource Dictionary: |
1579 SkPdfDictionary* colorSpaceResource = pdfContext->fGraphicsState.fResources-
>ColorSpace(pdfContext->fPdfDoc); | 1578 SkPdfDictionary* colorSpaceResource = pdfContext->fGraphicsState.fResources-
>ColorSpace(pdfContext->fPdfDoc); |
1580 | 1579 |
1581 SkPdfObject* colorSpace = colorSpaceResource ? pdfContext->fPdfDoc->resolveR
eference(colorSpaceResource->get(name)) : name; | 1580 SkPdfNativeObject* colorSpace = colorSpaceResource ? pdfContext->fPdfDoc->re
solveReference(colorSpaceResource->get(name)) : name; |
1582 | 1581 |
1583 if (colorSpace == NULL) { | 1582 if (colorSpace == NULL) { |
1584 colorOperator->fColorSpace = name->strRef(); | 1583 colorOperator->fColorSpace = name->strRef(); |
1585 } else { | 1584 } else { |
1586 #ifdef PDF_TRACE | 1585 #ifdef PDF_TRACE |
1587 printf("CS = %s\n", colorSpace->toString(0, 0).c_str()); | 1586 printf("CS = %s\n", colorSpace->toString(0, 0).c_str()); |
1588 #endif // PDF_TRACE | 1587 #endif // PDF_TRACE |
1589 if (colorSpace->isName()) { | 1588 if (colorSpace->isName()) { |
1590 colorOperator->fColorSpace = colorSpace->strRef(); | 1589 colorOperator->fColorSpace = colorSpace->strRef(); |
1591 } else if (colorSpace->isArray()) { | 1590 } else if (colorSpace->isArray()) { |
1592 int cnt = colorSpace->size(); | 1591 int cnt = colorSpace->size(); |
1593 if (cnt == 0) { | 1592 if (cnt == 0) { |
1594 return kIgnoreError_PdfResult; | 1593 return kIgnoreError_SkPdfResult; |
1595 } | 1594 } |
1596 SkPdfObject* type = colorSpace->objAtAIndex(0); | 1595 SkPdfNativeObject* type = colorSpace->objAtAIndex(0); |
1597 type = pdfContext->fPdfDoc->resolveReference(type); | 1596 type = pdfContext->fPdfDoc->resolveReference(type); |
1598 | 1597 |
1599 if (type->isName("ICCBased")) { | 1598 if (type->isName("ICCBased")) { |
1600 if (cnt != 2) { | 1599 if (cnt != 2) { |
1601 return kIgnoreError_PdfResult; | 1600 return kIgnoreError_SkPdfResult; |
1602 } | 1601 } |
1603 SkPdfObject* prop = colorSpace->objAtAIndex(1); | 1602 SkPdfNativeObject* prop = colorSpace->objAtAIndex(1); |
1604 prop = pdfContext->fPdfDoc->resolveReference(prop); | 1603 prop = pdfContext->fPdfDoc->resolveReference(prop); |
1605 #ifdef PDF_TRACE | 1604 #ifdef PDF_TRACE |
1606 printf("ICCBased prop = %s\n", prop->toString(0, 0).c_str()); | 1605 printf("ICCBased prop = %s\n", prop->toString(0, 0).c_str()); |
1607 #endif // PDF_TRACE | 1606 #endif // PDF_TRACE |
1608 // TODO(edisonn): hack | 1607 // TODO(edisonn): hack |
1609 if (prop && prop->isDictionary() && prop->get("N") && prop->get
("N")->isInteger() && prop->get("N")->intValue() == 3) { | 1608 if (prop && prop->isDictionary() && prop->get("N") && prop->get
("N")->isInteger() && prop->get("N")->intValue() == 3) { |
1610 colorOperator->setColorSpace(&strings_DeviceRGB); | 1609 colorOperator->setColorSpace(&strings_DeviceRGB); |
1611 return kPartial_PdfResult; | 1610 return kPartial_SkPdfResult; |
1612 } | 1611 } |
1613 return kNYI_PdfResult; | 1612 return kNYI_SkPdfResult; |
1614 } | 1613 } |
1615 } | 1614 } |
1616 } | 1615 } |
1617 | 1616 |
1618 return kPartial_PdfResult; | 1617 return kPartial_SkPdfResult; |
1619 } | 1618 } |
1620 | 1619 |
1621 static PdfResult PdfOp_CS(PdfContext* pdfContext, SkCanvas* canvas, PdfTokenLoop
er** looper) { | 1620 static SkPdfResult PdfOp_CS(SkPdfContext* pdfContext, SkCanvas* canvas, PdfToken
Looper** looper) { |
1622 return PdfOp_CS_cs(pdfContext, canvas, &pdfContext->fGraphicsState.fStroking
); | 1621 return PdfOp_CS_cs(pdfContext, canvas, &pdfContext->fGraphicsState.fStroking
); |
1623 } | 1622 } |
1624 | 1623 |
1625 static PdfResult PdfOp_cs(PdfContext* pdfContext, SkCanvas* canvas, PdfTokenLoop
er** looper) { | 1624 static SkPdfResult PdfOp_cs(SkPdfContext* pdfContext, SkCanvas* canvas, PdfToken
Looper** looper) { |
1626 return PdfOp_CS_cs(pdfContext, canvas, &pdfContext->fGraphicsState.fNonStrok
ing); | 1625 return PdfOp_CS_cs(pdfContext, canvas, &pdfContext->fGraphicsState.fNonStrok
ing); |
1627 } | 1626 } |
1628 | 1627 |
1629 static PdfResult PdfOp_SC_sc(PdfContext* pdfContext, SkCanvas* canvas, SkPdfColo
rOperator* colorOperator) { | 1628 static SkPdfResult PdfOp_SC_sc(SkPdfContext* pdfContext, SkCanvas* canvas, SkPdf
ColorOperator* colorOperator) { |
1630 double c[4]; | 1629 double c[4]; |
1631 // int64_t v[4]; | 1630 // int64_t v[4]; |
1632 | 1631 |
1633 int n = GetColorSpaceComponents(colorOperator->fColorSpace); | 1632 int n = GetColorSpaceComponents(colorOperator->fColorSpace); |
1634 | 1633 |
1635 bool doubles = true; | 1634 bool doubles = true; |
1636 if (colorOperator->fColorSpace.equals("Indexed")) { | 1635 if (colorOperator->fColorSpace.equals("Indexed")) { |
1637 doubles = false; | 1636 doubles = false; |
1638 } | 1637 } |
1639 | 1638 |
1640 #ifdef PDF_TRACE | 1639 #ifdef PDF_TRACE |
1641 printf("color space = %s, N = %i\n", colorOperator->fColorSpace.fBuffer, n); | 1640 printf("color space = %s, N = %i\n", colorOperator->fColorSpace.fBuffer, n); |
1642 #endif | 1641 #endif |
1643 | 1642 |
1644 for (int i = n - 1; i >= 0 ; i--) { | 1643 for (int i = n - 1; i >= 0 ; i--) { |
1645 if (doubles) { | 1644 if (doubles) { |
1646 c[i] = pdfContext->fObjectStack.top()->numberValue(); pdfCon
text->fObjectStack.pop(); | 1645 c[i] = pdfContext->fObjectStack.top()->numberValue(); pdfCon
text->fObjectStack.pop(); |
1647 // } else { | 1646 // } else { |
1648 // v[i] = pdfContext->fObjectStack.top()->intValue(); pdfConte
xt->fObjectStack.pop(); | 1647 // v[i] = pdfContext->fObjectStack.top()->intValue(); pdfConte
xt->fObjectStack.pop(); |
1649 } | 1648 } |
1650 } | 1649 } |
1651 | 1650 |
1652 // TODO(edisonn): Now, set that color. Only DeviceRGB supported. | 1651 // TODO(edisonn): Now, set that color. Only DeviceRGB supported. |
1653 // TODO(edisonn): do possible field values to enum at parsing time! | 1652 // TODO(edisonn): do possible field values to enum at parsing time! |
1654 // TODO(edisonn): support also abreviations /DeviceRGB == /RGB | 1653 // TODO(edisonn): support also abreviations /DeviceRGB == /RGB |
1655 if (colorOperator->fColorSpace.equals("DeviceRGB") || colorOperator->fColorS
pace.equals("RGB")) { | 1654 if (colorOperator->fColorSpace.equals("DeviceRGB") || colorOperator->fColorS
pace.equals("RGB")) { |
1656 colorOperator->setRGBColor(SkColorSetRGB((U8CPU)(255*c[0]), (U8CPU)(255*
c[1]), (U8CPU)(255*c[2]))); | 1655 colorOperator->setRGBColor(SkColorSetRGB((U8CPU)(255*c[0]), (U8CPU)(255*
c[1]), (U8CPU)(255*c[2]))); |
1657 } | 1656 } |
1658 return kPartial_PdfResult; | 1657 return kPartial_SkPdfResult; |
1659 } | 1658 } |
1660 | 1659 |
1661 static PdfResult PdfOp_SC(PdfContext* pdfContext, SkCanvas* canvas, PdfTokenLoop
er** looper) { | 1660 static SkPdfResult PdfOp_SC(SkPdfContext* pdfContext, SkCanvas* canvas, PdfToken
Looper** looper) { |
1662 return PdfOp_SC_sc(pdfContext, canvas, &pdfContext->fGraphicsState.fStroking
); | 1661 return PdfOp_SC_sc(pdfContext, canvas, &pdfContext->fGraphicsState.fStroking
); |
1663 } | 1662 } |
1664 | 1663 |
1665 static PdfResult PdfOp_sc(PdfContext* pdfContext, SkCanvas* canvas, PdfTokenLoop
er** looper) { | 1664 static SkPdfResult PdfOp_sc(SkPdfContext* pdfContext, SkCanvas* canvas, PdfToken
Looper** looper) { |
1666 return PdfOp_SC_sc(pdfContext, canvas, &pdfContext->fGraphicsState.fNonStrok
ing); | 1665 return PdfOp_SC_sc(pdfContext, canvas, &pdfContext->fGraphicsState.fNonStrok
ing); |
1667 } | 1666 } |
1668 | 1667 |
1669 static PdfResult PdfOp_SCN_scn(PdfContext* pdfContext, SkCanvas* canvas, SkPdfCo
lorOperator* colorOperator) { | 1668 static SkPdfResult PdfOp_SCN_scn(SkPdfContext* pdfContext, SkCanvas* canvas, SkP
dfColorOperator* colorOperator) { |
1670 if (pdfContext->fObjectStack.top()->isName()) { | 1669 if (pdfContext->fObjectStack.top()->isName()) { |
1671 SkPdfObject* name = pdfContext->fObjectStack.top(); pdfContext->fObje
ctStack.pop(); | 1670 SkPdfNativeObject* name = pdfContext->fObjectStack.top(); pdfContext-
>fObjectStack.pop(); |
1672 | 1671 |
1673 //Next, get the ExtGState Dictionary from the Resource Dictionary: | 1672 //Next, get the ExtGState Dictionary from the Resource Dictionary: |
1674 SkPdfDictionary* patternResources = pdfContext->fGraphicsState.fResource
s->Pattern(pdfContext->fPdfDoc); | 1673 SkPdfDictionary* patternResources = pdfContext->fGraphicsState.fResource
s->Pattern(pdfContext->fPdfDoc); |
1675 | 1674 |
1676 if (patternResources == NULL) { | 1675 if (patternResources == NULL) { |
1677 #ifdef PDF_TRACE | 1676 #ifdef PDF_TRACE |
1678 printf("ExtGState is NULL!\n"); | 1677 printf("ExtGState is NULL!\n"); |
1679 #endif | 1678 #endif |
1680 return kIgnoreError_PdfResult; | 1679 return kIgnoreError_SkPdfResult; |
1681 } | 1680 } |
1682 | 1681 |
1683 colorOperator->setPatternColorSpace(pdfContext->fPdfDoc->resolveReferenc
e(patternResources->get(name))); | 1682 colorOperator->setPatternColorSpace(pdfContext->fPdfDoc->resolveReferenc
e(patternResources->get(name))); |
1684 } | 1683 } |
1685 | 1684 |
1686 // TODO(edisonn): SCN supports more color spaces than SCN. Read and implemen
t spec. | 1685 // TODO(edisonn): SCN supports more color spaces than SCN. Read and implemen
t spec. |
1687 PdfOp_SC_sc(pdfContext, canvas, colorOperator); | 1686 PdfOp_SC_sc(pdfContext, canvas, colorOperator); |
1688 | 1687 |
1689 return kPartial_PdfResult; | 1688 return kPartial_SkPdfResult; |
1690 } | 1689 } |
1691 | 1690 |
1692 static PdfResult PdfOp_SCN(PdfContext* pdfContext, SkCanvas* canvas, PdfTokenLoo
per** looper) { | 1691 static SkPdfResult PdfOp_SCN(SkPdfContext* pdfContext, SkCanvas* canvas, PdfToke
nLooper** looper) { |
1693 return PdfOp_SCN_scn(pdfContext, canvas, &pdfContext->fGraphicsState.fStroki
ng); | 1692 return PdfOp_SCN_scn(pdfContext, canvas, &pdfContext->fGraphicsState.fStroki
ng); |
1694 } | 1693 } |
1695 | 1694 |
1696 static PdfResult PdfOp_scn(PdfContext* pdfContext, SkCanvas* canvas, PdfTokenLoo
per** looper) { | 1695 static SkPdfResult PdfOp_scn(SkPdfContext* pdfContext, SkCanvas* canvas, PdfToke
nLooper** looper) { |
1697 return PdfOp_SCN_scn(pdfContext, canvas, &pdfContext->fGraphicsState.fNonStr
oking); | 1696 return PdfOp_SCN_scn(pdfContext, canvas, &pdfContext->fGraphicsState.fNonStr
oking); |
1698 } | 1697 } |
1699 | 1698 |
1700 static PdfResult PdfOp_G_g(PdfContext* pdfContext, SkCanvas* canvas, SkPdfColorO
perator* colorOperator) { | 1699 static SkPdfResult PdfOp_G_g(SkPdfContext* pdfContext, SkCanvas* canvas, SkPdfCo
lorOperator* colorOperator) { |
1701 /*double gray = */pdfContext->fObjectStack.top()->numberValue(); pdfCont
ext->fObjectStack.pop(); | 1700 /*double gray = */pdfContext->fObjectStack.top()->numberValue(); pdfCont
ext->fObjectStack.pop(); |
1702 return kNYI_PdfResult; | 1701 return kNYI_SkPdfResult; |
1703 } | 1702 } |
1704 | 1703 |
1705 static PdfResult PdfOp_G(PdfContext* pdfContext, SkCanvas* canvas, PdfTokenLoope
r** looper) { | 1704 static SkPdfResult PdfOp_G(SkPdfContext* pdfContext, SkCanvas* canvas, PdfTokenL
ooper** looper) { |
1706 return PdfOp_G_g(pdfContext, canvas, &pdfContext->fGraphicsState.fStroking); | 1705 return PdfOp_G_g(pdfContext, canvas, &pdfContext->fGraphicsState.fStroking); |
1707 } | 1706 } |
1708 | 1707 |
1709 static PdfResult PdfOp_g(PdfContext* pdfContext, SkCanvas* canvas, PdfTokenLoope
r** looper) { | 1708 static SkPdfResult PdfOp_g(SkPdfContext* pdfContext, SkCanvas* canvas, PdfTokenL
ooper** looper) { |
1710 return PdfOp_G_g(pdfContext, canvas, &pdfContext->fGraphicsState.fNonStrokin
g); | 1709 return PdfOp_G_g(pdfContext, canvas, &pdfContext->fGraphicsState.fNonStrokin
g); |
1711 } | 1710 } |
1712 | 1711 |
1713 static PdfResult PdfOp_RG_rg(PdfContext* pdfContext, SkCanvas* canvas, SkPdfColo
rOperator* colorOperator) { | 1712 static SkPdfResult PdfOp_RG_rg(SkPdfContext* pdfContext, SkCanvas* canvas, SkPdf
ColorOperator* colorOperator) { |
1714 double b = pdfContext->fObjectStack.top()->numberValue(); pdfContext->fO
bjectStack.pop(); | 1713 double b = pdfContext->fObjectStack.top()->numberValue(); pdfContext->fO
bjectStack.pop(); |
1715 double g = pdfContext->fObjectStack.top()->numberValue(); pdfContext->fO
bjectStack.pop(); | 1714 double g = pdfContext->fObjectStack.top()->numberValue(); pdfContext->fO
bjectStack.pop(); |
1716 double r = pdfContext->fObjectStack.top()->numberValue(); pdfContext->fO
bjectStack.pop(); | 1715 double r = pdfContext->fObjectStack.top()->numberValue(); pdfContext->fO
bjectStack.pop(); |
1717 | 1716 |
1718 colorOperator->fColorSpace = strings_DeviceRGB; | 1717 colorOperator->fColorSpace = strings_DeviceRGB; |
1719 colorOperator->setRGBColor(SkColorSetRGB((U8CPU)(255*r), (U8CPU)(255*g), (U8
CPU)(255*b))); | 1718 colorOperator->setRGBColor(SkColorSetRGB((U8CPU)(255*r), (U8CPU)(255*g), (U8
CPU)(255*b))); |
1720 return kOK_PdfResult; | 1719 return kOK_SkPdfResult; |
1721 } | 1720 } |
1722 | 1721 |
1723 static PdfResult PdfOp_RG(PdfContext* pdfContext, SkCanvas* canvas, PdfTokenLoop
er** looper) { | 1722 static SkPdfResult PdfOp_RG(SkPdfContext* pdfContext, SkCanvas* canvas, PdfToken
Looper** looper) { |
1724 return PdfOp_RG_rg(pdfContext, canvas, &pdfContext->fGraphicsState.fStroking
); | 1723 return PdfOp_RG_rg(pdfContext, canvas, &pdfContext->fGraphicsState.fStroking
); |
1725 } | 1724 } |
1726 | 1725 |
1727 static PdfResult PdfOp_rg(PdfContext* pdfContext, SkCanvas* canvas, PdfTokenLoop
er** looper) { | 1726 static SkPdfResult PdfOp_rg(SkPdfContext* pdfContext, SkCanvas* canvas, PdfToken
Looper** looper) { |
1728 return PdfOp_RG_rg(pdfContext, canvas, &pdfContext->fGraphicsState.fNonStrok
ing); | 1727 return PdfOp_RG_rg(pdfContext, canvas, &pdfContext->fGraphicsState.fNonStrok
ing); |
1729 } | 1728 } |
1730 | 1729 |
1731 static PdfResult PdfOp_K_k(PdfContext* pdfContext, SkCanvas* canvas, SkPdfColorO
perator* colorOperator) { | 1730 static SkPdfResult PdfOp_K_k(SkPdfContext* pdfContext, SkCanvas* canvas, SkPdfCo
lorOperator* colorOperator) { |
1732 // TODO(edisonn): spec has some rules about overprint, implement them. | 1731 // TODO(edisonn): spec has some rules about overprint, implement them. |
1733 /*double k = */pdfContext->fObjectStack.top()->numberValue(); pdfContext
->fObjectStack.pop(); | 1732 /*double k = */pdfContext->fObjectStack.top()->numberValue(); pdfContext
->fObjectStack.pop(); |
1734 /*double y = */pdfContext->fObjectStack.top()->numberValue(); pdfContext
->fObjectStack.pop(); | 1733 /*double y = */pdfContext->fObjectStack.top()->numberValue(); pdfContext
->fObjectStack.pop(); |
1735 /*double m = */pdfContext->fObjectStack.top()->numberValue(); pdfContext
->fObjectStack.pop(); | 1734 /*double m = */pdfContext->fObjectStack.top()->numberValue(); pdfContext
->fObjectStack.pop(); |
1736 /*double c = */pdfContext->fObjectStack.top()->numberValue(); pdfContext
->fObjectStack.pop(); | 1735 /*double c = */pdfContext->fObjectStack.top()->numberValue(); pdfContext
->fObjectStack.pop(); |
1737 | 1736 |
1738 colorOperator->fColorSpace = strings_DeviceCMYK; | 1737 colorOperator->fColorSpace = strings_DeviceCMYK; |
1739 // TODO(edisonn): Set color. | 1738 // TODO(edisonn): Set color. |
1740 return kNYI_PdfResult; | 1739 return kNYI_SkPdfResult; |
1741 } | 1740 } |
1742 | 1741 |
1743 static PdfResult PdfOp_K(PdfContext* pdfContext, SkCanvas* canvas, PdfTokenLoope
r** looper) { | 1742 static SkPdfResult PdfOp_K(SkPdfContext* pdfContext, SkCanvas* canvas, PdfTokenL
ooper** looper) { |
1744 return PdfOp_K_k(pdfContext, canvas, &pdfContext->fGraphicsState.fStroking); | 1743 return PdfOp_K_k(pdfContext, canvas, &pdfContext->fGraphicsState.fStroking); |
1745 } | 1744 } |
1746 | 1745 |
1747 static PdfResult PdfOp_k(PdfContext* pdfContext, SkCanvas* canvas, PdfTokenLoope
r** looper) { | 1746 static SkPdfResult PdfOp_k(SkPdfContext* pdfContext, SkCanvas* canvas, PdfTokenL
ooper** looper) { |
1748 return PdfOp_K_k(pdfContext, canvas, &pdfContext->fGraphicsState.fNonStrokin
g); | 1747 return PdfOp_K_k(pdfContext, canvas, &pdfContext->fGraphicsState.fNonStrokin
g); |
1749 } | 1748 } |
1750 | 1749 |
1751 static PdfResult PdfOp_W(PdfContext* pdfContext, SkCanvas* canvas, PdfTokenLoope
r** looper) { | 1750 static SkPdfResult PdfOp_W(SkPdfContext* pdfContext, SkCanvas* canvas, PdfTokenL
ooper** looper) { |
1752 pdfContext->fGraphicsState.fClipPath = pdfContext->fGraphicsState.fPath; | 1751 pdfContext->fGraphicsState.fClipPath = pdfContext->fGraphicsState.fPath; |
1753 pdfContext->fGraphicsState.fHasClipPathToApply = true; | 1752 pdfContext->fGraphicsState.fHasClipPathToApply = true; |
1754 | 1753 |
1755 return kOK_PdfResult; | 1754 return kOK_SkPdfResult; |
1756 } | 1755 } |
1757 | 1756 |
1758 static PdfResult PdfOp_W_star(PdfContext* pdfContext, SkCanvas* canvas, PdfToken
Looper** looper) { | 1757 static SkPdfResult PdfOp_W_star(SkPdfContext* pdfContext, SkCanvas* canvas, PdfT
okenLooper** looper) { |
1759 pdfContext->fGraphicsState.fClipPath = pdfContext->fGraphicsState.fPath; | 1758 pdfContext->fGraphicsState.fClipPath = pdfContext->fGraphicsState.fPath; |
1760 | 1759 |
1761 pdfContext->fGraphicsState.fClipPath.setFillType(SkPath::kEvenOdd_FillType); | 1760 pdfContext->fGraphicsState.fClipPath.setFillType(SkPath::kEvenOdd_FillType); |
1762 pdfContext->fGraphicsState.fHasClipPathToApply = true; | 1761 pdfContext->fGraphicsState.fHasClipPathToApply = true; |
1763 | 1762 |
1764 return kOK_PdfResult; | 1763 return kOK_SkPdfResult; |
1765 } | 1764 } |
1766 | 1765 |
1767 static PdfResult PdfOp_BX(PdfContext* pdfContext, SkCanvas* canvas, PdfTokenLoop
er** looper) { | 1766 static SkPdfResult PdfOp_BX(SkPdfContext* pdfContext, SkCanvas* canvas, PdfToken
Looper** looper) { |
1768 *looper = new PdfCompatibilitySectionLooper(); | 1767 *looper = new PdfCompatibilitySectionLooper(); |
1769 return kOK_PdfResult; | 1768 return kOK_SkPdfResult; |
1770 } | 1769 } |
1771 | 1770 |
1772 static PdfResult PdfOp_EX(PdfContext* pdfContext, SkCanvas* canvas, PdfTokenLoop
er** looper) { | 1771 static SkPdfResult PdfOp_EX(SkPdfContext* pdfContext, SkCanvas* canvas, PdfToken
Looper** looper) { |
1773 #ifdef ASSERT_BAD_PDF_OPS | 1772 #ifdef ASSERT_BAD_PDF_OPS |
1774 SkASSERT(false); // EX must be consumed by PdfCompatibilitySectionLooper, b
ut let's | 1773 SkASSERT(false); // EX must be consumed by PdfCompatibilitySectionLooper, b
ut let's |
1775 // have the assert when testing good pdfs. | 1774 // have the assert when testing good pdfs. |
1776 #endif | 1775 #endif |
1777 return kIgnoreError_PdfResult; | 1776 return kIgnoreError_SkPdfResult; |
1778 } | 1777 } |
1779 | 1778 |
1780 static PdfResult PdfOp_BI(PdfContext* pdfContext, SkCanvas* canvas, PdfTokenLoop
er** looper) { | 1779 static SkPdfResult PdfOp_BI(SkPdfContext* pdfContext, SkCanvas* canvas, PdfToken
Looper** looper) { |
1781 *looper = new PdfInlineImageLooper(); | 1780 *looper = new PdfInlineImageLooper(); |
1782 return kOK_PdfResult; | 1781 return kOK_SkPdfResult; |
1783 } | 1782 } |
1784 | 1783 |
1785 static PdfResult PdfOp_ID(PdfContext* pdfContext, SkCanvas* canvas, PdfTokenLoop
er** looper) { | 1784 static SkPdfResult PdfOp_ID(SkPdfContext* pdfContext, SkCanvas* canvas, PdfToken
Looper** looper) { |
1786 #ifdef ASSERT_BAD_PDF_OPS | 1785 #ifdef ASSERT_BAD_PDF_OPS |
1787 SkASSERT(false); // must be processed in inline image looper, but let's | 1786 SkASSERT(false); // must be processed in inline image looper, but let's |
1788 // have the assert when testing good pdfs. | 1787 // have the assert when testing good pdfs. |
1789 #endif | 1788 #endif |
1790 return kIgnoreError_PdfResult; | 1789 return kIgnoreError_SkPdfResult; |
1791 } | 1790 } |
1792 | 1791 |
1793 static PdfResult PdfOp_EI(PdfContext* pdfContext, SkCanvas* canvas, PdfTokenLoop
er** looper) { | 1792 static SkPdfResult PdfOp_EI(SkPdfContext* pdfContext, SkCanvas* canvas, PdfToken
Looper** looper) { |
1794 #ifdef ASSERT_BAD_PDF_OPS | 1793 #ifdef ASSERT_BAD_PDF_OPS |
1795 SkASSERT(false); // must be processed in inline image looper, but let's | 1794 SkASSERT(false); // must be processed in inline image looper, but let's |
1796 // have the assert when testing good pdfs. | 1795 // have the assert when testing good pdfs. |
1797 #endif | 1796 #endif |
1798 return kIgnoreError_PdfResult; | 1797 return kIgnoreError_SkPdfResult; |
1799 } | 1798 } |
1800 | 1799 |
1801 | 1800 |
1802 // TODO(edisonn): security review here, make sure all parameters are valid, and
safe. | 1801 // TODO(edisonn): security review here, make sure all parameters are valid, and
safe. |
1803 PdfResult skpdfGraphicsStateApply_ca(PdfContext* pdfContext, double ca) { | 1802 SkPdfResult skpdfGraphicsStateApply_ca(SkPdfContext* pdfContext, double ca) { |
1804 pdfContext->fGraphicsState.fNonStroking.fOpacity = ca; | 1803 pdfContext->fGraphicsState.fNonStroking.fOpacity = ca; |
1805 return kOK_PdfResult; | 1804 return kOK_SkPdfResult; |
1806 } | 1805 } |
1807 | 1806 |
1808 PdfResult skpdfGraphicsStateApply_CA(PdfContext* pdfContext, double CA) { | 1807 SkPdfResult skpdfGraphicsStateApply_CA(SkPdfContext* pdfContext, double CA) { |
1809 pdfContext->fGraphicsState.fStroking.fOpacity = CA; | 1808 pdfContext->fGraphicsState.fStroking.fOpacity = CA; |
1810 return kOK_PdfResult; | 1809 return kOK_SkPdfResult; |
1811 } | 1810 } |
1812 | 1811 |
1813 PdfResult skpdfGraphicsStateApplyLW(PdfContext* pdfContext, double lineWidth) { | 1812 SkPdfResult skpdfGraphicsStateApplyLW(SkPdfContext* pdfContext, double lineWidth
) { |
1814 pdfContext->fGraphicsState.fLineWidth = lineWidth; | 1813 pdfContext->fGraphicsState.fLineWidth = lineWidth; |
1815 return kOK_PdfResult; | 1814 return kOK_SkPdfResult; |
1816 } | 1815 } |
1817 | 1816 |
1818 PdfResult skpdfGraphicsStateApplyLC(PdfContext* pdfContext, int64_t lineCap) { | 1817 SkPdfResult skpdfGraphicsStateApplyLC(SkPdfContext* pdfContext, int64_t lineCap)
{ |
1819 pdfContext->fGraphicsState.fLineCap = (int)lineCap; | 1818 pdfContext->fGraphicsState.fLineCap = (int)lineCap; |
1820 return kOK_PdfResult; | 1819 return kOK_SkPdfResult; |
1821 } | 1820 } |
1822 | 1821 |
1823 PdfResult skpdfGraphicsStateApplyLJ(PdfContext* pdfContext, int64_t lineJoin) { | 1822 SkPdfResult skpdfGraphicsStateApplyLJ(SkPdfContext* pdfContext, int64_t lineJoin
) { |
1824 pdfContext->fGraphicsState.fLineJoin = (int)lineJoin; | 1823 pdfContext->fGraphicsState.fLineJoin = (int)lineJoin; |
1825 return kOK_PdfResult; | 1824 return kOK_SkPdfResult; |
1826 } | 1825 } |
1827 | 1826 |
1828 PdfResult skpdfGraphicsStateApplyML(PdfContext* pdfContext, double miterLimit) { | 1827 SkPdfResult skpdfGraphicsStateApplyML(SkPdfContext* pdfContext, double miterLimi
t) { |
1829 pdfContext->fGraphicsState.fMiterLimit = miterLimit; | 1828 pdfContext->fGraphicsState.fMiterLimit = miterLimit; |
1830 return kOK_PdfResult; | 1829 return kOK_SkPdfResult; |
1831 } | 1830 } |
1832 | 1831 |
1833 // TODO(edisonn): implement all rules, as of now 3) and 5) and 6) do not seem su
ported by skia, but I am not sure | 1832 // TODO(edisonn): implement all rules, as of now 3) and 5) and 6) do not seem su
ported by skia, but I am not sure |
1834 /* | 1833 /* |
1835 1) [ ] 0 No dash; solid, unbroken lines | 1834 1) [ ] 0 No dash; solid, unbroken lines |
1836 2) [3] 0 3 units on, 3 units off, … | 1835 2) [3] 0 3 units on, 3 units off, … |
1837 3) [2] 1 1 on, 2 off, 2 on, 2 off, … | 1836 3) [2] 1 1 on, 2 off, 2 on, 2 off, … |
1838 4) [2 1] 0 2 on, 1 off, 2 on, 1 off, … | 1837 4) [2 1] 0 2 on, 1 off, 2 on, 1 off, … |
1839 5) [3 5] 6 2 off, 3 on, 5 off, 3 on, 5 off, … | 1838 5) [3 5] 6 2 off, 3 on, 5 off, 3 on, 5 off, … |
1840 6) [2 3] 11 1 on, 3 off, 2 on, 3 off, 2 on, … | 1839 6) [2 3] 11 1 on, 3 off, 2 on, 3 off, 2 on, … |
1841 */ | 1840 */ |
1842 | 1841 |
1843 PdfResult skpdfGraphicsStateApplyD(PdfContext* pdfContext, SkPdfArray* intervals
, SkPdfObject* phase) { | 1842 SkPdfResult skpdfGraphicsStateApplyD(SkPdfContext* pdfContext, SkPdfArray* inter
vals, SkPdfNativeObject* phase) { |
1844 int cnt = intervals->size(); | 1843 int cnt = intervals->size(); |
1845 if (cnt >= 256) { | 1844 if (cnt >= 256) { |
1846 // TODO(edisonn): report error/warning, unsuported; | 1845 // TODO(edisonn): report error/warning, unsuported; |
1847 // TODO(edisonn): alloc memory | 1846 // TODO(edisonn): alloc memory |
1848 return kIgnoreError_PdfResult; | 1847 return kIgnoreError_SkPdfResult; |
1849 } | 1848 } |
1850 for (int i = 0; i < cnt; i++) { | 1849 for (int i = 0; i < cnt; i++) { |
1851 if (!intervals->objAtAIndex(i)->isNumber()) { | 1850 if (!intervals->objAtAIndex(i)->isNumber()) { |
1852 // TODO(edisonn): report error/warning | 1851 // TODO(edisonn): report error/warning |
1853 return kIgnoreError_PdfResult; | 1852 return kIgnoreError_SkPdfResult; |
1854 } | 1853 } |
1855 } | 1854 } |
1856 | 1855 |
1857 double total = 0; | 1856 double total = 0; |
1858 for (int i = 0 ; i < cnt; i++) { | 1857 for (int i = 0 ; i < cnt; i++) { |
1859 pdfContext->fGraphicsState.fDashArray[i] = intervals->objAtAIndex(i)->sc
alarValue(); | 1858 pdfContext->fGraphicsState.fDashArray[i] = intervals->objAtAIndex(i)->sc
alarValue(); |
1860 total += pdfContext->fGraphicsState.fDashArray[i]; | 1859 total += pdfContext->fGraphicsState.fDashArray[i]; |
1861 } | 1860 } |
1862 if (cnt & 1) { | 1861 if (cnt & 1) { |
1863 if (cnt == 1) { | 1862 if (cnt == 1) { |
1864 pdfContext->fGraphicsState.fDashArray[1] = pdfContext->fGraphicsStat
e.fDashArray[0]; | 1863 pdfContext->fGraphicsState.fDashArray[1] = pdfContext->fGraphicsStat
e.fDashArray[0]; |
1865 cnt++; | 1864 cnt++; |
1866 } else { | 1865 } else { |
1867 // TODO(edisonn): report error/warning | 1866 // TODO(edisonn): report error/warning |
1868 return kNYI_PdfResult; | 1867 return kNYI_SkPdfResult; |
1869 } | 1868 } |
1870 } | 1869 } |
1871 pdfContext->fGraphicsState.fDashArrayLength = cnt; | 1870 pdfContext->fGraphicsState.fDashArrayLength = cnt; |
1872 pdfContext->fGraphicsState.fDashPhase = phase->scalarValue(); | 1871 pdfContext->fGraphicsState.fDashPhase = phase->scalarValue(); |
1873 if (pdfContext->fGraphicsState.fDashPhase == 0) { | 1872 if (pdfContext->fGraphicsState.fDashPhase == 0) { |
1874 // other rules, changes? | 1873 // other rules, changes? |
1875 pdfContext->fGraphicsState.fDashPhase = total; | 1874 pdfContext->fGraphicsState.fDashPhase = total; |
1876 } | 1875 } |
1877 | 1876 |
1878 return kOK_PdfResult; | 1877 return kOK_SkPdfResult; |
1879 } | 1878 } |
1880 | 1879 |
1881 PdfResult skpdfGraphicsStateApplyD(PdfContext* pdfContext, SkPdfArray* dash) { | 1880 SkPdfResult skpdfGraphicsStateApplyD(SkPdfContext* pdfContext, SkPdfArray* dash)
{ |
1882 // TODO(edisonn): verify input | 1881 // TODO(edisonn): verify input |
1883 if (!dash || dash->isArray() || dash->size() != 2 || !dash->objAtAIndex(0)->
isArray() || !dash->objAtAIndex(1)->isNumber()) { | 1882 if (!dash || dash->isArray() || dash->size() != 2 || !dash->objAtAIndex(0)->
isArray() || !dash->objAtAIndex(1)->isNumber()) { |
1884 // TODO(edisonn): report error/warning | 1883 // TODO(edisonn): report error/warning |
1885 return kIgnoreError_PdfResult; | 1884 return kIgnoreError_SkPdfResult; |
1886 } | 1885 } |
1887 return skpdfGraphicsStateApplyD(pdfContext, (SkPdfArray*)dash->objAtAIndex(0
), dash->objAtAIndex(1)); | 1886 return skpdfGraphicsStateApplyD(pdfContext, (SkPdfArray*)dash->objAtAIndex(0
), dash->objAtAIndex(1)); |
1888 } | 1887 } |
1889 | 1888 |
1890 void skpdfGraphicsStateApplyFont(PdfContext* pdfContext, SkPdfArray* fontAndSize
) { | 1889 void skpdfGraphicsStateApplyFont(SkPdfContext* pdfContext, SkPdfArray* fontAndSi
ze) { |
1891 if (!fontAndSize || fontAndSize->isArray() || fontAndSize->size() != 2 || !f
ontAndSize->objAtAIndex(0)->isName() || !fontAndSize->objAtAIndex(1)->isNumber()
) { | 1890 if (!fontAndSize || fontAndSize->isArray() || fontAndSize->size() != 2 || !f
ontAndSize->objAtAIndex(0)->isName() || !fontAndSize->objAtAIndex(1)->isNumber()
) { |
1892 // TODO(edisonn): report error/warning | 1891 // TODO(edisonn): report error/warning |
1893 return; | 1892 return; |
1894 } | 1893 } |
1895 skpdfGraphicsStateApplyFontCore(pdfContext, fontAndSize->objAtAIndex(0), fon
tAndSize->objAtAIndex(1)->numberValue()); | 1894 skpdfGraphicsStateApplyFontCore(pdfContext, fontAndSize->objAtAIndex(0), fon
tAndSize->objAtAIndex(1)->numberValue()); |
1896 } | 1895 } |
1897 | 1896 |
1898 | 1897 |
1899 //lineWidth w Set the line width in the graphics state (see “Line Width” on page
152). | 1898 //lineWidth w Set the line width in the graphics state (see “Line Width” on page
152). |
1900 static PdfResult PdfOp_w(PdfContext* pdfContext, SkCanvas* canvas, PdfTokenLoope
r** looper) { | 1899 static SkPdfResult PdfOp_w(SkPdfContext* pdfContext, SkCanvas* canvas, PdfTokenL
ooper** looper) { |
1901 double lw = pdfContext->fObjectStack.top()->numberValue(); pdfContext->fO
bjectStack.pop(); | 1900 double lw = pdfContext->fObjectStack.top()->numberValue(); pdfContext->fO
bjectStack.pop(); |
1902 return skpdfGraphicsStateApplyLW(pdfContext, lw); | 1901 return skpdfGraphicsStateApplyLW(pdfContext, lw); |
1903 } | 1902 } |
1904 | 1903 |
1905 //lineCap J Set the line cap style in the graphics state (see “Line Cap Style” o
n page 153). | 1904 //lineCap J Set the line cap style in the graphics state (see “Line Cap Style” o
n page 153). |
1906 static PdfResult PdfOp_J(PdfContext* pdfContext, SkCanvas* canvas, PdfTokenLoope
r** looper) { | 1905 static SkPdfResult PdfOp_J(SkPdfContext* pdfContext, SkCanvas* canvas, PdfTokenL
ooper** looper) { |
1907 int64_t lc = pdfContext->fObjectStack.top()->numberValue(); pdfContext->f
ObjectStack.pop(); | 1906 int64_t lc = pdfContext->fObjectStack.top()->numberValue(); pdfContext->f
ObjectStack.pop(); |
1908 return skpdfGraphicsStateApplyLC(pdfContext, lc); | 1907 return skpdfGraphicsStateApplyLC(pdfContext, lc); |
1909 } | 1908 } |
1910 | 1909 |
1911 //lineJoin j Set the line join style in the graphics state (see “Line Join Style
” on page 153). | 1910 //lineJoin j Set the line join style in the graphics state (see “Line Join Style
” on page 153). |
1912 static PdfResult PdfOp_j(PdfContext* pdfContext, SkCanvas* canvas, PdfTokenLoope
r** looper) { | 1911 static SkPdfResult PdfOp_j(SkPdfContext* pdfContext, SkCanvas* canvas, PdfTokenL
ooper** looper) { |
1913 double lj = pdfContext->fObjectStack.top()->numberValue(); pdfContext->fO
bjectStack.pop(); | 1912 double lj = pdfContext->fObjectStack.top()->numberValue(); pdfContext->fO
bjectStack.pop(); |
1914 return skpdfGraphicsStateApplyLJ(pdfContext, lj); | 1913 return skpdfGraphicsStateApplyLJ(pdfContext, lj); |
1915 } | 1914 } |
1916 | 1915 |
1917 //miterLimit M Set the miter limit in the graphics state (see “Miter Limit” on p
age 153). | 1916 //miterLimit M Set the miter limit in the graphics state (see “Miter Limit” on p
age 153). |
1918 static PdfResult PdfOp_M(PdfContext* pdfContext, SkCanvas* canvas, PdfTokenLoope
r** looper) { | 1917 static SkPdfResult PdfOp_M(SkPdfContext* pdfContext, SkCanvas* canvas, PdfTokenL
ooper** looper) { |
1919 double ml = pdfContext->fObjectStack.top()->numberValue(); pdfContext->fO
bjectStack.pop(); | 1918 double ml = pdfContext->fObjectStack.top()->numberValue(); pdfContext->fO
bjectStack.pop(); |
1920 return skpdfGraphicsStateApplyML(pdfContext, ml); | 1919 return skpdfGraphicsStateApplyML(pdfContext, ml); |
1921 } | 1920 } |
1922 | 1921 |
1923 //dashArray dashPhase d Set the line dash pattern in the graphics state (see “Li
ne Dash Pattern” on | 1922 //dashArray dashPhase d Set the line dash pattern in the graphics state (see “Li
ne Dash Pattern” on |
1924 //page 155). | 1923 //page 155). |
1925 static PdfResult PdfOp_d(PdfContext* pdfContext, SkCanvas* canvas, PdfTokenLoope
r** looper) { | 1924 static SkPdfResult PdfOp_d(SkPdfContext* pdfContext, SkCanvas* canvas, PdfTokenL
ooper** looper) { |
1926 SkPdfObject* phase = pdfContext->fObjectStack.top(); pdfContext->fO
bjectStack.pop(); | 1925 SkPdfNativeObject* phase = pdfContext->fObjectStack.top(); pdfConte
xt->fObjectStack.pop(); |
1927 SkPdfObject* array = pdfContext->fObjectStack.top(); pdfContext->fO
bjectStack.pop(); | 1926 SkPdfNativeObject* array = pdfContext->fObjectStack.top(); pdfConte
xt->fObjectStack.pop(); |
1928 | 1927 |
1929 if (!array->isArray()) { | 1928 if (!array->isArray()) { |
1930 return kIgnoreError_PdfResult; | 1929 return kIgnoreError_SkPdfResult; |
1931 } | 1930 } |
1932 | 1931 |
1933 return skpdfGraphicsStateApplyD(pdfContext, (SkPdfArray*)array, phase); | 1932 return skpdfGraphicsStateApplyD(pdfContext, (SkPdfArray*)array, phase); |
1934 } | 1933 } |
1935 | 1934 |
1936 //intent ri (PDF 1.1) Set the color rendering intent in the graphics state (see
“Rendering Intents” on page 197). | 1935 //intent ri (PDF 1.1) Set the color rendering intent in the graphics state (see
“Rendering Intents” on page 197). |
1937 static PdfResult PdfOp_ri(PdfContext* pdfContext, SkCanvas* canvas, PdfTokenLoop
er** looper) { | 1936 static SkPdfResult PdfOp_ri(SkPdfContext* pdfContext, SkCanvas* canvas, PdfToken
Looper** looper) { |
1938 pdfContext->fObjectStack.pop(); | 1937 pdfContext->fObjectStack.pop(); |
1939 | 1938 |
1940 return kNYI_PdfResult; | 1939 return kNYI_SkPdfResult; |
1941 } | 1940 } |
1942 | 1941 |
1943 //flatness i Set the flatness tolerance in the graphics state (see Section 6.5.1,
“Flatness | 1942 //flatness i Set the flatness tolerance in the graphics state (see Section 6.5.1,
“Flatness |
1944 //Tolerance”). flatness is a number in the range 0 to 100; a value of 0 speci- | 1943 //Tolerance”). flatness is a number in the range 0 to 100; a value of 0 speci- |
1945 //fies the output device’s default flatness tolerance. | 1944 //fies the output device’s default flatness tolerance. |
1946 static PdfResult PdfOp_i(PdfContext* pdfContext, SkCanvas* canvas, PdfTokenLoope
r** looper) { | 1945 static SkPdfResult PdfOp_i(SkPdfContext* pdfContext, SkCanvas* canvas, PdfTokenL
ooper** looper) { |
1947 pdfContext->fObjectStack.pop(); | 1946 pdfContext->fObjectStack.pop(); |
1948 | 1947 |
1949 return kNYI_PdfResult; | 1948 return kNYI_SkPdfResult; |
1950 } | 1949 } |
1951 | 1950 |
1952 SkTDict<SkXfermode::Mode> gPdfBlendModes(20); | 1951 SkTDict<SkXfermode::Mode> gPdfBlendModes(20); |
1953 | 1952 |
1954 class InitBlendModes { | 1953 class InitBlendModes { |
1955 public: | 1954 public: |
1956 InitBlendModes() { | 1955 InitBlendModes() { |
1957 // TODO(edisonn): use the python code generator? | 1956 // TODO(edisonn): use the python code generator? |
1958 // TABLE 7.2 Standard separable blend modes | 1957 // TABLE 7.2 Standard separable blend modes |
1959 gPdfBlendModes.set("Normal", SkXfermode::kSrc_Mode); | 1958 gPdfBlendModes.set("Normal", SkXfermode::kSrc_Mode); |
(...skipping 21 matching lines...) Expand all Loading... |
1981 | 1980 |
1982 SkXfermode::Mode xferModeFromBlendMode(const char* blendMode, size_t len) { | 1981 SkXfermode::Mode xferModeFromBlendMode(const char* blendMode, size_t len) { |
1983 SkXfermode::Mode mode = (SkXfermode::Mode)(SkXfermode::kLastMode + 1); | 1982 SkXfermode::Mode mode = (SkXfermode::Mode)(SkXfermode::kLastMode + 1); |
1984 if (gPdfBlendModes.find(blendMode, len, &mode)) { | 1983 if (gPdfBlendModes.find(blendMode, len, &mode)) { |
1985 return mode; | 1984 return mode; |
1986 } | 1985 } |
1987 | 1986 |
1988 return (SkXfermode::Mode)(SkXfermode::kLastMode + 1); | 1987 return (SkXfermode::Mode)(SkXfermode::kLastMode + 1); |
1989 } | 1988 } |
1990 | 1989 |
1991 void skpdfGraphicsStateApplyBM_name(PdfContext* pdfContext, const std::string& b
lendMode) { | 1990 void skpdfGraphicsStateApplyBM_name(SkPdfContext* pdfContext, const std::string&
blendMode) { |
1992 SkXfermode::Mode mode = xferModeFromBlendMode(blendMode.c_str(), blendMode.l
ength()); | 1991 SkXfermode::Mode mode = xferModeFromBlendMode(blendMode.c_str(), blendMode.l
ength()); |
1993 if (mode <= SkXfermode::kLastMode) { | 1992 if (mode <= SkXfermode::kLastMode) { |
1994 pdfContext->fGraphicsState.fBlendModesLength = 1; | 1993 pdfContext->fGraphicsState.fBlendModesLength = 1; |
1995 pdfContext->fGraphicsState.fBlendModes[0] = mode; | 1994 pdfContext->fGraphicsState.fBlendModes[0] = mode; |
1996 } else { | 1995 } else { |
1997 // TODO(edisonn): report unknown blend mode | 1996 // TODO(edisonn): report unknown blend mode |
1998 } | 1997 } |
1999 } | 1998 } |
2000 | 1999 |
2001 void skpdfGraphicsStateApplyBM_array(PdfContext* pdfContext, SkPdfArray* blendMo
des) { | 2000 void skpdfGraphicsStateApplyBM_array(SkPdfContext* pdfContext, SkPdfArray* blend
Modes) { |
2002 if (!blendModes || blendModes->isArray() || blendModes->size() == 0 || blend
Modes->size() > 256) { | 2001 if (!blendModes || blendModes->isArray() || blendModes->size() == 0 || blend
Modes->size() > 256) { |
2003 // TODO(edisonn): report error/warning | 2002 // TODO(edisonn): report error/warning |
2004 return; | 2003 return; |
2005 } | 2004 } |
2006 SkXfermode::Mode modes[256]; | 2005 SkXfermode::Mode modes[256]; |
2007 int cnt = blendModes->size(); | 2006 int cnt = blendModes->size(); |
2008 for (int i = 0; i < cnt; i++) { | 2007 for (int i = 0; i < cnt; i++) { |
2009 SkPdfObject* name = blendModes->objAtAIndex(i); | 2008 SkPdfNativeObject* name = blendModes->objAtAIndex(i); |
2010 if (!name->isName()) { | 2009 if (!name->isName()) { |
2011 // TODO(edisonn): report error/warning | 2010 // TODO(edisonn): report error/warning |
2012 return; | 2011 return; |
2013 } | 2012 } |
2014 SkXfermode::Mode mode = xferModeFromBlendMode(name->c_str(), name->lenst
r()); | 2013 SkXfermode::Mode mode = xferModeFromBlendMode(name->c_str(), name->lenst
r()); |
2015 if (mode > SkXfermode::kLastMode) { | 2014 if (mode > SkXfermode::kLastMode) { |
2016 // TODO(edisonn): report error/warning | 2015 // TODO(edisonn): report error/warning |
2017 return; | 2016 return; |
2018 } | 2017 } |
2019 } | 2018 } |
2020 | 2019 |
2021 pdfContext->fGraphicsState.fBlendModesLength = cnt; | 2020 pdfContext->fGraphicsState.fBlendModesLength = cnt; |
2022 for (int i = 0; i < cnt; i++) { | 2021 for (int i = 0; i < cnt; i++) { |
2023 pdfContext->fGraphicsState.fBlendModes[i] = modes[i]; | 2022 pdfContext->fGraphicsState.fBlendModes[i] = modes[i]; |
2024 } | 2023 } |
2025 } | 2024 } |
2026 | 2025 |
2027 void skpdfGraphicsStateApplySMask_dict(PdfContext* pdfContext, SkPdfDictionary*
sMask) { | 2026 void skpdfGraphicsStateApplySMask_dict(SkPdfContext* pdfContext, SkPdfDictionary
* sMask) { |
2028 // TODO(edisonn): verify input | 2027 // TODO(edisonn): verify input |
2029 if (pdfContext->fPdfDoc->mapper()->mapSoftMaskDictionary(sMask)) { | 2028 if (pdfContext->fPdfDoc->mapper()->mapSoftMaskDictionary(sMask)) { |
2030 pdfContext->fGraphicsState.fSoftMaskDictionary = (SkPdfSoftMaskDictionar
y*)sMask; | 2029 pdfContext->fGraphicsState.fSoftMaskDictionary = (SkPdfSoftMaskDictionar
y*)sMask; |
2031 } else if (pdfContext->fPdfDoc->mapper()->mapSoftMaskImageDictionary(sMask))
{ | 2030 } else if (pdfContext->fPdfDoc->mapper()->mapSoftMaskImageDictionary(sMask))
{ |
2032 SkPdfSoftMaskImageDictionary* smid = (SkPdfSoftMaskImageDictionary*)sMas
k; | 2031 SkPdfSoftMaskImageDictionary* smid = (SkPdfSoftMaskImageDictionary*)sMas
k; |
2033 pdfContext->fGraphicsState.fSMask = getImageFromObject(pdfContext, smid,
true); | 2032 pdfContext->fGraphicsState.fSMask = getImageFromObject(pdfContext, smid,
true); |
2034 } else { | 2033 } else { |
2035 // TODO (edisonn): report error/warning | 2034 // TODO (edisonn): report error/warning |
2036 } | 2035 } |
2037 } | 2036 } |
2038 | 2037 |
2039 void skpdfGraphicsStateApplySMask_name(PdfContext* pdfContext, const std::string
& sMask) { | 2038 void skpdfGraphicsStateApplySMask_name(SkPdfContext* pdfContext, const std::stri
ng& sMask) { |
2040 if (sMask == "None") { | 2039 if (sMask == "None") { |
2041 pdfContext->fGraphicsState.fSoftMaskDictionary = NULL; | 2040 pdfContext->fGraphicsState.fSoftMaskDictionary = NULL; |
2042 pdfContext->fGraphicsState.fSMask = NULL; | 2041 pdfContext->fGraphicsState.fSMask = NULL; |
2043 return; | 2042 return; |
2044 } | 2043 } |
2045 | 2044 |
2046 //Next, get the ExtGState Dictionary from the Resource Dictionary: | 2045 //Next, get the ExtGState Dictionary from the Resource Dictionary: |
2047 SkPdfDictionary* extGStateDictionary = pdfContext->fGraphicsState.fResources
->ExtGState(pdfContext->fPdfDoc); | 2046 SkPdfDictionary* extGStateDictionary = pdfContext->fGraphicsState.fResources
->ExtGState(pdfContext->fPdfDoc); |
2048 | 2047 |
2049 if (extGStateDictionary == NULL) { | 2048 if (extGStateDictionary == NULL) { |
2050 #ifdef PDF_TRACE | 2049 #ifdef PDF_TRACE |
2051 printf("ExtGState is NULL!\n"); | 2050 printf("ExtGState is NULL!\n"); |
2052 #endif | 2051 #endif |
2053 // TODO (edisonn): report error/warning | 2052 // TODO (edisonn): report error/warning |
2054 return; | 2053 return; |
2055 } | 2054 } |
2056 | 2055 |
2057 SkPdfObject* obj = pdfContext->fPdfDoc->resolveReference(extGStateDictionary
->get(sMask.c_str())); | 2056 SkPdfNativeObject* obj = pdfContext->fPdfDoc->resolveReference(extGStateDict
ionary->get(sMask.c_str())); |
2058 if (!obj || !obj->isDictionary()) { | 2057 if (!obj || !obj->isDictionary()) { |
2059 // TODO (edisonn): report error/warning | 2058 // TODO (edisonn): report error/warning |
2060 return; | 2059 return; |
2061 } | 2060 } |
2062 | 2061 |
2063 pdfContext->fGraphicsState.fSoftMaskDictionary = NULL; | 2062 pdfContext->fGraphicsState.fSoftMaskDictionary = NULL; |
2064 pdfContext->fGraphicsState.fSMask = NULL; | 2063 pdfContext->fGraphicsState.fSMask = NULL; |
2065 | 2064 |
2066 skpdfGraphicsStateApplySMask_dict(pdfContext, obj->asDictionary()); | 2065 skpdfGraphicsStateApplySMask_dict(pdfContext, obj->asDictionary()); |
2067 } | 2066 } |
2068 | 2067 |
2069 void skpdfGraphicsStateApplyAIS(PdfContext* pdfContext, bool alphaSource) { | 2068 void skpdfGraphicsStateApplyAIS(SkPdfContext* pdfContext, bool alphaSource) { |
2070 pdfContext->fGraphicsState.fAlphaSource = alphaSource; | 2069 pdfContext->fGraphicsState.fAlphaSource = alphaSource; |
2071 } | 2070 } |
2072 | 2071 |
2073 | 2072 |
2074 //dictName gs (PDF 1.2) Set the specified parameters in the graphics state. dictN
ame is | 2073 //dictName gs (PDF 1.2) Set the specified parameters in the graphics state. dictN
ame is |
2075 //the name of a graphics state parameter dictionary in the ExtGState subdictiona
ry of the current resource dictionary (see the next section). | 2074 //the name of a graphics state parameter dictionary in the ExtGState subdictiona
ry of the current resource dictionary (see the next section). |
2076 static PdfResult PdfOp_gs(PdfContext* pdfContext, SkCanvas* canvas, PdfTokenLoop
er** looper) { | 2075 static SkPdfResult PdfOp_gs(SkPdfContext* pdfContext, SkCanvas* canvas, PdfToken
Looper** looper) { |
2077 SkPdfObject* name = pdfContext->fObjectStack.top(); pdfContext->fObjectSt
ack.pop(); | 2076 SkPdfNativeObject* name = pdfContext->fObjectStack.top(); pdfContext->fOb
jectStack.pop(); |
2078 | 2077 |
2079 #ifdef PDF_TRACE | 2078 #ifdef PDF_TRACE |
2080 std::string str; | 2079 std::string str; |
2081 #endif | 2080 #endif |
2082 | 2081 |
2083 //Next, get the ExtGState Dictionary from the Resource Dictionary: | 2082 //Next, get the ExtGState Dictionary from the Resource Dictionary: |
2084 SkPdfDictionary* extGStateDictionary = pdfContext->fGraphicsState.fResources
->ExtGState(pdfContext->fPdfDoc); | 2083 SkPdfDictionary* extGStateDictionary = pdfContext->fGraphicsState.fResources
->ExtGState(pdfContext->fPdfDoc); |
2085 | 2084 |
2086 if (extGStateDictionary == NULL) { | 2085 if (extGStateDictionary == NULL) { |
2087 #ifdef PDF_TRACE | 2086 #ifdef PDF_TRACE |
2088 printf("ExtGState is NULL!\n"); | 2087 printf("ExtGState is NULL!\n"); |
2089 #endif | 2088 #endif |
2090 return kIgnoreError_PdfResult; | 2089 return kIgnoreError_SkPdfResult; |
2091 } | 2090 } |
2092 | 2091 |
2093 SkPdfObject* value = pdfContext->fPdfDoc->resolveReference(extGStateDictiona
ry->get(name)); | 2092 SkPdfNativeObject* value = pdfContext->fPdfDoc->resolveReference(extGStateDi
ctionary->get(name)); |
2094 | 2093 |
2095 if (kNone_SkPdfObjectType == pdfContext->fPdfDoc->mapper()->mapGraphicsState
Dictionary(value)) { | 2094 if (kNone_SkPdfNativeObjectType == pdfContext->fPdfDoc->mapper()->mapGraphic
sStateDictionary(value)) { |
2096 return kIgnoreError_PdfResult; | 2095 return kIgnoreError_SkPdfResult; |
2097 } | 2096 } |
2098 SkPdfGraphicsStateDictionary* gs = (SkPdfGraphicsStateDictionary*)value; | 2097 SkPdfGraphicsStateDictionary* gs = (SkPdfGraphicsStateDictionary*)value; |
2099 | 2098 |
2100 // TODO(edisonn): now load all those properties in graphic state. | 2099 // TODO(edisonn): now load all those properties in graphic state. |
2101 if (gs == NULL) { | 2100 if (gs == NULL) { |
2102 return kIgnoreError_PdfResult; | 2101 return kIgnoreError_SkPdfResult; |
2103 } | 2102 } |
2104 | 2103 |
2105 if (gs->has_LW()) { | 2104 if (gs->has_LW()) { |
2106 skpdfGraphicsStateApplyLW(pdfContext, gs->LW(pdfContext->fPdfDoc)); | 2105 skpdfGraphicsStateApplyLW(pdfContext, gs->LW(pdfContext->fPdfDoc)); |
2107 } | 2106 } |
2108 | 2107 |
2109 if (gs->has_LC()) { | 2108 if (gs->has_LC()) { |
2110 skpdfGraphicsStateApplyLC(pdfContext, gs->LC(pdfContext->fPdfDoc)); | 2109 skpdfGraphicsStateApplyLC(pdfContext, gs->LC(pdfContext->fPdfDoc)); |
2111 } | 2110 } |
2112 | 2111 |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2151 } | 2150 } |
2152 | 2151 |
2153 if (gs->has_CA()) { | 2152 if (gs->has_CA()) { |
2154 skpdfGraphicsStateApply_CA(pdfContext, gs->CA(pdfContext->fPdfDoc)); | 2153 skpdfGraphicsStateApply_CA(pdfContext, gs->CA(pdfContext->fPdfDoc)); |
2155 } | 2154 } |
2156 | 2155 |
2157 if (gs->has_AIS()) { | 2156 if (gs->has_AIS()) { |
2158 skpdfGraphicsStateApplyAIS(pdfContext, gs->AIS(pdfContext->fPdfDoc)); | 2157 skpdfGraphicsStateApplyAIS(pdfContext, gs->AIS(pdfContext->fPdfDoc)); |
2159 } | 2158 } |
2160 | 2159 |
2161 return kOK_PdfResult; | 2160 return kOK_SkPdfResult; |
2162 } | 2161 } |
2163 | 2162 |
2164 //charSpace Tc Set the character spacing, Tc | 2163 //charSpace Tc Set the character spacing, Tc |
2165 //, to charSpace, which is a number expressed in unscaled text space units. Char
acter spacing is used by the Tj, TJ, and ' operators. | 2164 //, to charSpace, which is a number expressed in unscaled text space units. Char
acter spacing is used by the Tj, TJ, and ' operators. |
2166 //Initial value: 0. | 2165 //Initial value: 0. |
2167 PdfResult PdfOp_Tc(PdfContext* pdfContext, SkCanvas* canvas, PdfTokenLooper** lo
oper) { | 2166 SkPdfResult PdfOp_Tc(SkPdfContext* pdfContext, SkCanvas* canvas, PdfTokenLooper*
* looper) { |
2168 double charSpace = pdfContext->fObjectStack.top()->numberValue(); pdfCon
text->fObjectStack.pop(); | 2167 double charSpace = pdfContext->fObjectStack.top()->numberValue(); pdfCon
text->fObjectStack.pop(); |
2169 pdfContext->fGraphicsState.fCharSpace = charSpace; | 2168 pdfContext->fGraphicsState.fCharSpace = charSpace; |
2170 | 2169 |
2171 return kOK_PdfResult; | 2170 return kOK_SkPdfResult; |
2172 } | 2171 } |
2173 | 2172 |
2174 //wordSpace Tw Set the word spacing, T | 2173 //wordSpace Tw Set the word spacing, T |
2175 //w | 2174 //w |
2176 //, to wordSpace, which is a number expressed in unscaled | 2175 //, to wordSpace, which is a number expressed in unscaled |
2177 //text space units. Word spacing is used by the Tj, TJ, and ' operators. Initial | 2176 //text space units. Word spacing is used by the Tj, TJ, and ' operators. Initial |
2178 //value: 0. | 2177 //value: 0. |
2179 PdfResult PdfOp_Tw(PdfContext* pdfContext, SkCanvas* canvas, PdfTokenLooper** lo
oper) { | 2178 SkPdfResult PdfOp_Tw(SkPdfContext* pdfContext, SkCanvas* canvas, PdfTokenLooper*
* looper) { |
2180 double wordSpace = pdfContext->fObjectStack.top()->numberValue(); pdfCon
text->fObjectStack.pop(); | 2179 double wordSpace = pdfContext->fObjectStack.top()->numberValue(); pdfCon
text->fObjectStack.pop(); |
2181 pdfContext->fGraphicsState.fWordSpace = wordSpace; | 2180 pdfContext->fGraphicsState.fWordSpace = wordSpace; |
2182 | 2181 |
2183 return kOK_PdfResult; | 2182 return kOK_SkPdfResult; |
2184 } | 2183 } |
2185 | 2184 |
2186 //scale Tz Set the horizontal scaling, Th | 2185 //scale Tz Set the horizontal scaling, Th |
2187 //, to (scale ˜ 100). scale is a number specifying the | 2186 //, to (scale ˜ 100). scale is a number specifying the |
2188 //percentage of the normal width. Initial value: 100 (normal width). | 2187 //percentage of the normal width. Initial value: 100 (normal width). |
2189 static PdfResult PdfOp_Tz(PdfContext* pdfContext, SkCanvas* canvas, PdfTokenLoop
er** looper) { | 2188 static SkPdfResult PdfOp_Tz(SkPdfContext* pdfContext, SkCanvas* canvas, PdfToken
Looper** looper) { |
2190 /*double scale = */pdfContext->fObjectStack.top()->numberValue(); pdfCon
text->fObjectStack.pop(); | 2189 /*double scale = */pdfContext->fObjectStack.top()->numberValue(); pdfCon
text->fObjectStack.pop(); |
2191 | 2190 |
2192 return kNYI_PdfResult; | 2191 return kNYI_SkPdfResult; |
2193 } | 2192 } |
2194 | 2193 |
2195 //render Tr Set the text rendering mode, T | 2194 //render Tr Set the text rendering mode, T |
2196 //mode, to render, which is an integer. Initial value: 0. | 2195 //mode, to render, which is an integer. Initial value: 0. |
2197 static PdfResult PdfOp_Tr(PdfContext* pdfContext, SkCanvas* canvas, PdfTokenLoop
er** looper) { | 2196 static SkPdfResult PdfOp_Tr(SkPdfContext* pdfContext, SkCanvas* canvas, PdfToken
Looper** looper) { |
2198 /*double render = */pdfContext->fObjectStack.top()->numberValue(); pdfCo
ntext->fObjectStack.pop(); | 2197 /*double render = */pdfContext->fObjectStack.top()->numberValue(); pdfCo
ntext->fObjectStack.pop(); |
2199 | 2198 |
2200 return kNYI_PdfResult; | 2199 return kNYI_SkPdfResult; |
2201 } | 2200 } |
2202 //rise Ts Set the text rise, Trise, to rise, which is a number expressed in unsc
aled text space | 2201 //rise Ts Set the text rise, Trise, to rise, which is a number expressed in unsc
aled text space |
2203 //units. Initial value: 0. | 2202 //units. Initial value: 0. |
2204 static PdfResult PdfOp_Ts(PdfContext* pdfContext, SkCanvas* canvas, PdfTokenLoop
er** looper) { | 2203 static SkPdfResult PdfOp_Ts(SkPdfContext* pdfContext, SkCanvas* canvas, PdfToken
Looper** looper) { |
2205 /*double rise = */pdfContext->fObjectStack.top()->numberValue(); pdfCont
ext->fObjectStack.pop(); | 2204 /*double rise = */pdfContext->fObjectStack.top()->numberValue(); pdfCont
ext->fObjectStack.pop(); |
2206 | 2205 |
2207 return kNYI_PdfResult; | 2206 return kNYI_SkPdfResult; |
2208 } | 2207 } |
2209 | 2208 |
2210 //wx wy d0 | 2209 //wx wy d0 |
2211 static PdfResult PdfOp_d0(PdfContext* pdfContext, SkCanvas* canvas, PdfTokenLoop
er** looper) { | 2210 static SkPdfResult PdfOp_d0(SkPdfContext* pdfContext, SkCanvas* canvas, PdfToken
Looper** looper) { |
2212 pdfContext->fObjectStack.pop(); | 2211 pdfContext->fObjectStack.pop(); |
2213 pdfContext->fObjectStack.pop(); | 2212 pdfContext->fObjectStack.pop(); |
2214 | 2213 |
2215 return kNYI_PdfResult; | 2214 return kNYI_SkPdfResult; |
2216 } | 2215 } |
2217 | 2216 |
2218 //wx wy llx lly urx ury d1 | 2217 //wx wy llx lly urx ury d1 |
2219 static PdfResult PdfOp_d1(PdfContext* pdfContext, SkCanvas* canvas, PdfTokenLoop
er** looper) { | 2218 static SkPdfResult PdfOp_d1(SkPdfContext* pdfContext, SkCanvas* canvas, PdfToken
Looper** looper) { |
2220 pdfContext->fObjectStack.pop(); | 2219 pdfContext->fObjectStack.pop(); |
2221 pdfContext->fObjectStack.pop(); | 2220 pdfContext->fObjectStack.pop(); |
2222 pdfContext->fObjectStack.pop(); | 2221 pdfContext->fObjectStack.pop(); |
2223 pdfContext->fObjectStack.pop(); | 2222 pdfContext->fObjectStack.pop(); |
2224 pdfContext->fObjectStack.pop(); | 2223 pdfContext->fObjectStack.pop(); |
2225 pdfContext->fObjectStack.pop(); | 2224 pdfContext->fObjectStack.pop(); |
2226 | 2225 |
2227 return kNYI_PdfResult; | 2226 return kNYI_SkPdfResult; |
2228 } | 2227 } |
2229 | 2228 |
2230 //name sh | 2229 //name sh |
2231 static PdfResult PdfOp_sh(PdfContext* pdfContext, SkCanvas* canvas, PdfTokenLoop
er** looper) { | 2230 static SkPdfResult PdfOp_sh(SkPdfContext* pdfContext, SkCanvas* canvas, PdfToken
Looper** looper) { |
2232 pdfContext->fObjectStack.pop(); | 2231 pdfContext->fObjectStack.pop(); |
2233 | 2232 |
2234 return kNYI_PdfResult; | 2233 return kNYI_SkPdfResult; |
2235 } | 2234 } |
2236 | 2235 |
2237 //name Do | 2236 //name Do |
2238 static PdfResult PdfOp_Do(PdfContext* pdfContext, SkCanvas* canvas, PdfTokenLoop
er** looper) { | 2237 static SkPdfResult PdfOp_Do(SkPdfContext* pdfContext, SkCanvas* canvas, PdfToken
Looper** looper) { |
2239 SkPdfObject* name = pdfContext->fObjectStack.top(); pdfContext->fObjectSt
ack.pop(); | 2238 SkPdfNativeObject* name = pdfContext->fObjectStack.top(); pdfContext->fOb
jectStack.pop(); |
2240 | 2239 |
2241 SkPdfDictionary* xObject = pdfContext->fGraphicsState.fResources->XObject(p
dfContext->fPdfDoc); | 2240 SkPdfDictionary* xObject = pdfContext->fGraphicsState.fResources->XObject(p
dfContext->fPdfDoc); |
2242 | 2241 |
2243 if (xObject == NULL) { | 2242 if (xObject == NULL) { |
2244 #ifdef PDF_TRACE | 2243 #ifdef PDF_TRACE |
2245 printf("XObject is NULL!\n"); | 2244 printf("XObject is NULL!\n"); |
2246 #endif | 2245 #endif |
2247 return kIgnoreError_PdfResult; | 2246 return kIgnoreError_SkPdfResult; |
2248 } | 2247 } |
2249 | 2248 |
2250 SkPdfObject* value = xObject->get(name); | 2249 SkPdfNativeObject* value = xObject->get(name); |
2251 value = pdfContext->fPdfDoc->resolveReference(value); | 2250 value = pdfContext->fPdfDoc->resolveReference(value); |
2252 | 2251 |
2253 #ifdef PDF_TRACE | 2252 #ifdef PDF_TRACE |
2254 // value->ToString(str); | 2253 // value->ToString(str); |
2255 // printf("Do object value: %s\n", str); | 2254 // printf("Do object value: %s\n", str); |
2256 #endif | 2255 #endif |
2257 | 2256 |
2258 return doXObject(pdfContext, canvas, value); | 2257 return doXObject(pdfContext, canvas, value); |
2259 } | 2258 } |
2260 | 2259 |
2261 //tag MP Designate a marked-content point. tag is a name object indicating the r
ole or | 2260 //tag MP Designate a marked-content point. tag is a name object indicating the r
ole or |
2262 //significance of the point. | 2261 //significance of the point. |
2263 static PdfResult PdfOp_MP(PdfContext* pdfContext, SkCanvas* canvas, PdfTokenLoop
er** looper) { | 2262 static SkPdfResult PdfOp_MP(SkPdfContext* pdfContext, SkCanvas* canvas, PdfToken
Looper** looper) { |
2264 pdfContext->fObjectStack.pop(); | 2263 pdfContext->fObjectStack.pop(); |
2265 | 2264 |
2266 return kNYI_PdfResult; | 2265 return kNYI_SkPdfResult; |
2267 } | 2266 } |
2268 | 2267 |
2269 //tag properties DP Designate a marked-content point with an associated property
list. tag is a | 2268 //tag properties DP Designate a marked-content point with an associated property
list. tag is a |
2270 //name object indicating the role or significance of the point; properties is | 2269 //name object indicating the role or significance of the point; properties is |
2271 //either an inline dictionary containing the property list or a name object | 2270 //either an inline dictionary containing the property list or a name object |
2272 //associated with it in the Properties subdictionary of the current resource | 2271 //associated with it in the Properties subdictionary of the current resource |
2273 //dictionary (see Section 9.5.1, “Property Lists”). | 2272 //dictionary (see Section 9.5.1, “Property Lists”). |
2274 static PdfResult PdfOp_DP(PdfContext* pdfContext, SkCanvas* canvas, PdfTokenLoop
er** looper) { | 2273 static SkPdfResult PdfOp_DP(SkPdfContext* pdfContext, SkCanvas* canvas, PdfToken
Looper** looper) { |
2275 pdfContext->fObjectStack.pop(); | 2274 pdfContext->fObjectStack.pop(); |
2276 pdfContext->fObjectStack.pop(); | 2275 pdfContext->fObjectStack.pop(); |
2277 | 2276 |
2278 return kNYI_PdfResult; | 2277 return kNYI_SkPdfResult; |
2279 } | 2278 } |
2280 | 2279 |
2281 //tag BMC Begin a marked-content sequence terminated by a balancing EMC operator
. | 2280 //tag BMC Begin a marked-content sequence terminated by a balancing EMC operator
. |
2282 //tag is a name object indicating the role or significance of the sequence. | 2281 //tag is a name object indicating the role or significance of the sequence. |
2283 static PdfResult PdfOp_BMC(PdfContext* pdfContext, SkCanvas* canvas, PdfTokenLoo
per** looper) { | 2282 static SkPdfResult PdfOp_BMC(SkPdfContext* pdfContext, SkCanvas* canvas, PdfToke
nLooper** looper) { |
2284 pdfContext->fObjectStack.pop(); | 2283 pdfContext->fObjectStack.pop(); |
2285 | 2284 |
2286 return kNYI_PdfResult; | 2285 return kNYI_SkPdfResult; |
2287 } | 2286 } |
2288 | 2287 |
2289 //tag properties BDC Begin a marked-content sequence with an associated property
list, terminated | 2288 //tag properties BDC Begin a marked-content sequence with an associated property
list, terminated |
2290 //by a balancing EMCoperator. tag is a name object indicating the role or signif
icance of the sequence; propertiesis either an inline dictionary containing the | 2289 //by a balancing EMCoperator. tag is a name object indicating the role or signif
icance of the sequence; propertiesis either an inline dictionary containing the |
2291 //property list or a name object associated with it in the Properties subdiction
ary of the current resource dictionary (see Section 9.5.1, “Property Lists”). | 2290 //property list or a name object associated with it in the Properties subdiction
ary of the current resource dictionary (see Section 9.5.1, “Property Lists”). |
2292 static PdfResult PdfOp_BDC(PdfContext* pdfContext, SkCanvas* canvas, PdfTokenLoo
per** looper) { | 2291 static SkPdfResult PdfOp_BDC(SkPdfContext* pdfContext, SkCanvas* canvas, PdfToke
nLooper** looper) { |
2293 pdfContext->fObjectStack.pop(); | 2292 pdfContext->fObjectStack.pop(); |
2294 pdfContext->fObjectStack.pop(); | 2293 pdfContext->fObjectStack.pop(); |
2295 | 2294 |
2296 return kNYI_PdfResult; | 2295 return kNYI_SkPdfResult; |
2297 } | 2296 } |
2298 | 2297 |
2299 //— EMC End a marked-content sequence begun by a BMC or BDC operator. | 2298 //— EMC End a marked-content sequence begun by a BMC or BDC operator. |
2300 static PdfResult PdfOp_EMC(PdfContext* pdfContext, SkCanvas* canvas, PdfTokenLoo
per** looper) { | 2299 static SkPdfResult PdfOp_EMC(SkPdfContext* pdfContext, SkCanvas* canvas, PdfToke
nLooper** looper) { |
2301 return kNYI_PdfResult; | 2300 return kNYI_SkPdfResult; |
2302 } | 2301 } |
2303 | 2302 |
2304 static void initPdfOperatorRenderes() { | 2303 static void initPdfOperatorRenderes() { |
2305 static bool gInitialized = false; | 2304 static bool gInitialized = false; |
2306 if (gInitialized) { | 2305 if (gInitialized) { |
2307 return; | 2306 return; |
2308 } | 2307 } |
2309 | 2308 |
2310 gPdfOps.set("q", PdfOp_q); | 2309 gPdfOps.set("q", PdfOp_q); |
2311 gPdfOps.set("Q", PdfOp_Q); | 2310 gPdfOps.set("Q", PdfOp_Q); |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2404 InitPdfOps() { | 2403 InitPdfOps() { |
2405 initPdfOperatorRenderes(); | 2404 initPdfOperatorRenderes(); |
2406 } | 2405 } |
2407 }; | 2406 }; |
2408 | 2407 |
2409 InitPdfOps gInitPdfOps; | 2408 InitPdfOps gInitPdfOps; |
2410 | 2409 |
2411 void reportPdfRenderStats() { | 2410 void reportPdfRenderStats() { |
2412 std::map<std::string, int>::iterator iter; | 2411 std::map<std::string, int>::iterator iter; |
2413 | 2412 |
2414 for (int i = 0 ; i < kCount_PdfResult; i++) { | 2413 for (int i = 0 ; i < kCount_SkPdfResult; i++) { |
2415 SkTDict<int>::Iter iter(gRenderStats[i]); | 2414 SkTDict<int>::Iter iter(gRenderStats[i]); |
2416 const char* key; | 2415 const char* key; |
2417 int value = 0; | 2416 int value = 0; |
2418 while ((key = iter.next(&value)) != NULL) { | 2417 while ((key = iter.next(&value)) != NULL) { |
2419 printf("%s: %s -> count %i\n", gRenderStatsNames[i], key, value); | 2418 printf("%s: %s -> count %i\n", gRenderStatsNames[i], key, value); |
2420 } | 2419 } |
2421 } | 2420 } |
2422 } | 2421 } |
2423 | 2422 |
2424 PdfResult PdfMainLooper::consumeToken(PdfToken& token) { | 2423 SkPdfResult PdfMainLooper::consumeToken(PdfToken& token) { |
2425 if (token.fType == kKeyword_TokenType && token.fKeywordLength < 256) | 2424 if (token.fType == kKeyword_TokenType && token.fKeywordLength < 256) |
2426 { | 2425 { |
2427 // TODO(edisonn): log trace flag (verbose, error, info, warning, ...) | 2426 // TODO(edisonn): log trace flag (verbose, error, info, warning, ...) |
2428 PdfOperatorRenderer pdfOperatorRenderer = NULL; | 2427 PdfOperatorRenderer pdfOperatorRenderer = NULL; |
2429 if (gPdfOps.find(token.fKeyword, token.fKeywordLength, &pdfOperatorRende
rer) && pdfOperatorRenderer) { | 2428 if (gPdfOps.find(token.fKeyword, token.fKeywordLength, &pdfOperatorRende
rer) && pdfOperatorRenderer) { |
2430 // caller, main work is done by pdfOperatorRenderer(...) | 2429 // caller, main work is done by pdfOperatorRenderer(...) |
2431 PdfTokenLooper* childLooper = NULL; | 2430 PdfTokenLooper* childLooper = NULL; |
2432 PdfResult result = pdfOperatorRenderer(fPdfContext, fCanvas, &childL
ooper); | 2431 SkPdfResult result = pdfOperatorRenderer(fPdfContext, fCanvas, &chil
dLooper); |
2433 | 2432 |
2434 int cnt = 0; | 2433 int cnt = 0; |
2435 gRenderStats[result].find(token.fKeyword, token.fKeywordLength, &cnt
); | 2434 gRenderStats[result].find(token.fKeyword, token.fKeywordLength, &cnt
); |
2436 gRenderStats[result].set(token.fKeyword, token.fKeywordLength, cnt +
1); | 2435 gRenderStats[result].set(token.fKeyword, token.fKeywordLength, cnt +
1); |
2437 | 2436 |
2438 if (childLooper) { | 2437 if (childLooper) { |
2439 childLooper->setUp(this); | 2438 childLooper->setUp(this); |
2440 childLooper->loop(); | 2439 childLooper->loop(); |
2441 delete childLooper; | 2440 delete childLooper; |
2442 } | 2441 } |
2443 } else { | 2442 } else { |
2444 int cnt = 0; | 2443 int cnt = 0; |
2445 gRenderStats[kUnsupported_PdfResult].find(token.fKeyword, token.fKey
wordLength, &cnt); | 2444 gRenderStats[kUnsupported_SkPdfResult].find(token.fKeyword, token.fK
eywordLength, &cnt); |
2446 gRenderStats[kUnsupported_PdfResult].set(token.fKeyword, token.fKeyw
ordLength, cnt + 1); | 2445 gRenderStats[kUnsupported_SkPdfResult].set(token.fKeyword, token.fKe
ywordLength, cnt + 1); |
2447 } | 2446 } |
2448 } | 2447 } |
2449 else if (token.fType == kObject_TokenType) | 2448 else if (token.fType == kObject_TokenType) |
2450 { | 2449 { |
2451 fPdfContext->fObjectStack.push( token.fObject ); | 2450 fPdfContext->fObjectStack.push( token.fObject ); |
2452 } | 2451 } |
2453 else { | 2452 else { |
2454 // TODO(edisonn): deine or use assert not reached | 2453 // TODO(edisonn): deine or use assert not reached |
2455 return kIgnoreError_PdfResult; | 2454 return kIgnoreError_SkPdfResult; |
2456 } | 2455 } |
2457 return kOK_PdfResult; | 2456 return kOK_SkPdfResult; |
2458 } | 2457 } |
2459 | 2458 |
2460 void PdfMainLooper::loop() { | 2459 void PdfMainLooper::loop() { |
2461 PdfToken token; | 2460 PdfToken token; |
2462 while (readToken(fTokenizer, &token)) { | 2461 while (readToken(fTokenizer, &token)) { |
2463 consumeToken(token); | 2462 consumeToken(token); |
2464 } | 2463 } |
2465 } | 2464 } |
2466 | 2465 |
2467 PdfResult PdfInlineImageLooper::consumeToken(PdfToken& token) { | 2466 SkPdfResult PdfInlineImageLooper::consumeToken(PdfToken& token) { |
2468 SkASSERT(false); | 2467 SkASSERT(false); |
2469 return kIgnoreError_PdfResult; | 2468 return kIgnoreError_SkPdfResult; |
2470 } | 2469 } |
2471 | 2470 |
2472 void PdfInlineImageLooper::loop() { | 2471 void PdfInlineImageLooper::loop() { |
2473 doXObject_Image(fPdfContext, fCanvas, fTokenizer->readInlineImage()); | 2472 doXObject_Image(fPdfContext, fCanvas, fTokenizer->readInlineImage()); |
2474 } | 2473 } |
2475 | 2474 |
2476 PdfResult PdfInlineImageLooper::done() { | 2475 SkPdfResult PdfInlineImageLooper::done() { |
2477 return kNYI_PdfResult; | 2476 return kNYI_SkPdfResult; |
2478 } | 2477 } |
2479 | 2478 |
2480 PdfResult PdfCompatibilitySectionLooper::consumeToken(PdfToken& token) { | 2479 SkPdfResult PdfCompatibilitySectionLooper::consumeToken(PdfToken& token) { |
2481 return fParent->consumeToken(token); | 2480 return fParent->consumeToken(token); |
2482 } | 2481 } |
2483 | 2482 |
2484 void PdfCompatibilitySectionLooper::loop() { | 2483 void PdfCompatibilitySectionLooper::loop() { |
2485 // TODO(edisonn): save stacks position, or create a new stack? | 2484 // TODO(edisonn): save stacks position, or create a new stack? |
2486 // TODO(edisonn): what happens if we pop out more variables then when we sta
rted? | 2485 // TODO(edisonn): what happens if we pop out more variables then when we sta
rted? |
2487 // restore them? fail? We could create a new operands stack for every new BX
/EX section, | 2486 // restore them? fail? We could create a new operands stack for every new BX
/EX section, |
2488 // pop-ing too much will not affect outside the section. | 2487 // pop-ing too much will not affect outside the section. |
2489 PdfToken token; | 2488 PdfToken token; |
2490 while (readToken(fTokenizer, &token)) { | 2489 while (readToken(fTokenizer, &token)) { |
(...skipping 14 matching lines...) Expand all Loading... |
2505 // TODO(edisonn): Add API for Forms viewing and editing | 2504 // TODO(edisonn): Add API for Forms viewing and editing |
2506 // e.g. SkBitmap getPage(int page); | 2505 // e.g. SkBitmap getPage(int page); |
2507 // int formsCount(); | 2506 // int formsCount(); |
2508 // SkForm getForm(int formID); // SkForm(SkRect, .. other data) | 2507 // SkForm getForm(int formID); // SkForm(SkRect, .. other data) |
2509 // TODO (edisonn): Add intend when loading pdf, for example: for viewing, parsin
g all content, ... | 2508 // TODO (edisonn): Add intend when loading pdf, for example: for viewing, parsin
g all content, ... |
2510 // if we load the first page, and we zoom to fit to screen horizontally, then lo
ad only those | 2509 // if we load the first page, and we zoom to fit to screen horizontally, then lo
ad only those |
2511 // resources needed, so the preview is fast. | 2510 // resources needed, so the preview is fast. |
2512 // TODO (edisonn): hide parser/tokenizer behind and interface and a query langua
ge, and resolve | 2511 // TODO (edisonn): hide parser/tokenizer behind and interface and a query langua
ge, and resolve |
2513 // references automatically. | 2512 // references automatically. |
2514 | 2513 |
2515 PdfContext* gPdfContext = NULL; | 2514 SkPdfContext* gPdfContext = NULL; |
2516 | 2515 |
2517 bool SkPdfRenderer::renderPage(int page, SkCanvas* canvas, const SkRect& dst) co
nst { | 2516 bool SkPdfRenderer::renderPage(int page, SkCanvas* canvas, const SkRect& dst) co
nst { |
2518 if (!fPdfDoc) { | 2517 if (!fPdfDoc) { |
2519 return false; | 2518 return false; |
2520 } | 2519 } |
2521 | 2520 |
2522 if (page < 0 || page >= pages()) { | 2521 if (page < 0 || page >= pages()) { |
2523 return false; | 2522 return false; |
2524 } | 2523 } |
2525 | 2524 |
2526 PdfContext pdfContext(fPdfDoc); | 2525 SkPdfContext pdfContext(fPdfDoc); |
2527 | 2526 |
2528 pdfContext.fOriginalMatrix = SkMatrix::I(); | 2527 pdfContext.fOriginalMatrix = SkMatrix::I(); |
2529 pdfContext.fGraphicsState.fResources = fPdfDoc->pageResources(page); | 2528 pdfContext.fGraphicsState.fResources = fPdfDoc->pageResources(page); |
2530 | 2529 |
2531 gPdfContext = &pdfContext; | 2530 gPdfContext = &pdfContext; |
2532 | 2531 |
2533 // TODO(edisonn): get matrix stuff right. | 2532 // TODO(edisonn): get matrix stuff right. |
2534 SkScalar z = SkIntToScalar(0); | 2533 SkScalar z = SkIntToScalar(0); |
2535 SkScalar w = dst.width(); | 2534 SkScalar w = dst.width(); |
2536 SkScalar h = dst.height(); | 2535 SkScalar h = dst.height(); |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2583 | 2582 |
2584 | 2583 |
2585 canvas->flush(); | 2584 canvas->flush(); |
2586 return true; | 2585 return true; |
2587 } | 2586 } |
2588 | 2587 |
2589 bool SkPdfRenderer::load(const SkString inputFileName) { | 2588 bool SkPdfRenderer::load(const SkString inputFileName) { |
2590 unload(); | 2589 unload(); |
2591 | 2590 |
2592 // TODO(edisonn): create static function that could return NULL if there are
errors | 2591 // TODO(edisonn): create static function that could return NULL if there are
errors |
2593 fPdfDoc = new SkNativeParsedPDF(inputFileName.c_str()); | 2592 fPdfDoc = new SkPdfNativeDoc(inputFileName.c_str()); |
2594 if (fPdfDoc->pages() == 0) { | 2593 if (fPdfDoc->pages() == 0) { |
2595 delete fPdfDoc; | 2594 delete fPdfDoc; |
2596 fPdfDoc = NULL; | 2595 fPdfDoc = NULL; |
2597 } | 2596 } |
2598 | 2597 |
2599 return fPdfDoc != NULL; | 2598 return fPdfDoc != NULL; |
2600 } | 2599 } |
2601 | 2600 |
2602 bool SkPdfRenderer::load(SkStream* stream) { | 2601 bool SkPdfRenderer::load(SkStream* stream) { |
2603 unload(); | 2602 unload(); |
2604 | 2603 |
2605 // TODO(edisonn): create static function that could return NULL if there are
errors | 2604 // TODO(edisonn): create static function that could return NULL if there are
errors |
2606 fPdfDoc = new SkNativeParsedPDF(stream); | 2605 fPdfDoc = new SkPdfNativeDoc(stream); |
2607 if (fPdfDoc->pages() == 0) { | 2606 if (fPdfDoc->pages() == 0) { |
2608 delete fPdfDoc; | 2607 delete fPdfDoc; |
2609 fPdfDoc = NULL; | 2608 fPdfDoc = NULL; |
2610 } | 2609 } |
2611 | 2610 |
2612 return fPdfDoc != NULL; | 2611 return fPdfDoc != NULL; |
2613 } | 2612 } |
2614 | 2613 |
2615 | 2614 |
2616 int SkPdfRenderer::pages() const { | 2615 int SkPdfRenderer::pages() const { |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2650 | 2649 |
2651 rect = SkRect::MakeWH(width, height); | 2650 rect = SkRect::MakeWH(width, height); |
2652 | 2651 |
2653 setup_bitmap(output, (int)SkScalarToDouble(width), (int)SkScalarToDouble(hei
ght)); | 2652 setup_bitmap(output, (int)SkScalarToDouble(width), (int)SkScalarToDouble(hei
ght)); |
2654 | 2653 |
2655 SkAutoTUnref<SkDevice> device(SkNEW_ARGS(SkDevice, (*output))); | 2654 SkAutoTUnref<SkDevice> device(SkNEW_ARGS(SkDevice, (*output))); |
2656 SkCanvas canvas(device); | 2655 SkCanvas canvas(device); |
2657 | 2656 |
2658 return renderer.renderPage(page, &canvas, rect); | 2657 return renderer.renderPage(page, &canvas, rect); |
2659 } | 2658 } |
OLD | NEW |