Index: src/doc/SkDocument_PDF.cpp |
diff --git a/src/doc/SkDocument_PDF.cpp b/src/doc/SkDocument_PDF.cpp |
index 27cf2e88c53241d20b56ce3c79b9166580909bc6..b9b55f8dce688cefa8f1e555200d5a8a93f36f79 100644 |
--- a/src/doc/SkDocument_PDF.cpp |
+++ b/src/doc/SkDocument_PDF.cpp |
@@ -6,13 +6,15 @@ |
*/ |
#include "SkDocument.h" |
-#include "SkPDFDocument.h" |
#include "SkPDFDevice.h" |
+#include "SkPDFDocument.h" |
class SkDocument_PDF : public SkDocument { |
public: |
- SkDocument_PDF(SkWStream* stream, void (*doneProc)(SkWStream*)) |
- : SkDocument(stream, doneProc) { |
+ SkDocument_PDF(SkWStream* stream, void (*doneProc)(SkWStream*), |
+ SkPicture::EncodeBitmap encoder) |
+ : SkDocument(stream, doneProc) |
+ , fEncoder(encoder) { |
fDoc = SkNEW(SkPDFDocument); |
fCanvas = NULL; |
fDevice = NULL; |
@@ -38,6 +40,9 @@ protected: |
matrix.setTranslate(content.fLeft, content.fTop); |
fDevice = SkNEW_ARGS(SkPDFDevice, (pageS, contentS, matrix)); |
+ if (fEncoder) { |
+ fDevice->setDCTEncoder(fEncoder); |
+ } |
fCanvas = SkNEW_ARGS(SkCanvas, (fDevice)); |
return fCanvas; |
} |
@@ -56,36 +61,44 @@ protected: |
fDevice = NULL; |
} |
- virtual void onClose(SkWStream* stream) SK_OVERRIDE { |
+ virtual bool onClose(SkWStream* stream) SK_OVERRIDE { |
SkASSERT(NULL == fCanvas); |
SkASSERT(NULL == fDevice); |
- fDoc->emitPDF(stream); |
+ bool success = fDoc->emitPDF(stream); |
+ SkDELETE(fDoc); |
+ fDoc = NULL; |
+ return success; |
+ } |
+ |
+ virtual void onAbort() SK_OVERRIDE { |
SkDELETE(fDoc); |
fDoc = NULL; |
} |
private: |
SkPDFDocument* fDoc; |
- SkPDFDevice* fDevice; |
+ SkPDFDevice* fDevice; |
SkCanvas* fCanvas; |
+ SkPicture::EncodeBitmap fEncoder; |
}; |
/////////////////////////////////////////////////////////////////////////////// |
-SkDocument* SkDocument::CreatePDF(SkWStream* stream, void (*done)(SkWStream*)) { |
- return stream ? SkNEW_ARGS(SkDocument_PDF, (stream, done)) : NULL; |
+SkDocument* SkDocument::CreatePDF(SkWStream* stream, void (*done)(SkWStream*), |
+ SkPicture::EncodeBitmap enc) { |
+ return stream ? SkNEW_ARGS(SkDocument_PDF, (stream, done, enc)) : NULL; |
} |
static void delete_wstream(SkWStream* stream) { |
SkDELETE(stream); |
} |
-SkDocument* SkDocument::CreatePDF(const char path[]) { |
+SkDocument* SkDocument::CreatePDF(const char path[], SkPicture::EncodeBitmap enc) { |
SkFILEWStream* stream = SkNEW_ARGS(SkFILEWStream, (path)); |
if (!stream->isValid()) { |
SkDELETE(stream); |
return NULL; |
} |
- return SkNEW_ARGS(SkDocument_PDF, (stream, delete_wstream)); |
+ return SkNEW_ARGS(SkDocument_PDF, (stream, delete_wstream, enc)); |
} |