blob: bb38ba96cf37616e7b014acd0d0fccc4c3ea47ed [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.org8459d4e2010-09-24 22:25:30 +000024*/
vandebo@chromium.orgd90c1412011-02-24 21:50:04 +000025class SkPDFStream : public SkPDFDict {
commit-bot@chromium.orgab1c1382013-12-05 12:08:12 +000026 SK_DECLARE_INST_COUNT(SkPDFStream)
vandebo@chromium.org8459d4e2010-09-24 22:25:30 +000027public:
28 /** Create a PDF stream. A Length entry is automatically added to the
halcanarye3224822014-07-14 09:12:12 -070029 * stream dictionary.
30 * @param data The data part of the stream. Will be ref()ed.
vandebo@chromium.org8459d4e2010-09-24 22:25:30 +000031 */
vandebo@chromium.org421d6442011-07-20 17:39:01 +000032 explicit SkPDFStream(SkData* data);
halcanarye3224822014-07-14 09:12:12 -070033
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 */
vandebo@chromium.org8459d4e2010-09-24 22:25:30 +000038 explicit SkPDFStream(SkStream* stream);
halcanary1f8ed022014-06-27 10:37:27 -070039
vandebo@chromium.org8459d4e2010-09-24 22:25:30 +000040 virtual ~SkPDFStream();
41
halcanaryc1b71d62015-02-20 12:45:50 -080042 // The SkPDFObject interface.
mtklein36352bf2015-03-25 18:17:31 -070043 virtual void emitObject(SkWStream* stream, SkPDFCatalog* catalog) override;
vandebo@chromium.org8459d4e2010-09-24 22:25:30 +000044
vandebo@chromium.org421d6442011-07-20 17:39:01 +000045protected:
vandebo@chromium.org421d6442011-07-20 17:39:01 +000046 enum State {
47 kUnused_State, //!< The stream hasn't been requested yet.
48 kNoCompression_State, //!< The stream's been requested in an
49 // uncompressed form.
50 kCompressed_State, //!< The stream's already been compressed.
51 };
edisonn@google.comd9dfa182013-04-24 13:01:01 +000052
halcanary1f8ed022014-06-27 10:37:27 -070053 /** Create a PDF stream with the same content and dictionary entries
54 * as the passed one.
55 */
56 explicit SkPDFStream(const SkPDFStream& pdfStream);
57
edisonn@google.comd9dfa182013-04-24 13:01:01 +000058 /* Create a PDF stream with no data. The setData method must be called to
59 * set the data.
60 */
61 SkPDFStream();
62
63 // Populate the stream dictionary. This method returns false if
64 // fSubstitute should be used.
65 virtual bool populate(SkPDFCatalog* catalog);
66
67 void setSubstitute(SkPDFStream* stream) {
68 fSubstitute.reset(stream);
69 }
70
halcanary67ec1f82014-06-27 11:36:20 -070071 SkPDFStream* getSubstitute() const {
edisonn@google.comd9dfa182013-04-24 13:01:01 +000072 return fSubstitute.get();
73 }
74
commit-bot@chromium.orgd8d976e2013-07-08 23:17:57 +000075 void setData(SkData* data);
edisonn@google.comd9dfa182013-04-24 13:01:01 +000076 void setData(SkStream* stream);
77
halcanary67ec1f82014-06-27 11:36:20 -070078 size_t dataSize() const;
79
edisonn@google.comd9dfa182013-04-24 13:01:01 +000080 void setState(State state) {
81 fState = state;
82 }
83
halcanary67ec1f82014-06-27 11:36:20 -070084 State getState() const {
edisonn@google.comd9dfa182013-04-24 13:01:01 +000085 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
scroggoa1193e42015-01-21 12:09:53 -080092 SkAutoTDelete<SkStreamRewindable> fDataStream;
vandebo@chromium.orgd96d17b2013-01-04 19:31:24 +000093 SkAutoTUnref<SkPDFStream> fSubstitute;
vandebo@chromium.orgd90c1412011-02-24 21:50:04 +000094
95 typedef SkPDFDict INHERITED;
vandebo@chromium.org8459d4e2010-09-24 22:25:30 +000096};
97
98#endif