Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
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
9
13
14SkSVGUse::SkSVGUse() : INHERITED(SkSVGTag::kUse) {}
15
17 SkDebugf("cannot append child nodes to this element.\n");
18}
19
20bool SkSVGUse::parseAndSetAttribute(const char* n, const char* 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
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
43void 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
53 const auto ref = ctx.findNodeById(fHref);
54 if (!ref) {
55 return SkPath();
56 }
57
58 return ref->asPath(ctx);
59}
60
62 const auto ref = ctx.findNodeById(fHref);
63 if (!ref) {
64 return SkRect::MakeEmpty();
65 }
66
67 const SkSVGLengthContext& lctx = ctx.lengthContext();
70
71 SkRect bounds = ref->objectBoundingBox(ctx);
72 bounds.offset(x, y);
73
74 return bounds;
75}
void SK_SPI SkDebugf(const char format[],...) SK_PRINTF_LIKE(1
#define INHERITED(method,...)
SkSVGTag
Definition SkSVGNode.h:23
void translate(SkScalar dx, SkScalar dy)
void ref() const
Definition SkRefCnt.h:62
SkScalar resolve(const SkSVGLength &, LengthType) const
void render(const SkSVGRenderContext &) const
Definition SkSVGNode.cpp:28
virtual bool parseAndSetAttribute(const char *name, const char *value)
Definition SkSVGNode.cpp:90
BorrowedNode findNodeById(const SkSVGIRI &) const
SkCanvas * canvas() const
const SkSVGLengthContext & lengthContext() const
bool onPrepareToRender(SkSVGRenderContext *) const override
void onRender(const SkSVGRenderContext &) const override
Definition SkSVGUse.cpp:43
SkRect onObjectBoundingBox(const SkSVGRenderContext &) const override
Definition SkSVGUse.cpp:61
SkPath onAsPath(const SkSVGRenderContext &) const override
Definition SkSVGUse.cpp:52
bool parseAndSetAttribute(const char *, const char *) override
Definition SkSVGUse.cpp:20
bool onPrepareToRender(SkSVGRenderContext *) const override
Definition SkSVGUse.cpp:27
void appendChild(sk_sp< SkSVGNode >) override
Definition SkSVGUse.cpp:16
float SkScalar
Definition extension.cpp:12
double y
double x
static constexpr SkRect MakeEmpty()
Definition SkRect.h:595