| 1 | <?xml version="1.0" encoding="UTF-8" ?> |
| 2 | <class name="Font" inherits="Resource" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../class.xsd"> |
| 3 | <brief_description> |
| 4 | Abstract base class for fonts and font variations. |
| 5 | </brief_description> |
| 6 | <description> |
| 7 | Abstract base class for different font types. It has methods for drawing text and font character introspection. |
| 8 | </description> |
| 9 | <tutorials> |
| 10 | </tutorials> |
| 11 | <methods> |
| 12 | <method name="draw_char" qualifiers="const"> |
| 13 | <return type="float" /> |
| 14 | <param index="0" name="canvas_item" type="RID" /> |
| 15 | <param index="1" name="pos" type="Vector2" /> |
| 16 | <param index="2" name="char" type="int" /> |
| 17 | <param index="3" name="font_size" type="int" /> |
| 18 | <param index="4" name="modulate" type="Color" default="Color(1, 1, 1, 1)" /> |
| 19 | <param index="5" name="oversampling" type="float" default="0.0" /> |
| 20 | <description> |
| 21 | Draw a single Unicode character [param char] into a canvas item using the font, at a given position, with [param modulate] color. [param pos] specifies the baseline, not the top. To draw from the top, [i]ascent[/i] must be added to the Y axis. If [param oversampling] is greater than zero, it is used as font oversampling factor, otherwise viewport oversampling settings are used. |
| 22 | [b]Note:[/b] Do not use this function to draw strings character by character, use [method draw_string] or [TextLine] instead. |
| 23 | </description> |
| 24 | </method> |
| 25 | <method name="draw_char_outline" qualifiers="const"> |
| 26 | <return type="float" /> |
| 27 | <param index="0" name="canvas_item" type="RID" /> |
| 28 | <param index="1" name="pos" type="Vector2" /> |
| 29 | <param index="2" name="char" type="int" /> |
| 30 | <param index="3" name="font_size" type="int" /> |
| 31 | <param index="4" name="size" type="int" default="-1" /> |
| 32 | <param index="5" name="modulate" type="Color" default="Color(1, 1, 1, 1)" /> |
| 33 | <param index="6" name="oversampling" type="float" default="0.0" /> |
| 34 | <description> |
| 35 | Draw a single Unicode character [param char] outline into a canvas item using the font, at a given position, with [param modulate] color and [param size] outline size. [param pos] specifies the baseline, not the top. To draw from the top, [i]ascent[/i] must be added to the Y axis. If [param oversampling] is greater than zero, it is used as font oversampling factor, otherwise viewport oversampling settings are used. |
| 36 | [b]Note:[/b] Do not use this function to draw strings character by character, use [method draw_string] or [TextLine] instead. |
| 37 | </description> |
| 38 | </method> |
| 39 | <method name="draw_multiline_string" qualifiers="const"> |
| 40 | <return type="void" /> |
| 41 | <param index="0" name="canvas_item" type="RID" /> |
| 42 | <param index="1" name="pos" type="Vector2" /> |
| 43 | <param index="2" name="text" type="String" /> |
| 44 | <param index="3" name="alignment" type="int" enum="HorizontalAlignment" default="0" /> |
| 45 | <param index="4" name="width" type="float" default="-1" /> |
| 46 | <param index="5" name="font_size" type="int" default="16" /> |
| 47 | <param index="6" name="max_lines" type="int" default="-1" /> |
| 48 | <param index="7" name="modulate" type="Color" default="Color(1, 1, 1, 1)" /> |
| 49 | <param index="8" name="brk_flags" type="int" enum="TextServer.LineBreakFlag" is_bitfield="true" default="3" /> |
| 50 | <param index="9" name="justification_flags" type="int" enum="TextServer.JustificationFlag" is_bitfield="true" default="3" /> |
| 51 | <param index="10" name="direction" type="int" enum="TextServer.Direction" default="0" /> |
| 52 | <param index="11" name="orientation" type="int" enum="TextServer.Orientation" default="0" /> |
| 53 | <param index="12" name="oversampling" type="float" default="0.0" /> |
| 54 | <description> |
| 55 | Breaks [param text] into lines using rules specified by [param brk_flags] and draws it into a canvas item using the font, at a given position, with [param modulate] color, optionally clipping the width and aligning horizontally. [param pos] specifies the baseline of the first line, not the top. To draw from the top, [i]ascent[/i] must be added to the Y axis. If [param oversampling] is greater than zero, it is used as font oversampling factor, otherwise viewport oversampling settings are used. |
| 56 | See also [method CanvasItem.draw_multiline_string]. |
| 57 | </description> |
| 58 | </method> |
| 59 | <method name="draw_multiline_string_outline" qualifiers="const"> |
| 60 | <return type="void" /> |
| 61 | <param index="0" name="canvas_item" type="RID" /> |
| 62 | <param index="1" name="pos" type="Vector2" /> |
| 63 | <param index="2" name="text" type="String" /> |
| 64 | <param index="3" name="alignment" type="int" enum="HorizontalAlignment" default="0" /> |
| 65 | <param index="4" name="width" type="float" default="-1" /> |
| 66 | <param index="5" name="font_size" type="int" default="16" /> |
| 67 | <param index="6" name="max_lines" type="int" default="-1" /> |
| 68 | <param index="7" name="size" type="int" default="1" /> |
| 69 | <param index="8" name="modulate" type="Color" default="Color(1, 1, 1, 1)" /> |
| 70 | <param index="9" name="brk_flags" type="int" enum="TextServer.LineBreakFlag" is_bitfield="true" default="3" /> |
| 71 | <param index="10" name="justification_flags" type="int" enum="TextServer.JustificationFlag" is_bitfield="true" default="3" /> |
| 72 | <param index="11" name="direction" type="int" enum="TextServer.Direction" default="0" /> |
| 73 | <param index="12" name="orientation" type="int" enum="TextServer.Orientation" default="0" /> |
| 74 | <param index="13" name="oversampling" type="float" default="0.0" /> |
| 75 | <description> |
| 76 | Breaks [param text] to the lines using rules specified by [param brk_flags] and draws text outline into a canvas item using the font, at a given position, with [param modulate] color and [param size] outline size, optionally clipping the width and aligning horizontally. [param pos] specifies the baseline of the first line, not the top. To draw from the top, [i]ascent[/i] must be added to the Y axis. If [param oversampling] is greater than zero, it is used as font oversampling factor, otherwise viewport oversampling settings are used. |
| 77 | See also [method CanvasItem.draw_multiline_string_outline]. |
| 78 | </description> |
| 79 | </method> |
| 80 | <method name="draw_string" qualifiers="const"> |
| 81 | <return type="void" /> |
| 82 | <param index="0" name="canvas_item" type="RID" /> |
| 83 | <param index="1" name="pos" type="Vector2" /> |
| 84 | <param index="2" name="text" type="String" /> |
| 85 | <param index="3" name="alignment" type="int" enum="HorizontalAlignment" default="0" /> |
| 86 | <param index="4" name="width" type="float" default="-1" /> |
| 87 | <param index="5" name="font_size" type="int" default="16" /> |
| 88 | <param index="6" name="modulate" type="Color" default="Color(1, 1, 1, 1)" /> |
| 89 | <param index="7" name="justification_flags" type="int" enum="TextServer.JustificationFlag" is_bitfield="true" default="3" /> |
| 90 | <param index="8" name="direction" type="int" enum="TextServer.Direction" default="0" /> |
| 91 | <param index="9" name="orientation" type="int" enum="TextServer.Orientation" default="0" /> |
| 92 | <param index="10" name="oversampling" type="float" default="0.0" /> |
| 93 | <description> |
| 94 | Draw [param text] into a canvas item using the font, at a given position, with [param modulate] color, optionally clipping the width and aligning horizontally. [param pos] specifies the baseline, not the top. To draw from the top, [i]ascent[/i] must be added to the Y axis. If [param oversampling] is greater than zero, it is used as font oversampling factor, otherwise viewport oversampling settings are used. |
| 95 | See also [method CanvasItem.draw_string]. |
| 96 | </description> |
| 97 | </method> |
| 98 | <method name="draw_string_outline" qualifiers="const"> |
| 99 | <return type="void" /> |
| 100 | <param index="0" name="canvas_item" type="RID" /> |
| 101 | <param index="1" name="pos" type="Vector2" /> |
| 102 | <param index="2" name="text" type="String" /> |
| 103 | <param index="3" name="alignment" type="int" enum="HorizontalAlignment" default="0" /> |
| 104 | <param index="4" name="width" type="float" default="-1" /> |
| 105 | <param index="5" name="font_size" type="int" default="16" /> |
| 106 | <param index="6" name="size" type="int" default="1" /> |
| 107 | <param index="7" name="modulate" type="Color" default="Color(1, 1, 1, 1)" /> |
| 108 | <param index="8" name="justification_flags" type="int" enum="TextServer.JustificationFlag" is_bitfield="true" default="3" /> |
| 109 | <param index="9" name="direction" type="int" enum="TextServer.Direction" default="0" /> |
| 110 | <param index="10" name="orientation" type="int" enum="TextServer.Orientation" default="0" /> |
| 111 | <param index="11" name="oversampling" type="float" default="0.0" /> |
| 112 | <description> |
| 113 | Draw [param text] outline into a canvas item using the font, at a given position, with [param modulate] color and [param size] outline size, optionally clipping the width and aligning horizontally. [param pos] specifies the baseline, not the top. To draw from the top, [i]ascent[/i] must be added to the Y axis. If [param oversampling] is greater than zero, it is used as font oversampling factor, otherwise viewport oversampling settings are used. |
| 114 | See also [method CanvasItem.draw_string_outline]. |
| 115 | </description> |
| 116 | </method> |
| 117 | <method name="find_variation" qualifiers="const"> |
| 118 | <return type="RID" /> |
| 119 | <param index="0" name="variation_coordinates" type="Dictionary" /> |
| 120 | <param index="1" name="face_index" type="int" default="0" /> |
| 121 | <param index="2" name="strength" type="float" default="0.0" /> |
| 122 | <param index="3" name="transform" type="Transform2D" default="Transform2D(1, 0, 0, 1, 0, 0)" /> |
| 123 | <param index="4" name="spacing_top" type="int" default="0" /> |
| 124 | <param index="5" name="spacing_bottom" type="int" default="0" /> |
| 125 | <param index="6" name="spacing_space" type="int" default="0" /> |
| 126 | <param index="7" name="spacing_glyph" type="int" default="0" /> |
| 127 | <param index="8" name="baseline_offset" type="float" default="0.0" /> |
| 128 | <description> |
| 129 | Returns [TextServer] RID of the font cache for specific variation. |
| 130 | </description> |
| 131 | </method> |
| 132 | <method name="get_ascent" qualifiers="const"> |
| 133 | <return type="float" /> |
| 134 | <param index="0" name="font_size" type="int" default="16" /> |
| 135 | <description> |
| 136 | Returns the average font ascent (number of pixels above the baseline). |
| 137 | [b]Note:[/b] Real ascent of the string is context-dependent and can be significantly different from the value returned by this function. Use it only as rough estimate (e.g. as the ascent of empty line). |
| 138 | </description> |
| 139 | </method> |
| 140 | <method name="get_char_size" qualifiers="const"> |
| 141 | <return type="Vector2" /> |
| 142 | <param index="0" name="char" type="int" /> |
| 143 | <param index="1" name="font_size" type="int" /> |
| 144 | <description> |
| 145 | Returns the size of a character. Does not take kerning into account. |
| 146 | [b]Note:[/b] Do not use this function to calculate width of the string character by character, use [method get_string_size] or [TextLine] instead. The height returned is the font height (see also [method get_height]) and has no relation to the glyph height. |
| 147 | </description> |
| 148 | </method> |
| 149 | <method name="get_descent" qualifiers="const"> |
| 150 | <return type="float" /> |
| 151 | <param index="0" name="font_size" type="int" default="16" /> |
| 152 | <description> |
| 153 | Returns the average font descent (number of pixels below the baseline). |
| 154 | [b]Note:[/b] Real descent of the string is context-dependent and can be significantly different from the value returned by this function. Use it only as rough estimate (e.g. as the descent of empty line). |
| 155 | </description> |
| 156 | </method> |
| 157 | <method name="get_face_count" qualifiers="const"> |
| 158 | <return type="int" /> |
| 159 | <description> |
| 160 | Returns number of faces in the TrueType / OpenType collection. |
| 161 | </description> |
| 162 | </method> |
| 163 | <method name="get_font_name" qualifiers="const"> |
| 164 | <return type="String" /> |
| 165 | <description> |
| 166 | Returns font family name. |
| 167 | </description> |
| 168 | </method> |
| 169 | <method name="get_font_stretch" qualifiers="const"> |
| 170 | <return type="int" /> |
| 171 | <description> |
| 172 | Returns font stretch amount, compared to a normal width. A percentage value between [code]50%[/code] and [code]200%[/code]. |
| 173 | </description> |
| 174 | </method> |
| 175 | <method name="get_font_style" qualifiers="const"> |
| 176 | <return type="int" enum="TextServer.FontStyle" is_bitfield="true" /> |
| 177 | <description> |
| 178 | Returns font style flags. |
| 179 | </description> |
| 180 | </method> |
| 181 | <method name="get_font_style_name" qualifiers="const"> |
| 182 | <return type="String" /> |
| 183 | <description> |
| 184 | Returns font style name. |
| 185 | </description> |
| 186 | </method> |
| 187 | <method name="get_font_weight" qualifiers="const"> |
| 188 | <return type="int" /> |
| 189 | <description> |
| 190 | Returns weight (boldness) of the font. A value in the [code]100...999[/code] range, normal font weight is [code]400[/code], bold font weight is [code]700[/code]. |
| 191 | </description> |
| 192 | </method> |
| 193 | <method name="get_height" qualifiers="const"> |
| 194 | <return type="float" /> |
| 195 | <param index="0" name="font_size" type="int" default="16" /> |
| 196 | <description> |
| 197 | Returns the total average font height (ascent plus descent) in pixels. |
| 198 | [b]Note:[/b] Real height of the string is context-dependent and can be significantly different from the value returned by this function. Use it only as rough estimate (e.g. as the height of empty line). |
| 199 | </description> |
| 200 | </method> |
| 201 | <method name="get_multiline_string_size" qualifiers="const"> |
| 202 | <return type="Vector2" /> |
| 203 | <param index="0" name="text" type="String" /> |
| 204 | <param index="1" name="alignment" type="int" enum="HorizontalAlignment" default="0" /> |
| 205 | <param index="2" name="width" type="float" default="-1" /> |
| 206 | <param index="3" name="font_size" type="int" default="16" /> |
| 207 | <param index="4" name="max_lines" type="int" default="-1" /> |
| 208 | <param index="5" name="brk_flags" type="int" enum="TextServer.LineBreakFlag" is_bitfield="true" default="3" /> |
| 209 | <param index="6" name="justification_flags" type="int" enum="TextServer.JustificationFlag" is_bitfield="true" default="3" /> |
| 210 | <param index="7" name="direction" type="int" enum="TextServer.Direction" default="0" /> |
| 211 | <param index="8" name="orientation" type="int" enum="TextServer.Orientation" default="0" /> |
| 212 | <description> |
| 213 | Returns the size of a bounding box of a string broken into the lines, taking kerning and advance into account. |
| 214 | See also [method draw_multiline_string]. |
| 215 | </description> |
| 216 | </method> |
| 217 | <method name="get_opentype_features" qualifiers="const"> |
| 218 | <return type="Dictionary" /> |
| 219 | <description> |
| 220 | Returns a set of OpenType feature tags. More info: [url=https://docs.microsoft.com/en-us/typography/opentype/spec/featuretags]OpenType feature tags[/url]. |
| 221 | </description> |
| 222 | </method> |
| 223 | <method name="get_ot_name_strings" qualifiers="const"> |
| 224 | <return type="Dictionary" /> |
| 225 | <description> |
| 226 | Returns [Dictionary] with OpenType font name strings (localized font names, version, description, license information, sample text, etc.). |
| 227 | </description> |
| 228 | </method> |
| 229 | <method name="get_rids" qualifiers="const"> |
| 230 | <return type="RID[]" /> |
| 231 | <description> |
| 232 | Returns [Array] of valid [Font] [RID]s, which can be passed to the [TextServer] methods. |
| 233 | </description> |
| 234 | </method> |
| 235 | <method name="get_spacing" qualifiers="const"> |
| 236 | <return type="int" /> |
| 237 | <param index="0" name="spacing" type="int" enum="TextServer.SpacingType" /> |
| 238 | <description> |
| 239 | Returns the amount of spacing for the given [param spacing] type. |
| 240 | </description> |
| 241 | </method> |
| 242 | <method name="get_string_size" qualifiers="const"> |
| 243 | <return type="Vector2" /> |
| 244 | <param index="0" name="text" type="String" /> |
| 245 | <param index="1" name="alignment" type="int" enum="HorizontalAlignment" default="0" /> |
| 246 | <param index="2" name="width" type="float" default="-1" /> |
| 247 | <param index="3" name="font_size" type="int" default="16" /> |
| 248 | <param index="4" name="justification_flags" type="int" enum="TextServer.JustificationFlag" is_bitfield="true" default="3" /> |
| 249 | <param index="5" name="direction" type="int" enum="TextServer.Direction" default="0" /> |
| 250 | <param index="6" name="orientation" type="int" enum="TextServer.Orientation" default="0" /> |
| 251 | <description> |
| 252 | Returns the size of a bounding box of a single-line string, taking kerning, advance and subpixel positioning into account. See also [method get_multiline_string_size] and [method draw_string]. |
| 253 | For example, to get the string size as displayed by a single-line Label, use: |
| 254 | [codeblocks] |
| 255 | [gdscript] |
| 256 | var string_size = $Label.get_theme_font("font").get_string_size($Label.text, HORIZONTAL_ALIGNMENT_LEFT, -1, $Label.get_theme_font_size("font_size")) |
| 257 | [/gdscript] |
| 258 | [csharp] |
| 259 | Label label = GetNode<Label>("Label"); |
| 260 | Vector2 stringSize = label.GetThemeFont("font").GetStringSize(label.Text, HorizontalAlignment.Left, -1, label.GetThemeFontSize("font_size")); |
| 261 | [/csharp] |
| 262 | [/codeblocks] |
| 263 | [b]Note:[/b] Since kerning, advance and subpixel positioning are taken into account by [method get_string_size], using separate [method get_string_size] calls on substrings of a string then adding the results together will return a different result compared to using a single [method get_string_size] call on the full string. |
| 264 | [b]Note:[/b] Real height of the string is context-dependent and can be significantly different from the value returned by [method get_height]. |
| 265 | </description> |
| 266 | </method> |
| 267 | <method name="get_supported_chars" qualifiers="const"> |
| 268 | <return type="String" /> |
| 269 | <description> |
| 270 | Returns a string containing all the characters available in the font. |
| 271 | If a given character is included in more than one font data source, it appears only once in the returned string. |
| 272 | </description> |
| 273 | </method> |
| 274 | <method name="get_supported_feature_list" qualifiers="const"> |
| 275 | <return type="Dictionary" /> |
| 276 | <description> |
| 277 | Returns list of OpenType features supported by font. |
| 278 | </description> |
| 279 | </method> |
| 280 | <method name="get_supported_variation_list" qualifiers="const"> |
| 281 | <return type="Dictionary" /> |
| 282 | <description> |
| 283 | Returns list of supported [url=https://docs.microsoft.com/en-us/typography/opentype/spec/dvaraxisreg]variation coordinates[/url], each coordinate is returned as [code]tag: Vector3i(min_value,max_value,default_value)[/code]. |
| 284 | Font variations allow for continuous change of glyph characteristics along some given design axis, such as weight, width or slant. |
| 285 | To print available variation axes of a variable font: |
| 286 | [codeblock] |
| 287 | var fv = FontVariation.new() |
| 288 | fv.base_font = load("res://RobotoFlex.ttf") |
| 289 | var variation_list = fv.get_supported_variation_list() |
| 290 | for tag in variation_list: |
| 291 | var name = TextServerManager.get_primary_interface().tag_to_name(tag) |
| 292 | var values = variation_list[tag] |
| 293 | print("variation axis: %s (%d)\n\tmin, max, default: %s" % [name, tag, values]) |
| 294 | [/codeblock] |
| 295 | [b]Note:[/b] To set and get variation coordinates of a [FontVariation], use [member FontVariation.variation_opentype]. |
| 296 | </description> |
| 297 | </method> |
| 298 | <method name="get_underline_position" qualifiers="const"> |
| 299 | <return type="float" /> |
| 300 | <param index="0" name="font_size" type="int" default="16" /> |
| 301 | <description> |
| 302 | Returns average pixel offset of the underline below the baseline. |
| 303 | [b]Note:[/b] Real underline position of the string is context-dependent and can be significantly different from the value returned by this function. Use it only as rough estimate. |
| 304 | </description> |
| 305 | </method> |
| 306 | <method name="get_underline_thickness" qualifiers="const"> |
| 307 | <return type="float" /> |
| 308 | <param index="0" name="font_size" type="int" default="16" /> |
| 309 | <description> |
| 310 | Returns average thickness of the underline. |
| 311 | [b]Note:[/b] Real underline thickness of the string is context-dependent and can be significantly different from the value returned by this function. Use it only as rough estimate. |
| 312 | </description> |
| 313 | </method> |
| 314 | <method name="has_char" qualifiers="const"> |
| 315 | <return type="bool" /> |
| 316 | <param index="0" name="char" type="int" /> |
| 317 | <description> |
| 318 | Returns [code]true[/code] if a Unicode [param char] is available in the font. |
| 319 | </description> |
| 320 | </method> |
| 321 | <method name="is_language_supported" qualifiers="const"> |
| 322 | <return type="bool" /> |
| 323 | <param index="0" name="language" type="String" /> |
| 324 | <description> |
| 325 | Returns [code]true[/code] if the font supports the given language (as a [url=https://en.wikipedia.org/wiki/ISO_639-1]ISO 639[/url] code). |
| 326 | </description> |
| 327 | </method> |
| 328 | <method name="is_script_supported" qualifiers="const"> |
| 329 | <return type="bool" /> |
| 330 | <param index="0" name="script" type="String" /> |
| 331 | <description> |
| 332 | Returns [code]true[/code] if the font supports the given script (as a [url=https://en.wikipedia.org/wiki/ISO_15924]ISO 15924[/url] code). |
| 333 | </description> |
| 334 | </method> |
| 335 | <method name="set_cache_capacity"> |
| 336 | <return type="void" /> |
| 337 | <param index="0" name="single_line" type="int" /> |
| 338 | <param index="1" name="multi_line" type="int" /> |
| 339 | <description> |
| 340 | Sets LRU cache capacity for [code]draw_*[/code] methods. |
| 341 | </description> |
| 342 | </method> |
| 343 | </methods> |
| 344 | <members> |
| 345 | <member name="fallbacks" type="Font[]" setter="set_fallbacks" getter="get_fallbacks" default="[]"> |
| 346 | Array of fallback [Font]s to use as a substitute if a glyph is not found in this current [Font]. |
| 347 | If this array is empty in a [FontVariation], the [member FontVariation.base_font]'s fallbacks are used instead. |
| 348 | </member> |
| 349 | </members> |
| 350 | </class> |