| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2010 Google Inc. | 2 * Copyright 2010 Google Inc. |
| 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 SkPDFStream_DEFINED | 9 #ifndef SkPDFStream_DEFINED |
| 10 #define SkPDFStream_DEFINED | 10 #define SkPDFStream_DEFINED |
| 11 | 11 |
| 12 #include "SkPDFTypes.h" | 12 #include "SkPDFTypes.h" |
| 13 #include "SkStream.h" | 13 #include "SkStream.h" |
| 14 | 14 |
| 15 /** \class SkPDFStream | 15 /** \class SkPDFStream |
| 16 | 16 |
| 17 A stream object in a PDF. Note, all streams must be indirect objects (via | 17 A stream object in a PDF. Note, all streams must be indirect objects (via |
| 18 SkObjRef). | 18 SkObjRef). |
| 19 */ | 19 */ |
| 20 class SkPDFStream : public SkPDFDict { | 20 class SkPDFStream : public SkPDFDict { |
| 21 | 21 |
| 22 public: | 22 public: |
| 23 /** Create a PDF stream. A Length entry is automatically added to the | 23 /** Create a PDF stream. A Length entry is automatically added to the |
| 24 * stream dictionary. | 24 * stream dictionary. |
| 25 * @param data The data part of the stream. Will not take ownership. | 25 * @param data The data part of the stream. */ |
| 26 */ | 26 explicit SkPDFStream(sk_sp<SkData> data) { |
| 27 explicit SkPDFStream(SkData* data) { this->setData(data); } | 27 this->setData(std::unique_ptr<SkStreamAsset>( |
| 28 new SkMemoryStream(std::move(data)))); |
| 29 } |
| 28 | 30 |
| 29 /** Create a PDF stream. A Length entry is automatically added to the | 31 /** Create a PDF stream. A Length entry is automatically added to the |
| 30 * stream dictionary. | 32 * stream dictionary. |
| 31 * @param stream The data part of the stream. | 33 * @param stream The data part of the stream. |
| 32 */ | 34 */ |
| 33 explicit SkPDFStream(std::unique_ptr<SkStreamAsset> stream) { | 35 explicit SkPDFStream(std::unique_ptr<SkStreamAsset> stream) { |
| 34 this->setData(std::move(stream)); | 36 this->setData(std::move(stream)); |
| 35 } | 37 } |
| 36 | 38 |
| 37 virtual ~SkPDFStream(); | 39 virtual ~SkPDFStream(); |
| 38 | 40 |
| 39 // The SkPDFObject interface. | 41 // The SkPDFObject interface. |
| 40 void emitObject(SkWStream* stream, | 42 void emitObject(SkWStream* stream, |
| 41 const SkPDFObjNumMap& objNumMap, | 43 const SkPDFObjNumMap& objNumMap, |
| 42 const SkPDFSubstituteMap& substitutes) const override; | 44 const SkPDFSubstituteMap& substitutes) const override; |
| 43 void drop() override; | 45 void drop() override; |
| 44 | 46 |
| 45 protected: | 47 protected: |
| 46 /* Create a PDF stream with no data. The setData method must be called to | 48 /* Create a PDF stream with no data. The setData method must be called to |
| 47 * set the data. | 49 * set the data. |
| 48 */ | 50 */ |
| 49 SkPDFStream() {} | 51 SkPDFStream() {} |
| 50 | 52 |
| 51 /** Only call this function once. */ | 53 /** Only call this function once. */ |
| 52 void setData(std::unique_ptr<SkStreamAsset> stream); | 54 void setData(std::unique_ptr<SkStreamAsset> stream); |
| 53 void setData(SkData* data) { | |
| 54 this->setData(std::unique_ptr<SkStreamAsset>(new SkMemoryStream(data))); | |
| 55 } | |
| 56 | 55 |
| 57 private: | 56 private: |
| 58 std::unique_ptr<SkStreamAsset> fCompressedData; | 57 std::unique_ptr<SkStreamAsset> fCompressedData; |
| 59 | 58 |
| 60 typedef SkPDFDict INHERITED; | 59 typedef SkPDFDict INHERITED; |
| 61 }; | 60 }; |
| 62 | 61 |
| 63 #endif | 62 #endif |
| OLD | NEW |