3 * Copyright 2010 Google Inc.
5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file.
10 #ifndef SkPDFStream_DEFINED
11 #define SkPDFStream_DEFINED
13 #include "SkPDFTypes.h"
16 #include "SkTemplates.h"
20 /** \class SkPDFStream
22 A stream object in a PDF. Note, all streams must be indirect objects (via
25 class SkPDFStream : public SkPDFDict {
26 SK_DECLARE_INST_COUNT(SkPDFStream)
28 /** Create a PDF stream. A Length entry is automatically added to the
30 * @param data The data part of the stream. Will be ref()ed.
32 explicit SkPDFStream(SkData* data);
34 /** Create a PDF stream. A Length entry is automatically added to the
36 * @param stream The data part of the stream. Will be duplicate()d.
38 explicit SkPDFStream(SkStream* stream);
40 virtual ~SkPDFStream();
42 // The SkPDFObject interface. These two methods use a mutex to
43 // allow multiple threads to call at the same time.
44 virtual void emitObject(SkWStream* stream, SkPDFCatalog* catalog,
46 virtual size_t getOutputSize(SkPDFCatalog* catalog, bool indirect);
50 kUnused_State, //!< The stream hasn't been requested yet.
51 kNoCompression_State, //!< The stream's been requested in an
53 kCompressed_State, //!< The stream's already been compressed.
56 /** Create a PDF stream with the same content and dictionary entries
59 explicit SkPDFStream(const SkPDFStream& pdfStream);
61 /* Create a PDF stream with no data. The setData method must be called to
66 // Populate the stream dictionary. This method returns false if
67 // fSubstitute should be used.
68 virtual bool populate(SkPDFCatalog* catalog);
70 void setSubstitute(SkPDFStream* stream) {
71 fSubstitute.reset(stream);
74 SkPDFStream* getSubstitute() const {
75 return fSubstitute.get();
78 void setData(SkData* data);
79 void setData(SkStream* stream);
81 size_t dataSize() const;
83 void setState(State state) {
87 State getState() const {
92 // Indicates what form (or if) the stream has been requested.
95 // Mutex guards fState, fDataStream, and fSubstitute in public interface.
98 SkMemoryStream fMemoryStream; // Used by fDataStream when
99 // fDataStream needs to be backed
101 SkAutoTUnref<SkStreamRewindable> fDataStream;
102 SkAutoTUnref<SkPDFStream> fSubstitute;
104 typedef SkPDFDict INHERITED;