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

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

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 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 #ifndef SkDocument_DEFINED
9 #define SkDocument_DEFINED
10
11 #include "SkRect.h"
12 #include "SkRefCnt.h"
13
14 class SkCanvas;
15 class SkWStream;
16
17 /**
18 * High-level API for creating a document-based canvas. To use..
19 *
20 * 1. Create a document, specifying a stream to store the output.
21 * 2. For each "page" of content:
22 * a. canvas = doc->beginPage(...)
23 * b. draw_my_content(canvas);
24 * c. doc->endPage();
25 * 3. Close the document with doc->close().
26 */
27 class SkDocument : public SkRefCnt {
28 public:
29 /**
30 * Create a PDF-backed document, writing the results into a file. If there
31 * is an error trying to create the doc, returns NULL.
32 */
33 static SkDocument* CreatePDF(const char filename[]);
wrong vandebo 2013/06/10 16:41:12 Are these factory methods and you'll have addition
34
35 /**
36 * Create a PDF-backed document, writing the results into a stream.
37 * there is an error trying to create the doc, returns NULL.
38 *
39 * The document may write to the stream at anytime during its lifetime,
40 * until either close() is called or the document is deleted. Once close()
41 * has been called, and all of the data has been written to the stream,
42 * if there is a Done proc provided, it will be called with the stream.
43 * The proc can delete the stream, or whatever it needs to do.
44 */
45 static SkDocument* CreatePDF(SkWStream*, void (*Done)(SkWStream*) = NULL);
wrong vandebo 2013/06/10 16:41:12 PDF has a couple of document options: disable comp
46
47 /**
48 * Begin a new page for the document, returning the canvas that will draw
49 * into the page. The document owns this canvas, and it will go out of
50 * scope when endPage() or close() is called, or the document is deleted.
51 */
52 SkCanvas* beginPage(SkScalar width, SkScalar height,
53 const SkRect* content = NULL);
wrong vandebo 2013/06/10 16:41:12 I tried using only a rect to specify the content a
54
55 /**
56 * Call endPage() when the content for the current page has been drawn
57 * (into the canvas returned by beginPage()). After this call the canvas
58 * returned by beginPage() will be out-of-scope.
59 */
60 void endPage();
61
62 /**
63 * Call close() when all pages have been drawn. This will close the file
64 * or stream holding the document's contents. After close() the document
65 * can no longer add new pages. Deleting the document will automatically
66 * call close() if need be.
67 */
68 void close();
wrong vandebo 2013/06/10 16:41:12 A feature that the PDF code has that's not represe
69
70 protected:
71 SkDocument(SkWStream*, void (*)(SkWStream*));
72 virtual ~SkDocument();
73
74 virtual SkCanvas* onBeginPage(SkScalar width, SkScalar height,
75 const SkRect& content) = 0;
76 virtual void onEndPage() = 0;
77 virtual void onClose(SkWStream*) = 0;
78
79 enum State {
80 kBetweenPages_State,
81 kInPage_State,
82 kClosed_State
83 };
84 State getState() const { return fState; }
85
86 private:
87 SkWStream* fStream;
88 void (*fDoneProc)(SkWStream*);
89 State fState;
90 };
91
92 #endif
OLDNEW
« no previous file with comments | « gyp/tools.gyp ('k') | src/doc/SkDocument.cpp » ('j') | src/doc/SkDocument.cpp » ('J')

Powered by Google App Engine
This is Rietveld 408576698