VectSharp  2.2.1
A light library for C# vector graphics
Graphics.Text.cs
1 /*
2  VectSharp - A light library for C# vector graphics.
3  Copyright (C) 2020-2022 Giorgio Bianchini
4 
5  This program is free software: you can redistribute it and/or modify
6  it under the terms of the GNU Lesser General Public License as published by
7  the Free Software Foundation, version 3.
8 
9  This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  GNU Lesser General Public License for more details.
13 
14  You should have received a copy of the GNU Lesser General Public License
15  along with this program. If not, see <https://www.gnu.org/licenses/>.
16 */
17 
18 using System;
19 using System.Collections.Generic;
20 using System.Linq;
21 using System.Text;
22 using static System.Net.Mime.MediaTypeNames;
23 
24 namespace VectSharp
25 {
26  public partial class Graphics
27  {
28  /// <summary>
29  /// Fill a text string.
30  /// </summary>
31  /// <param name="origin">The text origin. See <paramref name="textBaseline"/>.</param>
32  /// <param name="text">The string to draw.</param>
33  /// <param name="font">The font with which to draw the text.</param>
34  /// <param name="fillColour">The <see cref="Brush"/> to use to fill the text.</param>
35  /// <param name="textBaseline">The text baseline (determines what the vertical component of <paramref name="origin"/> represents).</param>
36  /// <param name="tag">A tag to identify the filled text.</param>
37  public void FillText(Point origin, string text, Font font, Brush fillColour, TextBaselines textBaseline = TextBaselines.Top, string tag = null)
38  {
39  Actions.Add(new TextAction(origin, text, font, textBaseline, fillColour, null, 0, LineCaps.Butt, LineJoins.Miter, LineDash.SolidLine, tag));
40 
41  if (font.Underline != null)
42  {
43  FillTextUnderline(origin, text, font, fillColour, textBaseline, tag);
44  }
45  }
46 
47  /// <summary>
48  /// Fill a text string.
49  /// </summary>
50  /// <param name="originX">The horizontal coordinate of the text origin.</param>
51  /// <param name="originY">The vertical coordinate of the text origin. See <paramref name="textBaseline"/>.</param>
52  /// <param name="text">The string to draw.</param>
53  /// <param name="font">The font with which to draw the text.</param>
54  /// <param name="fillColour">The <see cref="Brush"/> to use to fill the text.</param>
55  /// <param name="textBaseline">The text baseline (determines what <paramref name="originY"/> represents).</param>
56  /// <param name="tag">A tag to identify the filled text.</param>
57  public void FillText(double originX, double originY, string text, Font font, Brush fillColour, TextBaselines textBaseline = TextBaselines.Top, string tag = null)
58  {
59  Actions.Add(new TextAction(new Point(originX, originY), text, font, textBaseline, fillColour, null, 0, LineCaps.Butt, LineJoins.Miter, LineDash.SolidLine, tag));
60 
61  if (font.Underline != null)
62  {
63  FillTextUnderline(originX, originY, text, font, fillColour, textBaseline, tag);
64  }
65  }
66 
67  /// <summary>
68  /// Stroke a text string.
69  /// </summary>
70  /// <param name="origin">The text origin. See <paramref name="textBaseline"/>.</param>
71  /// <param name="text">The string to draw.</param>
72  /// <param name="font">The font with which to draw the text.</param>
73  /// <param name="strokeColour">The <see cref="Brush"/> with which to stroke the text.</param>
74  /// <param name="lineWidth">The width of the line with which the text is stroked.</param>
75  /// <param name="lineCap">The line cap to use to stroke the text.</param>
76  /// <param name="lineJoin">The line join to use to stroke the text.</param>
77  /// <param name="lineDash">The line dash to use to stroke the text.</param>
78  /// <param name="textBaseline">The text baseline (determines what the vertical component of <paramref name="origin"/> represents).</param>
79  /// <param name="tag">A tag to identify the stroked text.</param>
80  public void StrokeText(Point origin, string text, Font font, Brush strokeColour, TextBaselines textBaseline = TextBaselines.Top, double lineWidth = 1, LineCaps lineCap = LineCaps.Butt, LineJoins lineJoin = LineJoins.Miter, LineDash? lineDash = null, string tag = null)
81  {
82  Actions.Add(new TextAction(origin, text, font, textBaseline, null, strokeColour, lineWidth, lineCap, lineJoin, lineDash ?? LineDash.SolidLine, tag));
83 
84  if (font.Underline != null)
85  {
86  StrokeTextUnderline(origin, text, font, strokeColour, textBaseline, lineWidth, lineCap, lineJoin, lineDash, tag);
87  }
88  }
89 
90  /// <summary>
91  /// Stroke a text string.
92  /// </summary>
93  /// <param name="originX">The horizontal coordinate of the text origin.</param>
94  /// <param name="originY">The vertical coordinate of the text origin. See <paramref name="textBaseline"/>.</param>
95  /// <param name="text">The string to draw.</param>
96  /// <param name="font">The font with which to draw the text.</param>
97  /// <param name="strokeColour">The <see cref="Brush"/> with which to stroke the text.</param>
98  /// <param name="lineWidth">The width of the line with which the text is stroked.</param>
99  /// <param name="lineCap">The line cap to use to stroke the text.</param>
100  /// <param name="lineJoin">The line join to use to stroke the text.</param>
101  /// <param name="lineDash">The line dash to use to stroke the text.</param>
102  /// <param name="textBaseline">The text baseline (determines what <paramref name="originY"/> represents).</param>
103  /// <param name="tag">A tag to identify the stroked text.</param>
104  public void StrokeText(double originX, double originY, string text, Font font, Brush strokeColour, TextBaselines textBaseline = TextBaselines.Top, double lineWidth = 1, LineCaps lineCap = LineCaps.Butt, LineJoins lineJoin = LineJoins.Miter, LineDash? lineDash = null, string tag = null)
105  {
106  Actions.Add(new TextAction(new Point(originX, originY), text, font, textBaseline, null, strokeColour, lineWidth, lineCap, lineJoin, lineDash ?? LineDash.SolidLine, tag));
107 
108  if (font.Underline != null)
109  {
110  StrokeTextUnderline(originX, originY, text, font, strokeColour, textBaseline, lineWidth, lineCap, lineJoin, lineDash, tag);
111  }
112  }
113 
114  /// <summary>
115  /// Fill a text string along a <see cref="GraphicsPath"/>.
116  /// </summary>
117  /// <param name="path">The <see cref="GraphicsPath"/> along which the text will flow.</param>
118  /// <param name="text">The string to draw.</param>
119  /// <param name="font">The font with which to draw the text.</param>
120  /// <param name="fillColour">The <see cref="Brush"/> to use to fill the text.</param>
121  /// <param name="reference">The (relative) starting point on the path starting from which the text should be drawn (0 is the start of the path, 1 is the end of the path).</param>
122  /// <param name="anchor">The anchor in the text string that will correspond to the point specified by the <paramref name="reference"/>.</param>
123  /// <param name="textBaseline">The text baseline (determines which the position of the text in relation to the <paramref name="path"/>.</param>
124  /// <param name="tag">A tag to identify the filled text.</param>
125  public void FillTextOnPath(GraphicsPath path, string text, Font font, Brush fillColour, double reference = 0, TextAnchors anchor = TextAnchors.Left, TextBaselines textBaseline = TextBaselines.Top, string tag = null)
126  {
127  if (font.Underline != null)
128  {
129  font = new Font(font.FontFamily, font.FontSize, false);
130  }
131 
132  double currDelta = 0;
133  double pathLength = path.MeasureLength();
134 
135  Font.DetailedFontMetrics fullMetrics = font.MeasureTextAdvanced(text);
136 
137  switch (anchor)
138  {
139  case TextAnchors.Left:
140  break;
141  case TextAnchors.Center:
142  currDelta = -fullMetrics.Width * 0.5 / pathLength;
143  break;
144  case TextAnchors.Right:
145  currDelta = -fullMetrics.Width / pathLength;
146  break;
147  }
148 
149  Point currentGlyphPlacementDelta = new Point();
150  Point currentGlyphAdvanceDelta = new Point();
151  Point nextGlyphPlacementDelta = new Point();
152  Point nextGlyphAdvanceDelta = new Point();
153 
154  for (int i = 0; i < text.Length; i++)
155  {
156  string c = text.Substring(i, 1);
157 
158  if (Font.EnableKerning && i < text.Length - 1)
159  {
160  currentGlyphPlacementDelta = nextGlyphPlacementDelta;
161  currentGlyphAdvanceDelta = nextGlyphAdvanceDelta;
162  nextGlyphAdvanceDelta = new Point();
163  nextGlyphPlacementDelta = new Point();
164 
165  TrueTypeFile.PairKerning kerning = font.FontFamily.TrueTypeFile.Get1000EmKerning(text[i], text[i + 1]);
166 
167  if (kerning != null)
168  {
169  currentGlyphPlacementDelta = new Point(currentGlyphPlacementDelta.X + kerning.Glyph1Placement.X, currentGlyphPlacementDelta.Y + kerning.Glyph1Placement.Y);
170  currentGlyphAdvanceDelta = new Point(currentGlyphAdvanceDelta.X + kerning.Glyph1Advance.X, currentGlyphAdvanceDelta.Y + kerning.Glyph1Advance.Y);
171 
172  nextGlyphPlacementDelta = new Point(nextGlyphPlacementDelta.X + kerning.Glyph2Placement.X, nextGlyphPlacementDelta.Y + kerning.Glyph2Placement.Y);
173  nextGlyphAdvanceDelta = new Point(nextGlyphAdvanceDelta.X + kerning.Glyph2Advance.X, nextGlyphAdvanceDelta.Y + kerning.Glyph2Advance.Y);
174  }
175  }
176 
177  Font.DetailedFontMetrics metrics = font.MeasureTextAdvanced(c);
178 
179  Point origin = path.GetPointAtRelative(reference + currDelta + currentGlyphPlacementDelta.X * font.FontSize / 1000);
180 
181  Point tangent = path.GetTangentAtRelative(reference + currDelta + currentGlyphPlacementDelta.X * font.FontSize / 1000 + (metrics.Width + metrics.RightSideBearing + metrics.LeftSideBearing) / pathLength * 0.5);
182 
183  origin = new Point(origin.X - tangent.Y * currentGlyphPlacementDelta.Y * font.FontSize / 1000, origin.Y + tangent.X * currentGlyphPlacementDelta.Y * font.FontSize / 1000);
184 
185  this.Save();
186 
187  this.Translate(origin);
188  this.Rotate(Math.Atan2(tangent.Y, tangent.X));
189 
190  switch (textBaseline)
191  {
192  case TextBaselines.Top:
193  if (i > 0)
194  {
195  this.FillText(new Point(metrics.LeftSideBearing, fullMetrics.Top), c, font, fillColour, textBaseline: TextBaselines.Baseline, tag);
196  }
197  else
198  {
199  this.FillText(new Point(0, fullMetrics.Top), c, font, fillColour, textBaseline: TextBaselines.Baseline, tag);
200  }
201  break;
202  case TextBaselines.Baseline:
203  if (i > 0)
204  {
205  this.FillText(new Point(metrics.LeftSideBearing, 0), c, font, fillColour, textBaseline: TextBaselines.Baseline, tag);
206  }
207  else
208  {
209  this.FillText(new Point(0, 0), c, font, fillColour, textBaseline: TextBaselines.Baseline, tag);
210  }
211  break;
212  case TextBaselines.Bottom:
213  if (i > 0)
214  {
215  this.FillText(new Point(metrics.LeftSideBearing, fullMetrics.Bottom), c, font, fillColour, textBaseline: TextBaselines.Baseline, tag);
216  }
217  else
218  {
219  this.FillText(new Point(0, fullMetrics.Bottom), c, font, fillColour, textBaseline: TextBaselines.Baseline, tag);
220  }
221  break;
222  case TextBaselines.Middle:
223  if (i > 0)
224  {
225  this.FillText(new Point(metrics.LeftSideBearing, fullMetrics.Bottom + fullMetrics.Height / 2), c, font, fillColour, textBaseline: TextBaselines.Baseline, tag);
226  }
227  else
228  {
229  this.FillText(new Point(0, fullMetrics.Bottom + fullMetrics.Height / 2), c, font, fillColour, textBaseline: TextBaselines.Baseline, tag);
230  }
231  break;
232  }
233 
234  this.Restore();
235 
236  if (i > 0)
237  {
238  currDelta += (metrics.Width + metrics.RightSideBearing + metrics.LeftSideBearing + currentGlyphAdvanceDelta.X * font.FontSize / 1000) / pathLength;
239  }
240  else
241  {
242  currDelta += (metrics.Width + metrics.RightSideBearing + currentGlyphAdvanceDelta.X * font.FontSize / 1000) / pathLength;
243  }
244  }
245  }
246 
247  /// <summary>
248  /// Stroke a text string along a <see cref="GraphicsPath"/>.
249  /// </summary>
250  /// <param name="path">The <see cref="GraphicsPath"/> along which the text will flow.</param>
251  /// <param name="text">The string to draw.</param>
252  /// <param name="font">The font with which to draw the text.</param>
253  /// <param name="strokeColour">The <see cref="Brush"/> with which to stroke the text.</param>
254  /// <param name="lineWidth">The width of the line with which the text is stroked.</param>
255  /// <param name="lineCap">The line cap to use to stroke the text.</param>
256  /// <param name="lineJoin">The line join to use to stroke the text.</param>
257  /// <param name="lineDash">The line dash to use to stroke the text.</param>
258  /// <param name="reference">The (relative) starting point on the path starting from which the text should be drawn (0 is the start of the path, 1 is the end of the path).</param>
259  /// <param name="anchor">The anchor in the text string that will correspond to the point specified by the <paramref name="reference"/>.</param>
260  /// <param name="textBaseline">The text baseline (determines which the position of the text in relation to the <paramref name="path"/>.</param>
261  /// <param name="tag">A tag to identify the stroked text.</param>
262  public void StrokeTextOnPath(GraphicsPath path, string text, Font font, Brush strokeColour, double reference = 0, TextAnchors anchor = TextAnchors.Left, TextBaselines textBaseline = TextBaselines.Top, double lineWidth = 1, LineCaps lineCap = LineCaps.Butt, LineJoins lineJoin = LineJoins.Miter, LineDash? lineDash = null, string tag = null)
263  {
264  if (font.Underline != null)
265  {
266  font = new Font(font.FontFamily, font.FontSize, false);
267  }
268 
269  double currDelta = 0;
270  double pathLength = path.MeasureLength();
271 
272  Font.DetailedFontMetrics fullMetrics = font.MeasureTextAdvanced(text);
273 
274  switch (anchor)
275  {
276  case TextAnchors.Left:
277  break;
278  case TextAnchors.Center:
279  currDelta = -fullMetrics.Width * 0.5 / pathLength;
280  break;
281  case TextAnchors.Right:
282  currDelta = -fullMetrics.Width / pathLength;
283  break;
284  }
285 
286  Point currentGlyphPlacementDelta = new Point();
287  Point currentGlyphAdvanceDelta = new Point();
288  Point nextGlyphPlacementDelta = new Point();
289  Point nextGlyphAdvanceDelta = new Point();
290 
291  for (int i = 0; i < text.Length; i++)
292  {
293  string c = text.Substring(i, 1);
294 
295  if (Font.EnableKerning && i < text.Length - 1)
296  {
297  currentGlyphPlacementDelta = nextGlyphPlacementDelta;
298  currentGlyphAdvanceDelta = nextGlyphAdvanceDelta;
299  nextGlyphAdvanceDelta = new Point();
300  nextGlyphPlacementDelta = new Point();
301 
302  TrueTypeFile.PairKerning kerning = font.FontFamily.TrueTypeFile.Get1000EmKerning(text[i], text[i + 1]);
303 
304  if (kerning != null)
305  {
306  currentGlyphPlacementDelta = new Point(currentGlyphPlacementDelta.X + kerning.Glyph1Placement.X, currentGlyphPlacementDelta.Y + kerning.Glyph1Placement.Y);
307  currentGlyphAdvanceDelta = new Point(currentGlyphAdvanceDelta.X + kerning.Glyph1Advance.X, currentGlyphAdvanceDelta.Y + kerning.Glyph1Advance.Y);
308 
309  nextGlyphPlacementDelta = new Point(nextGlyphPlacementDelta.X + kerning.Glyph2Placement.X, nextGlyphPlacementDelta.Y + kerning.Glyph2Placement.Y);
310  nextGlyphAdvanceDelta = new Point(nextGlyphAdvanceDelta.X + kerning.Glyph2Advance.X, nextGlyphAdvanceDelta.Y + kerning.Glyph2Advance.Y);
311  }
312  }
313 
314  Font.DetailedFontMetrics metrics = font.MeasureTextAdvanced(c);
315 
316  Point origin = path.GetPointAtRelative(reference + currDelta + currentGlyphPlacementDelta.X * font.FontSize / 1000);
317 
318  Point tangent = path.GetTangentAtRelative(reference + currDelta + currentGlyphPlacementDelta.X * font.FontSize / 1000 + (metrics.Width + metrics.RightSideBearing + metrics.LeftSideBearing) / pathLength * 0.5);
319 
320  origin = new Point(origin.X - tangent.Y * currentGlyphPlacementDelta.Y * font.FontSize / 1000, origin.Y + tangent.X * currentGlyphPlacementDelta.Y * font.FontSize / 1000);
321 
322  this.Save();
323 
324  this.Translate(origin);
325  this.Rotate(Math.Atan2(tangent.Y, tangent.X));
326 
327  switch (textBaseline)
328  {
329  case TextBaselines.Top:
330  if (i > 0)
331  {
332  this.StrokeText(new Point(metrics.LeftSideBearing, fullMetrics.Top), c, font, strokeColour, textBaseline: TextBaselines.Baseline, lineWidth, lineCap, lineJoin, lineDash, tag);
333  }
334  else
335  {
336  this.StrokeText(new Point(0, fullMetrics.Top), c, font, strokeColour, textBaseline: TextBaselines.Baseline, lineWidth, lineCap, lineJoin, lineDash, tag);
337  }
338  break;
339  case TextBaselines.Baseline:
340  if (i > 0)
341  {
342  this.StrokeText(new Point(metrics.LeftSideBearing, 0), c, font, strokeColour, textBaseline: TextBaselines.Baseline, lineWidth, lineCap, lineJoin, lineDash, tag);
343  }
344  else
345  {
346  this.StrokeText(new Point(0, 0), c, font, strokeColour, textBaseline: TextBaselines.Baseline, lineWidth, lineCap, lineJoin, lineDash, tag);
347  }
348  break;
349  case TextBaselines.Bottom:
350  if (i > 0)
351  {
352  this.StrokeText(new Point(metrics.LeftSideBearing, fullMetrics.Bottom), c, font, strokeColour, textBaseline: TextBaselines.Baseline, lineWidth, lineCap, lineJoin, lineDash, tag);
353  }
354  else
355  {
356  this.StrokeText(new Point(0, fullMetrics.Bottom), c, font, strokeColour, textBaseline: TextBaselines.Baseline, lineWidth, lineCap, lineJoin, lineDash, tag);
357  }
358  break;
359  case TextBaselines.Middle:
360  if (i > 0)
361  {
362  this.StrokeText(new Point(metrics.LeftSideBearing, fullMetrics.Bottom + fullMetrics.Height / 2), c, font, strokeColour, textBaseline: TextBaselines.Baseline, lineWidth, lineCap, lineJoin, lineDash, tag);
363  }
364  else
365  {
366  this.StrokeText(new Point(0, fullMetrics.Bottom + fullMetrics.Height / 2), c, font, strokeColour, textBaseline: TextBaselines.Baseline, lineWidth, lineCap, lineJoin, lineDash, tag);
367  }
368  break;
369  }
370 
371  this.Restore();
372 
373  if (i > 0)
374  {
375  currDelta += (metrics.Width + metrics.RightSideBearing + metrics.LeftSideBearing + currentGlyphAdvanceDelta.X * font.FontSize / 1000) / pathLength;
376  }
377  else
378  {
379  currDelta += (metrics.Width + metrics.RightSideBearing + currentGlyphAdvanceDelta.X * font.FontSize / 1000) / pathLength;
380  }
381  }
382  }
383 
384  /// <summary>
385  /// Fill a formatted text string.
386  /// </summary>
387  /// <param name="origin">The text origin. See <paramref name="textBaseline"/>.</param>
388  /// <param name="text">The <see cref="FormattedText"/> to draw.</param>
389  /// <param name="fillColour">The default <see cref="Brush"/> to use to fill the text. This can be overridden by each <paramref name="text"/> element.</param>
390  /// <param name="textBaseline">The text baseline (determines what the vertical component of <paramref name="origin"/> represents).</param>
391  /// <param name="tag">A tag to identify the filled text.</param>
392  public void FillText(Point origin, IEnumerable<FormattedText> text, Brush fillColour, TextBaselines textBaseline = TextBaselines.Top, string tag = null)
393  {
394  List<FormattedText> enumeratedText = new List<FormattedText>();
395  List<Font.DetailedFontMetrics> allMetrics = new List<Font.DetailedFontMetrics>();
396 
397  Font.DetailedFontMetrics fullMetrics = text.Measure(enumeratedText, allMetrics);
398 
399  Point baselineOrigin = origin;
400 
401  switch (textBaseline)
402  {
403  case TextBaselines.Baseline:
404  baselineOrigin = origin;
405  break;
406  case TextBaselines.Top:
407  baselineOrigin = new Point(origin.X, origin.Y + fullMetrics.Top);
408  break;
409  case TextBaselines.Bottom:
410  baselineOrigin = new Point(origin.X, origin.Y + fullMetrics.Bottom);
411  break;
412  case TextBaselines.Middle:
413  baselineOrigin = new Point(origin.X, origin.Y + fullMetrics.Top * 0.5 + fullMetrics.Bottom * 0.5);
414  break;
415  }
416 
417  for (int i = 0; i < enumeratedText.Count; i++)
418  {
419  FormattedText txt = enumeratedText[i];
420 
421  if (txt.Script == Script.Normal)
422  {
423  Font.DetailedFontMetrics metrics = allMetrics[i];
424 
425  if (i > 0)
426  {
427  FillText(baselineOrigin.X + metrics.LeftSideBearing, baselineOrigin.Y, txt.Text, txt.Font, txt.Brush ?? fillColour, TextBaselines.Baseline, tag);
428  }
429  else
430  {
431  FillText(baselineOrigin, txt.Text, txt.Font, txt.Brush ?? fillColour, TextBaselines.Baseline, tag);
432  }
433 
434  if (i > 0)
435  {
436  baselineOrigin = new Point(baselineOrigin.X + metrics.Width + metrics.RightSideBearing + metrics.LeftSideBearing, baselineOrigin.Y);
437  }
438  else
439  {
440  baselineOrigin = new Point(baselineOrigin.X + metrics.Width + metrics.RightSideBearing, baselineOrigin.Y);
441  }
442  }
443  else
444  {
445  Font newFont = new Font(txt.Font.FontFamily, txt.Font.FontSize * 0.7, txt.Font.Underline);
446 
447  Font.DetailedFontMetrics metrics = allMetrics[i];
448 
449  if (i == 0)
450  {
451  baselineOrigin = new Point(baselineOrigin.X - metrics.LeftSideBearing, baselineOrigin.Y);
452  }
453 
454  if (txt.Script == Script.Subscript)
455  {
456  FillText(baselineOrigin.X + metrics.LeftSideBearing, baselineOrigin.Y + txt.Font.FontSize * 0.14, txt.Text, newFont, txt.Brush ?? fillColour, TextBaselines.Baseline, tag);
457  }
458  else if (txt.Script == Script.Superscript)
459  {
460  FillText(baselineOrigin.X + metrics.LeftSideBearing, baselineOrigin.Y - txt.Font.FontSize * 0.33, txt.Text, newFont, txt.Brush ?? fillColour, TextBaselines.Baseline, tag);
461  }
462 
463 
464  if (i > 0)
465  {
466  baselineOrigin = new Point(baselineOrigin.X + metrics.Width + metrics.RightSideBearing + metrics.LeftSideBearing, baselineOrigin.Y);
467  }
468  else
469  {
470  baselineOrigin = new Point(baselineOrigin.X + metrics.Width + metrics.RightSideBearing, baselineOrigin.Y);
471  }
472  }
473  }
474  }
475 
476  /// <summary>
477  /// Fill a formatted text string.
478  /// </summary>
479  /// <param name="originX">The horizontal coordinate of the text origin.</param>
480  /// <param name="originY">The vertical coordinate of the text origin. See <paramref name="textBaseline"/>.</param>
481  /// <param name="text">The <see cref="FormattedText"/> to draw.</param>
482  /// <param name="fillColour">The default <see cref="Brush"/> to use to fill the text. This can be overridden by each <paramref name="text"/> element.</param>
483  /// <param name="textBaseline">The text baseline (determines what <paramref name="originY"/> represents).</param>
484  /// <param name="tag">A tag to identify the filled text.</param>
485  public void FillText(double originX, double originY, IEnumerable<FormattedText> text, Brush fillColour, TextBaselines textBaseline = TextBaselines.Top, string tag = null)
486  {
487  FillText(new Point(originX, originY), text, fillColour, textBaseline, tag);
488  }
489 
490  /// <summary>
491  /// Stroke a formatted text string.
492  /// </summary>
493  /// <param name="origin">The text origin. See <paramref name="textBaseline"/>.</param>
494  /// <param name="text">The <see cref="FormattedText"/> to draw.</param>
495  /// <param name="strokeColour">The default <see cref="Brush"/> with which to stroke the text.</param>
496  /// <param name="lineWidth">The width of the line with which the text is stroked.</param>
497  /// <param name="lineCap">The line cap to use to stroke the text.</param>
498  /// <param name="lineJoin">The line join to use to stroke the text.</param>
499  /// <param name="lineDash">The line dash to use to stroke the text.</param>
500  /// <param name="textBaseline">The text baseline (determines what the vertical component of <paramref name="origin"/> represents).</param>
501  /// <param name="tag">A tag to identify the stroked text.</param>
502  public void StrokeText(Point origin, IEnumerable<FormattedText> text, Brush strokeColour, TextBaselines textBaseline = TextBaselines.Top, double lineWidth = 1, LineCaps lineCap = LineCaps.Butt, LineJoins lineJoin = LineJoins.Miter, LineDash? lineDash = null, string tag = null)
503  {
504  List<FormattedText> enumeratedText = new List<FormattedText>();
505  List<Font.DetailedFontMetrics> allMetrics = new List<Font.DetailedFontMetrics>();
506 
507  Font.DetailedFontMetrics fullMetrics = text.Measure(enumeratedText, allMetrics);
508 
509  Point baselineOrigin = origin;
510 
511  switch (textBaseline)
512  {
513  case TextBaselines.Baseline:
514  baselineOrigin = origin;
515  break;
516  case TextBaselines.Top:
517  baselineOrigin = new Point(origin.X, origin.Y + fullMetrics.Top);
518  break;
519  case TextBaselines.Bottom:
520  baselineOrigin = new Point(origin.X, origin.Y + fullMetrics.Bottom);
521  break;
522  case TextBaselines.Middle:
523  baselineOrigin = new Point(origin.X, origin.Y + fullMetrics.Top * 0.5 + fullMetrics.Bottom * 0.5);
524  break;
525  }
526 
527  for (int i = 0; i < enumeratedText.Count; i++)
528  {
529  FormattedText txt = enumeratedText[i];
530 
531  if (txt.Script == Script.Normal)
532  {
533  Font.DetailedFontMetrics metrics = allMetrics[i];
534 
535  if (i > 0)
536  {
537  StrokeText(baselineOrigin.X + metrics.LeftSideBearing, baselineOrigin.Y, txt.Text, txt.Font, txt.Brush ?? strokeColour, TextBaselines.Baseline, lineWidth, lineCap, lineJoin, lineDash, tag);
538  }
539  else
540  {
541  StrokeText(baselineOrigin, txt.Text, txt.Font, txt.Brush ?? strokeColour, TextBaselines.Baseline, lineWidth, lineCap, lineJoin, lineDash, tag);
542  }
543 
544  if (i > 0)
545  {
546  baselineOrigin = new Point(baselineOrigin.X + metrics.Width + metrics.RightSideBearing + metrics.LeftSideBearing, baselineOrigin.Y);
547  }
548  else
549  {
550  baselineOrigin = new Point(baselineOrigin.X + metrics.Width + metrics.RightSideBearing, baselineOrigin.Y);
551  }
552  }
553  else
554  {
555  Font newFont = new Font(txt.Font.FontFamily, txt.Font.FontSize * 0.7, txt.Font.Underline);
556 
557  Font.DetailedFontMetrics metrics = allMetrics[i];
558 
559  if (i == 0)
560  {
561  baselineOrigin = new Point(baselineOrigin.X - metrics.LeftSideBearing, baselineOrigin.Y);
562  }
563 
564  if (txt.Script == Script.Subscript)
565  {
566  StrokeText(baselineOrigin.X + metrics.LeftSideBearing, baselineOrigin.Y + txt.Font.FontSize * 0.14, txt.Text, newFont, txt.Brush ?? strokeColour, TextBaselines.Baseline, lineWidth, lineCap, lineJoin, lineDash, tag);
567  }
568  else if (txt.Script == Script.Superscript)
569  {
570  StrokeText(baselineOrigin.X + metrics.LeftSideBearing, baselineOrigin.Y - txt.Font.FontSize * 0.33, txt.Text, newFont, txt.Brush ?? strokeColour, TextBaselines.Baseline, lineWidth, lineCap, lineJoin, lineDash, tag);
571  }
572 
573 
574  if (i > 0)
575  {
576  baselineOrigin = new Point(baselineOrigin.X + metrics.Width + metrics.RightSideBearing + metrics.LeftSideBearing, baselineOrigin.Y);
577  }
578  else
579  {
580  baselineOrigin = new Point(baselineOrigin.X + metrics.Width + metrics.RightSideBearing, baselineOrigin.Y);
581  }
582  }
583  }
584  }
585 
586  /// <summary>
587  /// Stroke a formatted text string.
588  /// </summary>
589  /// <param name="originX">The horizontal coordinate of the text origin.</param>
590  /// <param name="originY">The vertical coordinate of the text origin. See <paramref name="textBaseline"/>.</param>
591  /// <param name="text">The <see cref="FormattedText"/> to draw.</param>
592  /// <param name="strokeColour">The default <see cref="Brush"/> with which to stroke the text.</param>
593  /// <param name="lineWidth">The width of the line with which the text is stroked.</param>
594  /// <param name="lineCap">The line cap to use to stroke the text.</param>
595  /// <param name="lineJoin">The line join to use to stroke the text.</param>
596  /// <param name="lineDash">The line dash to use to stroke the text.</param>
597  /// <param name="textBaseline">The text baseline (determines what <paramref name="originY"/> represents).</param>
598  /// <param name="tag">A tag to identify the stroked text.</param>
599  public void StrokeText(double originX, double originY, IEnumerable<FormattedText> text, Brush strokeColour, TextBaselines textBaseline = TextBaselines.Top, double lineWidth = 1, LineCaps lineCap = LineCaps.Butt, LineJoins lineJoin = LineJoins.Miter, LineDash? lineDash = null, string tag = null)
600  {
601  StrokeText(new Point(originX, originY), text, strokeColour, textBaseline, lineWidth, lineCap, lineJoin, lineDash, tag);
602  }
603 
604  /// <summary>
605  /// Measure a text string.
606  /// See also <seealso cref="Font.MeasureText(string)"/> and <seealso cref="Font.MeasureTextAdvanced(string)"/>.
607  /// </summary>
608  /// <param name="text">The string to measure.</param>
609  /// <param name="font">The font to use to measure the string.</param>
610  /// <returns>The size of the measured <paramref name="text"/>.</returns>
611  public Size MeasureText(string text, Font font)
612  {
613  return font.MeasureText(text);
614  }
615 
616  /// <summary>
617  /// Measure a formatted text string.
618  /// See also <seealso cref="FormattedTextExtensions.Measure(IEnumerable{FormattedText})"/>.
619  /// </summary>
620  /// <param name="text">The collection of <see cref="FormattedText"/> objects to measure.</param>
621  /// <returns>The size of the measured <paramref name="text"/>.</returns>
622  public Size MeasureText(IEnumerable<FormattedText> text)
623  {
624  Font.DetailedFontMetrics metrics = text.Measure();
625 
626  return new Size(metrics.Width, metrics.Height);
627  }
628 
629  /// <summary>
630  /// Fills the underline of the specified text string.
631  /// </summary>
632  /// <param name="originX">The horizontal coordinate of the text origin.</param>
633  /// <param name="originY">The vertical coordinate of the text origin. See <paramref name="textBaseline"/>.</param>
634  /// <param name="text">The string whose underline will be draw.</param>
635  /// <param name="font">The font with which to draw the text.</param>
636  /// <param name="fillColour">The <see cref="Brush"/> to use to fill the underline.</param>
637  /// <param name="textBaseline">The text baseline (determines what <paramref name="originY"/> represents).</param>
638  /// <param name="tag">A tag to identify the filled underline.</param>
639  public void FillTextUnderline(double originX, double originY, string text, Font font, Brush fillColour, TextBaselines textBaseline = TextBaselines.Top, string tag = null)
640  {
641  FillTextUnderline(new Point(originX, originY), text, font, fillColour, textBaseline, tag);
642  }
643 
644  /// <summary>
645  /// Fills the underline of the specified text string.
646  /// </summary>
647  /// <param name="origin">The text origin. See <paramref name="textBaseline"/>.</param>
648  /// <param name="text">The string whose underline will be draw.</param>
649  /// <param name="font">The font with which to draw the text.</param>
650  /// <param name="fillColour">The <see cref="Brush"/> to use to fill the underline.</param>
651  /// <param name="textBaseline">The text baseline (determines what the vertical component of <paramref name="origin"/> represents).</param>
652  /// <param name="tag">A tag to identify the filled underline.</param>
653  public void FillTextUnderline(Point origin, string text, Font font, Brush fillColour, TextBaselines textBaseline = TextBaselines.Top, string tag = null)
654  {
655  GraphicsPath underline = new GraphicsPath().AddTextUnderline(origin, text, font, textBaseline);
656  FillPath(underline, fillColour, tag);
657  }
658 
659  /// <summary>
660  /// Stroke the underline of the specified text string.
661  /// </summary>
662  /// <param name="originX">The horizontal coordinate of the text origin.</param>
663  /// <param name="originY">The vertical coordinate of the text origin. See <paramref name="textBaseline"/>.</param>
664  /// <param name="text">The string whose underline will be drawn.</param>
665  /// <param name="font">The font with which to draw the text.</param>
666  /// <param name="strokeColour">The <see cref="Brush"/> with which to stroke the underline.</param>
667  /// <param name="lineWidth">The width of the line with which the underline is stroked.</param>
668  /// <param name="lineCap">The line cap to use to stroke the underline.</param>
669  /// <param name="lineJoin">The line join to use to stroke the underline.</param>
670  /// <param name="lineDash">The line dash to use to stroke the underline.</param>
671  /// <param name="textBaseline">The text baseline (determines what <paramref name="originY"/> represents).</param>
672  /// <param name="tag">A tag to identify the stroked underline.</param>
673  public void StrokeTextUnderline(double originX, double originY, string text, Font font, Brush strokeColour, TextBaselines textBaseline = TextBaselines.Top, double lineWidth = 1, LineCaps lineCap = LineCaps.Butt, LineJoins lineJoin = LineJoins.Miter, LineDash? lineDash = null, string tag = null)
674  {
675  StrokeTextUnderline(new Point(originX, originY), text, font, strokeColour, textBaseline, lineWidth, lineCap, lineJoin, lineDash, tag);
676  }
677 
678  /// <summary>
679  /// Stroke the underline of the specified text string.
680  /// </summary>
681  /// <param name="origin">The text origin. See <paramref name="textBaseline"/>.</param>
682  /// <param name="text">The string whose underline will be drawn.</param>
683  /// <param name="font">The font with which to draw the text.</param>
684  /// <param name="strokeColour">The <see cref="Brush"/> with which to stroke the underline.</param>
685  /// <param name="lineWidth">The width of the line with which the underline is stroked.</param>
686  /// <param name="lineCap">The line cap to use to stroke the underline.</param>
687  /// <param name="lineJoin">The line join to use to stroke the underline.</param>
688  /// <param name="lineDash">The line dash to use to stroke the underline.</param>
689  /// <param name="textBaseline">The text baseline (determines what the vertical component of <paramref name="origin"/> represents).</param>
690  /// <param name="tag">A tag to identify the stroked underline.</param>
691  public void StrokeTextUnderline(Point origin, string text, Font font, Brush strokeColour, TextBaselines textBaseline = TextBaselines.Top, double lineWidth = 1, LineCaps lineCap = LineCaps.Butt, LineJoins lineJoin = LineJoins.Miter, LineDash? lineDash = null, string tag = null)
692  {
693  GraphicsPath underline = new GraphicsPath().AddTextUnderline(origin, text, font, textBaseline);
694  StrokePath(underline, strokeColour, lineWidth, lineCap, lineJoin, lineDash, tag);
695  }
696 
697 
698  /// <summary>
699  /// Fill the underline of the specified formatted text string.
700  /// </summary>
701  /// <param name="originX">The horizontal coordinate of the text origin.</param>
702  /// <param name="originY">The vertical coordinate of the text origin. See <paramref name="textBaseline"/>.</param>
703  /// <param name="text">The <see cref="FormattedText"/> whose underline will be drawn.</param>
704  /// <param name="fillColour">The default <see cref="Brush"/> to use to fill the underline. This can be overridden by each <paramref name="text"/> element.</param>
705  /// <param name="textBaseline">The text baseline (determines what <paramref name="originY"/> represents).</param>
706  /// <param name="tag">A tag to identify the filled underlined.</param>
707  public void FillTextUnderline(double originX, double originY, IEnumerable<FormattedText> text, Brush fillColour, TextBaselines textBaseline = TextBaselines.Top, string tag = null)
708  {
709  FillTextUnderline(new Point(originX, originY), text, fillColour, textBaseline, tag);
710  }
711 
712  /// <summary>
713  /// Fill the underline of the specified formatted text string.
714  /// </summary>
715  /// <param name="origin">The text origin. See <paramref name="textBaseline"/>.</param>
716  /// <param name="text">The <see cref="FormattedText"/> whose underline will be drawn.</param>
717  /// <param name="fillColour">The default <see cref="Brush"/> to use to fill the underline. This can be overridden by each <paramref name="text"/> element.</param>
718  /// <param name="textBaseline">The text baseline (determines what the vertical component of <paramref name="origin"/> represents).</param>
719  /// <param name="tag">A tag to identify the filled underlined.</param>
720  public void FillTextUnderline(Point origin, IEnumerable<FormattedText> text, Brush fillColour, TextBaselines textBaseline = TextBaselines.Top, string tag = null)
721  {
722  List<FormattedText> enumeratedText = new List<FormattedText>();
723  List<Font.DetailedFontMetrics> allMetrics = new List<Font.DetailedFontMetrics>();
724 
725  Font.DetailedFontMetrics fullMetrics = text.Measure(enumeratedText, allMetrics);
726 
727  Point baselineOrigin = origin;
728 
729  switch (textBaseline)
730  {
731  case TextBaselines.Baseline:
732  baselineOrigin = origin;
733  break;
734  case TextBaselines.Top:
735  baselineOrigin = new Point(origin.X, origin.Y + fullMetrics.Top);
736  break;
737  case TextBaselines.Bottom:
738  baselineOrigin = new Point(origin.X, origin.Y + fullMetrics.Bottom);
739  break;
740  case TextBaselines.Middle:
741  baselineOrigin = new Point(origin.X, origin.Y + fullMetrics.Top * 0.5 + fullMetrics.Bottom * 0.5);
742  break;
743  }
744 
745  for (int i = 0; i < enumeratedText.Count; i++)
746  {
747  FormattedText txt = enumeratedText[i];
748 
749  if (txt.Script == Script.Normal)
750  {
751  Font.DetailedFontMetrics metrics = allMetrics[i];
752 
753  if (i > 0)
754  {
755  FillTextUnderline(baselineOrigin.X + metrics.LeftSideBearing, baselineOrigin.Y, txt.Text, txt.Font, txt.Brush ?? fillColour, TextBaselines.Baseline, tag);
756  }
757  else
758  {
759  FillTextUnderline(baselineOrigin, txt.Text, txt.Font, txt.Brush ?? fillColour, TextBaselines.Baseline, tag);
760  }
761 
762  if (i > 0)
763  {
764  baselineOrigin = new Point(baselineOrigin.X + metrics.Width + metrics.RightSideBearing + metrics.LeftSideBearing, baselineOrigin.Y);
765  }
766  else
767  {
768  baselineOrigin = new Point(baselineOrigin.X + metrics.Width + metrics.RightSideBearing, baselineOrigin.Y);
769  }
770  }
771  else
772  {
773  Font newFont = new Font(txt.Font.FontFamily, txt.Font.FontSize * 0.7, txt.Font.Underline);
774 
775  Font.DetailedFontMetrics metrics = allMetrics[i];
776 
777  if (i == 0)
778  {
779  baselineOrigin = new Point(baselineOrigin.X - metrics.LeftSideBearing, baselineOrigin.Y);
780  }
781 
782  if (txt.Script == Script.Subscript)
783  {
784  FillTextUnderline(baselineOrigin.X + metrics.LeftSideBearing, baselineOrigin.Y + txt.Font.FontSize * 0.14, txt.Text, newFont, txt.Brush ?? fillColour, TextBaselines.Baseline, tag);
785  }
786  else if (txt.Script == Script.Superscript)
787  {
788  FillTextUnderline(baselineOrigin.X + metrics.LeftSideBearing, baselineOrigin.Y - txt.Font.FontSize * 0.33, txt.Text, newFont, txt.Brush ?? fillColour, TextBaselines.Baseline, tag);
789  }
790 
791 
792  if (i > 0)
793  {
794  baselineOrigin = new Point(baselineOrigin.X + metrics.Width + metrics.RightSideBearing + metrics.LeftSideBearing, baselineOrigin.Y);
795  }
796  else
797  {
798  baselineOrigin = new Point(baselineOrigin.X + metrics.Width + metrics.RightSideBearing, baselineOrigin.Y);
799  }
800  }
801  }
802  }
803 
804  /// <summary>
805  /// Stroke the underline of the specified formatted text string.
806  /// </summary>
807  /// <param name="originX">The horizontal coordinate of the text origin.</param>
808  /// <param name="originY">The vertical coordinate of the text origin. See <paramref name="textBaseline"/>.</param>
809  /// <param name="text">The <see cref="FormattedText"/> to draw.</param>
810  /// <param name="strokeColour">The default <see cref="Brush"/> with which to stroke the underline.</param>
811  /// <param name="lineWidth">The width of the line with which the underline is stroked.</param>
812  /// <param name="lineCap">The line cap to use to stroke the underline.</param>
813  /// <param name="lineJoin">The line join to use to stroke the underline.</param>
814  /// <param name="lineDash">The line dash to use to stroke the underline.</param>
815  /// <param name="textBaseline">The text baseline (determines what <paramref name="originY"/> represents).</param>
816  /// <param name="tag">A tag to identify the stroked underline.</param>
817  public void StrokeTextUnderline(double originX, double originY, IEnumerable<FormattedText> text, Brush strokeColour, TextBaselines textBaseline = TextBaselines.Top, double lineWidth = 1, LineCaps lineCap = LineCaps.Butt, LineJoins lineJoin = LineJoins.Miter, LineDash? lineDash = null, string tag = null)
818  {
819  StrokeTextUnderline(new Point(originX, originY), text, strokeColour, textBaseline, lineWidth, lineCap, lineJoin, lineDash, tag);
820  }
821 
822  /// <summary>
823  /// Stroke the underline of the specified formatted text string.
824  /// </summary>
825  /// <param name="origin">The text origin. See <paramref name="textBaseline"/>.</param>
826  /// <param name="text">The <see cref="FormattedText"/> to draw.</param>
827  /// <param name="strokeColour">The default <see cref="Brush"/> with which to stroke the underline.</param>
828  /// <param name="lineWidth">The width of the line with which the underline is stroked.</param>
829  /// <param name="lineCap">The line cap to use to stroke the underline.</param>
830  /// <param name="lineJoin">The line join to use to stroke the underline.</param>
831  /// <param name="lineDash">The line dash to use to stroke the underline.</param>
832  /// <param name="textBaseline">The text baseline (determines what the vertical component of <paramref name="origin"/> represents).</param>
833  /// <param name="tag">A tag to identify the stroked underline.</param>
834  public void StrokeTextUnderline(Point origin, IEnumerable<FormattedText> text, Brush strokeColour, TextBaselines textBaseline = TextBaselines.Top, double lineWidth = 1, LineCaps lineCap = LineCaps.Butt, LineJoins lineJoin = LineJoins.Miter, LineDash? lineDash = null, string tag = null)
835  {
836  List<FormattedText> enumeratedText = new List<FormattedText>();
837  List<Font.DetailedFontMetrics> allMetrics = new List<Font.DetailedFontMetrics>();
838 
839  Font.DetailedFontMetrics fullMetrics = text.Measure(enumeratedText, allMetrics);
840 
841  Point baselineOrigin = origin;
842 
843  switch (textBaseline)
844  {
845  case TextBaselines.Baseline:
846  baselineOrigin = origin;
847  break;
848  case TextBaselines.Top:
849  baselineOrigin = new Point(origin.X, origin.Y + fullMetrics.Top);
850  break;
851  case TextBaselines.Bottom:
852  baselineOrigin = new Point(origin.X, origin.Y + fullMetrics.Bottom);
853  break;
854  case TextBaselines.Middle:
855  baselineOrigin = new Point(origin.X, origin.Y + fullMetrics.Top * 0.5 + fullMetrics.Bottom * 0.5);
856  break;
857  }
858 
859  for (int i = 0; i < enumeratedText.Count; i++)
860  {
861  FormattedText txt = enumeratedText[i];
862 
863  if (txt.Script == Script.Normal)
864  {
865  Font.DetailedFontMetrics metrics = allMetrics[i];
866 
867  if (i > 0)
868  {
869  StrokeTextUnderline(baselineOrigin.X + metrics.LeftSideBearing, baselineOrigin.Y, txt.Text, txt.Font, txt.Brush ?? strokeColour, TextBaselines.Baseline, lineWidth, lineCap, lineJoin, lineDash, tag);
870  }
871  else
872  {
873  StrokeTextUnderline(baselineOrigin, txt.Text, txt.Font, txt.Brush ?? strokeColour, TextBaselines.Baseline, lineWidth, lineCap, lineJoin, lineDash, tag);
874  }
875 
876  if (i > 0)
877  {
878  baselineOrigin = new Point(baselineOrigin.X + metrics.Width + metrics.RightSideBearing + metrics.LeftSideBearing, baselineOrigin.Y);
879  }
880  else
881  {
882  baselineOrigin = new Point(baselineOrigin.X + metrics.Width + metrics.RightSideBearing, baselineOrigin.Y);
883  }
884  }
885  else
886  {
887  Font newFont = new Font(txt.Font.FontFamily, txt.Font.FontSize * 0.7, txt.Font.Underline);
888 
889  Font.DetailedFontMetrics metrics = allMetrics[i];
890 
891  if (i == 0)
892  {
893  baselineOrigin = new Point(baselineOrigin.X - metrics.LeftSideBearing, baselineOrigin.Y);
894  }
895 
896  if (txt.Script == Script.Subscript)
897  {
898  StrokeTextUnderline(baselineOrigin.X + metrics.LeftSideBearing, baselineOrigin.Y + txt.Font.FontSize * 0.14, txt.Text, newFont, txt.Brush ?? strokeColour, TextBaselines.Baseline, lineWidth, lineCap, lineJoin, lineDash, tag);
899  }
900  else if (txt.Script == Script.Superscript)
901  {
902  StrokeTextUnderline(baselineOrigin.X + metrics.LeftSideBearing, baselineOrigin.Y - txt.Font.FontSize * 0.33, txt.Text, newFont, txt.Brush ?? strokeColour, TextBaselines.Baseline, lineWidth, lineCap, lineJoin, lineDash, tag);
903  }
904 
905 
906  if (i > 0)
907  {
908  baselineOrigin = new Point(baselineOrigin.X + metrics.Width + metrics.RightSideBearing + metrics.LeftSideBearing, baselineOrigin.Y);
909  }
910  else
911  {
912  baselineOrigin = new Point(baselineOrigin.X + metrics.Width + metrics.RightSideBearing, baselineOrigin.Y);
913  }
914  }
915  }
916  }
917  }
918 }
VectSharp.GraphicsPath.GetTangentAtRelative
Point GetTangentAtRelative(double position)
Gets the tangent to the point at the relative position specified on the GraphicsPath.
Definition: GraphicsPath.cs:1525
VectSharp.Graphics.Translate
void Translate(double x, double y)
Translate the coordinate system origin.
Definition: Graphics.cs:370
VectSharp.TrueTypeFile
Represents a font file in TrueType format. Reference: http://stevehanov.ca/blog/?id=143,...
Definition: TrueType.cs:31
VectSharp.Font.Underline
FontUnderline Underline
Determines the underline style of text drawn using this font. If this is null, the text is not underl...
Definition: Font.cs:294
VectSharp.Graphics.FillPath
void FillPath(GraphicsPath path, Brush fillColour, string tag=null)
Fill a GraphicsPath.
Definition: Graphics.cs:276
VectSharp.Graphics.StrokePath
void StrokePath(GraphicsPath path, Brush strokeColour, double lineWidth=1, LineCaps lineCap=LineCaps.Butt, LineJoins lineJoin=LineJoins.Miter, LineDash? lineDash=null, string tag=null)
Stroke a GraphicsPath.
Definition: Graphics.cs:292
VectSharp.TrueTypeFile.Get1000EmKerning
PairKerning Get1000EmKerning(char glyph1, char glyph2)
Gets the kerning between two glyphs.
Definition: TrueType.cs:2490
VectSharp.GraphicsPath.MeasureLength
double MeasureLength()
Measures the length of the GraphicsPath.
Definition: GraphicsPath.cs:1156
VectSharp.Font.DetailedFontMetrics.Width
double Width
Width of the text (measured on the actual glyph outlines).
Definition: Font.cs:106
VectSharp.Graphics.FillText
void FillText(Point origin, IEnumerable< FormattedText > text, Brush fillColour, TextBaselines textBaseline=TextBaselines.Top, string tag=null)
Fill a formatted text string.
Definition: Graphics.Text.cs:392
VectSharp.GraphicsPath
Represents a graphics path that can be filled or stroked.
Definition: GraphicsPath.cs:29
VectSharp.Graphics.MeasureText
Size MeasureText(IEnumerable< FormattedText > text)
Measure a formatted text string. See also FormattedTextExtensions.Measure(IEnumerable<FormattedText>)...
Definition: Graphics.Text.cs:622
VectSharp.Graphics.StrokeTextOnPath
void StrokeTextOnPath(GraphicsPath path, string text, Font font, Brush strokeColour, double reference=0, TextAnchors anchor=TextAnchors.Left, TextBaselines textBaseline=TextBaselines.Top, double lineWidth=1, LineCaps lineCap=LineCaps.Butt, LineJoins lineJoin=LineJoins.Miter, LineDash? lineDash=null, string tag=null)
Stroke a text string along a GraphicsPath.
Definition: Graphics.Text.cs:262
VectSharp
Definition: Brush.cs:26
VectSharp.Graphics.FillTextUnderline
void FillTextUnderline(Point origin, IEnumerable< FormattedText > text, Brush fillColour, TextBaselines textBaseline=TextBaselines.Top, string tag=null)
Fill the underline of the specified formatted text string.
Definition: Graphics.Text.cs:720
VectSharp.Graphics.FillText
void FillText(double originX, double originY, string text, Font font, Brush fillColour, TextBaselines textBaseline=TextBaselines.Top, string tag=null)
Fill a text string.
Definition: Graphics.Text.cs:57
VectSharp.FormattedText.Text
string Text
Represents the text represented by this instance.
Definition: FormattedText.cs:55
VectSharp.Font.MeasureTextAdvanced
DetailedFontMetrics MeasureTextAdvanced(string text)
Measure all the metrics of a text string when typeset with this font.
Definition: Font.cs:358
VectSharp.Graphics.StrokeTextUnderline
void StrokeTextUnderline(Point origin, string text, Font font, Brush strokeColour, TextBaselines textBaseline=TextBaselines.Top, double lineWidth=1, LineCaps lineCap=LineCaps.Butt, LineJoins lineJoin=LineJoins.Miter, LineDash? lineDash=null, string tag=null)
Stroke the underline of the specified text string.
Definition: Graphics.Text.cs:691
VectSharp.Graphics.FillTextOnPath
void FillTextOnPath(GraphicsPath path, string text, Font font, Brush fillColour, double reference=0, TextAnchors anchor=TextAnchors.Left, TextBaselines textBaseline=TextBaselines.Top, string tag=null)
Fill a text string along a GraphicsPath.
Definition: Graphics.Text.cs:125
VectSharp.Brush
Represents a brush used to fill or stroke graphics elements. This could be a solid colour,...
Definition: Brush.cs:31
VectSharp.LineCaps
LineCaps
Represents line caps.
Definition: Enums.cs:71
VectSharp.Graphics.Save
void Save()
Save the current transform state (rotation, translation, scale).
Definition: Graphics.cs:524
VectSharp.Font
Represents a typeface with a specific size.
Definition: Font.cs:29
VectSharp.Graphics.FillTextUnderline
void FillTextUnderline(Point origin, string text, Font font, Brush fillColour, TextBaselines textBaseline=TextBaselines.Top, string tag=null)
Fills the underline of the specified text string.
Definition: Graphics.Text.cs:653
VectSharp.TextBaselines
TextBaselines
Represent text baselines.
Definition: Enums.cs:24
VectSharp.Graphics.StrokeText
void StrokeText(double originX, double originY, IEnumerable< FormattedText > text, Brush strokeColour, TextBaselines textBaseline=TextBaselines.Top, double lineWidth=1, LineCaps lineCap=LineCaps.Butt, LineJoins lineJoin=LineJoins.Miter, LineDash? lineDash=null, string tag=null)
Stroke a formatted text string.
Definition: Graphics.Text.cs:599
VectSharp.Graphics.FillText
void FillText(Point origin, string text, Font font, Brush fillColour, TextBaselines textBaseline=TextBaselines.Top, string tag=null)
Fill a text string.
Definition: Graphics.Text.cs:37
VectSharp.Graphics.FillTextUnderline
void FillTextUnderline(double originX, double originY, IEnumerable< FormattedText > text, Brush fillColour, TextBaselines textBaseline=TextBaselines.Top, string tag=null)
Fill the underline of the specified formatted text string.
Definition: Graphics.Text.cs:707
VectSharp.LineJoins
LineJoins
Represents line joining options.
Definition: Enums.cs:92
VectSharp.Graphics.StrokeTextUnderline
void StrokeTextUnderline(double originX, double originY, IEnumerable< FormattedText > text, Brush strokeColour, TextBaselines textBaseline=TextBaselines.Top, double lineWidth=1, LineCaps lineCap=LineCaps.Butt, LineJoins lineJoin=LineJoins.Miter, LineDash? lineDash=null, string tag=null)
Stroke the underline of the specified formatted text string.
Definition: Graphics.Text.cs:817
VectSharp.Graphics.StrokeTextUnderline
void StrokeTextUnderline(double originX, double originY, string text, Font font, Brush strokeColour, TextBaselines textBaseline=TextBaselines.Top, double lineWidth=1, LineCaps lineCap=LineCaps.Butt, LineJoins lineJoin=LineJoins.Miter, LineDash? lineDash=null, string tag=null)
Stroke the underline of the specified text string.
Definition: Graphics.Text.cs:673
VectSharp.FormattedText.Brush
Brush Brush
Represents the brush that should be used to draw the text. If this is null, the default brush is used...
Definition: FormattedText.cs:70
VectSharp.Graphics.StrokeTextUnderline
void StrokeTextUnderline(Point origin, IEnumerable< FormattedText > text, Brush strokeColour, TextBaselines textBaseline=TextBaselines.Top, double lineWidth=1, LineCaps lineCap=LineCaps.Butt, LineJoins lineJoin=LineJoins.Miter, LineDash? lineDash=null, string tag=null)
Stroke the underline of the specified formatted text string.
Definition: Graphics.Text.cs:834
VectSharp.FormattedText.Font
Font Font
Represents the font that should be used to draw the text.
Definition: FormattedText.cs:60
VectSharp.Graphics.Rotate
void Rotate(double angle)
Rotate the coordinate system around the origin.
Definition: Graphics.cs:332
VectSharp.FormattedText.Script
Script Script
Represents the position of the text.
Definition: FormattedText.cs:65
VectSharp.Font.EnableKerning
static bool EnableKerning
Determines whether text kerning is enabled. Note that, even when this is set to false,...
Definition: Font.cs:33
VectSharp.Font.DetailedFontMetrics
Represents detailed information about the metrics of a text string when drawn with a certain font.
Definition: Font.cs:102
VectSharp.GraphicsPath.AddTextUnderline
GraphicsPath AddTextUnderline(Point origin, string text, Font font, TextBaselines textBaseline=TextBaselines.Top)
Add the contour of the underline of the specified text string to the current path.
Definition: GraphicsPath.cs:572
VectSharp.Script
Script
Represents the position of the text.
Definition: FormattedText.cs:30
VectSharp.Point.X
double X
Horizontal (x) coordinate, measured to the right of the origin.
Definition: Point.cs:32
VectSharp.Graphics.FillText
void FillText(double originX, double originY, IEnumerable< FormattedText > text, Brush fillColour, TextBaselines textBaseline=TextBaselines.Top, string tag=null)
Fill a formatted text string.
Definition: Graphics.Text.cs:485
VectSharp.Graphics.MeasureText
Size MeasureText(string text, Font font)
Measure a text string. See also Font.MeasureText(string), Font.MeasureTextAdvanced(string)and .
Definition: Graphics.Text.cs:611
VectSharp.Font.FontFamily
FontFamily FontFamily
Font typeface.
Definition: Font.cs:158
VectSharp.Font.MeasureText
Size MeasureText(string text)
Measure the size of a text string when typeset with this font.
Definition: Font.cs:301
VectSharp.GraphicsPath.GetPointAtRelative
Point GetPointAtRelative(double position)
Gets the point at the relative position specified on the GraphicsPath.
Definition: GraphicsPath.cs:1228
VectSharp.Size
Represents the size of an object.
Definition: Point.cs:146
VectSharp.TextAnchors
TextAnchors
Represents text anchors.
Definition: Enums.cs:50
VectSharp.LineDash
Represents instructions on how to paint a dashed line.
Definition: Enums.cs:113
VectSharp.TrueTypeFile.PairKerning
Contains information describing how the position of two glyphs in a kerning pair should be altered.
Definition: TrueType.cs:4252
VectSharp.Graphics.Restore
void Restore()
Restore the previous transform state (rotation, translation scale).
Definition: Graphics.cs:532
VectSharp.Graphics.StrokeText
void StrokeText(double originX, double originY, string text, Font font, Brush strokeColour, TextBaselines textBaseline=TextBaselines.Top, double lineWidth=1, LineCaps lineCap=LineCaps.Butt, LineJoins lineJoin=LineJoins.Miter, LineDash? lineDash=null, string tag=null)
Stroke a text string.
Definition: Graphics.Text.cs:104
VectSharp.LineDash.SolidLine
static LineDash SolidLine
A solid (not dashed) line
Definition: Enums.cs:117
VectSharp.Font.FontSize
double FontSize
Font size, in graphics units.
Definition: Font.cs:153
VectSharp.Point
Represents a point relative to an origin in the top-left corner.
Definition: Point.cs:28
VectSharp.Graphics.StrokeText
void StrokeText(Point origin, string text, Font font, Brush strokeColour, TextBaselines textBaseline=TextBaselines.Top, double lineWidth=1, LineCaps lineCap=LineCaps.Butt, LineJoins lineJoin=LineJoins.Miter, LineDash? lineDash=null, string tag=null)
Stroke a text string.
Definition: Graphics.Text.cs:80
VectSharp.Graphics.StrokeText
void StrokeText(Point origin, IEnumerable< FormattedText > text, Brush strokeColour, TextBaselines textBaseline=TextBaselines.Top, double lineWidth=1, LineCaps lineCap=LineCaps.Butt, LineJoins lineJoin=LineJoins.Miter, LineDash? lineDash=null, string tag=null)
Stroke a formatted text string.
Definition: Graphics.Text.cs:502
VectSharp.FormattedText
Represents a run of text that should be drawn with the same style.
Definition: FormattedText.cs:51
VectSharp.Graphics.FillTextUnderline
void FillTextUnderline(double originX, double originY, string text, Font font, Brush fillColour, TextBaselines textBaseline=TextBaselines.Top, string tag=null)
Fills the underline of the specified text string.
Definition: Graphics.Text.cs:639
VectSharp.Point.Y
double Y
Vertical (y) coordinate, measured to the bottom of the origin.
Definition: Point.cs:37
VectSharp.FontFamily.TrueTypeFile
TrueTypeFile TrueTypeFile
Parsed TrueType font file for this font family. See also: VectSharp.TrueTypeFile.
Definition: Font.cs:586