Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.Problems.GrammaticalOptimization/SharpVectorRenderingGdi/Gdi/GdiPathRendering.cs @ 13777

Last change on this file since 13777 was 12762, checked in by aballeit, 9 years ago

#2283 GUI updates, Tree-chart, MCTS Version 2 (prune leaves)

File size: 3.8 KB
Line 
1using System;
2using System.Drawing;
3using System.Drawing.Drawing2D;
4
5using SharpVectors.Dom.Css;
6using SharpVectors.Dom.Svg;
7
8namespace SharpVectors.Renderers.Gdi
9{
10    public sealed class GdiPathRendering : GdiRendering
11  {
12        #region Constructor and Destructor
13
14    public GdiPathRendering(SvgElement element)
15            : base(element)
16    {
17    }
18
19        #endregion
20
21    #region Public Methods
22
23        public override void BeforeRender(GdiGraphicsRenderer renderer)
24        {
25            if (_uniqueColor.IsEmpty)
26              _uniqueColor = renderer.GetNextColor(this.Element);
27
28            GdiGraphicsWrapper graphics = renderer.GraphicsWrapper;
29
30            _graphicsContainer = graphics.BeginContainer();
31            SetQuality(graphics);
32            Transform(graphics);
33        }
34
35        public override void Render(GdiGraphicsRenderer renderer)
36        {
37            GdiGraphicsWrapper graphics = renderer.GraphicsWrapper;
38
39            SvgRenderingHint hint = element.RenderingHint;
40            if (hint != SvgRenderingHint.Shape || hint == SvgRenderingHint.Clipping)
41            {
42                return;
43            }
44            if (element.ParentNode is SvgClipPathElement)
45            {
46                return;
47            }
48
49            SvgStyleableElement styleElm = (SvgStyleableElement)element;
50
51      string sVisibility = styleElm.GetPropertyValue("visibility");
52      string sDisplay    = styleElm.GetPropertyValue("display");
53            if (String.Equals(sVisibility, "hidden") || String.Equals(sDisplay, "none"))
54            {
55                return;
56            }
57
58            GraphicsPath gp = CreatePath(element);
59
60      if (gp != null)
61      {
62        Clip(graphics);
63
64        GdiSvgPaint fillPaint = new GdiSvgPaint(styleElm, "fill");
65        Brush brush = fillPaint.GetBrush(gp);
66
67        GdiSvgPaint strokePaint = new GdiSvgPaint(styleElm, "stroke");
68        Pen pen = strokePaint.GetPen(gp);
69
70        if (brush != null)
71        {
72          if (brush is PathGradientBrush)
73          {
74            GdiGradientFill gps = fillPaint.PaintFill as GdiGradientFill;
75           
76            graphics.SetClip(gps.GetRadialGradientRegion(gp.GetBounds()), CombineMode.Exclude);
77
78            SolidBrush tempBrush = new SolidBrush(((PathGradientBrush)brush).InterpolationColors.Colors[0]);
79            graphics.FillPath(this, tempBrush,gp);
80            tempBrush.Dispose();
81            graphics.ResetClip();
82          }
83
84          graphics.FillPath(this, brush, gp);
85          brush.Dispose();
86                    brush = null;
87        }
88
89        if (pen != null)
90        {
91          if (pen.Brush is PathGradientBrush)
92          {
93            GdiGradientFill gps = strokePaint.PaintFill as GdiGradientFill;
94            GdiGraphicsContainer container = graphics.BeginContainer();
95
96            graphics.SetClip(gps.GetRadialGradientRegion(gp.GetBounds()), CombineMode.Exclude);
97
98            SolidBrush tempBrush = new SolidBrush(((PathGradientBrush)pen.Brush).InterpolationColors.Colors[0]);
99            Pen tempPen = new Pen(tempBrush, pen.Width);
100            graphics.DrawPath(this, tempPen,gp);
101            tempPen.Dispose();
102            tempBrush.Dispose();
103
104            graphics.EndContainer(container);
105          }
106
107          graphics.DrawPath(this, pen, gp);
108          pen.Dispose();
109                    pen = null;
110        }
111
112                gp.Dispose();
113                gp = null;
114      }
115
116      PaintMarkers(renderer, styleElm, graphics);
117        }
118
119        #endregion
120
121        #region Private Methods
122
123        private Brush GetBrush(GraphicsPath gp)
124        {
125            GdiSvgPaint paint = new GdiSvgPaint(element as SvgStyleableElement, "fill");
126            return paint.GetBrush(gp);
127        }
128
129        private Pen GetPen(GraphicsPath gp)
130        {
131            GdiSvgPaint paint = new GdiSvgPaint(element as SvgStyleableElement, "stroke");
132            return paint.GetPen(gp);
133        }
134   
135        #endregion
136    }
137}
Note: See TracBrowser for help on using the repository browser.