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

Side by Side Diff: include/core/SkDocument.h

Issue 26744002: SkDocument api changes (abort, close return success, ...) modified: include/core/SkDocument.h m… (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: consitent names 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
« no previous file with comments | « no previous file | src/doc/SkDocument.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 #ifndef SkDocument_DEFINED 8 #ifndef SkDocument_DEFINED
9 #define SkDocument_DEFINED 9 #define SkDocument_DEFINED
10 10
11 #include "SkBitmap.h"
12 #include "SkPicture.h"
11 #include "SkRect.h" 13 #include "SkRect.h"
12 #include "SkRefCnt.h" 14 #include "SkRefCnt.h"
13 15
14 class SkCanvas; 16 class SkCanvas;
15 class SkWStream; 17 class SkWStream;
16 18
17 /** 19 /**
18 * High-level API for creating a document-based canvas. To use.. 20 * High-level API for creating a document-based canvas. To use..
19 * 21 *
20 * 1. Create a document, specifying a stream to store the output. 22 * 1. Create a document, specifying a stream to store the output.
21 * 2. For each "page" of content: 23 * 2. For each "page" of content:
22 * a. canvas = doc->beginPage(...) 24 * a. canvas = doc->beginPage(...)
23 * b. draw_my_content(canvas); 25 * b. draw_my_content(canvas);
24 * c. doc->endPage(); 26 * c. doc->endPage();
25 * 3. Close the document with doc->close(). 27 * 3. Close the document with doc->close().
26 */ 28 */
27 class SkDocument : public SkRefCnt { 29 class SkDocument : public SkRefCnt {
28 public: 30 public:
29 SK_DECLARE_INST_COUNT(SkDocument) 31 SK_DECLARE_INST_COUNT(SkDocument)
30 32
31 /** 33 /**
32 * Create a PDF-backed document, writing the results into a file. 34 * Create a PDF-backed document, writing the results into a file.
33 * If there is an error trying to create the doc, returns NULL. 35 * If there is an error trying to create the doc, returns NULL.
36 * encoder sets the DCTEncoder for images, to encode a bitmap
37 * as JPEG (DCT).
34 */ 38 */
35 static SkDocument* CreatePDF(const char filename[]); 39 static SkDocument* CreatePDF(const char filename[],
40 SkPicture::EncodeBitmap encoder = NULL);
36 41
37 /** 42 /**
38 * Create a PDF-backed document, writing the results into a stream. 43 * Create a PDF-backed document, writing the results into a stream.
39 * If there is an error trying to create the doc, returns NULL. 44 * If there is an error trying to create the doc, returns NULL.
40 * 45 *
41 * The document may write to the stream at anytime during its lifetime, 46 * The document may write to the stream at anytime during its lifetime,
42 * until either close() is called or the document is deleted. Once close() 47 * until either close() is called or the document is deleted. Once close()
43 * has been called, and all of the data has been written to the stream, 48 * has been called, and all of the data has been written to the stream,
44 * if there is a Done proc provided, it will be called with the stream. 49 * if there is a Done proc provided, it will be called with the stream.
45 * The proc can delete the stream, or whatever it needs to do. 50 * The proc can delete the stream, or whatever it needs to do.
51 * encoder sets the DCTEncoder for images, to encode a bitmap
52 * as JPEG (DCT).
46 */ 53 */
47 static SkDocument* CreatePDF(SkWStream*, void (*Done)(SkWStream*) = NULL); 54 static SkDocument* CreatePDF(SkWStream*, void (*Done)(SkWStream*) = NULL,
55 SkPicture::EncodeBitmap encoder = NULL);
48 56
49 /** 57 /**
50 * Begin a new page for the document, returning the canvas that will draw 58 * Begin a new page for the document, returning the canvas that will draw
51 * into the page. The document owns this canvas, and it will go out of 59 * into the page. The document owns this canvas, and it will go out of
52 * scope when endPage() or close() is called, or the document is deleted. 60 * scope when endPage() or close() is called, or the document is deleted.
53 */ 61 */
54 SkCanvas* beginPage(SkScalar width, SkScalar height, 62 SkCanvas* beginPage(SkScalar width, SkScalar height,
55 const SkRect* content = NULL); 63 const SkRect* content = NULL);
56 64
57 /** 65 /**
58 * Call endPage() when the content for the current page has been drawn 66 * Call endPage() when the content for the current page has been drawn
59 * (into the canvas returned by beginPage()). After this call the canvas 67 * (into the canvas returned by beginPage()). After this call the canvas
60 * returned by beginPage() will be out-of-scope. 68 * returned by beginPage() will be out-of-scope.
61 */ 69 */
62 void endPage(); 70 void endPage();
63 71
64 /** 72 /**
65 * Call close() when all pages have been drawn. This will close the file 73 * Call close() when all pages have been drawn. This will close the file
66 * or stream holding the document's contents. After close() the document 74 * or stream holding the document's contents. After close() the document
67 * can no longer add new pages. Deleting the document will automatically 75 * can no longer add new pages. Deleting the document will automatically
68 * call close() if need be. 76 * call close() if need be.
77 * Returns true on success or false on failure.
69 */ 78 */
70 void close(); 79 bool close();
80
81 /**
82 * Call abort() to stop producing the document immediately.
83 * The stream output must be ignored, and should not be trusted.
84 */
85 void abort();
71 86
72 protected: 87 protected:
73 SkDocument(SkWStream*, void (*)(SkWStream*)); 88 SkDocument(SkWStream*, void (*)(SkWStream*));
74 // note: subclasses must call close() in their destructor, as the base class 89 // note: subclasses must call close() in their destructor, as the base class
75 // cannot do this for them. 90 // cannot do this for them.
76 virtual ~SkDocument(); 91 virtual ~SkDocument();
77 92
78 virtual SkCanvas* onBeginPage(SkScalar width, SkScalar height, 93 virtual SkCanvas* onBeginPage(SkScalar width, SkScalar height,
79 const SkRect& content) = 0; 94 const SkRect& content) = 0;
80 virtual void onEndPage() = 0; 95 virtual void onEndPage() = 0;
81 virtual void onClose(SkWStream*) = 0; 96 virtual bool onClose(SkWStream*) = 0;
97 virtual void onAbort() = 0;
82 98
83 enum State { 99 enum State {
84 kBetweenPages_State, 100 kBetweenPages_State,
85 kInPage_State, 101 kInPage_State,
86 kClosed_State 102 kClosed_State
87 }; 103 };
88 State getState() const { return fState; } 104 State getState() const { return fState; }
89 105
90 private: 106 private:
91 SkWStream* fStream; 107 SkWStream* fStream;
92 void (*fDoneProc)(SkWStream*); 108 void (*fDoneProc)(SkWStream*);
93 State fState; 109 State fState;
94 110
95 typedef SkRefCnt INHERITED; 111 typedef SkRefCnt INHERITED;
96 }; 112 };
97 113
98 #endif 114 #endif
OLDNEW
« no previous file with comments | « no previous file | src/doc/SkDocument.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698