Paradox Game Engine  v1.0.0 beta06
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros Pages
SpriteFont.cs
Go to the documentation of this file.
1 // Copyright (c) 2014 Silicon Studio Corp. (http://siliconstudio.co.jp)
2 // This file is distributed under GPL v3. See LICENSE.md for details.
3 using System;
4 using System.Collections.Generic;
5 using System.Runtime.InteropServices;
6 using System.Text;
7 
8 using SiliconStudio.Core;
9 using SiliconStudio.Core.Diagnostics;
10 using SiliconStudio.Core.Mathematics;
11 using SiliconStudio.Core.Serialization.Contents;
12 using SiliconStudio.Core.Serialization.Converters;
14 
18 
19 namespace SiliconStudio.Paradox.Graphics
20 {
21  /// <summary>
22  /// SpriteFont to use with <see cref="SpriteBatch"/>. See <see cref="SpriteFont"/> to learn how to use it.
23  /// </summary>
24  [ContentSerializer(typeof(DataContentConverterSerializer<DynamicSpriteFontData, SpriteFont>))]
25  [ContentSerializer(typeof(DataContentConverterSerializer<StaticSpriteFontData, SpriteFont>))]
26  public class SpriteFont : ComponentBase
27  {
28  private Vector4 nullVector4 = Vector4.Zero;
29 
30  /// <summary>
31  /// The <see cref="SiliconStudio.Paradox.Graphics.Font.FontSystem"/> that is managing this sprite font.
32  /// </summary>
33  protected readonly FontSystem FontSystem;
34 
35  // Lookup table indicates which way to move along each axis per SpriteEffects enum value.
36  private static readonly Vector2[] axisDirectionTable = {
37  new Vector2(-1, -1),
38  new Vector2(1, -1),
39  new Vector2(-1, 1),
40  new Vector2(1, 1)
41  };
42 
43  // Lookup table indicates which axes are mirrored for each SpriteEffects enum value.
44  private static readonly Vector2[] axisIsMirroredTable = {
45  new Vector2(0, 0),
46  new Vector2(1, 0),
47  new Vector2(0, 1),
48  new Vector2(1, 1)
49  };
50 
51  public static readonly Logger Logger = GlobalLogger.GetLogger("SpriteFont");
52  protected SwizzleMode Swizzle;
53  protected float BaseOffsetY;
54  protected float DefaultLineSpacing;
55  protected readonly Dictionary<int, float> KerningMap = new Dictionary<int, float>();
56 
57  public IReadOnlyList<Texture2D> Textures { get; protected set; }
58 
59  /// <summary>
60  /// Gets the font size (resp. the default font size) for static fonts (resp. for dynamic fonts) in pixels.
61  /// </summary>
62  public float Size { get; private set; }
63 
64  /// <summary>
65  /// Gets or sets the default character for the font.
66  /// </summary>
67  public char? DefaultCharacter { get; set; }
68 
69  /// <summary>
70  /// Completely skips characters that are not in the map.
71  /// </summary>
72  public bool IgnoreUnkownCharacters { get; set; }
73 
74  /// <summary>
75  /// Gets or sets extra spacing (in pixels) between the characters for the current font <see cref="Size"/>.
76  /// This value is scaled during the draw in the case of dynamic fonts.
77  /// Use <see cref="GetExtraSpacing"/> to get the value of the extra spacing for a given font size.
78  /// </summary>
79  public float ExtraSpacing { get; set; }
80 
81  /// <summary>
82  /// Gets or sets the extra line spacing (in pixels) to add to the default font line spacing for the current font <see cref="Size"/>.
83  /// This value will be scaled during the draw in the case of dynamic fonts.
84  /// Use <see cref="GetExtraLineSpacing"/> to get the value of the extra spacing for a given font size.
85  /// </summary>
86  /// <remarks>Line spacing is the distance between the base lines of two consecutive lines of text (blank space as well as characters' height are thus included).</remarks>
87  public float ExtraLineSpacing { get; set; }
88 
89  /// <summary>
90  /// Gets a boolean indicating if the current font is dynamic or not.
91  /// </summary>
92  public bool IsDynamic { get; private set; }
93 
94  protected SpriteFont(FontSystem fontSystem, SpriteFontData fontData, bool isDynamic)
95  {
96  // register itself to the managing font system
97  FontSystem = fontSystem;
98  FontSystem.AllocatedSpriteFonts.Add(this);
99 
100  // determine the type of the font
101  IsDynamic = isDynamic;
102 
103  // Read the font data.
104  Size = fontData.Size;
105  ExtraSpacing = fontData.ExtraSpacing;
106  ExtraLineSpacing = fontData.ExtraLineSpacing;
107  DefaultCharacter = fontData.DefaultCharacter;
108  }
109 
110  protected override void Destroy()
111  {
112  base.Destroy();
113 
114  // unregister itself from its managing system
115  FontSystem.AllocatedSpriteFonts.Remove(this);
116  }
117 
118  public interface IFontManager
119  {
120  void New();
121  }
122 
123  /// <summary>
124  /// Get the value of the extra line spacing for the given font size.
125  /// </summary>
126  /// <param name="fontSize">The font size in pixels</param>
127  /// <returns>The value of the character spacing</returns>
128  public virtual float GetExtraSpacing(float fontSize)
129  {
130  return fontSize / Size * ExtraSpacing;
131  }
132 
133  /// <summary>
134  /// Get the value of the extra character spacing for the given font size.
135  /// </summary>
136  /// <param name="fontSize">The font size in pixels</param>
137  /// <returns>The value of the character spacing</returns>
138  public virtual float GetExtraLineSpacing(float fontSize)
139  {
140  return fontSize / Size * ExtraLineSpacing;
141  }
142 
143  /// <summary>
144  /// Get the value of the font default line spacing for the given font size.
145  /// </summary>
146  /// <param name="fontSize">The font size in pixels</param>
147  /// <returns>The value of the default line spacing</returns>
148  public virtual float GetFontDefaultLineSpacing(float fontSize)
149  {
150  return fontSize / Size * DefaultLineSpacing;
151  }
152 
153  /// <summary>
154  /// Get the value of the base offset for the given font size.
155  /// </summary>
156  /// <param name="fontSize">The font size in pixels</param>
157  /// <returns>The value of the base offset</returns>
158  protected virtual float GetBaseOffsetY(float fontSize)
159  {
160  return fontSize / Size * BaseOffsetY;
161  }
162 
163  /// <summary>
164  /// Gets the value of the total line spacing (font default + user defined) in pixels for a given font size.
165  /// </summary>
166  /// <remarks>Line spacing is the distance between the base lines of two consecutive lines of text (blank space as well as characters' height are thus included).</remarks>
167  public float GetTotalLineSpacing(float fontSize)
168  {
169  return GetExtraLineSpacing(fontSize) + GetFontDefaultLineSpacing(fontSize);
170  }
171 
172  internal void InternalDraw(ref StringProxy text, ref InternalDrawCommand drawCommand, TextAlignment alignment)
173  {
174  // If the text is mirrored, offset the start position accordingly.
175  if (drawCommand.SpriteEffects != SpriteEffects.None)
176  {
177  drawCommand.Origin -= MeasureString(ref text, ref drawCommand.FontSize) * axisIsMirroredTable[(int)drawCommand.SpriteEffects & 3];
178  }
179 
180  // Draw each character in turn.
181  ForEachGlyph(ref text, ref drawCommand.FontSize, InternalDrawGlyph, ref drawCommand, alignment, true);
182  }
183 
184  /// <summary>
185  /// Pre-generate synchronously the glyphs of the character needed to render the provided text at the provided size.
186  /// </summary>
187  /// <param name="text">The text containing the characters to pre-generate</param>
188  /// <param name="size">The size of the font</param>
189  public void PreGenerateGlyphs(string text, Vector2 size)
190  {
191  var proxyText = new StringProxy(text);
192  PreGenerateGlyphs(ref proxyText, ref size);
193  }
194 
195  internal virtual void PreGenerateGlyphs(ref StringProxy text, ref Vector2 size)
196  {
197 
198  }
199 
200  internal void InternalDrawGlyph(ref InternalDrawCommand parameters, ref Vector2 fontSize, ref Glyph glyph, float x, float y, float nextx)
201  {
202  if (char.IsWhiteSpace((char)glyph.Character) || glyph.Subrect.Width == 0 || glyph.Subrect.Height == 0)
203  return;
204 
205  var spriteEffects = parameters.SpriteEffects;
206 
207  var offset = new Vector2(x, y + GetBaseOffsetY(fontSize.Y) + glyph.Offset.Y);
208  Vector2.Modulate(ref offset, ref axisDirectionTable[(int)spriteEffects & 3], out offset);
209  Vector2.Add(ref offset, ref parameters.Origin, out offset);
210  offset.X = (float)Math.Round(offset.X);
211  offset.Y = (float)Math.Round(offset.Y);
212 
213  if (spriteEffects != SpriteEffects.None)
214  {
215  // For mirrored characters, specify bottom and/or right instead of top left.
216  var glyphRect = new Vector2(glyph.Subrect.Right - glyph.Subrect.Left, glyph.Subrect.Top - glyph.Subrect.Bottom);
217  Vector2.Modulate(ref glyphRect, ref axisIsMirroredTable[(int)spriteEffects & 3], out offset);
218  }
219  var destination = new RectangleF(parameters.Position.X, parameters.Position.Y, parameters.Scale.X, parameters.Scale.Y);
220  RectangleF? sourceRectangle = glyph.Subrect;
221  parameters.SpriteBatch.DrawSprite(Textures[glyph.BitmapIndex], ref destination, true, ref sourceRectangle, parameters.Color, parameters.Rotation, ref offset, spriteEffects, ImageOrientation.AsIs, parameters.Depth, Swizzle, true);
222  }
223 
224  internal void InternalUIDraw(ref StringProxy text, ref InternalUIDrawCommand drawCommand)
225  {
226  if (!IsDynamic && (drawCommand.FontScale.X != 1 || drawCommand.FontScale.Y != 1)) // ensure that static font are not scaled internally
227  {
228  drawCommand.SnapText = false; // we don't want snapping of the resolution of the screen does not match virtual resolution. (character alignment problems)
229  drawCommand.FontScale = Vector2.One;
230  }
231 
232  var fontSize = drawCommand.FontSize * drawCommand.FontScale;
233  var scaledSize = new Vector2(drawCommand.Size.X * drawCommand.FontScale.X, drawCommand.Size.Y * drawCommand.FontScale.Y);
234  ForEachGlyph(ref text, ref fontSize, InternalUIDrawGlyph, ref drawCommand, drawCommand.Alignment, true, scaledSize);
235  }
236 
237  internal void InternalUIDrawGlyph(ref InternalUIDrawCommand parameters, ref Vector2 fontSize, ref Glyph glyph, float x, float y, float nextx)
238  {
239  if (char.IsWhiteSpace((char)glyph.Character))
240  return;
241 
242  var xShift = x + glyph.Subrect.Width / 2f;
243  var yShift = y + GetBaseOffsetY(fontSize.Y) + glyph.Offset.Y + glyph.Subrect.Height / 2f;
244  var xScaledShift = xShift / parameters.FontScale.X;
245  var yScaledShift = yShift / parameters.FontScale.Y;
246 
247  var worldMatrix = parameters.WorldMatrix;
248  worldMatrix.M41 += worldMatrix.M11 * xScaledShift + worldMatrix.M21 * yScaledShift;
249  worldMatrix.M42 += worldMatrix.M12 * xScaledShift + worldMatrix.M22 * yScaledShift;
250  worldMatrix.M43 += worldMatrix.M13 * xScaledShift + worldMatrix.M23 * yScaledShift;
251 
252  var elementSize = new Vector3(glyph.Subrect.Width / parameters.FontScale.X, glyph.Subrect.Height / parameters.FontScale.Y, 0);
253 
254  RectangleF sourceRectangle = glyph.Subrect;
255  parameters.Batch.DrawImage(Textures[glyph.BitmapIndex], null, ref worldMatrix, ref sourceRectangle, ref elementSize, ref nullVector4,
256  ref parameters.Color, parameters.DepthBias, ImageOrientation.AsIs, Swizzle, parameters.SnapText);
257  }
258 
259  /// <summary>
260  /// Returns the width and height of the provided text for the current font size <see cref="Size"/>
261  /// </summary>
262  /// <param name="text">The string to measure.</param>
263  /// <returns>Vector2.</returns>
264  public Vector2 MeasureString(string text)
265  {
266  return MeasureString(text, new Vector2(Size, Size), text.Length);
267  }
268 
269  /// <summary>
270  /// Returns the width and height of the provided text for the current font size <see cref="Size"/>
271  /// </summary>
272  /// <param name="text">The string to measure.</param>
273  /// <returns>Vector2.</returns>
274  public Vector2 MeasureString(StringBuilder text)
275  {
276  return MeasureString(text, new Vector2(Size, Size), text.Length);
277  }
278 
279  /// <summary>
280  /// Returns the width and height of the provided text for a given font size
281  /// </summary>
282  /// <param name="text">The string to measure.</param>
283  /// <param name="fontSize">The size of the font (ignored in the case of static fonts)</param>
284  /// <returns>Vector2.</returns>
285  public Vector2 MeasureString(string text, float fontSize)
286  {
287  return MeasureString(text, new Vector2(fontSize, fontSize), text.Length);
288  }
289 
290  /// <summary>
291  /// Returns the width and height of the provided text for a given font size
292  /// </summary>
293  /// <param name="text">The string to measure.</param>
294  /// <param name="fontSize">The size of the font (ignored in the case of static fonts)</param>
295  /// <returns>Vector2.</returns>
296  public Vector2 MeasureString(StringBuilder text, float fontSize)
297  {
298  return MeasureString(text, new Vector2(fontSize, fontSize), text.Length);
299  }
300 
301  /// <summary>
302  /// Returns the width and height of the provided text for a given font size
303  /// </summary>
304  /// <param name="text">The string to measure.</param>
305  /// <param name="fontSize">The size of the font (ignored in the case of static fonts)</param>
306  /// <returns>Vector2.</returns>
307  public Vector2 MeasureString(string text, Vector2 fontSize)
308  {
309  return MeasureString(text, ref fontSize, text.Length);
310  }
311 
312  /// <summary>
313  /// Returns the width and height of the provided text for a given font size
314  /// </summary>
315  /// <param name="text">The string to measure.</param>
316  /// <param name="fontSize">The size of the font (ignored in the case of static fonts)</param>
317  /// <returns>Vector2.</returns>
318  public Vector2 MeasureString(StringBuilder text, Vector2 fontSize)
319  {
320  return MeasureString(text, ref fontSize, text.Length);
321  }
322 
323  /// <summary>
324  /// Returns the width and height of the provided text for a given font size
325  /// </summary>
326  /// <param name="text">The string to measure.</param>
327  /// <param name="fontSize">The size of the font (ignored in the case of static fonts)</param>
328  /// <returns>Vector2.</returns>
329  public Vector2 MeasureString(string text, ref Vector2 fontSize)
330  {
331  return MeasureString(text, ref fontSize, text.Length);
332  }
333 
334  /// <summary>
335  /// Returns the width and height of the provided text for a given font size
336  /// </summary>
337  /// <param name="text">The string to measure.</param>
338  /// <param name="fontSize">The size of the font (ignored in the case of static fonts)</param>
339  /// <returns>Vector2.</returns>
340  public Vector2 MeasureString(StringBuilder text, ref Vector2 fontSize)
341  {
342  return MeasureString(text, ref fontSize, text.Length);
343  }
344 
345  /// <summary>
346  /// Returns the width and height of the provided text for a given font size
347  /// </summary>
348  /// <param name="text">The string to measure.</param>
349  /// <param name="fontSize">The size of the font (ignored in the case of static fonts)</param>
350  /// <param name="length">The length of the string to measure</param>
351  /// <returns>Vector2.</returns>
352  public Vector2 MeasureString(string text, Vector2 fontSize, int length)
353  {
354  return MeasureString(text, ref fontSize, length);
355  }
356 
357  /// <summary>
358  /// Returns the width and height of the provided text for a given font size
359  /// </summary>
360  /// <param name="text">The string to measure.</param>
361  /// <param name="fontSize">The size of the font (ignored in the case of static fonts)</param>
362  /// <param name="length">The length of the string to measure</param>
363  /// <returns>Vector2.</returns>
364  public Vector2 MeasureString(StringBuilder text, Vector2 fontSize, int length)
365  {
366  return MeasureString(text, ref fontSize, length);
367  }
368 
369  /// <summary>
370  /// Returns the width and height of the provided text for a given font size
371  /// </summary>
372  /// <param name="text">The string to measure.</param>
373  /// <param name="fontSize">The size of the font (ignored in the case of static fonts)</param>
374  /// <param name="length">The length of the string to measure</param>
375  /// <returns>Vector2.</returns>
376  public Vector2 MeasureString(string text, ref Vector2 fontSize, int length)
377  {
378  if (text == null)
379  throw new ArgumentNullException("text");
380 
381  var proxy = new StringProxy(text, length);
382  return MeasureString(ref proxy, ref fontSize);
383  }
384 
385  /// <summary>
386  /// Returns the width and height of the provided text for a given font size
387  /// </summary>
388  /// <param name="text">The string to measure.</param>
389  /// <param name="fontSize">The size of the font (ignored in the case of static fonts)</param>
390  /// <param name="length">The length of the string to measure</param>
391  /// <returns>Vector2.</returns>
392  public Vector2 MeasureString(StringBuilder text, ref Vector2 fontSize, int length)
393  {
394  if (text == null)
395  throw new ArgumentNullException("text");
396 
397  var proxy = new StringProxy(text, length);
398  return MeasureString(ref proxy, ref fontSize);
399  }
400 
401  internal Vector2 MeasureString(ref StringProxy text, ref Vector2 size)
402  {
403  var result = Vector2.Zero;
404  ForEachGlyph(ref text, ref size, MeasureStringGlyph, ref result, TextAlignment.Left, false); // text size is independent from the text alignment
405  return result;
406  }
407 
408  /// <summary>
409  /// Checks whether the provided character is present in the character map of the current <see cref="SpriteFont"/>.
410  /// </summary>
411  /// <param name="c">The character to check.</param>
412  /// <returns>true if the <paramref name="c"/> is present in the character map, false - otherwise.</returns>
413  public virtual bool IsCharPresent(char c)
414  {
415  return false;
416  }
417 
418  /// <summary>
419  /// Return the glyph associated to provided character at the given size.
420  /// </summary>
421  /// <param name="character">The character we want the glyph of</param>
422  /// <param name="fontSize">The font size in pixel</param>
423  /// <param name="uploadGpuResources">Indicate if the GPU resource should be uploaded or not.</param>
424  /// <returns>The glyph corresponding to the request or null if not existing</returns>
425  protected virtual Glyph GetGlyph(char character, ref Vector2 fontSize, bool uploadGpuResources)
426  {
427  return null;
428  }
429 
430  private void MeasureStringGlyph(ref Vector2 result, ref Vector2 fontSize, ref Glyph glyph, float x, float y, float nextx)
431  {
432  var h = y + GetTotalLineSpacing(fontSize.Y);
433  if (nextx > result.X)
434  {
435  result.X = nextx;
436  }
437  if (h > result.Y)
438  {
439  result.Y = h;
440  }
441  }
442 
443  private delegate void GlyphAction<T>(ref T parameters, ref Vector2 fontSize, ref Glyph glyph, float x, float y, float nextx);
444 
445  private int FindCariageReturn(ref StringProxy text, int startIndex)
446  {
447  var index = startIndex;
448 
449  while (index < text.Length && text[index] != '\n')
450  ++index;
451 
452  return index;
453  }
454 
455  private void ForEachGlyph<T>(ref StringProxy text, ref Vector2 fontSize, GlyphAction<T> action, ref T parameters, TextAlignment scanOrder, bool updateGpuResources, Vector2? elementsize = null)
456  {
457  if (scanOrder == TextAlignment.Left)
458  {
459  // scan the whole text only one time following the text letter order
460  ForGlyph(ref text, ref fontSize, action, ref parameters, 0, text.Length, updateGpuResources);
461  }
462  else // scan the text line by line incrementing y start position
463  {
464  // measure the whole string in order to be able to determine xStart
465  var wholeSize = elementsize.HasValue ? elementsize.Value : MeasureString(ref text, ref fontSize);
466 
467  // scan the text line by line
468  var yStart = 0f;
469  var startIndex = 0;
470  var endIndex = FindCariageReturn(ref text, 0);
471  while (startIndex < text.Length)
472  {
473  // measure the size of the current line
474  var lineSize = Vector2.Zero;
475  ForGlyph(ref text, ref fontSize, MeasureStringGlyph, ref lineSize, startIndex, endIndex, updateGpuResources);
476 
477  // scan the line
478  var xStart = (scanOrder == TextAlignment.Center) ? (wholeSize.X - lineSize.X) / 2 : wholeSize.X - lineSize.X;
479  ForGlyph(ref text, ref fontSize, action, ref parameters, startIndex, endIndex, updateGpuResources, xStart, yStart);
480 
481  // update variable before going to next line
482  yStart += GetTotalLineSpacing(fontSize.Y);
483  startIndex = endIndex + 1;
484  endIndex = FindCariageReturn(ref text, startIndex);
485  }
486  }
487  }
488 
489  private void ForGlyph<T>(ref StringProxy text, ref Vector2 fontSize, GlyphAction<T> action, ref T parameters, int forStart, int forEnd, bool updateGpuResources, float startX = 0, float startY = 0)
490  {
491  var key = 0;
492  var x = startX;
493  var y = startY;
494  for (var i = forStart; i < forEnd; i++)
495  {
496  char character = text[i];
497 
498  switch (character)
499  {
500  case '\r':
501  // Skip carriage returns.
502  key |= character;
503  continue;
504 
505  case '\n':
506  // New line.
507  x = 0;
508  y += GetTotalLineSpacing(fontSize.Y);
509  key |= character;
510  break;
511 
512  default:
513  // Output this character.
514  var glyph = GetGlyph(character, ref fontSize, updateGpuResources);
515  if (glyph == null && !IgnoreUnkownCharacters && DefaultCharacter.HasValue)
516  glyph = GetGlyph(DefaultCharacter.Value, ref fontSize, updateGpuResources);
517  if(glyph == null)
518  continue;
519 
520  key |= character;
521 
522  float dx = glyph.Offset.X;
523 
524  float kerningOffset;
525  if (KerningMap != null && KerningMap.TryGetValue(key, out kerningOffset))
526  dx += kerningOffset;
527 
528  float nextX = x + glyph.XAdvance + GetExtraSpacing(fontSize.X);
529  action(ref parameters, ref fontSize, ref glyph, x + dx, y, nextX);
530  x = nextX;
531  break;
532  }
533 
534  // Shift the kerning key
535  key = (key << 16);
536  }
537  }
538 
539  [StructLayout(LayoutKind.Sequential)]
540  internal struct StringProxy
541  {
542  private string textString;
543  private StringBuilder textBuilder;
544  public readonly int Length;
545 
546  public StringProxy(string text)
547  {
548  textString = text;
549  textBuilder = null;
550  Length = text.Length;
551  }
552 
553  public StringProxy(StringBuilder text)
554  {
555  textBuilder = text;
556  textString = null;
557  Length = text.Length;
558  }
559 
560  public StringProxy(string text, int length)
561  {
562  textString = text;
563  textBuilder = null;
564  Length = Math.Max(0, Math.Min(length, text.Length));
565  }
566 
567  public StringProxy(StringBuilder text, int length)
568  {
569  textBuilder = text;
570  textString = null;
571  Length = Math.Max(0, Math.Min(length, text.Length));
572  }
573 
574  public bool IsNull { get { return textString == null && textBuilder == null; } }
575 
576  public char this[int index]
577  {
578  get
579  {
580  if (textString != null)
581  {
582  return textString[index];
583  }
584  return textBuilder[index];
585  }
586  }
587  }
588 
589  /// <summary>
590  /// Structure InternalDrawCommand used to pass parameters to InternalDrawGlyph
591  /// </summary>
592  internal struct InternalDrawCommand
593  {
594  public InternalDrawCommand(SpriteBatch spriteBatch, ref Vector2 fontSize, ref Vector2 position, ref Color color, float rotation, ref Vector2 origin, ref Vector2 scale, SpriteEffects spriteEffects, float depth)
595  {
596  SpriteBatch = spriteBatch;
597  Position = position;
598  Color = color;
599  Rotation = rotation;
600  Origin = origin;
601  Scale = scale;
602  SpriteEffects = spriteEffects;
603  Depth = depth;
604  FontSize = fontSize;
605  }
606 
607  public Vector2 FontSize;
608 
609  public SpriteBatch SpriteBatch;
610 
611  public Vector2 Position;
612 
613  public Color Color;
614 
615  public float Rotation;
616 
617  public Vector2 Origin;
618 
619  public Vector2 Scale;
620 
622 
623  public float Depth;
624  }
625 
626  /// <summary>
627  /// Structure InternalDrawCommand used to pass parameters to InternalDrawGlyph
628  /// </summary>
629  internal struct InternalUIDrawCommand
630  {
631  public float FontSize;
632 
633  public Vector2 FontScale;
634 
635  public UIBatch Batch;
636 
637  public Matrix WorldMatrix;
638 
639  public Vector2 Size;
640 
641  public Color Color;
642 
643  public TextAlignment Alignment;
644 
645  public int DepthBias;
646 
647  public bool SnapText;
648  }
649  }
650 }
Vector2 MeasureString(StringBuilder text, Vector2 fontSize, int length)
Returns the width and height of the provided text for a given font size
Definition: SpriteFont.cs:364
SiliconStudio.Paradox.Games.Mathematics.Vector2 Vector2
Represents a two dimensional mathematical vector.
Definition: Vector2.cs:42
Vector2 MeasureString(StringBuilder text, ref Vector2 fontSize)
Returns the width and height of the provided text for a given font size
Definition: SpriteFont.cs:340
Vector2 MeasureString(string text, ref Vector2 fontSize)
Returns the width and height of the provided text for a given font size
Definition: SpriteFont.cs:329
float Length()
Calculates the length of the vector.
Definition: Vector2.cs:166
void PreGenerateGlyphs(string text, Vector2 size)
Pre-generate synchronously the glyphs of the character needed to render the provided text at the prov...
Definition: SpriteFont.cs:189
Vector2 MeasureString(string text)
Returns the width and height of the provided text for the current font size Size
Definition: SpriteFont.cs:264
TextAlignment
Specify the available text alignment when rendering text.
Definition: TextAlignment.cs:8
_In_ size_t _In_ DXGI_FORMAT _In_ size_t _In_ float size_t y
Definition: DirectXTexP.h:191
override void Destroy()
Disposes of object resources.
Definition: SpriteFont.cs:110
Vector2 MeasureString(string text, float fontSize)
Returns the width and height of the provided text for a given font size
Definition: SpriteFont.cs:285
The system managing the fonts.
Definition: FontSystem.cs:13
virtual Glyph GetGlyph(char character, ref Vector2 fontSize, bool uploadGpuResources)
Return the glyph associated to provided character at the given size.
Definition: SpriteFont.cs:425
Specifies that the object is null.
SpriteFont(FontSystem fontSystem, SpriteFontData fontData, bool isDynamic)
Definition: SpriteFont.cs:94
SpriteEffects
Defines sprite mirroring options.
Vector2 MeasureString(StringBuilder text, Vector2 fontSize)
Returns the width and height of the provided text for a given font size
Definition: SpriteFont.cs:318
Vector2 MeasureString(StringBuilder text, ref Vector2 fontSize, int length)
Returns the width and height of the provided text for a given font size
Definition: SpriteFont.cs:392
Base class for a framework component.
SharpDX.DirectWrite.Font Font
virtual float GetFontDefaultLineSpacing(float fontSize)
Get the value of the font default line spacing for the given font size.
Definition: SpriteFont.cs:148
Base implementation for ILogger.
Definition: Logger.cs:10
Define a RectangleF. This structure is slightly different from System.Drawing.RectangleF as it is int...
Definition: RectangleF.cs:36
SiliconStudio.Core.Mathematics.Rectangle Rectangle
Definition: SpriteFont.cs:16
SpriteFont to use with SpriteBatch. See SpriteFont to learn how to use it.
Definition: SpriteFont.cs:26
Vector2 MeasureString(StringBuilder text, float fontSize)
Returns the width and height of the provided text for a given font size
Definition: SpriteFont.cs:296
Represents a four dimensional mathematical vector.
Definition: Vector4.cs:42
virtual float GetBaseOffsetY(float fontSize)
Get the value of the base offset for the given font size.
Definition: SpriteFont.cs:158
float GetTotalLineSpacing(float fontSize)
Gets the value of the total line spacing (font default + user defined) in pixels for a given font siz...
Definition: SpriteFont.cs:167
virtual float GetExtraLineSpacing(float fontSize)
Get the value of the extra character spacing for the given font size.
Definition: SpriteFont.cs:138
readonly FontSystem FontSystem
The SiliconStudio.Paradox.Graphics.Font.FontSystem that is managing this sprite font.
Definition: SpriteFont.cs:33
Represents a 32-bit color (4 bytes) in the form of RGBA (in byte order: R, G, B, A).
Definition: Color.cs:16
Description of a glyph (a single character)
Definition: Glyph.cs:12
Vector2 MeasureString(string text, Vector2 fontSize, int length)
Returns the width and height of the provided text for a given font size
Definition: SpriteFont.cs:352
Vector2 MeasureString(string text, Vector2 fontSize)
Returns the width and height of the provided text for a given font size
Definition: SpriteFont.cs:307
SwizzleMode
Specify how to swizzle a vector.
Definition: SwizzleMode.cs:8
virtual bool IsCharPresent(char c)
Checks whether the provided character is present in the character map of the current SpriteFont...
Definition: SpriteFont.cs:413
SiliconStudio.Core.Mathematics.Vector3 Vector3
virtual float GetExtraSpacing(float fontSize)
Get the value of the extra line spacing for the given font size.
Definition: SpriteFont.cs:128
Vector2 MeasureString(string text, ref Vector2 fontSize, int length)
Returns the width and height of the provided text for a given font size
Definition: SpriteFont.cs:376
Structure using the same layout than System.Drawing.Rectangle
Definition: Rectangle.cs:35
_In_ size_t _In_ size_t size
Definition: DirectXTexP.h:175
SiliconStudio.Core.Mathematics.Color Color
Definition: SpriteFont.cs:15
SiliconStudio.Core.Mathematics.RectangleF RectangleF
Definition: SpriteFont.cs:17
Vector2 MeasureString(StringBuilder text)
Returns the width and height of the provided text for the current font size Size
Definition: SpriteFont.cs:274
Represents a 4x4 mathematical matrix.
Definition: Matrix.cs:47