Flutter Engine
The Flutter Engine
SkDocument.cpp
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 */
8
10#include "include/core/SkRect.h"
12
13SkDocument::SkDocument(SkWStream* stream) : fStream(stream), fState(kBetweenPages_State) {}
14
16 this->close();
17}
18
20 const SkRect* content) {
21 if (content && canvas) {
22 SkRect inner = *content;
23 if (!inner.intersect({0, 0, width, height})) {
24 return nullptr;
25 }
26 canvas->clipRect(inner);
27 canvas->translate(inner.x(), inner.y());
28 }
29 return canvas;
30}
31
33 const SkRect* content) {
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}
44
46 if (kInPage_State == fState) {
47 fState = kBetweenPages_State;
48 this->onEndPage();
49 }
50}
51
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}
71
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}
#define SkASSERT(cond)
Definition: SkAssert.h:116
static SkCanvas * trim(SkCanvas *canvas, SkScalar width, SkScalar height, const SkRect *content)
Definition: SkDocument.cpp:19
void clipRect(const SkRect &rect, SkClipOp op, bool doAntiAlias)
Definition: SkCanvas.cpp:1361
void translate(SkScalar dx, SkScalar dy)
Definition: SkCanvas.cpp:1278
virtual void onClose(SkWStream *)=0
virtual void onAbort()=0
~SkDocument() override
Definition: SkDocument.cpp:15
void close()
Definition: SkDocument.cpp:52
@ kInPage_State
Definition: SkDocument.h:81
@ kClosed_State
Definition: SkDocument.h:82
@ kBetweenPages_State
Definition: SkDocument.h:80
SkCanvas * beginPage(SkScalar width, SkScalar height, const SkRect *content=nullptr)
Definition: SkDocument.cpp:32
void abort()
Definition: SkDocument.cpp:72
SkDocument(SkWStream *)
Definition: SkDocument.cpp:13
virtual SkCanvas * onBeginPage(SkScalar width, SkScalar height)=0
virtual void onEndPage()=0
void endPage()
Definition: SkDocument.cpp:45
float SkScalar
Definition: extension.cpp:12
union flutter::testing::@2836::KeyboardChange::@76 content
int32_t height
int32_t width
bool intersect(const SkRect &r)
Definition: SkRect.cpp:114
constexpr float x() const
Definition: SkRect.h:720
constexpr float y() const
Definition: SkRect.h:727