Flutter Engine
The Flutter Engine
SkDocument.h
Go to the documentation of this file.
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
14
15class SkCanvas;
16class SkWStream;
17struct SkRect;
18
19/** SK_ScalarDefaultDPI is 72 dots per inch. */
20static constexpr SkScalar SK_ScalarDefaultRasterDPI = 72.0f;
21
22/**
23 * High-level API for creating a document-based canvas. To use..
24 *
25 * 1. Create a document, specifying a stream to store the output.
26 * 2. For each "page" of content:
27 * a. canvas = doc->beginPage(...)
28 * b. draw_my_content(canvas);
29 * c. doc->endPage();
30 * 3. Close the document with doc->close().
31 */
32class SK_API SkDocument : public SkRefCnt {
33public:
34
35 /**
36 * Begin a new page for the document, returning the canvas that will draw
37 * into the page. The document owns this canvas, and it will go out of
38 * scope when endPage() or close() is called, or the document is deleted.
39 * This will call endPage() if there is a currently active page.
40 */
41 SkCanvas* beginPage(SkScalar width, SkScalar height, const SkRect* content = nullptr);
42
43 /**
44 * Call endPage() when the content for the current page has been drawn
45 * (into the canvas returned by beginPage()). After this call the canvas
46 * returned by beginPage() will be out-of-scope.
47 */
48 void endPage();
49
50 /**
51 * Call close() when all pages have been drawn. This will close the file
52 * or stream holding the document's contents. After close() the document
53 * can no longer add new pages. Deleting the document will automatically
54 * call close() if need be.
55 */
56 void close();
57
58 /**
59 * Call abort() to stop producing the document immediately.
60 * The stream output must be ignored, and should not be trusted.
61 */
62 void abort();
63
64protected:
66
67 // note: subclasses must call close() in their destructor, as the base class
68 // cannot do this for them.
69 ~SkDocument() override;
70
72 virtual void onEndPage() = 0;
73 virtual void onClose(SkWStream*) = 0;
74 virtual void onAbort() = 0;
75
76 // Allows subclasses to write to the stream as pages are written.
77 SkWStream* getStream() { return fStream; }
78
79 enum State {
82 kClosed_State
83 };
84 State getState() const { return fState; }
85
86private:
87 SkWStream* fStream;
88 State fState;
89
90 using INHERITED = SkRefCnt;
91};
92
93#endif
#define SK_API
Definition: SkAPI.h:35
static constexpr SkScalar SK_ScalarDefaultRasterDPI
Definition: SkDocument.h:20
#define INHERITED(method,...)
Definition: SkRecorder.cpp:128
virtual void onClose(SkWStream *)=0
virtual void onAbort()=0
SkWStream * getStream()
Definition: SkDocument.h:77
@ kInPage_State
Definition: SkDocument.h:81
@ kBetweenPages_State
Definition: SkDocument.h:80
State getState() const
Definition: SkDocument.h:84
virtual SkCanvas * onBeginPage(SkScalar width, SkScalar height)=0
virtual void onEndPage()=0
float SkScalar
Definition: extension.cpp:12
union flutter::testing::@2836::KeyboardChange::@76 content
int32_t height
int32_t width