Flutter Engine
The Flutter Engine
Public Member Functions | Protected Types | Protected Member Functions | List of all members
SkDocument Class Referenceabstract

#include <SkDocument.h>

Inheritance diagram for SkDocument:
SkRefCnt SkRefCntBase SkPDFDocument

Public Member Functions

SkCanvasbeginPage (SkScalar width, SkScalar height, const SkRect *content=nullptr)
 
void endPage ()
 
void close ()
 
void abort ()
 
- Public Member Functions inherited from SkRefCntBase
 SkRefCntBase ()
 
virtual ~SkRefCntBase ()
 
bool unique () const
 
void ref () const
 
void unref () const
 

Protected Types

enum  State { kBetweenPages_State , kInPage_State , kClosed_State }
 

Protected Member Functions

 SkDocument (SkWStream *)
 
 ~SkDocument () override
 
virtual SkCanvasonBeginPage (SkScalar width, SkScalar height)=0
 
virtual void onEndPage ()=0
 
virtual void onClose (SkWStream *)=0
 
virtual void onAbort ()=0
 
SkWStreamgetStream ()
 
State getState () const
 

Detailed Description

High-level API for creating a document-based canvas. To use..

  1. Create a document, specifying a stream to store the output.
  2. For each "page" of content: a. canvas = doc->beginPage(...) b. draw_my_content(canvas); c. doc->endPage();
  3. Close the document with doc->close().

Definition at line 32 of file SkDocument.h.

Member Enumeration Documentation

◆ State

enum SkDocument::State
protected
Enumerator
kBetweenPages_State 
kInPage_State 
kClosed_State 

Definition at line 79 of file SkDocument.h.

79 {
83 };
@ kInPage_State
Definition: SkDocument.h:81
@ kClosed_State
Definition: SkDocument.h:82
@ kBetweenPages_State
Definition: SkDocument.h:80

Constructor & Destructor Documentation

◆ SkDocument()

SkDocument::SkDocument ( SkWStream stream)
protected

Definition at line 13 of file SkDocument.cpp.

◆ ~SkDocument()

SkDocument::~SkDocument ( )
overrideprotected

Definition at line 15 of file SkDocument.cpp.

15 {
16 this->close();
17}
void close()
Definition: SkDocument.cpp:52

Member Function Documentation

◆ abort()

void SkDocument::abort ( )

Call abort() to stop producing the document immediately. The stream output must be ignored, and should not be trusted.

Definition at line 72 of file SkDocument.cpp.

72 {
73 this->onAbort();
74
75 fState = kClosed_State;
76 // we don't own the stream, but we mark it nullptr since we can
77 // no longer write to it.
78 fStream = nullptr;
79}
virtual void onAbort()=0

◆ beginPage()

SkCanvas * SkDocument::beginPage ( SkScalar  width,
SkScalar  height,
const SkRect content = nullptr 
)

Begin a new page for the document, returning the canvas that will draw into the page. The document owns this canvas, and it will go out of scope when endPage() or close() is called, or the document is deleted. This will call endPage() if there is a currently active page.

Definition at line 32 of file SkDocument.cpp.

33 {
34 if (width <= 0 || height <= 0 || kClosed_State == fState) {
35 return nullptr;
36 }
37 if (kInPage_State == fState) {
38 this->endPage();
39 }
41 fState = kInPage_State;
42 return trim(this->onBeginPage(width, height), width, height, content);
43}
#define SkASSERT(cond)
Definition: SkAssert.h:116
static SkCanvas * trim(SkCanvas *canvas, SkScalar width, SkScalar height, const SkRect *content)
Definition: SkDocument.cpp:19
virtual SkCanvas * onBeginPage(SkScalar width, SkScalar height)=0
void endPage()
Definition: SkDocument.cpp:45
int32_t height
int32_t width

◆ close()

void SkDocument::close ( )

Call close() when all pages have been drawn. This will close the file or stream holding the document's contents. After close() the document can no longer add new pages. Deleting the document will automatically call close() if need be.

Definition at line 52 of file SkDocument.cpp.

52 {
53 for (;;) {
54 switch (fState) {
56 fState = kClosed_State;
57 this->onClose(fStream);
58 // we don't own the stream, but we mark it nullptr since we can
59 // no longer write to it.
60 fStream = nullptr;
61 return;
62 }
63 case kInPage_State:
64 this->endPage();
65 break;
66 case kClosed_State:
67 return;
68 }
69 }
70}
virtual void onClose(SkWStream *)=0

◆ endPage()

void SkDocument::endPage ( )

Call endPage() when the content for the current page has been drawn (into the canvas returned by beginPage()). After this call the canvas returned by beginPage() will be out-of-scope.

Definition at line 45 of file SkDocument.cpp.

45 {
46 if (kInPage_State == fState) {
47 fState = kBetweenPages_State;
48 this->onEndPage();
49 }
50}
virtual void onEndPage()=0

◆ getState()

State SkDocument::getState ( ) const
inlineprotected

Definition at line 84 of file SkDocument.h.

84{ return fState; }

◆ getStream()

SkWStream * SkDocument::getStream ( )
inlineprotected

Definition at line 77 of file SkDocument.h.

77{ return fStream; }

◆ onAbort()

virtual void SkDocument::onAbort ( )
protectedpure virtual

Implemented in SkPDFDocument.

◆ onBeginPage()

virtual SkCanvas * SkDocument::onBeginPage ( SkScalar  width,
SkScalar  height 
)
protectedpure virtual

Implemented in SkPDFDocument.

◆ onClose()

virtual void SkDocument::onClose ( SkWStream )
protectedpure virtual

Implemented in SkPDFDocument.

◆ onEndPage()

virtual void SkDocument::onEndPage ( )
protectedpure virtual

Implemented in SkPDFDocument.


The documentation for this class was generated from the following files: