Paradox Game Engine  v1.0.0 beta06
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros Pages
SpriteFontAsset.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 
4 using System.Collections.Generic;
5 using System.ComponentModel;
6 
7 using SiliconStudio.Assets;
8 using SiliconStudio.Assets.Compiler;
9 using SiliconStudio.Core;
10 using SiliconStudio.Core.IO;
12 
13 namespace SiliconStudio.Paradox.Assets.SpriteFont
14 {
15  /// <summary>
16  /// Description of a font.
17  /// </summary>
18  [DataContract("SpriteFont")]
19  [AssetFileExtension(FileExtension)]
20  [AssetCompiler(typeof(SpriteFontAssetCompiler))]
21  [ThumbnailCompiler(PreviewerCompilerNames.FontThumbnailCompilerQualifiedName)]
22  [AssetFactory(typeof(SpriteFontFactory))]
23  [AssetDescription("Sprite Font", "A sprite containing a rendered font", true)]
24  public class SpriteFontAsset : Asset
25  {
26  /// <summary>
27  /// The default file extension used by the <see cref="SpriteFontAsset"/>.
28  /// </summary>
29  public const string FileExtension = ".pdxfnt";
30 
31  /// <summary>
32  /// Gets or sets the source file containing the font data if required.
33  /// </summary>
34  /// <value>The source.</value>
35  [DataMember(10)]
36  public UFile Source { get; set; }
37 
38  /// <summary>
39  /// Input can be either a system (TrueType) font or a specially marked bitmap file.
40  /// </summary>
41  [DataMember(20)]
42  public string FontName { get; set; }
43 
44  /// <summary>
45  /// Size in points for TrueType fonts (ignored when converting a bitmap font).
46  /// </summary>
47  [DataMember(30)]
48  [StepRangeAttribute(1, 500, 1, 10)]
49  public float Size { get; set; }
50 
51  /// <summary>
52  /// Style for the font. 'regular', 'bold', 'italic', 'underline', 'strikeout'. Default is 'regular
53  /// </summary>
54  [DataMember(40)]
55  public FontStyle Style { get; set; }
56 
57  /// <summary>
58  /// Determine if the characters are pre-generated off-line or at run-time.
59  /// </summary>
60  [DataMember(50)]
61  public bool IsDynamic { get; set; }
62 
63  /// <summary>
64  /// Fallback character used when asked to render a codepoint that is not
65  /// included in the font. If zero, missing characters throw exceptions.
66  /// </summary>
67  [DataMember(60)]
68  public char DefaultCharacter { get; set; }
69 
70  /// <summary>
71  /// A text file referencing which characters to include when generating the static fonts (eg. "ABCDEF...")
72  /// </summary>
73  [DataMember(70)]
74  public UFile CharacterSet { get; set; }
75 
76  /// <summary>
77  /// Which addition characters range to include when generating the static fonts (eg. "/CharacterRegion:0x20-0x7F /CharacterRegion:0x123")
78  /// </summary>
79  [DataMember(80)]
80  public List<CharacterRegion> CharacterRegions { get; set; }
81 
82  /// <summary>
83  /// Format of the output texture. Values: 'auto', 'rgba32', 'bgra4444', 'compressedmono'. Default is 'auto'
84  /// </summary>
85  [DataMember(100)]
86  [DefaultValue(FontTextureFormat.Rgba32)]
87  public FontTextureFormat Format { get; set; }
88 
89  /// <summary>
90  /// By default, font textures is a grey. To generate ClearType textures, turn this flag to true
91  /// </summary>
92  [DataMember(110)]
93  public FontAntiAliasMode AntiAlias { get; set; }
94 
95  /// <summary>
96  /// By default, font textures use premultiplied alpha format. Set this if you want interpolative alpha instead.
97  /// </summary>
98  [DataMember(120)]
99  public bool NoPremultiply { get; set; }
100 
101  /// <summary>
102  /// Extra character spacing in pixels (relative to the font size). Zero is default spacing, negative closer together, positive further apart
103  /// </summary>
104  [DataMember(130)]
105  [StepRangeAttribute(-500, 500, 1, 10)]
106  public float Spacing { get; set; }
107 
108  /// <summary>
109  /// Extra line spacing in pixels (relative to the font size). Zero is default spacing, negative closer together, positive further apart
110  /// </summary>
111  [DataMember(140)]
112  [StepRangeAttribute(-500, 500, 1, 10)]
113  public float LineSpacing { get; set; }
114 
115  /// <summary>
116  /// A factor to apply to the default line gap that separate each line. Default is <c>1.0f</c>
117  /// </summary>
118  [DataMember(150)]
119  [DefaultValue(1.0f)]
120  [StepRangeAttribute(-500, 500, 1, 10)]
121  public float LineGapFactor { get; set; }
122 
123  /// <summary>
124  /// A factor to position the space occupied by the line gap before and/or after the font. See remarks. Default is <c>1.0f</c>
125  /// </summary>
126  /// <remarks>
127  /// A Font total height = LineGap * LineGapFactor + Ascent + Descent
128  /// A Font baseline = LineGap * LineGapFactor * LineGapBaseLineFactor + Ascent
129  /// The <see cref="LineGapBaseLineFactor"/> specify where the line gap should start. A value of 1.0 means that the linegap
130  /// should appear completely at the top of the line, while 0.0 would mean that the line gap would appear at the bottom
131  /// of the line.
132  /// </remarks>
133  [DataMember(160)]
134  [DefaultValue(1.0f)]
135  [StepRangeAttribute(-500, 500, 1, 10)]
136  public float LineGapBaseLineFactor { get; set; }
137 
138  /// <summary>
139  /// Specifies whether to use kerning information when rendering the font. Default value is false (NOT SUPPORTED YET).
140  /// </summary>
141  [DataMember(170)]
142  public bool UseKerning { get; set; }
143 
145  {
146  DefaultCharacter = ' ';
147  Style = FontStyle.Regular;
148  CharacterRegions = new List<CharacterRegion>();
149  LineGapFactor = 1.0f;
150  LineGapBaseLineFactor = 1.0f;
151  }
152 
153  /// <summary>
154  /// Creates a default instance.
155  /// </summary>
156  /// <returns>A default instance of <see cref="SpriteFontAsset"/>.</returns>
157  public static SpriteFontAsset Default()
158  {
159  var font = new SpriteFontAsset
160  {
161  Format = FontTextureFormat.Rgba32,
162  FontName = "Arial",
163  Size = 16,
164  };
165  font.CharacterRegions.Add(new CharacterRegion(' ', (char)127));
166 
167  return font;
168  }
169 
170  internal string SafeCharacterSet { get { return CharacterSet ?? ""; } }
171 
172  private class SpriteFontFactory : IAssetFactory
173  {
174  public Asset New()
175  {
176  return Default();
177  }
178  }
179  }
180 }
Base class for Asset.
Definition: Asset.cs:14
Describes a range of consecutive characters that should be included in the font.
SharpDX.DirectWrite.Font Font
Interface to create default instance of an asset type.
Definition: IAssetFactory.cs:8
Use the default mode depending on the type of the field/property.
static SpriteFontAsset Default()
Creates a default instance.
FontAntiAliasMode
Available antialias mode.
This attribute allows to define boundaries for a numeric property, and advice small and large increme...
Contains user-friendly names and descriptions of an asset type.
Defines a normalized file path. See UPath for details. This class cannot be inherited.
Definition: UFile.cs:13