TextServer API overview

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
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 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 )
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 ot_features="", String language="" )
void shaped_text_clear ( RID shaped )
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_USE_SUPPORT_DATA = 64

This article was updated on October 14, 2020