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

Unified Diff: src/doc/SkDocument.cpp

Issue 16660002: SkDocument base for pdf, xps, etc. (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: add Done proc, so caller can delete the stream automatically when the doc is done with it 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.cpp
diff --git a/src/doc/SkDocument.cpp b/src/doc/SkDocument.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..4298b3f595c8c3ee45c3ed5b64c2cbfbb1deec26
--- /dev/null
+++ b/src/doc/SkDocument.cpp
@@ -0,0 +1,83 @@
+/*
+ * 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 "SkStream.h"
+
+SkDocument::SkDocument(SkWStream* stream, void (*doneProc)(SkWStream*)) {
+ fStream = stream; // we do not own this object.
+ fDoneProc = doneProc;
+ fState = kBetweenPages_State;
+}
+
+SkDocument::~SkDocument() {
+ this->close();
+}
+
+SkCanvas* SkDocument::beginPage(SkScalar width, SkScalar height,
+ const SkRect* content) {
+ if (width <= 0 || height <= 0) {
+ return NULL;
+ }
+
+ SkRect outer = SkRect::MakeWH(width, height);
+ SkRect inner;
+ if (content) {
+ inner = *content;
+ if (!inner.intersect(outer)) {
+ return NULL;
+ }
+ } else {
+ inner = outer;
+ }
+
+ for (;;) {
+ switch (fState) {
+ case kBetweenPages_State:
+ fState = kInPage_State;
+ return this->onBeginPage(width, height, inner);
+ case kInPage_State:
+ this->endPage();
+ break;
+ case kClosed_State:
+ return NULL;
+ }
+ }
+ SkASSERT(!"never get here");
+ return NULL;
+}
+
+void SkDocument::endPage() {
wrong vandebo 2013/06/10 16:41:12 It seems like this method isn't strictly needed an
+ if (kInPage_State == fState) {
+ fState = kBetweenPages_State;
+ this->onEndPage();
+ }
+}
+
+void SkDocument::close() {
+ for (;;) {
+ switch (fState) {
+ case kBetweenPages_State:
+ fState = kClosed_State;
+ this->onClose(fStream);
+
+ if (fDoneProc) {
+ fDoneProc(fStream);
+ }
+ // we don't own the stream, but we mark it NULL since we can
+ // no longer write to it.
+ fStream = NULL;
+ return;
+ case kInPage_State:
+ this->endPage();
+ break;
+ case kClosed_State:
+ return;
+ }
+ }
+}
+

Powered by Google App Engine
This is Rietveld 408576698