blob: d7ff115ba9170fbd88af8571cdd70b4ec9f6673e [file] [log] [blame]
epoger@google.comec3ed6a2011-07-28 14:26:00 +00001
vandebo@chromium.org8459d4e2010-09-24 22:25:30 +00002/*
epoger@google.comec3ed6a2011-07-28 14:26:00 +00003 * Copyright 2010 Google Inc.
vandebo@chromium.org8459d4e2010-09-24 22:25:30 +00004 *
epoger@google.comec3ed6a2011-07-28 14:26:00 +00005 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file.
vandebo@chromium.org8459d4e2010-09-24 22:25:30 +00007 */
8
epoger@google.comec3ed6a2011-07-28 14:26:00 +00009
vandebo@chromium.org8459d4e2010-09-24 22:25:30 +000010#ifndef SkPDFStream_DEFINED
11#define SkPDFStream_DEFINED
12
13#include "SkPDFTypes.h"
14#include "SkRefCnt.h"
vandebo@chromium.orga09ef972010-12-01 22:17:20 +000015#include "SkStream.h"
vandebo@chromium.org8459d4e2010-09-24 22:25:30 +000016#include "SkTemplates.h"
17
vandebo@chromium.org8459d4e2010-09-24 22:25:30 +000018class SkPDFCatalog;
19
20/** \class SkPDFStream
21
vandebo@chromium.orgda912d62011-03-08 18:31:02 +000022 A stream object in a PDF. Note, all streams must be indirect objects (via
23 SkObjRef).
vandebo@chromium.org26e14492013-08-26 22:52:09 +000024 TODO(vandebo): SkStream should be replaced by SkStreamRewindable when that
25 is feasible.
vandebo@chromium.org8459d4e2010-09-24 22:25:30 +000026*/
vandebo@chromium.orgd90c1412011-02-24 21:50:04 +000027class SkPDFStream : public SkPDFDict {
vandebo@chromium.org8459d4e2010-09-24 22:25:30 +000028public:
29 /** Create a PDF stream. A Length entry is automatically added to the
reed@google.com6ed82492011-06-24 21:01:17 +000030 * stream dictionary. The stream may be retained (stream->ref() may be
31 * called) so its contents must not be changed after calling this.
vandebo@chromium.org421d6442011-07-20 17:39:01 +000032 * @param data The data part of the stream.
vandebo@chromium.org8459d4e2010-09-24 22:25:30 +000033 */
vandebo@chromium.org421d6442011-07-20 17:39:01 +000034 explicit SkPDFStream(SkData* data);
35 /** Deprecated constructor. */
vandebo@chromium.org8459d4e2010-09-24 22:25:30 +000036 explicit SkPDFStream(SkStream* stream);
vandebo@chromium.org421d6442011-07-20 17:39:01 +000037 /** Create a PDF stream with the same content and dictionary entries
38 * as the passed one.
39 */
40 explicit SkPDFStream(const SkPDFStream& pdfStream);
vandebo@chromium.org8459d4e2010-09-24 22:25:30 +000041 virtual ~SkPDFStream();
42
43 // The SkPDFObject interface.
44 virtual void emitObject(SkWStream* stream, SkPDFCatalog* catalog,
45 bool indirect);
46 virtual size_t getOutputSize(SkPDFCatalog* catalog, bool indirect);
47
vandebo@chromium.org421d6442011-07-20 17:39:01 +000048protected:
vandebo@chromium.org421d6442011-07-20 17:39:01 +000049 enum State {
50 kUnused_State, //!< The stream hasn't been requested yet.
51 kNoCompression_State, //!< The stream's been requested in an
52 // uncompressed form.
53 kCompressed_State, //!< The stream's already been compressed.
54 };
edisonn@google.comd9dfa182013-04-24 13:01:01 +000055
56 /* Create a PDF stream with no data. The setData method must be called to
57 * set the data.
58 */
59 SkPDFStream();
60
61 // Populate the stream dictionary. This method returns false if
62 // fSubstitute should be used.
63 virtual bool populate(SkPDFCatalog* catalog);
64
65 void setSubstitute(SkPDFStream* stream) {
66 fSubstitute.reset(stream);
67 }
68
69 SkPDFStream* getSubstitute() {
70 return fSubstitute.get();
71 }
72
commit-bot@chromium.orgd8d976e2013-07-08 23:17:57 +000073 void setData(SkData* data);
edisonn@google.comd9dfa182013-04-24 13:01:01 +000074 void setData(SkStream* stream);
75
76 SkStream* getData() {
77 return fData.get();
78 }
79
80 void setState(State state) {
81 fState = state;
82 }
83
84 State getState() {
85 return fState;
86 }
87
88private:
vandebo@chromium.org421d6442011-07-20 17:39:01 +000089 // Indicates what form (or if) the stream has been requested.
90 State fState;
skia.committer@gmail.com83f0d302013-04-25 07:01:04 +000091
ctguil@chromium.org769fa6a2011-08-20 00:36:18 +000092 // TODO(vandebo): Use SkData (after removing deprecated constructor).
vandebo@chromium.orgd96d17b2013-01-04 19:31:24 +000093 SkAutoTUnref<SkStream> fData;
94 SkAutoTUnref<SkPDFStream> fSubstitute;
vandebo@chromium.orgd90c1412011-02-24 21:50:04 +000095
96 typedef SkPDFDict INHERITED;
vandebo@chromium.org8459d4e2010-09-24 22:25:30 +000097};
98
99#endif