• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 
2 /*
3  * Copyright 2010 Google Inc.
4  *
5  * Use of this source code is governed by a BSD-style license that can be
6  * found in the LICENSE file.
7  */
8 
9 
10 #ifndef SkPDFStream_DEFINED
11 #define SkPDFStream_DEFINED
12 
13 #include "SkPDFTypes.h"
14 #include "SkRefCnt.h"
15 #include "SkStream.h"
16 #include "SkTemplates.h"
17 
18 class SkPDFObjNumMap;
19 
20 /** \class SkPDFStream
21 
22     A stream object in a PDF.  Note, all streams must be indirect objects (via
23     SkObjRef).
24 */
25 class SkPDFStream : public SkPDFDict {
26 
27 public:
28     /** Create a PDF stream. A Length entry is automatically added to the
29      *  stream dictionary.
30      *  @param data   The data part of the stream.  Will not take ownership.
31      */
SkPDFStream(SkData * data)32     explicit SkPDFStream(SkData* data) { this->setData(data); }
33 
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 not take ownership.
37      */
SkPDFStream(SkStream * stream)38     explicit SkPDFStream(SkStream* stream) { this->setData(stream); }
39 
40     virtual ~SkPDFStream();
41 
42     // The SkPDFObject interface.
43     void emitObject(SkWStream* stream,
44                     const SkPDFObjNumMap& objNumMap,
45                     const SkPDFSubstituteMap& substitutes) const override;
46 
47 protected:
48     /* Create a PDF stream with no data.  The setData method must be called to
49      * set the data.
50      */
SkPDFStream()51     SkPDFStream() {}
52 
53     /** Only call this function once. */
54     void setData(SkStream* stream);
setData(SkData * data)55     void setData(SkData* data) {
56         SkMemoryStream memoryStream(data);
57         this->setData(&memoryStream);
58     }
59 
60 private:
61     SkAutoTDelete<SkStreamRewindable> fCompressedData;
62 
63     typedef SkPDFDict INHERITED;
64 };
65 
66 #endif
67