diff options
Diffstat (limited to 'src/pdf/SkPDFTypes.h')
-rw-r--r-- | src/pdf/SkPDFTypes.h | 39 |
1 files changed, 26 insertions, 13 deletions
diff --git a/src/pdf/SkPDFTypes.h b/src/pdf/SkPDFTypes.h index f93b030465..a6a3e12ee6 100644 --- a/src/pdf/SkPDFTypes.h +++ b/src/pdf/SkPDFTypes.h @@ -39,6 +39,7 @@ public: * @param catalog The object catalog to use. * @param stream The writable output stream to send the output to. */ + // TODO(halcanary): make this method const virtual void emitObject(SkWStream* stream, const SkPDFObjNumMap& objNumMap, const SkPDFSubstituteMap& substitutes) const = 0; @@ -64,6 +65,8 @@ private: */ class SkPDFUnion { public: + // u.move() is analogous to std::move(u). It returns an rvalue. + SkPDFUnion move() { return static_cast<SkPDFUnion&&>(*this); } // Move contstructor and assignemnt operator destroy the argument // and steal their references (if needed). SkPDFUnion(SkPDFUnion&& other); @@ -82,7 +85,7 @@ public: static SkPDFUnion Scalar(SkScalar); - /** These two functions do NOT take ownership of char*, and do NOT + /** These two functions do NOT take ownership of ptr, and do NOT copy the string. Suitable for passing in static const strings. For example: SkPDFUnion n = SkPDFUnion::Name("Length"); @@ -105,8 +108,17 @@ public: /** SkPDFUnion::String will encode the passed string. */ static SkPDFUnion String(const SkString&); - static SkPDFUnion Object(sk_sp<SkPDFObject>); - static SkPDFUnion ObjRef(sk_sp<SkPDFObject>); + /** This function DOES take ownership of the object. E.g. + auto dict = sk_make_sp<SkPDFDict>(); + dict->insert(.....); + SkPDFUnion u = SkPDFUnion::Object(dict.detach()) */ + static SkPDFUnion Object(SkPDFObject*); + + /** This function DOES take ownership of the object. E.g. + sk_sp<SkPDFBitmap> image( + SkPDFBitmap::Create(fCanon, bitmap)); + SkPDFUnion u = SkPDFUnion::ObjRef(image.detach()) */ + static SkPDFUnion ObjRef(SkPDFObject*); /** These two non-virtual methods mirror SkPDFObject's corresponding virtuals. */ @@ -162,7 +174,7 @@ public: const SkPDFObjNumMap& objNumMap, const SkPDFSubstituteMap& substitutes) final; void addResources(SkPDFObjNumMap*, const SkPDFSubstituteMap&) const final; - SkPDFAtom(SkPDFUnion&& v) : fValue(std::move(v) {} + SkPDFAtom(SkPDFUnion&& v) : fValue(v.move()) {} private: const SkPDFUnion fValue; @@ -211,8 +223,9 @@ public: void appendName(const SkString&); void appendString(const char[]); void appendString(const SkString&); - void appendObject(sk_sp<SkPDFObject>); - void appendObjRef(sk_sp<SkPDFObject>); + /** appendObject and appendObjRef take ownership of the passed object */ + void appendObject(SkPDFObject*); + void appendObjRef(SkPDFObject*); private: SkTDArray<SkPDFUnion> fValues; @@ -248,14 +261,15 @@ public: */ int size() const; - /** Add the value to the dictionary with the given key. + /** Add the value to the dictionary with the given key. Takes + * ownership of the object. * @param key The text of the key for this dictionary entry. * @param value The value for this dictionary entry. */ - void insertObject(const char key[], sk_sp<SkPDFObject>); - void insertObject(const SkString& key, sk_sp<SkPDFObject>); - void insertObjRef(const char key[], sk_sp<SkPDFObject>); - void insertObjRef(const SkString& key, sk_sp<SkPDFObject>); + void insertObject(const char key[], SkPDFObject* value); + void insertObject(const SkString& key, SkPDFObject* value); + void insertObjRef(const char key[], SkPDFObject* value); + void insertObjRef(const SkString& key, SkPDFObject* value); /** Add the value to the dictionary with the given key. * @param key The text of the key for this dictionary entry. @@ -303,8 +317,7 @@ private: class SkPDFSharedStream final : public SkPDFObject { public: // Takes ownership of asset. - SkPDFSharedStream(SkStreamAsset* data) - : fAsset(data), fDict(new SkPDFDict) { SkASSERT(data); } + SkPDFSharedStream(SkStreamAsset* data) : fAsset(data), fDict(new SkPDFDict) { SkASSERT(data); } SkPDFDict* dict() { return fDict.get(); } void emitObject(SkWStream*, const SkPDFObjNumMap&, |