| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2015 Google Inc. | 2 * Copyright 2015 Google Inc. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
| 6 */ | 6 */ |
| 7 | 7 |
| 8 #include "SkDocument.h" | 8 #include "SkDocument.h" |
| 9 #include "SkXPSDevice.h" | 9 #include "SkXPSDevice.h" |
| 10 #include "SkStream.h" | 10 #include "SkStream.h" |
| (...skipping 15 matching lines...) Expand all Loading... |
| 26 // subclasses must call close() in their destructors | 26 // subclasses must call close() in their destructors |
| 27 this->close(); | 27 this->close(); |
| 28 } | 28 } |
| 29 | 29 |
| 30 protected: | 30 protected: |
| 31 SkCanvas* onBeginPage(SkScalar width, | 31 SkCanvas* onBeginPage(SkScalar width, |
| 32 SkScalar height, | 32 SkScalar height, |
| 33 const SkRect& trimBox) override { | 33 const SkRect& trimBox) override { |
| 34 fDevice.beginSheet(fUnitsPerMeter, fPixelsPerMeter, | 34 fDevice.beginSheet(fUnitsPerMeter, fPixelsPerMeter, |
| 35 SkSize::Make(width, height)); | 35 SkSize::Make(width, height)); |
| 36 fCanvas.reset(SkNEW_ARGS(SkCanvas, (&fDevice))); | 36 fCanvas.reset(new SkCanvas(&fDevice)); |
| 37 fCanvas->clipRect(trimBox); | 37 fCanvas->clipRect(trimBox); |
| 38 fCanvas->translate(trimBox.x(), trimBox.y()); | 38 fCanvas->translate(trimBox.x(), trimBox.y()); |
| 39 return fCanvas.get(); | 39 return fCanvas.get(); |
| 40 } | 40 } |
| 41 | 41 |
| 42 void onEndPage() override { | 42 void onEndPage() override { |
| 43 SkASSERT(fCanvas.get()); | 43 SkASSERT(fCanvas.get()); |
| 44 fCanvas->flush(); | 44 fCanvas->flush(); |
| 45 fCanvas.reset(NULL); | 45 fCanvas.reset(NULL); |
| 46 fDevice.endSheet(); | 46 fDevice.endSheet(); |
| 47 } | 47 } |
| 48 | 48 |
| 49 bool onClose(SkWStream*) override { | 49 bool onClose(SkWStream*) override { |
| 50 SkASSERT(!fCanvas.get()); | 50 SkASSERT(!fCanvas.get()); |
| 51 return fDevice.endPortfolio(); | 51 return fDevice.endPortfolio(); |
| 52 } | 52 } |
| 53 | 53 |
| 54 void onAbort() override {} | 54 void onAbort() override {} |
| 55 | 55 |
| 56 private: | 56 private: |
| 57 SkXPSDevice fDevice; | 57 SkXPSDevice fDevice; |
| 58 SkAutoTUnref<SkCanvas> fCanvas; | 58 SkAutoTUnref<SkCanvas> fCanvas; |
| 59 SkVector fUnitsPerMeter; | 59 SkVector fUnitsPerMeter; |
| 60 SkVector fPixelsPerMeter; | 60 SkVector fPixelsPerMeter; |
| 61 }; | 61 }; |
| 62 | 62 |
| 63 /////////////////////////////////////////////////////////////////////////////// | 63 /////////////////////////////////////////////////////////////////////////////// |
| 64 | 64 |
| 65 SkDocument* SkDocument::CreateXPS(SkWStream* stream, SkScalar dpi) { | 65 SkDocument* SkDocument::CreateXPS(SkWStream* stream, SkScalar dpi) { |
| 66 return stream ? SkNEW_ARGS(SkDocument_XPS, (stream, NULL, dpi)) : NULL; | 66 return stream ? new SkDocument_XPS(stream, NULL, dpi) : NULL; |
| 67 } | 67 } |
| 68 | 68 |
| 69 static void delete_wstream(SkWStream* stream, bool aborted) { | 69 static void delete_wstream(SkWStream* stream, bool aborted) { delete stream; } |
| 70 SkDELETE(stream); | |
| 71 } | |
| 72 | 70 |
| 73 SkDocument* SkDocument::CreateXPS(const char path[], SkScalar dpi) { | 71 SkDocument* SkDocument::CreateXPS(const char path[], SkScalar dpi) { |
| 74 SkAutoTDelete<SkFILEWStream> stream(SkNEW_ARGS(SkFILEWStream, (path))); | 72 SkAutoTDelete<SkFILEWStream> stream(new SkFILEWStream(path)); |
| 75 if (!stream->isValid()) { | 73 if (!stream->isValid()) { |
| 76 return NULL; | 74 return NULL; |
| 77 } | 75 } |
| 78 return SkNEW_ARGS(SkDocument_XPS, (stream.detach(), delete_wstream, dpi)); | 76 return new SkDocument_XPS(stream.detach(), delete_wstream, dpi); |
| 79 } | 77 } |
| OLD | NEW |