1 | using System;
|
---|
2 | using System.Linq;
|
---|
3 | using System.Text;
|
---|
4 | using System.Windows;
|
---|
5 | using System.Windows.Media;
|
---|
6 | using System.Windows.Markup;
|
---|
7 | using System.Collections.Generic;
|
---|
8 |
|
---|
9 | using SharpVectors.Xml;
|
---|
10 | using SharpVectors.Dom;
|
---|
11 | using SharpVectors.Dom.Css;
|
---|
12 | using SharpVectors.Dom.Svg;
|
---|
13 | using SharpVectors.Dom.Events;
|
---|
14 |
|
---|
15 | namespace SharpVectors.Renderers.Wpf
|
---|
16 | {
|
---|
17 | public sealed class WpfDrawingRenderer : DependencyObject,
|
---|
18 | ISvgRenderer, IDisposable
|
---|
19 | {
|
---|
20 | #region Private Fields
|
---|
21 |
|
---|
22 | /// <summary>
|
---|
23 | /// The renderer's <see cref="SvgWindow">SvgWindow</see> object.
|
---|
24 | /// </summary>
|
---|
25 | private ISvgWindow _svgWindow;
|
---|
26 |
|
---|
27 | private WpfDrawingContext _renderingContext;
|
---|
28 | private WpfDrawingSettings _renderingSettings;
|
---|
29 |
|
---|
30 | private WpfRenderingHelper _svgRenderer;
|
---|
31 |
|
---|
32 | private WpfLinkVisitor _linkVisitor;
|
---|
33 | private WpfFontFamilyVisitor _fontFamilyVisitor;
|
---|
34 | private WpfEmbeddedImageVisitor _imageVisitor;
|
---|
35 |
|
---|
36 | #endregion
|
---|
37 |
|
---|
38 | #region Constructors and Destructor
|
---|
39 |
|
---|
40 | public WpfDrawingRenderer()
|
---|
41 | {
|
---|
42 | _svgRenderer = new WpfRenderingHelper(this);
|
---|
43 | }
|
---|
44 |
|
---|
45 | public WpfDrawingRenderer(WpfDrawingSettings settings)
|
---|
46 | {
|
---|
47 | _svgRenderer = new WpfRenderingHelper(this);
|
---|
48 | _renderingSettings = settings;
|
---|
49 | }
|
---|
50 |
|
---|
51 | ~WpfDrawingRenderer()
|
---|
52 | {
|
---|
53 | this.Dispose(false);
|
---|
54 | }
|
---|
55 |
|
---|
56 | #endregion
|
---|
57 |
|
---|
58 | #region Public Properties
|
---|
59 |
|
---|
60 | public Drawing Drawing
|
---|
61 | {
|
---|
62 | get
|
---|
63 | {
|
---|
64 | if (_renderingContext == null)
|
---|
65 | {
|
---|
66 | return null;
|
---|
67 | }
|
---|
68 |
|
---|
69 | return _renderingContext.Root;
|
---|
70 | }
|
---|
71 | }
|
---|
72 |
|
---|
73 | public WpfDrawingContext Context
|
---|
74 | {
|
---|
75 | get
|
---|
76 | {
|
---|
77 | return _renderingContext;
|
---|
78 | }
|
---|
79 | }
|
---|
80 |
|
---|
81 | public WpfLinkVisitor LinkVisitor
|
---|
82 | {
|
---|
83 | get
|
---|
84 | {
|
---|
85 | return _linkVisitor;
|
---|
86 | }
|
---|
87 | set
|
---|
88 | {
|
---|
89 | _linkVisitor = value;
|
---|
90 | }
|
---|
91 | }
|
---|
92 |
|
---|
93 | public WpfEmbeddedImageVisitor ImageVisitor
|
---|
94 | {
|
---|
95 | get
|
---|
96 | {
|
---|
97 | return _imageVisitor;
|
---|
98 | }
|
---|
99 | set
|
---|
100 | {
|
---|
101 | _imageVisitor = value;
|
---|
102 | }
|
---|
103 | }
|
---|
104 |
|
---|
105 | public WpfFontFamilyVisitor FontFamilyVisitor
|
---|
106 | {
|
---|
107 | get
|
---|
108 | {
|
---|
109 | return _fontFamilyVisitor;
|
---|
110 | }
|
---|
111 | set
|
---|
112 | {
|
---|
113 | _fontFamilyVisitor = value;
|
---|
114 | }
|
---|
115 | }
|
---|
116 |
|
---|
117 | #endregion
|
---|
118 |
|
---|
119 | #region ISvgRenderer Members
|
---|
120 |
|
---|
121 | public ISvgWindow Window
|
---|
122 | {
|
---|
123 | get
|
---|
124 | {
|
---|
125 | return _svgWindow;
|
---|
126 | }
|
---|
127 | set
|
---|
128 | {
|
---|
129 | _svgWindow = value;
|
---|
130 | }
|
---|
131 | }
|
---|
132 |
|
---|
133 | public void Render(ISvgElement node)
|
---|
134 | {
|
---|
135 | //throw new NotImplementedException();
|
---|
136 |
|
---|
137 | //SvgRectF updatedRect;
|
---|
138 | //if (invalidRect != SvgRectF.Empty)
|
---|
139 | // updatedRect = new SvgRectF(invalidRect.X, invalidRect.Y,
|
---|
140 | // invalidRect.Width, invalidRect.Height);
|
---|
141 | //else
|
---|
142 | // updatedRect = SvgRectF.Empty;
|
---|
143 |
|
---|
144 | //RendererBeforeRender();
|
---|
145 |
|
---|
146 | //if (graphics != null && graphics.Graphics != null)
|
---|
147 | //{
|
---|
148 | // _svgRenderer.Render(node);
|
---|
149 | //}
|
---|
150 |
|
---|
151 | //RendererAfterRender();
|
---|
152 |
|
---|
153 | //if (onRender != null)
|
---|
154 | // OnRender(updatedRect);
|
---|
155 |
|
---|
156 | _renderingContext = new WpfDrawingContext(true,
|
---|
157 | _renderingSettings);
|
---|
158 |
|
---|
159 | _renderingContext.Initialize(null, _fontFamilyVisitor, _imageVisitor);
|
---|
160 |
|
---|
161 | _renderingContext.BeginDrawing();
|
---|
162 |
|
---|
163 | _svgRenderer.Render(node);
|
---|
164 |
|
---|
165 | _renderingContext.EndDrawing();
|
---|
166 | }
|
---|
167 |
|
---|
168 | public void Render(ISvgElement node, WpfDrawingContext context)
|
---|
169 | {
|
---|
170 | //throw new NotImplementedException();
|
---|
171 |
|
---|
172 | //SvgRectF updatedRect;
|
---|
173 | //if (invalidRect != SvgRectF.Empty)
|
---|
174 | // updatedRect = new SvgRectF(invalidRect.X, invalidRect.Y,
|
---|
175 | // invalidRect.Width, invalidRect.Height);
|
---|
176 | //else
|
---|
177 | // updatedRect = SvgRectF.Empty;
|
---|
178 |
|
---|
179 | //RendererBeforeRender();
|
---|
180 |
|
---|
181 | //if (graphics != null && graphics.Graphics != null)
|
---|
182 | //{
|
---|
183 | // _svgRenderer.Render(node);
|
---|
184 | //}
|
---|
185 |
|
---|
186 | //RendererAfterRender();
|
---|
187 |
|
---|
188 | //if (onRender != null)
|
---|
189 | // OnRender(updatedRect);
|
---|
190 |
|
---|
191 | if (context == null)
|
---|
192 | {
|
---|
193 | _renderingContext = new WpfDrawingContext(true,
|
---|
194 | _renderingSettings);
|
---|
195 |
|
---|
196 | _renderingContext.Initialize(null, _fontFamilyVisitor, _imageVisitor);
|
---|
197 | }
|
---|
198 | else
|
---|
199 | {
|
---|
200 | _renderingContext = context;
|
---|
201 | }
|
---|
202 |
|
---|
203 | _renderingContext.BeginDrawing();
|
---|
204 |
|
---|
205 | _svgRenderer.Render(node);
|
---|
206 |
|
---|
207 | _renderingContext.EndDrawing();
|
---|
208 | }
|
---|
209 |
|
---|
210 | public void Render(ISvgDocument node)
|
---|
211 | {
|
---|
212 | //SvgRectF updatedRect;
|
---|
213 | //if (invalidRect != SvgRectF.Empty)
|
---|
214 | // updatedRect = new SvgRectF(invalidRect.X, invalidRect.Y,
|
---|
215 | // invalidRect.Width, invalidRect.Height);
|
---|
216 | //else
|
---|
217 | // updatedRect = SvgRectF.Empty;
|
---|
218 |
|
---|
219 | //RendererBeforeRender();
|
---|
220 |
|
---|
221 | //_renderingContext = new WpfDrawingContext(new DrawingGroup());
|
---|
222 | _renderingContext = new WpfDrawingContext(false,
|
---|
223 | _renderingSettings);
|
---|
224 |
|
---|
225 | _renderingContext.Initialize(_linkVisitor, _fontFamilyVisitor, _imageVisitor);
|
---|
226 |
|
---|
227 | _renderingContext.BeginDrawing();
|
---|
228 |
|
---|
229 | _svgRenderer.Render(node);
|
---|
230 |
|
---|
231 | _renderingContext.EndDrawing();
|
---|
232 |
|
---|
233 | //RendererAfterRender();
|
---|
234 |
|
---|
235 | //if (onRender != null)
|
---|
236 | // OnRender(updatedRect);
|
---|
237 | }
|
---|
238 |
|
---|
239 | public SvgRectF InvalidRect
|
---|
240 | {
|
---|
241 | get
|
---|
242 | {
|
---|
243 | return SvgRectF.Empty;
|
---|
244 | }
|
---|
245 | set
|
---|
246 | {
|
---|
247 | }
|
---|
248 | }
|
---|
249 |
|
---|
250 | public void RenderChildren(ISvgElement node)
|
---|
251 | {
|
---|
252 | _svgRenderer.RenderChildren(node);
|
---|
253 | }
|
---|
254 |
|
---|
255 | public void RenderMask(ISvgElement node, WpfDrawingContext context)
|
---|
256 | {
|
---|
257 | if (context == null)
|
---|
258 | {
|
---|
259 | _renderingContext = new WpfDrawingContext(true,
|
---|
260 | _renderingSettings);
|
---|
261 |
|
---|
262 | _renderingContext.Initialize(null, _fontFamilyVisitor, _imageVisitor);
|
---|
263 | }
|
---|
264 | else
|
---|
265 | {
|
---|
266 | _renderingContext = context;
|
---|
267 | }
|
---|
268 |
|
---|
269 | _renderingContext.BeginDrawing();
|
---|
270 |
|
---|
271 | _svgRenderer.RenderMask(node);
|
---|
272 |
|
---|
273 | _renderingContext.EndDrawing();
|
---|
274 | }
|
---|
275 |
|
---|
276 | public void InvalidateRect(SvgRectF rect)
|
---|
277 | {
|
---|
278 | }
|
---|
279 |
|
---|
280 | public RenderEvent OnRender
|
---|
281 | {
|
---|
282 | get
|
---|
283 | {
|
---|
284 | return null;
|
---|
285 | }
|
---|
286 | set
|
---|
287 | {
|
---|
288 | }
|
---|
289 | }
|
---|
290 |
|
---|
291 | public ISvgRect GetRenderedBounds(ISvgElement element, float margin)
|
---|
292 | {
|
---|
293 | return SvgRect.Empty;
|
---|
294 | }
|
---|
295 |
|
---|
296 | #endregion
|
---|
297 |
|
---|
298 | #region IDisposable Members
|
---|
299 |
|
---|
300 | public void Dispose()
|
---|
301 | {
|
---|
302 | this.Dispose(true);
|
---|
303 | GC.SuppressFinalize(this);
|
---|
304 | }
|
---|
305 |
|
---|
306 | private void Dispose(bool disposing)
|
---|
307 | {
|
---|
308 | }
|
---|
309 |
|
---|
310 | #endregion
|
---|
311 | }
|
---|
312 | }
|
---|