Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(229)

Unified Diff: src/doc/SkDocument_PDF.cpp

Issue 941023005: PDF : New factory function for SkPDFDevice (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: rebase on 07d5947 Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | src/pdf/SkPDFCanon.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/doc/SkDocument_PDF.cpp
diff --git a/src/doc/SkDocument_PDF.cpp b/src/doc/SkDocument_PDF.cpp
index 6d6bf6352662962612e5a5e6fe43858ba4059130..e73b88867f2cd0ac314232e5be30e0e3c0fe8c85 100644
--- a/src/doc/SkDocument_PDF.cpp
+++ b/src/doc/SkDocument_PDF.cpp
@@ -6,6 +6,7 @@
*/
#include "SkDocument.h"
+#include "SkPDFCanon.h"
#include "SkPDFDocument.h"
#include "SkPDFDevice.h"
@@ -16,8 +17,6 @@ public:
SkScalar rasterDpi)
: SkDocument(stream, doneProc)
, fDoc(SkNEW(SkPDFDocument))
- , fDevice(NULL)
- , fCanvas(NULL)
, fRasterDpi(rasterDpi) {}
virtual ~SkDocument_PDF() {
@@ -28,56 +27,50 @@ public:
protected:
virtual SkCanvas* onBeginPage(SkScalar width, SkScalar height,
const SkRect& trimBox) SK_OVERRIDE {
- SkASSERT(NULL == fCanvas);
- SkASSERT(NULL == fDevice);
+ SkASSERT(!fCanvas.get());
+ SkASSERT(!fDevice.get());
- SkISize mediaBoxSize;
- mediaBoxSize.set(SkScalarRoundToInt(width), SkScalarRoundToInt(height));
-
- fDevice = SkNEW_ARGS(SkPDFDevice, (mediaBoxSize, mediaBoxSize, SkMatrix::I()));
- if (fRasterDpi != 0) {
- fDevice->setRasterDpi(fRasterDpi);
- }
- fCanvas = SkNEW_ARGS(SkCanvas, (fDevice));
+ SkISize pageSize = SkISize::Make(
+ SkScalarRoundToInt(width), SkScalarRoundToInt(height));
+ fDevice.reset(SkPDFDevice::Create(pageSize, fRasterDpi, &fCanon));
+ fCanvas.reset(SkNEW_ARGS(SkCanvas, (fDevice)));
fCanvas->clipRect(trimBox);
fCanvas->translate(trimBox.x(), trimBox.y());
- return fCanvas;
+ return fCanvas.get();
}
void onEndPage() SK_OVERRIDE {
- SkASSERT(fCanvas);
- SkASSERT(fDevice);
+ SkASSERT(fCanvas.get());
+ SkASSERT(fDevice.get());
fCanvas->flush();
- fDoc->appendPage(fDevice);
-
- fCanvas->unref();
- fDevice->unref();
+ fDoc->appendPage(fDevice.get());
- fCanvas = NULL;
- fDevice = NULL;
+ fCanvas.reset(NULL);
+ fDevice.reset(NULL);
}
bool onClose(SkWStream* stream) SK_OVERRIDE {
- SkASSERT(NULL == fCanvas);
- SkASSERT(NULL == fDevice);
+ SkASSERT(!fCanvas.get());
+ SkASSERT(!fDevice.get());
bool success = fDoc->emitPDF(stream);
- SkDELETE(fDoc);
- fDoc = NULL;
+ fDoc.free();
+ SkDEBUGCODE(fCanon.assertEmpty());
return success;
}
void onAbort() SK_OVERRIDE {
- SkDELETE(fDoc);
- fDoc = NULL;
+ fDoc.free();
+ SkDEBUGCODE(fCanon.assertEmpty());
}
private:
- SkPDFDocument* fDoc;
- SkPDFDevice* fDevice;
- SkCanvas* fCanvas;
- SkScalar fRasterDpi;
+ SkPDFCanon fCanon;
+ SkAutoTDelete<SkPDFDocument> fDoc;
+ SkAutoTUnref<SkPDFDevice> fDevice;
+ SkAutoTUnref<SkCanvas> fCanvas;
+ SkScalar fRasterDpi;
};
///////////////////////////////////////////////////////////////////////////////
« no previous file with comments | « no previous file | src/pdf/SkPDFCanon.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698