TriEngine  v0.0.16
General-purpose engine in C#/OpenGL
 All Classes Namespaces Files Functions Variables Enumerations Enumerator Properties Events
TriDevs.TriEngine.Text.Font Class Reference

Holds a specific font type. More...

Inheritance diagram for TriDevs.TriEngine.Text.Font:
[legend]
Collaboration diagram for TriDevs.TriEngine.Text.Font:
[legend]

Public Member Functions

 Font (string name, string file, int size, bool dropShadow=false, FontType type=FontType.TTF)
 Initalizes a new Font instance. More...
 
 Font (string name, string file, int size, FontType type, FontConstructionConfig fontConstructionConfig)
 Initializes a new Font instance using the specified builder configuration. More...
 
override string ToString ()
 
void Dispose ()
 Disposes of this font instance, releasing all unmanaged resources. More...
 

Static Public Member Functions

static string GetDefaultName (string file, int size)
 Returns an auto-generated font name based on the file name and font size. More...
 

Properties

string Name [get]
 Gets the name of this font instance. More...
 
string File [get]
 Gets the file used to create this font instance. More...
 
int Size [get]
 Gets the size of this font in points. More...
 
FontType Type [get]
 Gets the font type. More...
 
QFont QFont [get]
 Gets the QFont instance associated with this font. More...
 
Color Color [get, set]
 Gets or sets the color of this font. More...
 
- Properties inherited from TriDevs.TriEngine.Resources.IResource
string Name [get]
 Gets the name associated with this resource. More...
 

Detailed Description

Holds a specific font type.

Constructor & Destructor Documentation

TriDevs.TriEngine.Text.Font.Font ( string  name,
string  file,
int  size,
bool  dropShadow = false,
FontType  type = FontType.TTF 
)

Initalizes a new Font instance.

Parameters
nameName to use for identifying this font, must be unique. Can be set to null to allow the constructor to auto-generate a name for the font.
filePath to the font file (TTF or qfont).
sizeSize (in points) to use for this font.
dropShadowWhether or not this font should have shadows.
typeThe type of font. This will be detected by the file extension, but can be manually specified to control the fallback type used if one was not detected from the file name
94  : this(
95  name, file, size, type,
96  new FontConstructionConfig(new QFontBuilderConfiguration(dropShadow),
97  new QFontLoaderConfiguration(dropShadow)))
98  {
99 
100  }
TriDevs.TriEngine.Text.Font.Font ( string  name,
string  file,
int  size,
FontType  type,
FontConstructionConfig  fontConstructionConfig 
)

Initializes a new Font instance using the specified builder configuration.

Parameters
nameName to use for identifying this font, must be unique. Can be set to null to allow the constructor to auto-generate a name for the font.
filePath to the font file (TTF or qfont).
sizeSize (in points) to use for this font.
typeThe type of font. This will be detected by the file extension, but can be manually specified to control the fallback type used if one was not detected from the file name
fontConstructionConfigThe FontConstructionConfig containing relevant font build/load configurations.
118  {
119  _file = file;
120  _size = size;
121 
122  var ext = Path.GetExtension(_file);
123 
124  if (string.IsNullOrEmpty(ext))
125  throw new EngineException("Failed to get file extension of font file!",
126  new IOException("System.IO.Path.GetExtension returned null or empty for specified file."));
127 
128  // Disable resharper warning, we are checking for null, resharper doesn't like IsNullOrEmpty
129  // ReSharper disable PossibleNullReferenceException
130  ext = ext.TrimStart('.').ToLower();
131  // ReSharper restore PossibleNullReferenceException
132 
133  switch (ext)
134  {
135  case "ttf":
136  type = FontType.TTF;
137  break;
138  case "qfont":
139  type = FontType.QFont;
140  break;
141  }
142 
143  _type = type;
144 
145  QFont font;
146 
147  switch (_type)
148  {
149  case FontType.TTF:
150  if (fontConstructionConfig.BuildConfig == null)
151  throw new EngineException("Builder configuration was null but requested font type requires a builder config!",
152  new ArgumentException("BuildConfig was null.", "fontConstructionConfig"));
153  font = new QFont(_file, _size, fontConstructionConfig.BuildConfig);
154  break;
155  case FontType.QFont:
156  if (fontConstructionConfig.LoadConfig == null)
157  throw new EngineException("Loader configuration was null but requested font type requires a loader config!",
158  new ArgumentException("LoadConfig was null.", "fontConstructionConfig"));
159  font = QFont.FromQFontFile(_file, fontConstructionConfig.LoadConfig);
160  break;
161  default:
162  throw new EngineException("Unsupported font type: " + _type,
163  new ArgumentException("Font type unsupported.", "type"));
164  }
165 
166  if (font == null)
167  throw new EngineException("Font failed to initialize!",
168  new ArgumentException("Font failed to initialize.", "file"));
169 
170  _qfont = font;
171 
172  _name = name ?? GetDefaultName(file, size);
173  }

Member Function Documentation

void TriDevs.TriEngine.Text.Font.Dispose ( )

Disposes of this font instance, releasing all unmanaged resources.

196  {
197  QFont.Dispose();
198  }
static string TriDevs.TriEngine.Text.Font.GetDefaultName ( string  file,
int  size 
)
static

Returns an auto-generated font name based on the file name and font size.

Parameters
fileThe file name.
sizeThe size (in points) of the font.
Returns
The auto-generated font name.
182  {
183  return string.Format(NameFormat, Path.GetFileNameWithoutExtension(file), size);
184  }
override string TriDevs.TriEngine.Text.Font.ToString ( )
187  {
188  return Name;
189  }

Property Documentation

Color TriDevs.TriEngine.Text.Font.Color
getset

Gets or sets the color of this font.

string TriDevs.TriEngine.Text.Font.File
get

Gets the file used to create this font instance.

string TriDevs.TriEngine.Text.Font.Name
get

Gets the name of this font instance.

QFont TriDevs.TriEngine.Text.Font.QFont
get

Gets the QFont instance associated with this font.

int TriDevs.TriEngine.Text.Font.Size
get

Gets the size of this font in points.

FontType TriDevs.TriEngine.Text.Font.Type
get

Gets the font type.


The documentation for this class was generated from the following file: