1ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com
28459d4e5e32608ec6da3f2b81731aaeb7b038843vandebo@chromium.org/*
3ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com * Copyright 2010 Google Inc.
48459d4e5e32608ec6da3f2b81731aaeb7b038843vandebo@chromium.org *
5ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com * Use of this source code is governed by a BSD-style license that can be
6ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com * found in the LICENSE file.
78459d4e5e32608ec6da3f2b81731aaeb7b038843vandebo@chromium.org */
88459d4e5e32608ec6da3f2b81731aaeb7b038843vandebo@chromium.org
9ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com
108459d4e5e32608ec6da3f2b81731aaeb7b038843vandebo@chromium.org#ifndef SkPDFStream_DEFINED
118459d4e5e32608ec6da3f2b81731aaeb7b038843vandebo@chromium.org#define SkPDFStream_DEFINED
128459d4e5e32608ec6da3f2b81731aaeb7b038843vandebo@chromium.org
138459d4e5e32608ec6da3f2b81731aaeb7b038843vandebo@chromium.org#include "SkPDFTypes.h"
148459d4e5e32608ec6da3f2b81731aaeb7b038843vandebo@chromium.org#include "SkRefCnt.h"
15a09ef977b6799f01cd3fd64725fb3069da8be4bcvandebo@chromium.org#include "SkStream.h"
168459d4e5e32608ec6da3f2b81731aaeb7b038843vandebo@chromium.org#include "SkTemplates.h"
178459d4e5e32608ec6da3f2b81731aaeb7b038843vandebo@chromium.org
1837c46cad21632cfc1411b08d73af37a1fffe2944halcanaryclass SkPDFObjNumMap;
198459d4e5e32608ec6da3f2b81731aaeb7b038843vandebo@chromium.org
208459d4e5e32608ec6da3f2b81731aaeb7b038843vandebo@chromium.org/** \class SkPDFStream
218459d4e5e32608ec6da3f2b81731aaeb7b038843vandebo@chromium.org
22da912d61ede86dd3dfa8f645c6f3977f2183812bvandebo@chromium.org    A stream object in a PDF.  Note, all streams must be indirect objects (via
23da912d61ede86dd3dfa8f645c6f3977f2183812bvandebo@chromium.org    SkObjRef).
248459d4e5e32608ec6da3f2b81731aaeb7b038843vandebo@chromium.org*/
25d90c141feb10c80581c16dbb57fcc97719a0c002vandebo@chromium.orgclass SkPDFStream : public SkPDFDict {
262766c00fc0b6a07d46e5f74cdad45da2ef625237mtklein
278459d4e5e32608ec6da3f2b81731aaeb7b038843vandebo@chromium.orgpublic:
288459d4e5e32608ec6da3f2b81731aaeb7b038843vandebo@chromium.org    /** Create a PDF stream. A Length entry is automatically added to the
29e322482f4d82bc704e40b8c89843f2ea5b6ddc04halcanary     *  stream dictionary.
302880df2609eba09b555ca37be04b6ad89290c765Tom Hudson     *  @param data   The data part of the stream.  Will not take ownership.
318459d4e5e32608ec6da3f2b81731aaeb7b038843vandebo@chromium.org     */
322880df2609eba09b555ca37be04b6ad89290c765Tom Hudson    explicit SkPDFStream(SkData* data) { this->setData(data); }
33e322482f4d82bc704e40b8c89843f2ea5b6ddc04halcanary
34e322482f4d82bc704e40b8c89843f2ea5b6ddc04halcanary    /** Create a PDF stream. A Length entry is automatically added to the
35e322482f4d82bc704e40b8c89843f2ea5b6ddc04halcanary     *  stream dictionary.
362880df2609eba09b555ca37be04b6ad89290c765Tom Hudson     *  @param stream The data part of the stream.  Will not take ownership.
37e322482f4d82bc704e40b8c89843f2ea5b6ddc04halcanary     */
382880df2609eba09b555ca37be04b6ad89290c765Tom Hudson    explicit SkPDFStream(SkStream* stream) { this->setData(stream); }
391f8ed022226c9f960b9fc95af9297d5111a07eadhalcanary
408459d4e5e32608ec6da3f2b81731aaeb7b038843vandebo@chromium.org    virtual ~SkPDFStream();
418459d4e5e32608ec6da3f2b81731aaeb7b038843vandebo@chromium.org
42c1b71d6c30041f01675dd54a77adc9c177afdf44halcanary    // The SkPDFObject interface.
43f4219ddf31b2171a5576ab98d1fd2deab4d816fdtfarina    void emitObject(SkWStream* stream,
44f4219ddf31b2171a5576ab98d1fd2deab4d816fdtfarina                    const SkPDFObjNumMap& objNumMap,
452880df2609eba09b555ca37be04b6ad89290c765Tom Hudson                    const SkPDFSubstituteMap& substitutes) const override;
468459d4e5e32608ec6da3f2b81731aaeb7b038843vandebo@chromium.org
47421d6443fbd3a913dfa32b6492c4a2969bc6314bvandebo@chromium.orgprotected:
48421d6443fbd3a913dfa32b6492c4a2969bc6314bvandebo@chromium.org    /* Create a PDF stream with no data.  The setData method must be called to
49421d6443fbd3a913dfa32b6492c4a2969bc6314bvandebo@chromium.org     * set the data.
50421d6443fbd3a913dfa32b6492c4a2969bc6314bvandebo@chromium.org     */
512880df2609eba09b555ca37be04b6ad89290c765Tom Hudson    SkPDFStream() {}
52421d6443fbd3a913dfa32b6492c4a2969bc6314bvandebo@chromium.org
532880df2609eba09b555ca37be04b6ad89290c765Tom Hudson    /** Only call this function once. */
54421d6443fbd3a913dfa32b6492c4a2969bc6314bvandebo@chromium.org    void setData(SkStream* stream);
552880df2609eba09b555ca37be04b6ad89290c765Tom Hudson    void setData(SkData* data) {
562880df2609eba09b555ca37be04b6ad89290c765Tom Hudson        SkMemoryStream memoryStream(data);
572880df2609eba09b555ca37be04b6ad89290c765Tom Hudson        this->setData(&memoryStream);
58d9dfa18372119c8e1318125d2075fa80e0819094edisonn@google.com    }
59d9dfa18372119c8e1318125d2075fa80e0819094edisonn@google.com
608459d4e5e32608ec6da3f2b81731aaeb7b038843vandebo@chromium.orgprivate:
612880df2609eba09b555ca37be04b6ad89290c765Tom Hudson    SkAutoTDelete<SkStreamRewindable> fCompressedData;
62d90c141feb10c80581c16dbb57fcc97719a0c002vandebo@chromium.org
63d90c141feb10c80581c16dbb57fcc97719a0c002vandebo@chromium.org    typedef SkPDFDict INHERITED;
648459d4e5e32608ec6da3f2b81731aaeb7b038843vandebo@chromium.org};
658459d4e5e32608ec6da3f2b81731aaeb7b038843vandebo@chromium.org
668459d4e5e32608ec6da3f2b81731aaeb7b038843vandebo@chromium.org#endif
67