[12762] | 1 | using System;
|
---|
| 2 | using System.Xml;
|
---|
| 3 |
|
---|
| 4 | namespace SharpVectors.Dom.Svg
|
---|
| 5 | {
|
---|
| 6 | public enum SvgSpreadMethod
|
---|
| 7 | {
|
---|
| 8 | Pad = 0,
|
---|
| 9 | Reflect = 1,
|
---|
| 10 | Repeat = 2,
|
---|
| 11 | None = 3,
|
---|
| 12 | }
|
---|
| 13 |
|
---|
| 14 | public abstract class SvgGradientElement : SvgStyleableElement, ISvgGradientElement
|
---|
| 15 | {
|
---|
| 16 |
|
---|
| 17 | private ISvgAnimatedEnumeration gradientUnits;
|
---|
| 18 | private ISvgAnimatedEnumeration spreadMethod;
|
---|
| 19 | private ISvgAnimatedTransformList gradientTransform;
|
---|
| 20 |
|
---|
| 21 | protected SvgGradientElement(string prefix, string localname, string ns, SvgDocument doc)
|
---|
| 22 | : base(prefix, localname, ns, doc)
|
---|
| 23 | {
|
---|
| 24 | svgURIReference = new SvgUriReference(this);
|
---|
| 25 | svgExternalResourcesRequired = new SvgExternalResourcesRequired(this);
|
---|
| 26 | }
|
---|
| 27 |
|
---|
| 28 | #region ISvgGradientElement Members
|
---|
| 29 |
|
---|
| 30 | public ISvgAnimatedEnumeration GradientUnits
|
---|
| 31 | {
|
---|
| 32 | get
|
---|
| 33 | {
|
---|
| 34 | if (!HasAttribute("gradientUnits") && ReferencedElement != null)
|
---|
| 35 | {
|
---|
| 36 | return ReferencedElement.GradientUnits;
|
---|
| 37 | }
|
---|
| 38 | else
|
---|
| 39 | {
|
---|
| 40 | if(gradientUnits == null)
|
---|
| 41 | {
|
---|
| 42 | SvgUnitType gradUnit;
|
---|
| 43 | switch(GetAttribute("gradientUnits"))
|
---|
| 44 | {
|
---|
| 45 | case "userSpaceOnUse":
|
---|
| 46 | gradUnit = SvgUnitType.UserSpaceOnUse;
|
---|
| 47 | break;
|
---|
| 48 | default:
|
---|
| 49 | gradUnit = SvgUnitType.ObjectBoundingBox;
|
---|
| 50 | break;
|
---|
| 51 | }
|
---|
| 52 |
|
---|
| 53 | gradientUnits = new SvgAnimatedEnumeration((ushort)gradUnit);
|
---|
| 54 | }
|
---|
| 55 | return gradientUnits;
|
---|
| 56 | }
|
---|
| 57 | }
|
---|
| 58 | }
|
---|
| 59 |
|
---|
| 60 | public ISvgAnimatedTransformList GradientTransform
|
---|
| 61 | {
|
---|
| 62 | get
|
---|
| 63 | {
|
---|
| 64 | if (!HasAttribute("gradientTransform") && ReferencedElement != null)
|
---|
| 65 | {
|
---|
| 66 | return ReferencedElement.GradientTransform;
|
---|
| 67 | }
|
---|
| 68 | else
|
---|
| 69 | {
|
---|
| 70 | if (gradientTransform == null)
|
---|
| 71 | {
|
---|
| 72 | gradientTransform = new SvgAnimatedTransformList(GetAttribute("gradientTransform"));
|
---|
| 73 | }
|
---|
| 74 |
|
---|
| 75 | return gradientTransform;
|
---|
| 76 | }
|
---|
| 77 | }
|
---|
| 78 | }
|
---|
| 79 |
|
---|
| 80 | public ISvgAnimatedEnumeration SpreadMethod
|
---|
| 81 | {
|
---|
| 82 | get
|
---|
| 83 | {
|
---|
| 84 | if (!HasAttribute("spreadMethod") && ReferencedElement != null)
|
---|
| 85 | {
|
---|
| 86 | return ReferencedElement.SpreadMethod;
|
---|
| 87 | }
|
---|
| 88 | else
|
---|
| 89 | {
|
---|
| 90 | if (spreadMethod == null)
|
---|
| 91 | {
|
---|
| 92 | SvgSpreadMethod spreadMeth;
|
---|
| 93 | switch (GetAttribute("spreadMethod"))
|
---|
| 94 | {
|
---|
| 95 | case "pad":
|
---|
| 96 | spreadMeth = SvgSpreadMethod.Pad;
|
---|
| 97 | break;
|
---|
| 98 | case "reflect":
|
---|
| 99 | spreadMeth = SvgSpreadMethod.Reflect;
|
---|
| 100 | break;
|
---|
| 101 | case "repeat":
|
---|
| 102 | spreadMeth = SvgSpreadMethod.Repeat;
|
---|
| 103 | break;
|
---|
| 104 | default:
|
---|
| 105 | spreadMeth = SvgSpreadMethod.None;
|
---|
| 106 | break;
|
---|
| 107 | }
|
---|
| 108 |
|
---|
| 109 | spreadMethod = new SvgAnimatedEnumeration((ushort)spreadMeth);
|
---|
| 110 | }
|
---|
| 111 |
|
---|
| 112 | return spreadMethod;
|
---|
| 113 | }
|
---|
| 114 | }
|
---|
| 115 | }
|
---|
| 116 |
|
---|
| 117 | #endregion
|
---|
| 118 |
|
---|
| 119 | #region ISvgURIReference Members
|
---|
| 120 |
|
---|
| 121 | private SvgUriReference svgURIReference;
|
---|
| 122 | public ISvgAnimatedString Href
|
---|
| 123 | {
|
---|
| 124 | get
|
---|
| 125 | {
|
---|
| 126 | return svgURIReference.Href;
|
---|
| 127 | }
|
---|
| 128 | }
|
---|
| 129 |
|
---|
| 130 | public SvgGradientElement ReferencedElement
|
---|
| 131 | {
|
---|
| 132 | get
|
---|
| 133 | {
|
---|
| 134 | return svgURIReference.ReferencedNode as SvgGradientElement;
|
---|
| 135 | }
|
---|
| 136 | }
|
---|
| 137 |
|
---|
| 138 | #endregion
|
---|
| 139 |
|
---|
| 140 | #region ISvgExternalResourcesRequired Members
|
---|
| 141 |
|
---|
| 142 | private SvgExternalResourcesRequired svgExternalResourcesRequired;
|
---|
| 143 | public ISvgAnimatedBoolean ExternalResourcesRequired
|
---|
| 144 | {
|
---|
| 145 | get
|
---|
| 146 | {
|
---|
| 147 | return svgExternalResourcesRequired.ExternalResourcesRequired;
|
---|
| 148 | }
|
---|
| 149 | }
|
---|
| 150 |
|
---|
| 151 | #endregion
|
---|
| 152 |
|
---|
| 153 | #region Public Properties
|
---|
| 154 |
|
---|
| 155 | public XmlNodeList Stops
|
---|
| 156 | {
|
---|
| 157 | get
|
---|
| 158 | {
|
---|
| 159 | XmlNodeList stops = SelectNodes("svg:stop", OwnerDocument.NamespaceManager);
|
---|
| 160 | if(stops.Count > 0)
|
---|
| 161 | {
|
---|
| 162 | return stops;
|
---|
| 163 | }
|
---|
| 164 | else
|
---|
| 165 | {
|
---|
| 166 | // check any eventually referenced gradient
|
---|
| 167 | if(ReferencedElement == null)
|
---|
| 168 | {
|
---|
| 169 | // return an empty list
|
---|
| 170 | return stops;
|
---|
| 171 | }
|
---|
| 172 | else
|
---|
| 173 | {
|
---|
| 174 | return ReferencedElement.Stops;
|
---|
| 175 | }
|
---|
| 176 | }
|
---|
| 177 | }
|
---|
| 178 | }
|
---|
| 179 |
|
---|
| 180 | #endregion
|
---|
| 181 |
|
---|
| 182 | #region Update handling
|
---|
| 183 |
|
---|
| 184 | public override void HandleAttributeChange(XmlAttribute attribute)
|
---|
| 185 | {
|
---|
| 186 | if (attribute.NamespaceURI.Length == 0)
|
---|
| 187 | {
|
---|
| 188 | switch (attribute.LocalName)
|
---|
| 189 | {
|
---|
| 190 | case "gradientUnits":
|
---|
| 191 | gradientUnits = null;
|
---|
| 192 | break;
|
---|
| 193 | case "gradientTransform":
|
---|
| 194 | gradientTransform = null;
|
---|
| 195 | break;
|
---|
| 196 | case "spreadMethod":
|
---|
| 197 | spreadMethod = null;
|
---|
| 198 | break;
|
---|
| 199 | }
|
---|
| 200 | }
|
---|
| 201 |
|
---|
| 202 | base.HandleAttributeChange(attribute);
|
---|
| 203 | }
|
---|
| 204 |
|
---|
| 205 | #endregion
|
---|
| 206 | }
|
---|
| 207 | }
|
---|