TextServer

Inherits: RefCounted < Object

Inherited By: TextServerAdvanced, TextServerExtension, TextServerFallback

Interface for the fonts and complex text layouts.

Description

TextServer is the API backend for managing fonts, and rendering complex text.

Methods

RID

create_font ( )

RID

create_shaped_text ( Direction direction=0, Orientation orientation=0 )

void

draw_hex_code_box ( RID canvas, int size, Vector2 pos, int index, Color color ) const

void

font_clear_glyphs ( RID font_rid, Vector2i size )

void

font_clear_kerning_map ( RID font_rid, int size )

void

font_clear_size_cache ( RID font_rid )

void

font_clear_textures ( RID font_rid, Vector2i size )

void

font_draw_glyph ( RID font_rid, RID canvas, int size, Vector2 pos, int index, Color color=Color(1, 1, 1, 1) ) const

void

font_draw_glyph_outline ( RID font_rid, RID canvas, int size, int outline_size, Vector2 pos, int index, Color color=Color(1, 1, 1, 1) ) const

float

font_get_ascent ( RID font_rid, int size ) const

float

font_get_descent ( RID font_rid, int size ) const

int

font_get_fixed_size ( RID font_rid ) const

float

font_get_global_oversampling ( ) const

Vector2

font_get_glyph_advance ( RID font_rid, int size, int glyph ) const

Dictionary

font_get_glyph_contours ( RID font, int size, int index ) const

int

font_get_glyph_index ( RID font_rid, int size, int char, int variation_selector ) const

Array

font_get_glyph_list ( RID font_rid, Vector2i size ) const

Vector2

font_get_glyph_offset ( RID font_rid, Vector2i size, int glyph ) const

Vector2

font_get_glyph_size ( RID font_rid, Vector2i size, int glyph ) const

int

font_get_glyph_texture_idx ( RID font_rid, Vector2i size, int glyph ) const

Rect2

font_get_glyph_uv_rect ( RID font_rid, Vector2i size, int glyph ) const

Hinting

font_get_hinting ( RID font_rid ) const

Vector2

font_get_kerning ( RID font_rid, int size, Vector2i glyph_pair ) const

Array

font_get_kerning_list ( RID font_rid, int size ) const

bool

font_get_language_support_override ( RID font_rid, String language )

PackedStringArray

font_get_language_support_overrides ( RID font_rid )

int

font_get_msdf_pixel_range ( RID font_rid ) const

int

font_get_msdf_size ( RID font_rid ) const

float

font_get_oversampling ( RID font_rid ) const

float

font_get_scale ( RID font_rid, int size ) const

bool

font_get_script_support_override ( RID font_rid, String script )

PackedStringArray

font_get_script_support_overrides ( RID font_rid )

Array

font_get_size_cache_list ( RID font_rid ) const

int

font_get_spacing ( RID font_rid, int size, SpacingType spacing ) const

String

font_get_supported_chars ( RID font_rid ) const

int

font_get_texture_count ( RID font_rid, Vector2i size ) const

Image

font_get_texture_image ( RID font_rid, Vector2i size, int texture_index ) const

PackedInt32Array

font_get_texture_offsets ( RID font_rid, Vector2i size, int texture_index ) const

float

font_get_underline_position ( RID font_rid, int size ) const

float

font_get_underline_thickness ( RID font_rid, int size ) const

Dictionary

font_get_variation_coordinates ( RID font_rid ) const

bool

font_has_char ( RID font_rid, int char ) const

bool

font_is_antialiased ( RID font_rid ) const

bool

font_is_force_autohinter ( RID font_rid ) const

bool

font_is_language_supported ( RID font_rid, String language ) const

bool

font_is_multichannel_signed_distance_field ( RID font_rid ) const

bool

font_is_script_supported ( RID font_rid, String script ) const

void

font_remove_glyph ( RID font_rid, Vector2i size, int glyph )

void

font_remove_kerning ( RID font_rid, int size, Vector2i glyph_pair )

void

font_remove_language_support_override ( RID font_rid, String language )

void

font_remove_script_support_override ( RID font_rid, String script )

void

font_remove_size_cache ( RID font_rid, Vector2i size )

void

font_remove_texture ( RID font_rid, Vector2i size, int texture_index )

void

font_render_glyph ( RID font_rid, Vector2i size, int index )

void

font_render_range ( RID font_rid, Vector2i size, int start, int end )

void

font_set_antialiased ( RID font_rid, bool antialiased )

void

font_set_ascent ( RID font_rid, int size, float ascent )

void

font_set_data ( RID font_rid, PackedByteArray data )

void

font_set_descent ( RID font_rid, int size, float descent )

void

font_set_fixed_size ( RID font_rid, int fixed_size )

void

font_set_force_autohinter ( RID font_rid, bool force_autohinter )

void

font_set_global_oversampling ( float oversampling )

void

font_set_glyph_advance ( RID font_rid, int size, int glyph, Vector2 advance )

void

font_set_glyph_offset ( RID font_rid, Vector2i size, int glyph, Vector2 offset )

void

font_set_glyph_size ( RID font_rid, Vector2i size, int glyph, Vector2 gl_size )

void

font_set_glyph_texture_idx ( RID font_rid, Vector2i size, int glyph, int texture_idx )

void

font_set_glyph_uv_rect ( RID font_rid, Vector2i size, int glyph, Rect2 uv_rect )

void

font_set_hinting ( RID font_rid, Hinting _hinting )

void

font_set_kerning ( RID font_rid, int size, Vector2i glyph_pair, Vector2 kerning )

void

font_set_language_support_override ( RID font_rid, String language, bool supported )

void

font_set_msdf_pixel_range ( RID font_rid, int msdf_pixel_range )

void

font_set_msdf_size ( RID font_rid, int msdf_size )

void

font_set_multichannel_signed_distance_field ( RID font_rid, bool msdf )

void

font_set_oversampling ( RID font_rid, float oversampling )

void

font_set_scale ( RID font_rid, int size, float scale )

void

font_set_script_support_override ( RID font_rid, String script, bool supported )

void

font_set_spacing ( RID font_rid, int size, SpacingType spacing, int value )

void

font_set_texture_image ( RID font_rid, Vector2i size, int texture_index, Image image )

void

font_set_texture_offsets ( RID font_rid, Vector2i size, int texture_index, PackedInt32Array offset )

void

font_set_underline_position ( RID font_rid, int size, float underline_position )

void

font_set_underline_thickness ( RID font_rid, int size, float underline_thickness )

void

font_set_variation_coordinates ( RID font_rid, Dictionary variation_coordinates )

Dictionary

font_supported_feature_list ( RID font_rid ) const

Dictionary

font_supported_variation_list ( RID font_rid ) const

String

format_number ( String number, String language="" ) const

void

free_rid ( RID rid )

int

get_features ( ) const

Vector2

get_hex_code_box_size ( int size, int index ) const

String

get_name ( ) const

String

get_support_data_filename ( ) const

String

get_support_data_info ( ) const

bool

has ( RID rid )

bool

has_feature ( Feature feature ) const

bool

is_locale_right_to_left ( String locale ) const

bool

load_support_data ( String filename )

int

name_to_tag ( String name ) const

String

parse_number ( String number, String language="" ) const

String

percent_sign ( String language="" ) const

bool

save_support_data ( String filename ) const

bool

shaped_text_add_object ( RID shaped, Variant key, Vector2 size, InlineAlign inline_align=5, int length=1 )

bool

shaped_text_add_string ( RID shaped, String text, Array fonts, int size, Dictionary opentype_features={ }, String language="" )

void

shaped_text_clear ( RID rid )

void

shaped_text_draw ( RID shaped, RID canvas, Vector2 pos, float clip_l=-1, float clip_r=-1, Color color=Color(1, 1, 1, 1) ) const

void

shaped_text_draw_outline ( RID shaped, RID canvas, Vector2 pos, float clip_l=-1, float clip_r=-1, int outline_size=1, Color color=Color(1, 1, 1, 1) ) const

float

shaped_text_fit_to_width ( RID shaped, float width, int jst_flags=3 )

float

shaped_text_get_ascent ( RID shaped ) const

Dictionary

shaped_text_get_carets ( RID shaped, int position ) const

float

shaped_text_get_descent ( RID shaped ) const

Direction

shaped_text_get_direction ( RID shaped ) const

Direction

shaped_text_get_dominant_direction_in_range ( RID shaped, int start, int end ) const

int

shaped_text_get_ellipsis_glyph_count ( RID shaped ) const

Array

shaped_text_get_ellipsis_glyphs ( RID shaped ) const

int

shaped_text_get_ellipsis_pos ( RID shaped ) const

int

shaped_text_get_glyph_count ( RID shaped ) const

Array

shaped_text_get_glyphs ( RID shaped ) const

PackedInt32Array

shaped_text_get_line_breaks ( RID shaped, float width, int start=0, int break_flags=96 ) const

PackedInt32Array

shaped_text_get_line_breaks_adv ( RID shaped, PackedFloat32Array width, int start=0, bool once=true, int break_flags=96 ) const

Rect2

shaped_text_get_object_rect ( RID shaped, Variant key ) const

Array

shaped_text_get_objects ( RID shaped ) const

Orientation

shaped_text_get_orientation ( RID shaped ) const

RID

shaped_text_get_parent ( RID shaped ) const

bool

shaped_text_get_preserve_control ( RID shaped ) const

bool

shaped_text_get_preserve_invalid ( RID shaped ) const

Vector2i

shaped_text_get_range ( RID shaped ) const

PackedVector2Array

shaped_text_get_selection ( RID shaped, int start, int end ) const

Vector2

shaped_text_get_size ( RID shaped ) const

int

shaped_text_get_trim_pos ( RID shaped ) const

float

shaped_text_get_underline_position ( RID shaped ) const

float

shaped_text_get_underline_thickness ( RID shaped ) const

float

shaped_text_get_width ( RID shaped ) const

PackedInt32Array

shaped_text_get_word_breaks ( RID shaped, int grapheme_flags ) const

int

shaped_text_hit_test_grapheme ( RID shaped, float coords ) const

int

shaped_text_hit_test_position ( RID shaped, float coords ) const

bool

shaped_text_is_ready ( RID shaped ) const

int

shaped_text_next_grapheme_pos ( RID shaped, int pos ) const

void

shaped_text_overrun_trim_to_width ( RID shaped, float width=0, int overrun_trim_flags=0 )

int

shaped_text_prev_grapheme_pos ( RID shaped, int pos ) const

bool

shaped_text_resize_object ( RID shaped, Variant key, Vector2 size, InlineAlign inline_align=5 )

void

shaped_text_set_bidi_override ( RID shaped, Array override )

void

shaped_text_set_direction ( RID shaped, Direction direction=0 )

void

shaped_text_set_orientation ( RID shaped, Orientation orientation=0 )

void

shaped_text_set_preserve_control ( RID shaped, bool enabled )

void

shaped_text_set_preserve_invalid ( RID shaped, bool enabled )

bool

shaped_text_shape ( RID shaped )

Array

shaped_text_sort_logical ( RID shaped )

RID

shaped_text_substr ( RID shaped, int start, int length ) const

float

shaped_text_tab_align ( RID shaped, PackedFloat32Array tab_stops )

String

tag_to_name ( int tag ) const

Enumerations

enum Direction:

  • DIRECTION_AUTO = 0 --- Text direction is determined based on contents and current locale.

  • DIRECTION_LTR = 1 --- Text is written from left to right.

  • DIRECTION_RTL = 2 --- Text is written from right to left.


enum Orientation:

  • ORIENTATION_HORIZONTAL = 0 --- Text is written horizontally.

  • ORIENTATION_VERTICAL = 1 --- Left to right text is written vertically from top to bottom.

Right to left text is written vertically from bottom to top.


enum JustificationFlag:

  • JUSTIFICATION_NONE = 0 --- Do not justify text.

  • JUSTIFICATION_KASHIDA = 1 --- Justify text by adding and removing kashidas.

  • JUSTIFICATION_WORD_BOUND = 2 --- Justify text by changing width of the spaces between the words.

  • JUSTIFICATION_TRIM_EDGE_SPACES = 4 --- Remove trailing and leading spaces from the justified text.

  • JUSTIFICATION_AFTER_LAST_TAB = 8 --- Only apply justification to the part of the text after the last tab.

  • JUSTIFICATION_CONSTRAIN_ELLIPSIS = 16 --- Apply justification to the trimmed line with ellipsis.


enum LineBreakFlag:

  • BREAK_NONE = 0 --- Do not break the line.

  • BREAK_MANDATORY = 32 --- Break the line at the line mandatory break characters (e.g. "\n").

  • BREAK_WORD_BOUND = 64 --- Break the line between the words.

  • BREAK_GRAPHEME_BOUND = 128 --- Break the line between any unconnected graphemes.

  • BREAK_WORD_BOUND_ADAPTIVE = 320 --- Break the line between the words, or any unconnected graphemes if line is too short to fit the whole word.


enum TextOverrunFlag:

  • OVERRUN_NO_TRIMMING = 0 --- No trimming is performed.

  • OVERRUN_TRIM = 1 --- Trims the text when it exceeds the given width.

  • OVERRUN_TRIM_WORD_ONLY = 2 --- Trims the text per word instead of per grapheme.

  • OVERRUN_ADD_ELLIPSIS = 4 --- Determines whether an ellipsis should be added at the end of the text.

  • OVERRUN_ENFORCE_ELLIPSIS = 8 --- Determines whether the ellipsis at the end of the text is enforced and may not be hidden.

  • OVERRUN_JUSTIFICATION_AWARE = 16


enum GraphemeFlag:

  • GRAPHEME_IS_VALID = 1 --- Grapheme is supprted by the font, and can be drawn.

  • GRAPHEME_IS_RTL = 2 --- Grapheme is part of right-to-left or bottom-to-top run.

  • GRAPHEME_IS_VIRTUAL = 4 --- Grapheme is not part of source text, it was added by justification process.

  • GRAPHEME_IS_SPACE = 8 --- Grapheme is whitespace.

  • GRAPHEME_IS_BREAK_HARD = 16 --- Grapheme is mandatory break point (e.g. "\n").

  • GRAPHEME_IS_BREAK_SOFT = 32 --- Grapheme is optional break point (e.g. space).

  • GRAPHEME_IS_TAB = 64 --- Grapheme is the tabulation character.

  • GRAPHEME_IS_ELONGATION = 128 --- Grapheme is kashida.

  • GRAPHEME_IS_PUNCTUATION = 256 --- Grapheme is punctuation character.

  • GRAPHEME_IS_UNDERSCORE = 512 --- Grapheme is underscore character.

  • GRAPHEME_IS_CONNECTED = 1024 --- Grapheme is connected to the previous grapheme. Breaking line before this grapheme is not safe.


enum Hinting:

  • HINTING_NONE = 0 --- Disables font hinting (smoother but less crisp).

  • HINTING_LIGHT = 1 --- Use the light font hinting mode.

  • HINTING_NORMAL = 2 --- Use the default font hinting mode (crisper but less smooth).


enum Feature:

  • FEATURE_BIDI_LAYOUT = 1 --- TextServer supports bidirectional layouts.

  • FEATURE_VERTICAL_LAYOUT = 2 --- TextServer supports vertical layouts.

  • FEATURE_SHAPING = 4 --- TextServer supports complex text shaping.

  • FEATURE_KASHIDA_JUSTIFICATION = 8 --- TextServer supports justification using kashidas.

  • FEATURE_BREAK_ITERATORS = 16 --- TextServer supports complex line/word breaking rules (e.g. dictionary based).

  • FEATURE_FONT_SYSTEM = 32 --- TextServer supports loading system fonts.

  • FEATURE_FONT_VARIABLE = 64 --- TextServer supports variable fonts.

  • FEATURE_USE_SUPPORT_DATA = 128 --- TextServer require external data file for some features.


enum ContourPointTag:

  • CONTOUR_CURVE_TAG_ON = 1 --- Contour point is on the curve.

  • CONTOUR_CURVE_TAG_OFF_CONIC = 0 --- Contour point isn't on the curve, but serves as a control point for a conic (quadratic) Bézier arc.

  • CONTOUR_CURVE_TAG_OFF_CUBIC = 2 --- Contour point isn't on the curve, but serves as a control point for a cubic Bézier arc.


enum SpacingType:

  • SPACING_GLYPH = 0 --- Spacing for each glyph.

  • SPACING_SPACE = 1 --- Spacing for the space character.

  • SPACING_TOP = 2 --- Spacing at the top of the line.

  • SPACING_BOTTOM = 3 --- Spacing at the bottom of the line.

Method Descriptions

  • RID create_font ( )

Creates new, empty font cache entry resource. To free the resulting resourec, use free_rid method.


Creates new buffer for complex text layout, with the given direction and orientation. To free the resulting buffer, use free_rid method.

Note: Direction is ignored if server does not support FEATURE_BIDI_LAYOUT feature.

