blob: d70c458c74877918f777b7412b958386ff3f8cbd [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
commit-bot@chromium.org5e009892013-10-14 13:42:12 +000016#include "SkDocument.h"
edisonn@google.com2a827e82012-10-10 15:20:34 +000017#include "SkMath.h"
18#include "SkPicture.h"
19#include "SkTypes.h"
20#include "SkTDArray.h"
21#include "SkRefCnt.h"
22#include "SkString.h"
23
24class SkBitmap;
25class SkCanvas;
commit-bot@chromium.org5e009892013-10-14 13:42:12 +000026class SkWStream;
edisonn@google.com2a827e82012-10-10 15:20:34 +000027
28namespace sk_tools {
29
30class PdfRenderer : public SkRefCnt {
31public:
commit-bot@chromium.org5e009892013-10-14 13:42:12 +000032 virtual void init(SkPicture* pict, SkWStream* stream);
edisonn@google.com2a827e82012-10-10 15:20:34 +000033 virtual void setup() {}
commit-bot@chromium.org5e009892013-10-14 13:42:12 +000034 virtual bool render() = 0;
edisonn@google.com2a827e82012-10-10 15:20:34 +000035 virtual void end();
36
commit-bot@chromium.org608ea652013-10-03 19:29:21 +000037 PdfRenderer(SkPicture::EncodeBitmap encoder)
edisonn@google.com2a827e82012-10-10 15:20:34 +000038 : fPicture(NULL)
edisonn@google.comd9dfa182013-04-24 13:01:01 +000039 , fEncoder(encoder)
commit-bot@chromium.org5e009892013-10-14 13:42:12 +000040 , fPdfDoc(NULL)
edisonn@google.com2a827e82012-10-10 15:20:34 +000041 {}
42
edisonn@google.com2a827e82012-10-10 15:20:34 +000043protected:
commit-bot@chromium.org5e009892013-10-14 13:42:12 +000044 SkCanvas* setupCanvas(SkWStream* stream, int width, int height);
edisonn@google.com2a827e82012-10-10 15:20:34 +000045
46 SkAutoTUnref<SkCanvas> fCanvas;
47 SkPicture* fPicture;
commit-bot@chromium.org608ea652013-10-03 19:29:21 +000048 SkPicture::EncodeBitmap fEncoder;
commit-bot@chromium.org5e009892013-10-14 13:42:12 +000049 SkAutoTUnref<SkDocument> fPdfDoc;
edisonn@google.com2a827e82012-10-10 15:20:34 +000050
51private:
52 typedef SkRefCnt INHERITED;
53};
54
55class SimplePdfRenderer : public PdfRenderer {
56public:
commit-bot@chromium.org608ea652013-10-03 19:29:21 +000057 SimplePdfRenderer(SkPicture::EncodeBitmap encoder)
edisonn@google.comd9dfa182013-04-24 13:01:01 +000058 : PdfRenderer(encoder) {}
commit-bot@chromium.org5e009892013-10-14 13:42:12 +000059 virtual bool render() SK_OVERRIDE;
edisonn@google.com2a827e82012-10-10 15:20:34 +000060
61private:
62 typedef PdfRenderer INHERITED;
63};
64
65}
66
67#endif // PdfRenderer_DEFINED