TextServer

Inherits: Object

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_memory ( PackedByteArray data, String type, int base_size=16 )

RID

create_font_resource ( String filename, int base_size=16 )

RID

create_font_system ( String name, int base_size=16 )

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

Vector2

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

Vector2

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

bool

font_get_antialiased ( RID font ) const

float

font_get_ascent ( RID font, int size ) const

float

font_get_base_size ( RID font ) const

float

font_get_descent ( RID font, int size ) const

bool

font_get_distance_field_hint ( RID font ) const

bool

font_get_force_autohinter ( RID font ) const

Vector2

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

int

font_get_glyph_index ( RID font, int char, int variation_selector=0 ) const

Vector2

font_get_glyph_kerning ( RID font, int index_a, int index_b, int size ) const

float

font_get_height ( RID font, int size ) const

Hinting

font_get_hinting ( RID font ) const

bool

font_get_language_support_override ( RID font, String language )

PackedStringArray

font_get_language_support_overrides ( RID font )

float

font_get_oversampling ( ) const

bool

font_get_script_support_override ( RID font, String script )

PackedStringArray

font_get_script_support_overrides ( RID font )

String

font_get_supported_chars ( RID font ) const

float

font_get_underline_position ( RID font, int size ) const

float

font_get_underline_thickness ( RID font, int size ) const

String

font_get_variation_list ( RID fonte ) const

String

font_get_variations ( RID font ) const

bool

font_has_char ( RID font, int char ) const

bool

font_has_outline ( RID font ) const

bool

font_is_language_supported ( RID font, String language ) const

bool

font_is_script_supported ( RID font, String script ) const

void

font_remove_language_support_override ( RID font, String language )

void

font_remove_script_support_override ( RID font, String script )

void

font_set_antialiased ( RID font, bool antialiased )

void

font_set_distance_field_hint ( RID font, bool distance_field )

void

font_set_force_autohinter ( RID font, bool enabeld )

void

font_set_hinting ( RID font, Hinting hinting )

void

font_set_language_support_override ( RID font, String language, bool supported )

void

font_set_oversampling ( float oversampling )

void

font_set_script_support_override ( RID font, String script, bool supported )

void

font_set_variations ( RID font, String value )

String

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

void

free_rid ( RID rid )

Vector2

get_hex_code_box_size ( int size, int index ) const

String

get_name ( ) const

PackedStringArray

get_system_fonts ( ) const

bool

has ( RID rid )

bool

has_feature ( Feature feature )

bool

is_locale_right_to_left ( String locale )

bool

load_support_data ( String filename )

String

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

String

percent_sign ( String language="" ) const

bool

shaped_text_add_object ( RID shaped, Variant key, Vector2 size, VAlign inline_align=1 )

bool

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

void

shaped_text_clear ( RID arg0 )

void

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

void

shaped_text_draw_outline ( RID shaped, RID canvas, Vector2 pos, float clip_w=-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=48 )

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_direciton_in_range ( RID shaped, int start, int end ) const

Array

shaped_text_get_glyphs ( RID shaped ) const

Array

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

Array

shaped_text_get_line_breaks_adv ( RID shaped, PackedFloat32Array width, int start=0, bool once=true, int 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

Array

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

Vector2

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

Array

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

int

shaped_text_prev_grapheme_pos ( RID shaped, int pos )

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 )

RID

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

float

shaped_text_tab_align ( RID shaped, PackedFloat32Array tab_stops )

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 = 16 --- Justify text by adding and removing kashidas.

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

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

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


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


enum GraphemeFlag:

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


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

  • FEATURE_USE_SUPPORT_DATA = 128

Method Descriptions

Creates new font from the data in memory. To free the resulting font, use free_rid method.

Note: For non-scalable fonts base_size is ignored, use font_get_base_size to check actual font size.


  • RID create_font_resource ( String filename, int base_size=16 )

Creates new font from the file. To free the resulting font, use free_rid method.

Note: For non-scalable fonts base_size is ignored, use font_get_base_size to check actual font size.


Creates new font from the system font. To free the resulting font, use free_rid method.

Note: This method is supported by servers with the FEATURE_FONT_SYSTEM feature.

