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 "SkPDFDocument.h" | 9 #include "SkPDFDocument.h" |
10 #include "SkPDFDevice.h" | 10 #include "SkPDFDevice.h" |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
42 } | 42 } |
43 if (fRasterDpi != 0) { | 43 if (fRasterDpi != 0) { |
44 fDevice->setRasterDpi(fRasterDpi); | 44 fDevice->setRasterDpi(fRasterDpi); |
45 } | 45 } |
46 fCanvas = SkNEW_ARGS(SkCanvas, (fDevice)); | 46 fCanvas = SkNEW_ARGS(SkCanvas, (fDevice)); |
47 fCanvas->clipRect(trimBox); | 47 fCanvas->clipRect(trimBox); |
48 fCanvas->translate(trimBox.x(), trimBox.y()); | 48 fCanvas->translate(trimBox.x(), trimBox.y()); |
49 return fCanvas; | 49 return fCanvas; |
50 } | 50 } |
51 | 51 |
52 virtual void onEndPage() SK_OVERRIDE { | 52 void onEndPage() SK_OVERRIDE { |
53 SkASSERT(fCanvas); | 53 SkASSERT(fCanvas); |
54 SkASSERT(fDevice); | 54 SkASSERT(fDevice); |
55 | 55 |
56 fCanvas->flush(); | 56 fCanvas->flush(); |
57 fDoc->appendPage(fDevice); | 57 fDoc->appendPage(fDevice); |
58 | 58 |
59 fCanvas->unref(); | 59 fCanvas->unref(); |
60 fDevice->unref(); | 60 fDevice->unref(); |
61 | 61 |
62 fCanvas = NULL; | 62 fCanvas = NULL; |
63 fDevice = NULL; | 63 fDevice = NULL; |
64 } | 64 } |
65 | 65 |
66 virtual bool onClose(SkWStream* stream) SK_OVERRIDE { | 66 bool onClose(SkWStream* stream) SK_OVERRIDE { |
67 SkASSERT(NULL == fCanvas); | 67 SkASSERT(NULL == fCanvas); |
68 SkASSERT(NULL == fDevice); | 68 SkASSERT(NULL == fDevice); |
69 | 69 |
70 bool success = fDoc->emitPDF(stream); | 70 bool success = fDoc->emitPDF(stream); |
71 SkDELETE(fDoc); | 71 SkDELETE(fDoc); |
72 fDoc = NULL; | 72 fDoc = NULL; |
73 return success; | 73 return success; |
74 } | 74 } |
75 | 75 |
76 virtual void onAbort() SK_OVERRIDE { | 76 void onAbort() SK_OVERRIDE { |
77 SkDELETE(fDoc); | 77 SkDELETE(fDoc); |
78 fDoc = NULL; | 78 fDoc = NULL; |
79 } | 79 } |
80 | 80 |
81 private: | 81 private: |
82 SkPDFDocument* fDoc; | 82 SkPDFDocument* fDoc; |
83 SkPDFDevice* fDevice; | 83 SkPDFDevice* fDevice; |
84 SkCanvas* fCanvas; | 84 SkCanvas* fCanvas; |
85 SkPicture::EncodeBitmap fEncoder; | 85 SkPicture::EncodeBitmap fEncoder; |
86 SkScalar fRasterDpi; | 86 SkScalar fRasterDpi; |
(...skipping 14 matching lines...) Expand all Loading... |
101 SkDocument* SkDocument::CreatePDF(const char path[], | 101 SkDocument* SkDocument::CreatePDF(const char path[], |
102 SkPicture::EncodeBitmap enc, | 102 SkPicture::EncodeBitmap enc, |
103 SkScalar dpi) { | 103 SkScalar dpi) { |
104 SkFILEWStream* stream = SkNEW_ARGS(SkFILEWStream, (path)); | 104 SkFILEWStream* stream = SkNEW_ARGS(SkFILEWStream, (path)); |
105 if (!stream->isValid()) { | 105 if (!stream->isValid()) { |
106 SkDELETE(stream); | 106 SkDELETE(stream); |
107 return NULL; | 107 return NULL; |
108 } | 108 } |
109 return SkNEW_ARGS(SkDocument_PDF, (stream, delete_wstream, enc, dpi)); | 109 return SkNEW_ARGS(SkDocument_PDF, (stream, delete_wstream, enc, dpi)); |
110 } | 110 } |
OLD | NEW |