Flutter Engine
The Flutter Engine
Public Member Functions | Protected Member Functions | Static Protected Member Functions | List of all members
SkSVGNode Class Referenceabstract

#include <SkSVGNode.h>

Inheritance diagram for SkSVGNode:
SkRefCnt SkRefCntBase SkSVGTransformableNode SkSVGContainer SkSVGImage SkSVGShape SkSVGTextFragment SkSVGUse SkSVGG SkSVGHiddenContainer SkSVGSVG SkSVGCircle SkSVGEllipse SkSVGLine SkSVGPath SkSVGPoly SkSVGRect SkSVGTextContainer SkSVGTextLiteral

Public Member Functions

 ~SkSVGNode () override
 
SkSVGTag tag () const
 
virtual void appendChild (sk_sp< SkSVGNode >)=0
 
void render (const SkSVGRenderContext &) const
 
bool asPaint (const SkSVGRenderContext &, SkPaint *) const
 
SkPath asPath (const SkSVGRenderContext &) const
 
SkRect objectBoundingBox (const SkSVGRenderContext &) const
 
void setAttribute (SkSVGAttribute, const SkSVGValue &)
 
bool setAttribute (const char *attributeName, const char *attributeValue)
 
virtual bool parseAndSetAttribute (const char *name, const char *value)
 
- Public Member Functions inherited from SkRefCntBase
 SkRefCntBase ()
 
virtual ~SkRefCntBase ()
 
bool unique () const
 
void ref () const
 
void unref () const
 

Protected Member Functions

 SkSVGNode (SkSVGTag)
 
virtual bool onPrepareToRender (SkSVGRenderContext *) const
 
virtual void onRender (const SkSVGRenderContext &) const =0
 
virtual bool onAsPaint (const SkSVGRenderContext &, SkPaint *) const
 
virtual SkPath onAsPath (const SkSVGRenderContext &) const =0
 
virtual void onSetAttribute (SkSVGAttribute, const SkSVGValue &)
 
virtual bool hasChildren () const
 
virtual SkRect onObjectBoundingBox (const SkSVGRenderContext &) const
 

Static Protected Member Functions

static SkMatrix ComputeViewboxMatrix (const SkRect &, const SkRect &, SkSVGPreserveAspectRatio)
 

Detailed Description

Definition at line 102 of file SkSVGNode.h.

Constructor & Destructor Documentation

◆ ~SkSVGNode()

SkSVGNode::~SkSVGNode ( )
override

Definition at line 26 of file SkSVGNode.cpp.

26{ }

◆ SkSVGNode()

SkSVGNode::SkSVGNode ( SkSVGTag  t)
protected

Definition at line 17 of file SkSVGNode.cpp.

17 : fTag(t) {
18 // Uninherited presentation attributes need a non-null default value.
19 fPresentationAttributes.fStopColor.set(SkSVGColor(SK_ColorBLACK));
20 fPresentationAttributes.fStopOpacity.set(SkSVGNumberType(1.0f));
21 fPresentationAttributes.fFloodColor.set(SkSVGColor(SK_ColorBLACK));
22 fPresentationAttributes.fFloodOpacity.set(SkSVGNumberType(1.0f));
23 fPresentationAttributes.fLightingColor.set(SkSVGColor(SK_ColorWHITE));
24}
constexpr SkColor SK_ColorBLACK
Definition: SkColor.h:103
constexpr SkColor SK_ColorWHITE
Definition: SkColor.h:122
SkScalar SkSVGNumberType
Definition: SkSVGTypes.h:27
void set(SkSVGPropertyState state)
Definition: SkSVGTypes.h:70
SkSVGProperty< SkSVGColor, false > fLightingColor
SkSVGProperty< SkSVGColor, false > fStopColor
SkSVGProperty< SkSVGNumberType, false > fFloodOpacity
SkSVGProperty< SkSVGColor, false > fFloodColor
SkSVGProperty< SkSVGNumberType, false > fStopOpacity

Member Function Documentation

◆ appendChild()

virtual void SkSVGNode::appendChild ( sk_sp< SkSVGNode )
pure virtual

◆ asPaint()

bool SkSVGNode::asPaint ( const SkSVGRenderContext ctx,
SkPaint paint 
) const

Definition at line 36 of file SkSVGNode.cpp.

