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

Side by Side Diff: experimental/PdfViewer/SkPdfRenderer.cpp

Issue 19793011: (upload draf code for backup) pdfviewer: improve memory, son't allocate extra buffers, and put the … (Closed) Base URL: http://skia.googlecode.com/svn/trunk/
Patch Set: Created 7 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « experimental/PdfViewer/SkPdfFont.cpp ('k') | experimental/PdfViewer/pdf_viewer_main.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2013 Google Inc. 2 * Copyright 2013 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #include "SkCanvas.h" 8 #include "SkCanvas.h"
9 #include "SkDevice.h" 9 #include "SkDevice.h"
10 #include "SkForceLinking.h" 10 #include "SkForceLinking.h"
11 #include "SkGraphics.h" 11 #include "SkGraphics.h"
12 #include "SkImageDecoder.h" 12 #include "SkImageDecoder.h"
13 #include "SkImageEncoder.h" 13 #include "SkImageEncoder.h"
14 #include "SkOSFile.h" 14 #include "SkOSFile.h"
15 #include "SkPicture.h" 15 #include "SkPicture.h"
16 #include "SkStream.h" 16 #include "SkStream.h"
17 #include "SkTypeface.h" 17 #include "SkTypeface.h"
18 #include "SkTArray.h" 18 #include "SkTArray.h"
19 #include "SkTDict.h"
19 20
20 #include "SkPdfBasics.h" 21 #include "SkPdfBasics.h"
21 #include "SkPdfNativeTokenizer.h" 22 #include "SkPdfNativeTokenizer.h"
22
23 #include <iostream>
24 #include <cstdio> 23 #include <cstdio>
25 #include <stack> 24 #include <stack>
26 #include <set> 25 #include <set>
27 26
28 extern "C" PdfContext* gPdfContext; 27 extern "C" PdfContext* gPdfContext;
29 extern "C" SkBitmap* gDumpBitmap; 28 extern "C" SkBitmap* gDumpBitmap;
30 extern "C" SkCanvas* gDumpCanvas; 29 extern "C" SkCanvas* gDumpCanvas;
31 30
32 __SK_FORCE_IMAGE_DECODER_LINKING; 31 __SK_FORCE_IMAGE_DECODER_LINKING;
33 32
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
71 * - wrapper on classes for customizations? e.g. 70 * - wrapper on classes for customizations? e.g.
72 * SkPdfPageObjectVanila - has only the basic loaders/getters 71 * SkPdfPageObjectVanila - has only the basic loaders/getters
73 * SkPdfPageObject : public SkPdfPageObjectVanila, extends, and I can add custom izations here 72 * SkPdfPageObject : public SkPdfPageObjectVanila, extends, and I can add custom izations here
74 * need to find a nice object model for all this with constructors and factories 73 * need to find a nice object model for all this with constructors and factories
75 * - deal with inheritable automatically ? 74 * - deal with inheritable automatically ?
76 * - deal with specific type in spec directly, add all dictionary types to known types 75 * - deal with specific type in spec directly, add all dictionary types to known types
77 */ 76 */
78 77
79 using namespace std; 78 using namespace std;
80 79
80 NotOwnedString strings_DeviceRGB;
81 NotOwnedString strings_DeviceCMYK;
81 82
83 class StringsInit {
84 public:
85 StringsInit() {
86 NotOwnedString::init(&strings_DeviceRGB, "DeviceRGB");
87 NotOwnedString::init(&strings_DeviceCMYK, "DeviceCMYK");
88 }
89 };
90
91 StringsInit gStringsInit;
82 92
83 // TODO(edisonn): Document PdfTokenLooper and subclasses. 93 // TODO(edisonn): Document PdfTokenLooper and subclasses.
84 class PdfTokenLooper { 94 class PdfTokenLooper {
85 protected: 95 protected:
86 PdfTokenLooper* fParent; 96 PdfTokenLooper* fParent;
87 SkPdfNativeTokenizer* fTokenizer; 97 SkPdfNativeTokenizer* fTokenizer;
88 PdfContext* fPdfContext; 98 PdfContext* fPdfContext;
89 SkCanvas* fCanvas; 99 SkCanvas* fCanvas;
90 100
91 public: 101 public:
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
143 153
144 // Utilities 154 // Utilities
145 static void setup_bitmap(SkBitmap* bitmap, int width, int height, SkColor color = SK_ColorWHITE) { 155 static void setup_bitmap(SkBitmap* bitmap, int width, int height, SkColor color = SK_ColorWHITE) {
146 bitmap->setConfig(SkBitmap::kARGB_8888_Config, width, height); 156 bitmap->setConfig(SkBitmap::kARGB_8888_Config, width, height);
147 157
148 bitmap->allocPixels(); 158 bitmap->allocPixels();
149 bitmap->eraseColor(color); 159 bitmap->eraseColor(color);
150 } 160 }
151 161
152 // TODO(edisonn): synonyms? DeviceRGB and RGB ... 162 // TODO(edisonn): synonyms? DeviceRGB and RGB ...
153 static int GetColorSpaceComponents(const std::string& colorSpace) { 163 static int GetColorSpaceComponents(NotOwnedString& colorSpace) {
154 if (colorSpace == "DeviceCMYK") { 164 if (colorSpace.equals("DeviceCMYK")) {
155 return 4; 165 return 4;
156 } else if (colorSpace == "DeviceGray" || 166 } else if (colorSpace.equals("DeviceGray") ||
157 colorSpace == "CalGray" || 167 colorSpace.equals("CalGray") ||
158 colorSpace == "Indexed") { 168 colorSpace.equals("Indexed")) {
159 return 1; 169 return 1;
160 } else if (colorSpace == "DeviceRGB" || 170 } else if (colorSpace.equals("DeviceRGB") ||
161 colorSpace == "CalRGB" || 171 colorSpace.equals("CalRGB") ||
162 colorSpace == "Lab") { 172 colorSpace.equals("Lab")) {
163 return 3; 173 return 3;
164 } else { 174 } else {
165 return 0; 175 return 0;
166 } 176 }
167 } 177 }
168 178
169 SkMatrix SkMatrixFromPdfMatrix(double array[6]) { 179 SkMatrix SkMatrixFromPdfMatrix(double array[6]) {
170 SkMatrix matrix; 180 SkMatrix matrix;
171 matrix.setAll(SkDoubleToScalar(array[0]), 181 matrix.setAll(SkDoubleToScalar(array[0]),
172 SkDoubleToScalar(array[2]), 182 SkDoubleToScalar(array[2]),
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
310 } 320 }
311 #endif 321 #endif
312 322
313 return ret; 323 return ret;
314 } 324 }
315 325
316 326
317 327
318 typedef PdfResult (*PdfOperatorRenderer)(PdfContext*, SkCanvas*, PdfTokenLooper* *); 328 typedef PdfResult (*PdfOperatorRenderer)(PdfContext*, SkCanvas*, PdfTokenLooper* *);
319 329
320 map<std::string, PdfOperatorRenderer> gPdfOps; 330 SkTDict<PdfOperatorRenderer> gPdfOps(100);
321 331
322 map<std::string, int> gRenderStats[kCount_PdfResult]; 332
333 template <typename T> class SkTDictWithDefaultConstructor : public SkTDict<T> {
334 public:
335 SkTDictWithDefaultConstructor() : SkTDict<T>(10) {}
336 };
337
338 SkTDictWithDefaultConstructor<int> gRenderStats[kCount_PdfResult];
323 339
324 const char* gRenderStatsNames[kCount_PdfResult] = { 340 const char* gRenderStatsNames[kCount_PdfResult] = {
325 "Success", 341 "Success",
326 "Partially implemented", 342 "Partially implemented",
327 "Not yet implemented", 343 "Not yet implemented",
328 "Ignore Error", 344 "Ignore Error",
329 "Error", 345 "Error",
330 "Unsupported/Unknown" 346 "Unsupported/Unknown"
331 }; 347 };
332 348
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
412 if (grayColortable == NULL) { 428 if (grayColortable == NULL) {
413 SkPMColor* colors = new SkPMColor[256]; 429 SkPMColor* colors = new SkPMColor[256];
414 for (int i = 0 ; i < 256; i++) { 430 for (int i = 0 ; i < 256; i++) {
415 colors[i] = SkPreMultiplyARGB(255, i, i, i); 431 colors[i] = SkPreMultiplyARGB(255, i, i, i);
416 } 432 }
417 grayColortable = new SkColorTable(colors, 256); 433 grayColortable = new SkColorTable(colors, 256);
418 } 434 }
419 return grayColortable; 435 return grayColortable;
420 } 436 }
421 437
422 static SkBitmap transferImageStreamToBitmap(unsigned char* uncompressedStream, s ize_t uncompressedStreamLength, 438 static SkBitmap transferImageStreamToBitmap(const unsigned char* uncompressedStr eam, size_t uncompressedStreamLength,
423 int width, int height, int bytesPerLine, 439 int width, int height, int bytesPerLine,
424 int bpc, const std::string& colorSpace, 440 int bpc, const std::string& colorSpace,
425 bool transparencyMask) { 441 bool transparencyMask) {
426 SkBitmap bitmap; 442 SkBitmap bitmap;
427 443
428 //int components = GetColorSpaceComponents(colorSpace); 444 //int components = GetColorSpaceComponents(colorSpace);
429 //#define MAX_COMPONENTS 10 445 //#define MAX_COMPONENTS 10
430 446
431 // TODO(edisonn): assume start of lines are aligned at 32 bits? 447 // TODO(edisonn): assume start of lines are aligned at 32 bits?
432 // Is there a faster way to load the uncompressed stream into a bitmap? 448 // Is there a faster way to load the uncompressed stream into a bitmap?
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
501 517
502 if (imageMask) { 518 if (imageMask) {
503 if (bpc != 0 && bpc != 1) { 519 if (bpc != 0 && bpc != 1) {
504 // TODO(edisonn): report warning to be used in testing. 520 // TODO(edisonn): report warning to be used in testing.
505 return SkBitmap(); 521 return SkBitmap();
506 } 522 }
507 bpc = 1; 523 bpc = 1;
508 } 524 }
509 */ 525 */
510 526
511 unsigned char* uncompressedStream = NULL; 527 const unsigned char* uncompressedStream = NULL;
512 size_t uncompressedStreamLength = 0; 528 size_t uncompressedStreamLength = 0;
513 529
514 SkPdfStream* stream = (SkPdfStream*)image; 530 SkPdfStream* stream = (SkPdfStream*)image;
515 531
516 if (!stream || !stream->GetFilteredStreamRef(&uncompressedStream, &uncompres sedStreamLength, pdfContext->fPdfDoc->allocator()) || 532 if (!stream || !stream->GetFilteredStreamRef(&uncompressedStream, &uncompres sedStreamLength) ||
517 uncompressedStream == NULL || uncompressedStreamLength == 0) { 533 uncompressedStream == NULL || uncompressedStreamLength == 0) {
518 // TODO(edisonn): report warning to be used in testing. 534 // TODO(edisonn): report warning to be used in testing.
519 return SkBitmap(); 535 return SkBitmap();
520 } 536 }
521 537
522 SkPdfStreamCommonDictionary* streamDict = (SkPdfStreamCommonDictionary*)stre am; 538 SkPdfStreamCommonDictionary* streamDict = (SkPdfStreamCommonDictionary*)stre am;
523 539
524 if (streamDict->has_Filter() && ((streamDict->isFilterAName(NULL) && 540 if (streamDict->has_Filter() && ((streamDict->isFilterAName(NULL) &&
525 streamDict->getFilterAsName(NULL) == " DCTDecode") || 541 streamDict->getFilterAsName(NULL) == " DCTDecode") ||
526 (streamDict->isFilterAArray(NULL) && 542 (streamDict->isFilterAArray(NULL) &&
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
647 663
648 if (skobj->has_BBox()) { 664 if (skobj->has_BBox()) {
649 canvas->clipRect(skobj->BBox(pdfContext->fPdfDoc), SkRegion::kIntersect_ Op, true); // TODO(edisonn): AA from settings. 665 canvas->clipRect(skobj->BBox(pdfContext->fPdfDoc), SkRegion::kIntersect_ Op, true); // TODO(edisonn): AA from settings.
650 } 666 }
651 667
652 // TODO(edisonn): iterate smart on the stream even if it is compressed, toke nize it as we go. 668 // TODO(edisonn): iterate smart on the stream even if it is compressed, toke nize it as we go.
653 // For this PdfContentsTokenizer needs to be extended. 669 // For this PdfContentsTokenizer needs to be extended.
654 670
655 SkPdfStream* stream = (SkPdfStream*)skobj; 671 SkPdfStream* stream = (SkPdfStream*)skobj;
656 672
657 SkPdfNativeTokenizer* tokenizer = pdfContext->fPdfDoc->tokenizerOfStream(str eam); 673 SkPdfNativeTokenizer* tokenizer =
674 pdfContext->fPdfDoc->tokenizerOfStream(stream, pdfContext->fTmpPageA llocator);
658 if (tokenizer != NULL) { 675 if (tokenizer != NULL) {
659 PdfMainLooper looper(NULL, tokenizer, pdfContext, canvas); 676 PdfMainLooper looper(NULL, tokenizer, pdfContext, canvas);
660 looper.loop(); 677 looper.loop();
661 delete tokenizer; 678 delete tokenizer;
662 } 679 }
663 680
664 // TODO(edisonn): should we restore the variable stack at the same state? 681 // TODO(edisonn): should we restore the variable stack at the same state?
665 // There could be operands left, that could be consumed by a parent tokenize r when we pop. 682 // There could be operands left, that could be consumed by a parent tokenize r when we pop.
666 canvas->restore(); 683 canvas->restore();
667 PdfOp_Q(pdfContext, canvas, NULL); 684 PdfOp_Q(pdfContext, canvas, NULL);
(...skipping 27 matching lines...) Expand all
695 712
696 SkTraceRect(rm, "bbox mapped"); 713 SkTraceRect(rm, "bbox mapped");
697 714
698 canvas->clipRect(bBox, SkRegion::kIntersect_Op, true); // TODO(edisonn): AA from settings. 715 canvas->clipRect(bBox, SkRegion::kIntersect_Op, true); // TODO(edisonn): AA from settings.
699 716
700 // TODO(edisonn): iterate smart on the stream even if it is compressed, toke nize it as we go. 717 // TODO(edisonn): iterate smart on the stream even if it is compressed, toke nize it as we go.
701 // For this PdfContentsTokenizer needs to be extended. 718 // For this PdfContentsTokenizer needs to be extended.
702 719
703 SkPdfStream* stream = (SkPdfStream*)skobj; 720 SkPdfStream* stream = (SkPdfStream*)skobj;
704 721
705 SkPdfNativeTokenizer* tokenizer = pdfContext->fPdfDoc->tokenizerOfStream(str eam); 722 SkPdfNativeTokenizer* tokenizer =
723 pdfContext->fPdfDoc->tokenizerOfStream(stream, pdfContext->fTmpPageA llocator);
706 if (tokenizer != NULL) { 724 if (tokenizer != NULL) {
707 PdfMainLooper looper(NULL, tokenizer, pdfContext, canvas); 725 PdfMainLooper looper(NULL, tokenizer, pdfContext, canvas);
708 looper.loop(); 726 looper.loop();
709 delete tokenizer; 727 delete tokenizer;
710 } 728 }
711 729
712 // TODO(edisonn): should we restore the variable stack at the same state? 730 // TODO(edisonn): should we restore the variable stack at the same state?
713 // There could be operands left, that could be consumed by a parent tokenize r when we pop. 731 // There could be operands left, that could be consumed by a parent tokenize r when we pop.
714 canvas->restore(); 732 canvas->restore();
715 PdfOp_Q(pdfContext, canvas, NULL); 733 PdfOp_Q(pdfContext, canvas, NULL);
(...skipping 428 matching lines...) Expand 10 before | Expand all | Expand 10 after
1144 return kPartial_PdfResult; 1162 return kPartial_PdfResult;
1145 } 1163 }
1146 1164
1147 //font size Tf Set the text font, Tf 1165 //font size Tf Set the text font, Tf
1148 //, to font and the text font size, Tfs, to size. font is the name of a 1166 //, to font and the text font size, Tfs, to size. font is the name of a
1149 //font resource in the Fontsubdictionary of the current resource dictionary; siz e is 1167 //font resource in the Fontsubdictionary of the current resource dictionary; siz e is
1150 //a number representing a scale factor. There is no initial value for either fon t or 1168 //a number representing a scale factor. There is no initial value for either fon t or
1151 //size; they must be specified explicitly using Tf before any text is shown. 1169 //size; they must be specified explicitly using Tf before any text is shown.
1152 static PdfResult PdfOp_Tf(PdfContext* pdfContext, SkCanvas* canvas, PdfTokenLoop er** looper) { 1170 static PdfResult PdfOp_Tf(PdfContext* pdfContext, SkCanvas* canvas, PdfTokenLoop er** looper) {
1153 pdfContext->fGraphicsState.fCurFontSize = pdfContext->fObjectStack.top()->nu mberValue(); pdfContext->fObjectStack.pop(); 1171 pdfContext->fGraphicsState.fCurFontSize = pdfContext->fObjectStack.top()->nu mberValue(); pdfContext->fObjectStack.pop();
1154 const char* fontName = pdfContext->fObjectStack.top()->nameValue(); pdfContext->fObjectStack.pop(); 1172 SkPdfObject* fontName = pdfContext->fObjectStack.top(); pdfContext->fObjectStack.pop();
1155 1173
1156 #ifdef PDF_TRACE 1174 #ifdef PDF_TRACE
1157 printf("font name: %s\n", fontName); 1175 printf("font name: %s\n", fontName->nameValue2().c_str());
1158 #endif 1176 #endif
1159 1177
1160 if (pdfContext->fGraphicsState.fResources->Font(pdfContext->fPdfDoc)) { 1178 if (pdfContext->fGraphicsState.fResources->Font(pdfContext->fPdfDoc)) {
1161 SkPdfObject* objFont = pdfContext->fGraphicsState.fResources->Font(pdfCo ntext->fPdfDoc)->get(fontName); 1179 SkPdfObject* objFont = pdfContext->fGraphicsState.fResources->Font(pdfCo ntext->fPdfDoc)->get(fontName);
1162 objFont = pdfContext->fPdfDoc->resolveReference(objFont); 1180 objFont = pdfContext->fPdfDoc->resolveReference(objFont);
1163 if (kNone_SkPdfObjectType == pdfContext->fPdfDoc->mapper()->mapFontDicti onary(objFont)) { 1181 if (kNone_SkPdfObjectType == pdfContext->fPdfDoc->mapper()->mapFontDicti onary(objFont)) {
1164 // TODO(edisonn): try to recover and draw it any way? 1182 // TODO(edisonn): try to recover and draw it any way?
1165 return kIgnoreError_PdfResult; 1183 return kIgnoreError_PdfResult;
1166 } 1184 }
1167 SkPdfFontDictionary* fd = (SkPdfFontDictionary*)objFont; 1185 SkPdfFontDictionary* fd = (SkPdfFontDictionary*)objFont;
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
1256 SkDoubleToScalar(0), 1274 SkDoubleToScalar(0),
1257 SkDoubleToScalar(1)); 1275 SkDoubleToScalar(1));
1258 1276
1259 pdfContext->fGraphicsState.fMatrixTm.preConcat(matrix); 1277 pdfContext->fGraphicsState.fMatrixTm.preConcat(matrix);
1260 } 1278 }
1261 } 1279 }
1262 return kPartial_PdfResult; // TODO(edisonn): Implement fully DrawText befor e returing OK. 1280 return kPartial_PdfResult; // TODO(edisonn): Implement fully DrawText befor e returing OK.
1263 } 1281 }
1264 1282
1265 static PdfResult PdfOp_CS_cs(PdfContext* pdfContext, SkCanvas* canvas, SkPdfColo rOperator* colorOperator) { 1283 static PdfResult PdfOp_CS_cs(PdfContext* pdfContext, SkCanvas* canvas, SkPdfColo rOperator* colorOperator) {
1266 colorOperator->fColorSpace = pdfContext->fObjectStack.top()->nameValue(); pdfContext->fObjectStack.pop(); 1284 colorOperator->fColorSpace = pdfContext->fObjectStack.top()->strRef(); pd fContext->fObjectStack.pop();
1267 return kOK_PdfResult; 1285 return kOK_PdfResult;
1268 } 1286 }
1269 1287
1270 static PdfResult PdfOp_CS(PdfContext* pdfContext, SkCanvas* canvas, PdfTokenLoop er** looper) { 1288 static PdfResult PdfOp_CS(PdfContext* pdfContext, SkCanvas* canvas, PdfTokenLoop er** looper) {
1271 return PdfOp_CS_cs(pdfContext, canvas, &pdfContext->fGraphicsState.fStroking ); 1289 return PdfOp_CS_cs(pdfContext, canvas, &pdfContext->fGraphicsState.fStroking );
1272 } 1290 }
1273 1291
1274 static PdfResult PdfOp_cs(PdfContext* pdfContext, SkCanvas* canvas, PdfTokenLoop er** looper) { 1292 static PdfResult PdfOp_cs(PdfContext* pdfContext, SkCanvas* canvas, PdfTokenLoop er** looper) {
1275 return PdfOp_CS_cs(pdfContext, canvas, &pdfContext->fGraphicsState.fNonStrok ing); 1293 return PdfOp_CS_cs(pdfContext, canvas, &pdfContext->fGraphicsState.fNonStrok ing);
1276 } 1294 }
1277 1295
1278 static PdfResult PdfOp_SC_sc(PdfContext* pdfContext, SkCanvas* canvas, SkPdfColo rOperator* colorOperator) { 1296 static PdfResult PdfOp_SC_sc(PdfContext* pdfContext, SkCanvas* canvas, SkPdfColo rOperator* colorOperator) {
1279 double c[4]; 1297 double c[4];
1280 // int64_t v[4]; 1298 // int64_t v[4];
1281 1299
1282 int n = GetColorSpaceComponents(colorOperator->fColorSpace); 1300 int n = GetColorSpaceComponents(colorOperator->fColorSpace);
1283 1301
1284 bool doubles = true; 1302 bool doubles = true;
1285 if (strcmp(colorOperator->fColorSpace, "Indexed") == 0) { 1303 if (colorOperator->fColorSpace.equals("Indexed")) {
1286 doubles = false; 1304 doubles = false;
1287 } 1305 }
1288 1306
1289 #ifdef PDF_TRACE 1307 #ifdef PDF_TRACE
1290 printf("color space = %s, N = %i\n", colorOperator->fColorSpace, n); 1308 printf("color space = %s, N = %i\n", colorOperator->fColorSpace.fBuffer, n);
1291 #endif 1309 #endif
1292 1310
1293 for (int i = n - 1; i >= 0 ; i--) { 1311 for (int i = n - 1; i >= 0 ; i--) {
1294 if (doubles) { 1312 if (doubles) {
1295 c[i] = pdfContext->fObjectStack.top()->numberValue(); pdfCon text->fObjectStack.pop(); 1313 c[i] = pdfContext->fObjectStack.top()->numberValue(); pdfCon text->fObjectStack.pop();
1296 // } else { 1314 // } else {
1297 // v[i] = pdfContext->fObjectStack.top()->intValue(); pdfConte xt->fObjectStack.pop(); 1315 // v[i] = pdfContext->fObjectStack.top()->intValue(); pdfConte xt->fObjectStack.pop();
1298 } 1316 }
1299 } 1317 }
1300 1318
1301 // TODO(edisonn): Now, set that color. Only DeviceRGB supported. 1319 // TODO(edisonn): Now, set that color. Only DeviceRGB supported.
1302 // TODO(edisonn): do possible field values to enum at parsing time! 1320 // TODO(edisonn): do possible field values to enum at parsing time!
1303 // TODO(edisonn): support also abreviations /DeviceRGB == /RGB 1321 // TODO(edisonn): support also abreviations /DeviceRGB == /RGB
1304 if (strcmp(colorOperator->fColorSpace, "DeviceRGB") == 0 || strcmp(colorOper ator->fColorSpace, "RGB") == 0) { 1322 if (colorOperator->fColorSpace.equals("DeviceRGB") || colorOperator->fColorS pace.equals("RGB")) {
1305 colorOperator->setRGBColor(SkColorSetRGB(255*c[0], 255*c[1], 255*c[2])); 1323 colorOperator->setRGBColor(SkColorSetRGB(255*c[0], 255*c[1], 255*c[2]));
1306 } 1324 }
1307 return kPartial_PdfResult; 1325 return kPartial_PdfResult;
1308 } 1326 }
1309 1327
1310 static PdfResult PdfOp_SC(PdfContext* pdfContext, SkCanvas* canvas, PdfTokenLoop er** looper) { 1328 static PdfResult PdfOp_SC(PdfContext* pdfContext, SkCanvas* canvas, PdfTokenLoop er** looper) {
1311 return PdfOp_SC_sc(pdfContext, canvas, &pdfContext->fGraphicsState.fStroking ); 1329 return PdfOp_SC_sc(pdfContext, canvas, &pdfContext->fGraphicsState.fStroking );
1312 } 1330 }
1313 1331
1314 static PdfResult PdfOp_sc(PdfContext* pdfContext, SkCanvas* canvas, PdfTokenLoop er** looper) { 1332 static PdfResult PdfOp_sc(PdfContext* pdfContext, SkCanvas* canvas, PdfTokenLoop er** looper) {
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
1347 1365
1348 static PdfResult PdfOp_g(PdfContext* pdfContext, SkCanvas* canvas, PdfTokenLoope r** looper) { 1366 static PdfResult PdfOp_g(PdfContext* pdfContext, SkCanvas* canvas, PdfTokenLoope r** looper) {
1349 return PdfOp_G_g(pdfContext, canvas, &pdfContext->fGraphicsState.fNonStrokin g); 1367 return PdfOp_G_g(pdfContext, canvas, &pdfContext->fGraphicsState.fNonStrokin g);
1350 } 1368 }
1351 1369
1352 static PdfResult PdfOp_RG_rg(PdfContext* pdfContext, SkCanvas* canvas, SkPdfColo rOperator* colorOperator) { 1370 static PdfResult PdfOp_RG_rg(PdfContext* pdfContext, SkCanvas* canvas, SkPdfColo rOperator* colorOperator) {
1353 double b = pdfContext->fObjectStack.top()->numberValue(); pdfContext->fO bjectStack.pop(); 1371 double b = pdfContext->fObjectStack.top()->numberValue(); pdfContext->fO bjectStack.pop();
1354 double g = pdfContext->fObjectStack.top()->numberValue(); pdfContext->fO bjectStack.pop(); 1372 double g = pdfContext->fObjectStack.top()->numberValue(); pdfContext->fO bjectStack.pop();
1355 double r = pdfContext->fObjectStack.top()->numberValue(); pdfContext->fO bjectStack.pop(); 1373 double r = pdfContext->fObjectStack.top()->numberValue(); pdfContext->fO bjectStack.pop();
1356 1374
1357 colorOperator->fColorSpace = "DeviceRGB"; 1375 colorOperator->fColorSpace = strings_DeviceRGB;
1358 colorOperator->setRGBColor(SkColorSetRGB(255*r, 255*g, 255*b)); 1376 colorOperator->setRGBColor(SkColorSetRGB(255*r, 255*g, 255*b));
1359 return kOK_PdfResult; 1377 return kOK_PdfResult;
1360 } 1378 }
1361 1379
1362 static PdfResult PdfOp_RG(PdfContext* pdfContext, SkCanvas* canvas, PdfTokenLoop er** looper) { 1380 static PdfResult PdfOp_RG(PdfContext* pdfContext, SkCanvas* canvas, PdfTokenLoop er** looper) {
1363 return PdfOp_RG_rg(pdfContext, canvas, &pdfContext->fGraphicsState.fStroking ); 1381 return PdfOp_RG_rg(pdfContext, canvas, &pdfContext->fGraphicsState.fStroking );
1364 } 1382 }
1365 1383
1366 static PdfResult PdfOp_rg(PdfContext* pdfContext, SkCanvas* canvas, PdfTokenLoop er** looper) { 1384 static PdfResult PdfOp_rg(PdfContext* pdfContext, SkCanvas* canvas, PdfTokenLoop er** looper) {
1367 return PdfOp_RG_rg(pdfContext, canvas, &pdfContext->fGraphicsState.fNonStrok ing); 1385 return PdfOp_RG_rg(pdfContext, canvas, &pdfContext->fGraphicsState.fNonStrok ing);
1368 } 1386 }
1369 1387
1370 static PdfResult PdfOp_K_k(PdfContext* pdfContext, SkCanvas* canvas, SkPdfColorO perator* colorOperator) { 1388 static PdfResult PdfOp_K_k(PdfContext* pdfContext, SkCanvas* canvas, SkPdfColorO perator* colorOperator) {
1371 // TODO(edisonn): spec has some rules about overprint, implement them. 1389 // TODO(edisonn): spec has some rules about overprint, implement them.
1372 /*double k = */pdfContext->fObjectStack.top()->numberValue(); pdfContext ->fObjectStack.pop(); 1390 /*double k = */pdfContext->fObjectStack.top()->numberValue(); pdfContext ->fObjectStack.pop();
1373 /*double y = */pdfContext->fObjectStack.top()->numberValue(); pdfContext ->fObjectStack.pop(); 1391 /*double y = */pdfContext->fObjectStack.top()->numberValue(); pdfContext ->fObjectStack.pop();
1374 /*double m = */pdfContext->fObjectStack.top()->numberValue(); pdfContext ->fObjectStack.pop(); 1392 /*double m = */pdfContext->fObjectStack.top()->numberValue(); pdfContext ->fObjectStack.pop();
1375 /*double c = */pdfContext->fObjectStack.top()->numberValue(); pdfContext ->fObjectStack.pop(); 1393 /*double c = */pdfContext->fObjectStack.top()->numberValue(); pdfContext ->fObjectStack.pop();
1376 1394
1377 colorOperator->fColorSpace = "DeviceCMYK"; 1395 colorOperator->fColorSpace = strings_DeviceCMYK;
1378 // TODO(edisonn): Set color. 1396 // TODO(edisonn): Set color.
1379 return kNYI_PdfResult; 1397 return kNYI_PdfResult;
1380 } 1398 }
1381 1399
1382 static PdfResult PdfOp_K(PdfContext* pdfContext, SkCanvas* canvas, PdfTokenLoope r** looper) { 1400 static PdfResult PdfOp_K(PdfContext* pdfContext, SkCanvas* canvas, PdfTokenLoope r** looper) {
1383 return PdfOp_K_k(pdfContext, canvas, &pdfContext->fGraphicsState.fStroking); 1401 return PdfOp_K_k(pdfContext, canvas, &pdfContext->fGraphicsState.fStroking);
1384 } 1402 }
1385 1403
1386 static PdfResult PdfOp_k(PdfContext* pdfContext, SkCanvas* canvas, PdfTokenLoope r** looper) { 1404 static PdfResult PdfOp_k(PdfContext* pdfContext, SkCanvas* canvas, PdfTokenLoope r** looper) {
1387 return PdfOp_K_k(pdfContext, canvas, &pdfContext->fGraphicsState.fNonStrokin g); 1405 return PdfOp_K_k(pdfContext, canvas, &pdfContext->fGraphicsState.fNonStrokin g);
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
1497 //fies the output device’s default flatness tolerance. 1515 //fies the output device’s default flatness tolerance.
1498 static PdfResult PdfOp_i(PdfContext* pdfContext, SkCanvas* canvas, PdfTokenLoope r** looper) { 1516 static PdfResult PdfOp_i(PdfContext* pdfContext, SkCanvas* canvas, PdfTokenLoope r** looper) {
1499 pdfContext->fObjectStack.pop(); 1517 pdfContext->fObjectStack.pop();
1500 1518
1501 return kNYI_PdfResult; 1519 return kNYI_PdfResult;
1502 } 1520 }
1503 1521
1504 //dictName gs (PDF 1.2) Set the specified parameters in the graphics state. dictN ame is 1522 //dictName gs (PDF 1.2) Set the specified parameters in the graphics state. dictN ame is
1505 //the name of a graphics state parameter dictionary in the ExtGState subdictiona ry of the current resource dictionary (see the next section). 1523 //the name of a graphics state parameter dictionary in the ExtGState subdictiona ry of the current resource dictionary (see the next section).
1506 static PdfResult PdfOp_gs(PdfContext* pdfContext, SkCanvas* canvas, PdfTokenLoop er** looper) { 1524 static PdfResult PdfOp_gs(PdfContext* pdfContext, SkCanvas* canvas, PdfTokenLoop er** looper) {
1507 const char* name = pdfContext->fObjectStack.top()->nameValue(); pdfContex t->fObjectStack.pop(); 1525 SkPdfObject* name = pdfContext->fObjectStack.top(); pdfContext->fObjectSt ack.pop();
1508 1526
1509 #ifdef PDF_TRACE 1527 #ifdef PDF_TRACE
1510 std::string str; 1528 std::string str;
1511 #endif 1529 #endif
1512 1530
1513 //Next, get the ExtGState Dictionary from the Resource Dictionary: 1531 //Next, get the ExtGState Dictionary from the Resource Dictionary:
1514 SkPdfDictionary* extGStateDictionary = pdfContext->fGraphicsState.fResources ->ExtGState(pdfContext->fPdfDoc); 1532 SkPdfDictionary* extGStateDictionary = pdfContext->fGraphicsState.fResources ->ExtGState(pdfContext->fPdfDoc);
1515 1533
1516 if (extGStateDictionary == NULL) { 1534 if (extGStateDictionary == NULL) {
1517 #ifdef PDF_TRACE 1535 #ifdef PDF_TRACE
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
1615 1633
1616 //name sh 1634 //name sh
1617 static PdfResult PdfOp_sh(PdfContext* pdfContext, SkCanvas* canvas, PdfTokenLoop er** looper) { 1635 static PdfResult PdfOp_sh(PdfContext* pdfContext, SkCanvas* canvas, PdfTokenLoop er** looper) {
1618 pdfContext->fObjectStack.pop(); 1636 pdfContext->fObjectStack.pop();
1619 1637
1620 return kNYI_PdfResult; 1638 return kNYI_PdfResult;
1621 } 1639 }
1622 1640
1623 //name Do 1641 //name Do
1624 static PdfResult PdfOp_Do(PdfContext* pdfContext, SkCanvas* canvas, PdfTokenLoop er** looper) { 1642 static PdfResult PdfOp_Do(PdfContext* pdfContext, SkCanvas* canvas, PdfTokenLoop er** looper) {
1625 const char* name = pdfContext->fObjectStack.top()->nameValue(); pdfContex t->fObjectStack.pop(); 1643 SkPdfObject* name = pdfContext->fObjectStack.top(); pdfContext->fObjectSt ack.pop();
1626 1644
1627 SkPdfDictionary* xObject = pdfContext->fGraphicsState.fResources->XObject(p dfContext->fPdfDoc); 1645 SkPdfDictionary* xObject = pdfContext->fGraphicsState.fResources->XObject(p dfContext->fPdfDoc);
1628 1646
1629 if (xObject == NULL) { 1647 if (xObject == NULL) {
1630 #ifdef PDF_TRACE 1648 #ifdef PDF_TRACE
1631 printf("XObject is NULL!\n"); 1649 printf("XObject is NULL!\n");
1632 #endif 1650 #endif
1633 return kIgnoreError_PdfResult; 1651 return kIgnoreError_PdfResult;
1634 } 1652 }
1635 1653
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
1686 static PdfResult PdfOp_EMC(PdfContext* pdfContext, SkCanvas* canvas, PdfTokenLoo per** looper) { 1704 static PdfResult PdfOp_EMC(PdfContext* pdfContext, SkCanvas* canvas, PdfTokenLoo per** looper) {
1687 return kNYI_PdfResult; 1705 return kNYI_PdfResult;
1688 } 1706 }
1689 1707
1690 static void initPdfOperatorRenderes() { 1708 static void initPdfOperatorRenderes() {
1691 static bool gInitialized = false; 1709 static bool gInitialized = false;
1692 if (gInitialized) { 1710 if (gInitialized) {
1693 return; 1711 return;
1694 } 1712 }
1695 1713
1696 gPdfOps["q"] = PdfOp_q; 1714 gPdfOps.set("q", PdfOp_q);
1697 gPdfOps["Q"] = PdfOp_Q; 1715 gPdfOps.set("Q", PdfOp_Q);
1698 gPdfOps["cm"] = PdfOp_cm; 1716 gPdfOps.set("cm", PdfOp_cm);
1699 1717
1700 gPdfOps["TD"] = PdfOp_TD; 1718 gPdfOps.set("TD", PdfOp_TD);
1701 gPdfOps["Td"] = PdfOp_Td; 1719 gPdfOps.set("Td", PdfOp_Td);
1702 gPdfOps["Tm"] = PdfOp_Tm; 1720 gPdfOps.set("Tm", PdfOp_Tm);
1703 gPdfOps["T*"] = PdfOp_T_star; 1721 gPdfOps.set("T*", PdfOp_T_star);
1704 1722
1705 gPdfOps["m"] = PdfOp_m; 1723 gPdfOps.set("m", PdfOp_m);
1706 gPdfOps["l"] = PdfOp_l; 1724 gPdfOps.set("l", PdfOp_l);
1707 gPdfOps["c"] = PdfOp_c; 1725 gPdfOps.set("c", PdfOp_c);
1708 gPdfOps["v"] = PdfOp_v; 1726 gPdfOps.set("v", PdfOp_v);
1709 gPdfOps["y"] = PdfOp_y; 1727 gPdfOps.set("y", PdfOp_y);
1710 gPdfOps["h"] = PdfOp_h; 1728 gPdfOps.set("h", PdfOp_h);
1711 gPdfOps["re"] = PdfOp_re; 1729 gPdfOps.set("re", PdfOp_re);
1712 1730
1713 gPdfOps["S"] = PdfOp_S; 1731 gPdfOps.set("S", PdfOp_S);
1714 gPdfOps["s"] = PdfOp_s; 1732 gPdfOps.set("s", PdfOp_s);
1715 gPdfOps["f"] = PdfOp_f; 1733 gPdfOps.set("f", PdfOp_f);
1716 gPdfOps["F"] = PdfOp_F; 1734 gPdfOps.set("F", PdfOp_F);
1717 gPdfOps["f*"] = PdfOp_f_star; 1735 gPdfOps.set("f*", PdfOp_f_star);
1718 gPdfOps["B"] = PdfOp_B; 1736 gPdfOps.set("B", PdfOp_B);
1719 gPdfOps["B*"] = PdfOp_B_star; 1737 gPdfOps.set("B*", PdfOp_B_star);
1720 gPdfOps["b"] = PdfOp_b; 1738 gPdfOps.set("b", PdfOp_b);
1721 gPdfOps["b*"] = PdfOp_b_star; 1739 gPdfOps.set("b*", PdfOp_b_star);
1722 gPdfOps["n"] = PdfOp_n; 1740 gPdfOps.set("n", PdfOp_n);
1723 1741
1724 gPdfOps["BT"] = PdfOp_BT; 1742 gPdfOps.set("BT", PdfOp_BT);
1725 gPdfOps["ET"] = PdfOp_ET; 1743 gPdfOps.set("ET", PdfOp_ET);
1726 1744
1727 gPdfOps["Tj"] = PdfOp_Tj; 1745 gPdfOps.set("Tj", PdfOp_Tj);
1728 gPdfOps["'"] = PdfOp_quote; 1746 gPdfOps.set("'", PdfOp_quote);
1729 gPdfOps["\""] = PdfOp_doublequote; 1747 gPdfOps.set("\"", PdfOp_doublequote);
1730 gPdfOps["TJ"] = PdfOp_TJ; 1748 gPdfOps.set("TJ", PdfOp_TJ);
1731 1749
1732 gPdfOps["CS"] = PdfOp_CS; 1750 gPdfOps.set("CS", PdfOp_CS);
1733 gPdfOps["cs"] = PdfOp_cs; 1751 gPdfOps.set("cs", PdfOp_cs);
1734 gPdfOps["SC"] = PdfOp_SC; 1752 gPdfOps.set("SC", PdfOp_SC);
1735 gPdfOps["SCN"] = PdfOp_SCN; 1753 gPdfOps.set("SCN", PdfOp_SCN);
1736 gPdfOps["sc"] = PdfOp_sc; 1754 gPdfOps.set("sc", PdfOp_sc);
1737 gPdfOps["scn"] = PdfOp_scn; 1755 gPdfOps.set("scn", PdfOp_scn);
1738 gPdfOps["G"] = PdfOp_G; 1756 gPdfOps.set("G", PdfOp_G);
1739 gPdfOps["g"] = PdfOp_g; 1757 gPdfOps.set("g", PdfOp_g);
1740 gPdfOps["RG"] = PdfOp_RG; 1758 gPdfOps.set("RG", PdfOp_RG);
1741 gPdfOps["rg"] = PdfOp_rg; 1759 gPdfOps.set("rg", PdfOp_rg);
1742 gPdfOps["K"] = PdfOp_K; 1760 gPdfOps.set("K", PdfOp_K);
1743 gPdfOps["k"] = PdfOp_k; 1761 gPdfOps.set("k", PdfOp_k);
1744 1762
1745 gPdfOps["W"] = PdfOp_W; 1763 gPdfOps.set("W", PdfOp_W);
1746 gPdfOps["W*"] = PdfOp_W_star; 1764 gPdfOps.set("W*", PdfOp_W_star);
1747 1765
1748 gPdfOps["BX"] = PdfOp_BX; 1766 gPdfOps.set("BX", PdfOp_BX);
1749 gPdfOps["EX"] = PdfOp_EX; 1767 gPdfOps.set("EX", PdfOp_EX);
1750 1768
1751 gPdfOps["BI"] = PdfOp_BI; 1769 gPdfOps.set("BI", PdfOp_BI);
1752 gPdfOps["ID"] = PdfOp_ID; 1770 gPdfOps.set("ID", PdfOp_ID);
1753 gPdfOps["EI"] = PdfOp_EI; 1771 gPdfOps.set("EI", PdfOp_EI);
1754 1772
1755 gPdfOps["w"] = PdfOp_w; 1773 gPdfOps.set("w", PdfOp_w);
1756 gPdfOps["J"] = PdfOp_J; 1774 gPdfOps.set("J", PdfOp_J);
1757 gPdfOps["j"] = PdfOp_j; 1775 gPdfOps.set("j", PdfOp_j);
1758 gPdfOps["M"] = PdfOp_M; 1776 gPdfOps.set("M", PdfOp_M);
1759 gPdfOps["d"] = PdfOp_d; 1777 gPdfOps.set("d", PdfOp_d);
1760 gPdfOps["ri"] = PdfOp_ri; 1778 gPdfOps.set("ri", PdfOp_ri);
1761 gPdfOps["i"] = PdfOp_i; 1779 gPdfOps.set("i", PdfOp_i);
1762 gPdfOps["gs"] = PdfOp_gs; 1780 gPdfOps.set("gs", PdfOp_gs);
1763 1781
1764 gPdfOps["Tc"] = PdfOp_Tc; 1782 gPdfOps.set("Tc", PdfOp_Tc);
1765 gPdfOps["Tw"] = PdfOp_Tw; 1783 gPdfOps.set("Tw", PdfOp_Tw);
1766 gPdfOps["Tz"] = PdfOp_Tz; 1784 gPdfOps.set("Tz", PdfOp_Tz);
1767 gPdfOps["TL"] = PdfOp_TL; 1785 gPdfOps.set("TL", PdfOp_TL);
1768 gPdfOps["Tf"] = PdfOp_Tf; 1786 gPdfOps.set("Tf", PdfOp_Tf);
1769 gPdfOps["Tr"] = PdfOp_Tr; 1787 gPdfOps.set("Tr", PdfOp_Tr);
1770 gPdfOps["Ts"] = PdfOp_Ts; 1788 gPdfOps.set("Ts", PdfOp_Ts);
1771 1789
1772 gPdfOps["d0"] = PdfOp_d0; 1790 gPdfOps.set("d0", PdfOp_d0);
1773 gPdfOps["d1"] = PdfOp_d1; 1791 gPdfOps.set("d1", PdfOp_d1);
1774 1792
1775 gPdfOps["sh"] = PdfOp_sh; 1793 gPdfOps.set("sh", PdfOp_sh);
1776 1794
1777 gPdfOps["Do"] = PdfOp_Do; 1795 gPdfOps.set("Do", PdfOp_Do);
1778 1796
1779 gPdfOps["MP"] = PdfOp_MP; 1797 gPdfOps.set("MP", PdfOp_MP);
1780 gPdfOps["DP"] = PdfOp_DP; 1798 gPdfOps.set("DP", PdfOp_DP);
1781 gPdfOps["BMC"] = PdfOp_BMC; 1799 gPdfOps.set("BMC", PdfOp_BMC);
1782 gPdfOps["BDC"] = PdfOp_BDC; 1800 gPdfOps.set("BDC", PdfOp_BDC);
1783 gPdfOps["EMC"] = PdfOp_EMC; 1801 gPdfOps.set("EMC", PdfOp_EMC);
1784 1802
1785 gInitialized = true; 1803 gInitialized = true;
1786 } 1804 }
1787 1805
1788 class InitPdfOps { 1806 class InitPdfOps {
1789 public: 1807 public:
1790 InitPdfOps() { 1808 InitPdfOps() {
1791 initPdfOperatorRenderes(); 1809 initPdfOperatorRenderes();
1792 } 1810 }
1793 }; 1811 };
1794 1812
1795 InitPdfOps gInitPdfOps; 1813 InitPdfOps gInitPdfOps;
1796 1814
1797 void reportPdfRenderStats() { 1815 void reportPdfRenderStats() {
1798 std::map<std::string, int>::iterator iter; 1816 std::map<std::string, int>::iterator iter;
1799 1817
1800 for (int i = 0 ; i < kCount_PdfResult; i++) { 1818 for (int i = 0 ; i < kCount_PdfResult; i++) {
1801 for (iter = gRenderStats[i].begin(); iter != gRenderStats[i].end(); ++it er) { 1819 SkTDict<int>::Iter iter(gRenderStats[i]);
1802 printf("%s: %s -> count %i\n", gRenderStatsNames[i], iter->first.c_s tr(), iter->second); 1820 const char* key;
1821 int value = 0;
1822 while ((key = iter.next(&value)) != NULL) {
1823 printf("%s: %s -> count %i\n", gRenderStatsNames[i], key, value);
1803 } 1824 }
1804 } 1825 }
1805 } 1826 }
1806 1827
1807 PdfResult PdfMainLooper::consumeToken(PdfToken& token) { 1828 PdfResult PdfMainLooper::consumeToken(PdfToken& token) {
1808 char keyword[256]; 1829 char keyword[256];
1809 1830
1810 if (token.fType == kKeyword_TokenType && token.fKeywordLength < 256) 1831 if (token.fType == kKeyword_TokenType && token.fKeywordLength < 256)
1811 { 1832 {
1812 strncpy(keyword, token.fKeyword, token.fKeywordLength); 1833 strncpy(keyword, token.fKeyword, token.fKeywordLength);
1813 keyword[token.fKeywordLength] = '\0'; 1834 keyword[token.fKeywordLength] = '\0';
1814 // TODO(edisonn): log trace flag (verbose, error, info, warning, ...) 1835 // TODO(edisonn): log trace flag (verbose, error, info, warning, ...)
1815 PdfOperatorRenderer pdfOperatorRenderer = gPdfOps[keyword]; 1836 PdfOperatorRenderer pdfOperatorRenderer = NULL;
1816 if (pdfOperatorRenderer) { 1837 if (gPdfOps.find(keyword, &pdfOperatorRenderer) && pdfOperatorRenderer) {
1817 // caller, main work is done by pdfOperatorRenderer(...) 1838 // caller, main work is done by pdfOperatorRenderer(...)
1818 PdfTokenLooper* childLooper = NULL; 1839 PdfTokenLooper* childLooper = NULL;
1819 gRenderStats[pdfOperatorRenderer(fPdfContext, fCanvas, &childLooper) ][keyword]++; 1840 PdfResult result = pdfOperatorRenderer(fPdfContext, fCanvas, &childL ooper);
1841
1842 int cnt = 0;
1843 gRenderStats[result].find(keyword, &cnt);
1844 gRenderStats[result].set(keyword, cnt + 1);
1820 1845
1821 if (childLooper) { 1846 if (childLooper) {
1822 childLooper->setUp(this); 1847 childLooper->setUp(this);
1823 childLooper->loop(); 1848 childLooper->loop();
1824 delete childLooper; 1849 delete childLooper;
1825 } 1850 }
1826 } else { 1851 } else {
1827 gRenderStats[kUnsupported_PdfResult][keyword]++; 1852 int cnt = 0;
1853 gRenderStats[kUnsupported_PdfResult].find(keyword, &cnt);
1854 gRenderStats[kUnsupported_PdfResult].set(keyword, cnt + 1);
1828 } 1855 }
1829 } 1856 }
1830 else if (token.fType == kObject_TokenType) 1857 else if (token.fType == kObject_TokenType)
1831 { 1858 {
1832 fPdfContext->fObjectStack.push( token.fObject ); 1859 fPdfContext->fObjectStack.push( token.fObject );
1833 } 1860 }
1834 else { 1861 else {
1835 // TODO(edisonn): deine or use assert not reached 1862 // TODO(edisonn): deine or use assert not reached
1836 return kIgnoreError_PdfResult; 1863 return kIgnoreError_PdfResult;
1837 } 1864 }
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
1912 1939
1913 bool SkPdfRenderer::renderPage(int page, SkCanvas* canvas, const SkRect& dst) co nst { 1940 bool SkPdfRenderer::renderPage(int page, SkCanvas* canvas, const SkRect& dst) co nst {
1914 if (!fPdfDoc) { 1941 if (!fPdfDoc) {
1915 return false; 1942 return false;
1916 } 1943 }
1917 1944
1918 if (page < 0 || page >= pages()) { 1945 if (page < 0 || page >= pages()) {
1919 return false; 1946 return false;
1920 } 1947 }
1921 1948
1922 SkPdfNativeTokenizer* tokenizer = fPdfDoc->tokenizerOfPage(page); 1949 PdfContext pdfContext(fPdfDoc);
1923 1950
1924 PdfContext pdfContext(fPdfDoc); 1951 SkPdfNativeTokenizer* tokenizer = fPdfDoc->tokenizerOfPage(page, pdfContext. fTmpPageAllocator);
1952
1925 pdfContext.fOriginalMatrix = SkMatrix::I(); 1953 pdfContext.fOriginalMatrix = SkMatrix::I();
1926 pdfContext.fGraphicsState.fResources = fPdfDoc->pageResources(page); 1954 pdfContext.fGraphicsState.fResources = fPdfDoc->pageResources(page);
1927 1955
1928 gPdfContext = &pdfContext; 1956 gPdfContext = &pdfContext;
1929 1957
1930 // TODO(edisonn): get matrix stuff right. 1958 // TODO(edisonn): get matrix stuff right.
1931 SkScalar z = SkIntToScalar(0); 1959 SkScalar z = SkIntToScalar(0);
1932 SkScalar w = dst.width(); 1960 SkScalar w = dst.width();
1933 SkScalar h = dst.height(); 1961 SkScalar h = dst.height();
1934 1962
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
2008 } 2036 }
2009 2037
2010 SkRect SkPdfRenderer::MediaBox(int page) const { 2038 SkRect SkPdfRenderer::MediaBox(int page) const {
2011 SkASSERT(fPdfDoc); 2039 SkASSERT(fPdfDoc);
2012 return fPdfDoc->MediaBox(page); 2040 return fPdfDoc->MediaBox(page);
2013 } 2041 }
2014 2042
2015 size_t SkPdfRenderer::bytesUsed() const { 2043 size_t SkPdfRenderer::bytesUsed() const {
2016 return fPdfDoc ? fPdfDoc->bytesUsed() : 0; 2044 return fPdfDoc ? fPdfDoc->bytesUsed() : 0;
2017 } 2045 }
OLDNEW
« no previous file with comments | « experimental/PdfViewer/SkPdfFont.cpp ('k') | experimental/PdfViewer/pdf_viewer_main.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698