edisonn@google.com | 2a827e8 | 2012-10-10 15:20:34 +0000 | [diff] [blame] | 1 | /* |
| 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.org | 5e00989 | 2013-10-14 13:42:12 +0000 | [diff] [blame] | 16 | #include "SkDocument.h" |
edisonn@google.com | 2a827e8 | 2012-10-10 15:20:34 +0000 | [diff] [blame] | 17 | #include "SkMath.h" |
| 18 | #include "SkPicture.h" |
| 19 | #include "SkTypes.h" |
| 20 | #include "SkTDArray.h" |
| 21 | #include "SkRefCnt.h" |
| 22 | #include "SkString.h" |
| 23 | |
| 24 | class SkBitmap; |
| 25 | class SkCanvas; |
commit-bot@chromium.org | 5e00989 | 2013-10-14 13:42:12 +0000 | [diff] [blame] | 26 | class SkWStream; |
edisonn@google.com | 2a827e8 | 2012-10-10 15:20:34 +0000 | [diff] [blame] | 27 | |
| 28 | namespace sk_tools { |
| 29 | |
| 30 | class PdfRenderer : public SkRefCnt { |
| 31 | public: |
commit-bot@chromium.org | 5e00989 | 2013-10-14 13:42:12 +0000 | [diff] [blame] | 32 | virtual void init(SkPicture* pict, SkWStream* stream); |
edisonn@google.com | 2a827e8 | 2012-10-10 15:20:34 +0000 | [diff] [blame] | 33 | virtual void setup() {} |
commit-bot@chromium.org | 5e00989 | 2013-10-14 13:42:12 +0000 | [diff] [blame] | 34 | virtual bool render() = 0; |
edisonn@google.com | 2a827e8 | 2012-10-10 15:20:34 +0000 | [diff] [blame] | 35 | virtual void end(); |
| 36 | |
commit-bot@chromium.org | 608ea65 | 2013-10-03 19:29:21 +0000 | [diff] [blame] | 37 | PdfRenderer(SkPicture::EncodeBitmap encoder) |
edisonn@google.com | 2a827e8 | 2012-10-10 15:20:34 +0000 | [diff] [blame] | 38 | : fPicture(NULL) |
edisonn@google.com | d9dfa18 | 2013-04-24 13:01:01 +0000 | [diff] [blame] | 39 | , fEncoder(encoder) |
commit-bot@chromium.org | 5e00989 | 2013-10-14 13:42:12 +0000 | [diff] [blame] | 40 | , fPdfDoc(NULL) |
edisonn@google.com | 2a827e8 | 2012-10-10 15:20:34 +0000 | [diff] [blame] | 41 | {} |
| 42 | |
edisonn@google.com | 2a827e8 | 2012-10-10 15:20:34 +0000 | [diff] [blame] | 43 | protected: |
commit-bot@chromium.org | 5e00989 | 2013-10-14 13:42:12 +0000 | [diff] [blame] | 44 | SkCanvas* setupCanvas(SkWStream* stream, int width, int height); |
edisonn@google.com | 2a827e8 | 2012-10-10 15:20:34 +0000 | [diff] [blame] | 45 | |
| 46 | SkAutoTUnref<SkCanvas> fCanvas; |
| 47 | SkPicture* fPicture; |
commit-bot@chromium.org | 608ea65 | 2013-10-03 19:29:21 +0000 | [diff] [blame] | 48 | SkPicture::EncodeBitmap fEncoder; |
commit-bot@chromium.org | 5e00989 | 2013-10-14 13:42:12 +0000 | [diff] [blame] | 49 | SkAutoTUnref<SkDocument> fPdfDoc; |
edisonn@google.com | 2a827e8 | 2012-10-10 15:20:34 +0000 | [diff] [blame] | 50 | |
| 51 | private: |
| 52 | typedef SkRefCnt INHERITED; |
| 53 | }; |
| 54 | |
| 55 | class SimplePdfRenderer : public PdfRenderer { |
| 56 | public: |
commit-bot@chromium.org | 608ea65 | 2013-10-03 19:29:21 +0000 | [diff] [blame] | 57 | SimplePdfRenderer(SkPicture::EncodeBitmap encoder) |
edisonn@google.com | d9dfa18 | 2013-04-24 13:01:01 +0000 | [diff] [blame] | 58 | : PdfRenderer(encoder) {} |
commit-bot@chromium.org | 5e00989 | 2013-10-14 13:42:12 +0000 | [diff] [blame] | 59 | virtual bool render() SK_OVERRIDE; |
edisonn@google.com | 2a827e8 | 2012-10-10 15:20:34 +0000 | [diff] [blame] | 60 | |
| 61 | private: |
| 62 | typedef PdfRenderer INHERITED; |
| 63 | }; |
| 64 | |
| 65 | } |
| 66 | |
| 67 | #endif // PdfRenderer_DEFINED |