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

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

Issue 17395005: put each generated pdf api class in a file (Closed) Base URL: http://skia.googlecode.com/svn/trunk/
Patch Set: Created 7 years, 6 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/generate_code.py ('k') | experimental/PdfViewer/pdfspec_autogen.py » ('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 "SkGraphics.h" 10 #include "SkGraphics.h"
11 #include "SkImageDecoder.h" 11 #include "SkImageDecoder.h"
12 #include "SkImageEncoder.h" 12 #include "SkImageEncoder.h"
13 #include "SkOSFile.h" 13 #include "SkOSFile.h"
14 #include "SkPicture.h" 14 #include "SkPicture.h"
15 #include "SkStream.h" 15 #include "SkStream.h"
16 #include "SkTypeface.h" 16 #include "SkTypeface.h"
17 #include "SkTArray.h" 17 #include "SkTArray.h"
18 #include "picture_utils.h" 18 #include "picture_utils.h"
19 19
20 #include <iostream> 20 #include <iostream>
21 #include <cstdio> 21 #include <cstdio>
22 #include <stack> 22 #include <stack>
23 23
24 #include "podofo.h" 24 #include "podofo.h"
25 using namespace PoDoFo; 25 using namespace PoDoFo;
26 26
27 const PdfObject* resolveReferenceObject(const PdfMemDocument* pdfDoc,
28 const PdfObject* obj,
29 bool resolveOneElementArrays = false);
30
27 bool LongFromDictionary(const PdfMemDocument* pdfDoc, 31 bool LongFromDictionary(const PdfMemDocument* pdfDoc,
28 const PdfDictionary& dict, 32 const PdfDictionary& dict,
29 const char* key, 33 const char* key,
30 const char* abr, 34 const char* abr,
31 long* data); 35 long* data);
32 36
33 bool DoubleFromDictionary(const PdfMemDocument* pdfDoc, 37 bool DoubleFromDictionary(const PdfMemDocument* pdfDoc,
34 const PdfDictionary& dict, 38 const PdfDictionary& dict,
35 const char* key, 39 const char* key,
36 const char* abr, 40 const char* abr,
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
121 const char* abr, 125 const char* abr,
122 SkRect* data); 126 SkRect* data);
123 127
124 bool FunctionFromDictionary(const PdfMemDocument* pdfDoc, 128 bool FunctionFromDictionary(const PdfMemDocument* pdfDoc,
125 const PdfDictionary& dict, 129 const PdfDictionary& dict,
126 const char* key, 130 const char* key,
127 const char* abr, 131 const char* abr,
128 SkPdfFunction* data); 132 SkPdfFunction* data);
129 133
130 134
131 #include "pdf_auto_gen.h" 135 #include "SkPdfHeaders_autogen.h"
136 #include "SkPdfPodofoMapper_autogen.h"
137 #include "SkPdfParser.h"
132 138
133 bool ArrayFromDictionary(const PdfMemDocument* pdfDoc, 139 bool ArrayFromDictionary(const PdfMemDocument* pdfDoc,
134 const PdfDictionary& dict, 140 const PdfDictionary& dict,
135 const char* key, 141 const char* key,
136 const char* abr, 142 const char* abr,
137 SkPdfArray* data) {return false;} 143 SkPdfArray* data) {return false;}
138 144
139 bool FileSpecFromDictionary(const PdfMemDocument* pdfDoc, 145 bool FileSpecFromDictionary(const PdfMemDocument* pdfDoc,
140 const PdfDictionary& dict, 146 const PdfDictionary& dict,
141 const char* key, 147 const char* key,
(...skipping 11 matching lines...) Expand all
153 const char* key, 159 const char* key,
154 const char* abr, 160 const char* abr,
155 SkPdfTree** data) {return false;} 161 SkPdfTree** data) {return false;}
156 162
157 bool DateFromDictionary(const PdfMemDocument* pdfDoc, 163 bool DateFromDictionary(const PdfMemDocument* pdfDoc,
158 const PdfDictionary& dict, 164 const PdfDictionary& dict,
159 const char* key, 165 const char* key,
160 const char* abr, 166 const char* abr,
161 SkPdfDate* data) {return false;} 167 SkPdfDate* data) {return false;}
162 168
163 bool SkRectFromDictionary(const PdfMemDocument* pdfDoc,
164 const PdfDictionary& dict,
165 const char* key,
166 const char* abr,
167 SkRect* data) {return false;}
168
169 bool FunctionFromDictionary(const PdfMemDocument* pdfDoc, 169 bool FunctionFromDictionary(const PdfMemDocument* pdfDoc,
170 const PdfDictionary& dict, 170 const PdfDictionary& dict,
171 const char* key, 171 const char* key,
172 const char* abr, 172 const char* abr,
173 SkPdfFunction* data) {return false;} 173 SkPdfFunction* data) {return false;}
174 174
175 175
176 176
177 /* 177 /*
178 * TODO(edisonn): 178 * TODO(edisonn):
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
228 colorSpace == "CalRGB" || 228 colorSpace == "CalRGB" ||
229 colorSpace == "Lab") { 229 colorSpace == "Lab") {
230 return 3; 230 return 3;
231 } else { 231 } else {
232 return 0; 232 return 0;
233 } 233 }
234 } 234 }
235 235
236 const PdfObject* resolveReferenceObject(const PdfMemDocument* pdfDoc, 236 const PdfObject* resolveReferenceObject(const PdfMemDocument* pdfDoc,
237 const PdfObject* obj, 237 const PdfObject* obj,
238 bool resolveOneElementArrays = false) { 238 bool resolveOneElementArrays) {
239 while (obj && (obj->IsReference() || (resolveOneElementArrays && 239 while (obj && (obj->IsReference() || (resolveOneElementArrays &&
240 obj->IsArray() && 240 obj->IsArray() &&
241 obj->GetArray().GetSize() == 1))) { 241 obj->GetArray().GetSize() == 1))) {
242 if (obj->IsReference()) { 242 if (obj->IsReference()) {
243 // We need to force the non const, the only update we will do is for recurssion checks. 243 // We need to force the non const, the only update we will do is for recurssion checks.
244 PdfReference& ref = (PdfReference&)obj->GetReference(); 244 PdfReference& ref = (PdfReference&)obj->GetReference();
245 obj = pdfDoc->GetObjects().GetObject(ref); 245 obj = pdfDoc->GetObjects().GetObject(ref);
246 } else { 246 } else {
247 obj = &obj->GetArray()[0]; 247 obj = &obj->GetArray()[0];
248 } 248 }
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
300 SkPath fClipPath; 300 SkPath fClipPath;
301 301
302 PdfColorOperator fStroking; 302 PdfColorOperator fStroking;
303 PdfColorOperator fNonStroking; 303 PdfColorOperator fNonStroking;
304 304
305 double fLineWidth; 305 double fLineWidth;
306 double fTextLeading; 306 double fTextLeading;
307 double fWordSpace; 307 double fWordSpace;
308 double fCharSpace; 308 double fCharSpace;
309 309
310 SkPdfResourceDictionary fResources; 310 SkPdfResourceDictionary* fResources;
311 311
312 SkBitmap fSMask; 312 SkBitmap fSMask;
313 313
314 PdfGraphicsState() { 314 PdfGraphicsState() {
315 fCurPosX = 0.0; 315 fCurPosX = 0.0;
316 fCurPosY = 0.0; 316 fCurPosY = 0.0;
317 fCurFontSize = 0.0; 317 fCurFontSize = 0.0;
318 fTextBlock = false; 318 fTextBlock = false;
319 fCurFont = NULL; 319 fCurFont = NULL;
320 fMatrix = SkMatrix::I(); 320 fMatrix = SkMatrix::I();
321 fMatrixTm = SkMatrix::I(); 321 fMatrixTm = SkMatrix::I();
322 fMatrixTlm = SkMatrix::I(); 322 fMatrixTlm = SkMatrix::I();
323 fPathClosed = true; 323 fPathClosed = true;
324 fLineWidth = 0; 324 fLineWidth = 0;
325 fTextLeading = 0; 325 fTextLeading = 0;
326 fWordSpace = 0; 326 fWordSpace = 0;
327 fCharSpace = 0; 327 fCharSpace = 0;
328 fHasClipPathToApply = false; 328 fHasClipPathToApply = false;
329 fResources = NULL;
329 } 330 }
330 }; 331 };
331 332
332 // TODO(edisonn): better class design. 333 // TODO(edisonn): better class design.
333 struct PdfInlineImage { 334 struct PdfInlineImage {
334 std::map<std::string, std::string> fKeyValuePairs; 335 std::map<std::string, std::string> fKeyValuePairs;
335 std::string fImageData; 336 std::string fImageData;
336 337
337 }; 338 };
338 339
339 // TODO(edisonn): better class design. 340 // TODO(edisonn): better class design.
340 struct PdfContext { 341 struct PdfContext {
341 std::stack<PdfVariant> fVarStack; 342 std::stack<SkPdfObject*> fObjectStack;
342 std::stack<PdfGraphicsState> fStateStack; 343 std::stack<PdfGraphicsState> fStateStack;
343 PdfGraphicsState fGraphicsState; 344 PdfGraphicsState fGraphicsState;
344 PoDoFo::PdfPage* fPdfPage; 345 SkPdfDoc& fPdfDoc;
345 PdfMemDocument* fPdfDoc;
346 SkMatrix fOriginalMatrix; 346 SkMatrix fOriginalMatrix;
347 347
348 PdfInlineImage fInlineImage; 348 PdfInlineImage fInlineImage;
349 349
350 PdfContext() : fPdfPage(NULL), 350 PdfContext(SkPdfDoc& doc) : fPdfDoc(doc) {}
351 fPdfDoc(NULL) {}
352 351
353 }; 352 };
354 353
355 // TODO(edisonn): temporary code, to report how much of the PDF we actually thi nk we rendered. 354 // TODO(edisonn): temporary code, to report how much of the PDF we actually thi nk we rendered.
356 enum PdfResult { 355 enum PdfResult {
357 kOK_PdfResult, 356 kOK_PdfResult,
358 kPartial_PdfResult, 357 kPartial_PdfResult,
359 kNYI_PdfResult, 358 kNYI_PdfResult,
360 kIgnoreError_PdfResult, 359 kIgnoreError_PdfResult,
361 kError_PdfResult, 360 kError_PdfResult,
362 kUnsupported_PdfResult, 361 kUnsupported_PdfResult,
363 362
364 kCount_PdfResult 363 kCount_PdfResult
365 }; 364 };
366 365
367 struct PdfToken {
368 const char* pszToken;
369 PdfVariant var;
370 EPdfContentsType eType;
371
372 PdfToken() : pszToken(NULL) {}
373 };
374
375 PdfContext* gPdfContext = NULL; 366 PdfContext* gPdfContext = NULL;
376 SkBitmap* gDumpBitmap = NULL; 367 SkBitmap* gDumpBitmap = NULL;
377 SkCanvas* gDumpCanvas = NULL; 368 SkCanvas* gDumpCanvas = NULL;
378 char gLastKeyword[100] = ""; 369 char gLastKeyword[100] = "";
379 int gLastOpKeyword = -1; 370 int gLastOpKeyword = -1;
380 char allOpWithVisualEffects[100] = ",S,s,f,F,f*,B,B*,b,b*,n,Tj,TJ,\',\",d0,d1,sh ,EI,Do,EX"; 371 char allOpWithVisualEffects[100] = ",S,s,f,F,f*,B,B*,b,b*,n,Tj,TJ,\',\",d0,d1,sh ,EI,Do,EX,";
381 int gReadOp = 0; 372 int gReadOp = 0;
382 373
383 374
384 375
385 bool hasVisualEffect(const char* pdfOp) { 376 bool hasVisualEffect(const char* pdfOp) {
386 return true; 377 return true;
387 if (*pdfOp == '\0') return false; 378 if (*pdfOp == '\0') return false;
388 379
389 char markedPdfOp[100] = ","; 380 char markedPdfOp[100] = ",";
390 strcat(markedPdfOp, pdfOp); 381 strcat(markedPdfOp, pdfOp);
391 strcat(markedPdfOp, ","); 382 strcat(markedPdfOp, ",");
392 383
393 return (strstr(allOpWithVisualEffects, markedPdfOp) != NULL); 384 return (strstr(allOpWithVisualEffects, markedPdfOp) != NULL);
394 } 385 }
395 386
396 // TODO(edisonn): Pass PdfContext and SkCanvasd only with the define for instrum entation. 387 // TODO(edisonn): Pass PdfContext and SkCanvasd only with the define for instrum entation.
397 static bool readToken(PdfContentsTokenizer* fTokenizer, PdfToken* token) { 388 static bool readToken(SkPdfTokenizer fTokenizer, PdfToken* token) {
398 bool ret = fTokenizer->ReadNext(token->eType, token->pszToken, token->var); 389 bool ret = fTokenizer.readToken(token);
399 390
400 gReadOp++; 391 gReadOp++;
401 392
402 #ifdef PDF_TRACE_DIFF_IN_PNG 393 #ifdef PDF_TRACE_DIFF_IN_PNG
403 // TODO(edisonn): compare with old bitmap, and save only new bits are availa ble, and save 394 // TODO(edisonn): compare with old bitmap, and save only new bits are availa ble, and save
404 // the numbar and name of last operation, so the file name will reflect op t hat changed. 395 // the numbar and name of last operation, so the file name will reflect op t hat changed.
405 if (hasVisualEffect(gLastKeyword)) { // TODO(edisonn): and has dirty bits. 396 if (hasVisualEffect(gLastKeyword)) { // TODO(edisonn): and has dirty bits.
406 gDumpCanvas->flush(); 397 gDumpCanvas->flush();
407 398
408 SkBitmap bitmap; 399 SkBitmap bitmap;
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
467 458
468 SkString out; 459 SkString out;
469 460
470 // TODO(edisonn): get the image, and overlay on top of it, the clip , gr afic state, teh stack, 461 // TODO(edisonn): get the image, and overlay on top of it, the clip , gr afic state, teh stack,
471 // ... and other properties, to be able to debug th code easily 462 // ... and other properties, to be able to debug th code easily
472 463
473 out.appendf("/usr/local/google/home/edisonn/log_view2/step-%i-%s.png", g LastOpKeyword, gLastKeyword); 464 out.appendf("/usr/local/google/home/edisonn/log_view2/step-%i-%s.png", g LastOpKeyword, gLastKeyword);
474 SkImageEncoder::EncodeFile(out.c_str(), bitmap, SkImageEncoder::kPNG_Typ e, 100); 465 SkImageEncoder::EncodeFile(out.c_str(), bitmap, SkImageEncoder::kPNG_Typ e, 100);
475 } 466 }
476 467
477 if (token->eType == ePdfContentsType_Keyword) { 468 if (token->fType == kKeyword_TokenType) {
478 strcpy(gLastKeyword, token->pszToken); 469 strcpy(gLastKeyword, token->fKeyword);
479 gLastOpKeyword = gReadOp; 470 gLastOpKeyword = gReadOp;
480 } else { 471 } else {
481 strcpy(gLastKeyword, ""); 472 strcpy(gLastKeyword, "");
482 } 473 }
483 #endif 474 #endif
484 475
485 return ret; 476 return ret;
486 } 477 }
487 478
488 // TODO(edisonn): Document PdfTokenLooper and subclasses. 479 // TODO(edisonn): Document PdfTokenLooper and subclasses.
489 class PdfTokenLooper { 480 class PdfTokenLooper {
490 protected: 481 protected:
491 PdfTokenLooper* fParent; 482 PdfTokenLooper* fParent;
492 PdfContentsTokenizer* fTokenizer; 483 SkPdfTokenizer fTokenizer;
493 PdfContext* fPdfContext; 484 PdfContext* fPdfContext;
494 SkCanvas* fCanvas; 485 SkCanvas* fCanvas;
495 486
496 public: 487 public:
497 PdfTokenLooper(PdfTokenLooper* parent, 488 PdfTokenLooper(PdfTokenLooper* parent,
498 PdfContentsTokenizer* tokenizer, 489 SkPdfTokenizer tokenizer,
499 PdfContext* pdfContext, 490 PdfContext* pdfContext,
500 SkCanvas* canvas) 491 SkCanvas* canvas)
501 : fParent(parent), fTokenizer(tokenizer), fPdfContext(pdfContext), fCanv as(canvas) {} 492 : fParent(parent), fTokenizer(tokenizer), fPdfContext(pdfContext), fCanv as(canvas) {}
502 493
503 virtual PdfResult consumeToken(PdfToken& token) = 0; 494 virtual PdfResult consumeToken(PdfToken& token) = 0;
504 virtual void loop() = 0; 495 virtual void loop() = 0;
505 496
506 void setUp(PdfTokenLooper* parent) { 497 void setUp(PdfTokenLooper* parent) {
507 fParent = parent; 498 fParent = parent;
508 fTokenizer = parent->fTokenizer; 499 fTokenizer = parent->fTokenizer;
509 fPdfContext = parent->fPdfContext; 500 fPdfContext = parent->fPdfContext;
510 fCanvas = parent->fCanvas; 501 fCanvas = parent->fCanvas;
511 } 502 }
512 }; 503 };
513 504
514 class PdfMainLooper : public PdfTokenLooper { 505 class PdfMainLooper : public PdfTokenLooper {
515 public: 506 public:
516 PdfMainLooper(PdfTokenLooper* parent, 507 PdfMainLooper(PdfTokenLooper* parent,
517 PdfContentsTokenizer* tokenizer, 508 SkPdfTokenizer tokenizer,
518 PdfContext* pdfContext, 509 PdfContext* pdfContext,
519 SkCanvas* canvas) 510 SkCanvas* canvas)
520 : PdfTokenLooper(parent, tokenizer, pdfContext, canvas) {} 511 : PdfTokenLooper(parent, tokenizer, pdfContext, canvas) {}
521 512
522 virtual PdfResult consumeToken(PdfToken& token); 513 virtual PdfResult consumeToken(PdfToken& token);
523 virtual void loop(); 514 virtual void loop();
524 }; 515 };
525 516
526 class PdfInlineImageLooper : public PdfTokenLooper { 517 class PdfInlineImageLooper : public PdfTokenLooper {
527 public: 518 public:
528 PdfInlineImageLooper() 519 PdfInlineImageLooper()
529 : PdfTokenLooper(NULL, NULL, NULL, NULL) {} 520 : PdfTokenLooper(NULL, SkPdfTokenizer(), NULL, NULL) {}
530 521
531 virtual PdfResult consumeToken(PdfToken& token); 522 virtual PdfResult consumeToken(PdfToken& token);
532 virtual void loop(); 523 virtual void loop();
533 PdfResult done(); 524 PdfResult done();
534 }; 525 };
535 526
536 class PdfCompatibilitySectionLooper : public PdfTokenLooper { 527 class PdfCompatibilitySectionLooper : public PdfTokenLooper {
537 public: 528 public:
538 PdfCompatibilitySectionLooper() 529 PdfCompatibilitySectionLooper()
539 : PdfTokenLooper(NULL, NULL, NULL, NULL) {} 530 : PdfTokenLooper(NULL, SkPdfTokenizer(), NULL, NULL) {}
540 531
541 virtual PdfResult consumeToken(PdfToken& token); 532 virtual PdfResult consumeToken(PdfToken& token);
542 virtual void loop(); 533 virtual void loop();
543 }; 534 };
544 535
545 typedef PdfResult (*PdfOperatorRenderer)(PdfContext*, SkCanvas*, PdfTokenLooper* *); 536 typedef PdfResult (*PdfOperatorRenderer)(PdfContext*, SkCanvas*, PdfTokenLooper* *);
546 537
547 map<std::string, PdfOperatorRenderer> gPdfOps; 538 map<std::string, PdfOperatorRenderer> gPdfOps;
548 539
549 map<std::string, int> gRenderStats[kCount_PdfResult]; 540 map<std::string, int> gRenderStats[kCount_PdfResult];
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after
709 700
710 // TODO(edisonn): move this code in podofo, so we don't have to fix the font. 701 // TODO(edisonn): move this code in podofo, so we don't have to fix the font.
711 // This logic needs to be moved in PdfEncodingObjectFactory::CreateEncoding 702 // This logic needs to be moved in PdfEncodingObjectFactory::CreateEncoding
712 std::map<PdfFont*, PdfCMapEncoding*> gFontsFixed; 703 std::map<PdfFont*, PdfCMapEncoding*> gFontsFixed;
713 PdfEncoding* FixPdfFont(PdfContext* pdfContext, PdfFont* fCurFont) { 704 PdfEncoding* FixPdfFont(PdfContext* pdfContext, PdfFont* fCurFont) {
714 // TODO(edisonn): and is Identity-H 705 // TODO(edisonn): and is Identity-H
715 if (gFontsFixed.find(fCurFont) == gFontsFixed.end()) { 706 if (gFontsFixed.find(fCurFont) == gFontsFixed.end()) {
716 if (fCurFont->GetObject()->IsDictionary() && fCurFont->GetObject()->GetD ictionary().HasKey(PdfName("ToUnicode"))) { 707 if (fCurFont->GetObject()->IsDictionary() && fCurFont->GetObject()->GetD ictionary().HasKey(PdfName("ToUnicode"))) {
717 PdfCMapEncoding* enc = new PdfCMapEncoding( 708 PdfCMapEncoding* enc = new PdfCMapEncoding(
718 fCurFont->GetObject(), 709 fCurFont->GetObject(),
719 (PdfObject*)resolveReferenceObject(pdfContext->fPdfDoc, 710 (PdfObject*)resolveReferenceObject(&pdfContext->fPdfDoc.podo fo(),
720 fCurFont->GetObject()->GetDictionary( ).GetKey(PdfName("ToUnicode"))), 711 fCurFont->GetObject()->GetDictionary( ).GetKey(PdfName("ToUnicode"))),
721 PdfCMapEncoding::eBaseEncoding_Identity); // todo, read the base encoding 712 PdfCMapEncoding::eBaseEncoding_Identity); // todo, read the base encoding
722 gFontsFixed[fCurFont] = enc; 713 gFontsFixed[fCurFont] = enc;
723 return enc; 714 return enc;
724 } 715 }
725 716
726 return NULL; 717 return NULL;
727 } 718 }
728 719
729 return gFontsFixed[fCurFont]; 720 return gFontsFixed[fCurFont];
(...skipping 545 matching lines...) Expand 10 before | Expand all | Expand 10 after
1275 width, height, bytesPerLine, 1266 width, height, bytesPerLine,
1276 bpc, colorSpace, 1267 bpc, colorSpace,
1277 transparencyMask); 1268 transparencyMask);
1278 1269
1279 free(uncompressedStream); 1270 free(uncompressedStream);
1280 1271
1281 return bitmap; 1272 return bitmap;
1282 } 1273 }
1283 1274
1284 SkBitmap getSmaskFromObject(PdfContext* pdfContext, const SkPdfImageDictionary* obj) { 1275 SkBitmap getSmaskFromObject(PdfContext* pdfContext, const SkPdfImageDictionary* obj) {
1285 const PdfObject* sMask = resolveReferenceObject(pdfContext->fPdfDoc, 1276 const PdfObject* sMask = resolveReferenceObject(&pdfContext->fPdfDoc.podofo( ),
1286 obj->podofo()->GetDictionary().Get Key(PdfName("SMask"))); 1277 obj->podofo()->GetDictionary().Get Key(PdfName("SMask")));
1287 1278
1288 #ifdef PDF_TRACE 1279 #ifdef PDF_TRACE
1289 std::string str; 1280 std::string str;
1290 if (sMask) { 1281 if (sMask) {
1291 sMask->ToString(str); 1282 sMask->ToString(str);
1292 printf("/SMask of /Subtype /Image: %s\n", str.c_str()); 1283 printf("/SMask of /Subtype /Image: %s\n", str.c_str());
1293 } 1284 }
1294 #endif 1285 #endif
1295 1286
1296 if (sMask) { 1287 if (sMask) {
1297 SkPdfImageDictionary skxobjmask(pdfContext->fPdfDoc, sMask); 1288 SkPdfImageDictionary skxobjmask(&pdfContext->fPdfDoc.podofo(), sMask);
1298 return getImageFromObject(pdfContext, &skxobjmask, true); 1289 return getImageFromObject(pdfContext, &skxobjmask, true);
1299 } 1290 }
1300 1291
1301 // TODO(edisonn): implement GS SMask. Default to empty right now. 1292 // TODO(edisonn): implement GS SMask. Default to empty right now.
1302 return pdfContext->fGraphicsState.fSMask; 1293 return pdfContext->fGraphicsState.fSMask;
1303 } 1294 }
1304 1295
1305 PdfResult doXObject_Image(PdfContext* pdfContext, SkCanvas* canvas, const SkPdfI mageDictionary* skpdfimage) { 1296 PdfResult doXObject_Image(PdfContext* pdfContext, SkCanvas* canvas, const SkPdfI mageDictionary* skpdfimage) {
1306 if (skpdfimage == NULL || !skpdfimage->valid()) { 1297 if (skpdfimage == NULL || !skpdfimage->valid()) {
1307 return kIgnoreError_PdfResult; 1298 return kIgnoreError_PdfResult;
(...skipping 19 matching lines...) Expand all
1327 1318
1328 canvas->restore(); 1319 canvas->restore();
1329 1320
1330 return kPartial_PdfResult; 1321 return kPartial_PdfResult;
1331 } 1322 }
1332 1323
1333 bool SkMatrixFromDictionary(PdfContext* pdfContext, 1324 bool SkMatrixFromDictionary(PdfContext* pdfContext,
1334 const PdfDictionary& dict, 1325 const PdfDictionary& dict,
1335 const char* key, 1326 const char* key,
1336 SkMatrix* matrix) { 1327 SkMatrix* matrix) {
1337 const PdfObject* value = resolveReferenceObject(pdfContext->fPdfDoc, 1328 const PdfObject* value = resolveReferenceObject(&pdfContext->fPdfDoc.podofo( ),
1338 dict.GetKey(PdfName(key))); 1329 dict.GetKey(PdfName(key)));
1339 1330
1340 if (value == NULL || !value->IsArray()) { 1331 if (value == NULL || !value->IsArray()) {
1341 return false; 1332 return false;
1342 } 1333 }
1343 1334
1344 if (value->GetArray().GetSize() != 6) { 1335 if (value->GetArray().GetSize() != 6) {
1345 return false; 1336 return false;
1346 } 1337 }
1347 1338
1348 double array[6]; 1339 double array[6];
1349 for (int i = 0; i < 6; i++) { 1340 for (int i = 0; i < 6; i++) {
1350 const PdfObject* elem = resolveReferenceObject(pdfContext->fPdfDoc, &val ue->GetArray()[i]); 1341 const PdfObject* elem = resolveReferenceObject(&pdfContext->fPdfDoc.podo fo(), &value->GetArray()[i]);
1351 if (elem == NULL || (!elem->IsReal() && !elem->IsNumber())) { 1342 if (elem == NULL || (!elem->IsReal() && !elem->IsNumber())) {
1352 return false; 1343 return false;
1353 } 1344 }
1354 array[i] = elem->GetReal(); 1345 array[i] = elem->GetReal();
1355 } 1346 }
1356 1347
1357 *matrix = SkMatrixFromPdfMatrix(array); 1348 *matrix = SkMatrixFromPdfMatrix(array);
1358 return true; 1349 return true;
1359 } 1350 }
1360 1351
1361 bool SkRectFromDictionary(PdfContext* pdfContext, 1352 bool SkRectFromDictionary(const PdfMemDocument* pdfDoc,
1362 const PdfDictionary& dict, 1353 const PdfDictionary& dict,
1363 const char* key, 1354 const char* key,
1364 SkRect* rect) { 1355 SkRect* rect) {
1365 const PdfObject* value = resolveReferenceObject(pdfContext->fPdfDoc, 1356 const PdfObject* value = resolveReferenceObject(pdfDoc,
1366 dict.GetKey(PdfName(key))); 1357 dict.GetKey(PdfName(key)));
1367 1358
1368 if (value == NULL || !value->IsArray()) { 1359 if (value == NULL || !value->IsArray()) {
1369 return false; 1360 return false;
1370 } 1361 }
1371 1362
1372 if (value->GetArray().GetSize() != 4) { 1363 if (value->GetArray().GetSize() != 4) {
1373 return false; 1364 return false;
1374 } 1365 }
1375 1366
1376 double array[4]; 1367 double array[4];
1377 for (int i = 0; i < 4; i++) { 1368 for (int i = 0; i < 4; i++) {
1378 const PdfObject* elem = resolveReferenceObject(pdfContext->fPdfDoc, &val ue->GetArray()[i]); 1369 const PdfObject* elem = resolveReferenceObject(pdfDoc, &value->GetArray( )[i]);
1379 if (elem == NULL || (!elem->IsReal() && !elem->IsNumber())) { 1370 if (elem == NULL || (!elem->IsReal() && !elem->IsNumber())) {
1380 return false; 1371 return false;
1381 } 1372 }
1382 array[i] = elem->GetReal(); 1373 array[i] = elem->GetReal();
1383 } 1374 }
1384 1375
1385 *rect = SkRect::MakeLTRB(SkDoubleToScalar(array[0]), 1376 *rect = SkRect::MakeLTRB(SkDoubleToScalar(array[0]),
1386 SkDoubleToScalar(array[1]), 1377 SkDoubleToScalar(array[1]),
1387 SkDoubleToScalar(array[2]), 1378 SkDoubleToScalar(array[2]),
1388 SkDoubleToScalar(array[3])); 1379 SkDoubleToScalar(array[3]));
1389 return true; 1380 return true;
1390 } 1381 }
1391 1382
1383 bool SkRectFromDictionary(const PdfMemDocument* pdfDoc,
1384 const PdfDictionary& dict,
1385 const char* key,
1386 const char* abr,
1387 SkRect* data) {
1388 if (SkRectFromDictionary(pdfDoc, dict, key, data)) return true;
1389 if (abr == NULL || *abr == '\0') return false;
1390 return SkRectFromDictionary(pdfDoc, dict, abr, data);
1391
1392 }
1393
1394
1392 SkPdfObject* get(const SkPdfObject* obj, const char* key, const char* abr = "") { 1395 SkPdfObject* get(const SkPdfObject* obj, const char* key, const char* abr = "") {
1393 SkPdfObject* ret = NULL; 1396 SkPdfObject* ret = NULL;
1394 if (obj == NULL) return NULL; 1397 if (obj == NULL) return NULL;
1395 const SkPdfDictionary* dict = obj->asDictionary(); 1398 const SkPdfDictionary* dict = obj->asDictionary();
1396 if (dict == NULL) return NULL; 1399 if (dict == NULL) return NULL;
1397 if (!dict->podofo()->IsDictionary()) return NULL; 1400 if (!dict->podofo()->IsDictionary()) return NULL;
1398 ObjectFromDictionary(dict->doc(), dict->podofo()->GetDictionary(), key, abr, &ret); 1401 ObjectFromDictionary(dict->doc(), dict->podofo()->GetDictionary(), key, abr, &ret);
1399 return ret; 1402 return ret;
1400 } 1403 }
1401 1404
1402 PdfResult doXObject_Form(PdfContext* pdfContext, SkCanvas* canvas, SkPdfType1For mDictionary* skobj) { 1405 PdfResult doXObject_Form(PdfContext* pdfContext, SkCanvas* canvas, SkPdfType1For mDictionary* skobj) {
1403 if (!skobj || !skobj->podofo() || !skobj->podofo()->HasStream() || skobj->po dofo()->GetStream() == NULL || skobj->podofo()->GetStream()->GetLength() == 0) { 1406 if (!skobj || !skobj->podofo() || !skobj->podofo()->HasStream() || skobj->po dofo()->GetStream() == NULL || skobj->podofo()->GetStream()->GetLength() == 0) {
1404 return kOK_PdfResult; 1407 return kOK_PdfResult;
1405 } 1408 }
1406 1409
1407 PdfOp_q(pdfContext, canvas, NULL); 1410 PdfOp_q(pdfContext, canvas, NULL);
1408 canvas->save(); 1411 canvas->save();
1409 1412
1410 if (get(skobj, "Resources")) { 1413 if (get(skobj, "Resources")) {
1411 SkPdfResourceDictionary* res = NULL; 1414 SkPdfResourceDictionary* res = NULL;
1412 1415
1413 PodofoMapper::map(*get(skobj, "Resources"), &res); 1416 PodofoMapper::map(*get(skobj, "Resources"), &res);
1414 1417
1415 if (res) { 1418 if (res) {
1416 pdfContext->fGraphicsState.fResources = *res; 1419 pdfContext->fGraphicsState.fResources = res;
1417 delete res;
1418 } 1420 }
1419 } 1421 }
1420 1422
1421 SkTraceMatrix(pdfContext->fGraphicsState.fMatrix, "Current matrix"); 1423 SkTraceMatrix(pdfContext->fGraphicsState.fMatrix, "Current matrix");
1422 1424
1423 SkMatrix matrix; 1425 SkMatrix matrix;
1424 if (SkMatrixFromDictionary(pdfContext, skobj->podofo()->GetDictionary(), "Ma trix", &matrix)) { 1426 if (SkMatrixFromDictionary(pdfContext, skobj->podofo()->GetDictionary(), "Ma trix", &matrix)) {
1425 pdfContext->fGraphicsState.fMatrix.preConcat(matrix); 1427 pdfContext->fGraphicsState.fMatrix.preConcat(matrix);
1426 pdfContext->fGraphicsState.fMatrixTm = pdfContext->fGraphicsState.fMatri x; 1428 pdfContext->fGraphicsState.fMatrixTm = pdfContext->fGraphicsState.fMatri x;
1427 pdfContext->fGraphicsState.fMatrixTlm = pdfContext->fGraphicsState.fMatr ix; 1429 pdfContext->fGraphicsState.fMatrixTlm = pdfContext->fGraphicsState.fMatr ix;
1428 // TODO(edisonn) reset matrixTm and matricTlm also? 1430 // TODO(edisonn) reset matrixTm and matricTlm also?
1429 } 1431 }
1430 1432
1431 SkTraceMatrix(pdfContext->fGraphicsState.fMatrix, "Total matrix"); 1433 SkTraceMatrix(pdfContext->fGraphicsState.fMatrix, "Total matrix");
1432 1434
1433 canvas->setMatrix(pdfContext->fGraphicsState.fMatrix); 1435 canvas->setMatrix(pdfContext->fGraphicsState.fMatrix);
1434 1436
1435 SkRect bbox; 1437 SkRect bbox;
1436 if (SkRectFromDictionary(pdfContext, skobj->podofo()->GetDictionary(), "BBox ", &bbox)) { 1438 if (SkRectFromDictionary(&pdfContext->fPdfDoc.podofo(), skobj->podofo()->Get Dictionary(), "BBox", &bbox)) {
1437 canvas->clipRect(bbox, SkRegion::kIntersect_Op, true); // TODO(edisonn) : AA from settings. 1439 canvas->clipRect(bbox, SkRegion::kIntersect_Op, true); // TODO(edisonn) : AA from settings.
1438 } 1440 }
1439 1441
1440 // TODO(edisonn): iterate smart on the stream even if it is compressed, toke nize it as we go. 1442 // TODO(edisonn): iterate smart on the stream even if it is compressed, toke nize it as we go.
1441 // For this PdfContentsTokenizer needs to be extended. 1443 // For this PdfContentsTokenizer needs to be extended.
1442 1444
1443 char* uncompressedStream = NULL; 1445 char* uncompressedStream = NULL;
1444 pdf_long uncompressedStreamLength = 0; 1446 pdf_long uncompressedStreamLength = 0;
1445 1447
1446 PdfResult ret = kPartial_PdfResult; 1448 PdfResult ret = kPartial_PdfResult;
1447 1449
1448 // TODO(edisonn): get rid of try/catch exceptions! We should not throw on us er data! 1450 // TODO(edisonn): get rid of try/catch exceptions! We should not throw on us er data!
1449 try { 1451 try {
1450 skobj->podofo()->GetStream()->GetFilteredCopy(&uncompressedStream, &unco mpressedStreamLength); 1452 skobj->podofo()->GetStream()->GetFilteredCopy(&uncompressedStream, &unco mpressedStreamLength);
1451 if (uncompressedStream != NULL && uncompressedStreamLength != 0) { 1453 if (uncompressedStream != NULL && uncompressedStreamLength != 0) {
1452 PdfContentsTokenizer tokenizer(uncompressedStream, uncompressedStrea mLength); 1454 SkPdfTokenizer tokenizer = pdfContext->fPdfDoc.tokenizerOfStream(unc ompressedStream, uncompressedStreamLength);
1453 PdfMainLooper looper(NULL, &tokenizer, pdfContext, canvas); 1455 PdfMainLooper looper(NULL, tokenizer, pdfContext, canvas);
1454 looper.loop(); 1456 looper.loop();
1455 } 1457 }
1456 free(uncompressedStream); 1458 free(uncompressedStream);
1457 } catch (PdfError& e) { 1459 } catch (PdfError& e) {
1458 ret = kIgnoreError_PdfResult; 1460 ret = kIgnoreError_PdfResult;
1459 } 1461 }
1460 1462
1461 // TODO(edisonn): should we restore the variable stack at the same state? 1463 // TODO(edisonn): should we restore the variable stack at the same state?
1462 // There could be operands left, that could be consumed by a parent tokenize r when we pop. 1464 // There could be operands left, that could be consumed by a parent tokenize r when we pop.
1463 canvas->restore(); 1465 canvas->restore();
1464 PdfOp_Q(pdfContext, canvas, NULL); 1466 PdfOp_Q(pdfContext, canvas, NULL);
1465 return ret; 1467 return ret;
1466 } 1468 }
1467 1469
1468 PdfResult doXObject_PS(PdfContext* pdfContext, SkCanvas* canvas, const PdfObject & obj) { 1470 PdfResult doXObject_PS(PdfContext* pdfContext, SkCanvas* canvas, const PdfObject & obj) {
1469 return kNYI_PdfResult; 1471 return kNYI_PdfResult;
1470 } 1472 }
1471 1473
1472 // TODO(edisonn): faster, have the property on the PdfObject itself. 1474 // TODO(edisonn): faster, have the property on the SkPdfObject itself?
1473 std::set<const PdfObject*> gInRendering; 1475 std::set<const PdfObject*> gInRendering;
1474 1476
1475 class CheckRecursiveRendering { 1477 class CheckRecursiveRendering {
1476 const PdfObject& fObj; 1478 const PdfObject& fObj;
1477 public: 1479 public:
1478 CheckRecursiveRendering(const PdfObject& obj) : fObj(obj) { 1480 CheckRecursiveRendering(const PdfObject& obj) : fObj(obj) {
1479 gInRendering.insert(&obj); 1481 gInRendering.insert(&obj);
1480 } 1482 }
1481 1483
1482 ~CheckRecursiveRendering() { 1484 ~CheckRecursiveRendering() {
1483 //SkASSERT(fObj.fInRendering); 1485 //SkASSERT(fObj.fInRendering);
1484 gInRendering.erase(&fObj); 1486 gInRendering.erase(&fObj);
1485 } 1487 }
1486 1488
1487 static bool IsInRendering(const PdfObject& obj) { 1489 static bool IsInRendering(const PdfObject& obj) {
1488 return gInRendering.find(&obj) != gInRendering.end(); 1490 return gInRendering.find(&obj) != gInRendering.end();
1489 } 1491 }
1490 }; 1492 };
1491 1493
1492 PdfResult doXObject(PdfContext* pdfContext, SkCanvas* canvas, const PdfObject& o bj) { 1494 PdfResult doXObject(PdfContext* pdfContext, SkCanvas* canvas, const SkPdfObject& obj) {
1493 if (CheckRecursiveRendering::IsInRendering(obj)) { 1495 if (CheckRecursiveRendering::IsInRendering(*obj.podofo())) {
1494 // Oops, corrupt PDF! 1496 // Oops, corrupt PDF!
1495 return kIgnoreError_PdfResult; 1497 return kIgnoreError_PdfResult;
1496 } 1498 }
1497 1499
1498 CheckRecursiveRendering checkRecursion(obj); 1500 CheckRecursiveRendering checkRecursion(*obj.podofo());
1499 1501
1500 // TODO(edisonn): check type 1502 // TODO(edisonn): check type
1501 SkPdfXObjectDictionary* skobj = NULL; 1503 SkPdfXObjectDictionary* skobj = NULL;
1502 if (!PodofoMapper::map(*pdfContext->fPdfDoc, obj, &skobj)) return kIgnoreErr or_PdfResult; 1504 if (!PodofoMapper::map(obj, &skobj)) return kIgnoreError_PdfResult;
1503 1505
1504 if (!skobj || !skobj->valid()) return kIgnoreError_PdfResult; 1506 if (!skobj || !skobj->valid()) return kIgnoreError_PdfResult;
1505 1507
1506 PdfResult ret = kIgnoreError_PdfResult; 1508 PdfResult ret = kIgnoreError_PdfResult;
1507 switch (skobj->getType()) 1509 switch (skobj->getType())
1508 { 1510 {
1509 case kObjectDictionaryXObjectDictionaryImageDictionary_SkPdfObjectType: 1511 case kImageDictionary_SkPdfObjectType:
1510 ret = doXObject_Image(pdfContext, canvas, skobj->asImageDictionary() ); 1512 ret = doXObject_Image(pdfContext, canvas, skobj->asImageDictionary() );
1511 break; 1513 break;
1512 case kObjectDictionaryXObjectDictionaryType1FormDictionary_SkPdfObjectTy pe: 1514 case kType1FormDictionary_SkPdfObjectType:
1513 ret = doXObject_Form(pdfContext, canvas, skobj->asType1FormDictionar y()); 1515 ret = doXObject_Form(pdfContext, canvas, skobj->asType1FormDictionar y());
1514 break; 1516 break;
1515 //case kObjectDictionaryXObjectPS_SkPdfObjectType: 1517 //case kObjectDictionaryXObjectPS_SkPdfObjectType:
1516 //return doXObject_PS(skxobj.asPS()); 1518 //return doXObject_PS(skxobj.asPS());
1517 } 1519 }
1518 1520
1519 delete skobj; 1521 delete skobj;
1520 return ret; 1522 return ret;
1521 } 1523 }
1522 1524
1523 PdfResult PdfOp_q(PdfContext* pdfContext, SkCanvas* canvas, PdfTokenLooper** loo per) { 1525 PdfResult PdfOp_q(PdfContext* pdfContext, SkCanvas* canvas, PdfTokenLooper** loo per) {
1524 pdfContext->fStateStack.push(pdfContext->fGraphicsState); 1526 pdfContext->fStateStack.push(pdfContext->fGraphicsState);
1525 canvas->save(); 1527 canvas->save();
1526 return kOK_PdfResult; 1528 return kOK_PdfResult;
1527 } 1529 }
1528 1530
1529 PdfResult PdfOp_Q(PdfContext* pdfContext, SkCanvas* canvas, PdfTokenLooper** loo per) { 1531 PdfResult PdfOp_Q(PdfContext* pdfContext, SkCanvas* canvas, PdfTokenLooper** loo per) {
1530 pdfContext->fGraphicsState = pdfContext->fStateStack.top(); 1532 pdfContext->fGraphicsState = pdfContext->fStateStack.top();
1531 pdfContext->fStateStack.pop(); 1533 pdfContext->fStateStack.pop();
1532 canvas->restore(); 1534 canvas->restore();
1533 return kOK_PdfResult; 1535 return kOK_PdfResult;
1534 } 1536 }
1535 1537
1536 PdfResult PdfOp_cm(PdfContext* pdfContext, SkCanvas* canvas, PdfTokenLooper** lo oper) { 1538 PdfResult PdfOp_cm(PdfContext* pdfContext, SkCanvas* canvas, PdfTokenLooper** lo oper) {
1537 double array[6]; 1539 double array[6];
1538 for (int i = 0 ; i < 6 ; i++) { 1540 for (int i = 0 ; i < 6 ; i++) {
1539 array[5 - i] = pdfContext->fVarStack.top().GetReal(); 1541 array[5 - i] = pdfContext->fObjectStack.top()->asNumber()->value();
1540 pdfContext->fVarStack.pop(); 1542 pdfContext->fObjectStack.pop();
1541 } 1543 }
1542 1544
1543 // a b 1545 // a b
1544 // c d 1546 // c d
1545 // e f 1547 // e f
1546 1548
1547 // 0 1 1549 // 0 1
1548 // 2 3 1550 // 2 3
1549 // 4 5 1551 // 4 5
1550 1552
(...skipping 13 matching lines...) Expand all
1564 SkTraceMatrix(pdfContext->fGraphicsState.fMatrix); 1566 SkTraceMatrix(pdfContext->fGraphicsState.fMatrix);
1565 #endif 1567 #endif
1566 1568
1567 return kOK_PdfResult; 1569 return kOK_PdfResult;
1568 } 1570 }
1569 1571
1570 //leading TL Set the text leading, Tl 1572 //leading TL Set the text leading, Tl
1571 //, to leading, which is a number expressed in unscaled text 1573 //, to leading, which is a number expressed in unscaled text
1572 //space units. Text leading is used only by the T*, ', and " operators. Initial value: 0. 1574 //space units. Text leading is used only by the T*, ', and " operators. Initial value: 0.
1573 PdfResult PdfOp_TL(PdfContext* pdfContext, SkCanvas* canvas, PdfTokenLooper** lo oper) { 1575 PdfResult PdfOp_TL(PdfContext* pdfContext, SkCanvas* canvas, PdfTokenLooper** lo oper) {
1574 double ty = pdfContext->fVarStack.top().GetReal(); pdfContext->fVarStack.pop (); 1576 double ty = pdfContext->fObjectStack.top()->asNumber()->value(); pdfContext- >fObjectStack.pop();
1575 1577
1576 pdfContext->fGraphicsState.fTextLeading = ty; 1578 pdfContext->fGraphicsState.fTextLeading = ty;
1577 1579
1578 return kOK_PdfResult; 1580 return kOK_PdfResult;
1579 } 1581 }
1580 1582
1581 PdfResult PdfOp_Td(PdfContext* pdfContext, SkCanvas* canvas, PdfTokenLooper** lo oper) { 1583 PdfResult PdfOp_Td(PdfContext* pdfContext, SkCanvas* canvas, PdfTokenLooper** lo oper) {
1582 double ty = pdfContext->fVarStack.top().GetReal(); pdfContext->fVarStack.pop (); 1584 double ty = pdfContext->fObjectStack.top()->asNumber()->value(); pdfContext- >fObjectStack.pop();
1583 double tx = pdfContext->fVarStack.top().GetReal(); pdfContext->fVarStack.pop (); 1585 double tx = pdfContext->fObjectStack.top()->asNumber()->value(); pdfContext- >fObjectStack.pop();
1584 1586
1585 double array[6] = {1, 0, 0, 1, tx, ty}; 1587 double array[6] = {1, 0, 0, 1, tx, ty};
1586 SkMatrix matrix = SkMatrixFromPdfMatrix(array); 1588 SkMatrix matrix = SkMatrixFromPdfMatrix(array);
1587 1589
1588 pdfContext->fGraphicsState.fMatrixTm.preConcat(matrix); 1590 pdfContext->fGraphicsState.fMatrixTm.preConcat(matrix);
1589 pdfContext->fGraphicsState.fMatrixTlm.preConcat(matrix); 1591 pdfContext->fGraphicsState.fMatrixTlm.preConcat(matrix);
1590 1592
1591 return kPartial_PdfResult; 1593 return kPartial_PdfResult;
1592 } 1594 }
1593 1595
1594 PdfResult PdfOp_TD(PdfContext* pdfContext, SkCanvas* canvas, PdfTokenLooper** lo oper) { 1596 PdfResult PdfOp_TD(PdfContext* pdfContext, SkCanvas* canvas, PdfTokenLooper** lo oper) {
1595 double ty = pdfContext->fVarStack.top().GetReal(); pdfContext->fVarStack.pop (); 1597 double ty = pdfContext->fObjectStack.top()->asNumber()->value(); pdfContext- >fObjectStack.pop();
1596 double tx = pdfContext->fVarStack.top().GetReal(); pdfContext->fVarStack.pop (); 1598 double tx = pdfContext->fObjectStack.top()->asNumber()->value(); pdfContext- >fObjectStack.pop();
1597 1599
1598 PdfVariant _ty(-ty); 1600 PdfObject _ty(PdfVariant(-ty));
1599 pdfContext->fVarStack.push(_ty); 1601 pdfContext->fObjectStack.push(new SkPdfNumber(&pdfContext->fPdfDoc.podofo(), &_ty));
1602
1600 PdfOp_TL(pdfContext, canvas, looper); 1603 PdfOp_TL(pdfContext, canvas, looper);
1601 1604
1602 PdfVariant vtx(tx); 1605 PdfObject vtx(PdfVariant(-(-tx))); // TODO(edisonn) Hmm, the compiler think s I have here a function pointer if we use (tx), but not -(-tx)
1603 PdfVariant vty(ty); 1606 pdfContext->fObjectStack.push(new SkPdfNumber(&pdfContext->fPdfDoc.podofo(), &vtx));
1604 pdfContext->fVarStack.push(vtx); 1607
1605 pdfContext->fVarStack.push(vty); 1608 PdfObject vty(PdfVariant(-(-ty)));
1609 pdfContext->fObjectStack.push(new SkPdfNumber(&pdfContext->fPdfDoc.podofo(), &vty));
1610
1606 return PdfOp_Td(pdfContext, canvas, looper); 1611 return PdfOp_Td(pdfContext, canvas, looper);
1607 } 1612 }
1608 1613
1609 PdfResult PdfOp_Tm(PdfContext* pdfContext, SkCanvas* canvas, PdfTokenLooper** lo oper) { 1614 PdfResult PdfOp_Tm(PdfContext* pdfContext, SkCanvas* canvas, PdfTokenLooper** lo oper) {
1610 double f = pdfContext->fVarStack.top().GetReal(); pdfContext->fVarStack.pop( ); 1615 double f = pdfContext->fObjectStack.top()->asNumber()->value(); pdfContext-> fObjectStack.pop();
1611 double e = pdfContext->fVarStack.top().GetReal(); pdfContext->fVarStack.pop( ); 1616 double e = pdfContext->fObjectStack.top()->asNumber()->value(); pdfContext-> fObjectStack.pop();
1612 double d = pdfContext->fVarStack.top().GetReal(); pdfContext->fVarStack.pop( ); 1617 double d = pdfContext->fObjectStack.top()->asNumber()->value(); pdfContext-> fObjectStack.pop();
1613 double c = pdfContext->fVarStack.top().GetReal(); pdfContext->fVarStack.pop( ); 1618 double c = pdfContext->fObjectStack.top()->asNumber()->value(); pdfContext-> fObjectStack.pop();
1614 double b = pdfContext->fVarStack.top().GetReal(); pdfContext->fVarStack.pop( ); 1619 double b = pdfContext->fObjectStack.top()->asNumber()->value(); pdfContext-> fObjectStack.pop();
1615 double a = pdfContext->fVarStack.top().GetReal(); pdfContext->fVarStack.pop( ); 1620 double a = pdfContext->fObjectStack.top()->asNumber()->value(); pdfContext-> fObjectStack.pop();
1616 1621
1617 double array[6]; 1622 double array[6];
1618 array[0] = a; 1623 array[0] = a;
1619 array[1] = b; 1624 array[1] = b;
1620 array[2] = c; 1625 array[2] = c;
1621 array[3] = d; 1626 array[3] = d;
1622 array[4] = e; 1627 array[4] = e;
1623 array[5] = f; 1628 array[5] = f;
1624 1629
1625 SkMatrix matrix = SkMatrixFromPdfMatrix(array); 1630 SkMatrix matrix = SkMatrixFromPdfMatrix(array);
1626 matrix.postConcat(pdfContext->fGraphicsState.fMatrix); 1631 matrix.postConcat(pdfContext->fGraphicsState.fMatrix);
1627 1632
1628 // TODO(edisonn): Text positioning. 1633 // TODO(edisonn): Text positioning.
1629 pdfContext->fGraphicsState.fMatrixTm = matrix; 1634 pdfContext->fGraphicsState.fMatrixTm = matrix;
1630 pdfContext->fGraphicsState.fMatrixTlm = matrix;; 1635 pdfContext->fGraphicsState.fMatrixTlm = matrix;;
1631 1636
1632 return kPartial_PdfResult; 1637 return kPartial_PdfResult;
1633 } 1638 }
1634 1639
1635 //— T* Move to the start of the next line. This operator has the same effect as the code 1640 //— T* Move to the start of the next line. This operator has the same effect as the code
1636 //0 Tl Td 1641 //0 Tl Td
1637 //where Tl is the current leading parameter in the text state 1642 //where Tl is the current leading parameter in the text state
1638 PdfResult PdfOp_T_star(PdfContext* pdfContext, SkCanvas* canvas, PdfTokenLooper* * looper) { 1643 PdfResult PdfOp_T_star(PdfContext* pdfContext, SkCanvas* canvas, PdfTokenLooper* * looper) {
1639 PdfVariant zero(0.0); 1644 PdfObject zero(PdfVariant(0.0));
1640 PdfVariant tl(pdfContext->fGraphicsState.fTextLeading); 1645 PdfObject tl(PdfVariant(-(-pdfContext->fGraphicsState.fTextLeading)));
1641 1646
1642 pdfContext->fVarStack.push(zero); 1647 pdfContext->fObjectStack.push(new SkPdfNumber(&pdfContext->fPdfDoc.podofo(), &zero));
1643 pdfContext->fVarStack.push(tl); 1648 pdfContext->fObjectStack.push(new SkPdfNumber(&pdfContext->fPdfDoc.podofo(), &tl));
1644 return PdfOp_Td(pdfContext, canvas, looper); 1649 return PdfOp_Td(pdfContext, canvas, looper);
1645 } 1650 }
1646 1651
1647 PdfResult PdfOp_m(PdfContext* pdfContext, SkCanvas* canvas, PdfTokenLooper** loo per) { 1652 PdfResult PdfOp_m(PdfContext* pdfContext, SkCanvas* canvas, PdfTokenLooper** loo per) {
1648 if (pdfContext->fGraphicsState.fPathClosed) { 1653 if (pdfContext->fGraphicsState.fPathClosed) {
1649 pdfContext->fGraphicsState.fPath.reset(); 1654 pdfContext->fGraphicsState.fPath.reset();
1650 pdfContext->fGraphicsState.fPathClosed = false; 1655 pdfContext->fGraphicsState.fPathClosed = false;
1651 } 1656 }
1652 1657
1653 pdfContext->fGraphicsState.fCurPosY = pdfContext->fVarStack.top().GetReal(); pdfContext->fVarStack.pop(); 1658 pdfContext->fGraphicsState.fCurPosY = pdfContext->fObjectStack.top()->asNumb er()->value(); pdfContext->fObjectStack.pop();
1654 pdfContext->fGraphicsState.fCurPosX = pdfContext->fVarStack.top().GetReal(); pdfContext->fVarStack.pop(); 1659 pdfContext->fGraphicsState.fCurPosX = pdfContext->fObjectStack.top()->asNumb er()->value(); pdfContext->fObjectStack.pop();
1655 1660
1656 pdfContext->fGraphicsState.fPath.moveTo(SkDoubleToScalar(pdfContext->fGraphi csState.fCurPosX), 1661 pdfContext->fGraphicsState.fPath.moveTo(SkDoubleToScalar(pdfContext->fGraphi csState.fCurPosX),
1657 SkDoubleToScalar(pdfContext->fGraphics State.fCurPosY)); 1662 SkDoubleToScalar(pdfContext->fGraphics State.fCurPosY));
1658 1663
1659 return kOK_PdfResult; 1664 return kOK_PdfResult;
1660 } 1665 }
1661 1666
1662 PdfResult PdfOp_l(PdfContext* pdfContext, SkCanvas* canvas, PdfTokenLooper** loo per) { 1667 PdfResult PdfOp_l(PdfContext* pdfContext, SkCanvas* canvas, PdfTokenLooper** loo per) {
1663 if (pdfContext->fGraphicsState.fPathClosed) { 1668 if (pdfContext->fGraphicsState.fPathClosed) {
1664 pdfContext->fGraphicsState.fPath.reset(); 1669 pdfContext->fGraphicsState.fPath.reset();
1665 pdfContext->fGraphicsState.fPathClosed = false; 1670 pdfContext->fGraphicsState.fPathClosed = false;
1666 } 1671 }
1667 1672
1668 pdfContext->fGraphicsState.fCurPosY = pdfContext->fVarStack.top().GetReal(); pdfContext->fVarStack.pop(); 1673 pdfContext->fGraphicsState.fCurPosY = pdfContext->fObjectStack.top()->asNumb er()->value(); pdfContext->fObjectStack.pop();
1669 pdfContext->fGraphicsState.fCurPosX = pdfContext->fVarStack.top().GetReal(); pdfContext->fVarStack.pop(); 1674 pdfContext->fGraphicsState.fCurPosX = pdfContext->fObjectStack.top()->asNumb er()->value(); pdfContext->fObjectStack.pop();
1670 1675
1671 pdfContext->fGraphicsState.fPath.lineTo(SkDoubleToScalar(pdfContext->fGraphi csState.fCurPosX), 1676 pdfContext->fGraphicsState.fPath.lineTo(SkDoubleToScalar(pdfContext->fGraphi csState.fCurPosX),
1672 SkDoubleToScalar(pdfContext->fGraphics State.fCurPosY)); 1677 SkDoubleToScalar(pdfContext->fGraphics State.fCurPosY));
1673 1678
1674 return kOK_PdfResult; 1679 return kOK_PdfResult;
1675 } 1680 }
1676 1681
1677 PdfResult PdfOp_c(PdfContext* pdfContext, SkCanvas* canvas, PdfTokenLooper** loo per) { 1682 PdfResult PdfOp_c(PdfContext* pdfContext, SkCanvas* canvas, PdfTokenLooper** loo per) {
1678 if (pdfContext->fGraphicsState.fPathClosed) { 1683 if (pdfContext->fGraphicsState.fPathClosed) {
1679 pdfContext->fGraphicsState.fPath.reset(); 1684 pdfContext->fGraphicsState.fPath.reset();
1680 pdfContext->fGraphicsState.fPathClosed = false; 1685 pdfContext->fGraphicsState.fPathClosed = false;
1681 } 1686 }
1682 1687
1683 double y3 = pdfContext->fVarStack.top().GetReal(); pdfContext->fVarStack. pop(); 1688 double y3 = pdfContext->fObjectStack.top()->asNumber()->value(); pdfConte xt->fObjectStack.pop();
1684 double x3 = pdfContext->fVarStack.top().GetReal(); pdfContext->fVarStack. pop(); 1689 double x3 = pdfContext->fObjectStack.top()->asNumber()->value(); pdfConte xt->fObjectStack.pop();
1685 double y2 = pdfContext->fVarStack.top().GetReal(); pdfContext->fVarStack. pop(); 1690 double y2 = pdfContext->fObjectStack.top()->asNumber()->value(); pdfConte xt->fObjectStack.pop();
1686 double x2 = pdfContext->fVarStack.top().GetReal(); pdfContext->fVarStack. pop(); 1691 double x2 = pdfContext->fObjectStack.top()->asNumber()->value(); pdfConte xt->fObjectStack.pop();
1687 double y1 = pdfContext->fVarStack.top().GetReal(); pdfContext->fVarStack. pop(); 1692 double y1 = pdfContext->fObjectStack.top()->asNumber()->value(); pdfConte xt->fObjectStack.pop();
1688 double x1 = pdfContext->fVarStack.top().GetReal(); pdfContext->fVarStack. pop(); 1693 double x1 = pdfContext->fObjectStack.top()->asNumber()->value(); pdfConte xt->fObjectStack.pop();
1689 1694
1690 pdfContext->fGraphicsState.fPath.cubicTo(SkDoubleToScalar(x1), SkDoubleToSca lar(y1), 1695 pdfContext->fGraphicsState.fPath.cubicTo(SkDoubleToScalar(x1), SkDoubleToSca lar(y1),
1691 SkDoubleToScalar(x2), SkDoubleToScal ar(y2), 1696 SkDoubleToScalar(x2), SkDoubleToScal ar(y2),
1692 SkDoubleToScalar(x3), SkDoubleToScal ar(y3)); 1697 SkDoubleToScalar(x3), SkDoubleToScal ar(y3));
1693 1698
1694 pdfContext->fGraphicsState.fCurPosX = x3; 1699 pdfContext->fGraphicsState.fCurPosX = x3;
1695 pdfContext->fGraphicsState.fCurPosY = y3; 1700 pdfContext->fGraphicsState.fCurPosY = y3;
1696 1701
1697 return kOK_PdfResult; 1702 return kOK_PdfResult;
1698 } 1703 }
1699 1704
1700 PdfResult PdfOp_v(PdfContext* pdfContext, SkCanvas* canvas, PdfTokenLooper** loo per) { 1705 PdfResult PdfOp_v(PdfContext* pdfContext, SkCanvas* canvas, PdfTokenLooper** loo per) {
1701 if (pdfContext->fGraphicsState.fPathClosed) { 1706 if (pdfContext->fGraphicsState.fPathClosed) {
1702 pdfContext->fGraphicsState.fPath.reset(); 1707 pdfContext->fGraphicsState.fPath.reset();
1703 pdfContext->fGraphicsState.fPathClosed = false; 1708 pdfContext->fGraphicsState.fPathClosed = false;
1704 } 1709 }
1705 1710
1706 double y3 = pdfContext->fVarStack.top().GetReal(); pdfContext->fVarStack. pop(); 1711 double y3 = pdfContext->fObjectStack.top()->asNumber()->value(); pdfConte xt->fObjectStack.pop();
1707 double x3 = pdfContext->fVarStack.top().GetReal(); pdfContext->fVarStack. pop(); 1712 double x3 = pdfContext->fObjectStack.top()->asNumber()->value(); pdfConte xt->fObjectStack.pop();
1708 double y2 = pdfContext->fVarStack.top().GetReal(); pdfContext->fVarStack. pop(); 1713 double y2 = pdfContext->fObjectStack.top()->asNumber()->value(); pdfConte xt->fObjectStack.pop();
1709 double x2 = pdfContext->fVarStack.top().GetReal(); pdfContext->fVarStack. pop(); 1714 double x2 = pdfContext->fObjectStack.top()->asNumber()->value(); pdfConte xt->fObjectStack.pop();
1710 double y1 = pdfContext->fGraphicsState.fCurPosY; 1715 double y1 = pdfContext->fGraphicsState.fCurPosY;
1711 double x1 = pdfContext->fGraphicsState.fCurPosX; 1716 double x1 = pdfContext->fGraphicsState.fCurPosX;
1712 1717
1713 pdfContext->fGraphicsState.fPath.cubicTo(SkDoubleToScalar(x1), SkDoubleToSca lar(y1), 1718 pdfContext->fGraphicsState.fPath.cubicTo(SkDoubleToScalar(x1), SkDoubleToSca lar(y1),
1714 SkDoubleToScalar(x2), SkDoubleToScal ar(y2), 1719 SkDoubleToScalar(x2), SkDoubleToScal ar(y2),
1715 SkDoubleToScalar(x3), SkDoubleToScal ar(y3)); 1720 SkDoubleToScalar(x3), SkDoubleToScal ar(y3));
1716 1721
1717 pdfContext->fGraphicsState.fCurPosX = x3; 1722 pdfContext->fGraphicsState.fCurPosX = x3;
1718 pdfContext->fGraphicsState.fCurPosY = y3; 1723 pdfContext->fGraphicsState.fCurPosY = y3;
1719 1724
1720 return kOK_PdfResult; 1725 return kOK_PdfResult;
1721 } 1726 }
1722 1727
1723 PdfResult PdfOp_y(PdfContext* pdfContext, SkCanvas* canvas, PdfTokenLooper** loo per) { 1728 PdfResult PdfOp_y(PdfContext* pdfContext, SkCanvas* canvas, PdfTokenLooper** loo per) {
1724 if (pdfContext->fGraphicsState.fPathClosed) { 1729 if (pdfContext->fGraphicsState.fPathClosed) {
1725 pdfContext->fGraphicsState.fPath.reset(); 1730 pdfContext->fGraphicsState.fPath.reset();
1726 pdfContext->fGraphicsState.fPathClosed = false; 1731 pdfContext->fGraphicsState.fPathClosed = false;
1727 } 1732 }
1728 1733
1729 double y3 = pdfContext->fVarStack.top().GetReal(); pdfContext->fVarStack. pop(); 1734 double y3 = pdfContext->fObjectStack.top()->asNumber()->value(); pdfConte xt->fObjectStack.pop();
1730 double x3 = pdfContext->fVarStack.top().GetReal(); pdfContext->fVarStack. pop(); 1735 double x3 = pdfContext->fObjectStack.top()->asNumber()->value(); pdfConte xt->fObjectStack.pop();
1731 double y2 = pdfContext->fGraphicsState.fCurPosY; 1736 double y2 = pdfContext->fGraphicsState.fCurPosY;
1732 double x2 = pdfContext->fGraphicsState.fCurPosX; 1737 double x2 = pdfContext->fGraphicsState.fCurPosX;
1733 double y1 = pdfContext->fVarStack.top().GetReal(); pdfContext->fVarStack. pop(); 1738 double y1 = pdfContext->fObjectStack.top()->asNumber()->value(); pdfConte xt->fObjectStack.pop();
1734 double x1 = pdfContext->fVarStack.top().GetReal(); pdfContext->fVarStack. pop(); 1739 double x1 = pdfContext->fObjectStack.top()->asNumber()->value(); pdfConte xt->fObjectStack.pop();
1735 1740
1736 pdfContext->fGraphicsState.fPath.cubicTo(SkDoubleToScalar(x1), SkDoubleToSca lar(y1), 1741 pdfContext->fGraphicsState.fPath.cubicTo(SkDoubleToScalar(x1), SkDoubleToSca lar(y1),
1737 SkDoubleToScalar(x2), SkDoubleToScal ar(y2), 1742 SkDoubleToScalar(x2), SkDoubleToScal ar(y2),
1738 SkDoubleToScalar(x3), SkDoubleToScal ar(y3)); 1743 SkDoubleToScalar(x3), SkDoubleToScal ar(y3));
1739 1744
1740 pdfContext->fGraphicsState.fCurPosX = x3; 1745 pdfContext->fGraphicsState.fCurPosX = x3;
1741 pdfContext->fGraphicsState.fCurPosY = y3; 1746 pdfContext->fGraphicsState.fCurPosY = y3;
1742 1747
1743 return kOK_PdfResult; 1748 return kOK_PdfResult;
1744 } 1749 }
1745 1750
1746 PdfResult PdfOp_re(PdfContext* pdfContext, SkCanvas* canvas, PdfTokenLooper** lo oper) { 1751 PdfResult PdfOp_re(PdfContext* pdfContext, SkCanvas* canvas, PdfTokenLooper** lo oper) {
1747 if (pdfContext->fGraphicsState.fPathClosed) { 1752 if (pdfContext->fGraphicsState.fPathClosed) {
1748 pdfContext->fGraphicsState.fPath.reset(); 1753 pdfContext->fGraphicsState.fPath.reset();
1749 pdfContext->fGraphicsState.fPathClosed = false; 1754 pdfContext->fGraphicsState.fPathClosed = false;
1750 } 1755 }
1751 1756
1752 double height = pdfContext->fVarStack.top().GetReal(); pdfContext->fVar Stack.pop(); 1757 double height = pdfContext->fObjectStack.top()->asNumber()->value(); pd fContext->fObjectStack.pop();
1753 double width = pdfContext->fVarStack.top().GetReal(); pdfContext->fVar Stack.pop(); 1758 double width = pdfContext->fObjectStack.top()->asNumber()->value(); pd fContext->fObjectStack.pop();
1754 double y = pdfContext->fVarStack.top().GetReal(); pdfContext->fVar Stack.pop(); 1759 double y = pdfContext->fObjectStack.top()->asNumber()->value(); pd fContext->fObjectStack.pop();
1755 double x = pdfContext->fVarStack.top().GetReal(); pdfContext->fVar Stack.pop(); 1760 double x = pdfContext->fObjectStack.top()->asNumber()->value(); pd fContext->fObjectStack.pop();
1756 1761
1757 pdfContext->fGraphicsState.fPath.addRect(SkDoubleToScalar(x), SkDoubleToScal ar(y), 1762 pdfContext->fGraphicsState.fPath.addRect(SkDoubleToScalar(x), SkDoubleToScal ar(y),
1758 SkDoubleToScalar(x + width), SkDouble ToScalar(y + height)); 1763 SkDoubleToScalar(x + width), SkDouble ToScalar(y + height));
1759 1764
1760 pdfContext->fGraphicsState.fCurPosX = x; 1765 pdfContext->fGraphicsState.fCurPosX = x;
1761 pdfContext->fGraphicsState.fCurPosY = y + height; 1766 pdfContext->fGraphicsState.fCurPosY = y + height;
1762 1767
1763 return kOK_PdfResult; 1768 return kOK_PdfResult;
1764 } 1769 }
1765 1770
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
1897 // TODO(edisonn): anything else to be done once we are done with draw text? Like restore stack? 1902 // TODO(edisonn): anything else to be done once we are done with draw text? Like restore stack?
1898 return kPartial_PdfResult; 1903 return kPartial_PdfResult;
1899 } 1904 }
1900 1905
1901 //font size Tf Set the text font, Tf 1906 //font size Tf Set the text font, Tf
1902 //, to font and the text font size, Tfs, to size. font is the name of a 1907 //, to font and the text font size, Tfs, to size. font is the name of a
1903 //font resource in the Fontsubdictionary of the current resource dictionary; siz e is 1908 //font resource in the Fontsubdictionary of the current resource dictionary; siz e is
1904 //a number representing a scale factor. There is no initial value for either fon t or 1909 //a number representing a scale factor. There is no initial value for either fon t or
1905 //size; they must be specified explicitly using Tf before any text is shown. 1910 //size; they must be specified explicitly using Tf before any text is shown.
1906 PdfResult PdfOp_Tf(PdfContext* pdfContext, SkCanvas* canvas, PdfTokenLooper** lo oper) { 1911 PdfResult PdfOp_Tf(PdfContext* pdfContext, SkCanvas* canvas, PdfTokenLooper** lo oper) {
1907 pdfContext->fGraphicsState.fCurFontSize = pdfContext->fVarStack.top().GetRea l(); pdfContext->fVarStack.pop(); 1912 pdfContext->fGraphicsState.fCurFontSize = pdfContext->fObjectStack.top()->as Number()->value(); pdfContext->fObjectStack.pop();
1908 PdfName fontName = pdfContext->fVarStack.top().GetName(); pdfContext->fVarStack.pop(); 1913 std::string fontName = pdfContext->fObjectStack.top()->asName()->value(); pdfContext->fObjectStack.pop();
1914
1915 #ifdef PDF_TRACE
1916 printf("font name: %s\n", fontName.c_str());
1917 std::string str;
1918 pdfContext->fGraphicsState.fResources->podofo()->ToString(str);
1919 printf("Print Tf font Resources: %s\n", str.c_str());
1920 #endif
1909 1921
1910 // TODO(edisonn): Load font from pdfContext->fGraphicsState.fObjectWithResou rces ? 1922 // TODO(edisonn): Load font from pdfContext->fGraphicsState.fObjectWithResou rces ?
1911 PdfObject* pFont = pdfContext->fPdfPage->GetFromResources( PdfName("Font"), fontName ); 1923 const PdfObject* pFont = resolveReferenceObject(&pdfContext->fPdfDoc.podofo( ),
1924 pdfContext->fGraphicsState.f Resources->Font()->get(fontName.c_str()).podofo());
1912 if( !pFont ) 1925 if( !pFont )
1913 { 1926 {
1914 // TODO(edisonn): try to ignore the error, make sure we do not crash. 1927 // TODO(edisonn): try to ignore the error, make sure we do not crash.
1915 return kIgnoreError_PdfResult; 1928 return kIgnoreError_PdfResult;
1916 } 1929 }
1917 1930
1918 pdfContext->fGraphicsState.fCurFont = pdfContext->fPdfDoc->GetFont( pFont ); 1931 pdfContext->fGraphicsState.fCurFont = pdfContext->fPdfDoc.podofo().GetFont( (PdfObject*)pFont );
1919 if( !pdfContext->fGraphicsState.fCurFont ) 1932 if( !pdfContext->fGraphicsState.fCurFont )
1920 { 1933 {
1921 // TODO(edisonn): check ~/crasing, for one of the files PoDoFo throws ex ception 1934 // TODO(edisonn): check ~/crasing, for one of the files PoDoFo throws ex ception
1922 // when calling pFont->Reference(), with Linked list corruption. 1935 // when calling pFont->Reference(), with Linked list corruption.
1923 return kIgnoreError_PdfResult; 1936 return kIgnoreError_PdfResult;
1924 } 1937 }
1925 1938
1926 return kPartial_PdfResult; 1939 return kPartial_PdfResult;
1927 } 1940 }
1928 1941
1929 PdfResult PdfOp_Tj(PdfContext* pdfContext, SkCanvas* canvas, PdfTokenLooper** lo oper) { 1942 PdfResult PdfOp_Tj(PdfContext* pdfContext, SkCanvas* canvas, PdfTokenLooper** lo oper) {
1930 if (!pdfContext->fGraphicsState.fTextBlock) { 1943 if (!pdfContext->fGraphicsState.fTextBlock) {
1931 // TODO(edisonn): try to recover and draw it any way? 1944 // TODO(edisonn): try to recover and draw it any way?
1932 return kIgnoreError_PdfResult; 1945 return kIgnoreError_PdfResult;
1933 } 1946 }
1934 1947
1935 PdfResult ret = DrawText(pdfContext, 1948 PdfResult ret = DrawText(pdfContext,
1936 pdfContext->fGraphicsState.fCurFont, 1949 pdfContext->fGraphicsState.fCurFont,
1937 pdfContext->fVarStack.top().GetString(), 1950 pdfContext->fObjectStack.top()->podofo()->GetString (),
1938 canvas); 1951 canvas);
1939 pdfContext->fVarStack.pop(); 1952 pdfContext->fObjectStack.pop();
1940 1953
1941 return ret; 1954 return ret;
1942 } 1955 }
1943 1956
1944 PdfResult PdfOp_quote(PdfContext* pdfContext, SkCanvas* canvas, PdfTokenLooper** looper) { 1957 PdfResult PdfOp_quote(PdfContext* pdfContext, SkCanvas* canvas, PdfTokenLooper** looper) {
1945 if (!pdfContext->fGraphicsState.fTextBlock) { 1958 if (!pdfContext->fGraphicsState.fTextBlock) {
1946 // TODO(edisonn): try to recover and draw it any way? 1959 // TODO(edisonn): try to recover and draw it any way?
1947 return kIgnoreError_PdfResult; 1960 return kIgnoreError_PdfResult;
1948 } 1961 }
1949 1962
1950 PdfOp_T_star(pdfContext, canvas, looper); 1963 PdfOp_T_star(pdfContext, canvas, looper);
1951 // Do not pop, and push, just transfer the param to Tj 1964 // Do not pop, and push, just transfer the param to Tj
1952 return PdfOp_Tj(pdfContext, canvas, looper); 1965 return PdfOp_Tj(pdfContext, canvas, looper);
1953 } 1966 }
1954 1967
1955 PdfResult PdfOp_doublequote(PdfContext* pdfContext, SkCanvas* canvas, PdfTokenLo oper** looper) { 1968 PdfResult PdfOp_doublequote(PdfContext* pdfContext, SkCanvas* canvas, PdfTokenLo oper** looper) {
1956 if (!pdfContext->fGraphicsState.fTextBlock) { 1969 if (!pdfContext->fGraphicsState.fTextBlock) {
1957 // TODO(edisonn): try to recover and draw it any way? 1970 // TODO(edisonn): try to recover and draw it any way?
1958 return kIgnoreError_PdfResult; 1971 return kIgnoreError_PdfResult;
1959 } 1972 }
1960 1973
1961 PdfVariant str = pdfContext->fVarStack.top(); pdfContext->fVarStack.po p(); 1974 SkPdfObject* str = pdfContext->fObjectStack.top(); pdfContext->fObject Stack.pop();
1962 PdfVariant ac = pdfContext->fVarStack.top(); pdfContext->fVarStack.po p(); 1975 SkPdfObject* ac = pdfContext->fObjectStack.top(); pdfContext->fObject Stack.pop();
1963 PdfVariant aw = pdfContext->fVarStack.top(); pdfContext->fVarStack.po p(); 1976 SkPdfObject* aw = pdfContext->fObjectStack.top(); pdfContext->fObject Stack.pop();
1964 1977
1965 pdfContext->fVarStack.push(aw); 1978 pdfContext->fObjectStack.push(aw);
1966 PdfOp_Tw(pdfContext, canvas, looper); 1979 PdfOp_Tw(pdfContext, canvas, looper);
1967 1980
1968 pdfContext->fVarStack.push(ac); 1981 pdfContext->fObjectStack.push(ac);
1969 PdfOp_Tc(pdfContext, canvas, looper); 1982 PdfOp_Tc(pdfContext, canvas, looper);
1970 1983
1971 pdfContext->fVarStack.push(str); 1984 pdfContext->fObjectStack.push(str);
1972 PdfOp_quote(pdfContext, canvas, looper); 1985 PdfOp_quote(pdfContext, canvas, looper);
1973 1986
1974 return kPartial_PdfResult; 1987 return kPartial_PdfResult;
1975 } 1988 }
1976 1989
1977 PdfResult PdfOp_TJ(PdfContext* pdfContext, SkCanvas* canvas, PdfTokenLooper** lo oper) { 1990 PdfResult PdfOp_TJ(PdfContext* pdfContext, SkCanvas* canvas, PdfTokenLooper** lo oper) {
1978 if (!pdfContext->fGraphicsState.fTextBlock) { 1991 if (!pdfContext->fGraphicsState.fTextBlock) {
1979 // TODO(edisonn): try to recover and draw it any way? 1992 // TODO(edisonn): try to recover and draw it any way?
1980 return kIgnoreError_PdfResult; 1993 return kIgnoreError_PdfResult;
1981 } 1994 }
1982 1995
1983 PdfArray array = pdfContext->fVarStack.top().GetArray(); 1996 SkPdfArray* array = pdfContext->fObjectStack.top()->asArray();
1984 pdfContext->fVarStack.pop(); 1997 pdfContext->fObjectStack.pop();
1985 1998
1986 for( int i=0; i<static_cast<int>(array.GetSize()); i++ ) 1999 for( int i=0; i<static_cast<int>(array->size()); i++ )
1987 { 2000 {
1988 if( array[i].IsString() || array[i].IsHexString() ) { 2001 if( (*array)[i].asString()) {
1989 DrawText(pdfContext, 2002 DrawText(pdfContext,
1990 pdfContext->fGraphicsState.fCurFont, 2003 pdfContext->fGraphicsState.fCurFont,
1991 array[i].GetString(), 2004 (*array)[i].podofo()->GetString(),
1992 canvas); 2005 canvas);
1993 } else if (array[i].IsReal() || array[i].IsNumber()) { 2006 } else if ((*array)[i].asInteger() || (*array)[i].asNumber()) {
1994 double dx = array[i].GetReal(); 2007 double dx = (*array)[i].asNumber()->value();
1995 SkMatrix matrix; 2008 SkMatrix matrix;
1996 matrix.setAll(SkDoubleToScalar(1), 2009 matrix.setAll(SkDoubleToScalar(1),
1997 SkDoubleToScalar(0), 2010 SkDoubleToScalar(0),
1998 // TODO(edisonn): use writing mode, vertical/horizonta l. 2011 // TODO(edisonn): use writing mode, vertical/horizonta l.
1999 SkDoubleToScalar(-dx), // amount is substracted!!! 2012 SkDoubleToScalar(-dx), // amount is substracted!!!
2000 SkDoubleToScalar(0), 2013 SkDoubleToScalar(0),
2001 SkDoubleToScalar(1), 2014 SkDoubleToScalar(1),
2002 SkDoubleToScalar(0), 2015 SkDoubleToScalar(0),
2003 SkDoubleToScalar(0), 2016 SkDoubleToScalar(0),
2004 SkDoubleToScalar(0), 2017 SkDoubleToScalar(0),
2005 SkDoubleToScalar(1)); 2018 SkDoubleToScalar(1));
2006 2019
2007 pdfContext->fGraphicsState.fMatrixTm.preConcat(matrix); 2020 pdfContext->fGraphicsState.fMatrixTm.preConcat(matrix);
2008 } 2021 }
2009 } 2022 }
2010 return kPartial_PdfResult; // TODO(edisonn): Implement fully DrawText befor e returing OK. 2023 return kPartial_PdfResult; // TODO(edisonn): Implement fully DrawText befor e returing OK.
2011 } 2024 }
2012 2025
2013 PdfResult PdfOp_CS_cs(PdfContext* pdfContext, SkCanvas* canvas, PdfColorOperator * colorOperator) { 2026 PdfResult PdfOp_CS_cs(PdfContext* pdfContext, SkCanvas* canvas, PdfColorOperator * colorOperator) {
2014 colorOperator->fColorSpace = pdfContext->fVarStack.top().GetName().GetName() ; pdfContext->fVarStack.pop(); 2027 colorOperator->fColorSpace = pdfContext->fObjectStack.top()->asName()->value (); pdfContext->fObjectStack.pop();
2015 return kOK_PdfResult; 2028 return kOK_PdfResult;
2016 } 2029 }
2017 2030
2018 PdfResult PdfOp_CS(PdfContext* pdfContext, SkCanvas* canvas, PdfTokenLooper** lo oper) { 2031 PdfResult PdfOp_CS(PdfContext* pdfContext, SkCanvas* canvas, PdfTokenLooper** lo oper) {
2019 return PdfOp_CS_cs(pdfContext, canvas, &pdfContext->fGraphicsState.fStroking ); 2032 return PdfOp_CS_cs(pdfContext, canvas, &pdfContext->fGraphicsState.fStroking );
2020 } 2033 }
2021 2034
2022 PdfResult PdfOp_cs(PdfContext* pdfContext, SkCanvas* canvas, PdfTokenLooper** lo oper) { 2035 PdfResult PdfOp_cs(PdfContext* pdfContext, SkCanvas* canvas, PdfTokenLooper** lo oper) {
2023 return PdfOp_CS_cs(pdfContext, canvas, &pdfContext->fGraphicsState.fNonStrok ing); 2036 return PdfOp_CS_cs(pdfContext, canvas, &pdfContext->fGraphicsState.fNonStrok ing);
2024 } 2037 }
2025 2038
2026 PdfResult PdfOp_SC_sc(PdfContext* pdfContext, SkCanvas* canvas, PdfColorOperator * colorOperator) { 2039 PdfResult PdfOp_SC_sc(PdfContext* pdfContext, SkCanvas* canvas, PdfColorOperator * colorOperator) {
2027 double c[4]; 2040 double c[4];
2028 pdf_int64 v[4]; 2041 pdf_int64 v[4];
2029 2042
2030 int n = GetColorSpaceComponents(colorOperator->fColorSpace); 2043 int n = GetColorSpaceComponents(colorOperator->fColorSpace);
2031 2044
2032 bool doubles = true; 2045 bool doubles = true;
2033 if (colorOperator->fColorSpace == "Indexed") { 2046 if (colorOperator->fColorSpace == "Indexed") {
2034 doubles = false; 2047 doubles = false;
2035 } 2048 }
2036 2049
2037 #ifdef PDF_TRACE 2050 #ifdef PDF_TRACE
2038 printf("color space = %s, N = %i\n", colorOperator->fColorSpace.c_str(), n); 2051 printf("color space = %s, N = %i\n", colorOperator->fColorSpace.c_str(), n);
2039 #endif 2052 #endif
2040 2053
2041 for (int i = n - 1; i >= 0 ; i--) { 2054 for (int i = n - 1; i >= 0 ; i--) {
2042 if (doubles) { 2055 if (doubles) {
2043 c[i] = pdfContext->fVarStack.top().GetReal(); pdfContext->fVarSt ack.pop(); 2056 c[i] = pdfContext->fObjectStack.top()->asNumber()->value(); pdfC ontext->fObjectStack.pop();
2044 } else { 2057 } else {
2045 v[i] = pdfContext->fVarStack.top().GetNumber(); pdfContext->fVarSt ack.pop(); 2058 v[i] = pdfContext->fObjectStack.top()->asInteger()->value(); pdfCo ntext->fObjectStack.pop();
2046 } 2059 }
2047 } 2060 }
2048 2061
2049 // TODO(edisonn): Now, set that color. Only DeviceRGB supported. 2062 // TODO(edisonn): Now, set that color. Only DeviceRGB supported.
2050 if (colorOperator->fColorSpace == "DeviceRGB") { 2063 if (colorOperator->fColorSpace == "DeviceRGB") {
2051 colorOperator->setRGBColor(SkColorSetRGB(255*c[0], 255*c[1], 255*c[2])); 2064 colorOperator->setRGBColor(SkColorSetRGB(255*c[0], 255*c[1], 255*c[2]));
2052 } 2065 }
2053 return kPartial_PdfResult; 2066 return kPartial_PdfResult;
2054 } 2067 }
2055 2068
2056 PdfResult PdfOp_SC(PdfContext* pdfContext, SkCanvas* canvas, PdfTokenLooper** lo oper) { 2069 PdfResult PdfOp_SC(PdfContext* pdfContext, SkCanvas* canvas, PdfTokenLooper** lo oper) {
2057 return PdfOp_SC_sc(pdfContext, canvas, &pdfContext->fGraphicsState.fStroking ); 2070 return PdfOp_SC_sc(pdfContext, canvas, &pdfContext->fGraphicsState.fStroking );
2058 } 2071 }
2059 2072
2060 PdfResult PdfOp_sc(PdfContext* pdfContext, SkCanvas* canvas, PdfTokenLooper** lo oper) { 2073 PdfResult PdfOp_sc(PdfContext* pdfContext, SkCanvas* canvas, PdfTokenLooper** lo oper) {
2061 return PdfOp_SC_sc(pdfContext, canvas, &pdfContext->fGraphicsState.fNonStrok ing); 2074 return PdfOp_SC_sc(pdfContext, canvas, &pdfContext->fGraphicsState.fNonStrok ing);
2062 } 2075 }
2063 2076
2064 PdfResult PdfOp_SCN_scn(PdfContext* pdfContext, SkCanvas* canvas, PdfColorOperat or* colorOperator) { 2077 PdfResult PdfOp_SCN_scn(PdfContext* pdfContext, SkCanvas* canvas, PdfColorOperat or* colorOperator) {
2065 PdfString name; 2078 PdfString name;
2066 2079
2067 if (pdfContext->fVarStack.top().IsName()) { 2080 if (pdfContext->fObjectStack.top()->asName()) {
2068 pdfContext->fVarStack.pop(); 2081 pdfContext->fObjectStack.pop();
2069 } 2082 }
2070 2083
2071 // TODO(edisonn): SCN supports more color spaces than SCN. Read and implemen t spec. 2084 // TODO(edisonn): SCN supports more color spaces than SCN. Read and implemen t spec.
2072 PdfOp_SC_sc(pdfContext, canvas, colorOperator); 2085 PdfOp_SC_sc(pdfContext, canvas, colorOperator);
2073 2086
2074 return kPartial_PdfResult; 2087 return kPartial_PdfResult;
2075 } 2088 }
2076 2089
2077 PdfResult PdfOp_SCN(PdfContext* pdfContext, SkCanvas* canvas, PdfTokenLooper** l ooper) { 2090 PdfResult PdfOp_SCN(PdfContext* pdfContext, SkCanvas* canvas, PdfTokenLooper** l ooper) {
2078 return PdfOp_SCN_scn(pdfContext, canvas, &pdfContext->fGraphicsState.fStroki ng); 2091 return PdfOp_SCN_scn(pdfContext, canvas, &pdfContext->fGraphicsState.fStroki ng);
2079 } 2092 }
2080 2093
2081 PdfResult PdfOp_scn(PdfContext* pdfContext, SkCanvas* canvas, PdfTokenLooper** l ooper) { 2094 PdfResult PdfOp_scn(PdfContext* pdfContext, SkCanvas* canvas, PdfTokenLooper** l ooper) {
2082 return PdfOp_SCN_scn(pdfContext, canvas, &pdfContext->fGraphicsState.fNonStr oking); 2095 return PdfOp_SCN_scn(pdfContext, canvas, &pdfContext->fGraphicsState.fNonStr oking);
2083 } 2096 }
2084 2097
2085 PdfResult PdfOp_G_g(PdfContext* pdfContext, SkCanvas* canvas, PdfColorOperator* colorOperator) { 2098 PdfResult PdfOp_G_g(PdfContext* pdfContext, SkCanvas* canvas, PdfColorOperator* colorOperator) {
2086 double gray = pdfContext->fVarStack.top().GetReal(); pdfContext->fVarSta ck.pop(); 2099 double gray = pdfContext->fObjectStack.top()->asNumber()->value(); pdfCo ntext->fObjectStack.pop();
2087 return kNYI_PdfResult; 2100 return kNYI_PdfResult;
2088 } 2101 }
2089 2102
2090 PdfResult PdfOp_G(PdfContext* pdfContext, SkCanvas* canvas, PdfTokenLooper** loo per) { 2103 PdfResult PdfOp_G(PdfContext* pdfContext, SkCanvas* canvas, PdfTokenLooper** loo per) {
2091 return PdfOp_G_g(pdfContext, canvas, &pdfContext->fGraphicsState.fStroking); 2104 return PdfOp_G_g(pdfContext, canvas, &pdfContext->fGraphicsState.fStroking);
2092 } 2105 }
2093 2106
2094 PdfResult PdfOp_g(PdfContext* pdfContext, SkCanvas* canvas, PdfTokenLooper** loo per) { 2107 PdfResult PdfOp_g(PdfContext* pdfContext, SkCanvas* canvas, PdfTokenLooper** loo per) {
2095 return PdfOp_G_g(pdfContext, canvas, &pdfContext->fGraphicsState.fNonStrokin g); 2108 return PdfOp_G_g(pdfContext, canvas, &pdfContext->fGraphicsState.fNonStrokin g);
2096 } 2109 }
2097 2110
2098 PdfResult PdfOp_RG_rg(PdfContext* pdfContext, SkCanvas* canvas, PdfColorOperator * colorOperator) { 2111 PdfResult PdfOp_RG_rg(PdfContext* pdfContext, SkCanvas* canvas, PdfColorOperator * colorOperator) {
2099 double b = pdfContext->fVarStack.top().GetReal(); pdfContext->fVarStack. pop(); 2112 double b = pdfContext->fObjectStack.top()->asNumber()->value(); pdfConte xt->fObjectStack.pop();
2100 double g = pdfContext->fVarStack.top().GetReal(); pdfContext->fVarStack. pop(); 2113 double g = pdfContext->fObjectStack.top()->asNumber()->value(); pdfConte xt->fObjectStack.pop();
2101 double r = pdfContext->fVarStack.top().GetReal(); pdfContext->fVarStack. pop(); 2114 double r = pdfContext->fObjectStack.top()->asNumber()->value(); pdfConte xt->fObjectStack.pop();
2102 2115
2103 colorOperator->fColorSpace = "DeviceRGB"; 2116 colorOperator->fColorSpace = "DeviceRGB";
2104 colorOperator->setRGBColor(SkColorSetRGB(255*r, 255*g, 255*b)); 2117 colorOperator->setRGBColor(SkColorSetRGB(255*r, 255*g, 255*b));
2105 return kOK_PdfResult; 2118 return kOK_PdfResult;
2106 } 2119 }
2107 2120
2108 PdfResult PdfOp_RG(PdfContext* pdfContext, SkCanvas* canvas, PdfTokenLooper** lo oper) { 2121 PdfResult PdfOp_RG(PdfContext* pdfContext, SkCanvas* canvas, PdfTokenLooper** lo oper) {
2109 return PdfOp_RG_rg(pdfContext, canvas, &pdfContext->fGraphicsState.fStroking ); 2122 return PdfOp_RG_rg(pdfContext, canvas, &pdfContext->fGraphicsState.fStroking );
2110 } 2123 }
2111 2124
2112 PdfResult PdfOp_rg(PdfContext* pdfContext, SkCanvas* canvas, PdfTokenLooper** lo oper) { 2125 PdfResult PdfOp_rg(PdfContext* pdfContext, SkCanvas* canvas, PdfTokenLooper** lo oper) {
2113 return PdfOp_RG_rg(pdfContext, canvas, &pdfContext->fGraphicsState.fNonStrok ing); 2126 return PdfOp_RG_rg(pdfContext, canvas, &pdfContext->fGraphicsState.fNonStrok ing);
2114 } 2127 }
2115 2128
2116 PdfResult PdfOp_K_k(PdfContext* pdfContext, SkCanvas* canvas, PdfColorOperator* colorOperator) { 2129 PdfResult PdfOp_K_k(PdfContext* pdfContext, SkCanvas* canvas, PdfColorOperator* colorOperator) {
2117 // TODO(edisonn): spec has some rules about overprint, implement them. 2130 // TODO(edisonn): spec has some rules about overprint, implement them.
2118 double k = pdfContext->fVarStack.top().GetReal(); pdfContext->fVarStack. pop(); 2131 double k = pdfContext->fObjectStack.top()->asNumber()->value(); pdfConte xt->fObjectStack.pop();
2119 double y = pdfContext->fVarStack.top().GetReal(); pdfContext->fVarStack. pop(); 2132 double y = pdfContext->fObjectStack.top()->asNumber()->value(); pdfConte xt->fObjectStack.pop();
2120 double m = pdfContext->fVarStack.top().GetReal(); pdfContext->fVarStack. pop(); 2133 double m = pdfContext->fObjectStack.top()->asNumber()->value(); pdfConte xt->fObjectStack.pop();
2121 double c = pdfContext->fVarStack.top().GetReal(); pdfContext->fVarStack. pop(); 2134 double c = pdfContext->fObjectStack.top()->asNumber()->value(); pdfConte xt->fObjectStack.pop();
2122 2135
2123 colorOperator->fColorSpace = "DeviceCMYK"; 2136 colorOperator->fColorSpace = "DeviceCMYK";
2124 // TODO(edisonn): Set color. 2137 // TODO(edisonn): Set color.
2125 return kNYI_PdfResult; 2138 return kNYI_PdfResult;
2126 } 2139 }
2127 2140
2128 PdfResult PdfOp_K(PdfContext* pdfContext, SkCanvas* canvas, PdfTokenLooper** loo per) { 2141 PdfResult PdfOp_K(PdfContext* pdfContext, SkCanvas* canvas, PdfTokenLooper** loo per) {
2129 return PdfOp_K_k(pdfContext, canvas, &pdfContext->fGraphicsState.fStroking); 2142 return PdfOp_K_k(pdfContext, canvas, &pdfContext->fGraphicsState.fStroking);
2130 } 2143 }
2131 2144
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
2185 PdfResult PdfOp_EI(PdfContext* pdfContext, SkCanvas* canvas, PdfTokenLooper** lo oper) { 2198 PdfResult PdfOp_EI(PdfContext* pdfContext, SkCanvas* canvas, PdfTokenLooper** lo oper) {
2186 #ifdef ASSERT_BAD_PDF_OPS 2199 #ifdef ASSERT_BAD_PDF_OPS
2187 SkASSERT(false); // must be processed in inline image looper, but let's 2200 SkASSERT(false); // must be processed in inline image looper, but let's
2188 // have the assert when testing good pdfs. 2201 // have the assert when testing good pdfs.
2189 #endif 2202 #endif
2190 return kIgnoreError_PdfResult; 2203 return kIgnoreError_PdfResult;
2191 } 2204 }
2192 2205
2193 //lineWidth w Set the line width in the graphics state (see “Line Width” on page 152). 2206 //lineWidth w Set the line width in the graphics state (see “Line Width” on page 152).
2194 PdfResult PdfOp_w(PdfContext* pdfContext, SkCanvas* canvas, PdfTokenLooper** loo per) { 2207 PdfResult PdfOp_w(PdfContext* pdfContext, SkCanvas* canvas, PdfTokenLooper** loo per) {
2195 double lineWidth = pdfContext->fVarStack.top().GetReal(); pdfContext->fV arStack.pop(); 2208 double lineWidth = pdfContext->fObjectStack.top()->asNumber()->value(); pdfContext->fObjectStack.pop();
2196 pdfContext->fGraphicsState.fLineWidth = lineWidth; 2209 pdfContext->fGraphicsState.fLineWidth = lineWidth;
2197 2210
2198 return kOK_PdfResult; 2211 return kOK_PdfResult;
2199 } 2212 }
2200 2213
2201 //lineCap J Set the line cap style in the graphics state (see “Line Cap Style” o n page 153). 2214 //lineCap J Set the line cap style in the graphics state (see “Line Cap Style” o n page 153).
2202 PdfResult PdfOp_J(PdfContext* pdfContext, SkCanvas* canvas, PdfTokenLooper** loo per) { 2215 PdfResult PdfOp_J(PdfContext* pdfContext, SkCanvas* canvas, PdfTokenLooper** loo per) {
2203 pdfContext->fVarStack.pop(); 2216 pdfContext->fObjectStack.pop();
2204 //double lineCap = pdfContext->fVarStack.top().GetReal(); pdfContext->fV arStack.pop(); 2217 //double lineCap = pdfContext->fObjectStack.top()->asNumber()->value(); pdfContext->fObjectStack.pop();
2205 2218
2206 return kNYI_PdfResult; 2219 return kNYI_PdfResult;
2207 } 2220 }
2208 2221
2209 //lineJoin j Set the line join style in the graphics state (see “Line Join Style ” on page 153). 2222 //lineJoin j Set the line join style in the graphics state (see “Line Join Style ” on page 153).
2210 PdfResult PdfOp_j(PdfContext* pdfContext, SkCanvas* canvas, PdfTokenLooper** loo per) { 2223 PdfResult PdfOp_j(PdfContext* pdfContext, SkCanvas* canvas, PdfTokenLooper** loo per) {
2211 pdfContext->fVarStack.pop(); 2224 pdfContext->fObjectStack.pop();
2212 //double lineJoin = pdfContext->fVarStack.top().GetReal(); pdfContext->f VarStack.pop(); 2225 //double lineJoin = pdfContext->fObjectStack.top()->asNumber()->value(); pdfContext->fObjectStack.pop();
2213 2226
2214 return kNYI_PdfResult; 2227 return kNYI_PdfResult;
2215 } 2228 }
2216 2229
2217 //miterLimit M Set the miter limit in the graphics state (see “Miter Limit” on p age 153). 2230 //miterLimit M Set the miter limit in the graphics state (see “Miter Limit” on p age 153).
2218 PdfResult PdfOp_M(PdfContext* pdfContext, SkCanvas* canvas, PdfTokenLooper** loo per) { 2231 PdfResult PdfOp_M(PdfContext* pdfContext, SkCanvas* canvas, PdfTokenLooper** loo per) {
2219 pdfContext->fVarStack.pop(); 2232 pdfContext->fObjectStack.pop();
2220 //double miterLimit = pdfContext->fVarStack.top().GetReal(); pdfContext- >fVarStack.pop(); 2233 //double miterLimit = pdfContext->fObjectStack.top()->asNumber()->value(); pdfContext->fObjectStack.pop();
2221 2234
2222 return kNYI_PdfResult; 2235 return kNYI_PdfResult;
2223 } 2236 }
2224 2237
2225 //dashArray dashPhase d Set the line dash pattern in the graphics state (see “Li ne Dash Pattern” on 2238 //dashArray dashPhase d Set the line dash pattern in the graphics state (see “Li ne Dash Pattern” on
2226 //page 155). 2239 //page 155).
2227 PdfResult PdfOp_d(PdfContext* pdfContext, SkCanvas* canvas, PdfTokenLooper** loo per) { 2240 PdfResult PdfOp_d(PdfContext* pdfContext, SkCanvas* canvas, PdfTokenLooper** loo per) {
2228 pdfContext->fVarStack.pop(); 2241 pdfContext->fObjectStack.pop();
2229 pdfContext->fVarStack.pop(); 2242 pdfContext->fObjectStack.pop();
2230 2243
2231 return kNYI_PdfResult; 2244 return kNYI_PdfResult;
2232 } 2245 }
2233 2246
2234 //intent ri (PDF 1.1) Set the color rendering intent in the graphics state (see “Rendering Intents” on page 197). 2247 //intent ri (PDF 1.1) Set the color rendering intent in the graphics state (see “Rendering Intents” on page 197).
2235 PdfResult PdfOp_ri(PdfContext* pdfContext, SkCanvas* canvas, PdfTokenLooper** lo oper) { 2248 PdfResult PdfOp_ri(PdfContext* pdfContext, SkCanvas* canvas, PdfTokenLooper** lo oper) {
2236 pdfContext->fVarStack.pop(); 2249 pdfContext->fObjectStack.pop();
2237 2250
2238 return kNYI_PdfResult; 2251 return kNYI_PdfResult;
2239 } 2252 }
2240 2253
2241 //flatness i Set the flatness tolerance in the graphics state (see Section 6.5.1, “Flatness 2254 //flatness i Set the flatness tolerance in the graphics state (see Section 6.5.1, “Flatness
2242 //Tolerance”). flatness is a number in the range 0 to 100; a value of 0 speci- 2255 //Tolerance”). flatness is a number in the range 0 to 100; a value of 0 speci-
2243 //fies the output device’s default flatness tolerance. 2256 //fies the output device’s default flatness tolerance.
2244 PdfResult PdfOp_i(PdfContext* pdfContext, SkCanvas* canvas, PdfTokenLooper** loo per) { 2257 PdfResult PdfOp_i(PdfContext* pdfContext, SkCanvas* canvas, PdfTokenLooper** loo per) {
2245 pdfContext->fVarStack.pop(); 2258 pdfContext->fObjectStack.pop();
2246 2259
2247 return kNYI_PdfResult; 2260 return kNYI_PdfResult;
2248 } 2261 }
2249 2262
2250 //dictName gs (PDF 1.2) Set the specified parameters in the graphics state. dictN ame is 2263 //dictName gs (PDF 1.2) Set the specified parameters in the graphics state. dictN ame is
2251 //the name of a graphics state parameter dictionary in the ExtGState subdictiona ry of the current resource dictionary (see the next section). 2264 //the name of a graphics state parameter dictionary in the ExtGState subdictiona ry of the current resource dictionary (see the next section).
2252 PdfResult PdfOp_gs(PdfContext* pdfContext, SkCanvas* canvas, PdfTokenLooper** lo oper) { 2265 PdfResult PdfOp_gs(PdfContext* pdfContext, SkCanvas* canvas, PdfTokenLooper** lo oper) {
2253 PdfName name = pdfContext->fVarStack.top().GetName(); pdfContext->fVarSta ck.pop(); 2266 std::string name = pdfContext->fObjectStack.top()->asName()->value(); pdf Context->fObjectStack.pop();
2254 2267
2255 #ifdef PDF_TRACE 2268 #ifdef PDF_TRACE
2256 std::string str; 2269 std::string str;
2257 #endif 2270 #endif
2258 2271
2259 const PdfObject* resources = pdfContext->fGraphicsState.fResources.podofo();
2260
2261 if (resources == NULL) {
2262 #ifdef PDF_TRACE
2263 printf("WARNING: No Resources for a page with 'gs' operator!\n");
2264 #endif
2265 return kIgnoreError_PdfResult;
2266 }
2267
2268 #ifdef PDF_TRACE
2269 resources->ToString(str);
2270 printf("Print gs Page Resources: %s\n", str.c_str());
2271 #endif
2272
2273 if (!resources->IsDictionary()) {
2274 #ifdef PDF_TRACE
2275 printf("Resources is not a dictionary!\n");
2276 #endif
2277 return kIgnoreError_PdfResult;
2278 }
2279
2280 const PdfDictionary& resourceDict = resources->GetDictionary();
2281 //Next, get the ExtGState Dictionary from the Resource Dictionary: 2272 //Next, get the ExtGState Dictionary from the Resource Dictionary:
2282 const PdfObject* extGStateDictionary = resolveReferenceObject(pdfContext->fP dfDoc, 2273 const SkPdfDictionary* extGStateDictionary = pdfContext->fGraphicsState.fRes ources->ExtGState();
2283 resourceDict.Get Key("ExtGState"));
2284 2274
2285 if (extGStateDictionary == NULL) { 2275 if (extGStateDictionary == NULL) {
2286 #ifdef PDF_TRACE 2276 #ifdef PDF_TRACE
2287 printf("ExtGState is NULL!\n"); 2277 printf("ExtGState is NULL!\n");
2288 #endif 2278 #endif
2289 return kIgnoreError_PdfResult; 2279 return kIgnoreError_PdfResult;
2290 } 2280 }
2291 2281
2292 if (!extGStateDictionary->IsDictionary()) { 2282 SkPdfObject value = extGStateDictionary->get(name.c_str());
2293 #ifdef PDF_TRACE
2294 printf("extGStateDictionary is not a dictionary!\n");
2295 #endif
2296 return kIgnoreError_PdfResult;
2297 }
2298
2299 const PdfObject* value =
2300 resolveReferenceObject(pdfContext->fPdfDoc,
2301 extGStateDictionary->GetDictionary().GetKey(n ame));
2302
2303 if (value == NULL) {
2304 #ifdef PDF_TRACE
2305 printf("Named object not found!\n");
2306 #endif
2307 return kIgnoreError_PdfResult;
2308 }
2309 2283
2310 #ifdef PDF_TRACE 2284 #ifdef PDF_TRACE
2311 value->ToString(str); 2285 // value->ToString(str);
2312 printf("gs object value: %s\n", str.c_str()); 2286 // printf("gs object value: %s\n", str.c_str());
2313 #endif 2287 #endif
2314 2288
2315 SkPdfGraphicsStateDictionary gs(pdfContext->fPdfDoc, value); 2289 SkPdfGraphicsStateDictionary* gs = NULL;
2290 PodofoMapper::map(value, &gs);
2316 2291
2317 // TODO(edisonn): now load all those properties in graphic state. 2292 // TODO(edisonn): now load all those properties in graphic state.
2318 2293
2319 return kNYI_PdfResult; 2294 return kNYI_PdfResult;
2320 } 2295 }
2321 2296
2322 //charSpace Tc Set the character spacing, Tc 2297 //charSpace Tc Set the character spacing, Tc
2323 //, to charSpace, which is a number expressed in unscaled text space units. Char acter spacing is used by the Tj, TJ, and ' operators. 2298 //, to charSpace, which is a number expressed in unscaled text space units. Char acter spacing is used by the Tj, TJ, and ' operators.
2324 //Initial value: 0. 2299 //Initial value: 0.
2325 PdfResult PdfOp_Tc(PdfContext* pdfContext, SkCanvas* canvas, PdfTokenLooper** lo oper) { 2300 PdfResult PdfOp_Tc(PdfContext* pdfContext, SkCanvas* canvas, PdfTokenLooper** lo oper) {
2326 double charSpace = pdfContext->fVarStack.top().GetReal(); pdfContext->fV arStack.pop(); 2301 double charSpace = pdfContext->fObjectStack.top()->asNumber()->value(); pdfContext->fObjectStack.pop();
2327 pdfContext->fGraphicsState.fCharSpace = charSpace; 2302 pdfContext->fGraphicsState.fCharSpace = charSpace;
2328 2303
2329 return kOK_PdfResult; 2304 return kOK_PdfResult;
2330 } 2305 }
2331 2306
2332 //wordSpace Tw Set the word spacing, T 2307 //wordSpace Tw Set the word spacing, T
2333 //w 2308 //w
2334 //, to wordSpace, which is a number expressed in unscaled 2309 //, to wordSpace, which is a number expressed in unscaled
2335 //text space units. Word spacing is used by the Tj, TJ, and ' operators. Initial 2310 //text space units. Word spacing is used by the Tj, TJ, and ' operators. Initial
2336 //value: 0. 2311 //value: 0.
2337 PdfResult PdfOp_Tw(PdfContext* pdfContext, SkCanvas* canvas, PdfTokenLooper** lo oper) { 2312 PdfResult PdfOp_Tw(PdfContext* pdfContext, SkCanvas* canvas, PdfTokenLooper** lo oper) {
2338 double wordSpace = pdfContext->fVarStack.top().GetReal(); pdfContext->fV arStack.pop(); 2313 double wordSpace = pdfContext->fObjectStack.top()->asNumber()->value(); pdfContext->fObjectStack.pop();
2339 pdfContext->fGraphicsState.fWordSpace = wordSpace; 2314 pdfContext->fGraphicsState.fWordSpace = wordSpace;
2340 2315
2341 return kOK_PdfResult; 2316 return kOK_PdfResult;
2342 } 2317 }
2343 2318
2344 //scale Tz Set the horizontal scaling, Th 2319 //scale Tz Set the horizontal scaling, Th
2345 //, to (scale ˜ 100). scale is a number specifying the 2320 //, to (scale ˜ 100). scale is a number specifying the
2346 //percentage of the normal width. Initial value: 100 (normal width). 2321 //percentage of the normal width. Initial value: 100 (normal width).
2347 PdfResult PdfOp_Tz(PdfContext* pdfContext, SkCanvas* canvas, PdfTokenLooper** lo oper) { 2322 PdfResult PdfOp_Tz(PdfContext* pdfContext, SkCanvas* canvas, PdfTokenLooper** lo oper) {
2348 double scale = pdfContext->fVarStack.top().GetReal(); pdfContext->fVarSt ack.pop(); 2323 double scale = pdfContext->fObjectStack.top()->asNumber()->value(); pdfC ontext->fObjectStack.pop();
2349 2324
2350 return kNYI_PdfResult; 2325 return kNYI_PdfResult;
2351 } 2326 }
2352 2327
2353 //render Tr Set the text rendering mode, T 2328 //render Tr Set the text rendering mode, T
2354 //mode, to render, which is an integer. Initial value: 0. 2329 //mode, to render, which is an integer. Initial value: 0.
2355 PdfResult PdfOp_Tr(PdfContext* pdfContext, SkCanvas* canvas, PdfTokenLooper** lo oper) { 2330 PdfResult PdfOp_Tr(PdfContext* pdfContext, SkCanvas* canvas, PdfTokenLooper** lo oper) {
2356 double render = pdfContext->fVarStack.top().GetReal(); pdfContext->fVarS tack.pop(); 2331 double render = pdfContext->fObjectStack.top()->asNumber()->value(); pdf Context->fObjectStack.pop();
2357 2332
2358 return kNYI_PdfResult; 2333 return kNYI_PdfResult;
2359 } 2334 }
2360 2335
2361 //rise Ts Set the text rise, Trise, to rise, which is a number expressed in unsc aled text space 2336 //rise Ts Set the text rise, Trise, to rise, which is a number expressed in unsc aled text space
2362 //units. Initial value: 0. 2337 //units. Initial value: 0.
2363 PdfResult PdfOp_Ts(PdfContext* pdfContext, SkCanvas* canvas, PdfTokenLooper** lo oper) { 2338 PdfResult PdfOp_Ts(PdfContext* pdfContext, SkCanvas* canvas, PdfTokenLooper** lo oper) {
2364 double rise = pdfContext->fVarStack.top().GetReal(); pdfContext->fVarSta ck.pop(); 2339 double rise = pdfContext->fObjectStack.top()->asNumber()->value(); pdfCo ntext->fObjectStack.pop();
2365 2340
2366 return kNYI_PdfResult; 2341 return kNYI_PdfResult;
2367 } 2342 }
2368 2343
2369 //wx wy d0 2344 //wx wy d0
2370 PdfResult PdfOp_d0(PdfContext* pdfContext, SkCanvas* canvas, PdfTokenLooper** lo oper) { 2345 PdfResult PdfOp_d0(PdfContext* pdfContext, SkCanvas* canvas, PdfTokenLooper** lo oper) {
2371 pdfContext->fVarStack.pop(); 2346 pdfContext->fObjectStack.pop();
2372 pdfContext->fVarStack.pop(); 2347 pdfContext->fObjectStack.pop();
2373 2348
2374 return kNYI_PdfResult; 2349 return kNYI_PdfResult;
2375 } 2350 }
2376 2351
2377 //wx wy llx lly urx ury d1 2352 //wx wy llx lly urx ury d1
2378 PdfResult PdfOp_d1(PdfContext* pdfContext, SkCanvas* canvas, PdfTokenLooper** lo oper) { 2353 PdfResult PdfOp_d1(PdfContext* pdfContext, SkCanvas* canvas, PdfTokenLooper** lo oper) {
2379 pdfContext->fVarStack.pop(); 2354 pdfContext->fObjectStack.pop();
2380 pdfContext->fVarStack.pop(); 2355 pdfContext->fObjectStack.pop();
2381 pdfContext->fVarStack.pop(); 2356 pdfContext->fObjectStack.pop();
2382 pdfContext->fVarStack.pop(); 2357 pdfContext->fObjectStack.pop();
2383 pdfContext->fVarStack.pop(); 2358 pdfContext->fObjectStack.pop();
2384 pdfContext->fVarStack.pop(); 2359 pdfContext->fObjectStack.pop();
2385 2360
2386 return kNYI_PdfResult; 2361 return kNYI_PdfResult;
2387 } 2362 }
2388 2363
2389 //name sh 2364 //name sh
2390 PdfResult PdfOp_sh(PdfContext* pdfContext, SkCanvas* canvas, PdfTokenLooper** lo oper) { 2365 PdfResult PdfOp_sh(PdfContext* pdfContext, SkCanvas* canvas, PdfTokenLooper** lo oper) {
2391 pdfContext->fVarStack.pop(); 2366 pdfContext->fObjectStack.pop();
2392 2367
2393 return kNYI_PdfResult; 2368 return kNYI_PdfResult;
2394 } 2369 }
2395 2370
2396 //name Do 2371 //name Do
2397 PdfResult PdfOp_Do(PdfContext* pdfContext, SkCanvas* canvas, PdfTokenLooper** lo oper) { 2372 PdfResult PdfOp_Do(PdfContext* pdfContext, SkCanvas* canvas, PdfTokenLooper** lo oper) {
2398 PdfName name = pdfContext->fVarStack.top().GetName(); pdfContext->fVarSta ck.pop(); 2373 std::string name = pdfContext->fObjectStack.top()->asName()->value(); pdf Context->fObjectStack.pop();
2399 2374
2400 const PdfObject* resources = pdfContext->fGraphicsState.fResources.podofo(); 2375 SkPdfDictionary* xObject = pdfContext->fGraphicsState.fResources->XObject() ;
2401 2376
2402 if (resources == NULL) { 2377 if (xObject == NULL) {
2403 #ifdef PDF_TRACE
2404 printf("WARNING: No Resources for a page with 'Do' operator!s\n");
2405 #endif
2406 return kIgnoreError_PdfResult;
2407 }
2408
2409 #ifdef PDF_TRACE
2410 std::string str;
2411 resources->ToString(str);
2412 printf("Print Do Page Resources: %s\n", str.c_str());
2413 #endif
2414
2415 if (!resources->IsDictionary()) {
2416 #ifdef PDF_TRACE
2417 printf("Resources is not a dictionary!\n");
2418 #endif
2419 return kIgnoreError_PdfResult;
2420 }
2421
2422 const PdfDictionary& resourceDict = resources->GetDictionary();
2423 //Next, get the XObject Dictionary from the Resource Dictionary:
2424 const PdfObject* xObjectDictionary = resolveReferenceObject(pdfContext->fPdf Doc,
2425 resourceDict.Get Key("XObject"));
2426
2427 if (xObjectDictionary == NULL) {
2428 #ifdef PDF_TRACE 2378 #ifdef PDF_TRACE
2429 printf("XObject is NULL!\n"); 2379 printf("XObject is NULL!\n");
2430 #endif 2380 #endif
2431 return kIgnoreError_PdfResult; 2381 return kIgnoreError_PdfResult;
2432 } 2382 }
2433 2383
2434 if (!xObjectDictionary->IsDictionary()) { 2384 SkPdfObject value = xObject->get(name.c_str());
2435 #ifdef PDF_TRACE
2436 printf("xObjectDictionary is not a dictionary!\n");
2437 #endif
2438 return kIgnoreError_PdfResult;
2439 }
2440
2441 const PdfObject* value =
2442 resolveReferenceObject(pdfContext->fPdfDoc,
2443 xObjectDictionary->GetDictionary().GetKey(nam e));
2444
2445 if (value == NULL) {
2446 #ifdef PDF_TRACE
2447 printf("Named object not found!\n");
2448 #endif
2449 return kIgnoreError_PdfResult;
2450 }
2451 2385
2452 #ifdef PDF_TRACE 2386 #ifdef PDF_TRACE
2453 value->ToString(str); 2387 // value->ToString(str);
2454 printf("Do object value: %s\n", str.c_str()); 2388 // printf("Do object value: %s\n", str.c_str());
2455 #endif 2389 #endif
2456 2390
2457 return doXObject(pdfContext, canvas, *value); 2391 return doXObject(pdfContext, canvas, value);
2458 } 2392 }
2459 2393
2460
2461 //tag MP Designate a marked-content point. tag is a name object indicating the r ole or 2394 //tag MP Designate a marked-content point. tag is a name object indicating the r ole or
2462 //significance of the point. 2395 //significance of the point.
2463 PdfResult PdfOp_MP(PdfContext* pdfContext, SkCanvas* canvas, PdfTokenLooper** lo oper) { 2396 PdfResult PdfOp_MP(PdfContext* pdfContext, SkCanvas* canvas, PdfTokenLooper** lo oper) {
2464 pdfContext->fVarStack.pop(); 2397 pdfContext->fObjectStack.pop();
2465 2398
2466 return kNYI_PdfResult; 2399 return kNYI_PdfResult;
2467 } 2400 }
2468 2401
2469 //tag properties DP Designate a marked-content point with an associated property list. tag is a 2402 //tag properties DP Designate a marked-content point with an associated property list. tag is a
2470 //name object indicating the role or significance of the point; properties is 2403 //name object indicating the role or significance of the point; properties is
2471 //either an inline dictionary containing the property list or a name object 2404 //either an inline dictionary containing the property list or a name object
2472 //associated with it in the Properties subdictionary of the current resource 2405 //associated with it in the Properties subdictionary of the current resource
2473 //dictionary (see Section 9.5.1, “Property Lists”). 2406 //dictionary (see Section 9.5.1, “Property Lists”).
2474 PdfResult PdfOp_DP(PdfContext* pdfContext, SkCanvas* canvas, PdfTokenLooper** lo oper) { 2407 PdfResult PdfOp_DP(PdfContext* pdfContext, SkCanvas* canvas, PdfTokenLooper** lo oper) {
2475 pdfContext->fVarStack.pop(); 2408 pdfContext->fObjectStack.pop();
2476 pdfContext->fVarStack.pop(); 2409 pdfContext->fObjectStack.pop();
2477 2410
2478 return kNYI_PdfResult; 2411 return kNYI_PdfResult;
2479 } 2412 }
2480 2413
2481 //tag BMC Begin a marked-content sequence terminated by a balancing EMC operator . 2414 //tag BMC Begin a marked-content sequence terminated by a balancing EMC operator .
2482 //tag is a name object indicating the role or significance of the sequence. 2415 //tag is a name object indicating the role or significance of the sequence.
2483 PdfResult PdfOp_BMC(PdfContext* pdfContext, SkCanvas* canvas, PdfTokenLooper** l ooper) { 2416 PdfResult PdfOp_BMC(PdfContext* pdfContext, SkCanvas* canvas, PdfTokenLooper** l ooper) {
2484 pdfContext->fVarStack.pop(); 2417 pdfContext->fObjectStack.pop();
2485 2418
2486 return kNYI_PdfResult; 2419 return kNYI_PdfResult;
2487 } 2420 }
2488 2421
2489 //tag properties BDC Begin a marked-content sequence with an associated property list, terminated 2422 //tag properties BDC Begin a marked-content sequence with an associated property list, terminated
2490 //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 2423 //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
2491 //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”). 2424 //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”).
2492 PdfResult PdfOp_BDC(PdfContext* pdfContext, SkCanvas* canvas, PdfTokenLooper** l ooper) { 2425 PdfResult PdfOp_BDC(PdfContext* pdfContext, SkCanvas* canvas, PdfTokenLooper** l ooper) {
2493 pdfContext->fVarStack.pop(); 2426 pdfContext->fObjectStack.pop();
2494 pdfContext->fVarStack.pop(); 2427 pdfContext->fObjectStack.pop();
2495 2428
2496 return kNYI_PdfResult; 2429 return kNYI_PdfResult;
2497 } 2430 }
2498 2431
2499 //— EMC End a marked-content sequence begun by a BMC or BDC operator. 2432 //— EMC End a marked-content sequence begun by a BMC or BDC operator.
2500 PdfResult PdfOp_EMC(PdfContext* pdfContext, SkCanvas* canvas, PdfTokenLooper** l ooper) { 2433 PdfResult PdfOp_EMC(PdfContext* pdfContext, SkCanvas* canvas, PdfTokenLooper** l ooper) {
2501 return kNYI_PdfResult; 2434 return kNYI_PdfResult;
2502 } 2435 }
2503 2436
2504 void initPdfOperatorRenderes() { 2437 void initPdfOperatorRenderes() {
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
2603 std::map<std::string, int>::iterator iter; 2536 std::map<std::string, int>::iterator iter;
2604 2537
2605 for (int i = 0 ; i < kCount_PdfResult; i++) { 2538 for (int i = 0 ; i < kCount_PdfResult; i++) {
2606 for (iter = gRenderStats[i].begin(); iter != gRenderStats[i].end(); ++it er) { 2539 for (iter = gRenderStats[i].begin(); iter != gRenderStats[i].end(); ++it er) {
2607 printf("%s: %s -> count %i\n", gRenderStatsNames[i], iter->first.c_s tr(), iter->second); 2540 printf("%s: %s -> count %i\n", gRenderStatsNames[i], iter->first.c_s tr(), iter->second);
2608 } 2541 }
2609 } 2542 }
2610 } 2543 }
2611 2544
2612 PdfResult PdfMainLooper::consumeToken(PdfToken& token) { 2545 PdfResult PdfMainLooper::consumeToken(PdfToken& token) {
2613 if( token.eType == ePdfContentsType_Keyword ) 2546 if (token.fType == kKeyword_TokenType)
2614 { 2547 {
2615 // TODO(edisonn): log trace flag (verbose, error, info, warning, ...) 2548 // TODO(edisonn): log trace flag (verbose, error, info, warning, ...)
2616 #ifdef PDF_TRACE 2549 #ifdef PDF_TRACE
2617 printf("KEYWORD: %s\n", token.pszToken); 2550 printf("KEYWORD: %s\n", token.fKeyword);
2618 #endif 2551 #endif
2619 PdfOperatorRenderer pdfOperatorRenderer = gPdfOps[token.pszToken]; 2552 PdfOperatorRenderer pdfOperatorRenderer = gPdfOps[token.fKeyword];
2620 if (pdfOperatorRenderer) { 2553 if (pdfOperatorRenderer) {
2621 // caller, main work is done by pdfOperatorRenderer(...) 2554 // caller, main work is done by pdfOperatorRenderer(...)
2622 PdfTokenLooper* childLooper = NULL; 2555 PdfTokenLooper* childLooper = NULL;
2623 gRenderStats[pdfOperatorRenderer(fPdfContext, fCanvas, &childLooper) ][token.pszToken]++; 2556 gRenderStats[pdfOperatorRenderer(fPdfContext, fCanvas, &childLooper) ][token.fKeyword]++;
2624 2557
2625 if (childLooper) { 2558 if (childLooper) {
2626 childLooper->setUp(this); 2559 childLooper->setUp(this);
2627 childLooper->loop(); 2560 childLooper->loop();
2628 delete childLooper; 2561 delete childLooper;
2629 } 2562 }
2630 } else { 2563 } else {
2631 gRenderStats[kUnsupported_PdfResult][token.pszToken]++; 2564 gRenderStats[kUnsupported_PdfResult][token.fKeyword]++;
2632 } 2565 }
2633 } 2566 }
2634 else if ( token.eType == ePdfContentsType_Variant ) 2567 else if (token.fType == kObject_TokenType)
2635 { 2568 {
2636 #ifdef PDF_TRACE 2569 #ifdef PDF_TRACE
2637 std::string _var; 2570 std::string _var;
2638 token.var.ToString(_var); 2571 token.fObject->podofo()->ToString(_var);
2639 printf("var: %s\n", _var.c_str()); 2572 printf("var: %s\n", _var.c_str());
2640 #endif 2573 #endif
2641 fPdfContext->fVarStack.push( token.var ); 2574 fPdfContext->fObjectStack.push( token.fObject );
2642 } 2575 }
2643 else if ( token.eType == ePdfContentsType_ImageData) { 2576 else if ( token.fType == kImageData_TokenType) {
2644 // TODO(edisonn): implement inline image. 2577 // TODO(edisonn): implement inline image.
2645 } 2578 }
2646 else { 2579 else {
2647 return kIgnoreError_PdfResult; 2580 return kIgnoreError_PdfResult;
2648 } 2581 }
2649 return kOK_PdfResult; 2582 return kOK_PdfResult;
2650 } 2583 }
2651 2584
2652 void PdfMainLooper::loop() { 2585 void PdfMainLooper::loop() {
2653 PdfToken token; 2586 PdfToken token;
2654 while (readToken(fTokenizer, &token)) { 2587 while (readToken(fTokenizer, &token)) {
2655 consumeToken(token); 2588 consumeToken(token);
2656 } 2589 }
2657 } 2590 }
2658 2591
2659 PdfResult PdfInlineImageLooper::consumeToken(PdfToken& token) { 2592 PdfResult PdfInlineImageLooper::consumeToken(PdfToken& token) {
2660 //pdfContext.fInlineImage.fKeyValuePairs[key] = value; 2593 //pdfContext.fInlineImage.fKeyValuePairs[key] = value;
2661 return kNYI_PdfResult; 2594 return kNYI_PdfResult;
2662 } 2595 }
2663 2596
2664 void PdfInlineImageLooper::loop() { 2597 void PdfInlineImageLooper::loop() {
2665 PdfToken token; 2598 PdfToken token;
2666 while (readToken(fTokenizer, &token)) { 2599 while (readToken(fTokenizer, &token)) {
2667 if (token.eType == ePdfContentsType_Keyword && strcmp(token.pszToken, "B X") == 0) { 2600 if (token.fType == kKeyword_TokenType && strcmp(token.fKeyword, "BX") == 0) {
2668 PdfTokenLooper* looper = new PdfCompatibilitySectionLooper(); 2601 PdfTokenLooper* looper = new PdfCompatibilitySectionLooper();
2669 looper->setUp(this); 2602 looper->setUp(this);
2670 looper->loop(); 2603 looper->loop();
2671 } else { 2604 } else {
2672 if (token.eType == ePdfContentsType_Keyword && strcmp(token.pszToken , "EI") == 0) { 2605 if (token.fType == kKeyword_TokenType && strcmp(token.fKeyword, "EI" ) == 0) {
2673 done(); 2606 done();
2674 return; 2607 return;
2675 } 2608 }
2676 2609
2677 consumeToken(token); 2610 consumeToken(token);
2678 } 2611 }
2679 } 2612 }
2680 // TODO(edisonn): report error/warning, EOF without EI. 2613 // TODO(edisonn): report error/warning, EOF without EI.
2681 } 2614 }
2682 2615
(...skipping 20 matching lines...) Expand all
2703 return fParent->consumeToken(token); 2636 return fParent->consumeToken(token);
2704 } 2637 }
2705 2638
2706 void PdfCompatibilitySectionLooper::loop() { 2639 void PdfCompatibilitySectionLooper::loop() {
2707 // TODO(edisonn): save stacks position, or create a new stack? 2640 // TODO(edisonn): save stacks position, or create a new stack?
2708 // TODO(edisonn): what happens if we pop out more variables then when we sta rted? 2641 // TODO(edisonn): what happens if we pop out more variables then when we sta rted?
2709 // restore them? fail? We could create a new operands stack for every new BX /EX section, 2642 // restore them? fail? We could create a new operands stack for every new BX /EX section,
2710 // pop-ing too much will not affect outside the section. 2643 // pop-ing too much will not affect outside the section.
2711 PdfToken token; 2644 PdfToken token;
2712 while (readToken(fTokenizer, &token)) { 2645 while (readToken(fTokenizer, &token)) {
2713 if (token.eType == ePdfContentsType_Keyword && strcmp(token.pszToken, "B X") == 0) { 2646 if (token.fType == kKeyword_TokenType && strcmp(token.fKeyword, "BX") == 0) {
2714 PdfTokenLooper* looper = new PdfCompatibilitySectionLooper(); 2647 PdfTokenLooper* looper = new PdfCompatibilitySectionLooper();
2715 looper->setUp(this); 2648 looper->setUp(this);
2716 looper->loop(); 2649 looper->loop();
2717 delete looper; 2650 delete looper;
2718 } else { 2651 } else {
2719 if (token.eType == ePdfContentsType_Keyword && strcmp(token.pszToken , "EX") == 0) break; 2652 if (token.fType == kKeyword_TokenType && strcmp(token.fKeyword, "EX" ) == 0) break;
2720 fParent->consumeToken(token); 2653 fParent->consumeToken(token);
2721 } 2654 }
2722 } 2655 }
2723 // TODO(edisonn): restore stack. 2656 // TODO(edisonn): restore stack.
2724 } 2657 }
2725 2658
2726 // TODO(edisonn): fix PoDoFo load ~/crashing/Shading.pdf 2659 // TODO(edisonn): fix PoDoFo load ~/crashing/Shading.pdf
2727 // TODO(edisonn): Add API for Forms viewing and editing 2660 // TODO(edisonn): Add API for Forms viewing and editing
2728 // e.g. SkBitmap getPage(int page); 2661 // e.g. SkBitmap getPage(int page);
2729 // int formsCount(); 2662 // int formsCount();
2730 // SkForm getForm(int formID); // SkForm(SkRect, .. other data) 2663 // SkForm getForm(int formID); // SkForm(SkRect, .. other data)
2731 // TODO (edisonn): Add intend when loading pdf, for example: for viewing, parsin g all content, ... 2664 // TODO (edisonn): Add intend when loading pdf, for example: for viewing, parsin g all content, ...
2732 // if we load the first page, and we zoom to fit to screen horizontally, then lo ad only those 2665 // if we load the first page, and we zoom to fit to screen horizontally, then lo ad only those
2733 // resources needed, so the preview is fast. 2666 // resources needed, so the preview is fast.
2734 // TODO (edisonn): hide parser/tokenizer behind and interface and a query langua ge, and resolve 2667 // TODO (edisonn): hide parser/tokenizer behind and interface and a query langua ge, and resolve
2735 // references automatically. 2668 // references automatically.
2736 class SkPdfViewer : public SkRefCnt { 2669 class SkPdfViewer : public SkRefCnt {
2737 public: 2670 public:
2738 2671
2739 bool load(const SkString inputFileName, SkPicture* out) { 2672 bool load(const SkString inputFileName, SkPicture* out) {
2740 2673
2741 initPdfOperatorRenderes(); 2674 initPdfOperatorRenderes();
2742 2675
2743 try 2676 try
2744 { 2677 {
2745 std::cout << "Init: " << inputFileName.c_str() << std::endl; 2678 std::cout << "Init: " << inputFileName.c_str() << std::endl;
2746 2679
2747 PdfMemDocument doc(inputFileName.c_str()); 2680 SkPdfDoc doc(inputFileName.c_str());
2748 if( !doc.GetPageCount() ) 2681 if( !doc.pages() )
2749 { 2682 {
2750 std::cout << "ERROR: Empty Document" << inputFileName.c_str() << std ::endl; 2683 std::cout << "ERROR: Empty Document" << inputFileName.c_str() << std ::endl;
2751 return false; 2684 return false;
2752 } else { 2685 } else {
2753 2686
2754 for (int pn = 0; pn < doc.GetPageCount(); ++pn) { 2687 for (int pn = 0; pn < doc.pages(); ++pn) {
2755 PoDoFo::PdfPage* page = doc.GetPage(pn); 2688 SkPdfPageObjectDictionary* page = doc.page(pn);
2756 PdfRect rect = page->GetMediaBox(); 2689
2690 // TODO(edisonn): implement inheritance properties as per PDF sp ec
2691 //SkRect rect = page->MediaBox();
2692 SkRect rect = doc.MediaBox(pn);
2693
2757 #ifdef PDF_TRACE 2694 #ifdef PDF_TRACE
2758 printf("Page Width: %f, Page Height: %f\n", rect.GetWidth(), rec t.GetHeight()); 2695 printf("Page Width: %f, Page Height: %f\n", SkScalarToDouble(rec t.width()), SkScalarToDouble(rect.height()));
2759 #endif 2696 #endif
2760 2697
2761 // TODO(edisonn): page->GetCropBox(), page->GetTrimBox() ... how to use? 2698 // TODO(edisonn): page->GetCropBox(), page->GetTrimBox() ... how to use?
2762 2699
2763 SkBitmap bitmap; 2700 SkBitmap bitmap;
2764 #ifdef PDF_DEBUG_3X 2701 #ifdef PDF_DEBUG_3X
2765 setup_bitmap(&bitmap, 3*rect.GetWidth(), 3*rect.GetHeight()); 2702 setup_bitmap(&bitmap, 3 * (int)SkScalarToDouble(rect.width()), 3 * (int)SkScalarToDouble(rect.height()))
2766 #else 2703 #else
2767 setup_bitmap(&bitmap, rect.GetWidth(), rect.GetHeight()); 2704 setup_bitmap(&bitmap, (int)SkScalarToDouble(rect.width()), (int) SkScalarToDouble(rect.height()));
2768 #endif 2705 #endif
2769 SkAutoTUnref<SkDevice> device(SkNEW_ARGS(SkDevice, (bitmap))); 2706 SkAutoTUnref<SkDevice> device(SkNEW_ARGS(SkDevice, (bitmap)));
2770 SkCanvas canvas(device); 2707 SkCanvas canvas(device);
2771 2708
2709 SkPdfTokenizer tokenizer = doc.tokenizerOfPage(pn);
2772 2710
2773 const char* pszToken = NULL; 2711 PdfContext pdfContext(doc);
2774 PdfVariant var;
2775 EPdfContentsType eType;
2776
2777 PdfContentsTokenizer tokenizer( page );
2778
2779 PdfContext pdfContext;
2780 pdfContext.fPdfPage = page;
2781 pdfContext.fPdfDoc = &doc;
2782 pdfContext.fOriginalMatrix = SkMatrix::I(); 2712 pdfContext.fOriginalMatrix = SkMatrix::I();
2783 pdfContext.fGraphicsState.fResources = SkPdfResourceDictionary(p dfContext.fPdfDoc, resolveReferenceObject(pdfContext.fPdfDoc, 2713 pdfContext.fGraphicsState.fResources = NULL;
2784 pdfContext.fPdfPage->GetResources())); 2714 PodofoMapper::map(*page->Resources(), &pdfContext.fGraphicsState .fResources);
2785 2715
2786 gPdfContext = &pdfContext; 2716 gPdfContext = &pdfContext;
2787 gDumpBitmap = &bitmap; 2717 gDumpBitmap = &bitmap;
2788 gDumpCanvas = &canvas; 2718 gDumpCanvas = &canvas;
2789 2719
2790 2720
2791 // TODO(edisonn): get matrix stuff right. 2721 // TODO(edisonn): get matrix stuff right.
2792 // TODO(edisonn): add DPI/scale/zoom. 2722 // TODO(edisonn): add DPI/scale/zoom.
2793 SkScalar z = SkIntToScalar(0); 2723 SkScalar z = SkIntToScalar(0);
2794 SkScalar w = SkDoubleToScalar(rect.GetWidth()); 2724 SkScalar w = rect.width();
2795 SkScalar h = SkDoubleToScalar(rect.GetHeight()); 2725 SkScalar h = rect.height();
2796 2726
2797 SkPoint pdfSpace[4] = {SkPoint::Make(z, z), SkPoint::Make(w, z), SkPoint::Make(w, h), SkPoint::Make(z, h)}; 2727 SkPoint pdfSpace[4] = {SkPoint::Make(z, z), SkPoint::Make(w, z), SkPoint::Make(w, h), SkPoint::Make(z, h)};
2798 // SkPoint skiaSpace[4] = {SkPoint::Make(z, h), SkPoint::Make(w, h), SkPoint::Make(w, z), SkPoint::Make(z, z)}; 2728 // SkPoint skiaSpace[4] = {SkPoint::Make(z, h), SkPoint::Make(w, h), SkPoint::Make(w, z), SkPoint::Make(z, z)};
2799 2729
2800 // TODO(edisonn): add flag for this app to create sourunding buf fer zone 2730 // TODO(edisonn): add flag for this app to create sourunding buf fer zone
2801 // TODO(edisonn): add flagg for no clipping. 2731 // TODO(edisonn): add flagg for no clipping.
2802 // Use larger image to make sure we do not draw anything outside of page 2732 // Use larger image to make sure we do not draw anything outside of page
2803 // could be used in tests. 2733 // could be used in tests.
2804 2734
2805 #ifdef PDF_DEBUG_3X 2735 #ifdef PDF_DEBUG_3X
(...skipping 17 matching lines...) Expand all
2823 pdfContext.fGraphicsState.fMatrix = pdfContext.fOriginalMatrix; 2753 pdfContext.fGraphicsState.fMatrix = pdfContext.fOriginalMatrix;
2824 pdfContext.fGraphicsState.fMatrixTm = pdfContext.fGraphicsState. fMatrix; 2754 pdfContext.fGraphicsState.fMatrixTm = pdfContext.fGraphicsState. fMatrix;
2825 pdfContext.fGraphicsState.fMatrixTlm = pdfContext.fGraphicsState .fMatrix; 2755 pdfContext.fGraphicsState.fMatrixTlm = pdfContext.fGraphicsState .fMatrix;
2826 2756
2827 canvas.setMatrix(pdfContext.fOriginalMatrix); 2757 canvas.setMatrix(pdfContext.fOriginalMatrix);
2828 2758
2829 #ifndef PDF_DEBUG_NO_PAGE_CLIPING 2759 #ifndef PDF_DEBUG_NO_PAGE_CLIPING
2830 canvas.clipRect(SkRect::MakeXYWH(z, z, w, h), SkRegion::kInterse ct_Op, true); 2760 canvas.clipRect(SkRect::MakeXYWH(z, z, w, h), SkRegion::kInterse ct_Op, true);
2831 #endif 2761 #endif
2832 2762
2833 PdfMainLooper looper(NULL, &tokenizer, &pdfContext, &canvas); 2763 PdfMainLooper looper(NULL, tokenizer, &pdfContext, &canvas);
2834 looper.loop(); 2764 looper.loop();
2835 2765
2836 canvas.flush(); 2766 canvas.flush();
2837 2767
2838 SkString out; 2768 SkString out;
2839 out.appendf("%s-%i.png", inputFileName.c_str(), pn); 2769 out.appendf("%s-%i.png", inputFileName.c_str(), pn);
2840 SkImageEncoder::EncodeFile(out.c_str(), bitmap, SkImageEncoder:: kPNG_Type, 100); 2770 SkImageEncoder::EncodeFile(out.c_str(), bitmap, SkImageEncoder:: kPNG_Type, 100);
2841 } 2771 }
2842 return true; 2772 return true;
2843 } 2773 }
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after
3059 } 2989 }
3060 2990
3061 return 0; 2991 return 0;
3062 } 2992 }
3063 2993
3064 #if !defined SK_BUILD_FOR_IOS 2994 #if !defined SK_BUILD_FOR_IOS
3065 int main(int argc, char * const argv[]) { 2995 int main(int argc, char * const argv[]) {
3066 return tool_main(argc, (char**) argv); 2996 return tool_main(argc, (char**) argv);
3067 } 2997 }
3068 #endif 2998 #endif
OLDNEW
« no previous file with comments | « experimental/PdfViewer/generate_code.py ('k') | experimental/PdfViewer/pdfspec_autogen.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698