blob: d2d1a5c67c3403b24d97a4deb4b6aef64b5b7036 [file] [log] [blame]
edisonn@google.com2a827e82012-10-10 15:20:34 +00001/*
2 * Copyright 2012 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8#ifndef PdfRenderer_DEFINED
9#define PdfRenderer_DEFINED
10
11//
12// PdfRender takes a SkPicture and writes it to a PDF file.
13// An SkPicture can be built manually, or read from an SKP file.
14//
15
16#include "SkMath.h"
edisonn@google.comd9dfa182013-04-24 13:01:01 +000017#include "SkPDFDevice.h"
edisonn@google.com2a827e82012-10-10 15:20:34 +000018#include "SkPicture.h"
19#include "SkTypes.h"
20#include "SkTDArray.h"
21#include "SkRefCnt.h"
22#include "SkString.h"
23
24class SkBitmap;
25class SkCanvas;
edisonn@google.com2a827e82012-10-10 15:20:34 +000026
27namespace sk_tools {
28
29class PdfRenderer : public SkRefCnt {
30public:
31 virtual void init(SkPicture* pict);
32 virtual void setup() {}
33 virtual void render() = 0;
34 virtual void end();
35
edisonn@google.comd9dfa182013-04-24 13:01:01 +000036 PdfRenderer(EncodeToDCTStream encoder)
edisonn@google.com2a827e82012-10-10 15:20:34 +000037 : fPicture(NULL)
38 , fPDFDevice(NULL)
edisonn@google.comd9dfa182013-04-24 13:01:01 +000039 , fEncoder(encoder)
edisonn@google.com2a827e82012-10-10 15:20:34 +000040 {}
41
edisonn@google.com4fa566b2013-01-11 20:30:41 +000042 void write(SkWStream* stream) const;
edisonn@google.com2a827e82012-10-10 15:20:34 +000043
44protected:
45 SkCanvas* setupCanvas();
46 SkCanvas* setupCanvas(int width, int height);
47
48 SkAutoTUnref<SkCanvas> fCanvas;
49 SkPicture* fPicture;
50 SkPDFDevice* fPDFDevice;
edisonn@google.comd9dfa182013-04-24 13:01:01 +000051 EncodeToDCTStream fEncoder;
edisonn@google.com2a827e82012-10-10 15:20:34 +000052
53private:
54 typedef SkRefCnt INHERITED;
55};
56
57class SimplePdfRenderer : public PdfRenderer {
58public:
edisonn@google.comd9dfa182013-04-24 13:01:01 +000059 SimplePdfRenderer(EncodeToDCTStream encoder)
60 : PdfRenderer(encoder) {}
edisonn@google.com2a827e82012-10-10 15:20:34 +000061 virtual void render() SK_OVERRIDE;
62
63private:
64 typedef PdfRenderer INHERITED;
65};
66
67}
68
69#endif // PdfRenderer_DEFINED