Note: Orientation is ignored if server does not support FEATURE_VERTICAL_LAYOUT feature.


Draws box displaying character hexadecimal code. Used for replacing missing characters.


  • void font_clear_glyphs ( RID font_rid, Vector2i size )

Removes all rendered glyphs information from the cache entry.

Note: This function will not remove textures associated with the glyphs, use font_remove_texture to remove them manually.


  • void font_clear_kerning_map ( RID font_rid, int size )

Removes all kerning overrides.


  • void font_clear_size_cache ( RID font_rid )

Removes all font sizes from the cache entry


  • void font_clear_textures ( RID font_rid, Vector2i size )

Removes all textures from font cache entry.

Note: This function will not remove glyphs associated with the texture, use font_remove_glyph to remove them manually.


  • void font_draw_glyph ( RID font_rid, RID canvas, int size, Vector2 pos, int index, Color color=Color(1, 1, 1, 1) ) const

Draws single glyph into a canvas item at the position, using font_rid at the size size.

Note: Glyph index is specific to the font, use glyphs indices returned by shaped_text_get_glyphs or font_get_glyph_index.


  • void font_draw_glyph_outline ( RID font_rid, RID canvas, int size, int outline_size, Vector2 pos, int index, Color color=Color(1, 1, 1, 1) ) const

Draws single glyph outline of size outline_size into a canvas item at the position, using font_rid at the size size.

Note: Glyph index is specific to the font, use glyphs indices returned by shaped_text_get_glyphs or font_get_glyph_index.


  • float font_get_ascent ( RID font_rid, int size ) const

Returns the font ascent (number of pixels above the baseline).


  • float font_get_descent ( RID font_rid, int size ) const

Returns the font descent (number of pixels below the baseline).


  • int font_get_fixed_size ( RID font_rid ) const

Returns bitmap font fixed size.


  • float font_get_global_oversampling ( ) const

Returns the font oversampling factor, shared by all fonts in the TextServer.


Returns glyph advance (offset of the next glyph).

Note: Advance for glyphs outlines is the same as the base glyph advance and is not saved.


Returns outline contours of the glyph as a Dictionary with the following contents:

points - PackedVector3Array, containing outline points. x and y are point coordinates. z is the type of the point, using the ContourPointTag values.

contours - PackedInt32Array, containing indices the end points of each contour.

orientation - bool, contour orientation. If true, clockwise contours must be filled.


  • int font_get_glyph_index ( RID font_rid, int size, int char, int variation_selector ) const

Returns the glyph index of a char, optionally modified by the variation_selector.


Returns list of rendered glyphs in the cache entry.


Returns glyph offset from the baseline.


Returns size of the glyph.


Returns index of the cache texture containing the glyph.


Returns rectangle in the cache texture containing the glyph.


Returns the font hinting mode. Used by dynamic fonts only.


Returns kerning for the pair of glyphs.


  • Array font_get_kerning_list ( RID font_rid, int size ) const

Returns list of the kerning overrides.


  • bool font_get_language_support_override ( RID font_rid, String language )

Returns true if support override is enabled for the language.


Returns list of language support overrides.


  • int font_get_msdf_pixel_range ( RID font_rid ) const

Return the width of the range around the shape between the minimum and maximum representable signed distance.


  • int font_get_msdf_size ( RID font_rid ) const

Returns source font size used to generate MSDF textures.


  • float font_get_oversampling ( RID font_rid ) const

Returns font oversampling factor, if set to 0.0 global oversampling factor is used instead. Used by dynamic fonts only.


  • float font_get_scale ( RID font_rid, int size ) const

Returns scaling factor of the color bitmap font.


  • bool font_get_script_support_override ( RID font_rid, String script )

Returns true if support override is enabled for the script.


Returns list of script support overrides.


  • Array font_get_size_cache_list ( RID font_rid ) const

Return list of the font sizes in the cache. Each size is Vector2i with font size and outline size.


Returns extra spacing added between glyphs in pixels.


  • String font_get_supported_chars ( RID font_rid ) const

Returns a string containing all the characters available in the font.


Returns number of textures used by font cache entry.


Returns font cache texture image data.


Returns array containing the first free pixel in the each column of texture. Should be the same size as texture width or empty.


  • float font_get_underline_position ( RID font_rid, int size ) const

Returns pixel offset of the underline below the baseline.


  • float font_get_underline_thickness ( RID font_rid, int size ) const

