| 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 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 86 */ | 86 */ |
| 87 static void GetResourcesHelper( | 87 static void GetResourcesHelper( |
| 88 const SkTDArray<SkPDFObject*>* resources, | 88 const SkTDArray<SkPDFObject*>* resources, |
| 89 const SkTSet<SkPDFObject*>& knownResourceObjects, | 89 const SkTSet<SkPDFObject*>& knownResourceObjects, |
| 90 SkTSet<SkPDFObject*>* newResourceObjects); | 90 SkTSet<SkPDFObject*>* newResourceObjects); |
| 91 | 91 |
| 92 protected: | 92 protected: |
| 93 /** Subclasses must implement this method to print the object to the | 93 /** Subclasses must implement this method to print the object to the |
| 94 * PDF file. | 94 * PDF file. |
| 95 * @param catalog The object catalog to use. | 95 * @param catalog The object catalog to use. |
| 96 * @param indirect If true, output an object identifier with the object. | |
| 97 * @param stream The writable output stream to send the output to. | 96 * @param stream The writable output stream to send the output to. |
| 98 */ | 97 */ |
| 99 virtual void emitObject(SkWStream* stream, SkPDFCatalog* catalog, | 98 virtual void emitObject(SkWStream* stream, SkPDFCatalog* catalog) = 0; |
| 100 bool indirect) = 0; | |
| 101 | 99 |
| 102 typedef SkRefCnt INHERITED; | 100 typedef SkRefCnt INHERITED; |
| 103 }; | 101 }; |
| 104 | 102 |
| 105 /** \class SkPDFObjRef | 103 /** \class SkPDFObjRef |
| 106 | 104 |
| 107 An indirect reference to a PDF object. | 105 An indirect reference to a PDF object. |
| 108 */ | 106 */ |
| 109 class SkPDFObjRef : public SkPDFObject { | 107 class SkPDFObjRef : public SkPDFObject { |
| 110 public: | 108 public: |
| 111 SK_DECLARE_INST_COUNT(SkPDFObjRef) | 109 SK_DECLARE_INST_COUNT(SkPDFObjRef) |
| 112 | 110 |
| 113 /** Create a reference to an existing SkPDFObject. | 111 /** Create a reference to an existing SkPDFObject. |
| 114 * @param obj The object to reference. | 112 * @param obj The object to reference. |
| 115 */ | 113 */ |
| 116 explicit SkPDFObjRef(SkPDFObject* obj); | 114 explicit SkPDFObjRef(SkPDFObject* obj); |
| 117 virtual ~SkPDFObjRef(); | 115 virtual ~SkPDFObjRef(); |
| 118 | 116 |
| 119 // The SkPDFObject interface. | 117 // The SkPDFObject interface. |
| 120 virtual void emitObject(SkWStream* stream, SkPDFCatalog* catalog, | 118 virtual void emitObject(SkWStream* stream, SkPDFCatalog* catalog) SK_OVERRID
E; |
| 121 bool indirect); | |
| 122 virtual size_t getOutputSize(SkPDFCatalog* catalog, bool indirect); | 119 virtual size_t getOutputSize(SkPDFCatalog* catalog, bool indirect); |
| 123 | 120 |
| 124 private: | 121 private: |
| 125 SkAutoTUnref<SkPDFObject> fObj; | 122 SkAutoTUnref<SkPDFObject> fObj; |
| 126 | 123 |
| 127 typedef SkPDFObject INHERITED; | 124 typedef SkPDFObject INHERITED; |
| 128 }; | 125 }; |
| 129 | 126 |
| 130 /** \class SkPDFInt | 127 /** \class SkPDFInt |
| 131 | 128 |
| 132 An integer object in a PDF. | 129 An integer object in a PDF. |
| 133 */ | 130 */ |
| 134 class SkPDFInt : public SkPDFObject { | 131 class SkPDFInt : public SkPDFObject { |
| 135 public: | 132 public: |
| 136 SK_DECLARE_INST_COUNT(SkPDFInt) | 133 SK_DECLARE_INST_COUNT(SkPDFInt) |
| 137 | 134 |
| 138 /** Create a PDF integer (usually for indirect reference purposes). | 135 /** Create a PDF integer (usually for indirect reference purposes). |
| 139 * @param value An integer value between 2^31 - 1 and -2^31. | 136 * @param value An integer value between 2^31 - 1 and -2^31. |
| 140 */ | 137 */ |
| 141 explicit SkPDFInt(int32_t value); | 138 explicit SkPDFInt(int32_t value); |
| 142 virtual ~SkPDFInt(); | 139 virtual ~SkPDFInt(); |
| 143 | 140 |
| 144 // The SkPDFObject interface. | 141 // The SkPDFObject interface. |
| 145 virtual void emitObject(SkWStream* stream, SkPDFCatalog* catalog, | 142 virtual void emitObject(SkWStream* stream, SkPDFCatalog* catalog) SK_OVERRID
E; |
| 146 bool indirect); | |
| 147 | 143 |
| 148 private: | 144 private: |
| 149 int32_t fValue; | 145 int32_t fValue; |
| 150 | 146 |
| 151 typedef SkPDFObject INHERITED; | 147 typedef SkPDFObject INHERITED; |
| 152 }; | 148 }; |
| 153 | 149 |
| 154 /** \class SkPDFBool | 150 /** \class SkPDFBool |
| 155 | 151 |
| 156 An boolean value in a PDF. | 152 An boolean value in a PDF. |
| 157 */ | 153 */ |
| 158 class SkPDFBool : public SkPDFObject { | 154 class SkPDFBool : public SkPDFObject { |
| 159 public: | 155 public: |
| 160 SK_DECLARE_INST_COUNT(SkPDFBool) | 156 SK_DECLARE_INST_COUNT(SkPDFBool) |
| 161 | 157 |
| 162 /** Create a PDF boolean. | 158 /** Create a PDF boolean. |
| 163 * @param value true or false. | 159 * @param value true or false. |
| 164 */ | 160 */ |
| 165 explicit SkPDFBool(bool value); | 161 explicit SkPDFBool(bool value); |
| 166 virtual ~SkPDFBool(); | 162 virtual ~SkPDFBool(); |
| 167 | 163 |
| 168 // The SkPDFObject interface. | 164 // The SkPDFObject interface. |
| 169 virtual void emitObject(SkWStream* stream, SkPDFCatalog* catalog, | 165 virtual void emitObject(SkWStream* stream, SkPDFCatalog* catalog) SK_OVERRID
E; |
| 170 bool indirect); | |
| 171 virtual size_t getOutputSize(SkPDFCatalog* catalog, bool indirect); | 166 virtual size_t getOutputSize(SkPDFCatalog* catalog, bool indirect); |
| 172 | 167 |
| 173 private: | 168 private: |
| 174 bool fValue; | 169 bool fValue; |
| 175 | 170 |
| 176 typedef SkPDFObject INHERITED; | 171 typedef SkPDFObject INHERITED; |
| 177 }; | 172 }; |
| 178 | 173 |
| 179 /** \class SkPDFScalar | 174 /** \class SkPDFScalar |
| 180 | 175 |
| 181 A real number object in a PDF. | 176 A real number object in a PDF. |
| 182 */ | 177 */ |
| 183 class SkPDFScalar : public SkPDFObject { | 178 class SkPDFScalar : public SkPDFObject { |
| 184 public: | 179 public: |
| 185 SK_DECLARE_INST_COUNT(SkPDFScalar) | 180 SK_DECLARE_INST_COUNT(SkPDFScalar) |
| 186 | 181 |
| 187 /** Create a PDF real number. | 182 /** Create a PDF real number. |
| 188 * @param value A real value. | 183 * @param value A real value. |
| 189 */ | 184 */ |
| 190 explicit SkPDFScalar(SkScalar value); | 185 explicit SkPDFScalar(SkScalar value); |
| 191 virtual ~SkPDFScalar(); | 186 virtual ~SkPDFScalar(); |
| 192 | 187 |
| 193 static void Append(SkScalar value, SkWStream* stream); | 188 static void Append(SkScalar value, SkWStream* stream); |
| 194 | 189 |
| 195 // The SkPDFObject interface. | 190 // The SkPDFObject interface. |
| 196 virtual void emitObject(SkWStream* stream, SkPDFCatalog* catalog, | 191 virtual void emitObject(SkWStream* stream, SkPDFCatalog* catalog) SK_OVERRID
E; |
| 197 bool indirect); | |
| 198 | 192 |
| 199 private: | 193 private: |
| 200 SkScalar fValue; | 194 SkScalar fValue; |
| 201 | 195 |
| 202 typedef SkPDFObject INHERITED; | 196 typedef SkPDFObject INHERITED; |
| 203 }; | 197 }; |
| 204 | 198 |
| 205 /** \class SkPDFString | 199 /** \class SkPDFString |
| 206 | 200 |
| 207 A string object in a PDF. | 201 A string object in a PDF. |
| (...skipping 11 matching lines...) Expand all Loading... |
| 219 /** Create a PDF string. Maximum length (in bytes) is 65,535. | 213 /** Create a PDF string. Maximum length (in bytes) is 65,535. |
| 220 * @param value A string value. | 214 * @param value A string value. |
| 221 * @param len The length of value. | 215 * @param len The length of value. |
| 222 * @param wideChars Indicates if the top byte in value is significant and | 216 * @param wideChars Indicates if the top byte in value is significant and |
| 223 * should be encoded (true) or not (false). | 217 * should be encoded (true) or not (false). |
| 224 */ | 218 */ |
| 225 SkPDFString(const uint16_t* value, size_t len, bool wideChars); | 219 SkPDFString(const uint16_t* value, size_t len, bool wideChars); |
| 226 virtual ~SkPDFString(); | 220 virtual ~SkPDFString(); |
| 227 | 221 |
| 228 // The SkPDFObject interface. | 222 // The SkPDFObject interface. |
| 229 virtual void emitObject(SkWStream* stream, SkPDFCatalog* catalog, | 223 virtual void emitObject(SkWStream* stream, SkPDFCatalog* catalog) SK_OVERRID
E; |
| 230 bool indirect); | |
| 231 virtual size_t getOutputSize(SkPDFCatalog* catalog, bool indirect); | 224 virtual size_t getOutputSize(SkPDFCatalog* catalog, bool indirect); |
| 232 | 225 |
| 233 static SkString FormatString(const char* input, size_t len); | 226 static SkString FormatString(const char* input, size_t len); |
| 234 static SkString FormatString(const uint16_t* input, size_t len, | 227 static SkString FormatString(const uint16_t* input, size_t len, |
| 235 bool wideChars); | 228 bool wideChars); |
| 236 private: | 229 private: |
| 237 static const size_t kMaxLen = 65535; | 230 static const size_t kMaxLen = 65535; |
| 238 | 231 |
| 239 const SkString fValue; | 232 const SkString fValue; |
| 240 | 233 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 255 /** Create a PDF name object. Maximum length is 127 bytes. | 248 /** Create a PDF name object. Maximum length is 127 bytes. |
| 256 * @param value The name. | 249 * @param value The name. |
| 257 */ | 250 */ |
| 258 explicit SkPDFName(const char name[]); | 251 explicit SkPDFName(const char name[]); |
| 259 explicit SkPDFName(const SkString& name); | 252 explicit SkPDFName(const SkString& name); |
| 260 virtual ~SkPDFName(); | 253 virtual ~SkPDFName(); |
| 261 | 254 |
| 262 bool operator==(const SkPDFName& b) const; | 255 bool operator==(const SkPDFName& b) const; |
| 263 | 256 |
| 264 // The SkPDFObject interface. | 257 // The SkPDFObject interface. |
| 265 virtual void emitObject(SkWStream* stream, SkPDFCatalog* catalog, | 258 virtual void emitObject(SkWStream* stream, SkPDFCatalog* catalog) SK_OVERRID
E; |
| 266 bool indirect); | |
| 267 virtual size_t getOutputSize(SkPDFCatalog* catalog, bool indirect); | 259 virtual size_t getOutputSize(SkPDFCatalog* catalog, bool indirect); |
| 268 | 260 |
| 269 private: | 261 private: |
| 270 static const size_t kMaxLen = 127; | 262 static const size_t kMaxLen = 127; |
| 271 | 263 |
| 272 const SkString fValue; | 264 const SkString fValue; |
| 273 | 265 |
| 274 static SkString FormatName(const SkString& input); | 266 static SkString FormatName(const SkString& input); |
| 275 | 267 |
| 276 typedef SkPDFObject INHERITED; | 268 typedef SkPDFObject INHERITED; |
| 277 }; | 269 }; |
| 278 | 270 |
| 279 /** \class SkPDFArray | 271 /** \class SkPDFArray |
| 280 | 272 |
| 281 An array object in a PDF. | 273 An array object in a PDF. |
| 282 */ | 274 */ |
| 283 class SkPDFArray : public SkPDFObject { | 275 class SkPDFArray : public SkPDFObject { |
| 284 public: | 276 public: |
| 285 SK_DECLARE_INST_COUNT(SkPDFArray) | 277 SK_DECLARE_INST_COUNT(SkPDFArray) |
| 286 | 278 |
| 287 /** Create a PDF array. Maximum length is 8191. | 279 /** Create a PDF array. Maximum length is 8191. |
| 288 */ | 280 */ |
| 289 SkPDFArray(); | 281 SkPDFArray(); |
| 290 virtual ~SkPDFArray(); | 282 virtual ~SkPDFArray(); |
| 291 | 283 |
| 292 // The SkPDFObject interface. | 284 // The SkPDFObject interface. |
| 293 virtual void emitObject(SkWStream* stream, SkPDFCatalog* catalog, | 285 virtual void emitObject(SkWStream* stream, SkPDFCatalog* catalog) SK_OVERRID
E; |
| 294 bool indirect); | |
| 295 virtual size_t getOutputSize(SkPDFCatalog* catalog, bool indirect); | 286 virtual size_t getOutputSize(SkPDFCatalog* catalog, bool indirect); |
| 296 | 287 |
| 297 /** The size of the array. | 288 /** The size of the array. |
| 298 */ | 289 */ |
| 299 int size() { return fValue.count(); } | 290 int size() { return fValue.count(); } |
| 300 | 291 |
| 301 /** Preallocate space for the given number of entries. | 292 /** Preallocate space for the given number of entries. |
| 302 * @param length The number of array slots to preallocate. | 293 * @param length The number of array slots to preallocate. |
| 303 */ | 294 */ |
| 304 void reserve(int length); | 295 void reserve(int length); |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 356 SkPDFDict(); | 347 SkPDFDict(); |
| 357 | 348 |
| 358 /** Create a PDF dictionary with a Type entry. | 349 /** Create a PDF dictionary with a Type entry. |
| 359 * @param type The value of the Type entry. | 350 * @param type The value of the Type entry. |
| 360 */ | 351 */ |
| 361 explicit SkPDFDict(const char type[]); | 352 explicit SkPDFDict(const char type[]); |
| 362 | 353 |
| 363 virtual ~SkPDFDict(); | 354 virtual ~SkPDFDict(); |
| 364 | 355 |
| 365 // The SkPDFObject interface. | 356 // The SkPDFObject interface. |
| 366 virtual void emitObject(SkWStream* stream, SkPDFCatalog* catalog, | 357 virtual void emitObject(SkWStream* stream, SkPDFCatalog* catalog) SK_OVERRID
E; |
| 367 bool indirect); | |
| 368 virtual size_t getOutputSize(SkPDFCatalog* catalog, bool indirect); | 358 virtual size_t getOutputSize(SkPDFCatalog* catalog, bool indirect); |
| 369 | 359 |
| 370 /** The size of the dictionary. | 360 /** The size of the dictionary. |
| 371 */ | 361 */ |
| 372 int size() const; | 362 int size() const; |
| 373 | 363 |
| 374 /** Add the value to the dictionary with the given key. Refs value. | 364 /** Add the value to the dictionary with the given key. Refs value. |
| 375 * @param key The key for this dictionary entry. | 365 * @param key The key for this dictionary entry. |
| 376 * @param value The value for this dictionary entry. | 366 * @param value The value for this dictionary entry. |
| 377 * @return The value argument is returned. | 367 * @return The value argument is returned. |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 445 | 435 |
| 446 mutable SkMutex fMutex; // protects modifications to fValue | 436 mutable SkMutex fMutex; // protects modifications to fValue |
| 447 SkTDArray<struct Rec> fValue; | 437 SkTDArray<struct Rec> fValue; |
| 448 | 438 |
| 449 SkPDFObject* append(SkPDFName* key, SkPDFObject* value); | 439 SkPDFObject* append(SkPDFName* key, SkPDFObject* value); |
| 450 | 440 |
| 451 typedef SkPDFObject INHERITED; | 441 typedef SkPDFObject INHERITED; |
| 452 }; | 442 }; |
| 453 | 443 |
| 454 #endif | 444 #endif |
| OLD | NEW |