Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
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.

Constructor & Destructor Documentation

◆ SkDocument()

SkDocument::SkDocument ( SkWStream stream)
protected

Definition at line 13 of file SkDocument.cpp.

13: fStream(stream), fState(kBetweenPages_State) {}

◆ ~SkDocument()

SkDocument::~SkDocument ( )
overrideprotected

Definition at line 15 of file SkDocument.cpp.

15 {
16 this->close();
17}
void close()

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)
virtual SkCanvas * onBeginPage(SkScalar width, SkScalar height)=0
void endPage()
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: