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

Side by Side Diff: src/doc/SkDocument.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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 /*
2 * Copyright 2013 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8 #include "SkDocument.h"
9 #include "SkStream.h"
10
11 SkDocument::SkDocument(SkWStream* stream) {
12 fStream = stream;
13 fState = kBetweenPages_State;
14 }
15
16 SkDocument::~SkDocument() {
17 this->close();
18 }
19
20 SkCanvas* SkDocument::beginPage(SkScalar width, SkScalar height,
21 const SkRect* content) {
22 if (width <= 0 || height <= 0) {
23 return NULL;
24 }
25
26 SkRect outer = SkRect::MakeWH(width, height);
27 SkRect inner;
28 if (content) {
29 inner = *content;
30 if (!inner.intersect(outer)) {
31 return NULL;
32 }
33 } else {
34 inner = outer;
35 }
36
37 for (;;) {
38 switch (fState) {
39 case kBetweenPages_State:
40 fState = kInPage_State;
41 return this->onBeginPage(width, height, inner);
42 case kInPage_State:
43 this->endPage();
44 break;
45 case kClosed_State:
46 return NULL;
47 }
48 }
49 SkASSERT(!"never get here");
50 return NULL;
51 }
52
53 void SkDocument::endPage() {
54 if (kInPage_State == fState) {
55 fState = kBetweenPages_State;
56 this->onEndPage();
57 }
58 }
59
60 void SkDocument::close() {
61 for (;;) {
62 switch (fState) {
63 case kBetweenPages_State:
64 fState = kClosed_State;
65 this->onClose(fStream);
66 SkDELETE(fStream);
67 fStream = NULL;
68 return;
69 case kInPage_State:
70 this->endPage();
71 break;
72 case kClosed_State:
73 return;
74 }
75 }
76 }
77
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698