Chromium Code Reviews| 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 "SkPDFDeviceFlattener.h" | 10 #include "SkPDFDevice.h" |
| 11 | 11 |
| 12 class SkDocument_PDF : public SkDocument { | 12 class SkDocument_PDF : public SkDocument { |
| 13 public: | 13 public: |
| 14 SkDocument_PDF(SkWStream* stream, void (*doneProc)(SkWStream*,bool), | 14 SkDocument_PDF(SkWStream* stream, void (*doneProc)(SkWStream*,bool), |
| 15 SkPicture::EncodeBitmap encoder, | 15 SkPicture::EncodeBitmap encoder, |
| 16 SkScalar rasterDpi) | 16 SkScalar rasterDpi) |
| 17 : SkDocument(stream, doneProc) | 17 : SkDocument(stream, doneProc) |
| 18 , fEncoder(encoder) | 18 , fEncoder(encoder) |
| 19 , fRasterDpi(rasterDpi) { | 19 , fRasterDpi(rasterDpi) { |
| 20 fDoc = SkNEW(SkPDFDocument); | 20 fDoc = SkNEW(SkPDFDocument); |
| 21 fCanvas = NULL; | 21 fCanvas = NULL; |
| 22 fDevice = NULL; | 22 fDevice = NULL; |
| 23 } | 23 } |
| 24 | 24 |
| 25 virtual ~SkDocument_PDF() { | 25 virtual ~SkDocument_PDF() { |
| 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 virtual SkCanvas* onBeginPage(SkScalar width, SkScalar height, | 31 virtual SkCanvas* onBeginPage(SkScalar width, SkScalar height, |
| 32 const SkRect& trimBox) SK_OVERRIDE { | 32 const SkRect& trimBox) SK_OVERRIDE { |
|
hal.canary
2014/11/02 00:45:29
You are dropping trimBox on the floor.
| |
| 33 SkASSERT(NULL == fCanvas); | 33 SkASSERT(NULL == fCanvas); |
| 34 SkASSERT(NULL == fDevice); | 34 SkASSERT(NULL == fDevice); |
| 35 | 35 |
| 36 SkSize mediaBoxSize; | 36 SkISize mediaBoxSize; |
| 37 mediaBoxSize.set(width, height); | 37 mediaBoxSize.set(SkScalarRoundToInt(width), SkScalarRoundToInt(height)); |
| 38 | 38 |
| 39 fDevice = SkNEW_ARGS(SkPDFDeviceFlattener, (mediaBoxSize, &trimBox)); | 39 fDevice = SkNEW_ARGS(SkPDFDevice, (mediaBoxSize, mediaBoxSize, SkMatrix: :I())); |
| 40 if (fEncoder) { | 40 if (fEncoder) { |
| 41 fDevice->setDCTEncoder(fEncoder); | 41 fDevice->setDCTEncoder(fEncoder); |
| 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 return fCanvas; | 47 return fCanvas; |
| 48 } | 48 } |
| 49 | 49 |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 71 return success; | 71 return success; |
| 72 } | 72 } |
| 73 | 73 |
| 74 virtual void onAbort() SK_OVERRIDE { | 74 virtual void onAbort() SK_OVERRIDE { |
| 75 SkDELETE(fDoc); | 75 SkDELETE(fDoc); |
| 76 fDoc = NULL; | 76 fDoc = NULL; |
| 77 } | 77 } |
| 78 | 78 |
| 79 private: | 79 private: |
| 80 SkPDFDocument* fDoc; | 80 SkPDFDocument* fDoc; |
| 81 SkPDFDeviceFlattener* fDevice; | 81 SkPDFDevice* fDevice; |
| 82 SkCanvas* fCanvas; | 82 SkCanvas* fCanvas; |
| 83 SkPicture::EncodeBitmap fEncoder; | 83 SkPicture::EncodeBitmap fEncoder; |
| 84 SkScalar fRasterDpi; | 84 SkScalar fRasterDpi; |
| 85 }; | 85 }; |
| 86 | 86 |
| 87 /////////////////////////////////////////////////////////////////////////////// | 87 /////////////////////////////////////////////////////////////////////////////// |
| 88 | 88 |
| 89 SkDocument* SkDocument::CreatePDF(SkWStream* stream, void (*done)(SkWStream*,boo l), | 89 SkDocument* SkDocument::CreatePDF(SkWStream* stream, void (*done)(SkWStream*,boo l), |
| 90 SkPicture::EncodeBitmap enc, | 90 SkPicture::EncodeBitmap enc, |
| 91 SkScalar dpi) { | 91 SkScalar dpi) { |
| 92 return stream ? SkNEW_ARGS(SkDocument_PDF, (stream, done, enc, dpi)) : NULL; | 92 return stream ? SkNEW_ARGS(SkDocument_PDF, (stream, done, enc, dpi)) : NULL; |
| 93 } | 93 } |
| 94 | 94 |
| 95 static void delete_wstream(SkWStream* stream, bool aborted) { | 95 static void delete_wstream(SkWStream* stream, bool aborted) { |
| 96 SkDELETE(stream); | 96 SkDELETE(stream); |
| 97 } | 97 } |
| 98 | 98 |
| 99 SkDocument* SkDocument::CreatePDF(const char path[], | 99 SkDocument* SkDocument::CreatePDF(const char path[], |
| 100 SkPicture::EncodeBitmap enc, | 100 SkPicture::EncodeBitmap enc, |
| 101 SkScalar dpi) { | 101 SkScalar dpi) { |
| 102 SkFILEWStream* stream = SkNEW_ARGS(SkFILEWStream, (path)); | 102 SkFILEWStream* stream = SkNEW_ARGS(SkFILEWStream, (path)); |
| 103 if (!stream->isValid()) { | 103 if (!stream->isValid()) { |
| 104 SkDELETE(stream); | 104 SkDELETE(stream); |
| 105 return NULL; | 105 return NULL; |
| 106 } | 106 } |
| 107 return SkNEW_ARGS(SkDocument_PDF, (stream, delete_wstream, enc, dpi)); | 107 return SkNEW_ARGS(SkDocument_PDF, (stream, delete_wstream, enc, dpi)); |
| 108 } | 108 } |
| OLD | NEW |