Home | History | Annotate | Download | only in pdf
      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 SkPDFCatalog;
     19 
     20 /** \class SkPDFStream
     21 
     22     A stream object in a PDF.  Note, all streams must be indirect objects (via
     23     SkObjRef).
     24     TODO(vandebo): SkStream should be replaced by SkStreamRewindable when that
     25     is feasible.
     26 */
     27 class SkPDFStream : public SkPDFDict {
     28 public:
     29     /** Create a PDF stream. A Length entry is automatically added to the
     30      *  stream dictionary. The stream may be retained (stream->ref() may be
     31      *  called) so its contents must not be changed after calling this.
     32      *  @param data  The data part of the stream.
     33      */
     34     explicit SkPDFStream(SkData* data);
     35     /** Deprecated constructor. */
     36     explicit SkPDFStream(SkStream* stream);
     37     /** Create a PDF stream with the same content and dictionary entries
     38      *  as the passed one.
     39      */
     40     explicit SkPDFStream(const SkPDFStream& pdfStream);
     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 
     48 protected:
     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     };
     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 
     73     void setData(SkData* data);
     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:
     89     // Indicates what form (or if) the stream has been requested.
     90     State fState;
     91 
     92     // TODO(vandebo): Use SkData (after removing deprecated constructor).
     93     SkAutoTUnref<SkStream> fData;
     94     SkAutoTUnref<SkPDFStream> fSubstitute;
     95 
     96     typedef SkPDFDict INHERITED;
     97 };
     98 
     99 #endif
    100