[12762] | 1 | using System;
|
---|
| 2 | using System.Xml;
|
---|
| 3 | using System.Linq;
|
---|
| 4 | using System.Text;
|
---|
| 5 | using System.Windows;
|
---|
| 6 | using System.Windows.Media;
|
---|
| 7 | using System.Collections.Generic;
|
---|
| 8 |
|
---|
| 9 | using SharpVectors.Dom.Svg;
|
---|
| 10 | using SharpVectors.Runtime;
|
---|
| 11 |
|
---|
| 12 | namespace SharpVectors.Renderers.Wpf
|
---|
| 13 | {
|
---|
| 14 | public sealed class WpfARendering : WpfRendering
|
---|
| 15 | {
|
---|
| 16 | #region Private Fields
|
---|
| 17 |
|
---|
| 18 | private bool _isLayer;
|
---|
| 19 | private bool _isAggregated;
|
---|
| 20 | private DrawingGroup _drawGroup;
|
---|
| 21 |
|
---|
| 22 | #endregion
|
---|
| 23 |
|
---|
| 24 | #region Constructors and Destructor
|
---|
| 25 |
|
---|
| 26 | public WpfARendering(SvgElement element)
|
---|
| 27 | : base(element)
|
---|
| 28 | {
|
---|
| 29 | }
|
---|
| 30 |
|
---|
| 31 | #endregion
|
---|
| 32 |
|
---|
| 33 | #region Public Properties
|
---|
| 34 |
|
---|
| 35 | public override bool IsRecursive
|
---|
| 36 | {
|
---|
| 37 | get
|
---|
| 38 | {
|
---|
| 39 | return _isAggregated;
|
---|
| 40 | }
|
---|
| 41 | }
|
---|
| 42 |
|
---|
| 43 | #endregion
|
---|
| 44 |
|
---|
| 45 | #region Public Methods
|
---|
| 46 |
|
---|
| 47 | public override void BeforeRender(WpfDrawingRenderer renderer)
|
---|
| 48 | {
|
---|
| 49 | base.BeforeRender(renderer);
|
---|
| 50 |
|
---|
| 51 | _isAggregated = false;
|
---|
| 52 |
|
---|
| 53 | if (_svgElement.FirstChild == _svgElement.LastChild)
|
---|
| 54 | {
|
---|
| 55 | SvgGElement gElement = _svgElement.FirstChild as SvgGElement;
|
---|
| 56 | if (gElement != null)
|
---|
| 57 | {
|
---|
| 58 | string elementId = gElement.GetAttribute("id");
|
---|
| 59 | if (!String.IsNullOrEmpty(elementId) &&
|
---|
| 60 | String.Equals(elementId, "IndicateLayer", StringComparison.OrdinalIgnoreCase))
|
---|
| 61 | {
|
---|
| 62 | WpfDrawingContext context = renderer.Context;
|
---|
| 63 |
|
---|
| 64 | DrawingGroup animationGroup = context.Links;
|
---|
| 65 | if (animationGroup != null)
|
---|
| 66 | {
|
---|
| 67 | context.Push(animationGroup);
|
---|
| 68 | }
|
---|
| 69 |
|
---|
| 70 | _isLayer = true;
|
---|
| 71 | }
|
---|
| 72 | }
|
---|
| 73 | }
|
---|
| 74 | }
|
---|
| 75 |
|
---|
| 76 | public override void Render(WpfDrawingRenderer renderer)
|
---|
| 77 | {
|
---|
| 78 | _isAggregated = false;
|
---|
| 79 |
|
---|
| 80 | if (_isLayer)
|
---|
| 81 | {
|
---|
| 82 | base.Render(renderer);
|
---|
| 83 |
|
---|
| 84 | return;
|
---|
| 85 | }
|
---|
| 86 |
|
---|
| 87 | WpfDrawingContext context = renderer.Context;
|
---|
| 88 |
|
---|
| 89 | Geometry clipGeom = this.ClipGeometry;
|
---|
| 90 | Transform transform = this.Transform;
|
---|
| 91 |
|
---|
| 92 | float opacityValue = -1;
|
---|
| 93 |
|
---|
| 94 | SvgAElement element = (SvgAElement)_svgElement;
|
---|
| 95 | string opacity = element.GetPropertyValue("opacity");
|
---|
| 96 | if (opacity != null && opacity.Length > 0)
|
---|
| 97 | {
|
---|
| 98 | opacityValue = (float)SvgNumber.ParseNumber(opacity);
|
---|
| 99 | opacityValue = Math.Min(opacityValue, 1);
|
---|
| 100 | opacityValue = Math.Max(opacityValue, 0);
|
---|
| 101 | }
|
---|
| 102 |
|
---|
| 103 | WpfLinkVisitor linkVisitor = context.LinkVisitor;
|
---|
| 104 |
|
---|
| 105 | if (linkVisitor != null || clipGeom != null || transform != null || opacityValue >= 0)
|
---|
| 106 | {
|
---|
| 107 | _drawGroup = new DrawingGroup();
|
---|
| 108 |
|
---|
| 109 | string elementId = this.GetElementName();
|
---|
| 110 | if (!String.IsNullOrEmpty(elementId) && !context.IsRegisteredId(elementId))
|
---|
| 111 | {
|
---|
| 112 | _drawGroup.SetValue(FrameworkElement.NameProperty, elementId);
|
---|
| 113 |
|
---|
| 114 | context.RegisterId(elementId);
|
---|
| 115 |
|
---|
| 116 | if (context.IncludeRuntime)
|
---|
| 117 | {
|
---|
| 118 | SvgObject.SetId(_drawGroup, elementId);
|
---|
| 119 | }
|
---|
| 120 | }
|
---|
| 121 |
|
---|
| 122 | DrawingGroup currentGroup = context.Peek();
|
---|
| 123 |
|
---|
| 124 | if (currentGroup == null)
|
---|
| 125 | {
|
---|
| 126 | throw new InvalidOperationException("An existing group is expected.");
|
---|
| 127 | }
|
---|
| 128 |
|
---|
| 129 | if (linkVisitor != null && linkVisitor.Aggregates && context.Links != null)
|
---|
| 130 | {
|
---|
| 131 | if (!linkVisitor.Exists(elementId))
|
---|
| 132 | {
|
---|
| 133 | context.Links.Children.Add(_drawGroup);
|
---|
| 134 | }
|
---|
| 135 | }
|
---|
| 136 | else
|
---|
| 137 | {
|
---|
| 138 | currentGroup.Children.Add(_drawGroup);
|
---|
| 139 | }
|
---|
| 140 |
|
---|
| 141 | context.Push(_drawGroup);
|
---|
| 142 |
|
---|
| 143 | if (clipGeom != null)
|
---|
| 144 | {
|
---|
| 145 | _drawGroup.ClipGeometry = clipGeom;
|
---|
| 146 | }
|
---|
| 147 |
|
---|
| 148 | if (transform != null)
|
---|
| 149 | {
|
---|
| 150 | _drawGroup.Transform = transform;
|
---|
| 151 | }
|
---|
| 152 |
|
---|
| 153 | if (opacityValue >= 0)
|
---|
| 154 | {
|
---|
| 155 | _drawGroup.Opacity = opacityValue;
|
---|
| 156 | }
|
---|
| 157 |
|
---|
| 158 | if (linkVisitor != null)
|
---|
| 159 | {
|
---|
| 160 | linkVisitor.Visit(_drawGroup, element, context, opacityValue);
|
---|
| 161 |
|
---|
| 162 | _isAggregated = linkVisitor.IsAggregate;
|
---|
| 163 | }
|
---|
| 164 | }
|
---|
| 165 |
|
---|
| 166 | base.Render(renderer);
|
---|
| 167 | }
|
---|
| 168 |
|
---|
| 169 | public override void AfterRender(WpfDrawingRenderer renderer)
|
---|
| 170 | {
|
---|
| 171 | if (_isLayer)
|
---|
| 172 | {
|
---|
| 173 | WpfDrawingContext context = renderer.Context;
|
---|
| 174 |
|
---|
| 175 | context.Pop();
|
---|
| 176 |
|
---|
| 177 | base.AfterRender(renderer);
|
---|
| 178 |
|
---|
| 179 | return;
|
---|
| 180 | }
|
---|
| 181 |
|
---|
| 182 | if (_drawGroup != null)
|
---|
| 183 | {
|
---|
| 184 | WpfDrawingContext context = renderer.Context;
|
---|
| 185 |
|
---|
| 186 | if (context.IncludeRuntime)
|
---|
| 187 | {
|
---|
| 188 | // Add the element/object type...
|
---|
| 189 | SvgObject.SetType(_drawGroup, SvgObjectType.Link);
|
---|
| 190 |
|
---|
| 191 | // Add title for tooltips, if any...
|
---|
| 192 | SvgTitleElement titleElement = this.GetTitleElement();
|
---|
| 193 | if (titleElement != null)
|
---|
| 194 | {
|
---|
| 195 | string titleValue = titleElement.InnerText;
|
---|
| 196 | if (!String.IsNullOrEmpty(titleValue))
|
---|
| 197 | {
|
---|
| 198 | SvgObject.SetTitle(_drawGroup, titleValue);
|
---|
| 199 | }
|
---|
| 200 | }
|
---|
| 201 | }
|
---|
| 202 |
|
---|
| 203 | DrawingGroup currentGroup = context.Peek();
|
---|
| 204 |
|
---|
| 205 | if (currentGroup == null || currentGroup != _drawGroup)
|
---|
| 206 | {
|
---|
| 207 | throw new InvalidOperationException("An existing group is expected.");
|
---|
| 208 | }
|
---|
| 209 |
|
---|
| 210 | context.Pop();
|
---|
| 211 |
|
---|
| 212 | // If not aggregated by a link visitor, we remove it from the links/animation and
|
---|
| 213 | // add it to the main drawing stack...
|
---|
| 214 | if (!_isAggregated)
|
---|
| 215 | {
|
---|
| 216 | if (context.Links.Children.Remove(_drawGroup))
|
---|
| 217 | {
|
---|
| 218 | currentGroup = context.Peek();
|
---|
| 219 |
|
---|
| 220 | currentGroup.Children.Add(_drawGroup);
|
---|
| 221 | }
|
---|
| 222 | }
|
---|
| 223 | }
|
---|
| 224 |
|
---|
| 225 | base.AfterRender(renderer);
|
---|
| 226 | }
|
---|
| 227 |
|
---|
| 228 | #endregion
|
---|
| 229 | }
|
---|
| 230 | }
|
---|