| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2010 The Android Open Source Project | 2 * Copyright 2010 The Android Open Source Project |
| 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 | 8 |
| 9 #ifndef SkPDFTypes_DEFINED | 9 #ifndef SkPDFTypes_DEFINED |
| 10 #define SkPDFTypes_DEFINED | 10 #define SkPDFTypes_DEFINED |
| (...skipping 21 matching lines...) Expand all Loading... |
| 32 which are common in the PDF format. | 32 which are common in the PDF format. |
| 33 | 33 |
| 34 */ | 34 */ |
| 35 class SkPDFObject : public SkRefCnt { | 35 class SkPDFObject : public SkRefCnt { |
| 36 public: | 36 public: |
| 37 /** Subclasses must implement this method to print the object to the | 37 /** Subclasses must implement this method to print the object to the |
| 38 * PDF file. | 38 * PDF file. |
| 39 * @param catalog The object catalog to use. | 39 * @param catalog The object catalog to use. |
| 40 * @param stream The writable output stream to send the output to. | 40 * @param stream The writable output stream to send the output to. |
| 41 */ | 41 */ |
| 42 // TODO(halcanary): make this method const | |
| 43 virtual void emitObject(SkWStream* stream, | 42 virtual void emitObject(SkWStream* stream, |
| 44 const SkPDFObjNumMap& objNumMap, | 43 const SkPDFObjNumMap& objNumMap, |
| 45 const SkPDFSubstituteMap& substitutes) const = 0; | 44 const SkPDFSubstituteMap& substitutes) const = 0; |
| 46 | 45 |
| 47 /** | 46 /** |
| 48 * Adds all transitive dependencies of this object to the | 47 * Adds all transitive dependencies of this object to the |
| 49 * catalog. Implementations should respect the catalog's object | 48 * catalog. Implementations should respect the catalog's object |
| 50 * substitution map. | 49 * substitution map. |
| 51 */ | 50 */ |
| 52 virtual void addResources(SkPDFObjNumMap* catalog, | 51 virtual void addResources(SkPDFObjNumMap* catalog, |
| 53 const SkPDFSubstituteMap& substitutes) const {} | 52 const SkPDFSubstituteMap& substitutes) const {} |
| 54 | 53 |
| 55 private: | 54 private: |
| 56 typedef SkRefCnt INHERITED; | 55 typedef SkRefCnt INHERITED; |
| 57 }; | 56 }; |
| 58 | 57 |
| 59 //////////////////////////////////////////////////////////////////////////////// | 58 //////////////////////////////////////////////////////////////////////////////// |
| 60 | 59 |
| 61 /** | 60 /** |
| 62 A SkPDFUnion is a non-virtualized implementation of the | 61 A SkPDFUnion is a non-virtualized implementation of the |
| 63 non-compound, non-specialized PDF Object types: Name, String, | 62 non-compound, non-specialized PDF Object types: Name, String, |
| 64 Number, Boolean. | 63 Number, Boolean. |
| 65 */ | 64 */ |
| 66 class SkPDFUnion { | 65 class SkPDFUnion { |
| 67 public: | 66 public: |
| 68 // u.move() is analogous to std::move(u). It returns an rvalue. | |
| 69 SkPDFUnion move() { return static_cast<SkPDFUnion&&>(*this); } | |
| 70 // Move contstructor and assignemnt operator destroy the argument | 67 // Move contstructor and assignemnt operator destroy the argument |
| 71 // and steal their references (if needed). | 68 // and steal their references (if needed). |
| 72 SkPDFUnion(SkPDFUnion&& other); | 69 SkPDFUnion(SkPDFUnion&& other); |
| 73 SkPDFUnion& operator=(SkPDFUnion&& other); | 70 SkPDFUnion& operator=(SkPDFUnion&& other); |
| 74 | 71 |
| 75 ~SkPDFUnion(); | 72 ~SkPDFUnion(); |
| 76 | 73 |
| 77 /** The following nine functions are the standard way of creating | 74 /** The following nine functions are the standard way of creating |
| 78 SkPDFUnion objects. */ | 75 SkPDFUnion objects. */ |
| 79 | 76 |
| 80 static SkPDFUnion Int(int32_t); | 77 static SkPDFUnion Int(int32_t); |
| 81 | 78 |
| 82 static SkPDFUnion Int(size_t v) { return SkPDFUnion::Int(SkToS32(v)); } | 79 static SkPDFUnion Int(size_t v) { return SkPDFUnion::Int(SkToS32(v)); } |
| 83 | 80 |
| 84 static SkPDFUnion Bool(bool); | 81 static SkPDFUnion Bool(bool); |
| 85 | 82 |
| 86 static SkPDFUnion Scalar(SkScalar); | 83 static SkPDFUnion Scalar(SkScalar); |
| 87 | 84 |
| 88 /** These two functions do NOT take ownership of ptr, and do NOT | 85 /** These two functions do NOT take ownership of char*, and do NOT |
| 89 copy the string. Suitable for passing in static const | 86 copy the string. Suitable for passing in static const |
| 90 strings. For example: | 87 strings. For example: |
| 91 SkPDFUnion n = SkPDFUnion::Name("Length"); | 88 SkPDFUnion n = SkPDFUnion::Name("Length"); |
| 92 SkPDFUnion u = SkPDFUnion::String("Identity"); */ | 89 SkPDFUnion u = SkPDFUnion::String("Identity"); */ |
| 93 | 90 |
| 94 /** SkPDFUnion::Name(const char*) assumes that the passed string | 91 /** SkPDFUnion::Name(const char*) assumes that the passed string |
| 95 is already a valid name (that is: it has no control or | 92 is already a valid name (that is: it has no control or |
| 96 whitespace characters). This will not copy the name. */ | 93 whitespace characters). This will not copy the name. */ |
| 97 static SkPDFUnion Name(const char*); | 94 static SkPDFUnion Name(const char*); |
| 98 | 95 |
| 99 /** SkPDFUnion::String will encode the passed string. This will | 96 /** SkPDFUnion::String will encode the passed string. This will |
| 100 not copy the name. */ | 97 not copy the name. */ |
| 101 static SkPDFUnion String(const char*); | 98 static SkPDFUnion String(const char*); |
| 102 | 99 |
| 103 /** SkPDFUnion::Name(const SkString&) does not assume that the | 100 /** SkPDFUnion::Name(const SkString&) does not assume that the |
| 104 passed string is already a valid name and it will escape the | 101 passed string is already a valid name and it will escape the |
| 105 string. */ | 102 string. */ |
| 106 static SkPDFUnion Name(const SkString&); | 103 static SkPDFUnion Name(const SkString&); |
| 107 | 104 |
| 108 /** SkPDFUnion::String will encode the passed string. */ | 105 /** SkPDFUnion::String will encode the passed string. */ |
| 109 static SkPDFUnion String(const SkString&); | 106 static SkPDFUnion String(const SkString&); |
| 110 | 107 |
| 111 /** This function DOES take ownership of the object. E.g. | 108 static SkPDFUnion Object(sk_sp<SkPDFObject>); |
| 112 auto dict = sk_make_sp<SkPDFDict>(); | 109 static SkPDFUnion ObjRef(sk_sp<SkPDFObject>); |
| 113 dict->insert(.....); | |
| 114 SkPDFUnion u = SkPDFUnion::Object(dict.detach()) */ | |
| 115 static SkPDFUnion Object(SkPDFObject*); | |
| 116 | |
| 117 /** This function DOES take ownership of the object. E.g. | |
| 118 sk_sp<SkPDFBitmap> image( | |
| 119 SkPDFBitmap::Create(fCanon, bitmap)); | |
| 120 SkPDFUnion u = SkPDFUnion::ObjRef(image.detach()) */ | |
| 121 static SkPDFUnion ObjRef(SkPDFObject*); | |
| 122 | 110 |
| 123 /** These two non-virtual methods mirror SkPDFObject's | 111 /** These two non-virtual methods mirror SkPDFObject's |
| 124 corresponding virtuals. */ | 112 corresponding virtuals. */ |
| 125 void emitObject(SkWStream*, | 113 void emitObject(SkWStream*, |
| 126 const SkPDFObjNumMap&, | 114 const SkPDFObjNumMap&, |
| 127 const SkPDFSubstituteMap&) const; | 115 const SkPDFSubstituteMap&) const; |
| 128 void addResources(SkPDFObjNumMap*, const SkPDFSubstituteMap&) const; | 116 void addResources(SkPDFObjNumMap*, const SkPDFSubstituteMap&) const; |
| 129 | 117 |
| 130 bool isName() const; | 118 bool isName() const; |
| 131 | 119 |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 167 #if 0 // Enable if needed. | 155 #if 0 // Enable if needed. |
| 168 /** This class is a SkPDFUnion with SkPDFObject virtuals attached. | 156 /** This class is a SkPDFUnion with SkPDFObject virtuals attached. |
| 169 The only use case of this is when a non-compound PDF object is | 157 The only use case of this is when a non-compound PDF object is |
| 170 referenced indirectly. */ | 158 referenced indirectly. */ |
| 171 class SkPDFAtom final : public SkPDFObject { | 159 class SkPDFAtom final : public SkPDFObject { |
| 172 public: | 160 public: |
| 173 void emitObject(SkWStream* stream, | 161 void emitObject(SkWStream* stream, |
| 174 const SkPDFObjNumMap& objNumMap, | 162 const SkPDFObjNumMap& objNumMap, |
| 175 const SkPDFSubstituteMap& substitutes) final; | 163 const SkPDFSubstituteMap& substitutes) final; |
| 176 void addResources(SkPDFObjNumMap*, const SkPDFSubstituteMap&) const final; | 164 void addResources(SkPDFObjNumMap*, const SkPDFSubstituteMap&) const final; |
| 177 SkPDFAtom(SkPDFUnion&& v) : fValue(v.move()) {} | 165 SkPDFAtom(SkPDFUnion&& v) : fValue(std::move(v) {} |
| 178 | 166 |
| 179 private: | 167 private: |
| 180 const SkPDFUnion fValue; | 168 const SkPDFUnion fValue; |
| 181 typedef SkPDFObject INHERITED; | 169 typedef SkPDFObject INHERITED; |
| 182 }; | 170 }; |
| 183 #endif // 0 | 171 #endif // 0 |
| 184 | 172 |
| 185 //////////////////////////////////////////////////////////////////////////////// | 173 //////////////////////////////////////////////////////////////////////////////// |
| 186 | 174 |
| 187 /** \class SkPDFArray | 175 /** \class SkPDFArray |
| (...skipping 28 matching lines...) Expand all Loading... |
| 216 /** Appends a value to the end of the array. | 204 /** Appends a value to the end of the array. |
| 217 * @param value The value to add to the array. | 205 * @param value The value to add to the array. |
| 218 */ | 206 */ |
| 219 void appendInt(int32_t); | 207 void appendInt(int32_t); |
| 220 void appendBool(bool); | 208 void appendBool(bool); |
| 221 void appendScalar(SkScalar); | 209 void appendScalar(SkScalar); |
| 222 void appendName(const char[]); | 210 void appendName(const char[]); |
| 223 void appendName(const SkString&); | 211 void appendName(const SkString&); |
| 224 void appendString(const char[]); | 212 void appendString(const char[]); |
| 225 void appendString(const SkString&); | 213 void appendString(const SkString&); |
| 226 /** appendObject and appendObjRef take ownership of the passed object */ | 214 void appendObject(sk_sp<SkPDFObject>); |
| 227 void appendObject(SkPDFObject*); | 215 void appendObjRef(sk_sp<SkPDFObject>); |
| 228 void appendObjRef(SkPDFObject*); | |
| 229 | 216 |
| 230 private: | 217 private: |
| 231 SkTDArray<SkPDFUnion> fValues; | 218 SkTDArray<SkPDFUnion> fValues; |
| 232 void append(SkPDFUnion&& value); | 219 void append(SkPDFUnion&& value); |
| 233 typedef SkPDFObject INHERITED; | 220 typedef SkPDFObject INHERITED; |
| 234 }; | 221 }; |
| 235 | 222 |
| 236 /** \class SkPDFDict | 223 /** \class SkPDFDict |
| 237 | 224 |
| 238 A dictionary object in a PDF. | 225 A dictionary object in a PDF. |
| (...skipping 15 matching lines...) Expand all Loading... |
| 254 void emitObject(SkWStream* stream, | 241 void emitObject(SkWStream* stream, |
| 255 const SkPDFObjNumMap& objNumMap, | 242 const SkPDFObjNumMap& objNumMap, |
| 256 const SkPDFSubstituteMap& substitutes) const override; | 243 const SkPDFSubstituteMap& substitutes) const override; |
| 257 void addResources(SkPDFObjNumMap*, | 244 void addResources(SkPDFObjNumMap*, |
| 258 const SkPDFSubstituteMap&) const override; | 245 const SkPDFSubstituteMap&) const override; |
| 259 | 246 |
| 260 /** The size of the dictionary. | 247 /** The size of the dictionary. |
| 261 */ | 248 */ |
| 262 int size() const; | 249 int size() const; |
| 263 | 250 |
| 264 /** Add the value to the dictionary with the given key. Takes | 251 /** Add the value to the dictionary with the given key. |
| 265 * ownership of the object. | |
| 266 * @param key The text of the key for this dictionary entry. | 252 * @param key The text of the key for this dictionary entry. |
| 267 * @param value The value for this dictionary entry. | 253 * @param value The value for this dictionary entry. |
| 268 */ | 254 */ |
| 269 void insertObject(const char key[], SkPDFObject* value); | 255 void insertObject(const char key[], sk_sp<SkPDFObject>); |
| 270 void insertObject(const SkString& key, SkPDFObject* value); | 256 void insertObject(const SkString& key, sk_sp<SkPDFObject>); |
| 271 void insertObjRef(const char key[], SkPDFObject* value); | 257 void insertObjRef(const char key[], sk_sp<SkPDFObject>); |
| 272 void insertObjRef(const SkString& key, SkPDFObject* value); | 258 void insertObjRef(const SkString& key, sk_sp<SkPDFObject>); |
| 273 | 259 |
| 274 /** Add the value to the dictionary with the given key. | 260 /** Add the value to the dictionary with the given key. |
| 275 * @param key The text of the key for this dictionary entry. | 261 * @param key The text of the key for this dictionary entry. |
| 276 * @param value The value for this dictionary entry. | 262 * @param value The value for this dictionary entry. |
| 277 */ | 263 */ |
| 278 void insertBool(const char key[], bool value); | 264 void insertBool(const char key[], bool value); |
| 279 void insertInt(const char key[], int32_t value); | 265 void insertInt(const char key[], int32_t value); |
| 280 void insertInt(const char key[], size_t value); | 266 void insertInt(const char key[], size_t value); |
| 281 void insertScalar(const char key[], SkScalar value); | 267 void insertScalar(const char key[], SkScalar value); |
| 282 void insertName(const char key[], const char nameValue[]); | 268 void insertName(const char key[], const char nameValue[]); |
| (...skipping 27 matching lines...) Expand all Loading... |
| 310 /** \class SkPDFSharedStream | 296 /** \class SkPDFSharedStream |
| 311 | 297 |
| 312 This class takes an asset and assumes that it is backed by | 298 This class takes an asset and assumes that it is backed by |
| 313 long-lived shared data (for example, an open file | 299 long-lived shared data (for example, an open file |
| 314 descriptor). That is: no memory savings can be made by holding on | 300 descriptor). That is: no memory savings can be made by holding on |
| 315 to a compressed version instead. | 301 to a compressed version instead. |
| 316 */ | 302 */ |
| 317 class SkPDFSharedStream final : public SkPDFObject { | 303 class SkPDFSharedStream final : public SkPDFObject { |
| 318 public: | 304 public: |
| 319 // Takes ownership of asset. | 305 // Takes ownership of asset. |
| 320 SkPDFSharedStream(SkStreamAsset* data) : fAsset(data), fDict(new SkPDFDict)
{ SkASSERT(data); } | 306 SkPDFSharedStream(SkStreamAsset* data) |
| 307 : fAsset(data), fDict(new SkPDFDict) { SkASSERT(data); } |
| 321 SkPDFDict* dict() { return fDict.get(); } | 308 SkPDFDict* dict() { return fDict.get(); } |
| 322 void emitObject(SkWStream*, | 309 void emitObject(SkWStream*, |
| 323 const SkPDFObjNumMap&, | 310 const SkPDFObjNumMap&, |
| 324 const SkPDFSubstituteMap&) const override; | 311 const SkPDFSubstituteMap&) const override; |
| 325 void addResources(SkPDFObjNumMap*, | 312 void addResources(SkPDFObjNumMap*, |
| 326 const SkPDFSubstituteMap&) const override; | 313 const SkPDFSubstituteMap&) const override; |
| 327 | 314 |
| 328 private: | 315 private: |
| 329 SkAutoTDelete<SkStreamAsset> fAsset; | 316 SkAutoTDelete<SkStreamAsset> fAsset; |
| 330 sk_sp<SkPDFDict> fDict; | 317 sk_sp<SkPDFDict> fDict; |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 393 }; | 380 }; |
| 394 | 381 |
| 395 #ifdef SK_PDF_IMAGE_STATS | 382 #ifdef SK_PDF_IMAGE_STATS |
| 396 extern SkAtomic<int> gDrawImageCalls; | 383 extern SkAtomic<int> gDrawImageCalls; |
| 397 extern SkAtomic<int> gJpegImageObjects; | 384 extern SkAtomic<int> gJpegImageObjects; |
| 398 extern SkAtomic<int> gRegularImageObjects; | 385 extern SkAtomic<int> gRegularImageObjects; |
| 399 extern void SkPDFImageDumpStats(); | 386 extern void SkPDFImageDumpStats(); |
| 400 #endif // SK_PDF_IMAGE_STATS | 387 #endif // SK_PDF_IMAGE_STATS |
| 401 | 388 |
| 402 #endif | 389 #endif |
| OLD | NEW |