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

Side by Side Diff: src/doc/SkDocument.cpp

Issue 24811002: Update the SkDocument interface to allow for 1) abort won't emit pdf, 2) close can report success/f… (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: move SkPDFDevice in separate files, and various fixes Created 7 years, 2 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
1 /* 1 /*
2 * Copyright 2013 Google Inc. 2 * Copyright 2013 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #include "SkDocument.h" 8 #include "SkDocument.h"
9 #include "SkStream.h" 9 #include "SkStream.h"
10 10
11 SK_DEFINE_INST_COUNT(SkDocument) 11 SK_DEFINE_INST_COUNT(SkDocument)
12 12
13 SkDocument::SkDocument(SkWStream* stream, void (*doneProc)(SkWStream*)) { 13 SkDocument::SkDocument(SkWStream* stream, void (*doneProc)(SkWStream*)) {
14 fStream = stream; // we do not own this object. 14 fStream = stream; // we do not own this object.
15 fDoneProc = doneProc; 15 fDoneProc = doneProc;
16 fState = kBetweenPages_State; 16 fState = kBetweenPages_State;
17 } 17 }
18 18
19 SkDocument::~SkDocument() { 19 SkDocument::~SkDocument() {
20 this->close(); 20 this->close();
21 } 21 }
22 22
23 SkCanvas* SkDocument::beginPage(SkScalar width, SkScalar height, 23 SkCanvas* SkDocument::beginPage(SkScalar width, SkScalar height,
24 const SkRect* content) { 24 const SkRect* content) {
25 if (width <= 0 || height <= 0) { 25 if (width <= 0 || height <= 0) {
vandebo (ex-Chrome) 2013/10/08 23:37:06 nit: extra spaces
26 return NULL; 26 return NULL;
27 } 27 }
28 28
29 SkRect outer = SkRect::MakeWH(width, height); 29 SkRect outer = SkRect::MakeWH(width, height);
30 SkRect inner; 30 SkRect inner;
31 if (content) { 31 if (content) {
32 inner = *content; 32 inner = *content;
33 if (!inner.intersect(outer)) { 33 if (!inner.intersect(outer)) {
34 return NULL; 34 return NULL;
35 } 35 }
36 } else { 36 } else {
37 inner = outer; 37 inner = outer;
38 } 38 }
39 39
40 for (;;) { 40 for (;;) {
41 switch (fState) { 41 switch (fState) {
42 case kBetweenPages_State: 42 case kBetweenPages_State:
43 fState = kInPage_State; 43 fState = kInPage_State;
44 return this->onBeginPage(width, height, inner); 44 return this->onBeginPage(width, height, inner);
45 case kInPage_State: 45 case kInPage_State:
46 this->endPage(); 46 this->endPage();
47 break; 47 break;
48 case kClosed_State: 48 case kClosed_State:
49 return NULL; 49 return NULL;
50 } 50 }
51 } 51 }
52 SkDEBUGFAIL("never get here"); 52 SkDEBUGFAIL("never get here");
53 return NULL; 53 return NULL;
54 } 54 }
55 55
56 void SkDocument::endPage() { 56 void SkDocument::endPage() {
57 if (kInPage_State == fState) { 57 if (kInPage_State == fState) {
58 fState = kBetweenPages_State; 58 fState = kBetweenPages_State;
59 this->onEndPage(); 59 this->onEndPage();
60 } 60 }
61 } 61 }
62 62
63 void SkDocument::close() { 63 bool SkDocument::close() {
64 for (;;) { 64 for (;;) {
65 switch (fState) { 65 switch (fState) {
66 case kBetweenPages_State: 66 case kBetweenPages_State: {
67 fState = kClosed_State; 67 fState = kClosed_State;
68 this->onClose(fStream); 68 bool success = this->onClose(fStream);
69 69
70 if (fDoneProc) { 70 if (fDoneProc) {
71 fDoneProc(fStream); 71 fDoneProc(fStream);
72 } 72 }
73 // we don't own the stream, but we mark it NULL since we can 73 // we don't own the stream, but we mark it NULL since we can
74 // no longer write to it. 74 // no longer write to it.
75 fStream = NULL; 75 fStream = NULL;
76 return; 76 return success;
77 }
77 case kInPage_State: 78 case kInPage_State:
78 this->endPage(); 79 this->endPage();
79 break; 80 break;
80 case kClosed_State: 81 case kClosed_State:
81 return; 82 return false;
82 } 83 }
83 } 84 }
84 } 85 }
86
87 void SkDocument::abort() {
88 fState = kClosed_State;
89 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698