TextServer

Inherits: RefCounted < Object

Inherited By: TextServerExtension

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

FontAntialiasing

font_get_antialiasing ( RID font_rid ) const

float

font_get_ascent ( RID font_rid, int size ) const

float

font_get_descent ( RID font_rid, int size ) const

float

font_get_embolden ( RID font_rid ) const

int

font_get_face_count ( RID font_rid ) const

int

font_get_face_index ( RID font_rid ) const

int

font_get_fixed_size ( RID font_rid ) const

bool

font_get_generate_mipmaps ( 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

PackedInt32Array

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

RID

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

Vector2

font_get_glyph_texture_size ( 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

Vector2i[]

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

String

font_get_name ( RID font_rid ) const

Dictionary

font_get_opentype_feature_overrides ( 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 )

Vector2i[]

font_get_size_cache_list ( RID font_rid ) const

FontStyle

font_get_style ( RID font_rid ) const

String

font_get_style_name ( RID font_rid ) const

SubpixelPositioning

font_get_subpixel_positioning ( RID font_rid ) 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

Transform2D

font_get_transform ( RID font_rid ) 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_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_antialiasing ( RID font_rid, FontAntialiasing antialiasing )

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_embolden ( RID font_rid, float strength )

void

font_set_face_index ( RID font_rid, int face_index )

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_generate_mipmaps ( RID font_rid, bool generate_mipmaps )

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_name ( RID font_rid, String name )

void

font_set_opentype_feature_overrides ( RID font_rid, Dictionary overrides )

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_style ( RID font_rid, FontStyle style )

void

font_set_style_name ( RID font_rid, String name )

void

font_set_subpixel_positioning ( RID font_rid, SubpixelPositioning subpixel_positioning )

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_transform ( RID font_rid, Transform2D transform )

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

int

is_confusable ( String string, PackedStringArray dict ) const

bool

is_locale_right_to_left ( String locale ) const

bool

is_valid_identifier ( String string ) const

bool

load_support_data ( String filename )

int

name_to_tag ( String name ) const

String

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

Vector2i[]

parse_structured_text ( StructuredTextParser parser_type, Array args, String text ) const

String

percent_sign ( String language="" ) const

bool

save_support_data ( String filename ) const

int

shaped_get_span_count ( RID shaped ) const

Variant

shaped_get_span_meta ( RID shaped, int index ) const

void

shaped_set_span_update_font ( RID shaped, int index, RID[] fonts, int size, Dictionary opentype_features={} )

bool

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

bool

shaped_text_add_string ( RID shaped, String text, RID[] fonts, int size, Dictionary opentype_features={}, String language="", Variant meta=null )

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, JustificationFlag jst_flags=3 )

float

shaped_text_get_ascent ( RID shaped ) const

Dictionary

shaped_text_get_carets ( RID shaped, int position ) const

String

shaped_text_get_custom_punctuation ( RID shaped ) 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

Dictionary[]

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

Dictionary[]

shaped_text_get_glyphs ( RID shaped ) const

Vector2

shaped_text_get_grapheme_bounds ( RID shaped, int pos ) const

Direction

shaped_text_get_inferred_direction ( RID shaped ) const

PackedInt32Array

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

PackedInt32Array

shaped_text_get_line_breaks_adv ( RID shaped, PackedFloat32Array width, int start=0, bool once=true, LineBreakFlag break_flags=3 ) 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_spacing ( RID shaped, SpacingType spacing ) 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, GraphemeFlag grapheme_flags=264 ) 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, TextOverrunFlag 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, InlineAlignment inline_align=5 )

void

shaped_text_set_bidi_override ( RID shaped, Array override )

void

shaped_text_set_custom_punctuation ( RID shaped, String punct )

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 )

void

shaped_text_set_spacing ( RID shaped, SpacingType spacing, int value )

bool

shaped_text_shape ( RID shaped )

Dictionary[]

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 )

bool

spoof_check ( String string ) const

PackedInt32Array

string_get_word_breaks ( String string, String language="" ) const

String

string_to_lower ( String string, String language="" ) const

String

string_to_upper ( String string, String language="" ) const

String

strip_diacritics ( String string ) const

String

tag_to_name ( int tag ) const

Enumerations

enum FontAntialiasing:

  • FONT_ANTIALIASING_NONE = 0 --- Font glyphs are rasterized as 1-bit bitmaps.

  • FONT_ANTIALIASING_GRAY = 1 --- Font glyphs are rasterized as 8-bit grayscale anti-aliased bitmaps.

  • FONT_ANTIALIASING_LCD = 2 --- Font glyphs are rasterized for LCD screens.

