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 | |
| 16 | #include "SkMath.h" |
edisonn@google.com | d9dfa18 | 2013-04-24 13:01:01 +0000 | [diff] [blame] | 17 | #include "SkPDFDevice.h" |
edisonn@google.com | 2a827e8 | 2012-10-10 15:20:34 +0000 | [diff] [blame] | 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; |
edisonn@google.com | 2a827e8 | 2012-10-10 15:20:34 +0000 | [diff] [blame] | 26 | |
| 27 | namespace sk_tools { |
| 28 | |
| 29 | class PdfRenderer : public SkRefCnt { |
| 30 | public: |
| 31 | virtual void init(SkPicture* pict); |
| 32 | virtual void setup() {} |
| 33 | virtual void render() = 0; |
| 34 | virtual void end(); |
| 35 | |
edisonn@google.com | d9dfa18 | 2013-04-24 13:01:01 +0000 | [diff] [blame] | 36 | PdfRenderer(EncodeToDCTStream encoder) |
edisonn@google.com | 2a827e8 | 2012-10-10 15:20:34 +0000 | [diff] [blame] | 37 | : fPicture(NULL) |
| 38 | , fPDFDevice(NULL) |
edisonn@google.com | d9dfa18 | 2013-04-24 13:01:01 +0000 | [diff] [blame] | 39 | , fEncoder(encoder) |
edisonn@google.com | 2a827e8 | 2012-10-10 15:20:34 +0000 | [diff] [blame] | 40 | {} |
| 41 | |
edisonn@google.com | 4fa566b | 2013-01-11 20:30:41 +0000 | [diff] [blame] | 42 | void write(SkWStream* stream) const; |
edisonn@google.com | 2a827e8 | 2012-10-10 15:20:34 +0000 | [diff] [blame] | 43 | |
| 44 | protected: |
| 45 | SkCanvas* setupCanvas(); |
| 46 | SkCanvas* setupCanvas(int width, int height); |
| 47 | |
| 48 | SkAutoTUnref<SkCanvas> fCanvas; |
| 49 | SkPicture* fPicture; |
| 50 | SkPDFDevice* fPDFDevice; |
edisonn@google.com | d9dfa18 | 2013-04-24 13:01:01 +0000 | [diff] [blame] | 51 | EncodeToDCTStream fEncoder; |
edisonn@google.com | 2a827e8 | 2012-10-10 15:20:34 +0000 | [diff] [blame] | 52 | |
| 53 | private: |
| 54 | typedef SkRefCnt INHERITED; |
| 55 | }; |
| 56 | |
| 57 | class SimplePdfRenderer : public PdfRenderer { |
| 58 | public: |
edisonn@google.com | d9dfa18 | 2013-04-24 13:01:01 +0000 | [diff] [blame] | 59 | SimplePdfRenderer(EncodeToDCTStream encoder) |
| 60 | : PdfRenderer(encoder) {} |
edisonn@google.com | 2a827e8 | 2012-10-10 15:20:34 +0000 | [diff] [blame] | 61 | virtual void render() SK_OVERRIDE; |
| 62 | |
| 63 | private: |
| 64 | typedef PdfRenderer INHERITED; |
| 65 | }; |
| 66 | |
| 67 | } |
| 68 | |
| 69 | #endif // PdfRenderer_DEFINED |