Index: src/doc/SkDocument_PDF.cpp |
diff --git a/src/doc/SkDocument_PDF.cpp b/src/doc/SkDocument_PDF.cpp |
new file mode 100644 |
index 0000000000000000000000000000000000000000..85e318d2ac86a06a1829e5011e9f987ea3e1b6ac |
--- /dev/null |
+++ b/src/doc/SkDocument_PDF.cpp |
@@ -0,0 +1,86 @@ |
+/* |
+ * Copyright 2013 Google Inc. |
+ * |
+ * Use of this source code is governed by a BSD-style license that can be |
+ * found in the LICENSE file. |
+ */ |
+ |
+#include "SkDocument.h" |
+#include "SkPDFDocument.h" |
+#include "SkPDFDevice.h" |
+ |
+class SkDocument_PDF : public SkDocument { |
+public: |
+ SkDocument_PDF(SkWStream* stream) : SkDocument(stream) { |
+ fDoc = new SkPDFDocument; |
scroggo
2013/06/07 19:35:23
SkNEW
reed1
2013/06/07 19:50:40
Done.
|
+ fCanvas = NULL; |
+ fDevice = NULL; |
+ } |
+ |
+ virtual ~SkDocument_PDF() { |
+ this->close(); |
+ delete fDoc; |
scroggo
2013/06/07 19:35:23
SkDELETE
reed1
2013/06/07 19:50:40
Done.
|
+ } |
+ |
+protected: |
+ virtual SkCanvas* onBeginPage(SkScalar width, SkScalar height, |
+ const SkRect& content) SK_OVERRIDE { |
+ SkISize pageS, contentS; |
+ SkMatrix matrix; |
+ |
+ pageS.set(SkScalarRoundToInt(width), SkScalarRoundToInt(height)); |
+ contentS.set(SkScalarRoundToInt(content.width()), |
+ SkScalarRoundToInt(content.height())); |
+ matrix.setTranslate(content.fLeft, content.fTop); |
+ |
+ fDevice = new SkPDFDevice(pageS, contentS, matrix); |
scroggo
2013/06/07 19:35:23
SkNEW_ARGS
reed1
2013/06/07 19:50:40
Done.
|
+ fCanvas = new SkCanvas(fDevice); |
+ return fCanvas; |
+ } |
+ |
+ virtual void onEndPage() SK_OVERRIDE { |
+ if (fCanvas) { |
+ fCanvas->flush(); |
+ fDoc->appendPage(fDevice); |
+ |
+ fCanvas->unref(); |
+ fDevice->unref(); |
+ |
+ fCanvas = NULL; |
+ fDevice = NULL; |
+ } |
+ } |
+ |
+ virtual void onClose(SkWStream* stream) SK_OVERRIDE { |
+ fDoc->emitPDF(stream); |
+ |
+ delete fDoc; |
+ SkSafeUnref(fCanvas); |
scroggo
2013/06/07 19:35:23
Is there a way for fCanvas and fDevice to be non N
reed1
2013/06/07 19:50:40
Agreed. Simplified.
|
+ SkSafeUnref(fDevice); |
+ |
+ fDoc = NULL; |
+ fCanvas = NULL; |
+ fDevice = NULL; |
+ } |
+ |
+private: |
+ SkPDFDocument* fDoc; |
+ SkPDFDevice* fDevice; |
+ SkCanvas* fCanvas; |
+}; |
+ |
+/////////////////////////////////////////////////////////////////////////////// |
+ |
+SkDocument* SkDocument::CreatePDF(SkWStream* stream) { |
+ return stream ? SkNEW_ARGS(SkDocument_PDF, (stream)) : NULL; |
+} |
+ |
+SkDocument* SkDocument::CreatePDF(const char path[]) { |
+ SkFILEWStream* stream = SkNEW_ARGS(SkFILEWStream, (path)); |
+ if (!stream->isValid()) { |
+ SkDELETE(stream); |
+ return NULL; |
+ } |
+ return SkNEW_ARGS(SkDocument_PDF, (stream)); |
+} |
+ |