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 #include "include/private/base/SkAPI.h"
14 
15 class SkCanvas;
16 class SkWStream;
17 struct SkRect;
18 
20 static constexpr SkScalar SK_ScalarDefaultRasterDPI = 72.0f;
21 
32 class SK_API SkDocument : public SkRefCnt {
33 public:
34 
40  SkCanvas* beginPage(SkScalar width, SkScalar height, const SkRect* content = nullptr);
41 
47  void endPage();
48 
55  void close();
56 
61  void abort();
62 
63 protected:
65 
66  // note: subclasses must call close() in their destructor, as the base class
67  // cannot do this for them.
68  ~SkDocument() override;
69 
70  virtual SkCanvas* onBeginPage(SkScalar width, SkScalar height) = 0;
71  virtual void onEndPage() = 0;
72  virtual void onClose(SkWStream*) = 0;
73  virtual void onAbort() = 0;
74 
75  // Allows subclasses to write to the stream as pages are written.
76  SkWStream* getStream() { return fStream; }
77 
78  enum State {
81  kClosed_State
82  };
83  State getState() const { return fState; }
84 
85 private:
86  SkWStream* fStream;
87  State fState;
88 
89  using INHERITED = SkRefCnt;
90 };
91 
92 #endif
static constexpr SkScalar SK_ScalarDefaultRasterDPI
SK_ScalarDefaultDPI is 72 dots per inch.
Definition: SkDocument.h:20
float SkScalar
Definition: SkScalar.h:14
SkCanvas provides an interface for drawing, and how the drawing is clipped and transformed.
Definition: SkCanvas.h:99
High-level API for creating a document-based canvas.
Definition: SkDocument.h:32
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.
virtual void onClose(SkWStream *)=0
virtual void onAbort()=0
~SkDocument() override
void close()
Call close() when all pages have been drawn.
State
Definition: SkDocument.h:78
@ kInPage_State
Definition: SkDocument.h:80
@ kBetweenPages_State
Definition: SkDocument.h:79
State getState() const
Definition: SkDocument.h:83
void abort()
Call abort() to stop producing the document immediately.
SkDocument(SkWStream *)
virtual SkCanvas * onBeginPage(SkScalar width, SkScalar height)=0
virtual void onEndPage()=0
void endPage()
Call endPage() when the content for the current page has been drawn (into the canvas returned by begi...
SkWStream * getStream()
Definition: SkDocument.h:76
Definition: SkRefCnt.h:119
Definition: SkStream.h:218
SkRect holds four float coordinates describing the upper and lower bounds of a rectangle.
Definition: SkRect.h:582