class Font
package godot
extends Resource › Reference › Object
extended by BitmapFont, DynamicFont
Font contains a Unicode-compatible character set, as well as the ability to draw it with variable width, ascent, descent and kerning. For creating fonts from TTF files (or other font formats), see the editor support for fonts.
Note: If a godot.DynamicFont
doesn't contain a character used in a string, the character in question will be replaced with codepoint 0xfffd
if it's available in the godot.DynamicFont
. If this replacement character isn't available in the DynamicFont, the character will be hidden without displaying any replacement character in the string.
Note: If a godot.BitmapFont
doesn't contain a character used in a string, the character in question will be hidden without displaying any replacement character in the string.
Note: Unicode characters after 0xffff
(such as most emoji) are not supported on Windows. They will display as unknown characters instead. This will be resolved in Godot 4.0.
Methods
draw(canvasItem:RID, position:Vector2, string:String, ?modulate:Color, ?clipW:Int, ?outlineModulate:Color):Void
Draw string
into a canvas item using the font at a given position, with modulate
color, and optionally clipping the width. position
specifies the baseline, not the top. To draw from the top, ascent must be added to the Y axis.
See also godot.CanvasItem.drawString
.
Parameters:
modulate | If the parameter is null, then the default value is new Color(1, 1, 1, 1) |
---|---|
outlineModulate | If the parameter is null, then the default value is new Color(1, 1, 1, 1) |
drawChar(canvasItem:RID, position:Vector2, char:Int, ?next:Int, ?modulate:Color, ?outline:Bool):Single
Draw character char
into a canvas item using the font at a given position, with modulate
color, and optionally kerning if next
is passed. clipping the width. position
specifies the baseline, not the top. To draw from the top, ascent must be added to the Y axis. The width used by the character is returned, making this function useful for drawing strings character by character.
Parameters:
modulate | If the parameter is null, then the default value is new Color(1, 1, 1, 1) |
---|
getCharSize(char:Int, ?next:Int):Vector2
Returns the size of a character, optionally taking kerning into account if the next character is provided. Note that the height returned is the font height (see godot.Font.getHeight
) and has no relation to the glyph height.
getStringSize(string:String):Vector2
Returns the size of a string, taking kerning and advance into account. Note that the height returned is the font height (see godot.Font.getHeight
) and has no relation to the string.
getWordwrapStringSize(string:String, width:Single):Vector2
Returns the size that the string would have with word wrapping enabled with a fixed width
.
updateChanges():Void
After editing a font (changing size, ascent, char rects, etc.). Call this function to propagate changes to controls that might use it.