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

Unified Diff: src/doc/SkDocument_PDF.cpp

Issue 16660002: SkDocument base for pdf, xps, etc. (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Created 7 years, 6 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 | « src/doc/SkDocument.cpp ('k') | tools/skhello.cpp » ('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
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));
+}
+
« no previous file with comments | « src/doc/SkDocument.cpp ('k') | tools/skhello.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698