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" 17 #include "SkPDFDevice.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 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 36 PdfRenderer(EncodeToDCTStream encoder) 37 : fPicture(NULL) 38 , fPDFDevice(NULL) 39 , fEncoder(encoder) 40 {} 41 42 void write(SkWStream* stream) const; 43 44 protected: 45 SkCanvas* setupCanvas(); 46 SkCanvas* setupCanvas(int width, int height); 47 48 SkAutoTUnref<SkCanvas> fCanvas; 49 SkPicture* fPicture; 50 SkPDFDevice* fPDFDevice; 51 EncodeToDCTStream fEncoder; 52 53 private: 54 typedef SkRefCnt INHERITED; 55 }; 56 57 class SimplePdfRenderer : public PdfRenderer { 58 public: 59 SimplePdfRenderer(EncodeToDCTStream encoder) 60 : PdfRenderer(encoder) {} 61 virtual void render() SK_OVERRIDE; 62 63 private: 64 typedef PdfRenderer INHERITED; 65 }; 66 67 } 68 69 #endif // PdfRenderer_DEFINED 70