1 | using System;
|
---|
2 | using System.Xml;
|
---|
3 |
|
---|
4 | namespace SharpVectors.Dom.Svg
|
---|
5 | {
|
---|
6 | public sealed class SvgPathElement : SvgTransformableElement, ISvgPathElement, ISharpMarkerHost
|
---|
7 | {
|
---|
8 | #region Private Fields
|
---|
9 |
|
---|
10 | private ISvgAnimatedNumber _pathLength;
|
---|
11 | private SvgTests svgTests;
|
---|
12 |
|
---|
13 | private ISvgPathSegList pathSegList;
|
---|
14 |
|
---|
15 | #endregion
|
---|
16 |
|
---|
17 | #region Constructors and Destructor
|
---|
18 |
|
---|
19 | public SvgPathElement(string prefix, string localname, string ns, SvgDocument doc)
|
---|
20 | : base(prefix, localname, ns, doc)
|
---|
21 | {
|
---|
22 | svgTests = new SvgTests(this);
|
---|
23 | }
|
---|
24 |
|
---|
25 | #endregion
|
---|
26 |
|
---|
27 | #region Public Properties
|
---|
28 |
|
---|
29 | public string PathScript
|
---|
30 | {
|
---|
31 | get
|
---|
32 | {
|
---|
33 | return this.GetAttribute("d");
|
---|
34 | }
|
---|
35 | }
|
---|
36 |
|
---|
37 | #endregion
|
---|
38 |
|
---|
39 | #region Public Methods
|
---|
40 |
|
---|
41 | public void Invalidate()
|
---|
42 | {
|
---|
43 | }
|
---|
44 |
|
---|
45 | public override void HandleAttributeChange(XmlAttribute attribute)
|
---|
46 | {
|
---|
47 | if (attribute.NamespaceURI.Length == 0)
|
---|
48 | {
|
---|
49 | switch (attribute.LocalName)
|
---|
50 | {
|
---|
51 | case "d":
|
---|
52 | pathSegList = null;
|
---|
53 | Invalidate();
|
---|
54 | return;
|
---|
55 | case "pathLength":
|
---|
56 | _pathLength = null;
|
---|
57 | Invalidate();
|
---|
58 | return;
|
---|
59 | case "marker-start":
|
---|
60 | case "marker-mid":
|
---|
61 | case "marker-end":
|
---|
62 | // Color.attrib, Paint.attrib
|
---|
63 | case "color":
|
---|
64 | case "fill":
|
---|
65 | case "fill-rule":
|
---|
66 | case "stroke":
|
---|
67 | case "stroke-dasharray":
|
---|
68 | case "stroke-dashoffset":
|
---|
69 | case "stroke-linecap":
|
---|
70 | case "stroke-linejoin":
|
---|
71 | case "stroke-miterlimit":
|
---|
72 | case "stroke-width":
|
---|
73 | // Opacity.attrib
|
---|
74 | case "opacity":
|
---|
75 | case "stroke-opacity":
|
---|
76 | case "fill-opacity":
|
---|
77 | // Graphics.attrib
|
---|
78 | case "display":
|
---|
79 | case "image-rendering":
|
---|
80 | case "shape-rendering":
|
---|
81 | case "text-rendering":
|
---|
82 | case "visibility":
|
---|
83 | Invalidate();
|
---|
84 | break;
|
---|
85 | case "transform":
|
---|
86 | Invalidate();
|
---|
87 | break;
|
---|
88 | }
|
---|
89 | base.HandleAttributeChange(attribute);
|
---|
90 | }
|
---|
91 | }
|
---|
92 | #endregion
|
---|
93 |
|
---|
94 | #region ISvgElement Members
|
---|
95 |
|
---|
96 | /// <summary>
|
---|
97 | /// Gets a value providing a hint on the rendering defined by this element.
|
---|
98 | /// </summary>
|
---|
99 | /// <value>
|
---|
100 | /// An enumeration of the <see cref="SvgRenderingHint"/> specifying the rendering hint.
|
---|
101 | /// This will always return <see cref="SvgRenderingHint.Shape"/>
|
---|
102 | /// </value>
|
---|
103 | public override SvgRenderingHint RenderingHint
|
---|
104 | {
|
---|
105 | get
|
---|
106 | {
|
---|
107 | return SvgRenderingHint.Shape;
|
---|
108 | }
|
---|
109 | }
|
---|
110 |
|
---|
111 | #endregion
|
---|
112 |
|
---|
113 | #region ISharpMarkerHost Members
|
---|
114 |
|
---|
115 | public SvgPointF[] MarkerPositions
|
---|
116 | {
|
---|
117 | get
|
---|
118 | {
|
---|
119 | return ((SvgPathSegList)PathSegList).Points;
|
---|
120 | }
|
---|
121 | }
|
---|
122 |
|
---|
123 | public double GetStartAngle(int index)
|
---|
124 | {
|
---|
125 | return ((SvgPathSegList)PathSegList).GetStartAngle(index);
|
---|
126 | }
|
---|
127 |
|
---|
128 | public double GetEndAngle(int index)
|
---|
129 | {
|
---|
130 | return ((SvgPathSegList)PathSegList).GetEndAngle(index);
|
---|
131 | }
|
---|
132 |
|
---|
133 | #endregion
|
---|
134 |
|
---|
135 | #region ISvgPathElement Members
|
---|
136 |
|
---|
137 | public ISvgAnimatedBoolean ExternalResourcesRequired
|
---|
138 | {
|
---|
139 | get
|
---|
140 | {
|
---|
141 | throw new NotImplementedException();
|
---|
142 | }
|
---|
143 | }
|
---|
144 |
|
---|
145 | public ISvgPathSegList PathSegList
|
---|
146 | {
|
---|
147 | get
|
---|
148 | {
|
---|
149 | if (pathSegList == null)
|
---|
150 | {
|
---|
151 | pathSegList = new SvgPathSegList(this.GetAttribute("d"), false);
|
---|
152 | }
|
---|
153 | return pathSegList;
|
---|
154 | }
|
---|
155 | }
|
---|
156 |
|
---|
157 | public ISvgPathSegList NormalizedPathSegList
|
---|
158 | {
|
---|
159 | get { throw new NotImplementedException(); }
|
---|
160 | }
|
---|
161 |
|
---|
162 | public ISvgPathSegList AnimatedPathSegList
|
---|
163 | {
|
---|
164 | get { return PathSegList; }
|
---|
165 | }
|
---|
166 |
|
---|
167 | public ISvgPathSegList AnimatedNormalizedPathSegList
|
---|
168 | {
|
---|
169 | get { return NormalizedPathSegList; }
|
---|
170 | }
|
---|
171 |
|
---|
172 | public ISvgAnimatedNumber PathLength
|
---|
173 | {
|
---|
174 | get
|
---|
175 | {
|
---|
176 | if (_pathLength == null)
|
---|
177 | {
|
---|
178 | _pathLength = new SvgAnimatedNumber(GetAttribute("pathLength"));
|
---|
179 | }
|
---|
180 | return _pathLength;
|
---|
181 | }
|
---|
182 | }
|
---|
183 |
|
---|
184 | public double GetTotalLength()
|
---|
185 | {
|
---|
186 | return ((SvgPathSegList)PathSegList).GetTotalLength();
|
---|
187 | }
|
---|
188 |
|
---|
189 | public ISvgPoint GetPointAtLength(double distance)
|
---|
190 | {
|
---|
191 | throw new NotImplementedException();
|
---|
192 | }
|
---|
193 |
|
---|
194 |
|
---|
195 | public int GetPathSegAtLength(double distance)
|
---|
196 | {
|
---|
197 | return ((SvgPathSegList)PathSegList).GetPathSegAtLength(distance);
|
---|
198 | }
|
---|
199 |
|
---|
200 | #region Create methods
|
---|
201 |
|
---|
202 | public ISvgPathSegClosePath CreateSvgPathSegClosePath()
|
---|
203 | {
|
---|
204 | return new SvgPathSegClosePath();
|
---|
205 | }
|
---|
206 |
|
---|
207 | public ISvgPathSegMovetoAbs CreateSvgPathSegMovetoAbs(double x, double y)
|
---|
208 | {
|
---|
209 | return new SvgPathSegMovetoAbs(x, y);
|
---|
210 | }
|
---|
211 |
|
---|
212 | public ISvgPathSegMovetoRel CreateSvgPathSegMovetoRel(double x, double y)
|
---|
213 | {
|
---|
214 | return new SvgPathSegMovetoRel(x, y);
|
---|
215 | }
|
---|
216 |
|
---|
217 | public ISvgPathSegLinetoAbs CreateSvgPathSegLinetoAbs(double x, double y)
|
---|
218 | {
|
---|
219 | return new SvgPathSegLinetoAbs(x, y);
|
---|
220 | }
|
---|
221 |
|
---|
222 | public ISvgPathSegLinetoRel CreateSvgPathSegLinetoRel(double x, double y)
|
---|
223 | {
|
---|
224 | return new SvgPathSegLinetoRel(x, y);
|
---|
225 | }
|
---|
226 |
|
---|
227 | public ISvgPathSegCurvetoCubicAbs CreateSvgPathSegCurvetoCubicAbs(
|
---|
228 | double x, double y, double x1, double y1, double x2, double y2)
|
---|
229 | {
|
---|
230 | return new SvgPathSegCurvetoCubicAbs(x, y, x1, y1, x2, y2);
|
---|
231 | }
|
---|
232 |
|
---|
233 | public ISvgPathSegCurvetoCubicRel CreateSvgPathSegCurvetoCubicRel(
|
---|
234 | double x, double y, double x1, double y1, double x2, double y2)
|
---|
235 | {
|
---|
236 | return new SvgPathSegCurvetoCubicRel(x, y, x1, y1, x2, y2);
|
---|
237 | }
|
---|
238 |
|
---|
239 |
|
---|
240 | public ISvgPathSegCurvetoQuadraticAbs CreateSvgPathSegCurvetoQuadraticAbs(
|
---|
241 | double x, double y, double x1, double y1)
|
---|
242 | {
|
---|
243 | return new SvgPathSegCurvetoQuadraticAbs(x, y, x1, y1);
|
---|
244 | }
|
---|
245 |
|
---|
246 |
|
---|
247 | public ISvgPathSegCurvetoQuadraticRel CreateSvgPathSegCurvetoQuadraticRel(
|
---|
248 | double x, double y, double x1, double y1)
|
---|
249 | {
|
---|
250 | return new SvgPathSegCurvetoQuadraticRel(x, y, x1, y1);
|
---|
251 | }
|
---|
252 |
|
---|
253 | public ISvgPathSegArcAbs CreateSvgPathSegArcAbs(double x, double y,
|
---|
254 | double r1, double r2, double angle, bool largeArcFlag, bool sweepFlag)
|
---|
255 | {
|
---|
256 | return new SvgPathSegArcAbs(x, y, r1, r2, angle, largeArcFlag, sweepFlag);
|
---|
257 | }
|
---|
258 |
|
---|
259 | public ISvgPathSegArcRel CreateSvgPathSegArcRel(double x, double y,
|
---|
260 | double r1, double r2, double angle, bool largeArcFlag, bool sweepFlag)
|
---|
261 | {
|
---|
262 | return new SvgPathSegArcRel(x, y, r1, r2, angle, largeArcFlag, sweepFlag);
|
---|
263 | }
|
---|
264 |
|
---|
265 | public ISvgPathSegLinetoHorizontalAbs CreateSvgPathSegLinetoHorizontalAbs(double x)
|
---|
266 | {
|
---|
267 | return new SvgPathSegLinetoHorizontalAbs(x);
|
---|
268 | }
|
---|
269 |
|
---|
270 | public ISvgPathSegLinetoHorizontalRel CreateSvgPathSegLinetoHorizontalRel(double x)
|
---|
271 | {
|
---|
272 | return new SvgPathSegLinetoHorizontalRel(x);
|
---|
273 | }
|
---|
274 |
|
---|
275 | public ISvgPathSegLinetoVerticalAbs CreateSvgPathSegLinetoVerticalAbs(double y)
|
---|
276 | {
|
---|
277 | return new SvgPathSegLinetoVerticalAbs(y);
|
---|
278 | }
|
---|
279 |
|
---|
280 | public ISvgPathSegLinetoVerticalRel CreateSvgPathSegLinetoVerticalRel(double y)
|
---|
281 | {
|
---|
282 | return new SvgPathSegLinetoVerticalRel(y);
|
---|
283 | }
|
---|
284 |
|
---|
285 | public ISvgPathSegCurvetoCubicSmoothAbs CreateSvgPathSegCurvetoCubicSmoothAbs(
|
---|
286 | double x, double y, double x2, double y2)
|
---|
287 | {
|
---|
288 | return new SvgPathSegCurvetoCubicSmoothAbs(x, y, x2, y2);
|
---|
289 | }
|
---|
290 |
|
---|
291 | public ISvgPathSegCurvetoCubicSmoothRel CreateSvgPathSegCurvetoCubicSmoothRel(
|
---|
292 | double x, double y, double x2, double y2)
|
---|
293 | {
|
---|
294 | return new SvgPathSegCurvetoCubicSmoothRel(x, y, x2, y2);
|
---|
295 | }
|
---|
296 |
|
---|
297 | public ISvgPathSegCurvetoQuadraticSmoothAbs CreateSvgPathSegCurvetoQuadraticSmoothAbs(
|
---|
298 | double x, double y)
|
---|
299 | {
|
---|
300 | return new SvgPathSegCurvetoQuadraticSmoothAbs(x, y);
|
---|
301 | }
|
---|
302 |
|
---|
303 | public ISvgPathSegCurvetoQuadraticSmoothRel CreateSvgPathSegCurvetoQuadraticSmoothRel(
|
---|
304 | double x, double y)
|
---|
305 | {
|
---|
306 | return new SvgPathSegCurvetoQuadraticSmoothRel(x, y);
|
---|
307 | }
|
---|
308 |
|
---|
309 | #endregion
|
---|
310 |
|
---|
311 | #endregion
|
---|
312 |
|
---|
313 | #region ISvgTests Members
|
---|
314 |
|
---|
315 | public ISvgStringList RequiredFeatures
|
---|
316 | {
|
---|
317 | get { return svgTests.RequiredFeatures; }
|
---|
318 | }
|
---|
319 |
|
---|
320 | public ISvgStringList RequiredExtensions
|
---|
321 | {
|
---|
322 | get { return svgTests.RequiredExtensions; }
|
---|
323 | }
|
---|
324 |
|
---|
325 | public ISvgStringList SystemLanguage
|
---|
326 | {
|
---|
327 | get { return svgTests.SystemLanguage; }
|
---|
328 | }
|
---|
329 |
|
---|
330 | public bool HasExtension(string extension)
|
---|
331 | {
|
---|
332 | return svgTests.HasExtension(extension);
|
---|
333 | }
|
---|
334 |
|
---|
335 | #endregion
|
---|
336 | }
|
---|
337 | }
|
---|