aboutsummaryrefslogtreecommitdiffhomepage
path: root/include/core/SkDocument.h
diff options
context:
space:
mode:
authorGravatar reed@google.com <reed@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2013-06-07 20:30:16 +0000
committerGravatar reed@google.com <reed@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2013-06-07 20:30:16 +0000
commit99ac02bb701c1e30b20f2174aac25ffbe487c0af (patch)
tree19ed3f1e04606e8cb5e73650c870f106e0c0e5e9 /include/core/SkDocument.h
parent99d43ffcfbed84aac33a45e1eb725bb684cdc2e7 (diff)
SkDocument base for pdf, xps, etc.
R=scroggo@google.com Review URL: https://codereview.chromium.org/16660002 git-svn-id: http://skia.googlecode.com/svn/trunk@9476 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'include/core/SkDocument.h')
-rw-r--r--include/core/SkDocument.h94
1 files changed, 94 insertions, 0 deletions
diff --git a/include/core/SkDocument.h b/include/core/SkDocument.h
new file mode 100644
index 0000000000..5ca0a5cd6e
--- /dev/null
+++ b/include/core/SkDocument.h
@@ -0,0 +1,94 @@
+/*
+ * Copyright 2013 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#ifndef SkDocument_DEFINED
+#define SkDocument_DEFINED
+
+#include "SkRect.h"
+#include "SkRefCnt.h"
+
+class SkCanvas;
+class SkWStream;
+
+/**
+ * High-level API for creating a document-based canvas. To use..
+ *
+ * 1. Create a document, specifying a stream to store the output.
+ * 2. For each "page" of content:
+ * a. canvas = doc->beginPage(...)
+ * b. draw_my_content(canvas);
+ * c. doc->endPage();
+ * 3. Close the document with doc->close().
+ */
+class SkDocument : public SkRefCnt {
+public:
+ /**
+ * Create a PDF-backed document, writing the results into a file.
+ * If there is an error trying to create the doc, returns NULL.
+ */
+ static SkDocument* CreatePDF(const char filename[]);
+
+ /**
+ * Create a PDF-backed document, writing the results into a stream.
+ * If there is an error trying to create the doc, returns NULL.
+ *
+ * The document may write to the stream at anytime during its lifetime,
+ * until either close() is called or the document is deleted. Once close()
+ * has been called, and all of the data has been written to the stream,
+ * if there is a Done proc provided, it will be called with the stream.
+ * The proc can delete the stream, or whatever it needs to do.
+ */
+ static SkDocument* CreatePDF(SkWStream*, void (*Done)(SkWStream*) = NULL);
+
+ /**
+ * Begin a new page for the document, returning the canvas that will draw
+ * into the page. The document owns this canvas, and it will go out of
+ * scope when endPage() or close() is called, or the document is deleted.
+ */
+ SkCanvas* beginPage(SkScalar width, SkScalar height,
+ const SkRect* content = NULL);
+
+ /**
+ * Call endPage() when the content for the current page has been drawn
+ * (into the canvas returned by beginPage()). After this call the canvas
+ * returned by beginPage() will be out-of-scope.
+ */
+ void endPage();
+
+ /**
+ * Call close() when all pages have been drawn. This will close the file
+ * or stream holding the document's contents. After close() the document
+ * can no longer add new pages. Deleting the document will automatically
+ * call close() if need be.
+ */
+ void close();
+
+protected:
+ SkDocument(SkWStream*, void (*)(SkWStream*));
+ // note: subclasses must call close() in their destructor, as the base class
+ // cannot do this for them.
+ virtual ~SkDocument();
+
+ virtual SkCanvas* onBeginPage(SkScalar width, SkScalar height,
+ const SkRect& content) = 0;
+ virtual void onEndPage() = 0;
+ virtual void onClose(SkWStream*) = 0;
+
+ enum State {
+ kBetweenPages_State,
+ kInPage_State,
+ kClosed_State
+ };
+ State getState() const { return fState; }
+
+private:
+ SkWStream* fStream;
+ void (*fDoneProc)(SkWStream*);
+ State fState;
+};
+
+#endif