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 | |
halcanary | 37c46ca | 2015-03-31 12:30:20 -0700 | [diff] [blame] | 18 | class SkPDFObjNumMap; |
vandebo@chromium.org | 8459d4e | 2010-09-24 22:25:30 +0000 | [diff] [blame] | 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 | 8459d4e | 2010-09-24 22:25:30 +0000 | [diff] [blame] | 24 | */ |
vandebo@chromium.org | d90c141 | 2011-02-24 21:50:04 +0000 | [diff] [blame] | 25 | class SkPDFStream : public SkPDFDict { |
mtklein | 2766c00 | 2015-06-26 11:45:03 -0700 | [diff] [blame] | 26 | |
vandebo@chromium.org | 8459d4e | 2010-09-24 22:25:30 +0000 | [diff] [blame] | 27 | public: |
| 28 | /** Create a PDF stream. A Length entry is automatically added to the |
halcanary | e322482 | 2014-07-14 09:12:12 -0700 | [diff] [blame] | 29 | * stream dictionary. |
halcanary | a060eba | 2015-08-19 12:26:46 -0700 | [diff] [blame] | 30 | * @param data The data part of the stream. Will not take ownership. |
vandebo@chromium.org | 8459d4e | 2010-09-24 22:25:30 +0000 | [diff] [blame] | 31 | */ |
halcanary | a060eba | 2015-08-19 12:26:46 -0700 | [diff] [blame] | 32 | explicit SkPDFStream(SkData* data) { this->setData(data); } |
halcanary | e322482 | 2014-07-14 09:12:12 -0700 | [diff] [blame] | 33 | |
| 34 | /** Create a PDF stream. A Length entry is automatically added to the |
| 35 | * stream dictionary. |
halcanary | a060eba | 2015-08-19 12:26:46 -0700 | [diff] [blame] | 36 | * @param stream The data part of the stream. Will not take ownership. |
halcanary | e322482 | 2014-07-14 09:12:12 -0700 | [diff] [blame] | 37 | */ |
halcanary | a060eba | 2015-08-19 12:26:46 -0700 | [diff] [blame] | 38 | explicit SkPDFStream(SkStream* stream) { this->setData(stream); } |
halcanary | 1f8ed02 | 2014-06-27 10:37:27 -0700 | [diff] [blame] | 39 | |
vandebo@chromium.org | 8459d4e | 2010-09-24 22:25:30 +0000 | [diff] [blame] | 40 | virtual ~SkPDFStream(); |
| 41 | |
halcanary | c1b71d6 | 2015-02-20 12:45:50 -0800 | [diff] [blame] | 42 | // The SkPDFObject interface. |
tfarina | f4219dd | 2015-04-27 17:18:28 -0700 | [diff] [blame] | 43 | void emitObject(SkWStream* stream, |
| 44 | const SkPDFObjNumMap& objNumMap, |
halcanary | a060eba | 2015-08-19 12:26:46 -0700 | [diff] [blame] | 45 | const SkPDFSubstituteMap& substitutes) const override; |
vandebo@chromium.org | 8459d4e | 2010-09-24 22:25:30 +0000 | [diff] [blame] | 46 | |
vandebo@chromium.org | 421d644 | 2011-07-20 17:39:01 +0000 | [diff] [blame] | 47 | protected: |
edisonn@google.com | d9dfa18 | 2013-04-24 13:01:01 +0000 | [diff] [blame] | 48 | /* Create a PDF stream with no data. The setData method must be called to |
| 49 | * set the data. |
| 50 | */ |
halcanary | a060eba | 2015-08-19 12:26:46 -0700 | [diff] [blame] | 51 | SkPDFStream() {} |
edisonn@google.com | d9dfa18 | 2013-04-24 13:01:01 +0000 | [diff] [blame] | 52 | |
halcanary | a060eba | 2015-08-19 12:26:46 -0700 | [diff] [blame] | 53 | /** Only call this function once. */ |
edisonn@google.com | d9dfa18 | 2013-04-24 13:01:01 +0000 | [diff] [blame] | 54 | void setData(SkStream* stream); |
halcanary | a060eba | 2015-08-19 12:26:46 -0700 | [diff] [blame] | 55 | void setData(SkData* data) { |
| 56 | SkMemoryStream memoryStream(data); |
| 57 | this->setData(&memoryStream); |
edisonn@google.com | d9dfa18 | 2013-04-24 13:01:01 +0000 | [diff] [blame] | 58 | } |
| 59 | |
edisonn@google.com | d9dfa18 | 2013-04-24 13:01:01 +0000 | [diff] [blame] | 60 | private: |
halcanary | a060eba | 2015-08-19 12:26:46 -0700 | [diff] [blame] | 61 | SkAutoTDelete<SkStreamRewindable> fCompressedData; |
vandebo@chromium.org | d90c141 | 2011-02-24 21:50:04 +0000 | [diff] [blame] | 62 | |
| 63 | typedef SkPDFDict INHERITED; |
vandebo@chromium.org | 8459d4e | 2010-09-24 22:25:30 +0000 | [diff] [blame] | 64 | }; |
| 65 | |
| 66 | #endif |