FontType¶
Overview¶
A FontType config contains information about one of available fonts used by the game.
Font configs are referenced by Components to render text, such as:
- Button
- Canvas
- Carousel
- Check
- ComboField
- GroupBox
- InputField
- List
- PagedLayerHeader
- RadioGroup
- Slider
- Text
These config types can be found within the config.Font table:
config.Font.MUSEO_SANS_15PT_REGULAR
config.Font["MUSEO_SANS_15PT_REGULAR"]
config.Font.FromID(30) -- config.Font.MUSEO_SANS_15PT_REGULAR
Info
A FontType is a Proxy usertype, which means it is safe to copy and store in your scripts.
It cannot, however, be used with any persistent storage.
Common Modfiers¶
Font configs also provide methods to calculate the dimensions of strings drawn using that font, which can be used to help position surrounding Components.
There are three commonly used optional modifiers used in the methods provided:
ignoreTagstrue- Tags are treated as literal characters and included in the width calculation.false- Tags are skipped over and not included in the width calculation.
noWordWrappingtrue- Word wrapping occurs on any character.false- Word wrapping occurs only on spaces and hyphens.
noTrimEdges-true- Trailing spaces are not removed from wrapped lines before width calculation.false- Trailing spaces are removed from wrapped lines before width calculation.
Examples¶
-- Calculate the width of a string
local myText = "This is a test string which is long enough to wrap into multiple lines when drawn."
local textWidth = config.Font.MUSEO_SANS_15PT_REGULAR:GetStringWidth(myText)
-- The largest width of all lines when wrapped inside fixed bounds width
local fixedBoundsWidth = 200
local textWidthMax = config.Font.MUSEO_SANS_15PT_REGULAR:GetStringWidthMultiline(myText, fixedBoundsWidth)
Constructors¶
Info
This usertype has no constructor, and you cannot create your own.
Methods¶
GetStringWidth¶
Returns the pixel width of a string drawn with this font.
| Parameter | Type | Required | Description |
|---|---|---|---|
| text | String | The text to calculate the total pixel width for. | |
| ignoreTags | Boolean | See Common Modifiers. |
| Returns | Description |
|---|---|
| Integer | The total pixel width of the given string when drawn with this font. |
Example
-- Find the width of a string drawn with a specific font
local pixelWidth = config.Font.MUSEO_SANS_15PT_REGULAR:GetStringWidth("How long this a piece of string?")
-- Find the width of a string with text tags inside it
local tagText = "This is <col=FF0000>red text</col>"
-- Shorter - calculated as "This is red text"
local width = config.Font.MUSEO_SANS_15PT_REGULAR:GetStringWidth(tagText, false)
-- Longer - calculated as "This is <col=FF0000>red text</col>"
local widthIgnoreTags = config.Font.MUSEO_SANS_15PT_REGULAR:GetStringWidth(tagText, true)
GetStringWidthMultiline¶
function Font:GetStringWidthMultiline(text : String, wrapWidth : Integer, ignoreTags : Boolean?, noWordWrapping : Boolean?, noTrimEdges : Boolean?) -> Integer
Returns the pixel width of a wrapped multiline string drawn with this font.
| Parameter | Type | Required | Description |
|---|---|---|---|
| text | String | The text to calculate the pixel width for. | |
| wrapWidth | Integer | The pixel width limit at which the string should wrap. | |
| ignoreTags | Boolean | See Common Modifiers. | |
| noWordWrapping | Boolean | See Common Modifiers. | |
| noTrimEdges | Boolean | See Common Modifiers. |
| Returns | Description |
|---|---|
| Integer | The total pixel width of the longest line after wrapping this given string into multiple lines. |
Example
GetStringLineCount¶
function Font:GetStringLineCount(text : String, wrapWidth : Integer, ignoreTags : Boolean?, noWordWrapping : Boolean?, noTrimEdges : Boolean?) -> Integer
Returns how many lines the given string will be become when wrapped using this font.
| Parameter | Type | Required | Description |
|---|---|---|---|
| text | String | The text to calculate the line count for. | |
| wrapWidth | Integer | The pixel width limit at which the string should wrap. | |
| ignoreTags | Boolean | See Common Modifiers. | |
| noWordWrapping | Boolean | See Common Modifiers. | |
| noTrimEdges | Boolean | See Common Modifiers. |
| Returns | Description |
|---|---|
| Integer | The total number of lines resulting after wrapping the given string using this font. |
Example
GetStringHeightAndLineCount¶
function Font:GetStringHeightAndLineCount(text : String, wrapWidth : Integer, lineSpacing : Integer, ignoreTags : Boolean?, noWordWrapping : Boolean?, noTrimEdges : Boolean?) -> Integer, Integer
Returns the total pixel height of a string wrapped using this font and how many lines the text was wrapped into.
The resulting height is (lineCount * lineSpacing) + fontMaxAscent + fontMaxDescent.
| Parameter | Type | Required | Description |
|---|---|---|---|
| text | String | The text to calculate the height and line count for. | |
| wrapWidth | Integer | The pixel width limit at which the string should wrap. | |
| lineSpacing | Integer | The pixel spacing between each line.This is the distance between the baselines of each line. | |
| ignoreTags | Boolean | See Common Modifiers. | |
| noWordWrapping | Boolean | See Common Modifiers. | |
| noTrimEdges | Boolean | See Common Modifiers. |
| Returns | Description |
|---|---|
| Integer | The total pixel height after wrapping this given string into multiple lines. |
| Integer | The total number of lines resulting after wrapping the given string using this font. |
Example
SplitString¶
function Font:SplitString(text : String, wrapWidth : Integer, ignoreTags : Boolean?, noWordWrapping : Boolean?, noTrimEdges : Boolean?) -> [ String ]
Splits the given string using the given pixel wrap distance and returns the resulting strings.
| Parameter | Type | Required | Description |
|---|---|---|---|
| text | String | The text to split. | |
| wrapWidth | Integer | The pixel width limit at which the string should split. | |
| ignoreTags | Boolean | See Common Modifiers. | |
| noWordWrapping | Boolean | See Common Modifiers. | |
| noTrimEdges | Boolean | See Common Modifiers. |
| Returns | Description |
|---|---|
| [ String ] | The resulting strings after spliting the given string. |
Example
GetSplitStringLine¶
function Font:GetSplitStringLine(text : String, lineIndex : Integer, wrapWidth : Integer, ignoreTags : Boolean?, noWordWrapping : Boolean?, noTrimEdges : Boolean?) -> String
Splits the given string using the given pixel wrap distance and returns the specific line requested.
| Parameter | Type | Required | Description |
|---|---|---|---|
| text | String | The text to split. | |
| lineIndex | Integer | The index of the requested line.Line numbers are 1-indexed.Requesting a line index greater than available will return an empty string. | |
| wrapWidth | Integer | The pixel width limit at which the string should split. | |
| ignoreTags | Boolean | See Common Modifiers. | |
| noWordWrapping | Boolean | See Common Modifiers. | |
| noTrimEdges | Boolean | See Common Modifiers. |
| Returns | Description |
|---|---|
| String | The requested line after spliting the given string. |
Example
Properties¶
Info
All properties are read-only.
| Name | Type | Description |
|---|---|---|
| id | Integer | The ID of this config type. |
| configName | String | The name of this config, i.e. "MUSEO_SANS_15PT_REGULAR". |
| typeName | String | The type of this config. Will always be "Font". |
| baseline | Integer | The baseline distance of the font.This is also the vertical spacing between lines. |
| upperCaseAscent | Integer | The distance above the baseline for the uppercase 'X' glyph in the font. |
| lowerCaseAscent | Integer | The distance above the baseline for the lowercase 'x' glyph in the font. |
| maxAscent | Integer | The maximum distance above the baseline for the tallest glyph in the font. |
| maxDescent | Integer | The maximum distance below the baseline for the lowest glyph in the font. |