Skia
2D Graphics Library
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 
11 #include "include/core/SkRefCnt.h"
12 #include "include/core/SkScalar.h"
13 
14 class SkCanvas;
15 class SkWStream;
16 struct SkRect;
17 
19 static constexpr SkScalar SK_ScalarDefaultRasterDPI = 72.0f;
20 
31 class SK_API SkDocument : public SkRefCnt {
32 public:
33 
39  SkCanvas* beginPage(SkScalar width, SkScalar height, const SkRect* content = nullptr);
40 
46  void endPage();
47 
54  void close();
55 
60  void abort();
61 
62 protected:
64 
65  // note: subclasses must call close() in their destructor, as the base class
66  // cannot do this for them.
67  ~SkDocument() override;
68 
69  virtual SkCanvas* onBeginPage(SkScalar width, SkScalar height) = 0;
70  virtual void onEndPage() = 0;
71  virtual void onClose(SkWStream*) = 0;
72  virtual void onAbort() = 0;
73 
74  // Allows subclasses to write to the stream as pages are written.
75  SkWStream* getStream() { return fStream; }
76 
77  enum State {
80  kClosed_State
81  };
82  State getState() const { return fState; }
83 
84 private:
85  SkWStream* fStream;
86  State fState;
87 
88  using INHERITED = SkRefCnt;
89 };
90 
91 #endif
SkDocument::State
State
Definition: SkDocument.h:77
SkRefCnt
Definition: SkRefCnt.h:118
SkDocument
High-level API for creating a document-based canvas.
Definition: SkDocument.h:31
SK_ScalarDefaultRasterDPI
static constexpr SkScalar SK_ScalarDefaultRasterDPI
SK_ScalarDefaultDPI is 72 dots per inch.
Definition: SkDocument.h:19
SkRefCnt.h
SkDocument::close
void close()
Call close() when all pages have been drawn.
SkScalar.h
SK_API
#define SK_API
Definition: SkTypes.h:181
SkDocument::onBeginPage
virtual SkCanvas * onBeginPage(SkScalar width, SkScalar height)=0
SkDocument::onEndPage
virtual void onEndPage()=0
SkDocument::endPage
void endPage()
Call endPage() when the content for the current page has been drawn (into the canvas returned by begi...
SkCanvas
Definition: SkCanvas.h:87
SkDocument::kBetweenPages_State
@ kBetweenPages_State
Definition: SkDocument.h:78
SkDocument::onClose
virtual void onClose(SkWStream *)=0
SkScalar
float SkScalar
Definition: SkScalar.h:16
SkDocument::beginPage
SkCanvas * 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.
SkDocument::onAbort
virtual void onAbort()=0
SkDocument::SkDocument
SkDocument(SkWStream *)
SkWStream
Definition: SkStream.h:227
SkDocument::abort
void abort()
Call abort() to stop producing the document immediately.
SkRect
Definition: SkRect.h:572
SkDocument::getStream
SkWStream * getStream()
Definition: SkDocument.h:75
SkDocument::getState
State getState() const
Definition: SkDocument.h:82
SkDocument::~SkDocument
~SkDocument() override
SkDocument::kInPage_State
@ kInPage_State
Definition: SkDocument.h:79