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 "SkPdfRenderer.h" |
| 9 |
8 #include "SkBitmapDevice.h" | 10 #include "SkBitmapDevice.h" |
9 #include "SkCanvas.h" | 11 #include "SkCanvas.h" |
10 #include "SkDevice.h" | 12 #include "SkDevice.h" |
11 #include "SkForceLinking.h" | 13 #include "SkForceLinking.h" |
12 #include "SkGraphics.h" | 14 #include "SkGraphics.h" |
13 #include "SkImageDecoder.h" | 15 #include "SkImageDecoder.h" |
14 #include "SkImageEncoder.h" | 16 #include "SkImageEncoder.h" |
15 #include "SkOSFile.h" | 17 #include "SkOSFile.h" |
16 #include "SkPicture.h" | 18 #include "SkPicture.h" |
17 #include "SkStream.h" | 19 #include "SkStream.h" |
18 #include "SkTypeface.h" | 20 #include "SkTypeface.h" |
19 #include "SkTArray.h" | 21 #include "SkTArray.h" |
20 #include "SkTDict.h" | 22 #include "SkTDict.h" |
21 | 23 |
22 #include "SkPdfGraphicsState.h" | 24 #include "SkPdfGraphicsState.h" |
23 #include "SkPdfNativeTokenizer.h" | 25 #include "SkPdfNativeTokenizer.h" |
| 26 #include "SkPdfReporter.h" |
24 | 27 |
25 extern "C" SkPdfContext* gPdfContext; | 28 extern "C" SkPdfContext* gPdfContext; |
26 extern "C" SkBitmap* gDumpBitmap; | 29 extern "C" SkBitmap* gDumpBitmap; |
27 extern "C" SkCanvas* gDumpCanvas; | 30 extern "C" SkCanvas* gDumpCanvas; |
28 | 31 |
| 32 |
29 __SK_FORCE_IMAGE_DECODER_LINKING; | 33 __SK_FORCE_IMAGE_DECODER_LINKING; |
30 | 34 |
31 // TODO(edisonn): tool, show what objects were read at least, show the ones not
even read | 35 // TODO(edisonn): tool, show what objects were read at least, show the ones not
even read |
32 // keep for each object pos in file | 36 // keep for each object pos in file |
33 // plug in for VS? syntax coloring, show selected object ... from the text, or f
rom rendered x,y | 37 // plug in for VS? syntax coloring, show selected object ... from the text, or f
rom rendered x,y |
34 | 38 |
35 // TODO(edisonn): security - validate all the user input, all pdf! | 39 // TODO(edisonn): security - validate all the user input, all pdf! |
36 | 40 |
37 // TODO(edisonn): put drawtext in #ifdefs, so comparations will ignore minor cha
nges in text positioning and font | 41 // TODO(edisonn): put drawtext in #ifdefs, so comparations will ignore minor cha
nges in text positioning and font |
38 // this way, we look more at other features and layout in diffs | 42 // this way, we look more at other features and layout in diffs |
(...skipping 26 matching lines...) Expand all Loading... |
65 * - encapsulate native in the pdf api so the skpdf does not know anything about
native ... in progress | 69 * - encapsulate native in the pdf api so the skpdf does not know anything about
native ... in progress |
66 * - load gs/ especially smask and already known prop (skp) ... in progress | 70 * - load gs/ especially smask and already known prop (skp) ... in progress |
67 * - wrapper on classes for customizations? e.g. | 71 * - wrapper on classes for customizations? e.g. |
68 * SkPdfPageObjectVanila - has only the basic loaders/getters | 72 * SkPdfPageObjectVanila - has only the basic loaders/getters |
69 * SkPdfPageObject : public SkPdfPageObjectVanila, extends, and I can add custom
izations here | 73 * SkPdfPageObject : public SkPdfPageObjectVanila, extends, and I can add custom
izations here |
70 * need to find a nice object model for all this with constructors and factories | 74 * need to find a nice object model for all this with constructors and factories |
71 * - deal with inheritable automatically ? | 75 * - deal with inheritable automatically ? |
72 * - deal with specific type in spec directly, add all dictionary types to known
types | 76 * - deal with specific type in spec directly, add all dictionary types to known
types |
73 */ | 77 */ |
74 | 78 |
75 #define EXPECT_OPERANDS(pdfContext,n) \ | 79 #define EXPECT_OPERANDS(name,pdfContext,n) \ |
76 bool __failed = pdfContext->fObjectStack.count() < n; \ | 80 bool __failed = pdfContext->fObjectStack.count() < n; \ |
| 81 SkPdfREPORTCODE(const char* __operator_name = name); \ |
| 82 SkPdfREPORTCODE((void)__operator_name); \ |
| 83 SkPdfReportIf(pdfContext->fObjectStack.count() < n, kIgnoreError_SkPdfIssueS
everity, kStackOverflow_SkPdfIssue, "Not enought parameters.", NULL, pdfContext)
; \ |
77 SkDEBUGCODE(int __cnt = n); | 84 SkDEBUGCODE(int __cnt = n); |
78 | 85 |
79 #define POP_OBJ(pdfContext,name) \ | 86 #define POP_OBJ(pdfContext,name) \ |
80 SkDEBUGCODE(__cnt--); \ | 87 SkDEBUGCODE(__cnt--); \ |
81 SkASSERT(__cnt >= 0); \ | 88 SkASSERT(__cnt >= 0); \ |
82 SkPdfNativeObject* name = NULL; \ | 89 SkPdfNativeObject* name = NULL; \ |
83 __failed = __failed || pdfContext->fObjectStack.count() == 0; \ | 90 __failed = __failed || pdfContext->fObjectStack.count() == 0; \ |
84 if (pdfContext->fObjectStack.count() > 0) { \ | 91 if (pdfContext->fObjectStack.count() > 0) { \ |
85 name = pdfContext->fObjectStack.top(); \ | 92 name = pdfContext->fObjectStack.top(); \ |
86 pdfContext->fObjectStack.pop(); \ | 93 pdfContext->fObjectStack.pop(); \ |
87 } | 94 } |
88 | 95 |
| 96 // TODO(edisonn): make all pop function to use name##_obj |
89 #define POP_NUMBER(pdfContext,name) \ | 97 #define POP_NUMBER(pdfContext,name) \ |
90 SkDEBUGCODE(__cnt--); \ | 98 SkDEBUGCODE(__cnt--); \ |
91 SkASSERT(__cnt >= 0); \ | 99 SkASSERT(__cnt >= 0); \ |
92 double name = 0; \ | 100 double name = 0; \ |
| 101 SkPdfNativeObject* name##_obj = NULL; \ |
93 __failed = __failed || pdfContext->fObjectStack.count() == 0; \ | 102 __failed = __failed || pdfContext->fObjectStack.count() == 0; \ |
94 if (pdfContext->fObjectStack.count() > 0) { \ | 103 if (pdfContext->fObjectStack.count() > 0) { \ |
95 SkPdfNativeObject* tmp = pdfContext->fObjectStack.top(); \ | 104 name##_obj = pdfContext->fObjectStack.top(); \ |
96 pdfContext->fObjectStack.pop(); \ | 105 pdfContext->fObjectStack.pop(); \ |
97 if (!tmp || !tmp->isNumber()) { \ | 106 if (!name##_obj || !name##_obj->isNumber()) { \ |
| 107 SkPdfReportUnexpectedType(kIgnoreError_SkPdfIssueSeverity, __operato
r_name, name##_obj, SkPdfNativeObject::_kNumber_PdfObjectType, NULL);\ |
98 __failed = true;\ | 108 __failed = true;\ |
99 } else { \ | 109 } else { \ |
100 name = tmp->numberValue(); \ | 110 name = name##_obj->numberValue(); \ |
101 } \ | 111 } \ |
102 } | 112 } |
103 | 113 |
104 #define POP_INTEGER(pdfContext,name) \ | 114 #define POP_INTEGER(pdfContext,name) \ |
105 SkDEBUGCODE(__cnt--); \ | 115 SkDEBUGCODE(__cnt--); \ |
106 SkASSERT(__cnt >= 0); \ | 116 SkASSERT(__cnt >= 0); \ |
107 int64_t name = 0; \ | 117 int64_t name = 0; \ |
108 __failed = __failed || pdfContext->fObjectStack.count() == 0; \ | 118 __failed = __failed || pdfContext->fObjectStack.count() == 0; \ |
| 119 SkPdfNativeObject* name##_obj = NULL; \ |
109 if (pdfContext->fObjectStack.count() > 0) { \ | 120 if (pdfContext->fObjectStack.count() > 0) { \ |
110 SkPdfNativeObject* tmp = pdfContext->fObjectStack.top(); \ | 121 name##_obj = pdfContext->fObjectStack.top(); \ |
111 pdfContext->fObjectStack.pop(); \ | 122 pdfContext->fObjectStack.pop(); \ |
112 if (!tmp || !tmp->isInteger()) { \ | 123 if (!name##_obj || !name##_obj->isInteger()) { \ |
| 124 SkPdfReportUnexpectedType(kIgnoreError_SkPdfIssueSeverity, __operato
r_name, name##_obj, SkPdfNativeObject::kInteger_PdfObjectType, NULL);\ |
113 __failed = true;\ | 125 __failed = true;\ |
114 } else { \ | 126 } else { \ |
115 name = tmp->intValue(); \ | 127 name = name##_obj->intValue(); \ |
116 } \ | 128 } \ |
117 } | 129 } |
118 | 130 |
119 #define POP_NUMBER_INTO(pdfContext,var) \ | 131 #define POP_NUMBER_INTO(pdfContext,var) \ |
120 SkDEBUGCODE(__cnt--); \ | 132 SkDEBUGCODE(__cnt--); \ |
121 SkASSERT(__cnt >= 0); \ | 133 SkASSERT(__cnt >= 0); \ |
122 __failed = __failed || pdfContext->fObjectStack.count() == 0; \ | 134 __failed = __failed || pdfContext->fObjectStack.count() == 0; \ |
123 if (pdfContext->fObjectStack.count() > 0) { \ | 135 if (pdfContext->fObjectStack.count() > 0) { \ |
124 SkPdfNativeObject* tmp = pdfContext->fObjectStack.top(); \ | 136 SkPdfNativeObject* tmp = pdfContext->fObjectStack.top(); \ |
125 pdfContext->fObjectStack.pop(); \ | 137 pdfContext->fObjectStack.pop(); \ |
126 if (!tmp || !tmp->isNumber()) { \ | 138 if (!tmp || !tmp->isNumber()) { \ |
| 139 SkPdfReportUnexpectedType(kIgnoreError_SkPdfIssueSeverity, __operato
r_name, tmp, SkPdfNativeObject::kInteger_PdfObjectType | SkPdfNativeObject::kRea
l_PdfObjectType, NULL);\ |
127 __failed = true;\ | 140 __failed = true;\ |
128 } else { \ | 141 } else { \ |
129 var = tmp->numberValue(); \ | 142 var = tmp->numberValue(); \ |
130 } \ | 143 } \ |
131 } | 144 } |
132 | 145 |
133 | 146 |
134 #define POP_NAME(pdfContext,name) \ | 147 #define POP_NAME(pdfContext,name) \ |
135 SkDEBUGCODE(__cnt--); \ | 148 SkDEBUGCODE(__cnt--); \ |
136 SkASSERT(__cnt >= 0); \ | 149 SkASSERT(__cnt >= 0); \ |
137 SkPdfNativeObject* name = NULL; \ | 150 SkPdfNativeObject* name = NULL; \ |
138 __failed = __failed || pdfContext->fObjectStack.count() == 0; \ | 151 __failed = __failed || pdfContext->fObjectStack.count() == 0; \ |
139 if (pdfContext->fObjectStack.count() > 0) { \ | 152 if (pdfContext->fObjectStack.count() > 0) { \ |
140 SkPdfNativeObject* tmp = pdfContext->fObjectStack.top(); \ | 153 SkPdfNativeObject* tmp = pdfContext->fObjectStack.top(); \ |
141 pdfContext->fObjectStack.pop(); \ | 154 pdfContext->fObjectStack.pop(); \ |
142 if (!tmp || !tmp->isName()) { \ | 155 if (!tmp || !tmp->isName()) { \ |
| 156 SkPdfReportUnexpectedType(kIgnoreError_SkPdfIssueSeverity, __operato
r_name, tmp, SkPdfNativeObject::kName_PdfObjectType, NULL);\ |
143 __failed = true;\ | 157 __failed = true;\ |
144 } else { \ | 158 } else { \ |
145 name = tmp; \ | 159 name = tmp; \ |
146 } \ | 160 } \ |
147 } | 161 } |
148 | 162 |
149 #define POP_STRING(pdfContext,name) \ | 163 #define POP_STRING(pdfContext,name) \ |
150 SkDEBUGCODE(__cnt--); \ | 164 SkDEBUGCODE(__cnt--); \ |
151 SkASSERT(__cnt >= 0); \ | 165 SkASSERT(__cnt >= 0); \ |
152 SkPdfNativeObject* name = NULL; \ | 166 SkPdfNativeObject* name = NULL; \ |
153 __failed = __failed || pdfContext->fObjectStack.count() == 0; \ | 167 __failed = __failed || pdfContext->fObjectStack.count() == 0; \ |
154 if (pdfContext->fObjectStack.count() > 0) { \ | 168 if (pdfContext->fObjectStack.count() > 0) { \ |
155 SkPdfNativeObject* tmp = pdfContext->fObjectStack.top(); \ | 169 SkPdfNativeObject* tmp = pdfContext->fObjectStack.top(); \ |
156 pdfContext->fObjectStack.pop(); \ | 170 pdfContext->fObjectStack.pop(); \ |
157 if (!tmp || !tmp->isAnyString()) { \ | 171 if (!tmp || !tmp->isAnyString()) { \ |
| 172 SkPdfReportUnexpectedType(kIgnoreError_SkPdfIssueSeverity, __operato
r_name, tmp, SkPdfNativeObject::kString_PdfObjectType | SkPdfNativeObject::kHexS
tring_PdfObjectType, NULL);\ |
158 __failed = true;\ | 173 __failed = true;\ |
159 } else { \ | 174 } else { \ |
160 name = tmp; \ | 175 name = tmp; \ |
161 } \ | 176 } \ |
162 } | 177 } |
163 | 178 |
164 #define POP_ARRAY(pdfContext,name) \ | 179 #define POP_ARRAY(pdfContext,name) \ |
165 SkDEBUGCODE(__cnt--); \ | 180 SkDEBUGCODE(__cnt--); \ |
166 SkASSERT(__cnt >= 0); \ | 181 SkASSERT(__cnt >= 0); \ |
167 SkPdfArray* name = NULL; \ | 182 SkPdfArray* name = NULL; \ |
168 __failed = __failed || pdfContext->fObjectStack.count() == 0; \ | 183 __failed = __failed || pdfContext->fObjectStack.count() == 0; \ |
169 if (pdfContext->fObjectStack.count() > 0) { \ | 184 if (pdfContext->fObjectStack.count() > 0) { \ |
170 SkPdfNativeObject* tmp = pdfContext->fObjectStack.top(); \ | 185 SkPdfNativeObject* tmp = pdfContext->fObjectStack.top(); \ |
171 pdfContext->fObjectStack.pop(); \ | 186 pdfContext->fObjectStack.pop(); \ |
172 if (!tmp || !tmp->isArray()) { \ | 187 if (!tmp || !tmp->isArray()) { \ |
| 188 SkPdfReportUnexpectedType(kIgnoreError_SkPdfIssueSeverity, __operato
r_name, tmp, SkPdfNativeObject::kArray_PdfObjectType, NULL);\ |
173 __failed = true;\ | 189 __failed = true;\ |
174 } else { \ | 190 } else { \ |
175 name = (SkPdfArray*)tmp; \ | 191 name = (SkPdfArray*)tmp; \ |
176 } \ | 192 } \ |
177 } | 193 } |
178 | 194 |
179 // TODO(edisonn): ability to turn on asserts for known good files | 195 // TODO(edisonn): ability to turn on asserts for known good files |
180 // log error - add name of function? location in file? | 196 // log error - add name of function? location in file? |
181 #define CHECK_PARAMETERS() \ | 197 #define CHECK_PARAMETERS() \ |
182 SkASSERT(__cnt == 0); \ | 198 SkASSERT(__cnt == 0); \ |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
293 SkDoubleToScalar(0), | 309 SkDoubleToScalar(0), |
294 SkDoubleToScalar(1)); | 310 SkDoubleToScalar(1)); |
295 | 311 |
296 return matrix; | 312 return matrix; |
297 } | 313 } |
298 | 314 |
299 SkMatrix SkMatrixFromPdfArray(SkPdfArray* pdfArray) { | 315 SkMatrix SkMatrixFromPdfArray(SkPdfArray* pdfArray) { |
300 double array[6]; | 316 double array[6]; |
301 | 317 |
302 // TODO(edisonn): security issue, ret if size() != 6 | 318 // TODO(edisonn): security issue, ret if size() != 6 |
| 319 if (pdfArray == NULL) { |
| 320 SkPdfReport(kIgnoreError_SkPdfIssueSeverity, kNullObject_SkPdfIssue, "nu
ll array passed to build matrix", NULL, NULL); |
| 321 return SkMatrix::I(); |
| 322 } |
| 323 |
| 324 if (pdfArray->size() != 6) { |
| 325 SkPdfReport(kIgnoreError_SkPdfIssueSeverity, kUnexpectedArraySize_SkPdfI
ssue, "null array passed to build matrix", pdfArray, NULL); |
| 326 return SkMatrix::I(); |
| 327 } |
| 328 |
303 for (int i = 0; i < 6; i++) { | 329 for (int i = 0; i < 6; i++) { |
304 const SkPdfNativeObject* elem = pdfArray->operator [](i); | 330 const SkPdfNativeObject* elem = pdfArray->operator [](i); |
305 if (elem == NULL || !elem->isNumber()) { | 331 if (elem == NULL || !elem->isNumber()) { |
306 return SkMatrix::I(); // TODO(edisonn): report issue | 332 SkPdfReportUnexpectedType(kIgnoreError_SkPdfIssueSeverity, NULL, ele
m, SkPdfNativeObject::_kNumber_PdfObjectType, NULL); |
| 333 return SkMatrix::I(); |
307 } | 334 } |
308 array[i] = elem->numberValue(); | 335 array[i] = elem->numberValue(); |
309 } | 336 } |
310 | 337 |
311 return SkMatrixFromPdfMatrix(array); | 338 return SkMatrixFromPdfMatrix(array); |
312 } | 339 } |
313 | 340 |
314 | 341 |
315 extern "C" SkPdfNativeDoc* gDoc; | 342 extern "C" SkPdfNativeDoc* gDoc; |
316 SkBitmap* gDumpBitmap = NULL; | 343 SkBitmap* gDumpBitmap = NULL; |
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
455 static SkPdfResult DrawText(SkPdfContext* pdfContext, | 482 static SkPdfResult DrawText(SkPdfContext* pdfContext, |
456 const SkPdfNativeObject* _str, | 483 const SkPdfNativeObject* _str, |
457 SkCanvas* canvas) | 484 SkCanvas* canvas) |
458 { | 485 { |
459 | 486 |
460 SkPdfFont* skfont = pdfContext->fGraphicsState.fSkFont; | 487 SkPdfFont* skfont = pdfContext->fGraphicsState.fSkFont; |
461 if (skfont == NULL) { | 488 if (skfont == NULL) { |
462 skfont = SkPdfFont::Default(); | 489 skfont = SkPdfFont::Default(); |
463 } | 490 } |
464 | 491 |
465 | |
466 if (_str == NULL || !_str->isAnyString()) { | 492 if (_str == NULL || !_str->isAnyString()) { |
467 // TODO(edisonn): report warning | 493 SkPdfReportUnexpectedType(kIgnoreError_SkPdfIssueSeverity, "DrawText", _
str, SkPdfNativeObject::_kAnyString_PdfObjectType, pdfContext); |
468 return kIgnoreError_SkPdfResult; | 494 return kIgnoreError_SkPdfResult; |
469 } | 495 } |
470 const SkPdfString* str = (const SkPdfString*)_str; | 496 const SkPdfString* str = (const SkPdfString*)_str; |
471 | 497 |
472 SkUnencodedText binary(str); | 498 SkUnencodedText binary(str); |
473 | 499 |
474 SkDecodedText decoded; | 500 SkDecodedText decoded; |
475 | 501 |
476 if (skfont->encoding() == NULL) { | 502 if (skfont->encoding() == NULL) { |
477 // TODO(edisonn): report warning | 503 SkPdfReport(kIgnoreError_SkPdfIssueSeverity, kMissingEncoding_SkPdfIssue
, "draw text", _str, pdfContext); |
478 return kNYI_SkPdfResult; | 504 return kNYI_SkPdfResult; |
479 } | 505 } |
480 | 506 |
481 skfont->encoding()->decodeText(binary, &decoded); | 507 skfont->encoding()->decodeText(binary, &decoded); |
482 | 508 |
483 SkPaint paint; | 509 SkPaint paint; |
484 // TODO(edisonn): when should fCurFont->GetFontSize() used? When cur is fCur
FontSize == 0? | 510 // TODO(edisonn): when should fCurFont->GetFontSize() used? When cur is fCur
FontSize == 0? |
485 // Or maybe just not call setTextSize at all? | 511 // Or maybe just not call setTextSize at all? |
486 if (pdfContext->fGraphicsState.fCurFontSize != 0) { | 512 if (pdfContext->fGraphicsState.fCurFontSize != 0) { |
487 paint.setTextSize(SkDoubleToScalar(pdfContext->fGraphicsState.fCurFontSi
ze)); | 513 paint.setTextSize(SkDoubleToScalar(pdfContext->fGraphicsState.fCurFontSi
ze)); |
(...skipping 23 matching lines...) Expand all Loading... |
511 if (grayColortable == NULL) { | 537 if (grayColortable == NULL) { |
512 SkPMColor* colors = new SkPMColor[256]; | 538 SkPMColor* colors = new SkPMColor[256]; |
513 for (int i = 0 ; i < 256; i++) { | 539 for (int i = 0 ; i < 256; i++) { |
514 colors[i] = SkPreMultiplyARGB(255, i, i, i); | 540 colors[i] = SkPreMultiplyARGB(255, i, i, i); |
515 } | 541 } |
516 grayColortable = new SkColorTable(colors, 256); | 542 grayColortable = new SkColorTable(colors, 256); |
517 } | 543 } |
518 return grayColortable; | 544 return grayColortable; |
519 } | 545 } |
520 | 546 |
521 static SkBitmap* transferImageStreamToBitmap(const unsigned char* uncompressedSt
ream, size_t uncompressedStreamLength, | 547 static SkBitmap* transferImageStreamToBitmap(const unsigned char* uncompressedSt
ream, |
522 int width, int height, int bytesPerLine, | 548 size_t uncompressedStreamLength, |
523 int bpc, const SkString& colorSpace, | 549 int width, int height, int bytesPer
Line, |
524 bool transparencyMask) { | 550 int bpc, const SkString& colorSpace
, |
| 551 bool transparencyMask) { |
525 SkBitmap* bitmap = new SkBitmap(); | 552 SkBitmap* bitmap = new SkBitmap(); |
526 | 553 |
527 //int components = GetColorSpaceComponents(colorSpace); | 554 //int components = GetColorSpaceComponents(colorSpace); |
528 //#define MAX_COMPONENTS 10 | 555 //#define MAX_COMPONENTS 10 |
529 | 556 |
530 // TODO(edisonn): assume start of lines are aligned at 32 bits? | 557 // TODO(edisonn): assume start of lines are aligned at 32 bits? |
531 // Is there a faster way to load the uncompressed stream into a bitmap? | 558 // Is there a faster way to load the uncompressed stream into a bitmap? |
532 | 559 |
533 // minimal support for now | 560 // minimal support for now |
534 if ((colorSpace.equals("DeviceRGB") || colorSpace.equals("RGB")) && bpc == 8
) { | 561 if ((colorSpace.equals("DeviceRGB") || colorSpace.equals("RGB")) && bpc == 8
) { |
(...skipping 24 matching lines...) Expand all Loading... |
559 i++; | 586 i++; |
560 } | 587 } |
561 uncompressedStream += bytesPerLine; | 588 uncompressedStream += bytesPerLine; |
562 } | 589 } |
563 | 590 |
564 bitmap->setConfig(transparencyMask ? SkBitmap::kA8_Config : SkBitmap::kI
ndex8_Config, | 591 bitmap->setConfig(transparencyMask ? SkBitmap::kA8_Config : SkBitmap::kI
ndex8_Config, |
565 width, height); | 592 width, height); |
566 bitmap->setPixels(uncompressedStreamA8, transparencyMask ? NULL : getGra
yColortable()); | 593 bitmap->setPixels(uncompressedStreamA8, transparencyMask ? NULL : getGra
yColortable()); |
567 } | 594 } |
568 | 595 |
569 // TODO(edisonn): Report Warning, NYI, or error | 596 // TODO(edisonn): pass color space and context here? |
| 597 SkPdfReport(kCodeWarning_SkPdfIssueSeverity, kNYI_SkPdfIssue, "Color space N
YI", NULL, NULL); |
570 return bitmap; | 598 return bitmap; |
571 } | 599 } |
572 | 600 |
573 // utils | 601 // utils |
574 | 602 |
575 // TODO(edisonn): add cache, or put the bitmap property directly on the PdfObjec
t | 603 // TODO(edisonn): add cache, or put the bitmap property directly on the PdfObjec
t |
576 // TODO(edisonn): deal with colorSpaces, we could add them to SkBitmap::Config | 604 // TODO(edisonn): deal with colorSpaces, we could add them to SkBitmap::Config |
577 // TODO(edisonn): preserve A1 format that skia knows, + fast convert from 111, 2
22, 444 to closest | 605 // TODO(edisonn): preserve A1 format that skia knows, + fast convert from 111, 2
22, 444 to closest |
578 // skia format, through a table | 606 // skia format, through a table |
579 | 607 |
580 // this functions returns the image, it does not look at the smask. | 608 // this functions returns the image, it does not look at the smask. |
581 | 609 |
582 static SkBitmap* getImageFromObjectCore(SkPdfContext* pdfContext, SkPdfImageDict
ionary* image, bool transparencyMask) { | 610 static SkBitmap* getImageFromObjectCore(SkPdfContext* pdfContext, SkPdfImageDict
ionary* image, bool transparencyMask) { |
583 if (image == NULL || !image->hasStream()) { | 611 if (image == NULL || !image->hasStream()) { |
584 // TODO(edisonn): report warning to be used in testing. | 612 SkPdfReportUnexpectedType(kIgnoreError_SkPdfIssueSeverity, "Missing stre
am", image, SkPdfNativeObject::_kStream_PdfObjectType, pdfContext); |
585 return NULL; | 613 return NULL; |
586 } | 614 } |
587 | 615 |
588 int bpc = (int)image->BitsPerComponent(pdfContext->fPdfDoc); | 616 int bpc = (int)image->BitsPerComponent(pdfContext->fPdfDoc); |
589 int width = (int)image->Width(pdfContext->fPdfDoc); | 617 int width = (int)image->Width(pdfContext->fPdfDoc); |
590 int height = (int)image->Height(pdfContext->fPdfDoc); | 618 int height = (int)image->Height(pdfContext->fPdfDoc); |
591 SkString colorSpace("DeviceRGB"); | 619 SkString colorSpace("DeviceRGB"); |
592 | 620 |
593 bool indexed = false; | 621 bool indexed = false; |
594 SkPMColor colors[256]; | 622 SkPMColor colors[256]; |
595 int cnt = 0; | 623 int cnt = 0; |
596 | 624 |
597 // TODO(edisonn): color space can be an array too! | |
598 if (image->isColorSpaceAName(pdfContext->fPdfDoc)) { | 625 if (image->isColorSpaceAName(pdfContext->fPdfDoc)) { |
599 colorSpace = image->getColorSpaceAsName(pdfContext->fPdfDoc); | 626 colorSpace = image->getColorSpaceAsName(pdfContext->fPdfDoc); |
600 } else if (image->isColorSpaceAArray(pdfContext->fPdfDoc)) { | 627 } else if (image->isColorSpaceAArray(pdfContext->fPdfDoc)) { |
601 SkPdfArray* array = image->getColorSpaceAsArray(pdfContext->fPdfDoc); | 628 SkPdfArray* array = image->getColorSpaceAsArray(pdfContext->fPdfDoc); |
602 if (array && array->size() == 4 && array->objAtAIndex(0)->isName("Indexe
d") && | 629 if (array && array->size() == 4 && array->objAtAIndex(0)->isName("Indexe
d") && |
603 (array->objAtAIndex(1)->isName("Devic
eRGB") || array->objAtAIndex(1)->isName("RGB")) && | 630 (array->objAtAIndex(1)->isName("Devic
eRGB") || array->objAtAIndex(1)->isName("RGB")) && |
604 array->objAtAIndex(2)->isInteger() && | 631 array->objAtAIndex(2)->isInteger() && |
605 array->objAtAIndex(3)->isHexString() | 632 array->objAtAIndex(3)->isHexString() |
606 ) { | 633 ) { |
607 // TODO(edisonn): suport only DeviceRGB for now. | 634 SkPdfReport(kCodeWarning_SkPdfIssueSeverity, kNYI_SkPdfIssue, "Color
space NYI", image, pdfContext); |
608 indexed = true; | 635 indexed = true; |
609 cnt = (int)array->objAtAIndex(2)->intValue() + 1; | 636 cnt = (int)array->objAtAIndex(2)->intValue() + 1; |
610 if (cnt > 256) { | 637 if (cnt > 256) { |
611 // TODO(edionn): report NYIs | 638 SkPdfReport(kCodeWarning_SkPdfIssueSeverity, kNYI_SkPdfIssue, "C
olor space feature NYI, cnt > 256", image, pdfContext); |
612 return NULL; | 639 return NULL; |
613 } | 640 } |
614 SkColorTable colorTable(cnt); | 641 SkColorTable colorTable(cnt); |
615 NotOwnedString data = array->objAtAIndex(3)->strRef(); | 642 NotOwnedString data = array->objAtAIndex(3)->strRef(); |
616 if (data.fBytes != (unsigned int)cnt * 3) { | 643 if (data.fBytes != (unsigned int)cnt * 3) { |
617 // TODO(edionn): report error/warning | 644 SkPdfReport(kIgnoreError_SkPdfIssueSeverity, kIncostistentSizes_
SkPdfIssue, "Image color table mismatch color space specs", array, pdfContext); |
618 return NULL; | 645 return NULL; |
619 } | 646 } |
620 for (int i = 0 ; i < cnt; i++) { | 647 for (int i = 0 ; i < cnt; i++) { |
621 colors[i] = SkPreMultiplyARGB(0xff, data.fBuffer[3 * i], data.fB
uffer[3 * i + 1], data.fBuffer[3 * i + 2]); | 648 colors[i] = SkPreMultiplyARGB(0xff, data.fBuffer[3 * i], data.fB
uffer[3 * i + 1], data.fBuffer[3 * i + 2]); |
622 } | 649 } |
623 } | 650 } |
624 } | 651 } |
625 | 652 |
626 /* | 653 /* |
627 bool imageMask = image->imageMask(); | 654 bool imageMask = image->imageMask(); |
628 | 655 |
629 if (imageMask) { | 656 if (imageMask) { |
630 if (bpc != 0 && bpc != 1) { | 657 if (bpc != 0 && bpc != 1) { |
631 // TODO(edisonn): report warning to be used in testing. | 658 // TODO(edisonn): report warning to be used in testing. |
632 return SkBitmap(); | 659 return SkBitmap(); |
633 } | 660 } |
634 bpc = 1; | 661 bpc = 1; |
635 } | 662 } |
636 */ | 663 */ |
637 | 664 |
638 const unsigned char* uncompressedStream = NULL; | 665 const unsigned char* uncompressedStream = NULL; |
639 size_t uncompressedStreamLength = 0; | 666 size_t uncompressedStreamLength = 0; |
640 | 667 |
641 SkPdfStream* stream = (SkPdfStream*)image; | 668 SkPdfStream* stream = (SkPdfStream*)image; |
642 | 669 |
643 if (!stream || !stream->GetFilteredStreamRef(&uncompressedStream, &uncompres
sedStreamLength) || | 670 if (!stream || !stream->GetFilteredStreamRef(&uncompressedStream, &uncompres
sedStreamLength) || |
644 uncompressedStream == NULL || uncompressedStreamLength == 0) { | 671 uncompressedStream == NULL || uncompressedStreamLength == 0) { |
645 // TODO(edisonn): report warning to be used in testing. | 672 SkPdfReportUnexpectedType(kIgnoreError_SkPdfIssueSeverity, "Missing stre
am", stream, SkPdfNativeObject::_kStream_PdfObjectType, pdfContext); |
646 return NULL; | 673 return NULL; |
647 } | 674 } |
648 | 675 |
649 SkPdfStreamCommonDictionary* streamDict = (SkPdfStreamCommonDictionary*)stre
am; | 676 SkPdfStreamCommonDictionary* streamDict = (SkPdfStreamCommonDictionary*)stre
am; |
650 | 677 |
651 if (streamDict->has_Filter() && ((streamDict->isFilterAName(NULL) && | 678 if (streamDict->has_Filter() && ((streamDict->isFilterAName(NULL) && |
652 streamDict->getFilterAsName(NULL).equa
ls("DCTDecode")) || | 679 streamDict->getFilterAsName(NULL).equa
ls("DCTDecode")) || |
653 (streamDict->isFilterAArray(NULL) && | 680 (streamDict->isFilterAArray(NULL) && |
654 streamDict->getFilterAsArray(NULL)->si
ze() > 0 && | 681 streamDict->getFilterAsArray(NULL)->si
ze() > 0 && |
655 streamDict->getFilterAsArray(NULL)->ob
jAtAIndex(0)->isName() && | 682 streamDict->getFilterAsArray(NULL)->ob
jAtAIndex(0)->isName() && |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
711 } | 738 } |
712 | 739 |
713 static SkBitmap* getSmaskFromObject(SkPdfContext* pdfContext, SkPdfImageDictiona
ry* obj) { | 740 static SkBitmap* getSmaskFromObject(SkPdfContext* pdfContext, SkPdfImageDictiona
ry* obj) { |
714 SkPdfImageDictionary* sMask = obj->SMask(pdfContext->fPdfDoc); | 741 SkPdfImageDictionary* sMask = obj->SMask(pdfContext->fPdfDoc); |
715 | 742 |
716 if (sMask) { | 743 if (sMask) { |
717 return getImageFromObject(pdfContext, sMask, true); | 744 return getImageFromObject(pdfContext, sMask, true); |
718 } | 745 } |
719 | 746 |
720 // TODO(edisonn): implement GS SMask. Default to empty right now. | 747 // TODO(edisonn): implement GS SMask. Default to empty right now. |
| 748 SkPdfReport(kCodeWarning_SkPdfIssueSeverity, kNYI_SkPdfIssue, "implement GS
SMask. Default to empty right now.", obj, pdfContext); |
| 749 |
721 return pdfContext->fGraphicsState.fSMask; | 750 return pdfContext->fGraphicsState.fSMask; |
722 } | 751 } |
723 | 752 |
724 static SkPdfResult doXObject_Image(SkPdfContext* pdfContext, SkCanvas* canvas, S
kPdfImageDictionary* skpdfimage) { | 753 static SkPdfResult doXObject_Image(SkPdfContext* pdfContext, SkCanvas* canvas, S
kPdfImageDictionary* skpdfimage) { |
725 if (skpdfimage == NULL) { | 754 if (skpdfimage == NULL) { |
726 return kIgnoreError_SkPdfResult; | 755 return kIgnoreError_SkPdfResult; |
727 } | 756 } |
728 | 757 |
729 SkBitmap* image = getImageFromObject(pdfContext, skpdfimage, false); | 758 SkBitmap* image = getImageFromObject(pdfContext, skpdfimage, false); |
730 SkBitmap* sMask = getSmaskFromObject(pdfContext, skpdfimage); | 759 SkBitmap* sMask = getSmaskFromObject(pdfContext, skpdfimage); |
(...skipping 18 matching lines...) Expand all Loading... |
749 printf("IMAGE rect = "); | 778 printf("IMAGE rect = "); |
750 for (int i = 0; i < 4; i++) { | 779 for (int i = 0; i < 4; i++) { |
751 printf("(%f %f) ", SkScalarToDouble(final[i].x()), SkScalarToDouble(fina
l[i].y())); | 780 printf("(%f %f) ", SkScalarToDouble(final[i].x()), SkScalarToDouble(fina
l[i].y())); |
752 } | 781 } |
753 printf("\n"); | 782 printf("\n"); |
754 #endif // PDF_TRACE | 783 #endif // PDF_TRACE |
755 | 784 |
756 SkRect dst = SkRect::MakeXYWH(SkDoubleToScalar(0.0), SkDoubleToScalar(0.0),
SkDoubleToScalar(1.0), SkDoubleToScalar(1.0)); | 785 SkRect dst = SkRect::MakeXYWH(SkDoubleToScalar(0.0), SkDoubleToScalar(0.0),
SkDoubleToScalar(1.0), SkDoubleToScalar(1.0)); |
757 | 786 |
758 // TODO(edisonn): soft mask type? alpha/luminosity. | 787 // TODO(edisonn): soft mask type? alpha/luminosity. |
| 788 SkPdfReport(kCodeWarning_SkPdfIssueSeverity, kNYI_SkPdfIssue, "implement sof
t mask type", skpdfimage, pdfContext); |
| 789 |
759 SkPaint paint; | 790 SkPaint paint; |
760 pdfContext->fGraphicsState.applyGraphicsState(&paint, false); | 791 pdfContext->fGraphicsState.applyGraphicsState(&paint, false); |
761 | 792 |
762 if (!sMask || sMask->empty()) { | 793 if (!sMask || sMask->empty()) { |
763 canvas->drawBitmapRect(*image, dst, &paint); | 794 canvas->drawBitmapRect(*image, dst, &paint); |
764 } else { | 795 } else { |
765 canvas->saveLayer(&dst, &paint); | 796 canvas->saveLayer(&dst, &paint); |
766 canvas->drawBitmapRect(*image, dst, NULL); | 797 canvas->drawBitmapRect(*image, dst, NULL); |
767 SkPaint xfer; | 798 SkPaint xfer; |
768 // TODO(edisonn): is the blend mode specified already implicitly/explici
tly in pdf? | 799 // TODO(edisonn): is the blend mode specified already implicitly/explici
tly in pdf? |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
811 } | 842 } |
812 | 843 |
813 // TODO(edisonn): non isolation implemented in skia | 844 // TODO(edisonn): non isolation implemented in skia |
814 //static void doGroup_after(SkPdfContext* pdfContext, SkCanvas* canvas, SkRect b
box, SkPdfTransparencyGroupDictionary* tgroup) { | 845 //static void doGroup_after(SkPdfContext* pdfContext, SkCanvas* canvas, SkRect b
box, SkPdfTransparencyGroupDictionary* tgroup) { |
815 // if not isolated | 846 // if not isolated |
816 // canvas->drawBitmapRect(backdrop, bboxOrig, NULL); | 847 // canvas->drawBitmapRect(backdrop, bboxOrig, NULL); |
817 //} | 848 //} |
818 | 849 |
819 static SkPdfResult doXObject_Form(SkPdfContext* pdfContext, SkCanvas* canvas, Sk
PdfType1FormDictionary* skobj) { | 850 static SkPdfResult doXObject_Form(SkPdfContext* pdfContext, SkCanvas* canvas, Sk
PdfType1FormDictionary* skobj) { |
820 if (!skobj || !skobj->hasStream()) { | 851 if (!skobj || !skobj->hasStream()) { |
| 852 SkPdfReportUnexpectedType(kIgnoreError_SkPdfIssueSeverity, "Missing stre
am", skobj, SkPdfNativeObject::_kStream_PdfObjectType, pdfContext); |
821 return kIgnoreError_SkPdfResult; | 853 return kIgnoreError_SkPdfResult; |
822 } | 854 } |
823 | 855 |
824 if (!skobj->has_BBox()) { | 856 if (!skobj->has_BBox()) { |
| 857 SkPdfReport(kIgnoreError_SkPdfIssueSeverity, kMissingRequiredKey_SkPdfIs
sue, "BBox", skobj, pdfContext); |
825 return kIgnoreError_SkPdfResult; | 858 return kIgnoreError_SkPdfResult; |
826 } | 859 } |
827 | 860 |
828 PdfOp_q(pdfContext, canvas, NULL); | 861 PdfOp_q(pdfContext, canvas, NULL); |
829 | 862 |
830 | 863 |
831 if (skobj->Resources(pdfContext->fPdfDoc)) { | 864 if (skobj->Resources(pdfContext->fPdfDoc)) { |
832 pdfContext->fGraphicsState.fResources = skobj->Resources(pdfContext->fPd
fDoc); | 865 pdfContext->fGraphicsState.fResources = skobj->Resources(pdfContext->fPd
fDoc); |
833 } | 866 } |
834 | 867 |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
878 } | 911 } |
879 | 912 |
880 PdfOp_Q(pdfContext, canvas, NULL); | 913 PdfOp_Q(pdfContext, canvas, NULL); |
881 return kPartial_SkPdfResult; | 914 return kPartial_SkPdfResult; |
882 } | 915 } |
883 | 916 |
884 | 917 |
885 // TODO(edisonn): Extract a class like ObjWithStream | 918 // TODO(edisonn): Extract a class like ObjWithStream |
886 static SkPdfResult doXObject_Pattern(SkPdfContext* pdfContext, SkCanvas* canvas,
SkPdfType1PatternDictionary* skobj) { | 919 static SkPdfResult doXObject_Pattern(SkPdfContext* pdfContext, SkCanvas* canvas,
SkPdfType1PatternDictionary* skobj) { |
887 if (!skobj || !skobj->hasStream()) { | 920 if (!skobj || !skobj->hasStream()) { |
| 921 SkPdfReportUnexpectedType(kIgnoreError_SkPdfIssueSeverity, "Missing stre
am", skobj, SkPdfNativeObject::_kStream_PdfObjectType, pdfContext); |
888 return kIgnoreError_SkPdfResult; | 922 return kIgnoreError_SkPdfResult; |
889 } | 923 } |
890 | 924 |
891 if (!skobj->has_BBox()) { | 925 if (!skobj->has_BBox()) { |
| 926 SkPdfReport(kIgnoreError_SkPdfIssueSeverity, kMissingRequiredKey_SkPdfIs
sue, "BBox", skobj, pdfContext); |
892 return kIgnoreError_SkPdfResult; | 927 return kIgnoreError_SkPdfResult; |
893 } | 928 } |
894 | 929 |
895 PdfOp_q(pdfContext, canvas, NULL); | 930 PdfOp_q(pdfContext, canvas, NULL); |
896 | 931 |
897 | 932 |
898 if (skobj->Resources(pdfContext->fPdfDoc)) { | 933 if (skobj->Resources(pdfContext->fPdfDoc)) { |
899 pdfContext->fGraphicsState.fResources = skobj->Resources(pdfContext->fPd
fDoc); | 934 pdfContext->fGraphicsState.fResources = skobj->Resources(pdfContext->fPd
fDoc); |
900 } | 935 } |
901 | 936 |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
933 return kPartial_SkPdfResult; | 968 return kPartial_SkPdfResult; |
934 } | 969 } |
935 | 970 |
936 | 971 |
937 //static SkPdfResult doXObject_PS(SkPdfContext* pdfContext, SkCanvas* canvas, co
nst SkPdfNativeObject* obj) { | 972 //static SkPdfResult doXObject_PS(SkPdfContext* pdfContext, SkCanvas* canvas, co
nst SkPdfNativeObject* obj) { |
938 // return kNYI_SkPdfResult; | 973 // return kNYI_SkPdfResult; |
939 //} | 974 //} |
940 | 975 |
941 SkPdfResult doType3Char(SkPdfContext* pdfContext, SkCanvas* canvas, const SkPdfN
ativeObject* skobj, SkRect bBox, SkMatrix matrix, double textSize) { | 976 SkPdfResult doType3Char(SkPdfContext* pdfContext, SkCanvas* canvas, const SkPdfN
ativeObject* skobj, SkRect bBox, SkMatrix matrix, double textSize) { |
942 if (!skobj || !skobj->hasStream()) { | 977 if (!skobj || !skobj->hasStream()) { |
| 978 SkPdfReportUnexpectedType(kIgnoreError_SkPdfIssueSeverity, "Missing stre
am", skobj, SkPdfNativeObject::_kStream_PdfObjectType, pdfContext); |
943 return kIgnoreError_SkPdfResult; | 979 return kIgnoreError_SkPdfResult; |
944 } | 980 } |
945 | 981 |
946 PdfOp_q(pdfContext, canvas, NULL); | 982 PdfOp_q(pdfContext, canvas, NULL); |
947 | 983 |
948 pdfContext->fGraphicsState.fMatrixTm.preConcat(matrix); | 984 pdfContext->fGraphicsState.fMatrixTm.preConcat(matrix); |
949 pdfContext->fGraphicsState.fMatrixTm.preScale(SkDoubleToScalar(textSize), Sk
DoubleToScalar(textSize)); | 985 pdfContext->fGraphicsState.fMatrixTm.preScale(SkDoubleToScalar(textSize), Sk
DoubleToScalar(textSize)); |
950 pdfContext->fGraphicsState.fMatrixTlm = pdfContext->fGraphicsState.fMatrixTm
; | 986 pdfContext->fGraphicsState.fMatrixTlm = pdfContext->fGraphicsState.fMatrixTm
; |
951 | 987 |
952 pdfContext->fGraphicsState.fCTM = pdfContext->fGraphicsState.fMatrixTm; | 988 pdfContext->fGraphicsState.fCTM = pdfContext->fGraphicsState.fMatrixTm; |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
996 fObj->doneRendering(); | 1032 fObj->doneRendering(); |
997 } | 1033 } |
998 | 1034 |
999 static bool IsInRendering(const SkPdfNativeObject* obj) { | 1035 static bool IsInRendering(const SkPdfNativeObject* obj) { |
1000 return obj->inRendering(); | 1036 return obj->inRendering(); |
1001 } | 1037 } |
1002 }; | 1038 }; |
1003 | 1039 |
1004 static SkPdfResult doXObject(SkPdfContext* pdfContext, SkCanvas* canvas, SkPdfNa
tiveObject* obj) { | 1040 static SkPdfResult doXObject(SkPdfContext* pdfContext, SkCanvas* canvas, SkPdfNa
tiveObject* obj) { |
1005 if (CheckRecursiveRendering::IsInRendering(obj)) { | 1041 if (CheckRecursiveRendering::IsInRendering(obj)) { |
1006 // Oops, corrupt PDF! | 1042 SkPdfReport(kIgnoreError_SkPdfIssueSeverity, kRecursiveReferencing_SkPdf
Issue, "Recursive reverencing is invalid in draw objects", obj, pdfContext); |
1007 return kIgnoreError_SkPdfResult; | 1043 return kIgnoreError_SkPdfResult; |
1008 } | 1044 } |
1009 | 1045 |
1010 CheckRecursiveRendering checkRecursion(obj); | 1046 CheckRecursiveRendering checkRecursion(obj); |
1011 | 1047 |
1012 switch (pdfContext->fPdfDoc->mapper()->mapXObjectDictionary(obj)) | 1048 switch (pdfContext->fPdfDoc->mapper()->mapXObjectDictionary(obj)) |
1013 { | 1049 { |
1014 case kImageDictionary_SkPdfNativeObjectType: | 1050 case kImageDictionary_SkPdfNativeObjectType: |
1015 return doXObject_Image(pdfContext, canvas, (SkPdfImageDictionary*)ob
j); | 1051 return doXObject_Image(pdfContext, canvas, (SkPdfImageDictionary*)ob
j); |
1016 case kType1FormDictionary_SkPdfNativeObjectType: | 1052 case kType1FormDictionary_SkPdfNativeObjectType: |
1017 return doXObject_Form(pdfContext, canvas, (SkPdfType1FormDictionary*
)obj); | 1053 return doXObject_Form(pdfContext, canvas, (SkPdfType1FormDictionary*
)obj); |
1018 //case kObjectDictionaryXObjectPS_SkPdfNativeObjectType: | 1054 //case kObjectDictionaryXObjectPS_SkPdfNativeObjectType: |
1019 //return doXObject_PS(skxobj.asPS()); | 1055 //return doXObject_PS(skxobj.asPS()); |
1020 default: { | 1056 default: { |
1021 if (pdfContext->fPdfDoc->mapper()->mapType1PatternDictionary(obj) !=
kNone_SkPdfNativeObjectType) { | 1057 if (pdfContext->fPdfDoc->mapper()->mapType1PatternDictionary(obj) !=
kNone_SkPdfNativeObjectType) { |
1022 SkPdfType1PatternDictionary* pattern = (SkPdfType1PatternDiction
ary*)obj; | 1058 SkPdfType1PatternDictionary* pattern = (SkPdfType1PatternDiction
ary*)obj; |
1023 return doXObject_Pattern(pdfContext, canvas, pattern); | 1059 return doXObject_Pattern(pdfContext, canvas, pattern); |
1024 } | 1060 } |
| 1061 SkPdfReport(kCodeWarning_SkPdfIssueSeverity, kNYI_SkPdfIssue, "doXOb
ject", obj, pdfContext); |
1025 } | 1062 } |
1026 } | 1063 } |
1027 return kIgnoreError_SkPdfResult; | 1064 return kIgnoreError_SkPdfResult; |
1028 } | 1065 } |
1029 | 1066 |
1030 static SkPdfResult doPage(SkPdfContext* pdfContext, SkCanvas* canvas, SkPdfPageO
bjectDictionary* skobj) { | 1067 static SkPdfResult doPage(SkPdfContext* pdfContext, SkCanvas* canvas, SkPdfPageO
bjectDictionary* skobj) { |
1031 if (!skobj) { | 1068 if (!skobj || !skobj->isContentsAStream(pdfContext->fPdfDoc)) { |
1032 return kIgnoreError_SkPdfResult; | 1069 SkPdfReportUnexpectedType(kIgnoreError_SkPdfIssueSeverity, "Missing stre
am", skobj, SkPdfNativeObject::_kStream_PdfObjectType, pdfContext); |
1033 } | |
1034 | |
1035 if (!skobj->isContentsAStream(pdfContext->fPdfDoc)) { | |
1036 return kNYI_SkPdfResult; | 1070 return kNYI_SkPdfResult; |
1037 } | 1071 } |
1038 | 1072 |
1039 SkPdfStream* stream = skobj->getContentsAsStream(pdfContext->fPdfDoc); | 1073 SkPdfStream* stream = skobj->getContentsAsStream(pdfContext->fPdfDoc); |
1040 | 1074 |
1041 if (!stream) { | 1075 if (!stream) { |
| 1076 SkPdfReportUnexpectedType(kIgnoreError_SkPdfIssueSeverity, "Missing stre
am", skobj, SkPdfNativeObject::_kStream_PdfObjectType, pdfContext); |
1042 return kIgnoreError_SkPdfResult; | 1077 return kIgnoreError_SkPdfResult; |
1043 } | 1078 } |
1044 | 1079 |
1045 pdfContext->fGraphicsState.fResources = skobj->Resources(pdfContext->fPdfDoc
); | 1080 pdfContext->fGraphicsState.fResources = skobj->Resources(pdfContext->fPdfDoc
); |
1046 | 1081 |
1047 if (!pdfContext->fGraphicsState.fResources) { | 1082 if (!pdfContext->fGraphicsState.fResources) { |
1048 return kIgnoreError_SkPdfResult; // probably it is null because we have
not implemented yet inheritance | 1083 return kIgnoreError_SkPdfResult; // probably it is null because we have
not implemented yet inheritance |
1049 } | 1084 } |
1050 | 1085 |
1051 if (CheckRecursiveRendering::IsInRendering(skobj)) { | 1086 if (CheckRecursiveRendering::IsInRendering(skobj)) { |
1052 // Oops, corrupt PDF! | 1087 SkPdfReport(kIgnoreError_SkPdfIssueSeverity, kRecursiveReferencing_SkPdf
Issue, "Recursive reverencing is invalid in draw objects", skobj, pdfContext); |
1053 return kIgnoreError_SkPdfResult; | 1088 return kIgnoreError_SkPdfResult; |
1054 } | 1089 } |
1055 CheckRecursiveRendering checkRecursion(skobj); | 1090 CheckRecursiveRendering checkRecursion(skobj); |
1056 | 1091 |
1057 | 1092 |
1058 PdfOp_q(pdfContext, canvas, NULL); | 1093 PdfOp_q(pdfContext, canvas, NULL); |
1059 | 1094 |
1060 // TODO(edisonn): MediaBox can be inherited!!!! | 1095 // TODO(edisonn): MediaBox can be inherited!!!! |
| 1096 SkPdfReport(kCodeWarning_SkPdfIssueSeverity, kNYI_SkPdfIssue, "MediaBox inhe
ritance NYI", NULL, pdfContext); |
| 1097 |
1061 SkRect bbox = skobj->MediaBox(pdfContext->fPdfDoc); | 1098 SkRect bbox = skobj->MediaBox(pdfContext->fPdfDoc); |
1062 if (skobj->has_Group()) { | 1099 if (skobj->has_Group()) { |
1063 SkPdfTransparencyGroupDictionary* tgroup = skobj->Group(pdfContext->fPdf
Doc); | 1100 SkPdfTransparencyGroupDictionary* tgroup = skobj->Group(pdfContext->fPdf
Doc); |
1064 doGroup_before(pdfContext, canvas, bbox, tgroup, true); | 1101 doGroup_before(pdfContext, canvas, bbox, tgroup, true); |
1065 } else { | 1102 } else { |
1066 canvas->save(); | 1103 canvas->save(); |
1067 } | 1104 } |
1068 | 1105 |
1069 | 1106 |
1070 SkPdfNativeTokenizer* tokenizer = | 1107 SkPdfNativeTokenizer* tokenizer = |
(...skipping 19 matching lines...) Expand all Loading... |
1090 pdfContext->fObjectStack.nest(); | 1127 pdfContext->fObjectStack.nest(); |
1091 return kOK_SkPdfResult; | 1128 return kOK_SkPdfResult; |
1092 } | 1129 } |
1093 | 1130 |
1094 SkPdfResult PdfOp_Q(SkPdfContext* pdfContext, SkCanvas* canvas, PdfTokenLooper**
looper) { | 1131 SkPdfResult PdfOp_Q(SkPdfContext* pdfContext, SkCanvas* canvas, PdfTokenLooper**
looper) { |
1095 if (pdfContext->fStateStack.count() > 0) { | 1132 if (pdfContext->fStateStack.count() > 0) { |
1096 pdfContext->fGraphicsState = pdfContext->fStateStack.top(); | 1133 pdfContext->fGraphicsState = pdfContext->fStateStack.top(); |
1097 pdfContext->fStateStack.pop(); | 1134 pdfContext->fStateStack.pop(); |
1098 canvas->restore(); | 1135 canvas->restore(); |
1099 | 1136 |
1100 if (pdfContext->fObjectStack.nests() <= 0) { | 1137 if (pdfContext->fObjectStack.nests() == 0) { |
| 1138 SkPdfReport(kIgnoreError_SkPdfIssueSeverity, kStackNestingOverflow_S
kPdfIssue, "stack nesting overflow (q/Q)", NULL, pdfContext); |
1101 return kIgnoreError_SkPdfResult; | 1139 return kIgnoreError_SkPdfResult; |
1102 } else { | 1140 } else { |
1103 pdfContext->fObjectStack.unnest(); | 1141 pdfContext->fObjectStack.unnest(); |
1104 } | 1142 } |
1105 } else { | 1143 } else { |
| 1144 SkPdfReport(kIgnoreError_SkPdfIssueSeverity, kStackOverflow_SkPdfIssue,
"stack overflow (q/Q)", NULL, pdfContext); |
1106 return kIgnoreError_SkPdfResult; | 1145 return kIgnoreError_SkPdfResult; |
1107 } | 1146 } |
1108 | 1147 |
1109 return kOK_SkPdfResult; | 1148 return kOK_SkPdfResult; |
1110 } | 1149 } |
1111 | 1150 |
1112 static SkPdfResult PdfOp_cm(SkPdfContext* pdfContext, SkCanvas* canvas, PdfToken
Looper** looper) { | 1151 static SkPdfResult PdfOp_cm(SkPdfContext* pdfContext, SkCanvas* canvas, PdfToken
Looper** looper) { |
1113 EXPECT_OPERANDS(pdfContext, 6); | 1152 EXPECT_OPERANDS("cm", pdfContext, 6); |
1114 POP_NUMBER(pdfContext, f); | 1153 POP_NUMBER(pdfContext, f); |
1115 POP_NUMBER(pdfContext, e); | 1154 POP_NUMBER(pdfContext, e); |
1116 POP_NUMBER(pdfContext, d); | 1155 POP_NUMBER(pdfContext, d); |
1117 POP_NUMBER(pdfContext, c); | 1156 POP_NUMBER(pdfContext, c); |
1118 POP_NUMBER(pdfContext, b); | 1157 POP_NUMBER(pdfContext, b); |
1119 POP_NUMBER(pdfContext, a); | 1158 POP_NUMBER(pdfContext, a); |
1120 CHECK_PARAMETERS(); | 1159 CHECK_PARAMETERS(); |
1121 double array[6] = {a, b, c, d, e, f}; | 1160 double array[6] = {a, b, c, d, e, f}; |
1122 | 1161 |
1123 // a b | 1162 // a b |
(...skipping 20 matching lines...) Expand all Loading... |
1144 SkTraceMatrix(pdfContext->fGraphicsState.fCTM, "cm"); | 1183 SkTraceMatrix(pdfContext->fGraphicsState.fCTM, "cm"); |
1145 #endif | 1184 #endif |
1146 | 1185 |
1147 return kOK_SkPdfResult; | 1186 return kOK_SkPdfResult; |
1148 } | 1187 } |
1149 | 1188 |
1150 //leading TL Set the text leading, Tl | 1189 //leading TL Set the text leading, Tl |
1151 //, to leading, which is a number expressed in unscaled text | 1190 //, to leading, which is a number expressed in unscaled text |
1152 //space units. Text leading is used only by the T*, ', and " operators. Initial
value: 0. | 1191 //space units. Text leading is used only by the T*, ', and " operators. Initial
value: 0. |
1153 static SkPdfResult PdfOp_TL(SkPdfContext* pdfContext, SkCanvas* canvas, PdfToken
Looper** looper) { | 1192 static SkPdfResult PdfOp_TL(SkPdfContext* pdfContext, SkCanvas* canvas, PdfToken
Looper** looper) { |
1154 EXPECT_OPERANDS(pdfContext, 1) | 1193 EXPECT_OPERANDS("TL", pdfContext, 1); |
1155 POP_NUMBER(pdfContext, ty); | 1194 POP_NUMBER(pdfContext, ty); |
1156 CHECK_PARAMETERS(); | 1195 CHECK_PARAMETERS(); |
1157 | 1196 |
1158 pdfContext->fGraphicsState.fTextLeading = ty; | 1197 pdfContext->fGraphicsState.fTextLeading = ty; |
1159 | 1198 |
1160 return kOK_SkPdfResult; | 1199 return kOK_SkPdfResult; |
1161 } | 1200 } |
1162 | 1201 |
1163 static SkPdfResult PdfOp_Td(SkPdfContext* pdfContext, SkCanvas* canvas, PdfToken
Looper** looper) { | 1202 static SkPdfResult PdfOp_Td(SkPdfContext* pdfContext, SkCanvas* canvas, PdfToken
Looper** looper) { |
1164 EXPECT_OPERANDS(pdfContext, 2); | 1203 EXPECT_OPERANDS("Td", pdfContext, 2); |
1165 POP_NUMBER(pdfContext, ty); | 1204 POP_NUMBER(pdfContext, ty); |
1166 POP_NUMBER(pdfContext, tx); | 1205 POP_NUMBER(pdfContext, tx); |
1167 CHECK_PARAMETERS(); | 1206 CHECK_PARAMETERS(); |
1168 | 1207 |
1169 double array[6] = {1, 0, 0, 1, tx, -ty}; | 1208 double array[6] = {1, 0, 0, 1, tx, -ty}; |
1170 SkMatrix matrix = SkMatrixFromPdfMatrix(array); | 1209 SkMatrix matrix = SkMatrixFromPdfMatrix(array); |
1171 | 1210 |
1172 pdfContext->fGraphicsState.fMatrixTm.preConcat(matrix); | 1211 pdfContext->fGraphicsState.fMatrixTm.preConcat(matrix); |
1173 pdfContext->fGraphicsState.fMatrixTlm.preConcat(matrix); | 1212 pdfContext->fGraphicsState.fMatrixTlm.preConcat(matrix); |
1174 | 1213 |
1175 return kPartial_SkPdfResult; | 1214 return kPartial_SkPdfResult; |
1176 } | 1215 } |
1177 | 1216 |
1178 static SkPdfResult PdfOp_TD(SkPdfContext* pdfContext, SkCanvas* canvas, PdfToken
Looper** looper) { | 1217 static SkPdfResult PdfOp_TD(SkPdfContext* pdfContext, SkCanvas* canvas, PdfToken
Looper** looper) { |
1179 EXPECT_OPERANDS(pdfContext, 2) | 1218 EXPECT_OPERANDS("TD", pdfContext, 2) |
1180 POP_NUMBER(pdfContext, ty); | 1219 POP_NUMBER(pdfContext, ty); |
1181 POP_NUMBER(pdfContext, tx); | 1220 POP_NUMBER(pdfContext, tx); |
1182 CHECK_PARAMETERS(); | 1221 CHECK_PARAMETERS(); |
1183 | 1222 |
1184 // TODO(edisonn): Create factory methods or constructors so native is hidden | 1223 // TODO(edisonn): Create factory methods or constructors so native is hidden |
1185 SkPdfReal* _ty = pdfContext->fPdfDoc->createReal(-ty); | 1224 SkPdfReal* _ty = pdfContext->fPdfDoc->createReal(-ty); |
1186 pdfContext->fObjectStack.push(_ty); | 1225 pdfContext->fObjectStack.push(_ty); |
1187 | 1226 |
1188 PdfOp_TL(pdfContext, canvas, looper); | 1227 PdfOp_TL(pdfContext, canvas, looper); |
1189 | 1228 |
1190 SkPdfReal* vtx = pdfContext->fPdfDoc->createReal(tx); | 1229 SkPdfReal* vtx = pdfContext->fPdfDoc->createReal(tx); |
1191 pdfContext->fObjectStack.push(vtx); | 1230 pdfContext->fObjectStack.push(vtx); |
1192 | 1231 |
1193 SkPdfReal* vty = pdfContext->fPdfDoc->createReal(ty); | 1232 SkPdfReal* vty = pdfContext->fPdfDoc->createReal(ty); |
1194 pdfContext->fObjectStack.push(vty); | 1233 pdfContext->fObjectStack.push(vty); |
1195 | 1234 |
1196 SkPdfResult ret = PdfOp_Td(pdfContext, canvas, looper); | 1235 SkPdfResult ret = PdfOp_Td(pdfContext, canvas, looper); |
1197 | 1236 |
1198 // TODO(edisonn): delete all the objects after rendering was complete, in th
is way pdf is rendered faster | 1237 // TODO(edisonn): delete all the objects after rendering was complete, in th
is way pdf is rendered faster |
1199 // and the cleanup can happen while the user looks at the image | 1238 // and the cleanup can happen while the user looks at the image |
1200 | 1239 |
1201 return ret; | 1240 return ret; |
1202 } | 1241 } |
1203 | 1242 |
1204 static SkPdfResult PdfOp_Tm(SkPdfContext* pdfContext, SkCanvas* canvas, PdfToken
Looper** looper) { | 1243 static SkPdfResult PdfOp_Tm(SkPdfContext* pdfContext, SkCanvas* canvas, PdfToken
Looper** looper) { |
1205 EXPECT_OPERANDS(pdfContext, 6); | 1244 EXPECT_OPERANDS("Tm", pdfContext, 6); |
1206 POP_NUMBER(pdfContext, f); | 1245 POP_NUMBER(pdfContext, f); |
1207 POP_NUMBER(pdfContext, e); | 1246 POP_NUMBER(pdfContext, e); |
1208 POP_NUMBER(pdfContext, d); | 1247 POP_NUMBER(pdfContext, d); |
1209 POP_NUMBER(pdfContext, c); | 1248 POP_NUMBER(pdfContext, c); |
1210 POP_NUMBER(pdfContext, b); | 1249 POP_NUMBER(pdfContext, b); |
1211 POP_NUMBER(pdfContext, a); | 1250 POP_NUMBER(pdfContext, a); |
1212 CHECK_PARAMETERS(); | 1251 CHECK_PARAMETERS(); |
1213 | 1252 |
1214 double array[6]; | 1253 double array[6]; |
1215 array[0] = a; | 1254 array[0] = a; |
1216 array[1] = b; | 1255 array[1] = b; |
1217 array[2] = c; | 1256 array[2] = c; |
1218 array[3] = d; | 1257 array[3] = d; |
1219 array[4] = e; | 1258 array[4] = e; |
1220 array[5] = f; | 1259 array[5] = f; |
1221 | 1260 |
1222 SkMatrix matrix = SkMatrixFromPdfMatrix(array); | 1261 SkMatrix matrix = SkMatrixFromPdfMatrix(array); |
1223 matrix.postConcat(pdfContext->fGraphicsState.fCTM); | 1262 matrix.postConcat(pdfContext->fGraphicsState.fCTM); |
1224 matrix.preScale(SkDoubleToScalar(1), SkDoubleToScalar(-1)); | 1263 matrix.preScale(SkDoubleToScalar(1), SkDoubleToScalar(-1)); |
1225 | 1264 |
1226 // TODO(edisonn): Text positioning. | 1265 // TODO(edisonn): Text positioning. |
| 1266 SkPdfReport(kCodeWarning_SkPdfIssueSeverity, kNYI_SkPdfIssue, "Text position
ing not implemented for 2+ chars", NULL, pdfContext); |
| 1267 |
1227 pdfContext->fGraphicsState.fMatrixTm = matrix; | 1268 pdfContext->fGraphicsState.fMatrixTm = matrix; |
1228 pdfContext->fGraphicsState.fMatrixTlm = matrix;; | 1269 pdfContext->fGraphicsState.fMatrixTlm = matrix;; |
1229 | 1270 |
1230 return kPartial_SkPdfResult; | 1271 return kPartial_SkPdfResult; |
1231 } | 1272 } |
1232 | 1273 |
1233 //— T* Move to the start of the next line. This operator has the same effect as
the code | 1274 //— T* Move to the start of the next line. This operator has the same effect as
the code |
1234 //0 Tl Td | 1275 //0 Tl Td |
1235 //where Tl is the current leading parameter in the text state | 1276 //where Tl is the current leading parameter in the text state |
1236 static SkPdfResult PdfOp_T_star(SkPdfContext* pdfContext, SkCanvas* canvas, PdfT
okenLooper** looper) { | 1277 static SkPdfResult PdfOp_T_star(SkPdfContext* pdfContext, SkCanvas* canvas, PdfT
okenLooper** looper) { |
1237 SkPdfReal* zero = pdfContext->fPdfDoc->createReal(0.0); | 1278 SkPdfReal* zero = pdfContext->fPdfDoc->createReal(0.0); |
1238 SkPdfReal* tl = pdfContext->fPdfDoc->createReal(pdfContext->fGraphicsState.f
TextLeading); | 1279 SkPdfReal* tl = pdfContext->fPdfDoc->createReal(pdfContext->fGraphicsState.f
TextLeading); |
1239 | 1280 |
1240 pdfContext->fObjectStack.push(zero); | 1281 pdfContext->fObjectStack.push(zero); |
1241 pdfContext->fObjectStack.push(tl); | 1282 pdfContext->fObjectStack.push(tl); |
1242 | 1283 |
1243 SkPdfResult ret = PdfOp_Td(pdfContext, canvas, looper); | 1284 SkPdfResult ret = PdfOp_Td(pdfContext, canvas, looper); |
1244 | 1285 |
1245 return ret; | 1286 return ret; |
1246 } | 1287 } |
1247 | 1288 |
1248 static SkPdfResult PdfOp_m(SkPdfContext* pdfContext, SkCanvas* canvas, PdfTokenL
ooper** looper) { | 1289 static SkPdfResult PdfOp_m(SkPdfContext* pdfContext, SkCanvas* canvas, PdfTokenL
ooper** looper) { |
1249 if (pdfContext->fGraphicsState.fPathClosed) { | 1290 if (pdfContext->fGraphicsState.fPathClosed) { |
1250 pdfContext->fGraphicsState.fPath.reset(); | 1291 pdfContext->fGraphicsState.fPath.reset(); |
1251 pdfContext->fGraphicsState.fPathClosed = false; | 1292 pdfContext->fGraphicsState.fPathClosed = false; |
1252 } | 1293 } |
1253 | 1294 |
1254 EXPECT_OPERANDS(pdfContext, 2); | 1295 EXPECT_OPERANDS("m", pdfContext, 2); |
1255 POP_NUMBER(pdfContext, y); | 1296 POP_NUMBER(pdfContext, y); |
1256 POP_NUMBER(pdfContext, x); | 1297 POP_NUMBER(pdfContext, x); |
1257 CHECK_PARAMETERS(); | 1298 CHECK_PARAMETERS(); |
1258 | 1299 |
1259 pdfContext->fGraphicsState.fCurPosY = y; | 1300 pdfContext->fGraphicsState.fCurPosY = y; |
1260 pdfContext->fGraphicsState.fCurPosX = x; | 1301 pdfContext->fGraphicsState.fCurPosX = x; |
1261 | 1302 |
1262 pdfContext->fGraphicsState.fPath.moveTo(SkDoubleToScalar(pdfContext->fGraphi
csState.fCurPosX), | 1303 pdfContext->fGraphicsState.fPath.moveTo(SkDoubleToScalar(pdfContext->fGraphi
csState.fCurPosX), |
1263 SkDoubleToScalar(pdfContext->fGraphi
csState.fCurPosY)); | 1304 SkDoubleToScalar(pdfContext->fGraphi
csState.fCurPosY)); |
1264 | 1305 |
1265 return kOK_SkPdfResult; | 1306 return kOK_SkPdfResult; |
1266 } | 1307 } |
1267 | 1308 |
1268 static SkPdfResult PdfOp_l(SkPdfContext* pdfContext, SkCanvas* canvas, PdfTokenL
ooper** looper) { | 1309 static SkPdfResult PdfOp_l(SkPdfContext* pdfContext, SkCanvas* canvas, PdfTokenL
ooper** looper) { |
1269 if (pdfContext->fGraphicsState.fPathClosed) { | 1310 if (pdfContext->fGraphicsState.fPathClosed) { |
1270 pdfContext->fGraphicsState.fPath.reset(); | 1311 pdfContext->fGraphicsState.fPath.reset(); |
1271 pdfContext->fGraphicsState.fPathClosed = false; | 1312 pdfContext->fGraphicsState.fPathClosed = false; |
1272 } | 1313 } |
1273 | 1314 |
1274 EXPECT_OPERANDS(pdfContext, 2); | 1315 EXPECT_OPERANDS("l", pdfContext, 2); |
1275 POP_NUMBER(pdfContext, y); | 1316 POP_NUMBER(pdfContext, y); |
1276 POP_NUMBER(pdfContext, x); | 1317 POP_NUMBER(pdfContext, x); |
1277 CHECK_PARAMETERS(); | 1318 CHECK_PARAMETERS(); |
1278 | 1319 |
1279 pdfContext->fGraphicsState.fCurPosY = y; | 1320 pdfContext->fGraphicsState.fCurPosY = y; |
1280 pdfContext->fGraphicsState.fCurPosX = x; | 1321 pdfContext->fGraphicsState.fCurPosX = x; |
1281 | 1322 |
1282 pdfContext->fGraphicsState.fPath.lineTo(SkDoubleToScalar(pdfContext->fGraphi
csState.fCurPosX), | 1323 pdfContext->fGraphicsState.fPath.lineTo(SkDoubleToScalar(pdfContext->fGraphi
csState.fCurPosX), |
1283 SkDoubleToScalar(pdfContext->fGraphi
csState.fCurPosY)); | 1324 SkDoubleToScalar(pdfContext->fGraphi
csState.fCurPosY)); |
1284 | 1325 |
1285 return kOK_SkPdfResult; | 1326 return kOK_SkPdfResult; |
1286 } | 1327 } |
1287 | 1328 |
1288 static SkPdfResult PdfOp_c(SkPdfContext* pdfContext, SkCanvas* canvas, PdfTokenL
ooper** looper) { | 1329 static SkPdfResult PdfOp_c(SkPdfContext* pdfContext, SkCanvas* canvas, PdfTokenL
ooper** looper) { |
1289 if (pdfContext->fGraphicsState.fPathClosed) { | 1330 if (pdfContext->fGraphicsState.fPathClosed) { |
1290 pdfContext->fGraphicsState.fPath.reset(); | 1331 pdfContext->fGraphicsState.fPath.reset(); |
1291 pdfContext->fGraphicsState.fPathClosed = false; | 1332 pdfContext->fGraphicsState.fPathClosed = false; |
1292 } | 1333 } |
1293 | 1334 |
1294 EXPECT_OPERANDS(pdfContext, 6); | 1335 EXPECT_OPERANDS("c", pdfContext, 6); |
1295 POP_NUMBER(pdfContext, y3); | 1336 POP_NUMBER(pdfContext, y3); |
1296 POP_NUMBER(pdfContext, x3); | 1337 POP_NUMBER(pdfContext, x3); |
1297 POP_NUMBER(pdfContext, y2); | 1338 POP_NUMBER(pdfContext, y2); |
1298 POP_NUMBER(pdfContext, x2); | 1339 POP_NUMBER(pdfContext, x2); |
1299 POP_NUMBER(pdfContext, y1); | 1340 POP_NUMBER(pdfContext, y1); |
1300 POP_NUMBER(pdfContext, x1); | 1341 POP_NUMBER(pdfContext, x1); |
1301 CHECK_PARAMETERS(); | 1342 CHECK_PARAMETERS(); |
1302 | 1343 |
1303 pdfContext->fGraphicsState.fPath.cubicTo(SkDoubleToScalar(x1), SkDoubleToSca
lar(y1), | 1344 pdfContext->fGraphicsState.fPath.cubicTo(SkDoubleToScalar(x1), SkDoubleToSca
lar(y1), |
1304 SkDoubleToScalar(x2), SkDoubleToSca
lar(y2), | 1345 SkDoubleToScalar(x2), SkDoubleToSca
lar(y2), |
1305 SkDoubleToScalar(x3), SkDoubleToSca
lar(y3)); | 1346 SkDoubleToScalar(x3), SkDoubleToSca
lar(y3)); |
1306 | 1347 |
1307 pdfContext->fGraphicsState.fCurPosX = x3; | 1348 pdfContext->fGraphicsState.fCurPosX = x3; |
1308 pdfContext->fGraphicsState.fCurPosY = y3; | 1349 pdfContext->fGraphicsState.fCurPosY = y3; |
1309 | 1350 |
1310 return kOK_SkPdfResult; | 1351 return kOK_SkPdfResult; |
1311 } | 1352 } |
1312 | 1353 |
1313 static SkPdfResult PdfOp_v(SkPdfContext* pdfContext, SkCanvas* canvas, PdfTokenL
ooper** looper) { | 1354 static SkPdfResult PdfOp_v(SkPdfContext* pdfContext, SkCanvas* canvas, PdfTokenL
ooper** looper) { |
1314 if (pdfContext->fGraphicsState.fPathClosed) { | 1355 if (pdfContext->fGraphicsState.fPathClosed) { |
1315 pdfContext->fGraphicsState.fPath.reset(); | 1356 pdfContext->fGraphicsState.fPath.reset(); |
1316 pdfContext->fGraphicsState.fPathClosed = false; | 1357 pdfContext->fGraphicsState.fPathClosed = false; |
1317 } | 1358 } |
1318 | 1359 |
1319 EXPECT_OPERANDS(pdfContext, 4); | 1360 EXPECT_OPERANDS("v", pdfContext, 4); |
1320 POP_NUMBER(pdfContext, y3); | 1361 POP_NUMBER(pdfContext, y3); |
1321 POP_NUMBER(pdfContext, x3); | 1362 POP_NUMBER(pdfContext, x3); |
1322 POP_NUMBER(pdfContext, y2); | 1363 POP_NUMBER(pdfContext, y2); |
1323 POP_NUMBER(pdfContext, x2); | 1364 POP_NUMBER(pdfContext, x2); |
1324 CHECK_PARAMETERS(); | 1365 CHECK_PARAMETERS(); |
1325 | 1366 |
1326 double y1 = pdfContext->fGraphicsState.fCurPosY; | 1367 double y1 = pdfContext->fGraphicsState.fCurPosY; |
1327 double x1 = pdfContext->fGraphicsState.fCurPosX; | 1368 double x1 = pdfContext->fGraphicsState.fCurPosX; |
1328 | 1369 |
1329 pdfContext->fGraphicsState.fPath.cubicTo(SkDoubleToScalar(x1), SkDoubleToSca
lar(y1), | 1370 pdfContext->fGraphicsState.fPath.cubicTo(SkDoubleToScalar(x1), SkDoubleToSca
lar(y1), |
1330 SkDoubleToScalar(x2), SkDoubleToSca
lar(y2), | 1371 SkDoubleToScalar(x2), SkDoubleToSca
lar(y2), |
1331 SkDoubleToScalar(x3), SkDoubleToSca
lar(y3)); | 1372 SkDoubleToScalar(x3), SkDoubleToSca
lar(y3)); |
1332 | 1373 |
1333 pdfContext->fGraphicsState.fCurPosX = x3; | 1374 pdfContext->fGraphicsState.fCurPosX = x3; |
1334 pdfContext->fGraphicsState.fCurPosY = y3; | 1375 pdfContext->fGraphicsState.fCurPosY = y3; |
1335 | 1376 |
1336 return kOK_SkPdfResult; | 1377 return kOK_SkPdfResult; |
1337 } | 1378 } |
1338 | 1379 |
1339 static SkPdfResult PdfOp_y(SkPdfContext* pdfContext, SkCanvas* canvas, PdfTokenL
ooper** looper) { | 1380 static SkPdfResult PdfOp_y(SkPdfContext* pdfContext, SkCanvas* canvas, PdfTokenL
ooper** looper) { |
1340 if (pdfContext->fGraphicsState.fPathClosed) { | 1381 if (pdfContext->fGraphicsState.fPathClosed) { |
1341 pdfContext->fGraphicsState.fPath.reset(); | 1382 pdfContext->fGraphicsState.fPath.reset(); |
1342 pdfContext->fGraphicsState.fPathClosed = false; | 1383 pdfContext->fGraphicsState.fPathClosed = false; |
1343 } | 1384 } |
1344 | 1385 |
1345 EXPECT_OPERANDS(pdfContext, 4); | 1386 EXPECT_OPERANDS("y", pdfContext, 4); |
1346 POP_NUMBER(pdfContext, y3); | 1387 POP_NUMBER(pdfContext, y3); |
1347 POP_NUMBER(pdfContext, x3); | 1388 POP_NUMBER(pdfContext, x3); |
1348 POP_NUMBER(pdfContext, y1); | 1389 POP_NUMBER(pdfContext, y1); |
1349 POP_NUMBER(pdfContext, x1); | 1390 POP_NUMBER(pdfContext, x1); |
1350 CHECK_PARAMETERS(); | 1391 CHECK_PARAMETERS(); |
1351 | 1392 |
1352 double y2 = pdfContext->fGraphicsState.fCurPosY; | 1393 double y2 = pdfContext->fGraphicsState.fCurPosY; |
1353 double x2 = pdfContext->fGraphicsState.fCurPosX; | 1394 double x2 = pdfContext->fGraphicsState.fCurPosX; |
1354 | 1395 |
1355 pdfContext->fGraphicsState.fPath.cubicTo(SkDoubleToScalar(x1), SkDoubleToSca
lar(y1), | 1396 pdfContext->fGraphicsState.fPath.cubicTo(SkDoubleToScalar(x1), SkDoubleToSca
lar(y1), |
1356 SkDoubleToScalar(x2), SkDoubleToSca
lar(y2), | 1397 SkDoubleToScalar(x2), SkDoubleToSca
lar(y2), |
1357 SkDoubleToScalar(x3), SkDoubleToSca
lar(y3)); | 1398 SkDoubleToScalar(x3), SkDoubleToSca
lar(y3)); |
1358 | 1399 |
1359 pdfContext->fGraphicsState.fCurPosX = x3; | 1400 pdfContext->fGraphicsState.fCurPosX = x3; |
1360 pdfContext->fGraphicsState.fCurPosY = y3; | 1401 pdfContext->fGraphicsState.fCurPosY = y3; |
1361 | 1402 |
1362 return kOK_SkPdfResult; | 1403 return kOK_SkPdfResult; |
1363 } | 1404 } |
1364 | 1405 |
1365 static SkPdfResult PdfOp_re(SkPdfContext* pdfContext, SkCanvas* canvas, PdfToken
Looper** looper) { | 1406 static SkPdfResult PdfOp_re(SkPdfContext* pdfContext, SkCanvas* canvas, PdfToken
Looper** looper) { |
1366 if (pdfContext->fGraphicsState.fPathClosed) { | 1407 if (pdfContext->fGraphicsState.fPathClosed) { |
1367 pdfContext->fGraphicsState.fPath.reset(); | 1408 pdfContext->fGraphicsState.fPath.reset(); |
1368 pdfContext->fGraphicsState.fPathClosed = false; | 1409 pdfContext->fGraphicsState.fPathClosed = false; |
1369 } | 1410 } |
1370 | 1411 |
1371 EXPECT_OPERANDS(pdfContext, 4); | 1412 EXPECT_OPERANDS("re", pdfContext, 4); |
1372 POP_NUMBER(pdfContext, height); | 1413 POP_NUMBER(pdfContext, height); |
1373 POP_NUMBER(pdfContext, width); | 1414 POP_NUMBER(pdfContext, width); |
1374 POP_NUMBER(pdfContext, y); | 1415 POP_NUMBER(pdfContext, y); |
1375 POP_NUMBER(pdfContext, x); | 1416 POP_NUMBER(pdfContext, x); |
1376 CHECK_PARAMETERS(); | 1417 CHECK_PARAMETERS(); |
1377 | 1418 |
1378 pdfContext->fGraphicsState.fPath.addRect(SkDoubleToScalar(x), SkDoubleToScal
ar(y), | 1419 pdfContext->fGraphicsState.fPath.addRect(SkDoubleToScalar(x), SkDoubleToScal
ar(y), |
1379 SkDoubleToScalar(x + width), SkDoub
leToScalar(y + height)); | 1420 SkDoubleToScalar(x + width), SkDoub
leToScalar(y + height)); |
1380 | 1421 |
1381 pdfContext->fGraphicsState.fCurPosX = x; | 1422 pdfContext->fGraphicsState.fCurPosX = x; |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1428 SkPdfType1PatternDictionary* pattern = (SkPdfType1PatternDic
tionary*)pdfContext->fGraphicsState.fNonStroking.fPattern; | 1469 SkPdfType1PatternDictionary* pattern = (SkPdfType1PatternDic
tionary*)pdfContext->fGraphicsState.fNonStroking.fPattern; |
1429 | 1470 |
1430 // TODO(edisonn): constants | 1471 // TODO(edisonn): constants |
1431 // TODO(edisonn): colored | 1472 // TODO(edisonn): colored |
1432 if (pattern->PaintType(pdfContext->fPdfDoc) == 1) { | 1473 if (pattern->PaintType(pdfContext->fPdfDoc) == 1) { |
1433 // TODO(edisonn): don't use abs, iterate as asked, if th
e cells intersect | 1474 // TODO(edisonn): don't use abs, iterate as asked, if th
e cells intersect |
1434 // it will change the result iterating in reverse | 1475 // it will change the result iterating in reverse |
1435 int xStep = abs((int)pattern->XStep(pdfContext->fPdfDoc)
); | 1476 int xStep = abs((int)pattern->XStep(pdfContext->fPdfDoc)
); |
1436 int yStep = abs((int)pattern->YStep(pdfContext->fPdfDoc)
); | 1477 int yStep = abs((int)pattern->YStep(pdfContext->fPdfDoc)
); |
1437 | 1478 |
| 1479 SkPdfReport(kCodeWarning_SkPdfIssueSeverity, kNYI_SkPdfI
ssue, "paterns x/y step is forced to positive number", pattern, pdfContext); |
| 1480 |
1438 SkRect bounds = path.getBounds(); | 1481 SkRect bounds = path.getBounds(); |
1439 | 1482 |
1440 // TODO(edisonn): xstep and ystep can be negative, and w
e need to iterate in reverse | 1483 // TODO(edisonn): xstep and ystep can be negative, and w
e need to iterate in reverse |
1441 // TODO(edisonn): don't do that! | 1484 // TODO(edisonn): don't do that! |
1442 bounds.sort(); | 1485 bounds.sort(); |
1443 | 1486 |
1444 SkScalar x; | 1487 SkScalar x; |
1445 SkScalar y; | 1488 SkScalar y; |
1446 | 1489 |
1447 y = bounds.top(); | 1490 y = bounds.top(); |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1557 } | 1600 } |
1558 | 1601 |
1559 static SkPdfResult PdfOp_n(SkPdfContext* pdfContext, SkCanvas* canvas, PdfTokenL
ooper** looper) { | 1602 static SkPdfResult PdfOp_n(SkPdfContext* pdfContext, SkCanvas* canvas, PdfTokenL
ooper** looper) { |
1560 canvas->setMatrix(pdfContext->fGraphicsState.fCTM); | 1603 canvas->setMatrix(pdfContext->fGraphicsState.fCTM); |
1561 if (pdfContext->fGraphicsState.fHasClipPathToApply) { | 1604 if (pdfContext->fGraphicsState.fHasClipPathToApply) { |
1562 #ifndef PDF_DEBUG_NO_CLIPING | 1605 #ifndef PDF_DEBUG_NO_CLIPING |
1563 canvas->clipPath(pdfContext->fGraphicsState.fClipPath, SkRegion::kInters
ect_Op, true); | 1606 canvas->clipPath(pdfContext->fGraphicsState.fClipPath, SkRegion::kInters
ect_Op, true); |
1564 #endif | 1607 #endif |
1565 } | 1608 } |
1566 | 1609 |
1567 //pdfContext->fGraphicsState.fClipPath.reset(); | |
1568 pdfContext->fGraphicsState.fHasClipPathToApply = false; | 1610 pdfContext->fGraphicsState.fHasClipPathToApply = false; |
1569 | 1611 |
1570 pdfContext->fGraphicsState.fPathClosed = true; | 1612 pdfContext->fGraphicsState.fPathClosed = true; |
1571 | 1613 |
1572 return kOK_SkPdfResult; | 1614 return kOK_SkPdfResult; |
1573 } | 1615 } |
1574 | 1616 |
1575 static SkPdfResult PdfOp_BT(SkPdfContext* pdfContext, SkCanvas* canvas, PdfToken
Looper** looper) { | 1617 static SkPdfResult PdfOp_BT(SkPdfContext* pdfContext, SkCanvas* canvas, PdfToken
Looper** looper) { |
1576 pdfContext->fGraphicsState.fTextBlock = true; | 1618 pdfContext->fGraphicsState.fTextBlock = true; |
1577 SkMatrix matrix = pdfContext->fGraphicsState.fCTM; | 1619 SkMatrix matrix = pdfContext->fGraphicsState.fCTM; |
1578 matrix.preScale(SkDoubleToScalar(1), SkDoubleToScalar(-1)); | 1620 matrix.preScale(SkDoubleToScalar(1), SkDoubleToScalar(-1)); |
1579 pdfContext->fGraphicsState.fMatrixTm = matrix; | 1621 pdfContext->fGraphicsState.fMatrixTm = matrix; |
1580 pdfContext->fGraphicsState.fMatrixTlm = matrix; | 1622 pdfContext->fGraphicsState.fMatrixTlm = matrix; |
1581 | 1623 |
1582 return kPartial_SkPdfResult; | 1624 return kPartial_SkPdfResult; |
1583 } | 1625 } |
1584 | 1626 |
1585 static SkPdfResult PdfOp_ET(SkPdfContext* pdfContext, SkCanvas* canvas, PdfToken
Looper** looper) { | 1627 static SkPdfResult PdfOp_ET(SkPdfContext* pdfContext, SkCanvas* canvas, PdfToken
Looper** looper) { |
1586 if (!pdfContext->fGraphicsState.fTextBlock) { | 1628 if (!pdfContext->fGraphicsState.fTextBlock) { |
| 1629 SkPdfReport(kIgnoreError_SkPdfIssueSeverity, kMissingBT_SkPdfIssue, "ET
without BT", NULL, pdfContext); |
| 1630 |
1587 return kIgnoreError_SkPdfResult; | 1631 return kIgnoreError_SkPdfResult; |
1588 } | 1632 } |
1589 // TODO(edisonn): anything else to be done once we are done with draw text?
Like restore stack? | 1633 // TODO(edisonn): anything else to be done once we are done with draw text?
Like restore stack? |
1590 return kOK_SkPdfResult; | 1634 return kOK_SkPdfResult; |
1591 } | 1635 } |
1592 | 1636 |
1593 static SkPdfResult skpdfGraphicsStateApplyFontCore(SkPdfContext* pdfContext, con
st SkPdfNativeObject* fontName, double fontSize) { | 1637 static SkPdfResult skpdfGraphicsStateApplyFontCore(SkPdfContext* pdfContext, con
st SkPdfNativeObject* fontName, double fontSize) { |
1594 #ifdef PDF_TRACE | 1638 #ifdef PDF_TRACE |
1595 printf("font name: %s\n", fontName->nameValue2().c_str()); | 1639 printf("font name: %s\n", fontName->nameValue2().c_str()); |
1596 #endif | 1640 #endif |
1597 | 1641 |
1598 if (!pdfContext->fGraphicsState.fResources->Font(pdfContext->fPdfDoc)) { | 1642 if (!pdfContext->fGraphicsState.fResources->Font(pdfContext->fPdfDoc)) { |
1599 // TODO(edisonn): try to recover and draw it any way? | 1643 // TODO(edisonn): try to recover and draw it any way? |
| 1644 SkPdfReport(kIgnoreError_SkPdfIssueSeverity, kMissingFont_SkPdfIssue, "N
o font", fontName, pdfContext); |
1600 return kIgnoreError_SkPdfResult; | 1645 return kIgnoreError_SkPdfResult; |
1601 } | 1646 } |
1602 | 1647 |
1603 SkPdfNativeObject* objFont = pdfContext->fGraphicsState.fResources->Font(pdf
Context->fPdfDoc)->get(fontName); | 1648 SkPdfNativeObject* objFont = pdfContext->fGraphicsState.fResources->Font(pdf
Context->fPdfDoc)->get(fontName); |
1604 objFont = pdfContext->fPdfDoc->resolveReference(objFont); | 1649 objFont = pdfContext->fPdfDoc->resolveReference(objFont); |
1605 if (kNone_SkPdfNativeObjectType == pdfContext->fPdfDoc->mapper()->mapFontDic
tionary(objFont)) { | 1650 if (kNone_SkPdfNativeObjectType == pdfContext->fPdfDoc->mapper()->mapFontDic
tionary(objFont)) { |
1606 // TODO(edisonn): try to recover and draw it any way? | 1651 // TODO(edisonn): try to recover and draw it any way? |
| 1652 SkPdfReport(kIgnoreError_SkPdfIssueSeverity, kInvalidFont_SkPdfIssue, "I
nvalid font", objFont, pdfContext); |
1607 return kIgnoreError_SkPdfResult; | 1653 return kIgnoreError_SkPdfResult; |
1608 } | 1654 } |
1609 | 1655 |
1610 SkPdfFontDictionary* fd = (SkPdfFontDictionary*)objFont; | 1656 SkPdfFontDictionary* fd = (SkPdfFontDictionary*)objFont; |
1611 | 1657 |
1612 SkPdfFont* skfont = SkPdfFont::fontFromPdfDictionary(pdfContext->fPdfDoc, fd
); | 1658 SkPdfFont* skfont = SkPdfFont::fontFromPdfDictionary(pdfContext->fPdfDoc, fd
); |
1613 | 1659 |
1614 if (skfont) { | 1660 if (skfont) { |
1615 pdfContext->fGraphicsState.fSkFont = skfont; | 1661 pdfContext->fGraphicsState.fSkFont = skfont; |
1616 } | 1662 } |
1617 pdfContext->fGraphicsState.fCurFontSize = fontSize; | 1663 pdfContext->fGraphicsState.fCurFontSize = fontSize; |
1618 return kOK_SkPdfResult; | 1664 return kOK_SkPdfResult; |
1619 } | 1665 } |
1620 | 1666 |
1621 //font size Tf Set the text font, Tf | 1667 //font size Tf Set the text font, Tf |
1622 //, to font and the text font size, Tfs, to size. font is the name of a | 1668 //, to font and the text font size, Tfs, to size. font is the name of a |
1623 //font resource in the Fontsubdictionary of the current resource dictionary; siz
e is | 1669 //font resource in the Fontsubdictionary of the current resource dictionary; siz
e is |
1624 //a number representing a scale factor. There is no initial value for either fon
t or | 1670 //a number representing a scale factor. There is no initial value for either fon
t or |
1625 //size; they must be specified explicitly using Tf before any text is shown. | 1671 //size; they must be specified explicitly using Tf before any text is shown. |
1626 static SkPdfResult PdfOp_Tf(SkPdfContext* pdfContext, SkCanvas* canvas, PdfToken
Looper** looper) { | 1672 static SkPdfResult PdfOp_Tf(SkPdfContext* pdfContext, SkCanvas* canvas, PdfToken
Looper** looper) { |
1627 EXPECT_OPERANDS(pdfContext, 2); | 1673 EXPECT_OPERANDS("Tf", pdfContext, 2); |
1628 POP_NUMBER(pdfContext, fontSize); | 1674 POP_NUMBER(pdfContext, fontSize); |
1629 POP_NAME(pdfContext, fontName); | 1675 POP_NAME(pdfContext, fontName); |
1630 CHECK_PARAMETERS(); | 1676 CHECK_PARAMETERS(); |
1631 | 1677 |
1632 return skpdfGraphicsStateApplyFontCore(pdfContext, fontName, fontSize); | 1678 return skpdfGraphicsStateApplyFontCore(pdfContext, fontName, fontSize); |
1633 } | 1679 } |
1634 | 1680 |
1635 static SkPdfResult PdfOp_Tj(SkPdfContext* pdfContext, SkCanvas* canvas, PdfToken
Looper** looper) { | 1681 static SkPdfResult PdfOp_Tj(SkPdfContext* pdfContext, SkCanvas* canvas, PdfToken
Looper** looper) { |
1636 EXPECT_OPERANDS(pdfContext, 1); | 1682 EXPECT_OPERANDS("Tj", pdfContext, 1); |
1637 POP_STRING(pdfContext, str); | 1683 POP_STRING(pdfContext, str); |
1638 CHECK_PARAMETERS(); | 1684 CHECK_PARAMETERS(); |
1639 | 1685 |
1640 if (!pdfContext->fGraphicsState.fTextBlock) { | 1686 if (!pdfContext->fGraphicsState.fTextBlock) { |
1641 // TODO(edisonn): try to recover and draw it any way? | 1687 // TODO(edisonn): try to recover and draw it any way? |
| 1688 SkPdfReport(kIgnoreError_SkPdfIssueSeverity, kMissingBT_SkPdfIssue, "Tj
without BT", NULL, pdfContext); |
1642 return kIgnoreError_SkPdfResult; | 1689 return kIgnoreError_SkPdfResult; |
1643 } | 1690 } |
1644 | 1691 |
1645 SkPdfResult ret = DrawText(pdfContext, str, canvas); | 1692 SkPdfResult ret = DrawText(pdfContext, str, canvas); |
1646 | 1693 |
1647 return ret; | 1694 return ret; |
1648 } | 1695 } |
1649 | 1696 |
1650 static SkPdfResult PdfOp_quote(SkPdfContext* pdfContext, SkCanvas* canvas, PdfTo
kenLooper** looper) { | 1697 static SkPdfResult PdfOp_quote(SkPdfContext* pdfContext, SkCanvas* canvas, PdfTo
kenLooper** looper) { |
1651 if (!pdfContext->fGraphicsState.fTextBlock) { | 1698 if (!pdfContext->fGraphicsState.fTextBlock) { |
1652 // TODO(edisonn): try to recover and draw it any way? | 1699 // TODO(edisonn): try to recover and draw it any way? |
| 1700 SkPdfReport(kIgnoreError_SkPdfIssueSeverity, kMissingBT_SkPdfIssue, "' w
ithout BT", NULL, pdfContext); |
1653 return kIgnoreError_SkPdfResult; | 1701 return kIgnoreError_SkPdfResult; |
1654 } | 1702 } |
1655 | 1703 |
1656 PdfOp_T_star(pdfContext, canvas, looper); | 1704 PdfOp_T_star(pdfContext, canvas, looper); |
1657 // Do not pop, and push, just transfer the param to Tj | 1705 // Do not pop, and push, just transfer the param to Tj |
1658 return PdfOp_Tj(pdfContext, canvas, looper); | 1706 return PdfOp_Tj(pdfContext, canvas, looper); |
1659 } | 1707 } |
1660 | 1708 |
1661 static SkPdfResult PdfOp_doublequote(SkPdfContext* pdfContext, SkCanvas* canvas,
PdfTokenLooper** looper) { | 1709 static SkPdfResult PdfOp_doublequote(SkPdfContext* pdfContext, SkCanvas* canvas,
PdfTokenLooper** looper) { |
1662 if (!pdfContext->fGraphicsState.fTextBlock) { | 1710 if (!pdfContext->fGraphicsState.fTextBlock) { |
1663 // TODO(edisonn): try to recover and draw it any way? | 1711 // TODO(edisonn): try to recover and draw it any way? |
| 1712 SkPdfReport(kIgnoreError_SkPdfIssueSeverity, kMissingBT_SkPdfIssue, "\"
without BT", NULL, pdfContext); |
1664 return kIgnoreError_SkPdfResult; | 1713 return kIgnoreError_SkPdfResult; |
1665 } | 1714 } |
1666 | 1715 |
1667 EXPECT_OPERANDS(pdfContext, 3); | 1716 EXPECT_OPERANDS("\"", pdfContext, 3); |
1668 POP_OBJ(pdfContext, str); | 1717 POP_OBJ(pdfContext, str); |
1669 POP_OBJ(pdfContext, ac); | 1718 POP_OBJ(pdfContext, ac); |
1670 POP_OBJ(pdfContext, aw); | 1719 POP_OBJ(pdfContext, aw); |
1671 CHECK_PARAMETERS(); | 1720 CHECK_PARAMETERS(); |
1672 | 1721 |
1673 pdfContext->fObjectStack.push(aw); | 1722 pdfContext->fObjectStack.push(aw); |
1674 PdfOp_Tw(pdfContext, canvas, looper); | 1723 PdfOp_Tw(pdfContext, canvas, looper); |
1675 | 1724 |
1676 pdfContext->fObjectStack.push(ac); | 1725 pdfContext->fObjectStack.push(ac); |
1677 PdfOp_Tc(pdfContext, canvas, looper); | 1726 PdfOp_Tc(pdfContext, canvas, looper); |
1678 | 1727 |
1679 pdfContext->fObjectStack.push(str); | 1728 pdfContext->fObjectStack.push(str); |
1680 PdfOp_quote(pdfContext, canvas, looper); | 1729 PdfOp_quote(pdfContext, canvas, looper); |
1681 | 1730 |
1682 return kPartial_SkPdfResult; | 1731 return kPartial_SkPdfResult; |
1683 } | 1732 } |
1684 | 1733 |
1685 static SkPdfResult PdfOp_TJ(SkPdfContext* pdfContext, SkCanvas* canvas, PdfToken
Looper** looper) { | 1734 static SkPdfResult PdfOp_TJ(SkPdfContext* pdfContext, SkCanvas* canvas, PdfToken
Looper** looper) { |
1686 EXPECT_OPERANDS(pdfContext, 1); | 1735 EXPECT_OPERANDS("Tf", pdfContext, 1); |
1687 POP_ARRAY(pdfContext, array); | 1736 POP_ARRAY(pdfContext, array); |
1688 CHECK_PARAMETERS(); | 1737 CHECK_PARAMETERS(); |
1689 | 1738 |
1690 if (!pdfContext->fGraphicsState.fTextBlock) { | 1739 if (!pdfContext->fGraphicsState.fTextBlock) { |
1691 // TODO(edisonn): try to recover and draw it any way? | 1740 // TODO(edisonn): try to recover and draw it any way? |
| 1741 SkPdfReport(kIgnoreError_SkPdfIssueSeverity, kMissingBT_SkPdfIssue, "TJ
without BT", NULL, pdfContext); |
1692 return kIgnoreError_SkPdfResult; | 1742 return kIgnoreError_SkPdfResult; |
1693 } | 1743 } |
1694 | 1744 |
1695 if (!array->isArray()) { | 1745 if (!array->isArray()) { |
| 1746 SkPdfReportUnexpectedType(kIgnoreError_SkPdfIssueSeverity, NULL, array,
SkPdfNativeObject::kArray_PdfObjectType, pdfContext); |
1696 return kIgnoreError_SkPdfResult; | 1747 return kIgnoreError_SkPdfResult; |
1697 } | 1748 } |
1698 | 1749 |
1699 for( int i=0; i<static_cast<int>(array->size()); i++ ) | 1750 for( int i=0; i<static_cast<int>(array->size()); i++ ) |
1700 { | 1751 { |
1701 if( (*array)[i]->isAnyString()) { | 1752 if (!(*array)[i]) { |
| 1753 SkPdfReportUnexpectedType(kIgnoreError_SkPdfIssueSeverity, "element
[i] is null, no element should be null", array, SkPdfNativeObject::_kAnyString_P
dfObjectType || SkPdfNativeObject::_kNumber_PdfObjectType, pdfContext); |
| 1754 } else if( (*array)[i]->isAnyString()) { |
1702 SkPdfNativeObject* obj = (*array)[i]; | 1755 SkPdfNativeObject* obj = (*array)[i]; |
1703 DrawText(pdfContext, obj, canvas); | 1756 DrawText(pdfContext, obj, canvas); |
1704 } else if ((*array)[i]->isNumber()) { | 1757 } else if ((*array)[i]->isNumber()) { |
1705 double dx = (*array)[i]->numberValue(); | 1758 double dx = (*array)[i]->numberValue(); |
1706 SkMatrix matrix; | 1759 SkMatrix matrix; |
1707 matrix.setAll(SkDoubleToScalar(1), | 1760 matrix.setAll(SkDoubleToScalar(1), |
1708 SkDoubleToScalar(0), | 1761 SkDoubleToScalar(0), |
1709 // TODO(edisonn): use writing mode, vertical/horizonta
l. | 1762 // TODO(edisonn): use writing mode, vertical/horizonta
l. |
1710 SkDoubleToScalar(-dx), // amount is substracted!!! | 1763 SkDoubleToScalar(-dx), // amount is substracted!!! |
1711 SkDoubleToScalar(0), | 1764 SkDoubleToScalar(0), |
1712 SkDoubleToScalar(1), | 1765 SkDoubleToScalar(1), |
1713 SkDoubleToScalar(0), | 1766 SkDoubleToScalar(0), |
1714 SkDoubleToScalar(0), | 1767 SkDoubleToScalar(0), |
1715 SkDoubleToScalar(0), | 1768 SkDoubleToScalar(0), |
1716 SkDoubleToScalar(1)); | 1769 SkDoubleToScalar(1)); |
1717 | 1770 |
1718 pdfContext->fGraphicsState.fMatrixTm.preConcat(matrix); | 1771 pdfContext->fGraphicsState.fMatrixTm.preConcat(matrix); |
| 1772 } else { |
| 1773 SkPdfReportUnexpectedType(kIgnoreError_SkPdfIssueSeverity, "wrong ty
pe", (*array)[i], SkPdfNativeObject::kArray_PdfObjectType || SkPdfNativeObject::
_kNumber_PdfObjectType, pdfContext); |
1719 } | 1774 } |
1720 } | 1775 } |
1721 return kPartial_SkPdfResult; // TODO(edisonn): Implement fully DrawText bef
ore returing OK. | 1776 return kPartial_SkPdfResult; // TODO(edisonn): Implement fully DrawText bef
ore returing OK. |
1722 } | 1777 } |
1723 | 1778 |
1724 static SkPdfResult PdfOp_CS_cs(SkPdfContext* pdfContext, SkCanvas* canvas, SkPdf
ColorOperator* colorOperator) { | 1779 static SkPdfResult PdfOp_CS_cs(SkPdfContext* pdfContext, SkCanvas* canvas, SkPdf
ColorOperator* colorOperator) { |
1725 EXPECT_OPERANDS(pdfContext, 1); | 1780 EXPECT_OPERANDS("CS/cs", pdfContext, 1); |
1726 POP_NAME(pdfContext, name); | 1781 POP_NAME(pdfContext, name); |
1727 CHECK_PARAMETERS(); | 1782 CHECK_PARAMETERS(); |
1728 | 1783 |
1729 //Next, get the ColorSpace Dictionary from the Resource Dictionary: | 1784 //Next, get the ColorSpace Dictionary from the Resource Dictionary: |
1730 SkPdfDictionary* colorSpaceResource = pdfContext->fGraphicsState.fResources-
>ColorSpace(pdfContext->fPdfDoc); | 1785 SkPdfDictionary* colorSpaceResource = pdfContext->fGraphicsState.fResources-
>ColorSpace(pdfContext->fPdfDoc); |
1731 | 1786 |
1732 SkPdfNativeObject* colorSpace = colorSpaceResource ? pdfContext->fPdfDoc->re
solveReference(colorSpaceResource->get(name)) : name; | 1787 SkPdfNativeObject* colorSpace = colorSpaceResource ? pdfContext->fPdfDoc->re
solveReference(colorSpaceResource->get(name)) : name; |
1733 | 1788 |
1734 if (colorSpace == NULL) { | 1789 if (colorSpace == NULL) { |
1735 colorOperator->fColorSpace = name->strRef(); | 1790 colorOperator->fColorSpace = name->strRef(); |
1736 } else { | 1791 } else { |
1737 #ifdef PDF_TRACE | 1792 #ifdef PDF_TRACE |
1738 printf("CS = %s\n", colorSpace->toString(0, 0).c_str()); | 1793 printf("CS = %s\n", colorSpace->toString(0, 0).c_str()); |
1739 #endif // PDF_TRACE | 1794 #endif // PDF_TRACE |
1740 if (colorSpace->isName()) { | 1795 if (colorSpace->isName()) { |
1741 colorOperator->fColorSpace = colorSpace->strRef(); | 1796 colorOperator->fColorSpace = colorSpace->strRef(); |
1742 } else if (colorSpace->isArray()) { | 1797 } else if (colorSpace->isArray()) { |
1743 int cnt = colorSpace->size(); | 1798 int cnt = colorSpace->size(); |
1744 if (cnt == 0) { | 1799 if (cnt == 0) { |
| 1800 SkPdfReport(kIgnoreError_SkPdfIssueSeverity, kIncostistentSizes_
SkPdfIssue, "color space has length 0", colorSpace, pdfContext); |
1745 return kIgnoreError_SkPdfResult; | 1801 return kIgnoreError_SkPdfResult; |
1746 } | 1802 } |
1747 SkPdfNativeObject* type = colorSpace->objAtAIndex(0); | 1803 SkPdfNativeObject* type = colorSpace->objAtAIndex(0); |
1748 type = pdfContext->fPdfDoc->resolveReference(type); | 1804 type = pdfContext->fPdfDoc->resolveReference(type); |
1749 | 1805 |
1750 if (type->isName("ICCBased")) { | 1806 if (type->isName("ICCBased")) { |
1751 if (cnt != 2) { | 1807 if (cnt != 2) { |
| 1808 SkPdfReport(kIgnoreError_SkPdfIssueSeverity, kIncostistentSi
zes_SkPdfIssue, "ICCBased color space must have an array with 2 elements", color
Space, pdfContext); |
1752 return kIgnoreError_SkPdfResult; | 1809 return kIgnoreError_SkPdfResult; |
1753 } | 1810 } |
1754 SkPdfNativeObject* prop = colorSpace->objAtAIndex(1); | 1811 SkPdfNativeObject* prop = colorSpace->objAtAIndex(1); |
1755 prop = pdfContext->fPdfDoc->resolveReference(prop); | 1812 prop = pdfContext->fPdfDoc->resolveReference(prop); |
1756 #ifdef PDF_TRACE | 1813 #ifdef PDF_TRACE |
1757 printf("ICCBased prop = %s\n", prop->toString(0, 0).c_str()); | 1814 printf("ICCBased prop = %s\n", prop->toString(0, 0).c_str()); |
1758 #endif // PDF_TRACE | 1815 #endif // PDF_TRACE |
1759 // TODO(edisonn): hack | 1816 // TODO(edisonn): hack |
1760 if (prop && prop->isDictionary() && prop->get("N") && prop->get
("N")->isInteger() && prop->get("N")->intValue() == 3) { | 1817 if (prop && prop->isDictionary() && prop->get("N") && prop->get
("N")->isInteger() && prop->get("N")->intValue() == 3) { |
1761 colorOperator->setColorSpace(&strings_DeviceRGB); | 1818 colorOperator->setColorSpace(&strings_DeviceRGB); |
(...skipping 23 matching lines...) Expand all Loading... |
1785 | 1842 |
1786 bool doubles = true; | 1843 bool doubles = true; |
1787 if (colorOperator->fColorSpace.equals("Indexed")) { | 1844 if (colorOperator->fColorSpace.equals("Indexed")) { |
1788 doubles = false; | 1845 doubles = false; |
1789 } | 1846 } |
1790 | 1847 |
1791 #ifdef PDF_TRACE | 1848 #ifdef PDF_TRACE |
1792 printf("color space = %s, N = %i\n", colorOperator->fColorSpace.fBuffer, n); | 1849 printf("color space = %s, N = %i\n", colorOperator->fColorSpace.fBuffer, n); |
1793 #endif | 1850 #endif |
1794 | 1851 |
1795 EXPECT_OPERANDS(pdfContext, n); | 1852 EXPECT_OPERANDS("SC/sc", pdfContext, n); |
1796 | 1853 |
1797 for (int i = n - 1; i >= 0 ; i--) { | 1854 for (int i = n - 1; i >= 0 ; i--) { |
1798 if (doubles) { | 1855 if (doubles) { |
1799 POP_NUMBER_INTO(pdfContext, c[i]); | 1856 POP_NUMBER_INTO(pdfContext, c[i]); |
1800 // } else { | 1857 // } else { |
1801 // v[i] = pdfContext->fObjectStack.top()->intValue(); pdfConte
xt->fObjectStack.pop(); | 1858 // v[i] = pdfContext->fObjectStack.top()->intValue(); pdfConte
xt->fObjectStack.pop(); |
1802 } | 1859 } |
1803 } | 1860 } |
1804 CHECK_PARAMETERS(); | 1861 CHECK_PARAMETERS(); |
1805 | 1862 |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1845 | 1902 |
1846 static SkPdfResult PdfOp_SCN(SkPdfContext* pdfContext, SkCanvas* canvas, PdfToke
nLooper** looper) { | 1903 static SkPdfResult PdfOp_SCN(SkPdfContext* pdfContext, SkCanvas* canvas, PdfToke
nLooper** looper) { |
1847 return PdfOp_SCN_scn(pdfContext, canvas, &pdfContext->fGraphicsState.fStroki
ng); | 1904 return PdfOp_SCN_scn(pdfContext, canvas, &pdfContext->fGraphicsState.fStroki
ng); |
1848 } | 1905 } |
1849 | 1906 |
1850 static SkPdfResult PdfOp_scn(SkPdfContext* pdfContext, SkCanvas* canvas, PdfToke
nLooper** looper) { | 1907 static SkPdfResult PdfOp_scn(SkPdfContext* pdfContext, SkCanvas* canvas, PdfToke
nLooper** looper) { |
1851 return PdfOp_SCN_scn(pdfContext, canvas, &pdfContext->fGraphicsState.fNonStr
oking); | 1908 return PdfOp_SCN_scn(pdfContext, canvas, &pdfContext->fGraphicsState.fNonStr
oking); |
1852 } | 1909 } |
1853 | 1910 |
1854 static SkPdfResult PdfOp_G_g(SkPdfContext* pdfContext, SkCanvas* canvas, SkPdfCo
lorOperator* colorOperator) { | 1911 static SkPdfResult PdfOp_G_g(SkPdfContext* pdfContext, SkCanvas* canvas, SkPdfCo
lorOperator* colorOperator) { |
1855 EXPECT_OPERANDS(pdfContext, 1); | 1912 EXPECT_OPERANDS("G/g", pdfContext, 1); |
1856 POP_NUMBER(pdfContext, gray); | 1913 POP_NUMBER(pdfContext, gray); |
1857 CHECK_PARAMETERS(); | 1914 CHECK_PARAMETERS(); |
1858 | 1915 |
1859 colorOperator->fColorSpace = strings_DeviceRGB; // TODO(edisonn): HACK - it
should be device gray, but not suported right now | 1916 colorOperator->fColorSpace = strings_DeviceRGB; // TODO(edisonn): HACK - it
should be device gray, but not suported right now |
1860 colorOperator->setRGBColor(SkColorSetRGB((U8CPU)(255*gray), (U8CPU)(255*gray
), (U8CPU)(255*gray))); | 1917 colorOperator->setRGBColor(SkColorSetRGB((U8CPU)(255*gray), (U8CPU)(255*gray
), (U8CPU)(255*gray))); |
1861 | 1918 |
1862 return kPartial_SkPdfResult; | 1919 return kPartial_SkPdfResult; |
1863 } | 1920 } |
1864 | 1921 |
1865 static SkPdfResult PdfOp_G(SkPdfContext* pdfContext, SkCanvas* canvas, PdfTokenL
ooper** looper) { | 1922 static SkPdfResult PdfOp_G(SkPdfContext* pdfContext, SkCanvas* canvas, PdfTokenL
ooper** looper) { |
1866 return PdfOp_G_g(pdfContext, canvas, &pdfContext->fGraphicsState.fStroking); | 1923 return PdfOp_G_g(pdfContext, canvas, &pdfContext->fGraphicsState.fStroking); |
1867 } | 1924 } |
1868 | 1925 |
1869 static SkPdfResult PdfOp_g(SkPdfContext* pdfContext, SkCanvas* canvas, PdfTokenL
ooper** looper) { | 1926 static SkPdfResult PdfOp_g(SkPdfContext* pdfContext, SkCanvas* canvas, PdfTokenL
ooper** looper) { |
1870 return PdfOp_G_g(pdfContext, canvas, &pdfContext->fGraphicsState.fNonStrokin
g); | 1927 return PdfOp_G_g(pdfContext, canvas, &pdfContext->fGraphicsState.fNonStrokin
g); |
1871 } | 1928 } |
1872 | 1929 |
1873 static SkPdfResult PdfOp_RG_rg(SkPdfContext* pdfContext, SkCanvas* canvas, SkPdf
ColorOperator* colorOperator) { | 1930 static SkPdfResult PdfOp_RG_rg(SkPdfContext* pdfContext, SkCanvas* canvas, SkPdf
ColorOperator* colorOperator) { |
1874 EXPECT_OPERANDS(pdfContext, 3); | 1931 EXPECT_OPERANDS("RG/rg", pdfContext, 3); |
1875 POP_NUMBER(pdfContext, b); | 1932 POP_NUMBER(pdfContext, b); |
1876 POP_NUMBER(pdfContext, g); | 1933 POP_NUMBER(pdfContext, g); |
1877 POP_NUMBER(pdfContext, r); | 1934 POP_NUMBER(pdfContext, r); |
1878 CHECK_PARAMETERS(); | 1935 CHECK_PARAMETERS(); |
1879 | 1936 |
1880 colorOperator->fColorSpace = strings_DeviceRGB; | 1937 colorOperator->fColorSpace = strings_DeviceRGB; |
1881 colorOperator->setRGBColor(SkColorSetRGB((U8CPU)(255*r), (U8CPU)(255*g), (U8
CPU)(255*b))); | 1938 colorOperator->setRGBColor(SkColorSetRGB((U8CPU)(255*r), (U8CPU)(255*g), (U8
CPU)(255*b))); |
1882 return kOK_SkPdfResult; | 1939 return kOK_SkPdfResult; |
1883 } | 1940 } |
1884 | 1941 |
1885 static SkPdfResult PdfOp_RG(SkPdfContext* pdfContext, SkCanvas* canvas, PdfToken
Looper** looper) { | 1942 static SkPdfResult PdfOp_RG(SkPdfContext* pdfContext, SkCanvas* canvas, PdfToken
Looper** looper) { |
1886 return PdfOp_RG_rg(pdfContext, canvas, &pdfContext->fGraphicsState.fStroking
); | 1943 return PdfOp_RG_rg(pdfContext, canvas, &pdfContext->fGraphicsState.fStroking
); |
1887 } | 1944 } |
1888 | 1945 |
1889 static SkPdfResult PdfOp_rg(SkPdfContext* pdfContext, SkCanvas* canvas, PdfToken
Looper** looper) { | 1946 static SkPdfResult PdfOp_rg(SkPdfContext* pdfContext, SkCanvas* canvas, PdfToken
Looper** looper) { |
1890 return PdfOp_RG_rg(pdfContext, canvas, &pdfContext->fGraphicsState.fNonStrok
ing); | 1947 return PdfOp_RG_rg(pdfContext, canvas, &pdfContext->fGraphicsState.fNonStrok
ing); |
1891 } | 1948 } |
1892 | 1949 |
1893 static SkPdfResult PdfOp_K_k(SkPdfContext* pdfContext, SkCanvas* canvas, SkPdfCo
lorOperator* colorOperator) { | 1950 static SkPdfResult PdfOp_K_k(SkPdfContext* pdfContext, SkCanvas* canvas, SkPdfCo
lorOperator* colorOperator) { |
1894 // TODO(edisonn): spec has some rules about overprint, implement them. | 1951 // TODO(edisonn): spec has some rules about overprint, implement them. |
1895 EXPECT_OPERANDS(pdfContext, 4); | 1952 EXPECT_OPERANDS("K/k", pdfContext, 4); |
1896 POP_NUMBER(pdfContext, k); | 1953 POP_NUMBER(pdfContext, k); |
1897 POP_NUMBER(pdfContext, y); | 1954 POP_NUMBER(pdfContext, y); |
1898 POP_NUMBER(pdfContext, m); | 1955 POP_NUMBER(pdfContext, m); |
1899 POP_NUMBER(pdfContext, c); | 1956 POP_NUMBER(pdfContext, c); |
1900 CHECK_PARAMETERS(); | 1957 CHECK_PARAMETERS(); |
1901 | 1958 |
1902 // TODO(edisonn): silly way to remove compiler warning | 1959 // TODO(edisonn): silly way to remove compiler warning |
1903 if (k + y + m + c == 0) { | 1960 if (k + y + m + c == 0) { |
1904 return kNYI_SkPdfResult; | 1961 return kNYI_SkPdfResult; |
1905 } | 1962 } |
(...skipping 26 matching lines...) Expand all Loading... |
1932 | 1989 |
1933 return kOK_SkPdfResult; | 1990 return kOK_SkPdfResult; |
1934 } | 1991 } |
1935 | 1992 |
1936 static SkPdfResult PdfOp_BX(SkPdfContext* pdfContext, SkCanvas* canvas, PdfToken
Looper** looper) { | 1993 static SkPdfResult PdfOp_BX(SkPdfContext* pdfContext, SkCanvas* canvas, PdfToken
Looper** looper) { |
1937 *looper = new PdfCompatibilitySectionLooper(); | 1994 *looper = new PdfCompatibilitySectionLooper(); |
1938 return kOK_SkPdfResult; | 1995 return kOK_SkPdfResult; |
1939 } | 1996 } |
1940 | 1997 |
1941 static SkPdfResult PdfOp_EX(SkPdfContext* pdfContext, SkCanvas* canvas, PdfToken
Looper** looper) { | 1998 static SkPdfResult PdfOp_EX(SkPdfContext* pdfContext, SkCanvas* canvas, PdfToken
Looper** looper) { |
1942 #ifdef ASSERT_BAD_PDF_OPS | 1999 SkPdfReport(kIgnoreError_SkPdfIssueSeverity, kNullObject_SkPdfIssue, "EX ope
rator should not be called, it is habdled in a looper, unless the file is corrup
ted, we should assert", NULL, pdfContext); |
1943 SkASSERT(false); // EX must be consumed by PdfCompatibilitySectionLooper, b
ut let's | 2000 |
1944 // have the assert when testing good pdfs. | |
1945 #endif | |
1946 return kIgnoreError_SkPdfResult; | 2001 return kIgnoreError_SkPdfResult; |
1947 } | 2002 } |
1948 | 2003 |
1949 static SkPdfResult PdfOp_BI(SkPdfContext* pdfContext, SkCanvas* canvas, PdfToken
Looper** looper) { | 2004 static SkPdfResult PdfOp_BI(SkPdfContext* pdfContext, SkCanvas* canvas, PdfToken
Looper** looper) { |
1950 *looper = new PdfInlineImageLooper(); | 2005 *looper = new PdfInlineImageLooper(); |
1951 return kOK_SkPdfResult; | 2006 return kOK_SkPdfResult; |
1952 } | 2007 } |
1953 | 2008 |
1954 static SkPdfResult PdfOp_ID(SkPdfContext* pdfContext, SkCanvas* canvas, PdfToken
Looper** looper) { | 2009 static SkPdfResult PdfOp_ID(SkPdfContext* pdfContext, SkCanvas* canvas, PdfToken
Looper** looper) { |
1955 #ifdef ASSERT_BAD_PDF_OPS | 2010 SkPdfReport(kIgnoreError_SkPdfIssueSeverity, kNullObject_SkPdfIssue, "ID ope
rator should not be called, it is habdled in a looper, unless the file is corrup
ted, we should assert", NULL, pdfContext); |
1956 SkASSERT(false); // must be processed in inline image looper, but let's | |
1957 // have the assert when testing good pdfs. | |
1958 #endif | |
1959 return kIgnoreError_SkPdfResult; | 2011 return kIgnoreError_SkPdfResult; |
1960 } | 2012 } |
1961 | 2013 |
1962 static SkPdfResult PdfOp_EI(SkPdfContext* pdfContext, SkCanvas* canvas, PdfToken
Looper** looper) { | 2014 static SkPdfResult PdfOp_EI(SkPdfContext* pdfContext, SkCanvas* canvas, PdfToken
Looper** looper) { |
1963 #ifdef ASSERT_BAD_PDF_OPS | 2015 SkPdfReport(kIgnoreError_SkPdfIssueSeverity, kNullObject_SkPdfIssue, "EI ope
rator should not be called, it is habdled in a looper, unless the file is corrup
ted, we should assert", NULL, pdfContext); |
1964 SkASSERT(false); // must be processed in inline image looper, but let's | |
1965 // have the assert when testing good pdfs. | |
1966 #endif | |
1967 return kIgnoreError_SkPdfResult; | 2016 return kIgnoreError_SkPdfResult; |
1968 } | 2017 } |
1969 | 2018 |
1970 | |
1971 // TODO(edisonn): security review here, make sure all parameters are valid, and
safe. | 2019 // TODO(edisonn): security review here, make sure all parameters are valid, and
safe. |
1972 static SkPdfResult skpdfGraphicsStateApply_ca(SkPdfContext* pdfContext, double c
a) { | 2020 static SkPdfResult skpdfGraphicsStateApply_ca(SkPdfContext* pdfContext, double c
a) { |
1973 pdfContext->fGraphicsState.fNonStroking.fOpacity = ca; | 2021 pdfContext->fGraphicsState.fNonStroking.fOpacity = ca; |
1974 return kOK_SkPdfResult; | 2022 return kOK_SkPdfResult; |
1975 } | 2023 } |
1976 | 2024 |
1977 static SkPdfResult skpdfGraphicsStateApply_CA(SkPdfContext* pdfContext, double C
A) { | 2025 static SkPdfResult skpdfGraphicsStateApply_CA(SkPdfContext* pdfContext, double C
A) { |
1978 pdfContext->fGraphicsState.fStroking.fOpacity = CA; | 2026 pdfContext->fGraphicsState.fStroking.fOpacity = CA; |
1979 return kOK_SkPdfResult; | 2027 return kOK_SkPdfResult; |
1980 } | 2028 } |
(...skipping 22 matching lines...) Expand all Loading... |
2003 /* | 2051 /* |
2004 1) [ ] 0 No dash; solid, unbroken lines | 2052 1) [ ] 0 No dash; solid, unbroken lines |
2005 2) [3] 0 3 units on, 3 units off, … | 2053 2) [3] 0 3 units on, 3 units off, … |
2006 3) [2] 1 1 on, 2 off, 2 on, 2 off, … | 2054 3) [2] 1 1 on, 2 off, 2 on, 2 off, … |
2007 4) [2 1] 0 2 on, 1 off, 2 on, 1 off, … | 2055 4) [2 1] 0 2 on, 1 off, 2 on, 1 off, … |
2008 5) [3 5] 6 2 off, 3 on, 5 off, 3 on, 5 off, … | 2056 5) [3 5] 6 2 off, 3 on, 5 off, 3 on, 5 off, … |
2009 6) [2 3] 11 1 on, 3 off, 2 on, 3 off, 2 on, … | 2057 6) [2 3] 11 1 on, 3 off, 2 on, 3 off, 2 on, … |
2010 */ | 2058 */ |
2011 | 2059 |
2012 static SkPdfResult skpdfGraphicsStateApplyD(SkPdfContext* pdfContext, SkPdfArray
* intervals, SkPdfNativeObject* phase) { | 2060 static SkPdfResult skpdfGraphicsStateApplyD(SkPdfContext* pdfContext, SkPdfArray
* intervals, SkPdfNativeObject* phase) { |
| 2061 if (intervals == NULL) { |
| 2062 SkPdfReportUnexpectedType(kIgnoreError_SkPdfIssueSeverity, NULL, interva
ls, SkPdfNativeObject::_kNumber_PdfObjectType, pdfContext); |
| 2063 return kIgnoreError_SkPdfResult; |
| 2064 } |
| 2065 |
| 2066 if (phase == NULL) { |
| 2067 SkPdfReportUnexpectedType(kIgnoreError_SkPdfIssueSeverity, NULL, phase,
SkPdfNativeObject::_kNumber_PdfObjectType, pdfContext); |
| 2068 return kIgnoreError_SkPdfResult; |
| 2069 } |
| 2070 |
2013 int cnt = intervals->size(); | 2071 int cnt = intervals->size(); |
2014 if (cnt >= 256) { | 2072 if (cnt >= 256) { |
2015 // TODO(edisonn): report error/warning, unsuported; | |
2016 // TODO(edisonn): alloc memory | 2073 // TODO(edisonn): alloc memory |
| 2074 SkPdfReport(kCodeWarning_SkPdfIssueSeverity, kNYI_SkPdfIssue, "dash arra
y size unssuported, cnt > 256", intervals, pdfContext); |
2017 return kIgnoreError_SkPdfResult; | 2075 return kIgnoreError_SkPdfResult; |
2018 } | 2076 } |
2019 for (int i = 0; i < cnt; i++) { | 2077 for (int i = 0; i < cnt; i++) { |
2020 if (!intervals->objAtAIndex(i)->isNumber()) { | 2078 if (!intervals->objAtAIndex(i) || !intervals->objAtAIndex(i)->isNumber()
) { |
2021 // TODO(edisonn): report error/warning | 2079 SkPdfReportUnexpectedType(kIgnoreError_SkPdfIssueSeverity, NULL, int
ervals->objAtAIndex(i), SkPdfNativeObject::_kNumber_PdfObjectType, NULL); |
2022 return kIgnoreError_SkPdfResult; | 2080 return kIgnoreError_SkPdfResult; |
2023 } | 2081 } |
2024 } | 2082 } |
2025 | 2083 |
2026 double total = 0; | 2084 double total = 0; |
2027 for (int i = 0 ; i < cnt; i++) { | 2085 for (int i = 0 ; i < cnt; i++) { |
2028 pdfContext->fGraphicsState.fDashArray[i] = intervals->objAtAIndex(i)->sc
alarValue(); | 2086 pdfContext->fGraphicsState.fDashArray[i] = intervals->objAtAIndex(i)->sc
alarValue(); |
2029 total += pdfContext->fGraphicsState.fDashArray[i]; | 2087 total += pdfContext->fGraphicsState.fDashArray[i]; |
2030 } | 2088 } |
2031 if (cnt & 1) { | 2089 if (cnt & 1) { |
2032 if (cnt == 1) { | 2090 if (cnt == 1) { |
2033 pdfContext->fGraphicsState.fDashArray[1] = pdfContext->fGraphicsStat
e.fDashArray[0]; | 2091 pdfContext->fGraphicsState.fDashArray[1] = pdfContext->fGraphicsStat
e.fDashArray[0]; |
2034 cnt++; | 2092 cnt++; |
2035 } else { | 2093 } else { |
2036 // TODO(edisonn): report error/warning | 2094 // TODO(edisonn): report error/warning |
2037 return kNYI_SkPdfResult; | 2095 return kNYI_SkPdfResult; |
2038 } | 2096 } |
2039 } | 2097 } |
2040 pdfContext->fGraphicsState.fDashArrayLength = cnt; | 2098 pdfContext->fGraphicsState.fDashArrayLength = cnt; |
2041 pdfContext->fGraphicsState.fDashPhase = phase->scalarValue(); | 2099 pdfContext->fGraphicsState.fDashPhase = phase->scalarValue(); |
2042 if (pdfContext->fGraphicsState.fDashPhase == 0) { | 2100 if (pdfContext->fGraphicsState.fDashPhase == 0) { |
2043 // other rules, changes? | 2101 // other rules, changes? |
2044 pdfContext->fGraphicsState.fDashPhase = SkDoubleToScalar(total); | 2102 pdfContext->fGraphicsState.fDashPhase = SkDoubleToScalar(total); |
2045 } | 2103 } |
2046 | 2104 |
2047 return kOK_SkPdfResult; | 2105 return kOK_SkPdfResult; |
2048 } | 2106 } |
2049 | 2107 |
2050 static SkPdfResult skpdfGraphicsStateApplyD(SkPdfContext* pdfContext, SkPdfArray
* dash) { | 2108 static SkPdfResult skpdfGraphicsStateApplyD(SkPdfContext* pdfContext, SkPdfArray
* dash) { |
2051 // TODO(edisonn): verify input | 2109 if (!dash || dash->isArray()) { |
2052 if (!dash || dash->isArray() || dash->size() != 2 || !dash->objAtAIndex(0)->
isArray() || !dash->objAtAIndex(1)->isNumber()) { | 2110 SkPdfReportUnexpectedType(kIgnoreError_SkPdfIssueSeverity, NULL, dash, S
kPdfNativeObject::kArray_PdfObjectType, pdfContext); |
2053 // TODO(edisonn): report error/warning | |
2054 return kIgnoreError_SkPdfResult; | 2111 return kIgnoreError_SkPdfResult; |
2055 } | 2112 } |
| 2113 |
| 2114 if (dash->size() != 2) { |
| 2115 SkPdfReport(kIgnoreError_SkPdfIssueSeverity, kIncostistentSizes_SkPdfIss
ue, "hash array must have 2 elements", dash, pdfContext); |
| 2116 return kIgnoreError_SkPdfResult; |
| 2117 } |
| 2118 |
| 2119 if (!dash->objAtAIndex(0) || !dash->objAtAIndex(0)->isArray()) { |
| 2120 SkPdfReportUnexpectedType(kIgnoreError_SkPdfIssueSeverity, NULL, dash->o
bjAtAIndex(0), SkPdfNativeObject::kArray_PdfObjectType, pdfContext); |
| 2121 return kIgnoreError_SkPdfResult; |
| 2122 } |
| 2123 |
| 2124 if (!dash->objAtAIndex(1) || !dash->objAtAIndex(1)->isNumber()) { |
| 2125 SkPdfReportUnexpectedType(kIgnoreError_SkPdfIssueSeverity, NULL, dash->o
bjAtAIndex(1), SkPdfNativeObject::_kNumber_PdfObjectType, pdfContext); |
| 2126 return kIgnoreError_SkPdfResult; |
| 2127 } |
| 2128 |
2056 return skpdfGraphicsStateApplyD(pdfContext, (SkPdfArray*)dash->objAtAIndex(0
), dash->objAtAIndex(1)); | 2129 return skpdfGraphicsStateApplyD(pdfContext, (SkPdfArray*)dash->objAtAIndex(0
), dash->objAtAIndex(1)); |
2057 } | 2130 } |
2058 | 2131 |
2059 static void skpdfGraphicsStateApplyFont(SkPdfContext* pdfContext, SkPdfArray* fo
ntAndSize) { | 2132 static void skpdfGraphicsStateApplyFont(SkPdfContext* pdfContext, SkPdfArray* fo
ntAndSize) { |
2060 if (!fontAndSize || fontAndSize->isArray() || fontAndSize->size() != 2 || !f
ontAndSize->objAtAIndex(0)->isName() || !fontAndSize->objAtAIndex(1)->isNumber()
) { | 2133 if (!fontAndSize || !fontAndSize->isArray()) { |
2061 // TODO(edisonn): report error/warning | 2134 SkPdfReportUnexpectedType(kIgnoreError_SkPdfIssueSeverity, NULL, fontAnd
Size, SkPdfNativeObject::kArray_PdfObjectType, pdfContext); |
2062 return; | 2135 return; |
2063 } | 2136 } |
| 2137 |
| 2138 if (fontAndSize->size() != 2) { |
| 2139 SkPdfReport(kIgnoreError_SkPdfIssueSeverity, kIncostistentSizes_SkPdfIss
ue, "font array must have 2 elements", fontAndSize, pdfContext); |
| 2140 return; |
| 2141 } |
| 2142 |
| 2143 if (!fontAndSize->objAtAIndex(0) || !fontAndSize->objAtAIndex(0)->isName())
{ |
| 2144 SkPdfReportUnexpectedType(kIgnoreError_SkPdfIssueSeverity, NULL, fontAnd
Size->objAtAIndex(0), SkPdfNativeObject::kName_PdfObjectType, pdfContext); |
| 2145 return; |
| 2146 } |
| 2147 |
| 2148 |
| 2149 if (!fontAndSize->objAtAIndex(1) || !fontAndSize->objAtAIndex(1)->isNumber()
) { |
| 2150 SkPdfReportUnexpectedType(kIgnoreError_SkPdfIssueSeverity, NULL, fontAnd
Size->objAtAIndex(0), SkPdfNativeObject::_kNumber_PdfObjectType, pdfContext); |
| 2151 return; |
| 2152 } |
| 2153 |
2064 skpdfGraphicsStateApplyFontCore(pdfContext, fontAndSize->objAtAIndex(0), fon
tAndSize->objAtAIndex(1)->numberValue()); | 2154 skpdfGraphicsStateApplyFontCore(pdfContext, fontAndSize->objAtAIndex(0), fon
tAndSize->objAtAIndex(1)->numberValue()); |
2065 } | 2155 } |
2066 | 2156 |
2067 | 2157 |
2068 //lineWidth w Set the line width in the graphics state (see “Line Width” on page
152). | 2158 //lineWidth w Set the line width in the graphics state (see “Line Width” on page
152). |
2069 static SkPdfResult PdfOp_w(SkPdfContext* pdfContext, SkCanvas* canvas, PdfTokenL
ooper** looper) { | 2159 static SkPdfResult PdfOp_w(SkPdfContext* pdfContext, SkCanvas* canvas, PdfTokenL
ooper** looper) { |
2070 EXPECT_OPERANDS(pdfContext, 1); | 2160 EXPECT_OPERANDS("w", pdfContext, 1); |
2071 POP_NUMBER(pdfContext, lw); | 2161 POP_NUMBER(pdfContext, lw); |
2072 CHECK_PARAMETERS(); | 2162 CHECK_PARAMETERS(); |
2073 | 2163 |
2074 return skpdfGraphicsStateApplyLW(pdfContext, lw); | 2164 return skpdfGraphicsStateApplyLW(pdfContext, lw); |
2075 } | 2165 } |
2076 | 2166 |
2077 //lineCap J Set the line cap style in the graphics state (see “Line Cap Style” o
n page 153). | 2167 //lineCap J Set the line cap style in the graphics state (see “Line Cap Style” o
n page 153). |
2078 static SkPdfResult PdfOp_J(SkPdfContext* pdfContext, SkCanvas* canvas, PdfTokenL
ooper** looper) { | 2168 static SkPdfResult PdfOp_J(SkPdfContext* pdfContext, SkCanvas* canvas, PdfTokenL
ooper** looper) { |
2079 // TODO(edisonn): round/ceil to int? | 2169 // TODO(edisonn): round/ceil to int? |
2080 EXPECT_OPERANDS(pdfContext, 1); | 2170 EXPECT_OPERANDS("J", pdfContext, 1); |
2081 POP_NUMBER(pdfContext, lc); | 2171 POP_NUMBER(pdfContext, lc); |
2082 CHECK_PARAMETERS(); | 2172 CHECK_PARAMETERS(); |
2083 | 2173 |
2084 return skpdfGraphicsStateApplyLC(pdfContext, (int)lc); | 2174 return skpdfGraphicsStateApplyLC(pdfContext, (int)lc); |
2085 } | 2175 } |
2086 | 2176 |
2087 //lineJoin j Set the line join style in the graphics state (see “Line Join Style
” on page 153). | 2177 //lineJoin j Set the line join style in the graphics state (see “Line Join Style
” on page 153). |
2088 static SkPdfResult PdfOp_j(SkPdfContext* pdfContext, SkCanvas* canvas, PdfTokenL
ooper** looper) { | 2178 static SkPdfResult PdfOp_j(SkPdfContext* pdfContext, SkCanvas* canvas, PdfTokenL
ooper** looper) { |
2089 // TODO(edisonn): round/ceil to int? | 2179 // TODO(edisonn): round/ceil to int? |
2090 EXPECT_OPERANDS(pdfContext, 1); | 2180 EXPECT_OPERANDS("j", pdfContext, 1); |
2091 POP_NUMBER(pdfContext, lj); | 2181 POP_NUMBER(pdfContext, lj); |
2092 CHECK_PARAMETERS(); | 2182 CHECK_PARAMETERS(); |
2093 | 2183 |
2094 return skpdfGraphicsStateApplyLJ(pdfContext, (int)lj); | 2184 return skpdfGraphicsStateApplyLJ(pdfContext, (int)lj); |
2095 } | 2185 } |
2096 | 2186 |
2097 //miterLimit M Set the miter limit in the graphics state (see “Miter Limit” on p
age 153). | 2187 //miterLimit M Set the miter limit in the graphics state (see “Miter Limit” on p
age 153). |
2098 static SkPdfResult PdfOp_M(SkPdfContext* pdfContext, SkCanvas* canvas, PdfTokenL
ooper** looper) { | 2188 static SkPdfResult PdfOp_M(SkPdfContext* pdfContext, SkCanvas* canvas, PdfTokenL
ooper** looper) { |
2099 EXPECT_OPERANDS(pdfContext, 1); | 2189 EXPECT_OPERANDS("M", pdfContext, 1); |
2100 POP_NUMBER(pdfContext, ml); | 2190 POP_NUMBER(pdfContext, ml); |
2101 CHECK_PARAMETERS(); | 2191 CHECK_PARAMETERS(); |
2102 return skpdfGraphicsStateApplyML(pdfContext, ml); | 2192 return skpdfGraphicsStateApplyML(pdfContext, ml); |
2103 } | 2193 } |
2104 | 2194 |
2105 //dashArray dashPhase d Set the line dash pattern in the graphics state (see “Li
ne Dash Pattern” on | 2195 //dashArray dashPhase d Set the line dash pattern in the graphics state (see “Li
ne Dash Pattern” on |
2106 //page 155). | 2196 //page 155). |
2107 static SkPdfResult PdfOp_d(SkPdfContext* pdfContext, SkCanvas* canvas, PdfTokenL
ooper** looper) { | 2197 static SkPdfResult PdfOp_d(SkPdfContext* pdfContext, SkCanvas* canvas, PdfTokenL
ooper** looper) { |
2108 EXPECT_OPERANDS(pdfContext, 2); | 2198 EXPECT_OPERANDS("d", pdfContext, 2); |
2109 POP_OBJ(pdfContext, phase); | 2199 POP_OBJ(pdfContext, phase); |
2110 POP_ARRAY(pdfContext, array); | 2200 POP_ARRAY(pdfContext, array); |
2111 CHECK_PARAMETERS(); | 2201 CHECK_PARAMETERS(); |
2112 | 2202 |
2113 return skpdfGraphicsStateApplyD(pdfContext, array, phase); | 2203 return skpdfGraphicsStateApplyD(pdfContext, array, phase); |
2114 } | 2204 } |
2115 | 2205 |
2116 //intent ri (PDF 1.1) Set the color rendering intent in the graphics state (see
“Rendering Intents” on page 197). | 2206 //intent ri (PDF 1.1) Set the color rendering intent in the graphics state (see
“Rendering Intents” on page 197). |
2117 static SkPdfResult PdfOp_ri(SkPdfContext* pdfContext, SkCanvas* canvas, PdfToken
Looper** looper) { | 2207 static SkPdfResult PdfOp_ri(SkPdfContext* pdfContext, SkCanvas* canvas, PdfToken
Looper** looper) { |
2118 pdfContext->fObjectStack.pop(); | 2208 pdfContext->fObjectStack.pop(); |
2119 | 2209 |
| 2210 SkPdfReport(kCodeWarning_SkPdfIssueSeverity, kNYI_SkPdfIssue, "render intent
NYI", NULL, pdfContext); |
| 2211 |
2120 return kNYI_SkPdfResult; | 2212 return kNYI_SkPdfResult; |
2121 } | 2213 } |
2122 | 2214 |
2123 //flatness i Set the flatness tolerance in the graphics state (see Section 6.5.1,
“Flatness | 2215 //flatness i Set the flatness tolerance in the graphics state (see Section 6.5.1,
“Flatness |
2124 //Tolerance”). flatness is a number in the range 0 to 100; a value of 0 speci- | 2216 //Tolerance”). flatness is a number in the range 0 to 100; a value of 0 speci- |
2125 //fies the output device’s default flatness tolerance. | 2217 //fies the output device’s default flatness tolerance. |
2126 static SkPdfResult PdfOp_i(SkPdfContext* pdfContext, SkCanvas* canvas, PdfTokenL
ooper** looper) { | 2218 static SkPdfResult PdfOp_i(SkPdfContext* pdfContext, SkCanvas* canvas, PdfTokenL
ooper** looper) { |
2127 EXPECT_OPERANDS(pdfContext, 1); | 2219 EXPECT_OPERANDS("i", pdfContext, 1); |
2128 POP_NUMBER(pdfContext, flatness); | 2220 POP_NUMBER(pdfContext, flatness); |
2129 CHECK_PARAMETERS(); | 2221 CHECK_PARAMETERS(); |
2130 | 2222 |
2131 if (flatness < 0 || flatness > 100) { | 2223 if (flatness < 0 || flatness > 100) { |
2132 return kError_SkPdfResult; | 2224 SkPdfReport(kIgnoreError_SkPdfIssueSeverity, kOutOfRange_SkPdfIssue, "fl
atness must be a real in [0, 100] range", flatness_obj, pdfContext); |
| 2225 return kIgnoreError_SkPdfResult; |
2133 } | 2226 } |
2134 | 2227 |
2135 return kNYI_SkPdfResult; | 2228 return kNYI_SkPdfResult; |
2136 } | 2229 } |
2137 | 2230 |
2138 SkTDict<SkXfermode::Mode> gPdfBlendModes(20); | 2231 SkTDict<SkXfermode::Mode> gPdfBlendModes(20); |
2139 | 2232 |
2140 class InitBlendModes { | 2233 class InitBlendModes { |
2141 public: | 2234 public: |
2142 InitBlendModes() { | 2235 InitBlendModes() { |
(...skipping 30 matching lines...) Expand all Loading... |
2173 | 2266 |
2174 return (SkXfermode::Mode)(SkXfermode::kLastMode + 1); | 2267 return (SkXfermode::Mode)(SkXfermode::kLastMode + 1); |
2175 } | 2268 } |
2176 | 2269 |
2177 static void skpdfGraphicsStateApplyBM_name(SkPdfContext* pdfContext, const SkStr
ing& blendMode) { | 2270 static void skpdfGraphicsStateApplyBM_name(SkPdfContext* pdfContext, const SkStr
ing& blendMode) { |
2178 SkXfermode::Mode mode = xferModeFromBlendMode(blendMode.c_str(), blendMode.s
ize()); | 2271 SkXfermode::Mode mode = xferModeFromBlendMode(blendMode.c_str(), blendMode.s
ize()); |
2179 if (mode <= SkXfermode::kLastMode) { | 2272 if (mode <= SkXfermode::kLastMode) { |
2180 pdfContext->fGraphicsState.fBlendModesLength = 1; | 2273 pdfContext->fGraphicsState.fBlendModesLength = 1; |
2181 pdfContext->fGraphicsState.fBlendModes[0] = mode; | 2274 pdfContext->fGraphicsState.fBlendModes[0] = mode; |
2182 } else { | 2275 } else { |
2183 // TODO(edisonn): report unknown blend mode | 2276 SkPdfReport(kIgnoreError_SkPdfIssueSeverity, kUnknownBlendMode_SkPdfIssu
e, blendMode.c_str(), NULL, pdfContext); |
2184 } | 2277 } |
2185 } | 2278 } |
2186 | 2279 |
2187 static void skpdfGraphicsStateApplyBM_array(SkPdfContext* pdfContext, SkPdfArray
* blendModes) { | 2280 static void skpdfGraphicsStateApplyBM_array(SkPdfContext* pdfContext, SkPdfArray
* blendModes) { |
2188 if (!blendModes || blendModes->isArray() || blendModes->size() == 0 || blend
Modes->size() > 256) { | 2281 if (!blendModes || !blendModes->isArray()) { |
2189 // TODO(edisonn): report error/warning | 2282 SkPdfReportUnexpectedType(kIgnoreError_SkPdfIssueSeverity, NULL, blendMo
des, SkPdfNativeObject::kArray_PdfObjectType, pdfContext); |
2190 return; | 2283 return; |
2191 } | 2284 } |
| 2285 |
| 2286 if (blendModes->size() == 0 || blendModes->size() > 256) { |
| 2287 SkPdfReport(kIgnoreError_SkPdfIssueSeverity, kIncostistentSizes_SkPdfIss
ue, "length of blendmodes, 0, is an erro, 256+, is NYI", blendModes, pdfContext)
; |
| 2288 return; |
| 2289 } |
| 2290 |
2192 SkXfermode::Mode modes[256]; | 2291 SkXfermode::Mode modes[256]; |
2193 int cnt = blendModes->size(); | 2292 int cnt = blendModes->size(); |
2194 for (int i = 0; i < cnt; i++) { | 2293 for (int i = 0; i < cnt; i++) { |
2195 SkPdfNativeObject* name = blendModes->objAtAIndex(i); | 2294 SkPdfNativeObject* name = blendModes->objAtAIndex(i); |
2196 if (!name->isName()) { | 2295 if (!name || !name->isName()) { |
2197 // TODO(edisonn): report error/warning | 2296 SkPdfReportUnexpectedType(kIgnoreError_SkPdfIssueSeverity, NULL, nam
e, SkPdfNativeObject::kName_PdfObjectType, pdfContext); |
2198 return; | 2297 return; |
2199 } | 2298 } |
2200 SkXfermode::Mode mode = xferModeFromBlendMode(name->c_str(), name->lenst
r()); | 2299 SkXfermode::Mode mode = xferModeFromBlendMode(name->c_str(), name->lenst
r()); |
2201 if (mode > SkXfermode::kLastMode) { | 2300 if (mode > SkXfermode::kLastMode) { |
2202 // TODO(edisonn): report error/warning | 2301 SkPdfReport(kIgnoreError_SkPdfIssueSeverity, kUnknownBlendMode_SkPdf
Issue, NULL, name, pdfContext); |
2203 return; | 2302 return; |
2204 } | 2303 } |
2205 } | 2304 } |
2206 | 2305 |
2207 pdfContext->fGraphicsState.fBlendModesLength = cnt; | 2306 pdfContext->fGraphicsState.fBlendModesLength = cnt; |
2208 for (int i = 0; i < cnt; i++) { | 2307 for (int i = 0; i < cnt; i++) { |
2209 pdfContext->fGraphicsState.fBlendModes[i] = modes[i]; | 2308 pdfContext->fGraphicsState.fBlendModes[i] = modes[i]; |
2210 } | 2309 } |
2211 } | 2310 } |
2212 | 2311 |
2213 static void skpdfGraphicsStateApplySMask_dict(SkPdfContext* pdfContext, SkPdfDic
tionary* sMask) { | 2312 static void skpdfGraphicsStateApplySMask_dict(SkPdfContext* pdfContext, SkPdfDic
tionary* sMask) { |
2214 // TODO(edisonn): verify input | 2313 if (!sMask || !sMask->isName()) { |
| 2314 SkPdfReportUnexpectedType(kIgnoreError_SkPdfIssueSeverity, NULL, sMask,
SkPdfNativeObject::kArray_PdfObjectType, pdfContext); |
| 2315 return; |
| 2316 } |
| 2317 |
2215 if (pdfContext->fPdfDoc->mapper()->mapSoftMaskDictionary(sMask)) { | 2318 if (pdfContext->fPdfDoc->mapper()->mapSoftMaskDictionary(sMask)) { |
2216 pdfContext->fGraphicsState.fSoftMaskDictionary = (SkPdfSoftMaskDictionar
y*)sMask; | 2319 pdfContext->fGraphicsState.fSoftMaskDictionary = (SkPdfSoftMaskDictionar
y*)sMask; |
2217 } else if (pdfContext->fPdfDoc->mapper()->mapSoftMaskImageDictionary(sMask))
{ | 2320 } else if (pdfContext->fPdfDoc->mapper()->mapSoftMaskImageDictionary(sMask))
{ |
2218 SkPdfSoftMaskImageDictionary* smid = (SkPdfSoftMaskImageDictionary*)sMas
k; | 2321 SkPdfSoftMaskImageDictionary* smid = (SkPdfSoftMaskImageDictionary*)sMas
k; |
2219 pdfContext->fGraphicsState.fSMask = getImageFromObject(pdfContext, smid,
true); | 2322 pdfContext->fGraphicsState.fSMask = getImageFromObject(pdfContext, smid,
true); |
2220 } else { | 2323 } else { |
2221 // TODO (edisonn): report error/warning | 2324 // TODO(edisonn): make the dictionary types an enum? |
| 2325 SkPdfReportUnexpectedType(kIgnoreError_SkPdfIssueSeverity, "Dictionary m
ust be SoftMask, or SoftMaskImage", sMask, SkPdfNativeObject::kDictionary_PdfObj
ectType, pdfContext); |
2222 } | 2326 } |
2223 } | 2327 } |
2224 | 2328 |
2225 static void skpdfGraphicsStateApplySMask_name(SkPdfContext* pdfContext, const Sk
String& sMask) { | 2329 static void skpdfGraphicsStateApplySMask_name(SkPdfContext* pdfContext, const Sk
String& sMask) { |
2226 if (sMask.equals("None")) { | 2330 if (sMask.equals("None")) { |
2227 pdfContext->fGraphicsState.fSoftMaskDictionary = NULL; | 2331 pdfContext->fGraphicsState.fSoftMaskDictionary = NULL; |
2228 pdfContext->fGraphicsState.fSMask = NULL; | 2332 pdfContext->fGraphicsState.fSMask = NULL; |
2229 return; | 2333 return; |
2230 } | 2334 } |
2231 | 2335 |
2232 //Next, get the ExtGState Dictionary from the Resource Dictionary: | 2336 //Next, get the ExtGState Dictionary from the Resource Dictionary: |
2233 SkPdfDictionary* extGStateDictionary = pdfContext->fGraphicsState.fResources
->ExtGState(pdfContext->fPdfDoc); | 2337 SkPdfDictionary* extGStateDictionary = pdfContext->fGraphicsState.fResources
->ExtGState(pdfContext->fPdfDoc); |
2234 | 2338 |
2235 if (extGStateDictionary == NULL) { | 2339 if (extGStateDictionary == NULL) { |
2236 #ifdef PDF_TRACE | 2340 SkPdfReport(kIgnoreError_SkPdfIssueSeverity, kMissingExtGState_SkPdfIssu
e, NULL, pdfContext->fGraphicsState.fResources, pdfContext); |
2237 printf("ExtGState is NULL!\n"); | |
2238 #endif | |
2239 // TODO (edisonn): report error/warning | |
2240 return; | 2341 return; |
2241 } | 2342 } |
2242 | 2343 |
2243 SkPdfNativeObject* obj = pdfContext->fPdfDoc->resolveReference(extGStateDict
ionary->get(sMask.c_str())); | 2344 SkPdfNativeObject* obj = pdfContext->fPdfDoc->resolveReference(extGStateDict
ionary->get(sMask.c_str())); |
2244 if (!obj || !obj->isDictionary()) { | 2345 if (!obj || !obj->isDictionary()) { |
2245 // TODO (edisonn): report error/warning | 2346 SkPdfReportUnexpectedType(kIgnoreError_SkPdfIssueSeverity, NULL, obj, Sk
PdfNativeObject::kDictionary_PdfObjectType, pdfContext); |
2246 return; | 2347 return; |
2247 } | 2348 } |
2248 | 2349 |
2249 pdfContext->fGraphicsState.fSoftMaskDictionary = NULL; | 2350 pdfContext->fGraphicsState.fSoftMaskDictionary = NULL; |
2250 pdfContext->fGraphicsState.fSMask = NULL; | 2351 pdfContext->fGraphicsState.fSMask = NULL; |
2251 | 2352 |
2252 skpdfGraphicsStateApplySMask_dict(pdfContext, obj->asDictionary()); | 2353 skpdfGraphicsStateApplySMask_dict(pdfContext, obj->asDictionary()); |
2253 } | 2354 } |
2254 | 2355 |
2255 static void skpdfGraphicsStateApplyAIS(SkPdfContext* pdfContext, bool alphaSourc
e) { | 2356 static void skpdfGraphicsStateApplyAIS(SkPdfContext* pdfContext, bool alphaSourc
e) { |
2256 pdfContext->fGraphicsState.fAlphaSource = alphaSource; | 2357 pdfContext->fGraphicsState.fAlphaSource = alphaSource; |
2257 } | 2358 } |
2258 | 2359 |
2259 | 2360 |
2260 //dictName gs (PDF 1.2) Set the specified parameters in the graphics state. dictN
ame is | 2361 //dictName gs (PDF 1.2) Set the specified parameters in the graphics state. dictN
ame is |
2261 //the name of a graphics state parameter dictionary in the ExtGState subdictiona
ry of the current resource dictionary (see the next section). | 2362 //the name of a graphics state parameter dictionary in the ExtGState subdictiona
ry of the current resource dictionary (see the next section). |
2262 static SkPdfResult PdfOp_gs(SkPdfContext* pdfContext, SkCanvas* canvas, PdfToken
Looper** looper) { | 2363 static SkPdfResult PdfOp_gs(SkPdfContext* pdfContext, SkCanvas* canvas, PdfToken
Looper** looper) { |
2263 EXPECT_OPERANDS(pdfContext, 1); | 2364 EXPECT_OPERANDS("gs", pdfContext, 1); |
2264 POP_NAME(pdfContext, name); | 2365 POP_NAME(pdfContext, name); |
2265 CHECK_PARAMETERS(); | 2366 CHECK_PARAMETERS(); |
2266 | 2367 |
2267 #ifdef PDF_TRACE | 2368 #ifdef PDF_TRACE |
2268 SkString str; | 2369 SkString str; |
2269 #endif | 2370 #endif |
2270 | 2371 |
2271 //Next, get the ExtGState Dictionary from the Resource Dictionary: | 2372 //Next, get the ExtGState Dictionary from the Resource Dictionary: |
2272 SkPdfDictionary* extGStateDictionary = pdfContext->fGraphicsState.fResources
->ExtGState(pdfContext->fPdfDoc); | 2373 SkPdfDictionary* extGStateDictionary = pdfContext->fGraphicsState.fResources
->ExtGState(pdfContext->fPdfDoc); |
2273 | 2374 |
2274 if (extGStateDictionary == NULL) { | 2375 if (extGStateDictionary == NULL) { |
2275 #ifdef PDF_TRACE | 2376 SkPdfReport(kIgnoreError_SkPdfIssueSeverity, kMissingExtGState_SkPdfIssu
e, NULL, pdfContext->fGraphicsState.fResources, pdfContext); |
2276 printf("ExtGState is NULL!\n"); | |
2277 #endif | |
2278 return kIgnoreError_SkPdfResult; | 2377 return kIgnoreError_SkPdfResult; |
2279 } | 2378 } |
2280 | 2379 |
2281 SkPdfNativeObject* value = pdfContext->fPdfDoc->resolveReference(extGStateDi
ctionary->get(name)); | 2380 SkPdfNativeObject* value = pdfContext->fPdfDoc->resolveReference(extGStateDi
ctionary->get(name)); |
2282 | 2381 |
2283 if (kNone_SkPdfNativeObjectType == pdfContext->fPdfDoc->mapper()->mapGraphic
sStateDictionary(value)) { | 2382 if (kNone_SkPdfNativeObjectType == pdfContext->fPdfDoc->mapper()->mapGraphic
sStateDictionary(value)) { |
2284 return kIgnoreError_SkPdfResult; | 2383 return kIgnoreError_SkPdfResult; |
2285 } | 2384 } |
2286 SkPdfGraphicsStateDictionary* gs = (SkPdfGraphicsStateDictionary*)value; | 2385 SkPdfGraphicsStateDictionary* gs = (SkPdfGraphicsStateDictionary*)value; |
2287 | 2386 |
2288 // TODO(edisonn): now load all those properties in graphic state. | 2387 // TODO(edisonn): now load all those properties in graphic state. |
2289 if (gs == NULL) { | 2388 if (gs == NULL) { |
| 2389 SkPdfReportUnexpectedType(kIgnoreError_SkPdfIssueSeverity, NULL, gs, SkP
dfNativeObject::kDictionary_PdfObjectType, pdfContext); |
2290 return kIgnoreError_SkPdfResult; | 2390 return kIgnoreError_SkPdfResult; |
2291 } | 2391 } |
2292 | 2392 |
2293 if (gs->has_LW()) { | 2393 if (gs->has_LW()) { |
2294 skpdfGraphicsStateApplyLW(pdfContext, gs->LW(pdfContext->fPdfDoc)); | 2394 skpdfGraphicsStateApplyLW(pdfContext, gs->LW(pdfContext->fPdfDoc)); |
2295 } | 2395 } |
2296 | 2396 |
2297 if (gs->has_LC()) { | 2397 if (gs->has_LC()) { |
2298 skpdfGraphicsStateApplyLC(pdfContext, gs->LC(pdfContext->fPdfDoc)); | 2398 skpdfGraphicsStateApplyLC(pdfContext, gs->LC(pdfContext->fPdfDoc)); |
2299 } | 2399 } |
(...skipping 13 matching lines...) Expand all Loading... |
2313 if (gs->has_Font()) { | 2413 if (gs->has_Font()) { |
2314 skpdfGraphicsStateApplyFont(pdfContext, gs->Font(pdfContext->fPdfDoc)); | 2414 skpdfGraphicsStateApplyFont(pdfContext, gs->Font(pdfContext->fPdfDoc)); |
2315 } | 2415 } |
2316 | 2416 |
2317 if (gs->has_BM()) { | 2417 if (gs->has_BM()) { |
2318 if (gs->isBMAName(pdfContext->fPdfDoc)) { | 2418 if (gs->isBMAName(pdfContext->fPdfDoc)) { |
2319 skpdfGraphicsStateApplyBM_name(pdfContext, gs->getBMAsName(pdfContex
t->fPdfDoc)); | 2419 skpdfGraphicsStateApplyBM_name(pdfContext, gs->getBMAsName(pdfContex
t->fPdfDoc)); |
2320 } else if (gs->isBMAArray(pdfContext->fPdfDoc)) { | 2420 } else if (gs->isBMAArray(pdfContext->fPdfDoc)) { |
2321 skpdfGraphicsStateApplyBM_array(pdfContext, gs->getBMAsArray(pdfCont
ext->fPdfDoc)); | 2421 skpdfGraphicsStateApplyBM_array(pdfContext, gs->getBMAsArray(pdfCont
ext->fPdfDoc)); |
2322 } else { | 2422 } else { |
2323 // TODO(edisonn): report/warn | 2423 SkPdfReportUnexpectedType(kIgnoreError_SkPdfIssueSeverity, "wrong ty
pe", gs->get("BM"), SkPdfNativeObject::kArray_PdfObjectType || SkPdfNativeObject
::kName_PdfObjectType, pdfContext); |
2324 } | 2424 } |
2325 } | 2425 } |
2326 | 2426 |
2327 if (gs->has_SMask()) { | 2427 if (gs->has_SMask()) { |
2328 if (gs->isSMaskAName(pdfContext->fPdfDoc)) { | 2428 if (gs->isSMaskAName(pdfContext->fPdfDoc)) { |
2329 skpdfGraphicsStateApplySMask_name(pdfContext, gs->getSMaskAsName(pdf
Context->fPdfDoc)); | 2429 skpdfGraphicsStateApplySMask_name(pdfContext, gs->getSMaskAsName(pdf
Context->fPdfDoc)); |
2330 } else if (gs->isSMaskADictionary(pdfContext->fPdfDoc)) { | 2430 } else if (gs->isSMaskADictionary(pdfContext->fPdfDoc)) { |
2331 skpdfGraphicsStateApplySMask_dict(pdfContext, gs->getSMaskAsDictiona
ry(pdfContext->fPdfDoc)); | 2431 skpdfGraphicsStateApplySMask_dict(pdfContext, gs->getSMaskAsDictiona
ry(pdfContext->fPdfDoc)); |
2332 } else { | 2432 } else { |
2333 // TODO(edisonn): report/warn | 2433 SkPdfReportUnexpectedType(kIgnoreError_SkPdfIssueSeverity, "wrong ty
pe", gs->get("BM"), SkPdfNativeObject::kDictionary_PdfObjectType || SkPdfNativeO
bject::kName_PdfObjectType, pdfContext); |
2334 } | 2434 } |
2335 } | 2435 } |
2336 | 2436 |
2337 if (gs->has_ca()) { | 2437 if (gs->has_ca()) { |
2338 skpdfGraphicsStateApply_ca(pdfContext, gs->ca(pdfContext->fPdfDoc)); | 2438 skpdfGraphicsStateApply_ca(pdfContext, gs->ca(pdfContext->fPdfDoc)); |
2339 } | 2439 } |
2340 | 2440 |
2341 if (gs->has_CA()) { | 2441 if (gs->has_CA()) { |
2342 skpdfGraphicsStateApply_CA(pdfContext, gs->CA(pdfContext->fPdfDoc)); | 2442 skpdfGraphicsStateApply_CA(pdfContext, gs->CA(pdfContext->fPdfDoc)); |
2343 } | 2443 } |
2344 | 2444 |
2345 if (gs->has_AIS()) { | 2445 if (gs->has_AIS()) { |
2346 skpdfGraphicsStateApplyAIS(pdfContext, gs->AIS(pdfContext->fPdfDoc)); | 2446 skpdfGraphicsStateApplyAIS(pdfContext, gs->AIS(pdfContext->fPdfDoc)); |
2347 } | 2447 } |
2348 | 2448 |
2349 return kOK_SkPdfResult; | 2449 return kOK_SkPdfResult; |
2350 } | 2450 } |
2351 | 2451 |
2352 //charSpace Tc Set the character spacing, Tc | 2452 //charSpace Tc Set the character spacing, Tc |
2353 //, to charSpace, which is a number expressed in unscaled text space units. Char
acter spacing is used by the Tj, TJ, and ' operators. | 2453 //, to charSpace, which is a number expressed in unscaled text space units. Char
acter spacing is used by the Tj, TJ, and ' operators. |
2354 //Initial value: 0. | 2454 //Initial value: 0. |
2355 SkPdfResult PdfOp_Tc(SkPdfContext* pdfContext, SkCanvas* canvas, PdfTokenLooper*
* looper) { | 2455 SkPdfResult PdfOp_Tc(SkPdfContext* pdfContext, SkCanvas* canvas, PdfTokenLooper*
* looper) { |
2356 EXPECT_OPERANDS(pdfContext, 1); | 2456 EXPECT_OPERANDS("Tc", pdfContext, 1); |
2357 POP_NUMBER(pdfContext, charSpace); | 2457 POP_NUMBER(pdfContext, charSpace); |
2358 CHECK_PARAMETERS(); | 2458 CHECK_PARAMETERS(); |
2359 | 2459 |
2360 pdfContext->fGraphicsState.fCharSpace = charSpace; | 2460 pdfContext->fGraphicsState.fCharSpace = charSpace; |
2361 | 2461 |
2362 return kOK_SkPdfResult; | 2462 return kOK_SkPdfResult; |
2363 } | 2463 } |
2364 | 2464 |
2365 //wordSpace Tw Set the word spacing, T | 2465 //wordSpace Tw Set the word spacing, T |
2366 //w | 2466 //w |
2367 //, to wordSpace, which is a number expressed in unscaled | 2467 //, to wordSpace, which is a number expressed in unscaled |
2368 //text space units. Word spacing is used by the Tj, TJ, and ' operators. Initial | 2468 //text space units. Word spacing is used by the Tj, TJ, and ' operators. Initial |
2369 //value: 0. | 2469 //value: 0. |
2370 SkPdfResult PdfOp_Tw(SkPdfContext* pdfContext, SkCanvas* canvas, PdfTokenLooper*
* looper) { | 2470 SkPdfResult PdfOp_Tw(SkPdfContext* pdfContext, SkCanvas* canvas, PdfTokenLooper*
* looper) { |
2371 EXPECT_OPERANDS(pdfContext, 1); | 2471 EXPECT_OPERANDS("Tw", pdfContext, 1); |
2372 POP_NUMBER(pdfContext, wordSpace); | 2472 POP_NUMBER(pdfContext, wordSpace); |
2373 CHECK_PARAMETERS(); | 2473 CHECK_PARAMETERS(); |
2374 | 2474 |
2375 pdfContext->fGraphicsState.fWordSpace = wordSpace; | 2475 pdfContext->fGraphicsState.fWordSpace = wordSpace; |
2376 | 2476 |
2377 return kOK_SkPdfResult; | 2477 return kOK_SkPdfResult; |
2378 } | 2478 } |
2379 | 2479 |
2380 //scale Tz Set the horizontal scaling, Th | 2480 //scale Tz Set the horizontal scaling, Th |
2381 //, to (scale ˜ 100). scale is a number specifying the | 2481 //, to (scale ˜ 100). scale is a number specifying the |
2382 //percentage of the normal width. Initial value: 100 (normal width). | 2482 //percentage of the normal width. Initial value: 100 (normal width). |
2383 static SkPdfResult PdfOp_Tz(SkPdfContext* pdfContext, SkCanvas* canvas, PdfToken
Looper** looper) { | 2483 static SkPdfResult PdfOp_Tz(SkPdfContext* pdfContext, SkCanvas* canvas, PdfToken
Looper** looper) { |
2384 EXPECT_OPERANDS(pdfContext, 1); | 2484 EXPECT_OPERANDS("Tz", pdfContext, 1); |
2385 POP_NUMBER(pdfContext, scale); | 2485 POP_NUMBER(pdfContext, scale); |
2386 CHECK_PARAMETERS(); | 2486 CHECK_PARAMETERS(); |
2387 | 2487 |
2388 if (scale < 0) { | 2488 if (scale < 0) { |
| 2489 SkPdfReport(kIgnoreError_SkPdfIssueSeverity, kOutOfRange_SkPdfIssue, "sc
ale must a positive real number", scale_obj, pdfContext); |
2389 return kError_SkPdfResult; | 2490 return kError_SkPdfResult; |
2390 } | 2491 } |
2391 | 2492 |
2392 return kNYI_SkPdfResult; | 2493 return kNYI_SkPdfResult; |
2393 } | 2494 } |
2394 | 2495 |
2395 //render Tr Set the text rendering mode, T | 2496 //render Tr Set the text rendering mode, T |
2396 //mode, to render, which is an integer. Initial value: 0. | 2497 //mode, to render, which is an integer. Initial value: 0. |
2397 static SkPdfResult PdfOp_Tr(SkPdfContext* pdfContext, SkCanvas* canvas, PdfToken
Looper** looper) { | 2498 static SkPdfResult PdfOp_Tr(SkPdfContext* pdfContext, SkCanvas* canvas, PdfToken
Looper** looper) { |
2398 EXPECT_OPERANDS(pdfContext, 1); | 2499 EXPECT_OPERANDS("Tr", pdfContext, 1); |
2399 POP_INTEGER(pdfContext, mode); | 2500 POP_INTEGER(pdfContext, mode); |
2400 CHECK_PARAMETERS(); | 2501 CHECK_PARAMETERS(); |
2401 | 2502 |
2402 if (mode < 0) { // TODO(edisonn): function/enums with supported modes | 2503 if (mode < 0) { // TODO(edisonn): function/enums with supported modes |
| 2504 SkPdfReport(kIgnoreError_SkPdfIssueSeverity, kOutOfRange_SkPdfIssue, "mo
de must a positive integer or 0", mode_obj, pdfContext); |
2403 return kError_SkPdfResult; | 2505 return kError_SkPdfResult; |
2404 } | 2506 } |
2405 | 2507 |
2406 return kNYI_SkPdfResult; | 2508 return kNYI_SkPdfResult; |
2407 } | 2509 } |
2408 //rise Ts Set the text rise, Trise, to rise, which is a number expressed in unsc
aled text space | 2510 //rise Ts Set the text rise, Trise, to rise, which is a number expressed in unsc
aled text space |
2409 //units. Initial value: 0. | 2511 //units. Initial value: 0. |
2410 static SkPdfResult PdfOp_Ts(SkPdfContext* pdfContext, SkCanvas* canvas, PdfToken
Looper** looper) { | 2512 static SkPdfResult PdfOp_Ts(SkPdfContext* pdfContext, SkCanvas* canvas, PdfToken
Looper** looper) { |
2411 EXPECT_OPERANDS(pdfContext, 1); | 2513 EXPECT_OPERANDS("Ts", pdfContext, 1); |
2412 POP_NUMBER(pdfContext, rise); | 2514 POP_NUMBER(pdfContext, rise); |
2413 CHECK_PARAMETERS(); | 2515 CHECK_PARAMETERS(); |
2414 | 2516 |
2415 if (rise < 0) { | 2517 if (rise < 0) { |
| 2518 SkPdfReport(kIgnoreError_SkPdfIssueSeverity, kOutOfRange_SkPdfIssue, "ri
se must a positive real number", rise_obj, pdfContext); |
2416 return kNYI_SkPdfResult; | 2519 return kNYI_SkPdfResult; |
2417 } | 2520 } |
2418 | 2521 |
2419 return kNYI_SkPdfResult; | 2522 return kNYI_SkPdfResult; |
2420 } | 2523 } |
2421 | 2524 |
2422 //wx wy d0 | 2525 //wx wy d0 |
2423 static SkPdfResult PdfOp_d0(SkPdfContext* pdfContext, SkCanvas* canvas, PdfToken
Looper** looper) { | 2526 static SkPdfResult PdfOp_d0(SkPdfContext* pdfContext, SkCanvas* canvas, PdfToken
Looper** looper) { |
2424 EXPECT_OPERANDS(pdfContext, 2); | 2527 EXPECT_OPERANDS("d0", pdfContext, 2); |
2425 POP_NUMBER(pdfContext, wy); | 2528 POP_NUMBER(pdfContext, wy); |
2426 POP_NUMBER(pdfContext, wx); | 2529 POP_NUMBER(pdfContext, wx); |
2427 CHECK_PARAMETERS(); | 2530 CHECK_PARAMETERS(); |
2428 | 2531 |
2429 if (wx < 0 || wy < 0) { | 2532 if (wx < 0) { |
| 2533 SkPdfReport(kIgnoreError_SkPdfIssueSeverity, kOutOfRange_SkPdfIssue, "wx
must a positive real number", wx_obj, pdfContext); |
| 2534 return kError_SkPdfResult; |
| 2535 } |
| 2536 |
| 2537 if (wy < 0) { |
| 2538 SkPdfReport(kIgnoreError_SkPdfIssueSeverity, kOutOfRange_SkPdfIssue, "wy
must a positive real number", wy_obj, pdfContext); |
2430 return kError_SkPdfResult; | 2539 return kError_SkPdfResult; |
2431 } | 2540 } |
2432 | 2541 |
2433 return kNYI_SkPdfResult; | 2542 return kNYI_SkPdfResult; |
2434 } | 2543 } |
2435 | 2544 |
2436 //wx wy llx lly urx ury d1 | 2545 //wx wy llx lly urx ury d1 |
2437 static SkPdfResult PdfOp_d1(SkPdfContext* pdfContext, SkCanvas* canvas, PdfToken
Looper** looper) { | 2546 static SkPdfResult PdfOp_d1(SkPdfContext* pdfContext, SkCanvas* canvas, PdfToken
Looper** looper) { |
2438 EXPECT_OPERANDS(pdfContext, 6); | 2547 EXPECT_OPERANDS("d1", pdfContext, 6); |
2439 POP_NUMBER(pdfContext, ury); | 2548 POP_NUMBER(pdfContext, ury); |
2440 POP_NUMBER(pdfContext, urx); | 2549 POP_NUMBER(pdfContext, urx); |
2441 POP_NUMBER(pdfContext, lly); | 2550 POP_NUMBER(pdfContext, lly); |
2442 POP_NUMBER(pdfContext, llx); | 2551 POP_NUMBER(pdfContext, llx); |
2443 POP_NUMBER(pdfContext, wy); | 2552 POP_NUMBER(pdfContext, wy); |
2444 POP_NUMBER(pdfContext, wx); | 2553 POP_NUMBER(pdfContext, wx); |
2445 CHECK_PARAMETERS(); | 2554 CHECK_PARAMETERS(); |
2446 | 2555 |
| 2556 // TODO(edisonn): silly way to remove warning |
2447 if (wx + wy + llx + lly + urx + ury) { | 2557 if (wx + wy + llx + lly + urx + ury) { |
2448 return kNYI_SkPdfResult; | 2558 return kNYI_SkPdfResult; |
2449 } | 2559 } |
2450 | 2560 |
2451 return kNYI_SkPdfResult; | 2561 return kNYI_SkPdfResult; |
2452 } | 2562 } |
2453 | 2563 |
2454 //name sh | 2564 //name sh |
2455 static SkPdfResult PdfOp_sh(SkPdfContext* pdfContext, SkCanvas* canvas, PdfToken
Looper** looper) { | 2565 static SkPdfResult PdfOp_sh(SkPdfContext* pdfContext, SkCanvas* canvas, PdfToken
Looper** looper) { |
2456 EXPECT_OPERANDS(pdfContext, 1); | 2566 EXPECT_OPERANDS("sh", pdfContext, 1); |
2457 POP_NAME(pdfContext, name); | 2567 POP_NAME(pdfContext, name); |
2458 CHECK_PARAMETERS(); | 2568 CHECK_PARAMETERS(); |
2459 | 2569 |
2460 if (name == NULL) { | 2570 if (name == NULL) { |
| 2571 SkPdfReportUnexpectedType(kIgnoreError_SkPdfIssueSeverity, NULL, name, S
kPdfNativeObject::kName_PdfObjectType, pdfContext); |
2461 return kError_SkPdfResult; | 2572 return kError_SkPdfResult; |
2462 } | 2573 } |
2463 | 2574 |
2464 return kNYI_SkPdfResult; | 2575 return kNYI_SkPdfResult; |
2465 } | 2576 } |
2466 | 2577 |
2467 //name Do | 2578 //name Do |
2468 static SkPdfResult PdfOp_Do(SkPdfContext* pdfContext, SkCanvas* canvas, PdfToken
Looper** looper) { | 2579 static SkPdfResult PdfOp_Do(SkPdfContext* pdfContext, SkCanvas* canvas, PdfToken
Looper** looper) { |
2469 EXPECT_OPERANDS(pdfContext, 1); | 2580 EXPECT_OPERANDS("Do", pdfContext, 1); |
2470 POP_NAME(pdfContext, name); | 2581 POP_NAME(pdfContext, name); |
2471 CHECK_PARAMETERS(); | 2582 CHECK_PARAMETERS(); |
2472 | 2583 |
2473 SkPdfDictionary* xObject = pdfContext->fGraphicsState.fResources->XObject(p
dfContext->fPdfDoc); | 2584 SkPdfDictionary* xObject = pdfContext->fGraphicsState.fResources->XObject(p
dfContext->fPdfDoc); |
2474 | 2585 |
2475 if (xObject == NULL) { | 2586 if (xObject == NULL) { |
2476 #ifdef PDF_TRACE | 2587 SkPdfReport(kIgnoreError_SkPdfIssueSeverity, kMissingXObject_SkPdfIssue,
NULL, pdfContext->fGraphicsState.fResources, pdfContext); |
2477 printf("XObject is NULL!\n"); | |
2478 #endif | |
2479 return kIgnoreError_SkPdfResult; | 2588 return kIgnoreError_SkPdfResult; |
2480 } | 2589 } |
2481 | 2590 |
2482 SkPdfNativeObject* value = xObject->get(name); | 2591 SkPdfNativeObject* value = xObject->get(name); |
2483 value = pdfContext->fPdfDoc->resolveReference(value); | 2592 value = pdfContext->fPdfDoc->resolveReference(value); |
2484 | 2593 |
2485 #ifdef PDF_TRACE | |
2486 // value->ToString(str); | |
2487 // printf("Do object value: %s\n", str); | |
2488 #endif | |
2489 | |
2490 return doXObject(pdfContext, canvas, value); | 2594 return doXObject(pdfContext, canvas, value); |
2491 } | 2595 } |
2492 | 2596 |
2493 //tag MP Designate a marked-content point. tag is a name object indicating the r
ole or | 2597 //tag MP Designate a marked-content point. tag is a name object indicating the r
ole or |
2494 //significance of the point. | 2598 //significance of the point. |
2495 static SkPdfResult PdfOp_MP(SkPdfContext* pdfContext, SkCanvas* canvas, PdfToken
Looper** looper) { | 2599 static SkPdfResult PdfOp_MP(SkPdfContext* pdfContext, SkCanvas* canvas, PdfToken
Looper** looper) { |
2496 EXPECT_OPERANDS(pdfContext, 1); | 2600 EXPECT_OPERANDS("MP", pdfContext, 1); |
2497 POP_OBJ(pdfContext, tag); | 2601 POP_OBJ(pdfContext, tag); |
2498 CHECK_PARAMETERS(); | 2602 CHECK_PARAMETERS(); |
2499 | 2603 |
2500 if (tag == NULL) { | 2604 if (tag == NULL) { |
| 2605 SkPdfReportUnexpectedType(kIgnoreError_SkPdfIssueSeverity, NULL, tag, Sk
PdfNativeObject::_kObject_PdfObjectType, pdfContext); |
2501 return kNYI_SkPdfResult; | 2606 return kNYI_SkPdfResult; |
2502 } | 2607 } |
2503 | 2608 |
| 2609 SkPdfReport(kCodeWarning_SkPdfIssueSeverity, kNYI_SkPdfIssue, "MP NYI", NULL
, NULL); |
2504 return kNYI_SkPdfResult; | 2610 return kNYI_SkPdfResult; |
2505 } | 2611 } |
2506 | 2612 |
2507 //tag properties DP Designate a marked-content point with an associated property
list. tag is a | 2613 //tag properties DP Designate a marked-content point with an associated property
list. tag is a |
2508 //name object indicating the role or significance of the point; properties is | 2614 //name object indicating the role or significance of the point; properties is |
2509 //either an inline dictionary containing the property list or a name object | 2615 //either an inline dictionary containing the property list or a name object |
2510 //associated with it in the Properties subdictionary of the current resource | 2616 //associated with it in the Properties subdictionary of the current resource |
2511 //dictionary (see Section 9.5.1, “Property Lists”). | 2617 //dictionary (see Section 9.5.1, “Property Lists”). |
2512 static SkPdfResult PdfOp_DP(SkPdfContext* pdfContext, SkCanvas* canvas, PdfToken
Looper** looper) { | 2618 static SkPdfResult PdfOp_DP(SkPdfContext* pdfContext, SkCanvas* canvas, PdfToken
Looper** looper) { |
2513 EXPECT_OPERANDS(pdfContext, 2); | 2619 EXPECT_OPERANDS("DP", pdfContext, 2); |
2514 POP_OBJ(pdfContext, properties); | 2620 POP_OBJ(pdfContext, properties); |
2515 POP_OBJ(pdfContext, tag); | 2621 POP_OBJ(pdfContext, tag); |
2516 CHECK_PARAMETERS(); | 2622 CHECK_PARAMETERS(); |
2517 | 2623 |
2518 if (tag == NULL || properties == NULL) { | 2624 if (tag == NULL) { |
| 2625 SkPdfReportUnexpectedType(kIgnoreError_SkPdfIssueSeverity, NULL, tag, Sk
PdfNativeObject::_kObject_PdfObjectType, pdfContext); |
2519 return kNYI_SkPdfResult; | 2626 return kNYI_SkPdfResult; |
2520 } | 2627 } |
2521 | 2628 |
| 2629 if (properties == NULL) { |
| 2630 SkPdfReportUnexpectedType(kIgnoreError_SkPdfIssueSeverity, NULL, propert
ies, SkPdfNativeObject::_kObject_PdfObjectType, pdfContext); |
| 2631 return kNYI_SkPdfResult; |
| 2632 } |
| 2633 |
| 2634 SkPdfReport(kCodeWarning_SkPdfIssueSeverity, kNYI_SkPdfIssue, "DP NYI", NULL
, NULL); |
2522 return kNYI_SkPdfResult; | 2635 return kNYI_SkPdfResult; |
2523 } | 2636 } |
2524 | 2637 |
2525 //tag BMC Begin a marked-content sequence terminated by a balancing EMC operator
. | 2638 //tag BMC Begin a marked-content sequence terminated by a balancing EMC operator
. |
2526 //tag is a name object indicating the role or significance of the sequence. | 2639 //tag is a name object indicating the role or significance of the sequence. |
2527 static SkPdfResult PdfOp_BMC(SkPdfContext* pdfContext, SkCanvas* canvas, PdfToke
nLooper** looper) { | 2640 static SkPdfResult PdfOp_BMC(SkPdfContext* pdfContext, SkCanvas* canvas, PdfToke
nLooper** looper) { |
2528 EXPECT_OPERANDS(pdfContext, 1); | 2641 EXPECT_OPERANDS("BMC", pdfContext, 1); |
2529 POP_OBJ(pdfContext, tag); | 2642 POP_OBJ(pdfContext, tag); |
2530 CHECK_PARAMETERS(); | 2643 CHECK_PARAMETERS(); |
2531 | 2644 |
2532 if (tag == NULL) { | 2645 if (tag == NULL) { |
| 2646 SkPdfReportUnexpectedType(kIgnoreError_SkPdfIssueSeverity, NULL, tag, Sk
PdfNativeObject::_kObject_PdfObjectType, pdfContext); |
2533 return kNYI_SkPdfResult; | 2647 return kNYI_SkPdfResult; |
2534 } | 2648 } |
2535 | 2649 |
| 2650 SkPdfReport(kCodeWarning_SkPdfIssueSeverity, kNYI_SkPdfIssue, "BMC NYI", NUL
L, NULL); |
2536 return kNYI_SkPdfResult; | 2651 return kNYI_SkPdfResult; |
2537 } | 2652 } |
2538 | 2653 |
2539 //tag properties BDC Begin a marked-content sequence with an associated property
list, terminated | 2654 //tag properties BDC Begin a marked-content sequence with an associated property
list, terminated |
2540 //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 | 2655 //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 |
2541 //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”). | 2656 //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”). |
2542 static SkPdfResult PdfOp_BDC(SkPdfContext* pdfContext, SkCanvas* canvas, PdfToke
nLooper** looper) { | 2657 static SkPdfResult PdfOp_BDC(SkPdfContext* pdfContext, SkCanvas* canvas, PdfToke
nLooper** looper) { |
2543 EXPECT_OPERANDS(pdfContext, 2); | 2658 EXPECT_OPERANDS("BDC", pdfContext, 2); |
2544 POP_OBJ(pdfContext, properties); | 2659 POP_OBJ(pdfContext, properties); |
2545 POP_OBJ(pdfContext, tag); | 2660 POP_OBJ(pdfContext, tag); |
2546 CHECK_PARAMETERS(); | 2661 CHECK_PARAMETERS(); |
2547 | 2662 |
2548 if (tag == NULL || properties == NULL) { | 2663 if (tag == NULL) { |
| 2664 SkPdfReportUnexpectedType(kIgnoreError_SkPdfIssueSeverity, NULL, tag, Sk
PdfNativeObject::_kObject_PdfObjectType, pdfContext); |
2549 return kNYI_SkPdfResult; | 2665 return kNYI_SkPdfResult; |
2550 } | 2666 } |
2551 | 2667 |
| 2668 if (properties == NULL) { |
| 2669 SkPdfReportUnexpectedType(kIgnoreError_SkPdfIssueSeverity, NULL, propert
ies, SkPdfNativeObject::_kObject_PdfObjectType, pdfContext); |
| 2670 return kNYI_SkPdfResult; |
| 2671 } |
| 2672 |
| 2673 SkPdfReport(kCodeWarning_SkPdfIssueSeverity, kNYI_SkPdfIssue, "BDC NYI", NUL
L, NULL); |
2552 return kNYI_SkPdfResult; | 2674 return kNYI_SkPdfResult; |
2553 } | 2675 } |
2554 | 2676 |
2555 //— EMC End a marked-content sequence begun by a BMC or BDC operator. | 2677 //— EMC End a marked-content sequence begun by a BMC or BDC operator. |
2556 static SkPdfResult PdfOp_EMC(SkPdfContext* pdfContext, SkCanvas* canvas, PdfToke
nLooper** looper) { | 2678 static SkPdfResult PdfOp_EMC(SkPdfContext* pdfContext, SkCanvas* canvas, PdfToke
nLooper** looper) { |
| 2679 SkPdfReport(kCodeWarning_SkPdfIssueSeverity, kNYI_SkPdfIssue, "EMC NYI", NUL
L, NULL); |
2557 return kNYI_SkPdfResult; | 2680 return kNYI_SkPdfResult; |
2558 } | 2681 } |
2559 | 2682 |
2560 static void initPdfOperatorRenderes() { | 2683 static void initPdfOperatorRenderes() { |
2561 static bool gInitialized = false; | 2684 static bool gInitialized = false; |
2562 if (gInitialized) { | 2685 if (gInitialized) { |
2563 return; | 2686 return; |
2564 } | 2687 } |
2565 | 2688 |
2566 gPdfOps.set("q", PdfOp_q); | 2689 gPdfOps.set("q", PdfOp_q); |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2698 int cnt = 0; | 2821 int cnt = 0; |
2699 gRenderStats[kUnsupported_SkPdfResult].find(token.fKeyword, token.fK
eywordLength, &cnt); | 2822 gRenderStats[kUnsupported_SkPdfResult].find(token.fKeyword, token.fK
eywordLength, &cnt); |
2700 gRenderStats[kUnsupported_SkPdfResult].set(token.fKeyword, token.fKe
ywordLength, cnt + 1); | 2823 gRenderStats[kUnsupported_SkPdfResult].set(token.fKeyword, token.fKe
ywordLength, cnt + 1); |
2701 } | 2824 } |
2702 } | 2825 } |
2703 else if (token.fType == kObject_TokenType) | 2826 else if (token.fType == kObject_TokenType) |
2704 { | 2827 { |
2705 fPdfContext->fObjectStack.push( token.fObject ); | 2828 fPdfContext->fObjectStack.push( token.fObject ); |
2706 } | 2829 } |
2707 else { | 2830 else { |
2708 // TODO(edisonn): deine or use assert not reached | 2831 // TODO(edisonn): store the keyword as a object, so we can track the loc
ation in file, and report it |
| 2832 SkPdfReport(kCodeWarning_SkPdfIssueSeverity, kNYI_SkPdfIssue, token.fKey
word, NULL, fPdfContext); |
2709 return kIgnoreError_SkPdfResult; | 2833 return kIgnoreError_SkPdfResult; |
2710 } | 2834 } |
2711 return kOK_SkPdfResult; | 2835 return kOK_SkPdfResult; |
2712 } | 2836 } |
2713 | 2837 |
2714 void PdfMainLooper::loop() { | 2838 void PdfMainLooper::loop() { |
2715 PdfToken token; | 2839 PdfToken token; |
2716 while (readToken(fTokenizer, &token)) { | 2840 while (readToken(fTokenizer, &token)) { |
2717 consumeToken(token); | 2841 consumeToken(token); |
2718 } | 2842 } |
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2908 | 3032 |
2909 rect = SkRect::MakeWH(width, height); | 3033 rect = SkRect::MakeWH(width, height); |
2910 | 3034 |
2911 setup_bitmap(output, (int)SkScalarToDouble(width), (int)SkScalarToDouble(hei
ght)); | 3035 setup_bitmap(output, (int)SkScalarToDouble(width), (int)SkScalarToDouble(hei
ght)); |
2912 | 3036 |
2913 SkAutoTUnref<SkBaseDevice> device(SkNEW_ARGS(SkBitmapDevice, (*output))); | 3037 SkAutoTUnref<SkBaseDevice> device(SkNEW_ARGS(SkBitmapDevice, (*output))); |
2914 SkCanvas canvas(device); | 3038 SkCanvas canvas(device); |
2915 | 3039 |
2916 return renderer.renderPage(page, &canvas, rect); | 3040 return renderer.renderPage(page, &canvas, rect); |
2917 } | 3041 } |
OLD | NEW |