aboutsummaryrefslogtreecommitdiffhomepage
path: root/tools/PdfRenderer.h
blob: d2d1a5c67c3403b24d97a4deb4b6aef64b5b7036 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
/*
 * Copyright 2012 Google Inc.
 *
 * Use of this source code is governed by a BSD-style license that can be
 * found in the LICENSE file.
 */

#ifndef PdfRenderer_DEFINED
#define PdfRenderer_DEFINED

//
// PdfRender takes a SkPicture and writes it to a PDF file.
// An SkPicture can be built manually, or read from an SKP file.
//

#include "SkMath.h"
#include "SkPDFDevice.h"
#include "SkPicture.h"
#include "SkTypes.h"
#include "SkTDArray.h"
#include "SkRefCnt.h"
#include "SkString.h"

class SkBitmap;
class SkCanvas;

namespace sk_tools {

class PdfRenderer : public SkRefCnt {
public:
    virtual void init(SkPicture* pict);
    virtual void setup() {}
    virtual void render() = 0;
    virtual void end();

    PdfRenderer(EncodeToDCTStream encoder)
        : fPicture(NULL)
        , fPDFDevice(NULL)
        , fEncoder(encoder)
        {}

    void write(SkWStream* stream) const;

protected:
    SkCanvas* setupCanvas();
    SkCanvas* setupCanvas(int width, int height);

    SkAutoTUnref<SkCanvas> fCanvas;
    SkPicture* fPicture;
    SkPDFDevice* fPDFDevice;
    EncodeToDCTStream fEncoder;

private:
    typedef SkRefCnt INHERITED;
};

class SimplePdfRenderer : public PdfRenderer {
public:
    SimplePdfRenderer(EncodeToDCTStream encoder)
        : PdfRenderer(encoder) {}
    virtual void render() SK_OVERRIDE;

private:
    typedef PdfRenderer INHERITED;
};

}

#endif  // PdfRenderer_DEFINED