Returns thickness of the underline in pixels.


  • Dictionary font_get_variation_coordinates ( RID font_rid ) const

Returns variation coordinates for the specified font cache entry. See font_supported_variation_list for more info.


  • bool font_has_char ( RID font_rid, int char ) const

Return true if a Unicode char is available in the font.


  • bool font_is_antialiased ( RID font_rid ) const

Returns true if font 8-bit anitialiased glyph rendering is supported and enabled.


  • bool font_is_force_autohinter ( RID font_rid ) const

Returns true if auto-hinting is supported and preffered over font built-in hinting. Used by dynamic fonts only.


  • bool font_is_language_supported ( RID font_rid, String language ) const

Returns true, if font supports given language (ISO 639 code).


  • bool font_is_multichannel_signed_distance_field ( RID font_rid ) const

Returns true if glyphs of all sizes are rendered using single multichannel signed distance field generated from the dynamic font vector data.


  • bool font_is_script_supported ( RID font_rid, String script ) const

Returns true, if font supports given script (ISO 15924 code).


Removes specified rendered glyph information from the cache entry.

Note: This function will not remove textures associated with the glyphs, use font_remove_texture to remove them manually.


  • void font_remove_kerning ( RID font_rid, int size, Vector2i glyph_pair )

Removes kerning override for the pair of glyphs.


  • void font_remove_language_support_override ( RID font_rid, String language )

Remove language support override.


  • void font_remove_script_support_override ( RID font_rid, String script )

Removes script support override.


  • void font_remove_size_cache ( RID font_rid, Vector2i size )

Removes specified font size from the cache entry.


  • void font_remove_texture ( RID font_rid, Vector2i size, int texture_index )

Removes specified texture from font cache entry.

Note: This function will not remove glyphs associated with the texture, remove them manually, using font_remove_glyph.


Renders specified glyph the the font cache texture.


Renders the range of characters to the font cache texture.


  • void font_set_antialiased ( RID font_rid, bool antialiased )

If set to true, 8-bit antialiased glyph rendering is used, otherwise 1-bit rendering is used. Used by dynamic fonts only.


  • void font_set_ascent ( RID font_rid, int size, float ascent )

Sets the font ascent (number of pixels above the baseline).


Sets font source data, e.g contents of the dynamic font source file.


  • void font_set_descent ( RID font_rid, int size, float descent )

Sets the font descent (number of pixels below the baseline).


  • void font_set_fixed_size ( RID font_rid, int fixed_size )

Sets bitmap font fixed size. If set to value greater than zero, same cache entry will be used for all font sizes.


  • void font_set_force_autohinter ( RID font_rid, bool force_autohinter )

If set to true auto-hinting is preffered over font built-in hinting.


  • void font_set_global_oversampling ( float oversampling )

Sets oversampling factor, shared by all font in the TextServer.

Note: This value can be automaticaly changed by display server.


  • void font_set_glyph_advance ( RID font_rid, int size, int glyph, Vector2 advance )

Sets glyph advance (offset of the next glyph).

Note: Advance for glyphs outlines is the same as the base glyph advance and is not saved.


Sets glyph offset from the baseline.


Sets size of the glyph.


  • void font_set_glyph_texture_idx ( RID font_rid, Vector2i size, int glyph, int texture_idx )

Sets index of the cache texture containing the glyph.


Sets rectangle in the cache texture containing the glyph.


  • void font_set_hinting ( RID font_rid, Hinting _hinting )

Sets font hinting mode. Used by dynamic fonts only.


Sets kerning for the pair of glyphs.


  • void font_set_language_support_override ( RID font_rid, String language, bool supported )

Adds override for font_is_language_supported.


  • void font_set_msdf_pixel_range ( RID font_rid, int msdf_pixel_range )

Sets the width of the range around the shape between the minimum and maximum representable signed distance.


  • void font_set_msdf_size ( RID font_rid, int msdf_size )

Sets source font size used to generate MSDF textures.


  • void font_set_multichannel_signed_distance_field ( RID font_rid, bool msdf )

If set to true, glyphs of all sizes are rendered using single multichannel signed distance field generated from the dynamic font vector data. MSDF rendering allows displaying the font at any scaling factor without blurriness, and without incurring a CPU cost when the font size changes (since the font no longer needs to be rasterized on the CPU). As a downside, font hinting is not available with MSDF. The lack of font hinting may result in less crisp and less readable fonts at small sizes.

