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 */
     25 class SkPDFStream : public SkPDFDict {
     26 public:
     27     /** Create a PDF stream. A Length entry is automatically added to the
     28      *  stream dictionary. The stream may be retained (stream->ref() may be
     29      *  called) so its contents must not be changed after calling this.
     30      *  @param data  The data part of the stream.
     31      */
     32     explicit SkPDFStream(SkData* data);
     33     /** Deprecated constructor. */
     34     explicit SkPDFStream(SkStream* stream);
     35     /** Create a PDF stream with the same content and dictionary entries
     36      *  as the passed one.
     37      */
     38     explicit SkPDFStream(const SkPDFStream& pdfStream);
     39     virtual ~SkPDFStream();
     40 
     41     // The SkPDFObject interface.
     42     virtual void emitObject(SkWStream* stream, SkPDFCatalog* catalog,
     43                             bool indirect);
     44     virtual size_t getOutputSize(SkPDFCatalog* catalog, bool indirect);
     45 
     46 protected:
     47     /* Create a PDF stream with no data.  The setData method must be called to
     48      * set the data.
     49      */
     50     SkPDFStream();
     51 
     52     void setData(SkStream* stream);
     53 
     54 private:
     55     enum State {
     56         kUnused_State,         //!< The stream hasn't been requested yet.
     57         kNoCompression_State,  //!< The stream's been requested in an
     58                                //   uncompressed form.
     59         kCompressed_State,     //!< The stream's already been compressed.
     60     };
     61     // Indicates what form (or if) the stream has been requested.
     62     State fState;
     63 
     64     // TODO(vandebo): Use SkData (after removing deprecated constructor).
     65     SkRefPtr<SkStream> fData;
     66     SkRefPtr<SkPDFStream> fSubstitute;
     67 
     68     typedef SkPDFDict INHERITED;
     69 
     70     // Populate the stream dictionary.  This method returns false if
     71     // fSubstitute should be used.
     72     bool populate(SkPDFCatalog* catalog);
     73 };
     74 
     75 #endif
     76