blob: 263a408d72e502e770ccc80a90cb53887402999c [file] [log] [blame]
vandebo@chromium.org8459d4e2010-09-24 22:25:30 +00001/*
vandebo@chromium.orgd90c1412011-02-24 21:50:04 +00002 * Copyright (C) 2010 Google Inc.
vandebo@chromium.org8459d4e2010-09-24 22:25:30 +00003 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#ifndef SkPDFStream_DEFINED
18#define SkPDFStream_DEFINED
19
20#include "SkPDFTypes.h"
21#include "SkRefCnt.h"
vandebo@chromium.orga09ef972010-12-01 22:17:20 +000022#include "SkStream.h"
vandebo@chromium.org8459d4e2010-09-24 22:25:30 +000023#include "SkTemplates.h"
24
vandebo@chromium.org8459d4e2010-09-24 22:25:30 +000025class SkPDFCatalog;
26
27/** \class SkPDFStream
28
vandebo@chromium.orgda912d62011-03-08 18:31:02 +000029 A stream object in a PDF. Note, all streams must be indirect objects (via
30 SkObjRef).
vandebo@chromium.org8459d4e2010-09-24 22:25:30 +000031*/
vandebo@chromium.orgd90c1412011-02-24 21:50:04 +000032class SkPDFStream : public SkPDFDict {
vandebo@chromium.org8459d4e2010-09-24 22:25:30 +000033public:
34 /** Create a PDF stream. A Length entry is automatically added to the
reed@google.com6ed82492011-06-24 21:01:17 +000035 * stream dictionary. The stream may be retained (stream->ref() may be
36 * called) so its contents must not be changed after calling this.
vandebo@chromium.org421d6442011-07-20 17:39:01 +000037 * @param data The data part of the stream.
vandebo@chromium.org8459d4e2010-09-24 22:25:30 +000038 */
vandebo@chromium.org421d6442011-07-20 17:39:01 +000039 explicit SkPDFStream(SkData* data);
40 /** Deprecated constructor. */
vandebo@chromium.org8459d4e2010-09-24 22:25:30 +000041 explicit SkPDFStream(SkStream* stream);
vandebo@chromium.org421d6442011-07-20 17:39:01 +000042 /** Create a PDF stream with the same content and dictionary entries
43 * as the passed one.
44 */
45 explicit SkPDFStream(const SkPDFStream& pdfStream);
vandebo@chromium.org8459d4e2010-09-24 22:25:30 +000046 virtual ~SkPDFStream();
47
48 // The SkPDFObject interface.
49 virtual void emitObject(SkWStream* stream, SkPDFCatalog* catalog,
50 bool indirect);
51 virtual size_t getOutputSize(SkPDFCatalog* catalog, bool indirect);
52
vandebo@chromium.org421d6442011-07-20 17:39:01 +000053protected:
54 /* Create a PDF stream with no data. The setData method must be called to
55 * set the data.
56 */
57 SkPDFStream();
58
59 void setData(SkStream* stream);
60
vandebo@chromium.org8459d4e2010-09-24 22:25:30 +000061private:
vandebo@chromium.org421d6442011-07-20 17:39:01 +000062 enum State {
63 kUnused_State, //!< The stream hasn't been requested yet.
64 kNoCompression_State, //!< The stream's been requested in an
65 // uncompressed form.
66 kCompressed_State, //!< The stream's already been compressed.
67 };
68 // Indicates what form (or if) the stream has been requested.
69 State fState;
70
71 // TODO(vandebo) Use SkData (after removing deprecated constructor).
72 SkRefPtr<SkStream> fData;
73 SkRefPtr<SkPDFStream> fSubstitute;
vandebo@chromium.orgd90c1412011-02-24 21:50:04 +000074
75 typedef SkPDFDict INHERITED;
vandebo@chromium.org421d6442011-07-20 17:39:01 +000076
77 // Populate the stream dictionary. This method returns false if
78 // fSubstitute should be used.
79 bool populate(SkPDFCatalog* catalog);
vandebo@chromium.org8459d4e2010-09-24 22:25:30 +000080};
81
82#endif