Note: MSDF font rendering does not render glyphs with overlapping shapes correctly. Overlapping shapes are not valid per the OpenType standard, but are still commonly found in many font files, especially those converted by Google Fonts. To avoid issues with overlapping glyphs, consider downloading the font file directly from the type foundry instead of relying on Google Fonts.


  • void font_set_oversampling ( RID font_rid, float oversampling )

Sets font oversampling factor, if set to 0.0 global oversampling factor is used instead. Used by dynamic fonts only.


  • void font_set_scale ( RID font_rid, int size, float scale )

Sets scaling factor of the color bitmap font.


  • void font_set_script_support_override ( RID font_rid, String script, bool supported )

Adds override for font_is_script_supported.


Sets extra spacing added between glyphs in pixels.


Sets font cache texture image data.


Sets array containing the first free pixel in the each column of texture. Should be the same size as texture width or empty.


  • void font_set_underline_position ( RID font_rid, int size, float underline_position )

Sets pixel offset of the underline below the baseline.


  • void font_set_underline_thickness ( RID font_rid, int size, float underline_thickness )

Sets thickness of the underline in pixels.


  • void font_set_variation_coordinates ( RID font_rid, Dictionary variation_coordinates )

Sets variation coordinates for the specified font cache entry. See font_supported_variation_list for more info.


Returns the dictionary of the supported OpenType features.


  • Dictionary font_supported_variation_list ( RID font_rid ) const

Returns the dictionary of the supported OpenType variation coordinates.


Converts a number from the Western Arabic (0..9) to the numeral systems used in language.


  • void free_rid ( RID rid )

Frees an object created by this TextServer.


  • int get_features ( ) const

Returns text server features, see Feature.


Returns size of the replacement character (box with character hexadecimal code that is drawn in place of invalid characters).


Returns the name of the server interface.


  • String get_support_data_filename ( ) const

Returns default TextServer database (e.g. ICU break iterators and dictionaries) filename.


  • String get_support_data_info ( ) const

Returns TextServer database (e.g. ICU break iterators and dictionaries) description.


Returns true if rid is valid resource owned by this text server.


Returns true if the server supports a feature.


  • bool is_locale_right_to_left ( String locale ) const

Returns true if locale is right-to-left.


Loads optional TextServer database (e.g. ICU break iterators and dictionaries).

Note: This function should be called before any other TextServer functions used, otherwise it won't have any effect.


Converts readable feature, variation, script or language name to OpenType tag.


Converts a number from the numeral systems used in language to Western Arabic (0..9).


Returns percent sign used in the language.


  • bool save_support_data ( String filename ) const

Saves optional TextServer database (e.g. ICU break iterators and dictionaries) to the file.

Note: This function is used by during project export, to include TextServer database.


Adds inline object to the text buffer, key must be unique. In the text, object is represented as length object replacement characters.


Adds text span and font to draw it to the text buffer.


  • void shaped_text_clear ( RID rid )

Clears text buffer (removes text and inline objects).


Draw shaped text into a canvas item at a given position, with color. pos specifies the leftmost point of the baseline (for horizontal layout) or topmost point of the baseline (for vertical layout).


  • void shaped_text_draw_outline ( RID shaped, RID canvas, Vector2 pos, float clip_l=-1, float clip_r=-1, int outline_size=1, Color color=Color(1, 1, 1, 1) ) const

Draw the outline of the shaped text into a canvas item at a given position, with color. pos specifies the leftmost point of the baseline (for horizontal layout) or topmost point of the baseline (for vertical layout).


Adjusts text with to fit to specified width, returns new text width.


  • float shaped_text_get_ascent ( RID shaped ) const

Returns the text ascent (number of pixels above the baseline for horizontal layout or to the left of baseline for vertical).

Note: Overall ascent can be higher than font ascent, if some glyphs are displaced from the baseline.


Returns shapes of the carets corresponding to the character offset position in the text. Returned caret shape is 1 pixel wide rectangle.


  • float shaped_text_get_descent ( RID shaped ) const

Returns the text descent (number of pixels below the baseline for horizontal layout or to the right of baseline for vertical).

Note: Overall descent can be higher than font descent, if some glyphs are displaced from the baseline.


