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 "SkDocument.h" 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; 26 class SkWStream; 27 28 namespace sk_tools { 29 30 class PdfRenderer : public SkRefCnt { 31 public: 32 virtual void init(SkPicture* pict, SkWStream* stream); setup()33 virtual void setup() {} 34 virtual bool render() = 0; 35 virtual void end(); 36 PdfRenderer(SkPicture::EncodeBitmap encoder)37 PdfRenderer(SkPicture::EncodeBitmap encoder) 38 : fPicture(NULL) 39 , fEncoder(encoder) 40 , fPdfDoc(NULL) 41 {} 42 43 protected: 44 SkCanvas* setupCanvas(SkWStream* stream, int width, int height); 45 46 SkAutoTUnref<SkCanvas> fCanvas; 47 SkPicture* fPicture; 48 SkPicture::EncodeBitmap fEncoder; 49 SkAutoTUnref<SkDocument> fPdfDoc; 50 51 private: 52 typedef SkRefCnt INHERITED; 53 }; 54 55 class SimplePdfRenderer : public PdfRenderer { 56 public: SimplePdfRenderer(SkPicture::EncodeBitmap encoder)57 SimplePdfRenderer(SkPicture::EncodeBitmap encoder) 58 : PdfRenderer(encoder) {} 59 virtual bool render() SK_OVERRIDE; 60 61 private: 62 typedef PdfRenderer INHERITED; 63 }; 64 65 } 66 67 #endif // PdfRenderer_DEFINED 68