diff options
Diffstat (limited to 'src/pdf/SkPDFTypes.h')
-rw-r--r-- | src/pdf/SkPDFTypes.h | 51 |
1 files changed, 46 insertions, 5 deletions
diff --git a/src/pdf/SkPDFTypes.h b/src/pdf/SkPDFTypes.h index 5e4de3a259..6ee9162139 100644 --- a/src/pdf/SkPDFTypes.h +++ b/src/pdf/SkPDFTypes.h @@ -14,6 +14,7 @@ #include "SkTHash.h" #include "SkTypes.h" +class SkData; class SkPDFObjNumMap; class SkPDFObject; class SkPDFSubstituteMap; @@ -307,10 +308,9 @@ private: */ class SkPDFSharedStream final : public SkPDFObject { public: - // Takes ownership of asset. - SkPDFSharedStream(SkStreamAsset* data); + SkPDFSharedStream(std::unique_ptr<SkStreamAsset> data); ~SkPDFSharedStream(); - SkPDFDict* dict() { return fDict.get(); } + SkPDFDict* dict() { return &fDict; } void emitObject(SkWStream*, const SkPDFObjNumMap&, const SkPDFSubstituteMap&) const override; @@ -320,11 +320,52 @@ public: private: std::unique_ptr<SkStreamAsset> fAsset; - sk_sp<SkPDFDict> fDict; - SkDEBUGCODE(bool fDumped;) + SkPDFDict fDict; typedef SkPDFObject INHERITED; }; +/** \class SkPDFStream + + This class takes an asset and assumes that it is the only owner of + the asset's data. It immediately compresses the asset to save + memory. + */ + +class SkPDFStream : public SkPDFObject { + +public: + /** Create a PDF stream. A Length entry is automatically added to the + * stream dictionary. + * @param data The data part of the stream. + * @param stream The data part of the stream. */ + explicit SkPDFStream(sk_sp<SkData> data); + explicit SkPDFStream(std::unique_ptr<SkStreamAsset> stream); + virtual ~SkPDFStream(); + + SkPDFDict* dict() { return &fDict; } + + // The SkPDFObject interface. + void emitObject(SkWStream* stream, + const SkPDFObjNumMap& objNumMap, + const SkPDFSubstituteMap& substitutes) const override; + void addResources(SkPDFObjNumMap*, const SkPDFSubstituteMap&) const final; + void drop() override; + +protected: + /* Create a PDF stream with no data. The setData method must be called to + * set the data. */ + SkPDFStream(); + + /** Only call this function once. */ + void setData(std::unique_ptr<SkStreamAsset> stream); + +private: + std::unique_ptr<SkStreamAsset> fCompressedData; + SkPDFDict fDict; + + typedef SkPDFDict INHERITED; +}; + //////////////////////////////////////////////////////////////////////////////// /** \class SkPDFObjNumMap |