Returns direction of the text.


  • Direction shaped_text_get_dominant_direction_in_range ( RID shaped, int start, int end ) const

Returns dominant direction of in the range of text.


  • int shaped_text_get_ellipsis_glyph_count ( RID shaped ) const

Returns number of glyphs in the ellipsis.


  • Array shaped_text_get_ellipsis_glyphs ( RID shaped ) const

Returns array of the glyphs in the ellipsis.


  • int shaped_text_get_ellipsis_pos ( RID shaped ) const

Returns position of the ellipsis.


  • int shaped_text_get_glyph_count ( RID shaped ) const

Returns number of glyphs in the buffer.


  • Array shaped_text_get_glyphs ( RID shaped ) const

Returns text glyphs in the visual order.


Breaks text to the lines and returns character ranges for each line.


Breaks text to the lines and columns. Returns character ranges for each segment.


Returns bounding rectangle of the inline object.


  • Array shaped_text_get_objects ( RID shaped ) const

Returns array of inline objects.


Returns text orientation.


  • RID shaped_text_get_parent ( RID shaped ) const

Sets text orientation.


  • bool shaped_text_get_preserve_control ( RID shaped ) const

Returns true if text buffer is configured to display control characters.


  • bool shaped_text_get_preserve_invalid ( RID shaped ) const

Returns true if text buffer is configured to display hexadecimal codes in place of invalid characters.

Note: If set to false, nothing is displayed in place of invalid characters.


Returns substring buffer character range in the parent buffer.


Returns selection rectangles for the specified character range.


  • Vector2 shaped_text_get_size ( RID shaped ) const

Returns size of the text.


  • int shaped_text_get_trim_pos ( RID shaped ) const

Returns position of the trim.


  • float shaped_text_get_underline_position ( RID shaped ) const

Returns pixel offset of the underline below the baseline.


  • float shaped_text_get_underline_thickness ( RID shaped ) const

Returns thickness of the underline.


  • float shaped_text_get_width ( RID shaped ) const

Returns width (for horizontal layout) or height (for vertical) of the text.


Breaks text into words and returns array of character ranges.


  • int shaped_text_hit_test_grapheme ( RID shaped, float coords ) const

Returns grapheme index at the specified pixel offset at the baseline, or -1 if none is found.


  • int shaped_text_hit_test_position ( RID shaped, float coords ) const

Returns caret character offset at the specified pixel offset at the baseline. This function always returns a valid position.


  • bool shaped_text_is_ready ( RID shaped ) const

Returns true if buffer is successfully shaped.


  • int shaped_text_next_grapheme_pos ( RID shaped, int pos ) const

Returns composite character end position closest to the pos.


  • void shaped_text_overrun_trim_to_width ( RID shaped, float width=0, int overrun_trim_flags=0 )

Trims text if it exceeds the given width.


  • int shaped_text_prev_grapheme_pos ( RID shaped, int pos ) const

Returns composite character start position closest to the pos.


Sets new size and alignment of embedded object.


  • void shaped_text_set_bidi_override ( RID shaped, Array override )

Overrides BiDi for the structured text.

Override ranges should cover full source text without overlaps. BiDi algorithm will be used on each range separately.


  • void shaped_text_set_direction ( RID shaped, Direction direction=0 )

Sets desired text direction. If set to TEXT_DIRECTION_AUTO, direction will be detected based on the buffer contents and current locale.

Note: Direction is ignored if server does not support FEATURE_BIDI_LAYOUT feature.


  • void shaped_text_set_orientation ( RID shaped, Orientation orientation=0 )

Sets desired text orientation.

Note: Orientation is ignored if server does not support FEATURE_VERTICAL_LAYOUT feature.


  • void shaped_text_set_preserve_control ( RID shaped, bool enabled )

If set to true text buffer will display control characters.


  • void shaped_text_set_preserve_invalid ( RID shaped, bool enabled )

If set to true text buffer will display invalid characters as hexadecimal codes, otherwise nothing is displayed.


  • bool shaped_text_shape ( RID shaped )

Shapes buffer if it's not shaped. Returns true if the string is shaped successfully.

Note: It is not necessary to call this function manually, buffer will be shaped automatically as soon as any of its output data is requested.


  • Array shaped_text_sort_logical ( RID shaped )

Returns text glyphs in the logical order.


  • RID shaped_text_substr ( RID shaped, int start,