1 | using System;
|
---|
2 | using System.Xml;
|
---|
3 |
|
---|
4 | namespace SharpVectors.Dom.Svg
|
---|
5 | {
|
---|
6 | public sealed class SvgPatternElement : SvgStyleableElement, ISvgPatternElement
|
---|
7 | {
|
---|
8 | #region Private Fields
|
---|
9 |
|
---|
10 | private ISvgAnimatedEnumeration patternUnits;
|
---|
11 | private ISvgAnimatedEnumeration patternContentUnits;
|
---|
12 | private ISvgAnimatedTransformList patternTransform;
|
---|
13 | private ISvgAnimatedLength x;
|
---|
14 | private ISvgAnimatedLength y;
|
---|
15 | private ISvgAnimatedLength width;
|
---|
16 | private ISvgAnimatedLength height;
|
---|
17 |
|
---|
18 | private SvgUriReference svgURIReference;
|
---|
19 | private SvgExternalResourcesRequired svgExternalResourcesRequired;
|
---|
20 | private SvgFitToViewBox svgFitToViewBox;
|
---|
21 | private SvgTests svgTests;
|
---|
22 |
|
---|
23 | #endregion
|
---|
24 |
|
---|
25 | #region Constructors and Destructor
|
---|
26 |
|
---|
27 | public SvgPatternElement(string prefix, string localname, string ns, SvgDocument doc)
|
---|
28 | : base(prefix, localname, ns, doc)
|
---|
29 | {
|
---|
30 | svgURIReference = new SvgUriReference(this);
|
---|
31 | svgExternalResourcesRequired = new SvgExternalResourcesRequired(this);
|
---|
32 | svgFitToViewBox = new SvgFitToViewBox(this);
|
---|
33 | svgTests = new SvgTests(this);
|
---|
34 | }
|
---|
35 |
|
---|
36 | #endregion
|
---|
37 |
|
---|
38 | #region Public Properties
|
---|
39 |
|
---|
40 | public XmlNodeList Children
|
---|
41 | {
|
---|
42 | get
|
---|
43 | {
|
---|
44 | XmlNodeList children = SelectNodes("svg:*", OwnerDocument.NamespaceManager);
|
---|
45 | if(children.Count > 0)
|
---|
46 | {
|
---|
47 | return children;
|
---|
48 | }
|
---|
49 | else
|
---|
50 | {
|
---|
51 | // check any eventually referenced gradient
|
---|
52 | if(ReferencedElement == null)
|
---|
53 | {
|
---|
54 | // return an empty list
|
---|
55 | return children;
|
---|
56 | }
|
---|
57 | else
|
---|
58 | {
|
---|
59 | return ReferencedElement.Children;
|
---|
60 | }
|
---|
61 | }
|
---|
62 | }
|
---|
63 | }
|
---|
64 |
|
---|
65 | #endregion
|
---|
66 |
|
---|
67 | #region ISvgElement Members
|
---|
68 |
|
---|
69 | /// <summary>
|
---|
70 | /// Gets a value indicating whether this SVG element is renderable.
|
---|
71 | /// </summary>
|
---|
72 | /// <value>
|
---|
73 | /// This is <see langword="'true"/> if the element is renderable; otherwise,
|
---|
74 | /// it is <see langword="false"/>.
|
---|
75 | /// </value>
|
---|
76 | public override bool IsRenderable
|
---|
77 | {
|
---|
78 | get
|
---|
79 | {
|
---|
80 | return false;
|
---|
81 | }
|
---|
82 | }
|
---|
83 |
|
---|
84 | /// <summary>
|
---|
85 | /// Gets a value providing a hint on the rendering defined by this element.
|
---|
86 | /// </summary>
|
---|
87 | /// <value>
|
---|
88 | /// An enumeration of the <see cref="SvgRenderingHint"/> specifying the rendering hint.
|
---|
89 | /// This will always return <see cref="SvgRenderingHint.Containment"/>
|
---|
90 | /// </value>
|
---|
91 | public override SvgRenderingHint RenderingHint
|
---|
92 | {
|
---|
93 | get
|
---|
94 | {
|
---|
95 | return SvgRenderingHint.Containment;
|
---|
96 | }
|
---|
97 | }
|
---|
98 |
|
---|
99 | #endregion
|
---|
100 |
|
---|
101 | #region ISvgPatternElement Members
|
---|
102 |
|
---|
103 | public ISvgAnimatedEnumeration PatternUnits
|
---|
104 | {
|
---|
105 | get
|
---|
106 | {
|
---|
107 | if(!HasAttribute("patternUnits") && ReferencedElement != null)
|
---|
108 | {
|
---|
109 | return ReferencedElement.PatternUnits;
|
---|
110 | }
|
---|
111 | else
|
---|
112 | {
|
---|
113 | if(patternUnits == null)
|
---|
114 | {
|
---|
115 | SvgUnitType type;
|
---|
116 | switch(GetAttribute("patternUnits"))
|
---|
117 | {
|
---|
118 | case "userSpaceOnUse":
|
---|
119 | type = SvgUnitType.UserSpaceOnUse;
|
---|
120 | break;
|
---|
121 | default:
|
---|
122 | type = SvgUnitType.ObjectBoundingBox;
|
---|
123 | break;
|
---|
124 | }
|
---|
125 | patternUnits = new SvgAnimatedEnumeration((ushort)type);
|
---|
126 | }
|
---|
127 | return patternUnits;
|
---|
128 | }
|
---|
129 | }
|
---|
130 | }
|
---|
131 |
|
---|
132 | public ISvgAnimatedEnumeration PatternContentUnits
|
---|
133 | {
|
---|
134 | get
|
---|
135 | {
|
---|
136 | if(!HasAttribute("patternContentUnits") && ReferencedElement != null)
|
---|
137 | {
|
---|
138 | return ReferencedElement.PatternContentUnits;
|
---|
139 | }
|
---|
140 | else
|
---|
141 | {
|
---|
142 | if(patternContentUnits == null)
|
---|
143 | {
|
---|
144 | SvgUnitType type;
|
---|
145 | switch(GetAttribute("patternContentUnits"))
|
---|
146 | {
|
---|
147 | case "objectBoundingBox":
|
---|
148 | type = SvgUnitType.ObjectBoundingBox;
|
---|
149 | break;
|
---|
150 | default:
|
---|
151 | type = SvgUnitType.UserSpaceOnUse;
|
---|
152 | break;
|
---|
153 | }
|
---|
154 | patternContentUnits = new SvgAnimatedEnumeration((ushort)type);
|
---|
155 | }
|
---|
156 | return patternContentUnits;
|
---|
157 | }
|
---|
158 | }
|
---|
159 | }
|
---|
160 |
|
---|
161 | public ISvgAnimatedTransformList PatternTransform
|
---|
162 | {
|
---|
163 | get
|
---|
164 | {
|
---|
165 | if(!HasAttribute("patternTransform") && ReferencedElement != null)
|
---|
166 | {
|
---|
167 | return ReferencedElement.PatternTransform;
|
---|
168 | }
|
---|
169 | else{
|
---|
170 | if(patternTransform == null)
|
---|
171 | {
|
---|
172 | patternTransform = new SvgAnimatedTransformList(GetAttribute("patternTransform"));
|
---|
173 | }
|
---|
174 | return patternTransform;
|
---|
175 | }
|
---|
176 | }
|
---|
177 | }
|
---|
178 |
|
---|
179 | public ISvgAnimatedLength X
|
---|
180 | {
|
---|
181 | get
|
---|
182 | {
|
---|
183 | if(!HasAttribute("x") && ReferencedElement != null)
|
---|
184 | {
|
---|
185 | return ReferencedElement.X;
|
---|
186 | }
|
---|
187 | else{
|
---|
188 | if(x == null)
|
---|
189 | {
|
---|
190 | x = new SvgAnimatedLength(this, "x", SvgLengthDirection.Horizontal, "0");
|
---|
191 | }
|
---|
192 | return x;
|
---|
193 | }
|
---|
194 | }
|
---|
195 | }
|
---|
196 |
|
---|
197 | public ISvgAnimatedLength Y
|
---|
198 | {
|
---|
199 | get
|
---|
200 | {
|
---|
201 | if(!HasAttribute("y") && ReferencedElement != null)
|
---|
202 | {
|
---|
203 | return ReferencedElement.Y;
|
---|
204 | }
|
---|
205 | else
|
---|
206 | {
|
---|
207 | if(y == null)
|
---|
208 | {
|
---|
209 | y = new SvgAnimatedLength(this, "y", SvgLengthDirection.Vertical, "0");
|
---|
210 | }
|
---|
211 | return y;
|
---|
212 | }
|
---|
213 | }
|
---|
214 | }
|
---|
215 |
|
---|
216 | public ISvgAnimatedLength Width
|
---|
217 | {
|
---|
218 | get
|
---|
219 | {
|
---|
220 | if(!HasAttribute("width") && ReferencedElement != null)
|
---|
221 | {
|
---|
222 | return ReferencedElement.Width;
|
---|
223 | }
|
---|
224 | else
|
---|
225 | {
|
---|
226 | if(width == null)
|
---|
227 | {
|
---|
228 | width = new SvgAnimatedLength(this, "width", SvgLengthDirection.Horizontal, "0");
|
---|
229 | }
|
---|
230 | return width;
|
---|
231 | }
|
---|
232 | }
|
---|
233 | }
|
---|
234 |
|
---|
235 | public ISvgAnimatedLength Height
|
---|
236 | {
|
---|
237 | get
|
---|
238 | {
|
---|
239 | if(!HasAttribute("height") && ReferencedElement != null)
|
---|
240 | {
|
---|
241 | return ReferencedElement.Height;
|
---|
242 | }
|
---|
243 | else
|
---|
244 | {
|
---|
245 | if(height == null)
|
---|
246 | {
|
---|
247 | height = new SvgAnimatedLength(this, "height", SvgLengthDirection.Vertical, "0");
|
---|
248 | }
|
---|
249 | return height;
|
---|
250 | }
|
---|
251 | }
|
---|
252 | }
|
---|
253 |
|
---|
254 | #endregion
|
---|
255 |
|
---|
256 | #region ISvgURIReference Members
|
---|
257 |
|
---|
258 | public ISvgAnimatedString Href
|
---|
259 | {
|
---|
260 | get
|
---|
261 | {
|
---|
262 | return svgURIReference.Href;
|
---|
263 | }
|
---|
264 | }
|
---|
265 |
|
---|
266 | public SvgPatternElement ReferencedElement
|
---|
267 | {
|
---|
268 | get
|
---|
269 | {
|
---|
270 | return svgURIReference.ReferencedNode as SvgPatternElement;
|
---|
271 | }
|
---|
272 | }
|
---|
273 |
|
---|
274 | #endregion
|
---|
275 |
|
---|
276 | #region ISvgExternalResourcesRequired Members
|
---|
277 |
|
---|
278 | public ISvgAnimatedBoolean ExternalResourcesRequired
|
---|
279 | {
|
---|
280 | get
|
---|
281 | {
|
---|
282 | return svgExternalResourcesRequired.ExternalResourcesRequired;
|
---|
283 | }
|
---|
284 | }
|
---|
285 |
|
---|
286 | #endregion
|
---|
287 |
|
---|
288 | #region ISvgFitToViewBox Members
|
---|
289 |
|
---|
290 | public ISvgAnimatedRect ViewBox
|
---|
291 | {
|
---|
292 | get
|
---|
293 | {
|
---|
294 | return svgFitToViewBox.ViewBox;
|
---|
295 | }
|
---|
296 | }
|
---|
297 |
|
---|
298 | public ISvgAnimatedPreserveAspectRatio PreserveAspectRatio
|
---|
299 | {
|
---|
300 | get
|
---|
301 | {
|
---|
302 | return svgFitToViewBox.PreserveAspectRatio;
|
---|
303 | }
|
---|
304 | }
|
---|
305 |
|
---|
306 | #endregion
|
---|
307 |
|
---|
308 | #region ISvgTests Members
|
---|
309 |
|
---|
310 | public ISvgStringList RequiredFeatures
|
---|
311 | {
|
---|
312 | get { return svgTests.RequiredFeatures; }
|
---|
313 | }
|
---|
314 |
|
---|
315 | public ISvgStringList RequiredExtensions
|
---|
316 | {
|
---|
317 | get { return svgTests.RequiredExtensions; }
|
---|
318 | }
|
---|
319 |
|
---|
320 | public ISvgStringList SystemLanguage
|
---|
321 | {
|
---|
322 | get { return svgTests.SystemLanguage; }
|
---|
323 | }
|
---|
324 |
|
---|
325 | public bool HasExtension(string extension)
|
---|
326 | {
|
---|
327 | return svgTests.HasExtension(extension);
|
---|
328 | }
|
---|
329 |
|
---|
330 | #endregion
|
---|
331 | }
|
---|
332 | }
|
---|