| OLD | NEW |
| 1 | 1 |
| 2 /* | 2 /* |
| 3 * Copyright 2010 The Android Open Source Project | 3 * Copyright 2010 The Android Open Source Project |
| 4 * | 4 * |
| 5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
| 6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
| 7 */ | 7 */ |
| 8 | 8 |
| 9 | 9 |
| 10 #ifndef SkPDFTypes_DEFINED | 10 #ifndef SkPDFTypes_DEFINED |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 /** \class SkPDFObject | 22 /** \class SkPDFObject |
| 23 | 23 |
| 24 A PDF Object is the base class for primitive elements in a PDF file. A | 24 A PDF Object is the base class for primitive elements in a PDF file. A |
| 25 common subtype is used to ease the use of indirect object references, | 25 common subtype is used to ease the use of indirect object references, |
| 26 which are common in the PDF format. | 26 which are common in the PDF format. |
| 27 */ | 27 */ |
| 28 class SkPDFObject : public SkRefCnt { | 28 class SkPDFObject : public SkRefCnt { |
| 29 public: | 29 public: |
| 30 SK_DECLARE_INST_COUNT(SkPDFObject) | 30 SK_DECLARE_INST_COUNT(SkPDFObject) |
| 31 | 31 |
| 32 virtual ~SkPDFObject() { }; |
| 33 |
| 32 /** Return the size (number of bytes) of this object in the final output | 34 /** Return the size (number of bytes) of this object in the final output |
| 33 * file. Compound objects or objects that are computationally intensive | 35 * file. Compound objects or objects that are computationally intensive |
| 34 * to output should override this method. | 36 * to output should override this method. |
| 35 * @param catalog The object catalog to use. | 37 * @param catalog The object catalog to use. |
| 36 * @param indirect If true, output an object identifier with the object. | 38 * @param indirect If true, output an object identifier with the object. |
| 37 */ | 39 */ |
| 38 virtual size_t getOutputSize(SkPDFCatalog* catalog, bool indirect); | 40 virtual size_t getOutputSize(SkPDFCatalog* catalog, bool indirect); |
| 39 | 41 |
| 40 /** For non-primitive objects (i.e. objects defined outside this file), | 42 /** For non-primitive objects (i.e. objects defined outside this file), |
| 41 * this method will add to resourceList any objects that this method | 43 * this method will add to resourceList any objects that this method |
| (...skipping 30 matching lines...) Expand all Loading... |
| 72 SkTDArray<SkPDFObject*>* list); | 74 SkTDArray<SkPDFObject*>* list); |
| 73 | 75 |
| 74 /** Static helper function to copy and reference the resources (and all | 76 /** Static helper function to copy and reference the resources (and all |
| 75 * their subresources) into a new list. | 77 * their subresources) into a new list. |
| 76 * @param resources The resource list. | 78 * @param resources The resource list. |
| 77 * @param result The list to add to. | 79 * @param result The list to add to. |
| 78 */ | 80 */ |
| 79 static void GetResourcesHelper(SkTDArray<SkPDFObject*>* resources, | 81 static void GetResourcesHelper(SkTDArray<SkPDFObject*>* resources, |
| 80 SkTDArray<SkPDFObject*>* result); | 82 SkTDArray<SkPDFObject*>* result); |
| 81 | 83 |
| 84 /** Destroys safely an array of SkPDFObject's. |
| 85 * The stack won't be used much, and stack overflow will be avoided. |
| 86 * @param list: The list of objects to be destroyed. |
| 87 */ |
| 88 static void safeUnref(SkTDArray<SkPDFObject*>* list) { |
| 89 while (list->count() > 0) { |
| 90 SkPDFObject* obj = NULL; |
| 91 list->pop(&obj); |
| 92 if (obj) { |
| 93 // Releases all refs to be owned by list, unref will call destru
ctor! |
| 94 if (obj->fRefCnt == 1) { |
| 95 obj->trasferPDFObjecsOwnership(list); |
| 96 } |
| 97 // If unref calls destructor, it won't call recursively |
| 98 // other ~SkPDFObjects(). |
| 99 obj->unref(); |
| 100 } |
| 101 } |
| 102 } |
| 103 |
| 82 protected: | 104 protected: |
| 83 /** Subclasses must implement this method to print the object to the | 105 /** Subclasses must implement this method to print the object to the |
| 84 * PDF file. | 106 * PDF file. |
| 85 * @param catalog The object catalog to use. | 107 * @param catalog The object catalog to use. |
| 86 * @param indirect If true, output an object identifier with the object. | 108 * @param indirect If true, output an object identifier with the object. |
| 87 * @param stream The writable output stream to send the output to. | 109 * @param stream The writable output stream to send the output to. |
| 88 */ | 110 */ |
| 89 virtual void emitObject(SkWStream* stream, SkPDFCatalog* catalog, | 111 virtual void emitObject(SkWStream* stream, SkPDFCatalog* catalog, |
| 90 bool indirect) = 0; | 112 bool indirect) = 0; |
| 91 | 113 |
| 114 /** Dumps all the SkPDFObject members in the list. When the destructor is |
| 115 * called, the stack won't be used much. |
| 116 * This method will destroy the state of the object. Should be called only |
| 117 * during destructor calls. |
| 118 * @param list: The list that will own the SkPDFObject members. |
| 119 */ |
| 120 virtual void trasferPDFObjecsOwnership(SkTDArray<SkPDFObject*>* list) {} |
| 121 |
| 92 typedef SkRefCnt INHERITED; | 122 typedef SkRefCnt INHERITED; |
| 93 }; | 123 }; |
| 94 | 124 |
| 95 /** \class SkPDFObjRef | 125 /** \class SkPDFObjRef |
| 96 | 126 |
| 97 An indirect reference to a PDF object. | 127 An indirect reference to a PDF object. |
| 98 */ | 128 */ |
| 99 class SkPDFObjRef : public SkPDFObject { | 129 class SkPDFObjRef : public SkPDFObject { |
| 100 public: | 130 public: |
| 101 SK_DECLARE_INST_COUNT(SkPDFObjRef) | 131 SK_DECLARE_INST_COUNT(SkPDFObjRef) |
| 102 | 132 |
| 103 /** Create a reference to an existing SkPDFObject. | 133 /** Create a reference to an existing SkPDFObject. |
| 104 * @param obj The object to reference. | 134 * @param obj The object to reference. |
| 105 */ | 135 */ |
| 106 explicit SkPDFObjRef(SkPDFObject* obj); | 136 explicit SkPDFObjRef(SkPDFObject* obj); |
| 107 virtual ~SkPDFObjRef(); | 137 virtual ~SkPDFObjRef(); |
| 108 | 138 |
| 109 // The SkPDFObject interface. | 139 // The SkPDFObject interface. |
| 110 virtual void emitObject(SkWStream* stream, SkPDFCatalog* catalog, | 140 virtual void emitObject(SkWStream* stream, SkPDFCatalog* catalog, |
| 111 bool indirect); | 141 bool indirect); |
| 112 virtual size_t getOutputSize(SkPDFCatalog* catalog, bool indirect); | 142 virtual size_t getOutputSize(SkPDFCatalog* catalog, bool indirect); |
| 113 | 143 |
| 144 protected: |
| 145 virtual void trasferPDFObjecsOwnership(SkTDArray<SkPDFObject*>* list) { |
| 146 list->push(fObj.detach()); |
| 147 |
| 148 INHERITED::trasferPDFObjecsOwnership(list); |
| 149 } |
| 150 |
| 114 private: | 151 private: |
| 115 SkAutoTUnref<SkPDFObject> fObj; | 152 SkAutoTUnref<SkPDFObject> fObj; |
| 116 | 153 |
| 117 typedef SkPDFObject INHERITED; | 154 typedef SkPDFObject INHERITED; |
| 118 }; | 155 }; |
| 119 | 156 |
| 120 /** \class SkPDFInt | 157 /** \class SkPDFInt |
| 121 | 158 |
| 122 An integer object in a PDF. | 159 An integer object in a PDF. |
| 123 */ | 160 */ |
| (...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 399 * @param name The name for this dictionary entry. | 436 * @param name The name for this dictionary entry. |
| 400 */ | 437 */ |
| 401 void insertName(const char key[], const SkString& name) { | 438 void insertName(const char key[], const SkString& name) { |
| 402 this->insertName(key, name.c_str()); | 439 this->insertName(key, name.c_str()); |
| 403 } | 440 } |
| 404 | 441 |
| 405 /** Remove all entries from the dictionary. | 442 /** Remove all entries from the dictionary. |
| 406 */ | 443 */ |
| 407 void clear(); | 444 void clear(); |
| 408 | 445 |
| 446 virtual void trasferPDFObjecsOwnership(SkTDArray<SkPDFObject*>* list) { |
| 447 for (int i = 0; i < fValue.count(); i++) { |
| 448 list->push(fValue[i].key); |
| 449 fValue[i].key = NULL; |
| 450 list->push(fValue[i].value); |
| 451 fValue[i].value = NULL; |
| 452 } |
| 453 fValue.reset(); |
| 454 |
| 455 INHERITED::trasferPDFObjecsOwnership(list); |
| 456 } |
| 457 |
| 409 private: | 458 private: |
| 410 struct Rec { | 459 struct Rec { |
| 411 SkPDFName* key; | 460 SkPDFName* key; |
| 412 SkPDFObject* value; | 461 SkPDFObject* value; |
| 413 }; | 462 }; |
| 414 | 463 |
| 415 public: | 464 public: |
| 416 class Iter { | 465 class Iter { |
| 417 public: | 466 public: |
| 418 explicit Iter(const SkPDFDict& dict); | 467 explicit Iter(const SkPDFDict& dict); |
| 419 SkPDFName* next(SkPDFObject** value); | 468 SkPDFName* next(SkPDFObject** value); |
| 420 | 469 |
| 421 private: | 470 private: |
| 422 const Rec* fIter; | 471 const Rec* fIter; |
| 423 const Rec* fStop; | 472 const Rec* fStop; |
| 424 }; | 473 }; |
| 425 | 474 |
| 426 private: | 475 private: |
| 427 static const int kMaxLen = 4095; | 476 static const int kMaxLen = 4095; |
| 428 | 477 |
| 429 SkTDArray<struct Rec> fValue; | 478 SkTDArray<struct Rec> fValue; |
| 430 | 479 |
| 431 typedef SkPDFObject INHERITED; | 480 typedef SkPDFObject INHERITED; |
| 432 }; | 481 }; |
| 433 | 482 |
| 434 #endif | 483 #endif |
| OLD | NEW |