Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 /* | |
| 2 * Copyright 2013 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 #include "SkDocument.h" | |
| 9 #include "SkPDFDocument.h" | |
| 10 #include "SkPDFDevice.h" | |
| 11 | |
| 12 class SkDocument_PDF : public SkDocument { | |
| 13 public: | |
| 14 SkDocument_PDF(SkWStream* stream) : SkDocument(stream) { | |
| 15 fDoc = new SkPDFDocument; | |
|
scroggo
2013/06/07 19:35:23
SkNEW
reed1
2013/06/07 19:50:40
Done.
| |
| 16 fCanvas = NULL; | |
| 17 fDevice = NULL; | |
| 18 } | |
| 19 | |
| 20 virtual ~SkDocument_PDF() { | |
| 21 this->close(); | |
| 22 delete fDoc; | |
|
scroggo
2013/06/07 19:35:23
SkDELETE
reed1
2013/06/07 19:50:40
Done.
| |
| 23 } | |
| 24 | |
| 25 protected: | |
| 26 virtual SkCanvas* onBeginPage(SkScalar width, SkScalar height, | |
| 27 const SkRect& content) SK_OVERRIDE { | |
| 28 SkISize pageS, contentS; | |
| 29 SkMatrix matrix; | |
| 30 | |
| 31 pageS.set(SkScalarRoundToInt(width), SkScalarRoundToInt(height)); | |
| 32 contentS.set(SkScalarRoundToInt(content.width()), | |
| 33 SkScalarRoundToInt(content.height())); | |
| 34 matrix.setTranslate(content.fLeft, content.fTop); | |
| 35 | |
| 36 fDevice = new SkPDFDevice(pageS, contentS, matrix); | |
|
scroggo
2013/06/07 19:35:23
SkNEW_ARGS
reed1
2013/06/07 19:50:40
Done.
| |
| 37 fCanvas = new SkCanvas(fDevice); | |
| 38 return fCanvas; | |
| 39 } | |
| 40 | |
| 41 virtual void onEndPage() SK_OVERRIDE { | |
| 42 if (fCanvas) { | |
| 43 fCanvas->flush(); | |
| 44 fDoc->appendPage(fDevice); | |
| 45 | |
| 46 fCanvas->unref(); | |
| 47 fDevice->unref(); | |
| 48 | |
| 49 fCanvas = NULL; | |
| 50 fDevice = NULL; | |
| 51 } | |
| 52 } | |
| 53 | |
| 54 virtual void onClose(SkWStream* stream) SK_OVERRIDE { | |
| 55 fDoc->emitPDF(stream); | |
| 56 | |
| 57 delete fDoc; | |
| 58 SkSafeUnref(fCanvas); | |
|
scroggo
2013/06/07 19:35:23
Is there a way for fCanvas and fDevice to be non N
reed1
2013/06/07 19:50:40
Agreed. Simplified.
| |
| 59 SkSafeUnref(fDevice); | |
| 60 | |
| 61 fDoc = NULL; | |
| 62 fCanvas = NULL; | |
| 63 fDevice = NULL; | |
| 64 } | |
| 65 | |
| 66 private: | |
| 67 SkPDFDocument* fDoc; | |
| 68 SkPDFDevice* fDevice; | |
| 69 SkCanvas* fCanvas; | |
| 70 }; | |
| 71 | |
| 72 /////////////////////////////////////////////////////////////////////////////// | |
| 73 | |
| 74 SkDocument* SkDocument::CreatePDF(SkWStream* stream) { | |
| 75 return stream ? SkNEW_ARGS(SkDocument_PDF, (stream)) : NULL; | |
| 76 } | |
| 77 | |
| 78 SkDocument* SkDocument::CreatePDF(const char path[]) { | |
| 79 SkFILEWStream* stream = SkNEW_ARGS(SkFILEWStream, (path)); | |
| 80 if (!stream->isValid()) { | |
| 81 SkDELETE(stream); | |
| 82 return NULL; | |
| 83 } | |
| 84 return SkNEW_ARGS(SkDocument_PDF, (stream)); | |
| 85 } | |
| 86 | |
| OLD | NEW |