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

Side by Side Diff: experimental/PdfViewer/pdfparser/native/SkPdfNativeObject.h

Issue 23601017: pdfviewer: track what objects have been used during rendering. It will be the base of reporting unu… (Closed) Base URL: http://skia.googlecode.com/svn/trunk/
Patch Set: Created 7 years, 3 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
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 #ifndef SkPdfNativeObject_DEFINED 8 #ifndef SkPdfNativeObject_DEFINED
9 #define SkPdfNativeObject_DEFINED 9 #define SkPdfNativeObject_DEFINED
10 10
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
96 SkTDArray<SkPdfNativeObject*>* fArray; 96 SkTDArray<SkPdfNativeObject*>* fArray;
97 Reference fRef; 97 Reference fRef;
98 }; 98 };
99 SkTDict<SkPdfNativeObject*>* fMap; 99 SkTDict<SkPdfNativeObject*>* fMap;
100 100
101 // TODO(edisonn): rename data with cache 101 // TODO(edisonn): rename data with cache
102 void* fData; 102 void* fData;
103 DataType fDataType; 103 DataType fDataType;
104 104
105 105
106 // Keep this the last entrys
107 #ifdef PDF_TRACK_OBJECT_USAGE
108 mutable bool fUsed;
109 #endif // PDF_TRACK_OBJECT_USAGE
110
106 public: 111 public:
107 112
108 SkPdfNativeObject() : fInRendering(0), fObjectType(kInvalid_PdfObjectType), fMap(NULL), fData(NULL), fDataType(kEmpty_Data) {} 113 SkPdfNativeObject() : fInRendering(0)
114 , fObjectType(kInvalid_PdfObjectType)
115 , fMap(NULL)
116 , fData(NULL)
117 , fDataType(kEmpty_Data)
118 #ifdef PDF_TRACK_OBJECT_USAGE
119 , fUsed(false)
120 #endif // PDF_TRACK_OBJECT_USAGE
121 {}
109 122
110 bool inRendering() const { return fInRendering != 0; } 123 bool inRendering() const { return fInRendering != 0; }
111 void startRendering() {fInRendering = 1;} 124 void startRendering() {fInRendering = 1;}
112 void doneRendering() {fInRendering = 0;} 125 void doneRendering() {fInRendering = 0;}
113 126
114 inline bool hasData(DataType type) { 127 inline bool hasData(DataType type) {
115 return type == fDataType; 128 return type == fDataType;
116 } 129 }
117 130
118 inline void* data(DataType type) { 131 inline void* data(DataType type) {
119 return type == fDataType ? fData : NULL; 132 return type == fDataType ? fData : NULL;
120 } 133 }
121 134
122 inline void setData(void* data, DataType type) { 135 inline void setData(void* data, DataType type) {
123 releaseData(); 136 releaseData();
124 fDataType = type; 137 fDataType = type;
125 fData = data; 138 fData = data;
126 } 139 }
127 140
128 void releaseData(); 141 void releaseData();
129 142
130 // ~SkPdfNativeObject() { 143 // ~SkPdfNativeObject() {
131 // //reset(); must be called manually! 144 // //reset(); must be called manually!
132 // } 145 // }
133 146
134 void reset() { 147 void reset() {
148 SkPdfMarkObjectUnused();
149
135 switch (fObjectType) { 150 switch (fObjectType) {
136 case kArray_PdfObjectType: 151 case kArray_PdfObjectType:
137 delete fArray; 152 delete fArray;
138 break; 153 break;
139 154
140 case kDictionary_PdfObjectType: 155 case kDictionary_PdfObjectType:
141 delete fMap; 156 delete fMap;
142 if (isStreamOwned()) { 157 if (isStreamOwned()) {
143 delete[] fStr.fBuffer; 158 delete[] fStr.fBuffer;
144 fStr.fBuffer = NULL; 159 fStr.fBuffer = NULL;
145 fStr.fBytes = 0; 160 fStr.fBytes = 0;
146 } 161 }
147 break; 162 break;
148 163
149 default: 164 default:
150 break; 165 break;
151 } 166 }
152 fObjectType = kInvalid_PdfObjectType; 167 fObjectType = kInvalid_PdfObjectType;
153 releaseData(); 168 releaseData();
154 } 169 }
155 170
156 ObjectType type() { return fObjectType; } 171 ObjectType type() {
172 SkPdfMarkObjectUsed();
173
174 return fObjectType;
175 }
157 176
158 const char* c_str() const { 177 const char* c_str() const {
178 SkPdfMarkObjectUsed();
179
159 switch (fObjectType) { 180 switch (fObjectType) {
160 case kString_PdfObjectType: 181 case kString_PdfObjectType:
161 case kHexString_PdfObjectType: 182 case kHexString_PdfObjectType:
162 case kKeyword_PdfObjectType: 183 case kKeyword_PdfObjectType:
163 case kName_PdfObjectType: 184 case kName_PdfObjectType:
164 return (const char*)fStr.fBuffer; 185 return (const char*)fStr.fBuffer;
165 186
166 default: 187 default:
167 // TODO(edisonn): report/warning 188 // TODO(edisonn): report/warning
168 return NULL; 189 return NULL;
169 } 190 }
170 } 191 }
171 192
172 size_t lenstr() const { 193 size_t lenstr() const {
194 SkPdfMarkObjectUsed();
195
173 switch (fObjectType) { 196 switch (fObjectType) {
174 case kString_PdfObjectType: 197 case kString_PdfObjectType:
175 case kHexString_PdfObjectType: 198 case kHexString_PdfObjectType:
176 case kKeyword_PdfObjectType: 199 case kKeyword_PdfObjectType:
177 case kName_PdfObjectType: 200 case kName_PdfObjectType:
178 return fStr.fBytes; 201 return fStr.fBytes;
179 202
180 default: 203 default:
181 // TODO(edisonn): report/warning 204 // TODO(edisonn): report/warning
182 return 0; 205 return 0;
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after
346 if (fObjectType != kArray_PdfObjectType) { 369 if (fObjectType != kArray_PdfObjectType) {
347 // TODO(edisonn): report err 370 // TODO(edisonn): report err
348 return false; 371 return false;
349 } 372 }
350 373
351 fArray->push(obj); 374 fArray->push(obj);
352 return true; 375 return true;
353 } 376 }
354 377
355 size_t size() const { 378 size_t size() const {
379 SkPdfMarkObjectUsed();
380
356 SkASSERT(fObjectType == kArray_PdfObjectType); 381 SkASSERT(fObjectType == kArray_PdfObjectType);
357 382
358 return fArray->count(); 383 return fArray->count();
359 } 384 }
360 385
361 SkPdfNativeObject* objAtAIndex(int i) { 386 SkPdfNativeObject* objAtAIndex(int i) {
387 SkPdfMarkObjectUsed();
388
362 SkASSERT(fObjectType == kArray_PdfObjectType); 389 SkASSERT(fObjectType == kArray_PdfObjectType);
363 390
364 return (*fArray)[i]; 391 return (*fArray)[i];
365 } 392 }
366 393
367 SkPdfNativeObject* removeLastInArray() { 394 SkPdfNativeObject* removeLastInArray() {
395 // SkPdfMarkObjectUsed();
396
368 SkASSERT(fObjectType == kArray_PdfObjectType); 397 SkASSERT(fObjectType == kArray_PdfObjectType);
369 398
370 SkPdfNativeObject* ret = NULL; 399 SkPdfNativeObject* ret = NULL;
371 fArray->pop(&ret); 400 fArray->pop(&ret);
372 401
373 return ret; 402 return ret;
374 } 403 }
375 404
376 405
377 const SkPdfNativeObject* objAtAIndex(int i) const { 406 const SkPdfNativeObject* objAtAIndex(int i) const {
407 SkPdfMarkObjectUsed();
408
378 SkASSERT(fObjectType == kArray_PdfObjectType); 409 SkASSERT(fObjectType == kArray_PdfObjectType);
379 410
380 return (*fArray)[i]; 411 return (*fArray)[i];
381 } 412 }
382 413
383 SkPdfNativeObject* operator[](int i) { 414 SkPdfNativeObject* operator[](int i) {
384 SkASSERT(fObjectType == kArray_PdfObjectType); 415 SkASSERT(fObjectType == kArray_PdfObjectType);
385 416
386 return (*fArray)[i]; 417 return (*fArray)[i];
387 } 418 }
388 419
389 const SkPdfNativeObject* operator[](int i) const { 420 const SkPdfNativeObject* operator[](int i) const {
421 SkPdfMarkObjectUsed();
422
390 SkASSERT(fObjectType == kArray_PdfObjectType); 423 SkASSERT(fObjectType == kArray_PdfObjectType);
391 424
392 return (*fArray)[i]; 425 return (*fArray)[i];
393 } 426 }
394 427
395 428
396 // TODO(edisonn): make the functions to return SkPdfDictionary, move these f unctions in SkPdfDictionary 429 // TODO(edisonn): make the functions to return SkPdfDictionary, move these f unctions in SkPdfDictionary
397 static void makeEmptyDictionary(SkPdfNativeObject* obj) { 430 static void makeEmptyDictionary(SkPdfNativeObject* obj) {
398 SkASSERT(obj->fObjectType == kInvalid_PdfObjectType); 431 SkASSERT(obj->fObjectType == kInvalid_PdfObjectType);
399 432
400 obj->fObjectType = kDictionary_PdfObjectType; 433 obj->fObjectType = kDictionary_PdfObjectType;
401 obj->fMap = new SkTDict<SkPdfNativeObject*>(1); 434 obj->fMap = new SkTDict<SkPdfNativeObject*>(1);
402 obj->fStr.fBuffer = NULL; 435 obj->fStr.fBuffer = NULL;
403 obj->fStr.fBytes = 0; 436 obj->fStr.fBytes = 0;
404 } 437 }
405 438
406 // TODO(edisonn): get all the possible names from spec, and compute a hash f unction 439 // TODO(edisonn): get all the possible names from spec, and compute a hash f unction
407 // that would create no overlaps in the same dictionary 440 // that would create no overlaps in the same dictionary
408 // or build a tree of chars that when followed goes to a unique id/index/has h 441 // or build a tree of chars that when followed goes to a unique id/index/has h
409 // TODO(edisonn): generate constants like kDictFoo, kNameDict_name 442 // TODO(edisonn): generate constants like kDictFoo, kNameDict_name
410 // which will be used in code 443 // which will be used in code
411 // add function SkPdfFastNameKey key(const char* key); 444 // add function SkPdfFastNameKey key(const char* key);
412 // TODO(edisonn): setting the same key twike, will make the value undefined! 445 // TODO(edisonn): setting the same key twike, will make the value undefined!
413 bool set(const SkPdfNativeObject* key, SkPdfNativeObject* value) { 446 bool set(const SkPdfNativeObject* key, SkPdfNativeObject* value) {
447 //SkPdfMarkObjectUsed();
448
414 SkASSERT(fObjectType == kDictionary_PdfObjectType); 449 SkASSERT(fObjectType == kDictionary_PdfObjectType);
415 SkASSERT(key->fObjectType == kName_PdfObjectType); 450 SkASSERT(key->fObjectType == kName_PdfObjectType);
416 451
417 if (key->fObjectType != kName_PdfObjectType || fObjectType != kDictionar y_PdfObjectType) { 452 if (key->fObjectType != kName_PdfObjectType || fObjectType != kDictionar y_PdfObjectType) {
418 // TODO(edisonn): report err 453 // TODO(edisonn): report err
419 return false; 454 return false;
420 } 455 }
421 456
422 //// we rewrite all delimiters and white spaces with '\0', so we expect the end of name to be '\0' 457 //// we rewrite all delimiters and white spaces with '\0', so we expect the end of name to be '\0'
423 //SkASSERT(key->fStr.fBuffer[key->fStr.fBytes] == '\0'); 458 //SkASSERT(key->fStr.fBuffer[key->fStr.fBytes] == '\0');
424 459
425 return set(key->fStr.fBuffer, key->fStr.fBytes, value); 460 return set(key->fStr.fBuffer, key->fStr.fBytes, value);
426 } 461 }
427 462
428 bool set(const char* key, SkPdfNativeObject* value) { 463 bool set(const char* key, SkPdfNativeObject* value) {
464 //SkPdfMarkObjectUsed();
465
429 return set((const unsigned char*)key, strlen(key), value); 466 return set((const unsigned char*)key, strlen(key), value);
430 } 467 }
431 468
432 bool set(const unsigned char* key, size_t len, SkPdfNativeObject* value) { 469 bool set(const unsigned char* key, size_t len, SkPdfNativeObject* value) {
470 //SkPdfMarkObjectUsed();
471
433 SkASSERT(fObjectType == kDictionary_PdfObjectType); 472 SkASSERT(fObjectType == kDictionary_PdfObjectType);
434 473
435 if (fObjectType != kDictionary_PdfObjectType) { 474 if (fObjectType != kDictionary_PdfObjectType) {
436 // TODO(edisonn): report err 475 // TODO(edisonn): report err
437 return false; 476 return false;
438 } 477 }
439 478
440 return fMap->set((const char*)key, len, value); 479 return fMap->set((const char*)key, len, value);
441 } 480 }
442 481
443 SkPdfNativeObject* get(const SkPdfNativeObject* key) { 482 SkPdfNativeObject* get(const SkPdfNativeObject* key) {
483 SkPdfMarkObjectUsed();
484
444 SkASSERT(fObjectType == kDictionary_PdfObjectType); 485 SkASSERT(fObjectType == kDictionary_PdfObjectType);
445 SkASSERT(key->fObjectType == kName_PdfObjectType); 486 SkASSERT(key->fObjectType == kName_PdfObjectType);
446 487
447 if (key->fObjectType != kName_PdfObjectType || fObjectType != kDictionar y_PdfObjectType) { 488 if (key->fObjectType != kName_PdfObjectType || fObjectType != kDictionar y_PdfObjectType) {
448 // TODO(edisonn): report err 489 // TODO(edisonn): report err
449 return NULL; 490 return NULL;
450 } 491 }
451 492
452 //SkASSERT(key->fStr.fBuffer[key->fStr.fBytes] == '\0'); 493 //SkASSERT(key->fStr.fBuffer[key->fStr.fBytes] == '\0');
453 494
454 return get(key->fStr.fBuffer, key->fStr.fBytes); 495 return get(key->fStr.fBuffer, key->fStr.fBytes);
455 } 496 }
456 497
457 SkPdfNativeObject* get(const char* key) { 498 SkPdfNativeObject* get(const char* key) {
499 SkPdfMarkObjectUsed();
500
458 return get((const unsigned char*)key, strlen(key)); 501 return get((const unsigned char*)key, strlen(key));
459 } 502 }
460 503
461 SkPdfNativeObject* get(const unsigned char* key, size_t len) { 504 SkPdfNativeObject* get(const unsigned char* key, size_t len) {
505 SkPdfMarkObjectUsed();
506
462 SkASSERT(fObjectType == kDictionary_PdfObjectType); 507 SkASSERT(fObjectType == kDictionary_PdfObjectType);
463 SkASSERT(key); 508 SkASSERT(key);
464 if (fObjectType != kDictionary_PdfObjectType) { 509 if (fObjectType != kDictionary_PdfObjectType) {
465 // TODO(edisonn): report err 510 // TODO(edisonn): report err
466 return NULL; 511 return NULL;
467 } 512 }
468 SkPdfNativeObject* ret = NULL; 513 SkPdfNativeObject* ret = NULL;
469 fMap->find((const char*)key, len, &ret); 514 fMap->find((const char*)key, len, &ret);
470 515
471 #ifdef PDF_TRACE 516 #ifdef PDF_TRACE
472 SkString _key; 517 SkString _key;
473 _key.append((const char*)key, len); 518 _key.append((const char*)key, len);
474 printf("\nget(/%s) = %s\n", _key.c_str(), ret ? ret->toString(0, len + 9 ).c_str() : "_NOT_FOUND"); 519 printf("\nget(/%s) = %s\n", _key.c_str(), ret ? ret->toString(0, len + 9 ).c_str() : "_NOT_FOUND");
475 #endif 520 #endif
476 521
477 return ret; 522 return ret;
478 } 523 }
479 524
480 const SkPdfNativeObject* get(const SkPdfNativeObject* key) const { 525 const SkPdfNativeObject* get(const SkPdfNativeObject* key) const {
526 SkPdfMarkObjectUsed();
527
481 SkASSERT(fObjectType == kDictionary_PdfObjectType); 528 SkASSERT(fObjectType == kDictionary_PdfObjectType);
482 SkASSERT(key->fObjectType == kName_PdfObjectType); 529 SkASSERT(key->fObjectType == kName_PdfObjectType);
483 530
484 if (key->fObjectType != kName_PdfObjectType || fObjectType != kDictionar y_PdfObjectType) { 531 if (key->fObjectType != kName_PdfObjectType || fObjectType != kDictionar y_PdfObjectType) {
485 // TODO(edisonn): report err 532 // TODO(edisonn): report err
486 return NULL; 533 return NULL;
487 } 534 }
488 535
489 //SkASSERT(key->fStr.fBuffer[key->fStr.fBytes] == '\0'); 536 //SkASSERT(key->fStr.fBuffer[key->fStr.fBytes] == '\0');
490 537
491 return get(key->fStr.fBuffer, key->fStr.fBytes); 538 return get(key->fStr.fBuffer, key->fStr.fBytes);
492 } 539 }
493 540
494 const SkPdfNativeObject* get(const char* key) const { 541 const SkPdfNativeObject* get(const char* key) const {
542 SkPdfMarkObjectUsed();
543
495 return get((const unsigned char*)key, strlen(key)); 544 return get((const unsigned char*)key, strlen(key));
496 } 545 }
497 546
498 const SkPdfNativeObject* get(const unsigned char* key, size_t len) const { 547 const SkPdfNativeObject* get(const unsigned char* key, size_t len) const {
548 SkPdfMarkObjectUsed();
549
499 SkASSERT(fObjectType == kDictionary_PdfObjectType); 550 SkASSERT(fObjectType == kDictionary_PdfObjectType);
500 SkASSERT(key); 551 SkASSERT(key);
501 if (fObjectType != kDictionary_PdfObjectType) { 552 if (fObjectType != kDictionary_PdfObjectType) {
502 // TODO(edisonn): report err 553 // TODO(edisonn): report err
503 return NULL; 554 return NULL;
504 } 555 }
505 SkPdfNativeObject* ret = NULL; 556 SkPdfNativeObject* ret = NULL;
506 fMap->find((const char*)key, len, &ret); 557 fMap->find((const char*)key, len, &ret);
507 558
508 #ifdef PDF_TRACE 559 #ifdef PDF_TRACE
509 SkString _key; 560 SkString _key;
510 _key.append((const char*)key, len); 561 _key.append((const char*)key, len);
511 printf("\nget(/%s) = %s\n", _key.c_str(), ret ? ret->toString(0, len + 9 ).c_str() : "_NOT_FOUND"); 562 printf("\nget(/%s) = %s\n", _key.c_str(), ret ? ret->toString(0, len + 9 ).c_str() : "_NOT_FOUND");
512 #endif 563 #endif
513 564
514 return ret; 565 return ret;
515 } 566 }
516 567
517 const SkPdfNativeObject* get(const char* key, const char* abr) const { 568 const SkPdfNativeObject* get(const char* key, const char* abr) const {
569 SkPdfMarkObjectUsed();
570
518 const SkPdfNativeObject* ret = get(key); 571 const SkPdfNativeObject* ret = get(key);
519 // TODO(edisonn): / is a valid name, and it might be an abreviation, so "" should not be like NULL 572 // TODO(edisonn): / is a valid name, and it might be an abreviation, so "" should not be like NULL
520 // make this distiontion in generator, and remove "" from condition 573 // make this distiontion in generator, and remove "" from condition
521 if (ret != NULL || abr == NULL || *abr == '\0') { 574 if (ret != NULL || abr == NULL || *abr == '\0') {
522 return ret; 575 return ret;
523 } 576 }
524 return get(abr); 577 return get(abr);
525 } 578 }
526 579
527 SkPdfNativeObject* get(const char* key, const char* abr) { 580 SkPdfNativeObject* get(const char* key, const char* abr) {
581 SkPdfMarkObjectUsed();
582
528 SkPdfNativeObject* ret = get(key); 583 SkPdfNativeObject* ret = get(key);
529 // TODO(edisonn): / is a valid name, and it might be an abreviation, so "" should not be like NULL 584 // TODO(edisonn): / is a valid name, and it might be an abreviation, so "" should not be like NULL
530 // make this distiontion in generator, and remove "" from condition 585 // make this distiontion in generator, and remove "" from condition
531 if (ret != NULL || abr == NULL || *abr == '\0') { 586 if (ret != NULL || abr == NULL || *abr == '\0') {
532 return ret; 587 return ret;
533 } 588 }
534 return get(abr); 589 return get(abr);
535 } 590 }
536 591
537 SkPdfDictionary* asDictionary() { 592 SkPdfDictionary* asDictionary() {
593 SkPdfMarkObjectUsed();
594
538 SkASSERT(isDictionary()); 595 SkASSERT(isDictionary());
539 if (!isDictionary()) { 596 if (!isDictionary()) {
540 return NULL; 597 return NULL;
541 } 598 }
542 return (SkPdfDictionary*) this; 599 return (SkPdfDictionary*) this;
543 } 600 }
544 601
545 const SkPdfDictionary* asDictionary() const { 602 const SkPdfDictionary* asDictionary() const {
603 SkPdfMarkObjectUsed();
604
546 SkASSERT(isDictionary()); 605 SkASSERT(isDictionary());
547 if (!isDictionary()) { 606 if (!isDictionary()) {
548 return NULL; 607 return NULL;
549 } 608 }
550 return (SkPdfDictionary*) this; 609 return (SkPdfDictionary*) this;
551 } 610 }
552 611
553 612
554 bool isReference() const { 613 bool isReference() const {
614 SkPdfMarkObjectUsed();
615
555 return fObjectType == kReference_PdfObjectType; 616 return fObjectType == kReference_PdfObjectType;
556 } 617 }
557 618
558 bool isBoolean() const { 619 bool isBoolean() const {
620 SkPdfMarkObjectUsed();
621
559 return fObjectType == kBoolean_PdfObjectType; 622 return fObjectType == kBoolean_PdfObjectType;
560 } 623 }
561 624
562 bool isInteger() const { 625 bool isInteger() const {
626 SkPdfMarkObjectUsed();
627
563 return fObjectType == kInteger_PdfObjectType; 628 return fObjectType == kInteger_PdfObjectType;
564 } 629 }
565 private: 630 private:
566 bool isReal() const { 631 bool isReal() const {
632 SkPdfMarkObjectUsed();
633
567 return fObjectType == kReal_PdfObjectType; 634 return fObjectType == kReal_PdfObjectType;
568 } 635 }
569 public: 636 public:
570 bool isNumber() const { 637 bool isNumber() const {
638 SkPdfMarkObjectUsed();
639
571 return fObjectType == kInteger_PdfObjectType || fObjectType == kReal_Pdf ObjectType; 640 return fObjectType == kInteger_PdfObjectType || fObjectType == kReal_Pdf ObjectType;
572 } 641 }
573 642
574 bool isKeywordReference() const { 643 bool isKeywordReference() const {
644 SkPdfMarkObjectUsed();
645
575 return fObjectType == kKeyword_PdfObjectType && fStr.fBytes == 1 && fStr .fBuffer[0] == 'R'; 646 return fObjectType == kKeyword_PdfObjectType && fStr.fBytes == 1 && fStr .fBuffer[0] == 'R';
576 } 647 }
577 648
578 bool isKeyword() const { 649 bool isKeyword() const {
650 SkPdfMarkObjectUsed();
651
579 return fObjectType == kKeyword_PdfObjectType; 652 return fObjectType == kKeyword_PdfObjectType;
580 } 653 }
581 654
582 bool isKeyword(const char* keyword) const { 655 bool isKeyword(const char* keyword) const {
656 SkPdfMarkObjectUsed();
657
583 if (!isKeyword()) { 658 if (!isKeyword()) {
584 return false; 659 return false;
585 } 660 }
586 661
587 if (strlen(keyword) != fStr.fBytes) { 662 if (strlen(keyword) != fStr.fBytes) {
588 return false; 663 return false;
589 } 664 }
590 665
591 if (strncmp(keyword, (const char*)fStr.fBuffer, fStr.fBytes) != 0) { 666 if (strncmp(keyword, (const char*)fStr.fBuffer, fStr.fBytes) != 0) {
592 return false; 667 return false;
593 } 668 }
594 669
595 return true; 670 return true;
596 } 671 }
597 672
598 bool isName() const { 673 bool isName() const {
674 SkPdfMarkObjectUsed();
675
599 return fObjectType == kName_PdfObjectType; 676 return fObjectType == kName_PdfObjectType;
600 } 677 }
601 678
602 bool isName(const char* name) const { 679 bool isName(const char* name) const {
680 SkPdfMarkObjectUsed();
681
603 return fObjectType == kName_PdfObjectType && fStr.fBytes == strlen(name) && strncmp((const char*)fStr.fBuffer, name, fStr.fBytes) == 0; 682 return fObjectType == kName_PdfObjectType && fStr.fBytes == strlen(name) && strncmp((const char*)fStr.fBuffer, name, fStr.fBytes) == 0;
604 } 683 }
605 684
606 bool isArray() const { 685 bool isArray() const {
686 SkPdfMarkObjectUsed();
687
607 return fObjectType == kArray_PdfObjectType; 688 return fObjectType == kArray_PdfObjectType;
608 } 689 }
609 690
610 bool isDate() const { 691 bool isDate() const {
692 SkPdfMarkObjectUsed();
693
611 return fObjectType == kString_PdfObjectType || fObjectType == kHexString _PdfObjectType; 694 return fObjectType == kString_PdfObjectType || fObjectType == kHexString _PdfObjectType;
612 } 695 }
613 696
614 bool isDictionary() const { 697 bool isDictionary() const {
698 SkPdfMarkObjectUsed();
699
615 return fObjectType == kDictionary_PdfObjectType; 700 return fObjectType == kDictionary_PdfObjectType;
616 } 701 }
617 702
618 bool isFunction() const { 703 bool isFunction() const {
704 SkPdfMarkObjectUsed();
705
619 return false; // NYI 706 return false; // NYI
620 } 707 }
621 708
622 bool isRectangle() const { 709 bool isRectangle() const {
710 SkPdfMarkObjectUsed();
711
623 return fObjectType == kArray_PdfObjectType && fArray->count() == 4; // N YI + and elems are numbers 712 return fObjectType == kArray_PdfObjectType && fArray->count() == 4; // N YI + and elems are numbers
624 } 713 }
625 714
626 // TODO(edisonn): has stream .. or is stream ... TBD 715 // TODO(edisonn): has stream .. or is stream ... TBD
627 bool hasStream() const { 716 bool hasStream() const {
717 SkPdfMarkObjectUsed();
718
628 return isDictionary() && fStr.fBuffer != NULL; 719 return isDictionary() && fStr.fBuffer != NULL;
629 } 720 }
630 721
631 // TODO(edisonn): has stream .. or is stream ... TBD 722 // TODO(edisonn): has stream .. or is stream ... TBD
632 const SkPdfStream* getStream() const { 723 const SkPdfStream* getStream() const {
724 SkPdfMarkObjectUsed();
725
633 return hasStream() ? (const SkPdfStream*)this : NULL; 726 return hasStream() ? (const SkPdfStream*)this : NULL;
634 } 727 }
635 728
636 SkPdfStream* getStream() { 729 SkPdfStream* getStream() {
730 SkPdfMarkObjectUsed();
731
637 return hasStream() ? (SkPdfStream*)this : NULL; 732 return hasStream() ? (SkPdfStream*)this : NULL;
638 } 733 }
639 734
640 bool isAnyString() const { 735 bool isAnyString() const {
736 SkPdfMarkObjectUsed();
737
641 return fObjectType == kString_PdfObjectType || fObjectType == kHexString _PdfObjectType; 738 return fObjectType == kString_PdfObjectType || fObjectType == kHexString _PdfObjectType;
642 } 739 }
643 740
644 bool isHexString() const { 741 bool isHexString() const {
742 SkPdfMarkObjectUsed();
743
645 return fObjectType == kHexString_PdfObjectType; 744 return fObjectType == kHexString_PdfObjectType;
646 } 745 }
647 746
648 bool isMatrix() const { 747 bool isMatrix() const {
748 SkPdfMarkObjectUsed();
749
649 return fObjectType == kArray_PdfObjectType && fArray->count() == 6; // N YI + and elems are numbers 750 return fObjectType == kArray_PdfObjectType && fArray->count() == 6; // N YI + and elems are numbers
650 } 751 }
651 752
652 inline int64_t intValue() const { 753 inline int64_t intValue() const {
754 SkPdfMarkObjectUsed();
755
653 SkASSERT(fObjectType == kInteger_PdfObjectType); 756 SkASSERT(fObjectType == kInteger_PdfObjectType);
654 757
655 if (fObjectType != kInteger_PdfObjectType) { 758 if (fObjectType != kInteger_PdfObjectType) {
656 // TODO(edisonn): log err 759 // TODO(edisonn): log err
657 return 0; 760 return 0;
658 } 761 }
659 return fIntegerValue; 762 return fIntegerValue;
660 } 763 }
661 private: 764 private:
662 inline double realValue() const { 765 inline double realValue() const {
766 SkPdfMarkObjectUsed();
767
663 SkASSERT(fObjectType == kReal_PdfObjectType); 768 SkASSERT(fObjectType == kReal_PdfObjectType);
664 769
665 if (fObjectType != kReal_PdfObjectType) { 770 if (fObjectType != kReal_PdfObjectType) {
666 // TODO(edisonn): log err 771 // TODO(edisonn): log err
667 return 0; 772 return 0;
668 } 773 }
669 return fRealValue; 774 return fRealValue;
670 } 775 }
671 public: 776 public:
672 inline double numberValue() const { 777 inline double numberValue() const {
778 SkPdfMarkObjectUsed();
779
673 SkASSERT(isNumber()); 780 SkASSERT(isNumber());
674 781
675 if (!isNumber()) { 782 if (!isNumber()) {
676 // TODO(edisonn): log err 783 // TODO(edisonn): log err
677 return 0; 784 return 0;
678 } 785 }
679 return fObjectType == kReal_PdfObjectType ? fRealValue : fIntegerValue; 786 return fObjectType == kReal_PdfObjectType ? fRealValue : fIntegerValue;
680 } 787 }
681 788
682 inline SkScalar scalarValue() const { 789 inline SkScalar scalarValue() const {
790 SkPdfMarkObjectUsed();
791
683 SkASSERT(isNumber()); 792 SkASSERT(isNumber());
684 793
685 if (!isNumber()) { 794 if (!isNumber()) {
686 // TODO(edisonn): log err 795 // TODO(edisonn): log err
687 return SkIntToScalar(0); 796 return SkIntToScalar(0);
688 } 797 }
689 return fObjectType == kReal_PdfObjectType ? SkDoubleToScalar(fRealValue) : 798 return fObjectType == kReal_PdfObjectType ? SkDoubleToScalar(fRealValue) :
690 SkIntToScalar(fIntegerValue) ; 799 SkIntToScalar(fIntegerValue) ;
691 } 800 }
692 801
693 int referenceId() const { 802 int referenceId() const {
803 SkPdfMarkObjectUsed();
804
694 SkASSERT(fObjectType == kReference_PdfObjectType); 805 SkASSERT(fObjectType == kReference_PdfObjectType);
695 return fRef.fId; 806 return fRef.fId;
696 } 807 }
697 808
698 int referenceGeneration() const { 809 int referenceGeneration() const {
810 SkPdfMarkObjectUsed();
811
699 SkASSERT(fObjectType == kReference_PdfObjectType); 812 SkASSERT(fObjectType == kReference_PdfObjectType);
700 return fRef.fGen; 813 return fRef.fGen;
701 } 814 }
702 815
703 inline const char* nameValue() const { 816 inline const char* nameValue() const {
817 SkPdfMarkObjectUsed();
818
704 SkASSERT(fObjectType == kName_PdfObjectType); 819 SkASSERT(fObjectType == kName_PdfObjectType);
705 820
706 if (fObjectType != kName_PdfObjectType) { 821 if (fObjectType != kName_PdfObjectType) {
707 // TODO(edisonn): log err 822 // TODO(edisonn): log err
708 return ""; 823 return "";
709 } 824 }
710 return (const char*)fStr.fBuffer; 825 return (const char*)fStr.fBuffer;
711 } 826 }
712 827
713 inline const char* stringValue() const { 828 inline const char* stringValue() const {
829 SkPdfMarkObjectUsed();
830
714 SkASSERT(fObjectType == kString_PdfObjectType || fObjectType == kHexStri ng_PdfObjectType); 831 SkASSERT(fObjectType == kString_PdfObjectType || fObjectType == kHexStri ng_PdfObjectType);
715 832
716 if (fObjectType != kString_PdfObjectType && fObjectType != kHexString_Pd fObjectType) { 833 if (fObjectType != kString_PdfObjectType && fObjectType != kHexString_Pd fObjectType) {
717 // TODO(edisonn): log err 834 // TODO(edisonn): log err
718 return ""; 835 return "";
719 } 836 }
720 return (const char*)fStr.fBuffer; 837 return (const char*)fStr.fBuffer;
721 } 838 }
722 839
723 inline NotOwnedString strRef() { 840 inline NotOwnedString strRef() {
841 SkPdfMarkObjectUsed();
842
724 switch (fObjectType) { 843 switch (fObjectType) {
725 case kString_PdfObjectType: 844 case kString_PdfObjectType:
726 case kHexString_PdfObjectType: 845 case kHexString_PdfObjectType:
727 case kKeyword_PdfObjectType: 846 case kKeyword_PdfObjectType:
728 case kName_PdfObjectType: 847 case kName_PdfObjectType:
729 return fStr; 848 return fStr;
730 849
731 default: 850 default:
732 // TODO(edisonn): report/warning 851 // TODO(edisonn): report/warning
733 return NotOwnedString(); 852 return NotOwnedString();
734 } 853 }
735 } 854 }
736 855
737 // TODO(edisonn): nameValue2 and stringValue2 are used to make code generati on easy, 856 // TODO(edisonn): nameValue2 and stringValue2 are used to make code generati on easy,
738 // but it is not a performat way to do it, since it will create an extra cop y 857 // but it is not a performat way to do it, since it will create an extra cop y
739 // remove these functions and make code generated faster 858 // remove these functions and make code generated faster
740 inline SkString nameValue2() const { 859 inline SkString nameValue2() const {
860 SkPdfMarkObjectUsed();
861
741 SkASSERT(fObjectType == kName_PdfObjectType); 862 SkASSERT(fObjectType == kName_PdfObjectType);
742 863
743 if (fObjectType != kName_PdfObjectType) { 864 if (fObjectType != kName_PdfObjectType) {
744 // TODO(edisonn): log err 865 // TODO(edisonn): log err
745 return SkString(); 866 return SkString();
746 } 867 }
747 return SkString((const char*)fStr.fBuffer, fStr.fBytes); 868 return SkString((const char*)fStr.fBuffer, fStr.fBytes);
748 } 869 }
749 870
750 inline SkString stringValue2() const { 871 inline SkString stringValue2() const {
872 SkPdfMarkObjectUsed();
873
751 SkASSERT(fObjectType == kString_PdfObjectType || fObjectType == kHexStri ng_PdfObjectType); 874 SkASSERT(fObjectType == kString_PdfObjectType || fObjectType == kHexStri ng_PdfObjectType);
752 875
753 if (fObjectType != kString_PdfObjectType && fObjectType != kHexString_Pd fObjectType) { 876 if (fObjectType != kString_PdfObjectType && fObjectType != kHexString_Pd fObjectType) {
754 // TODO(edisonn): log err 877 // TODO(edisonn): log err
755 return SkString(); 878 return SkString();
756 } 879 }
757 return SkString((const char*)fStr.fBuffer, fStr.fBytes); 880 return SkString((const char*)fStr.fBuffer, fStr.fBytes);
758 } 881 }
759 882
760 inline bool boolValue() const { 883 inline bool boolValue() const {
884 SkPdfMarkObjectUsed();
885
761 SkASSERT(fObjectType == kBoolean_PdfObjectType); 886 SkASSERT(fObjectType == kBoolean_PdfObjectType);
762 887
763 if (fObjectType != kBoolean_PdfObjectType) { 888 if (fObjectType != kBoolean_PdfObjectType) {
764 // TODO(edisonn): log err 889 // TODO(edisonn): log err
765 return false; 890 return false;
766 } 891 }
767 return fBooleanValue; 892 return fBooleanValue;
768 } 893 }
769 894
770 SkRect rectangleValue() const { 895 SkRect rectangleValue() const {
896 SkPdfMarkObjectUsed();
897
771 SkASSERT(isRectangle()); 898 SkASSERT(isRectangle());
772 if (!isRectangle()) { 899 if (!isRectangle()) {
773 return SkRect::MakeEmpty(); 900 return SkRect::MakeEmpty();
774 } 901 }
775 902
776 double array[4]; 903 double array[4];
777 for (int i = 0; i < 4; i++) { 904 for (int i = 0; i < 4; i++) {
778 // TODO(edisonn): version where we could resolve references? 905 // TODO(edisonn): version where we could resolve references?
779 const SkPdfNativeObject* elem = objAtAIndex(i); 906 const SkPdfNativeObject* elem = objAtAIndex(i);
780 if (elem == NULL || !elem->isNumber()) { 907 if (elem == NULL || !elem->isNumber()) {
781 // TODO(edisonn): report error 908 // TODO(edisonn): report error
782 return SkRect::MakeEmpty(); 909 return SkRect::MakeEmpty();
783 } 910 }
784 array[i] = elem->numberValue(); 911 array[i] = elem->numberValue();
785 } 912 }
786 913
787 return SkRect::MakeLTRB(SkDoubleToScalar(array[0]), 914 return SkRect::MakeLTRB(SkDoubleToScalar(array[0]),
788 SkDoubleToScalar(array[1]), 915 SkDoubleToScalar(array[1]),
789 SkDoubleToScalar(array[2]), 916 SkDoubleToScalar(array[2]),
790 SkDoubleToScalar(array[3])); 917 SkDoubleToScalar(array[3]));
791 } 918 }
792 919
793 SkMatrix matrixValue() const { 920 SkMatrix matrixValue() const {
921 SkPdfMarkObjectUsed();
922
794 SkASSERT(isMatrix()); 923 SkASSERT(isMatrix());
795 if (!isMatrix()) { 924 if (!isMatrix()) {
796 return SkMatrix::I(); 925 return SkMatrix::I();
797 } 926 }
798 927
799 double array[6]; 928 double array[6];
800 for (int i = 0; i < 6; i++) { 929 for (int i = 0; i < 6; i++) {
801 // TODO(edisonn): version where we could resolve references? 930 // TODO(edisonn): version where we could resolve references?
802 const SkPdfNativeObject* elem = objAtAIndex(i); 931 const SkPdfNativeObject* elem = objAtAIndex(i);
803 if (elem == NULL || !elem->isNumber()) { 932 if (elem == NULL || !elem->isNumber()) {
804 // TODO(edisonn): report error 933 // TODO(edisonn): report error
805 return SkMatrix::I(); 934 return SkMatrix::I();
806 } 935 }
807 array[i] = elem->numberValue(); 936 array[i] = elem->numberValue();
808 } 937 }
809 938
810 return SkMatrixFromPdfMatrix(array); 939 return SkMatrixFromPdfMatrix(array);
811 } 940 }
812 941
813 bool filterStream(); 942 bool filterStream();
814 943
815 944
816 bool GetFilteredStreamRef(unsigned char const** buffer, size_t* len) { 945 bool GetFilteredStreamRef(unsigned char const** buffer, size_t* len) {
946 SkPdfMarkObjectUsed();
947
817 // TODO(edisonn): add params that couls let the last filter in place if it is jpeg or png to fast load images 948 // TODO(edisonn): add params that couls let the last filter in place if it is jpeg or png to fast load images
818 if (!hasStream()) { 949 if (!hasStream()) {
819 return false; 950 return false;
820 } 951 }
821 952
822 filterStream(); 953 filterStream();
823 954
824 if (buffer) { 955 if (buffer) {
825 *buffer = fStr.fBuffer; 956 *buffer = fStr.fBuffer;
826 } 957 }
827 958
828 if (len) { 959 if (len) {
829 *len = fStr.fBytes >> 2; // last 2 bits 960 *len = fStr.fBytes >> 2; // last 2 bits
830 } 961 }
831 962
832 return true; 963 return true;
833 } 964 }
834 965
835 bool isStreamFiltered() const { 966 bool isStreamFiltered() const {
967 SkPdfMarkObjectUsed();
968
836 return hasStream() && ((fStr.fBytes & 1) == kFilteredStreamBit); 969 return hasStream() && ((fStr.fBytes & 1) == kFilteredStreamBit);
837 } 970 }
838 971
839 bool isStreamOwned() const { 972 bool isStreamOwned() const {
973 SkPdfMarkObjectUsed();
974
840 return hasStream() && ((fStr.fBytes & 2) == kOwnedStreamBit); 975 return hasStream() && ((fStr.fBytes & 2) == kOwnedStreamBit);
841 } 976 }
842 977
843 bool GetUnfilteredStreamRef(unsigned char const** buffer, size_t* len) const { 978 bool GetUnfilteredStreamRef(unsigned char const** buffer, size_t* len) const {
979 SkPdfMarkObjectUsed();
980
844 if (isStreamFiltered()) { 981 if (isStreamFiltered()) {
845 return false; 982 return false;
846 } 983 }
847 984
848 if (!hasStream()) { 985 if (!hasStream()) {
849 return false; 986 return false;
850 } 987 }
851 988
852 if (buffer) { 989 if (buffer) {
853 *buffer = fStr.fBuffer; 990 *buffer = fStr.fBuffer;
854 } 991 }
855 992
856 if (len) { 993 if (len) {
857 *len = fStr.fBytes >> 2; // remove last 2 bits 994 *len = fStr.fBytes >> 2; // remove last 2 bits
858 } 995 }
859 996
860 return true; 997 return true;
861 } 998 }
862 999
863 bool addStream(const unsigned char* buffer, size_t len) { 1000 bool addStream(const unsigned char* buffer, size_t len) {
1001 //SkPdfMarkObjectUsed();
1002
864 SkASSERT(!hasStream()); 1003 SkASSERT(!hasStream());
865 SkASSERT(isDictionary()); 1004 SkASSERT(isDictionary());
866 1005
867 if (!isDictionary() || hasStream()) { 1006 if (!isDictionary() || hasStream()) {
868 return false; 1007 return false;
869 } 1008 }
870 1009
871 fStr.fBuffer = buffer; 1010 fStr.fBuffer = buffer;
872 fStr.fBytes = (len << 2) + kUnfilteredStreamBit; 1011 fStr.fBytes = (len << 2) + kUnfilteredStreamBit;
873 1012
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after
1038 SkPdfName() : SkPdfNativeObject() { 1177 SkPdfName() : SkPdfNativeObject() {
1039 SkPdfNativeObject::makeName((const unsigned char*)"", this); 1178 SkPdfNativeObject::makeName((const unsigned char*)"", this);
1040 } 1179 }
1041 public: 1180 public:
1042 SkPdfName(char* name) : SkPdfNativeObject() { 1181 SkPdfName(char* name) : SkPdfNativeObject() {
1043 this->makeName((const unsigned char*)name, this); 1182 this->makeName((const unsigned char*)name, this);
1044 } 1183 }
1045 }; 1184 };
1046 1185
1047 #endif // SkPdfNativeObject 1186 #endif // SkPdfNativeObject
OLDNEW
« no previous file with comments | « experimental/PdfViewer/SkPdfConfig.h ('k') | experimental/PdfViewer/pdfparser/native/SkPdfNativeObject.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698