36 {
37 SkSVGRenderContext localContext(ctx);
38
39 return this->onPrepareToRender(&localContext) && this->onAsPaint(localContext, paint);
40}
virtual bool onAsPaint(const SkSVGRenderContext &, SkPaint *) const
Definition: SkSVGNode.h:171
virtual bool onPrepareToRender(SkSVGRenderContext *) const
Definition: SkSVGNode.cpp:62
const Paint & paint
Definition: color_source.cc:38

◆ asPath()

SkPath SkSVGNode::asPath ( const SkSVGRenderContext ctx) const

Definition at line 42 of file SkSVGNode.cpp.

42 {
43 SkSVGRenderContext localContext(ctx);
44 if (!this->onPrepareToRender(&localContext)) {
45 return SkPath();
46 }
47
48 SkPath path = this->onAsPath(localContext);
49
50 if (const auto* clipPath = localContext.clipPath()) {
51 // There is a clip-path present on the current node.
53 }
54
55 return path;
56}
@ kIntersect_SkPathOp
intersect the two paths
Definition: SkPathOps.h:24
Definition: SkPath.h:59
virtual SkPath onAsPath(const SkSVGRenderContext &) const =0
clipPath(r.path, r.opAA.op(), r.opAA.aa())) DRAW(ClipRRect
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir path
Definition: switches.h:57

◆ ComputeViewboxMatrix()

SkMatrix SkSVGNode::ComputeViewboxMatrix ( const SkRect viewBox,
const SkRect viewPort,
SkSVGPreserveAspectRatio  par 
)
staticprotected

Definition at line 132 of file SkSVGNode.cpp.

134 {
135 if (viewBox.isEmpty() || viewPort.isEmpty()) {
136 return SkMatrix::Scale(0, 0);
137 }
138
139 auto compute_scale = [&]() -> SkV2 {
140 const auto sx = viewPort.width() / viewBox.width(),
141 sy = viewPort.height() / viewBox.height();
142
144 // none -> anisotropic scaling, regardless of fScale
145 return {sx, sy};
146 }
147
148 // isotropic scaling
149 const auto s = par.fScale == SkSVGPreserveAspectRatio::kMeet
150 ? std::min(sx, sy)
151 : std::max(sx, sy);
152 return {s, s};
153 };
154
155 auto compute_trans = [&](const SkV2& scale) -> SkV2 {
156 static constexpr float gAlignCoeffs[] = {
157 0.0f, // Min
158 0.5f, // Mid
159 1.0f // Max
160 };
161
162 const size_t x_coeff = par.fAlign >> 0 & 0x03,
163 y_coeff = par.fAlign >> 2 & 0x03;
164
165 SkASSERT(x_coeff < std::size(gAlignCoeffs) &&
166 y_coeff < std::size(gAlignCoeffs));
167
168 const auto tx = -viewBox.x() * scale.x,
169 ty = -viewBox.y() * scale.y,
170 dx = viewPort.width() - viewBox.width() * scale.x,
171 dy = viewPort.height() - viewBox.height() * scale.y;
172
173 return {
174 tx + dx * gAlignCoeffs[x_coeff],
175 ty + dy * gAlignCoeffs[y_coeff]
176 };
177 };
178
179 const auto s = compute_scale(),
180 t = compute_trans(s);
181
182 return SkMatrix::Translate(t.x, t.y) *
184}
#define SkASSERT(cond)
Definition: SkAssert.h:116
static SkMatrix Scale(SkScalar sx, SkScalar sy)
Definition: SkMatrix.h:75
static SkMatrix Translate(SkScalar dx, SkScalar dy)
Definition: SkMatrix.h:91
struct MyStruct s
static float max(float r, float g, float b)
Definition: hsl.cpp:49
static float min(float r, float g, float b)
Definition: hsl.cpp:48
skia_private::AutoTArray< sk_sp< SkImageFilter > > filters TypedMatrix matrix TypedMatrix matrix SkScalar dx
Definition: SkRecords.h:208
it will be possible to load the file into Perfetto s trace viewer disable asset Prevents usage of any non test fonts unless they were explicitly Loaded via prefetched default font Indicates whether the embedding started a prefetch of the default font manager before creating the engine run In non interactive keep the shell running after the Dart script has completed enable serial On low power devices with low core running concurrent GC tasks on threads can cause them to contend with the UI thread which could potentially lead to jank This option turns off all concurrent GC activities domain network JSON encoded network policy per domain This overrides the DisallowInsecureConnections switch Embedder can specify whether to allow or disallow insecure connections at a domain level old gen heap size
Definition: switches.h:259
Definition: ref_ptr.h:256
const Scalar scale
constexpr float x() const
Definition: SkRect.h:720
constexpr float y() const
Definition: SkRect.h:727
constexpr float height() const
Definition: SkRect.h:769
constexpr float width() const
Definition: SkRect.h:762
bool isEmpty() const
Definition: SkRect.h:693
Definition: SkM44.h:19

