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

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: update dox that we don't take ownership of the stream 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
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..61f04e97e99cb18976748a4ccfb68dedabea576a
--- /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 = SkNEW(SkPDFDocument);
+ fCanvas = NULL;
+ fDevice = NULL;
+ }
+
+ virtual ~SkDocument_PDF() {
+ this->close();
+ }
+
+protected:
+ virtual SkCanvas* onBeginPage(SkScalar width, SkScalar height,
+ const SkRect& content) SK_OVERRIDE {
+ SkASSERT(NULL == fCanvas);
+ SkASSERT(NULL == fDevice);
+
+ 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 = SkNEW_ARGS(SkPDFDevice, (pageS, contentS, matrix));
+ fCanvas = SkNEW_ARGS(SkCanvas, (fDevice));
+ return fCanvas;
+ }
+
+ virtual void onEndPage() SK_OVERRIDE {
+ SkASSERT(fCanvas);
+ SkASSERT(fDevice);
+
+ fCanvas->flush();
+ fDoc->appendPage(fDevice);
+
+ fCanvas->unref();
+ fDevice->unref();
+
+ fCanvas = NULL;
+ fDevice = NULL;
+ }
+
+ virtual void onClose(SkWStream* stream) SK_OVERRIDE {
+ SkASSERT(NULL == fCanvas);
+ SkASSERT(NULL == fDevice);
+
+ fDoc->emitPDF(stream);
+ SkDELETE(fDoc);
+ fDoc = 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));
scroggo 2013/06/07 20:12:32 This one does need to be deleted.
+ if (!stream->isValid()) {
+ SkDELETE(stream);
+ return NULL;
+ }
+ return SkNEW_ARGS(SkDocument_PDF, (stream));
+}
+
« include/core/SkDocument.h ('K') | « src/doc/SkDocument.cpp ('k') | tools/skhello.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698