epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 1 | |
vandebo@chromium.org | 8459d4e | 2010-09-24 22:25:30 +0000 | [diff] [blame] | 2 | /* |
epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 3 | * Copyright 2010 Google Inc. |
vandebo@chromium.org | 8459d4e | 2010-09-24 22:25:30 +0000 | [diff] [blame] | 4 | * |
epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 5 | * Use of this source code is governed by a BSD-style license that can be |
| 6 | * found in the LICENSE file. |
vandebo@chromium.org | 8459d4e | 2010-09-24 22:25:30 +0000 | [diff] [blame] | 7 | */ |
| 8 | |
epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 9 | |
vandebo@chromium.org | 8459d4e | 2010-09-24 22:25:30 +0000 | [diff] [blame] | 10 | #ifndef SkPDFStream_DEFINED |
| 11 | #define SkPDFStream_DEFINED |
| 12 | |
| 13 | #include "SkPDFTypes.h" |
| 14 | #include "SkRefCnt.h" |
vandebo@chromium.org | a09ef97 | 2010-12-01 22:17:20 +0000 | [diff] [blame] | 15 | #include "SkStream.h" |
vandebo@chromium.org | 8459d4e | 2010-09-24 22:25:30 +0000 | [diff] [blame] | 16 | #include "SkTemplates.h" |
| 17 | |
vandebo@chromium.org | 8459d4e | 2010-09-24 22:25:30 +0000 | [diff] [blame] | 18 | class SkPDFCatalog; |
| 19 | |
| 20 | /** \class SkPDFStream |
| 21 | |
vandebo@chromium.org | da912d6 | 2011-03-08 18:31:02 +0000 | [diff] [blame] | 22 | A stream object in a PDF. Note, all streams must be indirect objects (via |
| 23 | SkObjRef). |
vandebo@chromium.org | 26e1449 | 2013-08-26 22:52:09 +0000 | [diff] [blame] | 24 | TODO(vandebo): SkStream should be replaced by SkStreamRewindable when that |
| 25 | is feasible. |
vandebo@chromium.org | 8459d4e | 2010-09-24 22:25:30 +0000 | [diff] [blame] | 26 | */ |
vandebo@chromium.org | d90c141 | 2011-02-24 21:50:04 +0000 | [diff] [blame] | 27 | class SkPDFStream : public SkPDFDict { |
vandebo@chromium.org | 8459d4e | 2010-09-24 22:25:30 +0000 | [diff] [blame] | 28 | public: |
| 29 | /** Create a PDF stream. A Length entry is automatically added to the |
reed@google.com | 6ed8249 | 2011-06-24 21:01:17 +0000 | [diff] [blame] | 30 | * 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.org | 421d644 | 2011-07-20 17:39:01 +0000 | [diff] [blame] | 32 | * @param data The data part of the stream. |
vandebo@chromium.org | 8459d4e | 2010-09-24 22:25:30 +0000 | [diff] [blame] | 33 | */ |
vandebo@chromium.org | 421d644 | 2011-07-20 17:39:01 +0000 | [diff] [blame] | 34 | explicit SkPDFStream(SkData* data); |
| 35 | /** Deprecated constructor. */ |
vandebo@chromium.org | 8459d4e | 2010-09-24 22:25:30 +0000 | [diff] [blame] | 36 | explicit SkPDFStream(SkStream* stream); |
vandebo@chromium.org | 421d644 | 2011-07-20 17:39:01 +0000 | [diff] [blame] | 37 | /** 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.org | 8459d4e | 2010-09-24 22:25:30 +0000 | [diff] [blame] | 41 | 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.org | 421d644 | 2011-07-20 17:39:01 +0000 | [diff] [blame] | 48 | protected: |
vandebo@chromium.org | 421d644 | 2011-07-20 17:39:01 +0000 | [diff] [blame] | 49 | 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.com | d9dfa18 | 2013-04-24 13:01:01 +0000 | [diff] [blame] | 55 | |
| 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.org | d8d976e | 2013-07-08 23:17:57 +0000 | [diff] [blame] | 73 | void setData(SkData* data); |
edisonn@google.com | d9dfa18 | 2013-04-24 13:01:01 +0000 | [diff] [blame] | 74 | 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 | |
| 88 | private: |
vandebo@chromium.org | 421d644 | 2011-07-20 17:39:01 +0000 | [diff] [blame] | 89 | // Indicates what form (or if) the stream has been requested. |
| 90 | State fState; |
skia.committer@gmail.com | 83f0d30 | 2013-04-25 07:01:04 +0000 | [diff] [blame] | 91 | |
ctguil@chromium.org | 769fa6a | 2011-08-20 00:36:18 +0000 | [diff] [blame] | 92 | // TODO(vandebo): Use SkData (after removing deprecated constructor). |
vandebo@chromium.org | d96d17b | 2013-01-04 19:31:24 +0000 | [diff] [blame] | 93 | SkAutoTUnref<SkStream> fData; |
| 94 | SkAutoTUnref<SkPDFStream> fSubstitute; |
vandebo@chromium.org | d90c141 | 2011-02-24 21:50:04 +0000 | [diff] [blame] | 95 | |
| 96 | typedef SkPDFDict INHERITED; |
vandebo@chromium.org | 8459d4e | 2010-09-24 22:25:30 +0000 | [diff] [blame] | 97 | }; |
| 98 | |
| 99 | #endif |