Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
third_party
skia
modules
svg
src
SkSVGUse.cpp
Go to the documentation of this file.
1
/*
2
* Copyright 2017 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
#include "
modules/svg/include/SkSVGUse.h
"
9
10
#include "
include/core/SkCanvas.h
"
11
#include "
modules/svg/include/SkSVGRenderContext.h
"
12
#include "
modules/svg/include/SkSVGValue.h
"
13
14
SkSVGUse::SkSVGUse() :
INHERITED
(
SkSVGTag
::
kUse
) {}
15
16
void
SkSVGUse::appendChild
(
sk_sp<SkSVGNode>
) {
17
SkDebugf
(
"cannot append child nodes to this element.\n"
);
18
}
19
20
bool
SkSVGUse::parseAndSetAttribute
(
const
char
* n,
const
char
* v) {
21
return
INHERITED::parseAndSetAttribute
(n, v) ||
22
this->setX(SkSVGAttributeParser::parse<SkSVGLength>(
"x"
, n, v)) ||
23
this->setY(SkSVGAttributeParser::parse<SkSVGLength>(
"y"
, n, v)) ||
24
this->setHref(SkSVGAttributeParser::parse<SkSVGIRI>(
"xlink:href"
, n, v));
25
}
26
27
bool
SkSVGUse::onPrepareToRender
(
SkSVGRenderContext
* ctx)
const
{
28
if
(fHref.iri().isEmpty() || !
INHERITED::onPrepareToRender
(ctx)) {
29
return
false
;
30
}
31
32
if
(fX.value() || fY.value()) {
33
// Restored when the local SkSVGRenderContext leaves scope.
34
ctx->
saveOnce
();
35
ctx->
canvas
()->
translate
(fX.value(), fY.value());
36
}
37
38
// TODO: width/height override for <svg> targets.
39
40
return
true
;
41
}
42
43
void
SkSVGUse::onRender
(
const
SkSVGRenderContext
& ctx)
const
{
44
const
auto
ref
= ctx.
findNodeById
(fHref);
45
if
(!
ref
) {
46
return
;
47
}
48
49
ref
->
render
(ctx);
50
}
51
52
SkPath
SkSVGUse::onAsPath
(
const
SkSVGRenderContext
& ctx)
const
{
53
const
auto
ref
= ctx.
findNodeById
(fHref);
54
if
(!
ref
) {
55
return
SkPath
();
56
}
57
58
return
ref
->asPath(ctx);
59
}
60
61
SkRect
SkSVGUse::onObjectBoundingBox
(
const
SkSVGRenderContext
& ctx)
const
{
62
const
auto
ref
= ctx.
findNodeById
(fHref);
63
if
(!
ref
) {
64
return
SkRect::MakeEmpty
();
65
}
66
67
const
SkSVGLengthContext
& lctx = ctx.
lengthContext
();
68
const
SkScalar
x
= lctx.
resolve
(fX,
SkSVGLengthContext::LengthType::kHorizontal
);
69
const
SkScalar
y
= lctx.
resolve
(fY,
SkSVGLengthContext::LengthType::kVertical
);
70
71
SkRect
bounds =
ref
->objectBoundingBox(ctx);
72
bounds.offset(
x
,
y
);
73
74
return
bounds;
75
}
SkCanvas.h
SkDebugf
void SK_SPI SkDebugf(const char format[],...) SK_PRINTF_LIKE(1
INHERITED
#define INHERITED(method,...)
Definition
SkRecorder.cpp:128
SkSVGTag
SkSVGTag
Definition
SkSVGNode.h:23
SkSVGTag::kUse
@ kUse
SkSVGRenderContext.h
SkSVGUse.h
SkSVGValue.h
SkCanvas::translate
void translate(SkScalar dx, SkScalar dy)
Definition
SkCanvas.cpp:1602
SkPath
Definition
SkPath.h:59
SkRefCntBase::ref
void ref() const
Definition
SkRefCnt.h:62
SkSVGLengthContext
Definition
SkSVGRenderContext.h:29
SkSVGLengthContext::LengthType::kVertical
@ kVertical
SkSVGLengthContext::LengthType::kHorizontal
@ kHorizontal
SkSVGLengthContext::resolve
SkScalar resolve(const SkSVGLength &, LengthType) const
Definition
SkSVGRenderContext.cpp:54
SkSVGNode::render
void render(const SkSVGRenderContext &) const
Definition
SkSVGNode.cpp:28
SkSVGNode::parseAndSetAttribute
virtual bool parseAndSetAttribute(const char *name, const char *value)
Definition
SkSVGNode.cpp:90
SkSVGRenderContext
Definition
SkSVGRenderContext.h:63
SkSVGRenderContext::findNodeById
BorrowedNode findNodeById(const SkSVGIRI &) const
Definition
SkSVGRenderContext.cpp:201
SkSVGRenderContext::canvas
SkCanvas * canvas() const
Definition
SkSVGRenderContext.h:90
SkSVGRenderContext::lengthContext
const SkSVGLengthContext & lengthContext() const
Definition
SkSVGRenderContext.h:85
SkSVGRenderContext::saveOnce
void saveOnce()
Definition
SkSVGRenderContext.cpp:323
SkSVGTransformableNode::onPrepareToRender
bool onPrepareToRender(SkSVGRenderContext *) const override
Definition
SkSVGTransformableNode.cpp:18
SkSVGUse::onRender
void onRender(const SkSVGRenderContext &) const override
Definition
SkSVGUse.cpp:43
SkSVGUse::onObjectBoundingBox
SkRect onObjectBoundingBox(const SkSVGRenderContext &) const override
Definition
SkSVGUse.cpp:61
SkSVGUse::onAsPath
SkPath onAsPath(const SkSVGRenderContext &) const override
Definition
SkSVGUse.cpp:52
SkSVGUse::parseAndSetAttribute
bool parseAndSetAttribute(const char *, const char *) override
Definition
SkSVGUse.cpp:20
SkSVGUse::onPrepareToRender
bool onPrepareToRender(SkSVGRenderContext *) const override
Definition
SkSVGUse.cpp:27
SkSVGUse::appendChild
void appendChild(sk_sp< SkSVGNode >) override
Definition
SkSVGUse.cpp:16
sk_sp
Definition
SkRefCnt.h:220
SkScalar
float SkScalar
Definition
extension.cpp:12
y
double y
Definition
mouse-input-test.cc:83
x
double x
Definition
mouse-input-test.cc:82
SkRect
Definition
extension.cpp:13
SkRect::MakeEmpty
static constexpr SkRect MakeEmpty()
Definition
SkRect.h:595
Generated on Fri Apr 26 2024 06:16:31 for Flutter Engine by
1.9.8