1 2 /* 3 * Copyright 2010 Google Inc. 4 * 5 * Use of this source code is governed by a BSD-style license that can be 6 * found in the LICENSE file. 7 */ 8 9 10 #ifndef SkPDFStream_DEFINED 11 #define SkPDFStream_DEFINED 12 13 #include "SkPDFTypes.h" 14 #include "SkRefCnt.h" 15 #include "SkStream.h" 16 #include "SkTemplates.h" 17 18 class SkPDFObjNumMap; 19 20 /** \class SkPDFStream 21 22 A stream object in a PDF. Note, all streams must be indirect objects (via 23 SkObjRef). 24 */ 25 class SkPDFStream : public SkPDFDict { 26 SK_DECLARE_INST_COUNT(SkPDFStream) 27 public: 28 /** Create a PDF stream. A Length entry is automatically added to the 29 * stream dictionary. 30 * @param data The data part of the stream. Will be ref()ed. 31 */ 32 explicit SkPDFStream(SkData* data); 33 34 /** Create a PDF stream. A Length entry is automatically added to the 35 * stream dictionary. 36 * @param stream The data part of the stream. Will be duplicate()d. 37 */ 38 explicit SkPDFStream(SkStream* stream); 39 40 virtual ~SkPDFStream(); 41 42 // The SkPDFObject interface. 43 void emitObject(SkWStream* stream, 44 const SkPDFObjNumMap& objNumMap, 45 const SkPDFSubstituteMap& substitutes) override; 46 47 protected: 48 enum State { 49 kUnused_State, //!< The stream hasn't been requested yet. 50 kNoCompression_State, //!< The stream's been requested in an 51 // uncompressed form. 52 kCompressed_State, //!< The stream's already been compressed. 53 }; 54 55 /* Create a PDF stream with no data. The setData method must be called to 56 * set the data. 57 */ 58 SkPDFStream(); 59 60 void setData(SkData* data); 61 void setData(SkStream* stream); 62 63 size_t dataSize() const; 64 setState(State state)65 void setState(State state) { 66 fState = state; 67 } 68 69 private: 70 // Indicates what form (or if) the stream has been requested. 71 State fState; 72 73 SkAutoTDelete<SkStreamRewindable> fDataStream; 74 75 typedef SkPDFDict INHERITED; 76 }; 77 78 #endif 79