1 | using System;
|
---|
2 | using System.Text;
|
---|
3 | using System.Globalization;
|
---|
4 | using System.Collections.Generic;
|
---|
5 |
|
---|
6 | using System.Windows;
|
---|
7 | using System.Windows.Media;
|
---|
8 |
|
---|
9 | namespace SharpVectors.Renderers.Wpf
|
---|
10 | {
|
---|
11 | /// <summary>
|
---|
12 | /// This provides the options for the drawing/rendering engine of the WPF.
|
---|
13 | /// </summary>
|
---|
14 | public sealed class WpfDrawingSettings : DependencyObject, ICloneable
|
---|
15 | {
|
---|
16 | #region Private Fields
|
---|
17 |
|
---|
18 | private bool _textAsGeometry;
|
---|
19 | private bool _includeRuntime;
|
---|
20 | private bool _optimizePath;
|
---|
21 |
|
---|
22 | private CultureInfo _culture;
|
---|
23 | private CultureInfo _neutralCulture;
|
---|
24 |
|
---|
25 | private string _defaultFontName;
|
---|
26 | private static FontFamily _defaultFontFamily;
|
---|
27 | private static FontFamily _genericSerif;
|
---|
28 | private static FontFamily _genericSansSerif;
|
---|
29 | private static FontFamily _genericMonospace;
|
---|
30 |
|
---|
31 | #endregion
|
---|
32 |
|
---|
33 | #region Constructor and Destructor
|
---|
34 |
|
---|
35 | /// <overloads>
|
---|
36 | /// Initializes a new instance of the <see cref="WpfDrawingSettings"/> class.
|
---|
37 | /// </overloads>
|
---|
38 | /// <summary>
|
---|
39 | /// Initializes a new instance of the <see cref="WpfDrawingSettings"/> class
|
---|
40 | /// with the default parameters and settings.
|
---|
41 | /// </summary>
|
---|
42 | public WpfDrawingSettings()
|
---|
43 | {
|
---|
44 | _defaultFontName = "Arial Unicode MS";
|
---|
45 | _textAsGeometry = false;
|
---|
46 | _optimizePath = true;
|
---|
47 | _includeRuntime = true;
|
---|
48 | _neutralCulture = CultureInfo.GetCultureInfo("en-us");
|
---|
49 | _culture = CultureInfo.GetCultureInfo("en-us");
|
---|
50 | }
|
---|
51 |
|
---|
52 | /// <summary>
|
---|
53 | /// Initializes a new instance of the <see cref="WpfDrawingSettings"/> class
|
---|
54 | /// with the specified initial drawing or rendering settings, a copy constructor.
|
---|
55 | /// </summary>
|
---|
56 | /// <param name="settings">
|
---|
57 | /// This specifies the initial options for the rendering or drawing engine.
|
---|
58 | /// </param>
|
---|
59 | public WpfDrawingSettings(WpfDrawingSettings settings)
|
---|
60 | {
|
---|
61 | _defaultFontName = settings._defaultFontName;
|
---|
62 | _textAsGeometry = settings._textAsGeometry;
|
---|
63 | _optimizePath = settings._optimizePath;
|
---|
64 | _includeRuntime = settings._includeRuntime;
|
---|
65 | _neutralCulture = settings._neutralCulture;
|
---|
66 | _culture = settings._culture;
|
---|
67 | }
|
---|
68 |
|
---|
69 | #endregion
|
---|
70 |
|
---|
71 | #region Public Properties
|
---|
72 |
|
---|
73 | /// <summary>
|
---|
74 | /// Gets or sets a value indicating whether the path geometry is
|
---|
75 | /// optimized using the <see cref="StreamGeometry"/>.
|
---|
76 | /// </summary>
|
---|
77 | /// <value>
|
---|
78 | /// This is <see langword="true"/> if the path geometry is optimized
|
---|
79 | /// using the <see cref="StreamGeometry"/>; otherwise, it is
|
---|
80 | /// <see langword="false"/>. The default is <see langword="true"/>.
|
---|
81 | /// </value>
|
---|
82 | public bool OptimizePath
|
---|
83 | {
|
---|
84 | get
|
---|
85 | {
|
---|
86 | return _optimizePath;
|
---|
87 | }
|
---|
88 | set
|
---|
89 | {
|
---|
90 | _optimizePath = value;
|
---|
91 | }
|
---|
92 | }
|
---|
93 |
|
---|
94 | /// <summary>
|
---|
95 | /// Gets or sets a value indicating whether the texts are rendered as
|
---|
96 | /// path geometry.
|
---|
97 | /// </summary>
|
---|
98 | /// <value>
|
---|
99 | /// This is <see langword="true"/> if texts are rendered as path
|
---|
100 | /// geometries; otherwise, this is <see langword="false"/>. The default
|
---|
101 | /// is <see langword="false"/>.
|
---|
102 | /// </value>
|
---|
103 | public bool TextAsGeometry
|
---|
104 | {
|
---|
105 | get
|
---|
106 | {
|
---|
107 | return _textAsGeometry;
|
---|
108 | }
|
---|
109 | set
|
---|
110 | {
|
---|
111 | _textAsGeometry = value;
|
---|
112 | }
|
---|
113 | }
|
---|
114 |
|
---|
115 | /// <summary>
|
---|
116 | /// Gets or sets a value indicating whether the <c>SharpVectors.Runtime.dll</c>
|
---|
117 | /// classes are used in the generated output.
|
---|
118 | /// </summary>
|
---|
119 | /// <value>
|
---|
120 | /// This is <see langword="true"/> if the <c>SharpVectors.Runtime.dll</c>
|
---|
121 | /// classes and types are used in the generated output; otherwise, it is
|
---|
122 | /// <see langword="false"/>. The default is <see langword="true"/>.
|
---|
123 | /// </value>
|
---|
124 | /// <remarks>
|
---|
125 | /// The use of the <c>SharpVectors.Runtime.dll</c> prevents the hard-coded
|
---|
126 | /// font path generated by the <see cref="FormattedText"/> class, support
|
---|
127 | /// for embedded images etc.
|
---|
128 | /// </remarks>
|
---|
129 | public bool IncludeRuntime
|
---|
130 | {
|
---|
131 | get
|
---|
132 | {
|
---|
133 | return _includeRuntime;
|
---|
134 | }
|
---|
135 | set
|
---|
136 | {
|
---|
137 | _includeRuntime = value;
|
---|
138 | }
|
---|
139 | }
|
---|
140 |
|
---|
141 | /// <summary>
|
---|
142 | /// Gets or sets the main culture information used for rendering texts.
|
---|
143 | /// </summary>
|
---|
144 | /// <value>
|
---|
145 | /// An instance of the <see cref="CultureInfo"/> specifying the main
|
---|
146 | /// culture information for texts. The default is the English culture.
|
---|
147 | /// </value>
|
---|
148 | /// <remarks>
|
---|
149 | /// <para>
|
---|
150 | /// This is the culture information passed to the <see cref="FormattedText"/>
|
---|
151 | /// class instance for the text rendering.
|
---|
152 | /// </para>
|
---|
153 | /// <para>
|
---|
154 | /// The library does not currently provide any means of splitting texts
|
---|
155 | /// into its multi-language parts.
|
---|
156 | /// </para>
|
---|
157 | /// </remarks>
|
---|
158 | public CultureInfo CultureInfo
|
---|
159 | {
|
---|
160 | get
|
---|
161 | {
|
---|
162 | return _culture;
|
---|
163 | }
|
---|
164 | set
|
---|
165 | {
|
---|
166 | if (value != null)
|
---|
167 | {
|
---|
168 | _culture = value;
|
---|
169 | }
|
---|
170 | }
|
---|
171 | }
|
---|
172 |
|
---|
173 | /// <summary>
|
---|
174 | /// Gets the neutral language for text rendering.
|
---|
175 | /// </summary>
|
---|
176 | /// <value>
|
---|
177 | /// An instance of the <see cref="CultureInfo"/> specifying the neutral
|
---|
178 | /// culture information for texts. The default is the English culture.
|
---|
179 | /// </value>
|
---|
180 | /// <remarks>
|
---|
181 | /// For vertical text rendering, there is a basic text splitting into
|
---|
182 | /// Western and other languages. This culture information is used to
|
---|
183 | /// render the Western language part, and the mains culture information
|
---|
184 | /// for the other languages.
|
---|
185 | /// </remarks>
|
---|
186 | public CultureInfo NeutralCultureInfo
|
---|
187 | {
|
---|
188 | get
|
---|
189 | {
|
---|
190 | return _neutralCulture;
|
---|
191 | }
|
---|
192 | }
|
---|
193 |
|
---|
194 | /// <summary>
|
---|
195 | /// Gets or sets the default font family name, which is used when a text
|
---|
196 | /// node does not specify a font family name.
|
---|
197 | /// </summary>
|
---|
198 | /// <value>
|
---|
199 | /// A string containing the default font family name. The default is
|
---|
200 | /// the <c>Arial Unicode MS</c> font, for its support of Unicode texts.
|
---|
201 | /// This value cannot be <see langword="null"/> or empty.
|
---|
202 | /// </value>
|
---|
203 | public string DefaultFontName
|
---|
204 | {
|
---|
205 | get
|
---|
206 | {
|
---|
207 | return _defaultFontName;
|
---|
208 | }
|
---|
209 | set
|
---|
210 | {
|
---|
211 | if (value != null)
|
---|
212 | {
|
---|
213 | value = value.Trim();
|
---|
214 | }
|
---|
215 |
|
---|
216 | if (!String.IsNullOrEmpty(value))
|
---|
217 | {
|
---|
218 | _defaultFontName = value;
|
---|
219 | _defaultFontFamily = new FontFamily(value);
|
---|
220 | }
|
---|
221 | }
|
---|
222 | }
|
---|
223 |
|
---|
224 | /// <summary>
|
---|
225 | /// Gets or sets the globally available default font family.
|
---|
226 | /// </summary>
|
---|
227 | /// <value>
|
---|
228 | /// An instance of the <see cref="FontFamily"/> specifying the globally
|
---|
229 | /// available font family. The default is a <c>Arial Unicode MS</c> font
|
---|
230 | /// family.
|
---|
231 | /// </value>
|
---|
232 | public static FontFamily DefaultFontFamily
|
---|
233 | {
|
---|
234 | get
|
---|
235 | {
|
---|
236 | if (_defaultFontFamily == null)
|
---|
237 | {
|
---|
238 | _defaultFontFamily = new FontFamily("Arial Unicode MS");
|
---|
239 | }
|
---|
240 |
|
---|
241 | return _defaultFontFamily;
|
---|
242 | }
|
---|
243 | set
|
---|
244 | {
|
---|
245 | if (value != null)
|
---|
246 | {
|
---|
247 | _defaultFontFamily = value;
|
---|
248 | }
|
---|
249 | }
|
---|
250 | }
|
---|
251 |
|
---|
252 | /// <summary>
|
---|
253 | /// Gets or set the globally available generic serif font family.
|
---|
254 | /// </summary>
|
---|
255 | /// <value>
|
---|
256 | /// An instance of <see cref="FontFamily"/> specifying the generic serif
|
---|
257 | /// font family. The default is <c>Times New Roman</c> font family.
|
---|
258 | /// </value>
|
---|
259 | public static FontFamily GenericSerif
|
---|
260 | {
|
---|
261 | get
|
---|
262 | {
|
---|
263 | if (_genericSerif == null)
|
---|
264 | {
|
---|
265 | _genericSerif = new FontFamily("Times New Roman");
|
---|
266 | }
|
---|
267 |
|
---|
268 | return _genericSerif;
|
---|
269 | }
|
---|
270 | set
|
---|
271 | {
|
---|
272 | if (value != null)
|
---|
273 | {
|
---|
274 | _genericSerif = value;
|
---|
275 | }
|
---|
276 | }
|
---|
277 | }
|
---|
278 |
|
---|
279 | /// <summary>
|
---|
280 | /// Gets or set the globally available generic sans serif font family.
|
---|
281 | /// </summary>
|
---|
282 | /// <value>
|
---|
283 | /// An instance of <see cref="FontFamily"/> specifying the generic sans
|
---|
284 | /// serif font family. The default is <c>Tahoma</c> font family.
|
---|
285 | /// </value>
|
---|
286 | /// <remarks>
|
---|
287 | /// The possible font names are <c>Tahoma</c>, <c>Arial</c>,
|
---|
288 | /// <c>Verdana</c>, <c>Trebuchet</c>, <c>MS Sans Serif</c> and <c>Helvetica</c>.
|
---|
289 | /// </remarks>
|
---|
290 | public static FontFamily GenericSansSerif
|
---|
291 | {
|
---|
292 | get
|
---|
293 | {
|
---|
294 | if (_genericSansSerif == null)
|
---|
295 | {
|
---|
296 | // Possibilities: Tahoma, Arial, Verdana, Trebuchet, MS Sans Serif, Helvetica
|
---|
297 | _genericSansSerif = new FontFamily("Tahoma");
|
---|
298 | }
|
---|
299 |
|
---|
300 | return _genericSansSerif;
|
---|
301 | }
|
---|
302 | set
|
---|
303 | {
|
---|
304 | if (value != null)
|
---|
305 | {
|
---|
306 | _genericSansSerif = value;
|
---|
307 | }
|
---|
308 | }
|
---|
309 | }
|
---|
310 |
|
---|
311 | /// <summary>
|
---|
312 | /// Gets or set the globally available generic Monospace font family.
|
---|
313 | /// </summary>
|
---|
314 | /// <value>
|
---|
315 | /// An instance of <see cref="FontFamily"/> specifying the generic
|
---|
316 | /// Monospace font family. The default is <c>MS Gothic</c> font family.
|
---|
317 | /// </value>
|
---|
318 | public static FontFamily GenericMonospace
|
---|
319 | {
|
---|
320 | get
|
---|
321 | {
|
---|
322 | if (_genericMonospace == null)
|
---|
323 | {
|
---|
324 | // Possibilities: Courier New, MS Gothic
|
---|
325 | _genericMonospace = new FontFamily("MS Gothic");
|
---|
326 | }
|
---|
327 |
|
---|
328 | return _genericMonospace;
|
---|
329 | }
|
---|
330 | set
|
---|
331 | {
|
---|
332 | if (value != null)
|
---|
333 | {
|
---|
334 | _genericMonospace = value;
|
---|
335 | }
|
---|
336 | }
|
---|
337 | }
|
---|
338 |
|
---|
339 | #endregion
|
---|
340 |
|
---|
341 | #region ICloneable Members
|
---|
342 |
|
---|
343 | /// <overloads>
|
---|
344 | /// This creates a new settings object that is a deep copy of the current
|
---|
345 | /// instance.
|
---|
346 | /// </overloads>
|
---|
347 | /// <summary>
|
---|
348 | /// This creates a new settings object that is a deep copy of the current
|
---|
349 | /// instance.
|
---|
350 | /// </summary>
|
---|
351 | /// <returns>
|
---|
352 | /// A new settings object that is a deep copy of this instance.
|
---|
353 | /// </returns>
|
---|
354 | /// <remarks>
|
---|
355 | /// This is deep cloning of the members of this settings object. If you
|
---|
356 | /// need just a copy, use the copy constructor to create a new instance.
|
---|
357 | /// </remarks>
|
---|
358 | public WpfDrawingSettings Clone()
|
---|
359 | {
|
---|
360 | WpfDrawingSettings settings = new WpfDrawingSettings(this);
|
---|
361 |
|
---|
362 | return settings;
|
---|
363 | }
|
---|
364 |
|
---|
365 | /// <summary>
|
---|
366 | /// This creates a new settings object that is a deep copy of the current
|
---|
367 | /// instance.
|
---|
368 | /// </summary>
|
---|
369 | /// <returns>
|
---|
370 | /// A new settings object that is a deep copy of this instance.
|
---|
371 | /// </returns>
|
---|
372 | /// <remarks>
|
---|
373 | /// This is deep cloning of the members of this style object. If you need just a copy,
|
---|
374 | /// use the copy constructor to create a new instance.
|
---|
375 | /// </remarks>
|
---|
376 | object ICloneable.Clone()
|
---|
377 | {
|
---|
378 | return this.Clone();
|
---|
379 | }
|
---|
380 |
|
---|
381 | #endregion
|
---|
382 | }
|
---|
383 | }
|
---|