Note: For non-scalable fonts base_size is ignored, use font_get_base_size to check actual font size.


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.


Draws single glyph into a canvas item at the position, using font 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.


Draws single glyph outline of size outline_size into a canvas item at the position, using font 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.


  • bool font_get_antialiased ( RID font ) const

Returns true, if font anti-aliasing is supported and enabled.


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


  • float font_get_base_size ( RID font ) const

Returns the default size of the font.


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


  • bool font_get_distance_field_hint ( RID font ) const

Returns true, if distance field hint is enabled.


  • bool font_get_force_autohinter ( RID font ) const

Returns true, if autohinter is supported and enabled.


Returns advance of the glyph.


  • int font_get_glyph_index ( RID font, int char, int variation_selector=0 ) const

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


Returns a kerning of the pair of glyphs.


Returns the total font height (ascent plus descent) in pixels.


Returns the font hinting.


  • bool font_get_language_support_override ( RID font, String language )

Returns true if support override is enabled for the language.


Returns list of language support overrides.


  • float font_get_oversampling ( ) const

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


  • bool font_get_script_support_override ( RID font, String script )

Returns true if support override is enabled for the script.


Returns list of script support overrides.


  • String font_get_supported_chars ( RID font ) const

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


  • float font_get_underline_position ( RID font, int size ) const

Returns underline offset (number of pixels below the baseline).


  • float font_get_underline_thickness ( RID font, int size ) const

Returns underline thickness in pixels.


  • String font_get_variation_list ( RID fonte ) const

Returns ";" separated list of supported variation coordinates, each coordinate is returned in the following format: "tag,min_value,max_value,default_value".


  • String font_get_variations ( RID font ) const

Returns variation coordinates. Returned string is identical to the string set by font_set_variations, to get default values use font_get_variation_list instead.


Returns true if char is available in the font.


  • bool font_has_outline ( RID font ) const

Returns true, if font supports glyph outlines.


  • bool font_is_language_supported ( RID font, String language ) const

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


  • bool font_is_script_supported ( RID font, String script ) const

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


  • void font_remove_language_support_override ( RID font, String language )

Remove language support override.


  • void font_remove_script_support_override ( RID font, String script )

Removes script support override.


  • void font_set_antialiased ( RID font, bool antialiased )

Sets font anti-aliasing.


  • void font_set_distance_field_hint ( RID font, bool distance_field )

Sets font distance field hint.


  • void font_set_force_autohinter ( RID font, bool enabeld )


  • void font_set_hinting ( RID font, Hinting hinting )

Sets font hinting.


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

Adds override for font_is_language_supported.


  • void font_set_oversampling ( float oversampling )

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


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

Adds override for font_is_script_supported.


  • void font_set_variations ( RID font, String value )

Sets variation coordinates, value is a comma separated list of the in the "tag=value" format. Tags are case-sensitive. Unsupported or incorrectly formatted coordinates will be silently ignored.


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



Returns the name of the server interface.


Returns list of available system fonts.

Note: This method is supported by servers with the FEATURE_FONT_SYSTEM feature.


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


Returns true if the server supports a feature.


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.


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


Returns percent sign used in the language.


Adds inline object to the text buffer, key must be unique.


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


  • void shaped_text_clear ( RID arg0 )

Clears text buffer (removes text and inline objects).


  • void shaped_text_draw ( RID shaped, RID canvas, Vector2 pos, float clip_w=-1, Color color=Color( 1, 1, 1, 1 ) ) const

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_w=-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_direciton_in_range ( RID shaped, int start, int end ) const

Returns dominant direction of in the range of text.


  • Array shaped_text_get_glyphs ( RID shaped ) const

Returns text glyphs.


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

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.


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

Returns selection rectangles for the specified character range.


  • Vector2 shaped_text_get_size ( RID shaped ) const

Returns size of the text.


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


  • Array shaped_text_get_word_breaks ( RID shaped ) const

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 )

Returns composite character end position closest to the pos.


  • int shaped_text_prev_grapheme_pos ( RID shaped, int pos )

Returns composite character start position closest to the pos.


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


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

Returns text buffer for the substring of the text in the shaped text buffer (including inline objects).


Aligns shaped text to the given tab-stops.