[12762] | 1 | using System;
|
---|
| 2 | using System.Linq;
|
---|
| 3 | using System.Text;
|
---|
| 4 | using System.Diagnostics;
|
---|
| 5 | using System.Windows;
|
---|
| 6 | using System.Windows.Media;
|
---|
| 7 | using System.Collections.Generic;
|
---|
| 8 |
|
---|
| 9 | using SharpVectors.Dom.Svg;
|
---|
| 10 |
|
---|
| 11 | namespace SharpVectors.Renderers.Wpf
|
---|
| 12 | {
|
---|
| 13 | public sealed class WpfSwitchRendering : WpfRendering
|
---|
| 14 | {
|
---|
| 15 | #region Private Fields
|
---|
| 16 |
|
---|
| 17 | private DrawingGroup _drawGroup;
|
---|
| 18 |
|
---|
| 19 | #endregion
|
---|
| 20 |
|
---|
| 21 | #region Constructors and Destructor
|
---|
| 22 |
|
---|
| 23 | public WpfSwitchRendering(SvgElement element)
|
---|
| 24 | : base(element)
|
---|
| 25 | {
|
---|
| 26 | }
|
---|
| 27 |
|
---|
| 28 | #endregion
|
---|
| 29 |
|
---|
| 30 | #region Public Methods
|
---|
| 31 |
|
---|
| 32 | public override void BeforeRender(WpfDrawingRenderer renderer)
|
---|
| 33 | {
|
---|
| 34 | base.BeforeRender(renderer);
|
---|
| 35 | }
|
---|
| 36 |
|
---|
| 37 | public override void Render(WpfDrawingRenderer renderer)
|
---|
| 38 | {
|
---|
| 39 | Geometry clipGeom = this.ClipGeometry;
|
---|
| 40 | Transform transform = this.Transform;
|
---|
| 41 |
|
---|
| 42 | if (clipGeom != null || transform != null)
|
---|
| 43 | {
|
---|
| 44 | WpfDrawingContext context = renderer.Context;
|
---|
| 45 | _drawGroup = new DrawingGroup();
|
---|
| 46 |
|
---|
| 47 | DrawingGroup currentGroup = context.Peek();
|
---|
| 48 |
|
---|
| 49 | if (currentGroup == null)
|
---|
| 50 | {
|
---|
| 51 | throw new InvalidOperationException("An existing group is expected.");
|
---|
| 52 | }
|
---|
| 53 |
|
---|
| 54 | currentGroup.Children.Add(_drawGroup);
|
---|
| 55 | context.Push(_drawGroup);
|
---|
| 56 |
|
---|
| 57 | if (clipGeom != null)
|
---|
| 58 | {
|
---|
| 59 | _drawGroup.ClipGeometry = clipGeom;
|
---|
| 60 | }
|
---|
| 61 |
|
---|
| 62 | if (transform != null)
|
---|
| 63 | {
|
---|
| 64 | _drawGroup.Transform = transform;
|
---|
| 65 | }
|
---|
| 66 | }
|
---|
| 67 |
|
---|
| 68 | base.Render(renderer);
|
---|
| 69 | }
|
---|
| 70 |
|
---|
| 71 | public override void AfterRender(WpfDrawingRenderer renderer)
|
---|
| 72 | {
|
---|
| 73 | if (_drawGroup != null)
|
---|
| 74 | {
|
---|
| 75 | WpfDrawingContext context = renderer.Context;
|
---|
| 76 |
|
---|
| 77 | DrawingGroup currentGroup = context.Peek();
|
---|
| 78 |
|
---|
| 79 | if (currentGroup == null || currentGroup != _drawGroup)
|
---|
| 80 | {
|
---|
| 81 | throw new InvalidOperationException("An existing group is expected.");
|
---|
| 82 | }
|
---|
| 83 |
|
---|
| 84 | context.Pop();
|
---|
| 85 | }
|
---|
| 86 |
|
---|
| 87 | base.AfterRender(renderer);
|
---|
| 88 | }
|
---|
| 89 |
|
---|
| 90 | #endregion
|
---|
| 91 | }
|
---|
| 92 | }
|
---|