Class TextFormatter
- Namespace
- MLEM.Formatting
- Assembly
- MLEM.dll
A text formatter is used for drawing text using GenericFont that contains different colors, bold/italic sections and animations. To format a string of text, use the codes as specified in the constructor. To tokenize and render a formatted string, use Tokenize(GenericFont, string, TextAlignment).
public class TextFormatter : GenericDataHolder, IGenericDataHolder
- Inheritance
-
TextFormatter
- Implements
- Inherited Members
- Extension Methods
Constructors
TextFormatter(bool, bool, bool, bool)
Creates a new text formatter with an optional set of default formatting codes.
public TextFormatter(bool hasFontModifiers = true, bool hasColors = true, bool hasAnimations = true, bool hasMacros = true)
Parameters
hasFontModifiers
boolWhether default font modifier codes should be added, including bold, italic, strikethrough, shadow, subscript, and more.
hasColors
boolWhether default color codes should be added, including all Microsoft.Xna.Framework.Color values and the ability to use custom colors.
hasAnimations
boolWhether default animation codes should be added, namely the wobbly animation.
hasMacros
boolWhether default macros should be added, including TeX's ~ non-breaking space and more.
Fields
Codes
The formatting codes that this text formatter uses. The Regex defines how the formatting code should be matched.
public readonly Dictionary<Regex, Code.Constructor> Codes
Field Value
DefaultOutlineColor
The default outline color used by this text formatter, which determines how the default OutlineCode is drawn if no custom value is used. Note that this value only has an effect on the default formatting codes created through the TextFormatter(bool, bool, bool, bool) constructor.
public Color DefaultOutlineColor
Field Value
- Color
DefaultOutlineThickness
The default outline thickness used by this text formatter, which determines how the default OutlineCode is drawn if no custom value is used. Note that this value only has an effect on the default formatting codes created through the TextFormatter(bool, bool, bool, bool) constructor.
public float DefaultOutlineThickness
Field Value
DefaultShadowColor
The default shadow color used by this text formatter, which determines how the default ShadowCode is drawn if no custom value is used. Note that this value only has an effect on the default formatting codes created through the TextFormatter(bool, bool, bool, bool) constructor.
public Color DefaultShadowColor
Field Value
- Color
DefaultShadowOffset
The default shadow offset used by this text formatter, which determines how the default ShadowCode is drawn if no custom value is used. Note that this value only has an effect on the default formatting codes created through the TextFormatter(bool, bool, bool, bool) constructor.
public Vector2 DefaultShadowOffset
Field Value
- Vector2
DefaultSubOffset
The default subscript offset used by this text formatter, which determines how the default SubSupCode is drawn if no custom value is used. Note that this value only has an effect on the default formatting codes created through the TextFormatter(bool, bool, bool, bool) constructor.
public float DefaultSubOffset
Field Value
DefaultSupOffset
The default superscript offset used by this text formatter, which determines how the default SubSupCode is drawn if no custom value is used. Note that this value only has an effect on the default formatting codes created through the TextFormatter(bool, bool, bool, bool) constructor.
public float DefaultSupOffset
Field Value
DefaultWobblyHeight
The default wobbly modifier used by this text formatter, which determines how the default WobblyCode is drawn if no custom value is used. Note that this value only has an effect on the default formatting codes created through the TextFormatter(bool, bool, bool, bool) constructor.
public float DefaultWobblyHeight
Field Value
DefaultWobblyModifier
The default wobbly modifier used by this text formatter, which determines how the default WobblyCode is drawn if no custom value is used. Note that this value only has an effect on the default formatting codes created through the TextFormatter(bool, bool, bool, bool) constructor.
public float DefaultWobblyModifier
Field Value
LineThickness
The line thickness used by this text formatter, which determines how the default UnderlineCode-based formatting codes are drawn. Note that this value only has an effect on the default formatting codes created through the TextFormatter(bool, bool, bool, bool) constructor.
public float LineThickness
Field Value
Macros
The macros that this text formatter uses. A macro is a Regex that turns a snippet of text into another snippet of text. Macros can resolve recursively and can resolve into formatting codes.
public readonly Dictionary<Regex, TextFormatter.Macro> Macros
Field Value
OutlineDiagonals
Whether the default outline used by this text formatter should also draw outlines diagonally, which determines how the default OutlineCode is drawn if no custom value is used. Non-diagonally drawn outlines might generally look better when using a pixelart font. Note that this value only has an effect on the default formatting codes created through the TextFormatter(bool, bool, bool, bool) constructor.
public bool OutlineDiagonals
Field Value
StrikethroughOffset
The strikethrough offset used by this text formatter, which determines how the default UnderlineCode's strikethrough variant is drawn. Note that this value only has an effect on the default formatting codes created through the TextFormatter(bool, bool, bool, bool) constructor.
public float StrikethroughOffset
Field Value
UnderlineOffset
The underline offset used by this text formatter, which determines how the default UnderlineCode is drawn. Note that this value only has an effect on the default formatting codes created through the TextFormatter(bool, bool, bool, bool) constructor.
public float UnderlineOffset
Field Value
Methods
ResolveMacros(string)
Resolves the macros in the given string recursively, until no more macros can be resolved. This method is used by Tokenize(GenericFont, string, TextAlignment), meaning that it does not explicitly have to be called when using text formatting.
public string ResolveMacros(string s)
Parameters
s
stringThe string to resolve macros for
Returns
- string
The final, recursively resolved string
StripAllFormatting(string)
Strips all formatting codes from the given string, causing a string without any formatting codes to be returned. Note that, if a TokenizedString has already been created using Tokenize(GenericFont, string, TextAlignment), it is more efficient to use String or DisplayString.
public string StripAllFormatting(string s)
Parameters
s
stringThe string to strip formatting codes from.
Returns
- string
The stripped string.
Tokenize(GenericFont, string, TextAlignment)
Tokenizes a string, returning a tokenized string that is ready for splitting, measuring and drawing.
public TokenizedString Tokenize(GenericFont font, string s, TextAlignment alignment = TextAlignment.Left)
Parameters
font
GenericFontThe font to use for tokenization. Note that this font needs to be the same that will later be used for splitting, measuring and/or drawing.
s
stringThe string to tokenize
alignment
TextAlignmentThe text alignment that should be used. This alignment can later be changed using Realign(GenericFont, TextAlignment).
Returns
- TokenizedString
The tokenized string.