| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2013 Google Inc. | 2 * Copyright 2013 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 "SkPDFCanon.h" | 9 #include "SkPDFCanon.h" |
| 10 #include "SkPDFDocument.h" | 10 #include "SkPDFDocument.h" |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 49 fCanvas.reset(NULL); | 49 fCanvas.reset(NULL); |
| 50 fDevice.reset(NULL); | 50 fDevice.reset(NULL); |
| 51 } | 51 } |
| 52 | 52 |
| 53 bool onClose(SkWStream* stream) SK_OVERRIDE { | 53 bool onClose(SkWStream* stream) SK_OVERRIDE { |
| 54 SkASSERT(!fCanvas.get()); | 54 SkASSERT(!fCanvas.get()); |
| 55 SkASSERT(!fDevice.get()); | 55 SkASSERT(!fDevice.get()); |
| 56 | 56 |
| 57 bool success = fDoc->emitPDF(stream); | 57 bool success = fDoc->emitPDF(stream); |
| 58 fDoc.free(); | 58 fDoc.free(); |
| 59 SkDEBUGCODE(fCanon.assertEmpty()); | 59 fCanon.reset(); |
| 60 return success; | 60 return success; |
| 61 } | 61 } |
| 62 | 62 |
| 63 void onAbort() SK_OVERRIDE { | 63 void onAbort() SK_OVERRIDE { |
| 64 fDoc.free(); | 64 fDoc.free(); |
| 65 SkDEBUGCODE(fCanon.assertEmpty()); | 65 fCanon.reset(); |
| 66 } | 66 } |
| 67 | 67 |
| 68 private: | 68 private: |
| 69 SkPDFCanon fCanon; | 69 SkPDFCanon fCanon; |
| 70 SkAutoTDelete<SkPDFDocument> fDoc; | 70 SkAutoTDelete<SkPDFDocument> fDoc; |
| 71 SkAutoTUnref<SkPDFDevice> fDevice; | 71 SkAutoTUnref<SkPDFDevice> fDevice; |
| 72 SkAutoTUnref<SkCanvas> fCanvas; | 72 SkAutoTUnref<SkCanvas> fCanvas; |
| 73 SkScalar fRasterDpi; | 73 SkScalar fRasterDpi; |
| 74 }; | 74 }; |
| 75 | 75 |
| 76 /////////////////////////////////////////////////////////////////////////////// | 76 /////////////////////////////////////////////////////////////////////////////// |
| 77 | 77 |
| 78 SkDocument* SkDocument::CreatePDF(SkWStream* stream, SkScalar dpi) { | 78 SkDocument* SkDocument::CreatePDF(SkWStream* stream, SkScalar dpi) { |
| 79 return stream ? SkNEW_ARGS(SkDocument_PDF, (stream, NULL, dpi)) : NULL; | 79 return stream ? SkNEW_ARGS(SkDocument_PDF, (stream, NULL, dpi)) : NULL; |
| 80 } | 80 } |
| 81 | 81 |
| 82 static void delete_wstream(SkWStream* stream, bool aborted) { | 82 static void delete_wstream(SkWStream* stream, bool aborted) { |
| 83 SkDELETE(stream); | 83 SkDELETE(stream); |
| 84 } | 84 } |
| 85 | 85 |
| 86 SkDocument* SkDocument::CreatePDF(const char path[], SkScalar dpi) { | 86 SkDocument* SkDocument::CreatePDF(const char path[], SkScalar dpi) { |
| 87 SkFILEWStream* stream = SkNEW_ARGS(SkFILEWStream, (path)); | 87 SkFILEWStream* stream = SkNEW_ARGS(SkFILEWStream, (path)); |
| 88 if (!stream->isValid()) { | 88 if (!stream->isValid()) { |
| 89 SkDELETE(stream); | 89 SkDELETE(stream); |
| 90 return NULL; | 90 return NULL; |
| 91 } | 91 } |
| 92 return SkNEW_ARGS(SkDocument_PDF, (stream, delete_wstream, dpi)); | 92 return SkNEW_ARGS(SkDocument_PDF, (stream, delete_wstream, dpi)); |
| 93 } | 93 } |
| OLD | NEW |