◆ hasChildren()

virtual bool SkSVGNode::hasChildren ( ) const
inlineprotectedvirtual

Reimplemented in SkSVGContainer.

Definition at line 177 of file SkSVGNode.h.

177{ return false; }

◆ objectBoundingBox()

SkRect SkSVGNode::objectBoundingBox ( const SkSVGRenderContext ctx) const

Definition at line 58 of file SkSVGNode.cpp.

58 {
59 return this->onObjectBoundingBox(ctx);
60}
virtual SkRect onObjectBoundingBox(const SkSVGRenderContext &) const
Definition: SkSVGNode.h:179

◆ onAsPaint()

virtual bool SkSVGNode::onAsPaint ( const SkSVGRenderContext ,
SkPaint  
) const
inlineprotectedvirtual

Reimplemented in SkSVGGradient, and SkSVGPattern.

Definition at line 171 of file SkSVGNode.h.

171{ return false; }

◆ onAsPath()

virtual SkPath SkSVGNode::onAsPath ( const SkSVGRenderContext ) const
protectedpure virtual

◆ onObjectBoundingBox()

virtual SkRect SkSVGNode::onObjectBoundingBox ( const SkSVGRenderContext ) const
inlineprotectedvirtual

Reimplemented in SkSVGCircle, SkSVGContainer, SkSVGImage, SkSVGPath, SkSVGPoly, SkSVGRect, and SkSVGUse.

Definition at line 179 of file SkSVGNode.h.

179 {
180 return SkRect::MakeEmpty();
181 }
static constexpr SkRect MakeEmpty()
Definition: SkRect.h:595

◆ onPrepareToRender()

bool SkSVGNode::onPrepareToRender ( SkSVGRenderContext ctx) const
protectedvirtual

Reimplemented in SkSVGImage, SkSVGSVG, SkSVGTransformableNode, and SkSVGUse.

Definition at line 62 of file SkSVGNode.cpp.