LCD sub-pixel layout is determined by the value of gui/theme/lcd_subpixel_layout project settings.

LCD sub-pixel anti-aliasing mode is suitable only for rendering horizontal, unscaled text in 2D.


enum FontLCDSubpixelLayout:

  • FONT_LCD_SUBPIXEL_LAYOUT_NONE = 0 --- Unknown or unsupported sub-pixel layout, LCD sub-pixel anti-aliasing is disabled.

  • FONT_LCD_SUBPIXEL_LAYOUT_HRGB = 1 --- Horizontal RGB sub-pixel layout.

  • FONT_LCD_SUBPIXEL_LAYOUT_HBGR = 2 --- Horizontal BGR sub-pixel layout.

  • FONT_LCD_SUBPIXEL_LAYOUT_VRGB = 3 --- Vertical RGB sub-pixel layout.

  • FONT_LCD_SUBPIXEL_LAYOUT_VBGR = 4 --- Vertical BGR sub-pixel layout.


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.


flags 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 AutowrapMode:

  • AUTOWRAP_OFF = 0 --- Autowrap is disabled.

  • AUTOWRAP_ARBITRARY = 1 --- Wraps the text inside the node's bounding rectangle by allowing to break lines at arbitrary positions, which is useful when very limited space is available.

  • AUTOWRAP_WORD = 2 --- Wraps the text inside the node's bounding rectangle by soft-breaking between words.

  • AUTOWRAP_WORD_SMART = 3 --- Behaves similarly to AUTOWRAP_WORD, but force-breaks a word if that single word does not fit in one line.


flags LineBreakFlag:

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

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

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

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

  • BREAK_ADAPTIVE = 8 --- Should be used only in conjunction with BREAK_WORD_BOUND, break the line between any unconnected graphemes, if it's impossible to break it between the words.

  • BREAK_TRIM_EDGE_SPACES = 16 --- Remove edge spaces from the broken line segments.


enum VisibleCharactersBehavior:


enum OverrunBehavior:

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

  • OVERRUN_TRIM_CHAR = 1 --- Trims the text per character.

  • OVERRUN_TRIM_WORD = 2 --- Trims the text per word.

  • OVERRUN_TRIM_ELLIPSIS = 3 --- Trims the text per character and adds an ellipsis to indicate that parts are hidden.

  • OVERRUN_TRIM_WORD_ELLIPSIS = 4 --- Trims the text per word and adds an ellipsis to indicate that parts are hidden.


flags TextOverrunFlag:

  • OVERRUN_NO_TRIM = 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


flags GraphemeFlag:

  • GRAPHEME_IS_VALID = 1 --- Grapheme is supported 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.

  • GRAPHEME_IS_SAFE_TO_INSERT_TATWEEL = 2048 --- It is safe to insert a U+0640 before this grapheme for elongation.


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).

Note: This hinting mode changes both horizontal and vertical glyph metrics. If applied to monospace font, some glyphs might have different width.


enum SubpixelPositioning:

  • SUBPIXEL_POSITIONING_DISABLED = 0 --- Glyph horizontal position is rounded to the whole pixel size, each glyph is rasterized once.

  • SUBPIXEL_POSITIONING_AUTO = 1 --- Glyph horizontal position is rounded based on font size.

  • SUBPIXEL_POSITIONING_ONE_HALF = 2 --- Glyph horizontal position is rounded to one half of the pixel size, each glyph is rasterized up to two times.

  • SUBPIXEL_POSITIONING_ONE_QUARTER = 3 --- Glyph horizontal position is rounded to one quarter of the pixel size, each glyph is rasterized up to four times.

  • SUBPIXEL_POSITIONING_ONE_HALF_MAX_SIZE = 20 --- Maximum font size which will use one half of the pixel subpixel positioning in SUBPIXEL_POSITIONING_AUTO mode.

  • SUBPIXEL_POSITIONING_ONE_QUARTER_MAX_SIZE = 16 --- Maximum font size which will use one quarter of the pixel subpixel positioning in SUBPIXEL_POSITIONING_AUTO mode.


enum Feature:

  • FEATURE_SIMPLE_LAYOUT = 1 --- TextServer supports simple text layouts.

  • FEATURE_BIDI_LAYOUT = 2</