[12762] | 1 | using System;
|
---|
| 2 | using System.Xml;
|
---|
| 3 |
|
---|
| 4 | namespace SharpVectors.Dom.Svg
|
---|
| 5 | {
|
---|
| 6 | public abstract class SvgPolyElement : SvgTransformableElement, ISharpMarkerHost
|
---|
| 7 | {
|
---|
| 8 | #region Private Fields
|
---|
| 9 |
|
---|
| 10 | private ISvgPointList points;
|
---|
| 11 | private SvgTests svgTests;
|
---|
| 12 | private SvgExternalResourcesRequired svgExternalResourcesRequired;
|
---|
| 13 |
|
---|
| 14 | #endregion
|
---|
| 15 |
|
---|
| 16 | #region Contructors and Destructor
|
---|
| 17 |
|
---|
| 18 | protected SvgPolyElement(string prefix, string localname, string ns, SvgDocument doc)
|
---|
| 19 | : base(prefix, localname, ns, doc)
|
---|
| 20 | {
|
---|
| 21 | svgExternalResourcesRequired = new SvgExternalResourcesRequired(this);
|
---|
| 22 | svgTests = new SvgTests(this);
|
---|
| 23 | }
|
---|
| 24 |
|
---|
| 25 | #endregion
|
---|
| 26 |
|
---|
| 27 | #region Public Properties
|
---|
| 28 |
|
---|
| 29 | public ISvgPointList AnimatedPoints
|
---|
| 30 | {
|
---|
| 31 | get
|
---|
| 32 | {
|
---|
| 33 | return Points;
|
---|
| 34 | }
|
---|
| 35 | }
|
---|
| 36 |
|
---|
| 37 | public ISvgPointList Points
|
---|
| 38 | {
|
---|
| 39 | get
|
---|
| 40 | {
|
---|
| 41 | if (points == null)
|
---|
| 42 | {
|
---|
| 43 | points = new SvgPointList(GetAttribute("points"));
|
---|
| 44 | }
|
---|
| 45 | return points;
|
---|
| 46 | }
|
---|
| 47 | }
|
---|
| 48 |
|
---|
| 49 | #endregion
|
---|
| 50 |
|
---|
| 51 | #region Public Methods
|
---|
| 52 |
|
---|
| 53 | public void Invalidate()
|
---|
| 54 | {
|
---|
| 55 | }
|
---|
| 56 |
|
---|
| 57 | public override void HandleAttributeChange(XmlAttribute attribute)
|
---|
| 58 | {
|
---|
| 59 | if (attribute.NamespaceURI.Length == 0)
|
---|
| 60 | {
|
---|
| 61 | switch (attribute.LocalName)
|
---|
| 62 | {
|
---|
| 63 | case "points":
|
---|
| 64 | points = null;
|
---|
| 65 | Invalidate();
|
---|
| 66 | return;
|
---|
| 67 | case "marker-start":
|
---|
| 68 | case "marker-mid":
|
---|
| 69 | case "marker-end":
|
---|
| 70 | // Color.attrib, Paint.attrib
|
---|
| 71 | case "color":
|
---|
| 72 | case "fill":
|
---|
| 73 | case "fill-rule":
|
---|
| 74 | case "stroke":
|
---|
| 75 | case "stroke-dasharray":
|
---|
| 76 | case "stroke-dashoffset":
|
---|
| 77 | case "stroke-linecap":
|
---|
| 78 | case "stroke-linejoin":
|
---|
| 79 | case "stroke-miterlimit":
|
---|
| 80 | case "stroke-width":
|
---|
| 81 | // Opacity.attrib
|
---|
| 82 | case "opacity":
|
---|
| 83 | case "stroke-opacity":
|
---|
| 84 | case "fill-opacity":
|
---|
| 85 | // Graphics.attrib
|
---|
| 86 | case "display":
|
---|
| 87 | case "image-rendering":
|
---|
| 88 | case "shape-rendering":
|
---|
| 89 | case "text-rendering":
|
---|
| 90 | case "visibility":
|
---|
| 91 | Invalidate();
|
---|
| 92 | break;
|
---|
| 93 | case "transform":
|
---|
| 94 | Invalidate();
|
---|
| 95 | break;
|
---|
| 96 | }
|
---|
| 97 |
|
---|
| 98 | base.HandleAttributeChange(attribute);
|
---|
| 99 | }
|
---|
| 100 | }
|
---|
| 101 | #endregion
|
---|
| 102 |
|
---|
| 103 | #region ISvgElement Members
|
---|
| 104 |
|
---|
| 105 | /// <summary>
|
---|
| 106 | /// Gets a value providing a hint on the rendering defined by this element.
|
---|
| 107 | /// </summary>
|
---|
| 108 | /// <value>
|
---|
| 109 | /// An enumeration of the <see cref="SvgRenderingHint"/> specifying the rendering hint.
|
---|
| 110 | /// This will always return <see cref="SvgRenderingHint.Shape"/>
|
---|
| 111 | /// </value>
|
---|
| 112 | public override SvgRenderingHint RenderingHint
|
---|
| 113 | {
|
---|
| 114 | get
|
---|
| 115 | {
|
---|
| 116 | return SvgRenderingHint.Shape;
|
---|
| 117 | }
|
---|
| 118 | }
|
---|
| 119 |
|
---|
| 120 | #endregion
|
---|
| 121 |
|
---|
| 122 | #region ISvgExternalResourcesRequired Members
|
---|
| 123 |
|
---|
| 124 | public ISvgAnimatedBoolean ExternalResourcesRequired
|
---|
| 125 | {
|
---|
| 126 | get
|
---|
| 127 | {
|
---|
| 128 | return svgExternalResourcesRequired.ExternalResourcesRequired;
|
---|
| 129 | }
|
---|
| 130 | }
|
---|
| 131 |
|
---|
| 132 | #endregion
|
---|
| 133 |
|
---|
| 134 | #region ISharpMarkerHost Members
|
---|
| 135 |
|
---|
| 136 | public virtual SvgPointF[] MarkerPositions
|
---|
| 137 | {
|
---|
| 138 | get
|
---|
| 139 | {
|
---|
| 140 | // moved this code from SvgPointList. This should eventually migrate into
|
---|
| 141 | // the GDI+ renderer
|
---|
| 142 | SvgPointF[] points = new SvgPointF[Points.NumberOfItems];
|
---|
| 143 |
|
---|
| 144 | for (uint i = 0; i < Points.NumberOfItems; i++)
|
---|
| 145 | {
|
---|
| 146 | ISvgPoint point = Points.GetItem(i);
|
---|
| 147 | points[i] = new SvgPointF(point.X, point.Y);
|
---|
| 148 | }
|
---|
| 149 |
|
---|
| 150 | return points;
|
---|
| 151 | }
|
---|
| 152 | }
|
---|
| 153 |
|
---|
| 154 | public double GetStartAngle(int index)
|
---|
| 155 | {
|
---|
| 156 | index--;
|
---|
| 157 |
|
---|
| 158 | SvgPointF[] positions = MarkerPositions;
|
---|
| 159 |
|
---|
| 160 | if (index > positions.Length - 1)
|
---|
| 161 | {
|
---|
| 162 | throw new Exception("GetStartAngle: index to large");
|
---|
| 163 | }
|
---|
| 164 |
|
---|
| 165 | SvgPointF p1 = positions[index];
|
---|
| 166 | SvgPointF p2 = positions[index + 1];
|
---|
| 167 |
|
---|
| 168 | double dx = p2.X - p1.X;
|
---|
| 169 | double dy = p2.Y - p1.Y;
|
---|
| 170 |
|
---|
| 171 | double a = (Math.Atan2(dy, dx) * 180 / Math.PI);
|
---|
| 172 | a -= 90;
|
---|
| 173 | a %= 360;
|
---|
| 174 | return a;
|
---|
| 175 | }
|
---|
| 176 |
|
---|
| 177 | public double GetEndAngle(int index)
|
---|
| 178 | {
|
---|
| 179 | double a = GetStartAngle(index);
|
---|
| 180 | a += 180;
|
---|
| 181 | a %= 360;
|
---|
| 182 | return a;
|
---|
| 183 | }
|
---|
| 184 |
|
---|
| 185 | #endregion
|
---|
| 186 |
|
---|
| 187 | #region ISvgTests Members
|
---|
| 188 |
|
---|
| 189 | public ISvgStringList RequiredFeatures
|
---|
| 190 | {
|
---|
| 191 | get { return svgTests.RequiredFeatures; }
|
---|
| 192 | }
|
---|
| 193 |
|
---|
| 194 | public ISvgStringList RequiredExtensions
|
---|
| 195 | {
|
---|
| 196 | get { return svgTests.RequiredExtensions; }
|
---|
| 197 | }
|
---|
| 198 |
|
---|
| 199 | public ISvgStringList SystemLanguage
|
---|
| 200 | {
|
---|
| 201 | get { return svgTests.SystemLanguage; }
|
---|
| 202 | }
|
---|
| 203 |
|
---|
| 204 | public bool HasExtension(string extension)
|
---|
| 205 | {
|
---|
| 206 | return svgTests.HasExtension(extension);
|
---|
| 207 | }
|
---|
| 208 |
|
---|
| 209 | #endregion
|
---|
| 210 | }
|
---|
| 211 | }
|
---|