62 {
63 ctx->applyPresentationAttributes(fPresentationAttributes,
65
66 // visibility:hidden and display:none disable rendering.
67 // TODO: if display is not a value (true when display="inherit"), we currently
68 // ignore it. Eventually we should be able to add SkASSERT(display.isValue()).
69 const auto visibility = ctx->presentationContext().fInherited.fVisibility->type();
70 const auto display = fPresentationAttributes.fDisplay; // display is uninherited
71 return visibility != SkSVGVisibility::Type::kHidden &&
72 (!display.isValue() || *display != SkSVGDisplay::kNone);
73}
virtual bool hasChildren() const
Definition: SkSVGNode.h:177
const SkSVGPresentationContext & presentationContext() const
void applyPresentationAttributes(const SkSVGPresentationAttributes &, uint32_t flags)
Type type() const
Definition: SkSVGTypes.h:388
SkSVGProperty< SkSVGDisplay, false > fDisplay
SkSVGProperty< SkSVGVisibility, true > fVisibility
SkSVGPresentationAttributes fInherited

◆ onRender()

virtual void SkSVGNode::onRender ( const SkSVGRenderContext ) const
protectedpure virtual

◆ onSetAttribute()

virtual void SkSVGNode::onSetAttribute ( SkSVGAttribute  ,
const SkSVGValue  
)
inlineprotectedvirtual

Reimplemented in SkSVGSVG, and SkSVGTransformableNode.

Definition at line 175 of file SkSVGNode.h.

175{}

◆ parseAndSetAttribute()

bool SkSVGNode::parseAndSetAttribute ( const char *  name,
const char *  value 
)
virtual

Reimplemented in SkSVGCircle, SkSVGClipPath, SkSVGEllipse, SkSVGFe, SkSVGFeBlend, SkSVGFeColorMatrix, SkSVGFeFunc, SkSVGFeComposite, SkSVGFeDisplacementMap, SkSVGFeGaussianBlur, SkSVGFeImage, SkSVGFeLighting, SkSVGFeSpecularLighting, SkSVGFeDiffuseLighting, SkSVGFeMergeNode, SkSVGFeMorphology, SkSVGFeOffset, SkSVGFeTurbulence, SkSVGFilter, SkSVGGradient, SkSVGImage, SkSVGLine, SkSVGLinearGradient, SkSVGMask, SkSVGPath, SkSVGPattern, SkSVGPoly, SkSVGRadialGradient, SkSVGRect, SkSVGStop, and SkSVGTextContainer.

Definition at line 90 of file SkSVGNode.cpp.

90 {
91#define PARSE_AND_SET(svgName, attrName) \
92 this->set##attrName( \
93 SkSVGAttributeParser::parseProperty<decltype(fPresentationAttributes.f##attrName)>( \
94 svgName, n, v))
95
96 return PARSE_AND_SET( "clip-path" , ClipPath)
97 || PARSE_AND_SET("clip-rule" , ClipRule)
98 || PARSE_AND_SET("color" , Color)
99 || PARSE_AND_SET("color-interpolation" , ColorInterpolation)
100 || PARSE_AND_SET("color-interpolation-filters", ColorInterpolationFilters)
101 || PARSE_AND_SET("display" , Display)
102 || PARSE_AND_SET("fill" , Fill)
103 || PARSE_AND_SET("fill-opacity" , FillOpacity)
104 || PARSE_AND_SET("fill-rule" , FillRule)
105 || PARSE_AND_SET("filter" , Filter)
106 || PARSE_AND_SET("flood-color" , FloodColor)
107 || PARSE_AND_SET("flood-opacity" , FloodOpacity)
108 || PARSE_AND_SET("font-family" , FontFamily)
109 || PARSE_AND_SET("font-size" , FontSize)
110 || PARSE_AND_SET("font-style" , FontStyle)
111 || PARSE_AND_SET("font-weight" , FontWeight)
112 || PARSE_AND_SET("lighting-color" , LightingColor)
113 || PARSE_AND_SET("mask" , Mask)
114 || PARSE_AND_SET("opacity" , Opacity)
115 || PARSE_AND_SET("stop-color" , StopColor)
116 || PARSE_AND_SET("stop-opacity" , StopOpacity)
117 || PARSE_AND_SET("stroke" , Stroke)
118 || PARSE_AND_SET("stroke-dasharray" , StrokeDashArray)
119 || PARSE_AND_SET("stroke-dashoffset" , StrokeDashOffset)
120 || PARSE_AND_SET("stroke-linecap" , StrokeLineCap)
121 || PARSE_AND_SET("stroke-linejoin" , StrokeLineJoin)
122 || PARSE_AND_SET("stroke-miterlimit" , StrokeMiterLimit)
123 || PARSE_AND_SET("stroke-opacity" , StrokeOpacity)
124 || PARSE_AND_SET("stroke-width" , StrokeWidth)
125 || PARSE_AND_SET("text-anchor" , TextAnchor)
126 || PARSE_AND_SET("visibility" , Visibility);
127
128#undef PARSE_AND_SET
129}
#define PARSE_AND_SET(svgName, attrName)
SkFilterMode
SK_API sk_sp< SkShader > Color(SkColor)
FontWeight
Definition: font_weight.h:22
FontStyle
Definition: font_style.h:22

◆ render()

void SkSVGNode::render ( const SkSVGRenderContext ctx) const

Definition at line 28 of file SkSVGNode.cpp.

28 {
29 SkSVGRenderContext localContext(ctx, this);
30
31 if (this->onPrepareToRender(&localContext)) {
32 this->onRender(localContext);
33 }
34}
virtual void onRender(const SkSVGRenderContext &) const =0

◆ setAttribute() [1/2]

bool SkSVGNode::setAttribute ( const char *  attributeName,
const char *  attributeValue 
)

Definition at line 508 of file SkSVGDOM.cpp.

508 {
509 return set_string_attribute(sk_ref_sp(this), attributeName, attributeValue);
510}
sk_sp< T > sk_ref_sp(T *obj)
Definition: SkRefCnt.h:381

◆ setAttribute() [2/2]

void SkSVGNode::setAttribute ( SkSVGAttribute  attr,
const SkSVGValue v 
)

Definition at line 75 of file SkSVGNode.cpp.

75 {
76 this->onSetAttribute(attr, v);
77}
virtual void onSetAttribute(SkSVGAttribute, const SkSVGValue &)
Definition: SkSVGNode.h:175

◆ tag()

SkSVGTag SkSVGNode::tag ( ) const
inline

Definition at line 106 of file SkSVGNode.h.

106{ return fTag; }

The documentation for this class was generated from the following files: