TextServer

继承: RefCounted < Object

派生: TextServerExtension

用于字体管理和文本呈现的服务器接口。

描述

TextServer是用于管理字体和渲染文本的API后端。

注意:这是一个底层API,建议使用TextLineTextParagraphFont类。

这是一个抽象类,因此要获取当前活动的TextServer实例,请使用以下代码: .. tabs:

.. code-tab:: s3script

   var ts = TextServerManager.get_primary_interface()

.. code-tab:: csharp

   var ts = TextServerManager.GetPrimaryInterface();

方法

RID

create_font()

RID

create_font_linked_variation(font_rid: RID)

RID

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

void

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

void

font_clear_glyphs(font_rid: RID, size: Vector2i)

void

font_clear_kerning_map(font_rid: RID, size: int)

void

font_clear_size_cache(font_rid: RID)

void

font_clear_textures(font_rid: RID, size: Vector2i)

void

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

void

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

FontAntialiasing

font_get_antialiasing(font_rid: RID) const

float

font_get_ascent(font_rid: RID, size: int) const

float

font_get_baseline_offset(font_rid: RID) const

int

font_get_char_from_glyph_index(font_rid: RID, size: int, glyph_index: int) const

float

font_get_descent(font_rid: RID, size: int) const

bool

font_get_disable_embedded_bitmaps(font_rid: RID) const

float

font_get_embolden(font_rid: RID) const

int

font_get_face_count(font_rid: RID) const

int

font_get_face_index(font_rid: RID) const

int

font_get_fixed_size(font_rid: RID) const

FixedSizeScaleMode

font_get_fixed_size_scale_mode(font_rid: RID) const

bool

font_get_generate_mipmaps(font_rid: RID) const

float

font_get_global_oversampling() const

Vector2

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

Dictionary

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

int

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

PackedInt32Array

font_get_glyph_list(font_rid: RID, size: Vector2i) const

Vector2

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

Vector2

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

int

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

RID

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

Vector2

font_get_glyph_texture_size(font_rid: RID, size: Vector2i, glyph: int) const

Rect2

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

Hinting

font_get_hinting(font_rid: RID) const

bool

font_get_keep_rounding_remainders(font_rid: RID) const

Vector2

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

Array[Vector2i]

font_get_kerning_list(font_rid: RID, size: int) const

bool

font_get_language_support_override(font_rid: RID, language: String)

PackedStringArray

font_get_language_support_overrides(font_rid: RID)

int

font_get_msdf_pixel_range(font_rid: RID) const

int

font_get_msdf_size(font_rid: RID) const

String

font_get_name(font_rid: RID) const

Dictionary

font_get_opentype_feature_overrides(font_rid: RID) const

Dictionary

font_get_ot_name_strings(font_rid: RID) const

float

font_get_oversampling(font_rid: RID) const

float

font_get_scale(font_rid: RID, size: int) const

bool

font_get_script_support_override(font_rid: RID, script: String)

PackedStringArray

font_get_script_support_overrides(font_rid: RID)

Array[Vector2i]

font_get_size_cache_list(font_rid: RID) const

int

font_get_spacing(font_rid: RID, spacing: SpacingType) const

int

font_get_stretch(font_rid: RID) const

BitField[FontStyle]

font_get_style(font_rid: RID) const

String

font_get_style_name(font_rid: RID) const

SubpixelPositioning

font_get_subpixel_positioning(font_rid: RID) const

String

font_get_supported_chars(font_rid: RID) const

PackedInt32Array

font_get_supported_glyphs(font_rid: RID) const

int

font_get_texture_count(font_rid: RID, size: Vector2i) const

Image

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

PackedInt32Array

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

Transform2D

font_get_transform(font_rid: RID) const

float

font_get_underline_position(font_rid: RID, size: int) const

float

font_get_underline_thickness(font_rid: RID, size: int) const

Dictionary

font_get_variation_coordinates(font_rid: RID) const

int

font_get_weight(font_rid: RID) const

bool

font_has_char(font_rid: RID, char: int) const

bool

font_is_allow_system_fallback(font_rid: RID) const

bool

font_is_force_autohinter(font_rid: RID) const

bool

font_is_language_supported(font_rid: RID, language: String) const

bool

font_is_multichannel_signed_distance_field(font_rid: RID) const

bool

font_is_script_supported(font_rid: RID, script: String) const

void

font_remove_glyph(font_rid: RID, size: Vector2i, glyph: int)

void

font_remove_kerning(font_rid: RID, size: int, glyph_pair: Vector2i)

void

font_remove_language_support_override(font_rid: RID, language: String)

void

font_remove_script_support_override(font_rid: RID, script: String)

void

font_remove_size_cache(font_rid: RID, size: Vector2i)

void

font_remove_texture(font_rid: RID, size: Vector2i, texture_index: int)

void

font_render_glyph(font_rid: RID, size: Vector2i, index: int)

void

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

void

font_set_allow_system_fallback(font_rid: RID, allow_system_fallback: bool)

void

font_set_antialiasing(font_rid: RID, antialiasing: FontAntialiasing)

void

font_set_ascent(font_rid: RID, size: int, ascent: float)

void

font_set_baseline_offset(font_rid: RID, baseline_offset: float)

void

font_set_data(font_rid: RID, data: PackedByteArray)

void

font_set_descent(font_rid: RID, size: int, descent: float)

void

font_set_disable_embedded_bitmaps(font_rid: RID, disable_embedded_bitmaps: bool)

void

font_set_embolden(font_rid: RID, strength: float)

void

font_set_face_index(font_rid: RID, face_index: int)

void

font_set_fixed_size(font_rid: RID, fixed_size: int)

void

font_set_fixed_size_scale_mode(font_rid: RID, fixed_size_scale_mode: FixedSizeScaleMode)

void

font_set_force_autohinter(font_rid: RID, force_autohinter: bool)

void

font_set_generate_mipmaps(font_rid: RID, generate_mipmaps: bool)

void

font_set_global_oversampling(oversampling: float)

void

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

void

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

void

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

void

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

void

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

void

font_set_hinting(font_rid: RID, hinting: Hinting)

void

font_set_keep_rounding_remainders(font_rid: RID, keep_rounding_remainders: bool)

void

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

void

font_set_language_support_override(font_rid: RID, language: String, supported: bool)

void

font_set_msdf_pixel_range(font_rid: RID, msdf_pixel_range: int)

void

font_set_msdf_size(font_rid: RID, msdf_size: int)

void

font_set_multichannel_signed_distance_field(font_rid: RID, msdf: bool)

void

font_set_name(font_rid: RID, name: String)

void

font_set_opentype_feature_overrides(font_rid: RID, overrides: Dictionary)

void

font_set_oversampling(font_rid: RID, oversampling: float)

void

font_set_scale(font_rid: RID, size: int, scale: float)

void

font_set_script_support_override(font_rid: RID, script: String, supported: bool)

void

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

void

font_set_stretch(font_rid: RID, weight: int)

void

font_set_style(font_rid: RID, style: BitField[FontStyle])

void

font_set_style_name(font_rid: RID, name: String)

void

font_set_subpixel_positioning(font_rid: RID, subpixel_positioning: SubpixelPositioning)

void

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

void

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

void

font_set_transform(font_rid: RID, transform: Transform2D)

void

font_set_underline_position(font_rid: RID, size: int, underline_position: float)

void

font_set_underline_thickness(font_rid: RID, size: int, underline_thickness: float)

void

font_set_variation_coordinates(font_rid: RID, variation_coordinates: Dictionary)

void

font_set_weight(font_rid: RID, weight: int)

Dictionary

font_supported_feature_list(font_rid: RID) const

Dictionary

font_supported_variation_list(font_rid: RID) const

String

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

void

free_rid(rid: RID)

int

get_features() const

Vector2

get_hex_code_box_size(size: int, index: int) const

String

get_name() const

PackedByteArray

get_support_data() 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, dict: PackedStringArray) const

bool

is_locale_right_to_left(locale: String) const

bool

is_valid_identifier(string: String) const

bool

is_valid_letter(unicode: int) const

bool

load_support_data(filename: String)

int

name_to_tag(name: String) const

String

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

Array[Vector3i]

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

String

percent_sign(language: String = "") const

bool

save_support_data(filename: String) const

int

shaped_get_span_count(shaped: RID) const

Variant

shaped_get_span_embedded_object(shaped: RID, index: int) const

Variant

shaped_get_span_meta(shaped: RID, index: int) const

void

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

bool

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

bool

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

void

shaped_text_clear(rid: RID)

int

shaped_text_closest_character_pos(shaped: RID, pos: int) const

void

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

void

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

float

shaped_text_fit_to_width(shaped: RID, width: float, justification_flags: BitField[JustificationFlag] = 3)

float

shaped_text_get_ascent(shaped: RID) const

Dictionary

shaped_text_get_carets(shaped: RID, position: int) const

PackedInt32Array

shaped_text_get_character_breaks(shaped: RID) const

int

shaped_text_get_custom_ellipsis(shaped: RID) const

String

shaped_text_get_custom_punctuation(shaped: RID) const

float

shaped_text_get_descent(shaped: RID) const

Direction

shaped_text_get_direction(shaped: RID) const

Direction

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

int

shaped_text_get_ellipsis_glyph_count(shaped: RID) const

Array[Dictionary]

shaped_text_get_ellipsis_glyphs(shaped: RID) const

int

shaped_text_get_ellipsis_pos(shaped: RID) const

int

shaped_text_get_glyph_count(shaped: RID) const

Array[Dictionary]

shaped_text_get_glyphs(shaped: RID) const

Vector2

shaped_text_get_grapheme_bounds(shaped: RID, pos: int) const

Direction

shaped_text_get_inferred_direction(shaped: RID) const

PackedInt32Array

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

PackedInt32Array

shaped_text_get_line_breaks_adv(shaped: RID, width: PackedFloat32Array, start: int = 0, once: bool = true, break_flags: BitField[LineBreakFlag] = 3) const

int

shaped_text_get_object_glyph(shaped: RID, key: Variant) const

Vector2i

shaped_text_get_object_range(shaped: RID, key: Variant) const

Rect2

shaped_text_get_object_rect(shaped: RID, key: Variant) const

Array

shaped_text_get_objects(shaped: RID) const

Orientation

shaped_text_get_orientation(shaped: RID) const

RID

shaped_text_get_parent(shaped: RID) const

bool

shaped_text_get_preserve_control(shaped: RID) const

bool

shaped_text_get_preserve_invalid(shaped: RID) const

Vector2i

shaped_text_get_range(shaped: RID) const

PackedVector2Array

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

Vector2

shaped_text_get_size(shaped: RID) const

int

shaped_text_get_spacing(shaped: RID, spacing: SpacingType) const

int

shaped_text_get_trim_pos(shaped: RID) const

float

shaped_text_get_underline_position(shaped: RID) const

float

shaped_text_get_underline_thickness(shaped: RID) const

float

shaped_text_get_width(shaped: RID) const

PackedInt32Array

shaped_text_get_word_breaks(shaped: RID, grapheme_flags: BitField[GraphemeFlag] = 264, skip_grapheme_flags: BitField[GraphemeFlag] = 4) const

bool

shaped_text_has_visible_chars(shaped: RID) const

int

shaped_text_hit_test_grapheme(shaped: RID, coords: float) const

int

shaped_text_hit_test_position(shaped: RID, coords: float) const

bool

shaped_text_is_ready(shaped: RID) const

int

shaped_text_next_character_pos(shaped: RID, pos: int) const

int

shaped_text_next_grapheme_pos(shaped: RID, pos: int) const

void

shaped_text_overrun_trim_to_width(shaped: RID, width: float = 0, overrun_trim_flags: BitField[TextOverrunFlag] = 0)

int

shaped_text_prev_character_pos(shaped: RID, pos: int) const

int

shaped_text_prev_grapheme_pos(shaped: RID, pos: int) const

bool

shaped_text_resize_object(shaped: RID, key: Variant, size: Vector2, inline_align: InlineAlignment = 5, baseline: float = 0.0)

void

shaped_text_set_bidi_override(shaped: RID, override: Array)

void

shaped_text_set_custom_ellipsis(shaped: RID, char: int)

void

shaped_text_set_custom_punctuation(shaped: RID, punct: String)

void

shaped_text_set_direction(shaped: RID, direction: Direction = 0)

void

shaped_text_set_orientation(shaped: RID, orientation: Orientation = 0)

void

shaped_text_set_preserve_control(shaped: RID, enabled: bool)

void

shaped_text_set_preserve_invalid(shaped: RID, enabled: bool)

void

shaped_text_set_spacing(shaped: RID, spacing: SpacingType, value: int)

bool

shaped_text_shape(shaped: RID)

Array[Dictionary]

shaped_text_sort_logical(shaped: RID)

RID

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

float

shaped_text_tab_align(shaped: RID, tab_stops: PackedFloat32Array)

bool

spoof_check(string: String) const

PackedInt32Array

string_get_character_breaks(string: String, language: String = "") const

PackedInt32Array

string_get_word_breaks(string: String, language: String = "", chars_per_line: int = 0) const

String

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

String

string_to_title(string: String, language: String = "") const

String

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

String

strip_diacritics(string: String) const

String

tag_to_name(tag: int) const


枚举

enum FontAntialiasing: 🔗

FontAntialiasing FONT_ANTIALIASING_NONE = 0

字体字形被光栅化为1位位图。

FontAntialiasing FONT_ANTIALIASING_GRAY = 1

字体字形被光栅化为8位灰度抗锯齿位图。

FontAntialiasing FONT_ANTIALIASING_LCD = 2

用于LCD屏幕的字体字形被光栅化。

LCD子像素布局由gui/theme/lcd_subpixel_layout项目设置的值决定。

LCD子像素抗混淆现象模式仅适用于在2D中渲染水平、未缩放的文本。


enum FontLCDSubpixelLayout: 🔗

FontLCDSubpixelLayout FONT_LCD_SUBPIXEL_LAYOUT_NONE = 0

未知或不支持的子像素布局,LCD子像素抗锯齿被禁用。

FontLCDSubpixelLayout FONT_LCD_SUBPIXEL_LAYOUT_HRGB = 1

水平RGB子像素布局。

FontLCDSubpixelLayout FONT_LCD_SUBPIXEL_LAYOUT_HBGR = 2

水平BGR子像素布局。

FontLCDSubpixelLayout FONT_LCD_SUBPIXEL_LAYOUT_VRGB = 3

垂直RGB子像素布局。

FontLCDSubpixelLayout FONT_LCD_SUBPIXEL_LAYOUT_VBGR = 4

垂直BGR子像素布局。

FontLCDSubpixelLayout FONT_LCD_SUBPIXEL_LAYOUT_MAX = 5

表示FontLCDSubpixelLayout枚举的大小。


enum Direction: 🔗

Direction DIRECTION_AUTO = 0

文本方向是根据内容和当前区域设置确定的。

Direction DIRECTION_LTR = 1

文本从左到右书写。

Direction DIRECTION_RTL = 2

文本从右向左书写。

Direction DIRECTION_INHERITED = 3

文本写入方向与基本字符串写入方向相同。仅用于BiDi覆盖。


enum Orientation: 🔗

Orientation ORIENTATION_HORIZONTAL = 0

文本是水平书写的。

Orientation ORIENTATION_VERTICAL = 1

从左到右的文本是从上到下垂直书写的。

从右到左的文本是从下到上垂直书写的。


flags JustificationFlag: 🔗

JustificationFlag JUSTIFICATION_NONE = 0

不要为文本辩护。

JustificationFlag JUSTIFICATION_KASHIDA = 1

通过添加和删除kashidas来证明文本的合理性。

JustificationFlag JUSTIFICATION_WORD_BOUND = 2

通过改变单词之间空格的宽度来证明文本的正确性。

JustificationFlag JUSTIFICATION_TRIM_EDGE_SPACES = 4

从对齐的文本中删除尾部和前导空格。

JustificationFlag JUSTIFICATION_AFTER_LAST_TAB = 8

仅对最后一个选项卡之后的文本部分应用对齐。

JustificationFlag JUSTIFICATION_CONSTRAIN_ELLIPSIS = 16

对带有省略号的修剪线应用对齐。

JustificationFlag JUSTIFICATION_SKIP_LAST_LINE = 32

不要将理由应用于该段的最后一行。

JustificationFlag JUSTIFICATION_SKIP_LAST_LINE_WITH_VISIBLE_CHARS = 64

不要对带有可见字符的段落的最后一行应用对齐(优先于JUSTIFICATION_SKIP_LAST_LINE)。

JustificationFlag JUSTIFICATION_DO_NOT_SKIP_SINGLE_LINE = 128

始终对单行段落应用对齐(JUSTIFICATION_SKIP_LAST_LINEJUSTIFICATION_SKIP_LAST_LINE_WITH_VISIBLE_CHARS被忽略)。


enum AutowrapMode: 🔗

AutowrapMode AUTOWRAP_OFF = 0

自动包装已禁用。

AutowrapMode AUTOWRAP_ARBITRARY = 1

通过允许在任意位置折线将文本包装在节点的边界矩形内,这在可用空间非常有限时很有用。

AutowrapMode AUTOWRAP_WORD = 2

通过单词之间的软中断将文本包装在节点的边界矩形内。

AutowrapMode AUTOWRAP_WORD_SMART = 3

行为类似于AUTOWRAP_WORD,但如果单个单词不适合一行,则强制中断该单词。


flags LineBreakFlag: 🔗

LineBreakFlag BREAK_NONE = 0

不要打破界限。

LineBreakFlag BREAK_MANDATORY = 1

在强制换行字符处(例如"\n")换行

LineBreakFlag BREAK_WORD_BOUND = 2

打破单词之间的界限。

LineBreakFlag BREAK_GRAPHEME_BOUND = 4

打破任何未连接的字素之间的界限。

LineBreakFlag BREAK_ADAPTIVE = 8

应仅与BREAK_WORD_BOUND连用,如果不可能在单词之间打破任何未连接的字素之间的界限。

LineBreakFlag BREAK_TRIM_EDGE_SPACES = 16

从虚线段中删除边缘空间。

LineBreakFlag BREAK_TRIM_INDENT = 32

从第一行之后的所有行中减去第一行缩进宽度。


enum VisibleCharactersBehavior: 🔗

VisibleCharactersBehavior VC_CHARS_BEFORE_SHAPING = 0

在整形之前修剪文本。例如,增加Label.visible_charactersRichTextLabel.visible_characters值在视觉上与键入文本相同。

注意:在此模式下,根本不处理修剪后的文本。它不计入换行和大小计算。

VisibleCharactersBehavior VC_CHARS_AFTER_SHAPING = 1

显示映射到文本开头的第一个Label.visible_charactersRichTextLabel.visible_characters字符的字形。

VisibleCharactersBehavior VC_GLYPHS_AUTO = 2

显示Label.visible_ratioRichTextLabel.visible_ratio字形,从左侧或右侧开始,具体取决于Control.layout_direction值。

VisibleCharactersBehavior VC_GLYPHS_LTR = 3

显示Label.visible_ratioRichTextLabel.visible_ratio字形,从左侧开始。

VisibleCharactersBehavior VC_GLYPHS_RTL = 4

显示Label.visible_ratioRichTextLabel.visible_ratio字形,从右侧开始。


enum OverrunBehavior: 🔗

OverrunBehavior OVERRUN_NO_TRIMMING = 0

不执行文本修剪。

OverrunBehavior OVERRUN_TRIM_CHAR = 1

修剪每个字符的文本。

OverrunBehavior OVERRUN_TRIM_WORD = 2

修剪每个单词的文本。

OverrunBehavior OVERRUN_TRIM_ELLIPSIS = 3

修剪每个字符的文本并添加省略号以指示部分被隐藏。

OverrunBehavior OVERRUN_TRIM_WORD_ELLIPSIS = 4

修剪每个单词的文本并添加省略号以指示部分被隐藏。


flags TextOverrunFlag: 🔗

TextOverrunFlag OVERRUN_NO_TRIM = 0

不执行修剪。

TextOverrunFlag OVERRUN_TRIM = 1

当超过给定宽度时修剪文本。

TextOverrunFlag OVERRUN_TRIM_WORD_ONLY = 2

修剪每个单词而不是每个字位的文本。

TextOverrunFlag OVERRUN_ADD_ELLIPSIS = 4

确定是否应在文本末尾添加省略号。

TextOverrunFlag OVERRUN_ENFORCE_ELLIPSIS = 8

确定文本末尾的省略号是否强制执行且不得隐藏。

TextOverrunFlag OVERRUN_JUSTIFICATION_AWARE = 16

在尝试修剪文本之前对文本进行对齐的帐户(参见JustificationFlag)。


flags GraphemeFlag: 🔗

GraphemeFlag GRAPHEME_IS_VALID = 1

字位由字体支持,可以绘制。

GraphemeFlag GRAPHEME_IS_RTL = 2

字位是从右到左或从下到上运行的一部分。

GraphemeFlag GRAPHEME_IS_VIRTUAL = 4

字位不是源文本的一部分,它是通过对齐过程添加的。

GraphemeFlag GRAPHEME_IS_SPACE = 8

字位为空格。

GraphemeFlag GRAPHEME_IS_BREAK_HARD = 16

字位是强制断点(例如"\n"

GraphemeFlag GRAPHEME_IS_BREAK_SOFT = 32

字位是可选的断点(例如空格)。

GraphemeFlag GRAPHEME_IS_TAB = 64

字位是制表字符。

GraphemeFlag GRAPHEME_IS_ELONGATION = 128

字位是kashida

GraphemeFlag GRAPHEME_IS_PUNCTUATION = 256

字位是标点符号。

GraphemeFlag GRAPHEME_IS_UNDERSCORE = 512

字位是下划线字符。

GraphemeFlag GRAPHEME_IS_CONNECTED = 1024

字位连接到前一个字位。在此字位之前断线是不安全的。

GraphemeFlag GRAPHEME_IS_SAFE_TO_INSERT_TATWEEL = 2048

在此字位前插入U+0640以进行伸长是安全的。

GraphemeFlag GRAPHEME_IS_EMBEDDED_OBJECT = 4096

字位是嵌入对象的对象替换字符。

GraphemeFlag GRAPHEME_IS_SOFT_HYPHEN = 8192

字位是软连字符。


enum Hinting: 🔗

Hinting HINTING_NONE = 0

禁用字体提示(更流畅但不那么清晰)。

Hinting HINTING_LIGHT = 1

使用浅色字体提示模式。

Hinting HINTING_NORMAL = 2

使用默认字体提示模式(更清晰但不太流畅)。

注意:此提示模式会更改水平和垂直字形指标。如果应用于等宽字体,某些字形可能具有不同的宽度。


enum SubpixelPositioning: 🔗

SubpixelPositioning SUBPIXEL_POSITIONING_DISABLED = 0

字形水平位置被舍入到整个像素大小,每个字形被光栅化一次。

SubpixelPositioning SUBPIXEL_POSITIONING_AUTO = 1

字形水平位置根据字体大小四舍五入。

-如果字体大小小于或等于SUBPIXEL_POSITIONING_ONE_QUARTER_MAX_SIZE,则为像素大小的四分之一。

-如果字体大小小于或等于SUBPIXEL_POSITIONING_ONE_HALF_MAX_SIZE,则为像素大小的一半。

-更大字体的整个像素大小。

SubpixelPositioning SUBPIXEL_POSITIONING_ONE_HALF = 2

字形水平位置被舍入到像素大小的一半,每个字形最多被光栅化两次。

SubpixelPositioning SUBPIXEL_POSITIONING_ONE_QUARTER = 3

字形水平位置被舍入到像素大小的四分之一,每个字形被光栅化多达四次。

SubpixelPositioning SUBPIXEL_POSITIONING_ONE_HALF_MAX_SIZE = 20

SUBPIXEL_POSITIONING_AUTO模式下将使用像素子像素定位的一半的最大字体大小。

SubpixelPositioning SUBPIXEL_POSITIONING_ONE_QUARTER_MAX_SIZE = 16

SUBPIXEL_POSITIONING_AUTO模式下使用四分之一像素子像素定位的最大字体大小。


enum Feature: 🔗

Feature FEATURE_SIMPLE_LAYOUT = 1

TextServer支持简单的文本布局。

Feature FEATURE_BIDI_LAYOUT = 2

TextServer支持双向文本布局。

Feature FEATURE_VERTICAL_LAYOUT = 4

TextServer支持垂直布局。

Feature FEATURE_SHAPING = 8

TextServer支持复杂的文本整形。

Feature FEATURE_KASHIDA_JUSTIFICATION = 16

TextServer支持使用kashidas进行对齐。

Feature FEATURE_BREAK_ITERATORS = 32

TextServer支持复杂的换行/分词规则(例如基于字典)。

Feature FEATURE_FONT_BITMAP = 64

TextServer支持加载位图字体。

Feature FEATURE_FONT_DYNAMIC = 128

TextServer支持加载动态(TrueType、OpeType等)字体。

Feature FEATURE_FONT_MSDF = 256

TextServer支持多通道有符号距离字段动态字体渲染。

Feature FEATURE_FONT_SYSTEM = 512

TextServer支持加载系统字体。

Feature FEATURE_FONT_VARIABLE = 1024

TextServer支持可变字体。

Feature FEATURE_CONTEXT_SENSITIVE_CASE_CONVERSION = 2048

TextServer支持区域设置相关和上下文相关的大小写转换。

Feature FEATURE_USE_SUPPORT_DATA = 4096

对于某些功能,TextServer需要外部数据文件,请参见load_support_data()

Feature FEATURE_UNICODE_IDENTIFIERS = 8192

TextServer支持UAX#31标识符验证,参见is_valid_identifier()

Feature FEATURE_UNICODE_SECURITY = 16384

TextServer支持Unicode技术报告#36基于Unicode技术标准#39的欺骗检测功能。


enum ContourPointTag: 🔗

ContourPointTag CONTOUR_CURVE_TAG_ON = 1

等高线点在曲线上。

ContourPointTag CONTOUR_CURVE_TAG_OFF_CONIC = 0

等高线点不在曲线上,但作为二次曲线贝塞尔弧的控制点。

ContourPointTag CONTOUR_CURVE_TAG_OFF_CUBIC = 2

等高线点不在曲线上,但作为立方贝塞尔弧的控制点。


enum SpacingType: 🔗

SpacingType SPACING_GLYPH = 0

每个字形的间距。

SpacingType SPACING_SPACE = 1

空格字符的间距。

SpacingType SPACING_TOP = 2

行顶部的间距。

SpacingType SPACING_BOTTOM = 3

行底部的间距。

SpacingType SPACING_MAX = 4

表示SpacingType枚举的大小。


flags FontStyle: 🔗

FontStyle FONT_BOLD = 1

字体为粗体。

FontStyle FONT_ITALIC = 2

字体为斜体字或斜体字。

FontStyle FONT_FIXED_WIDTH = 4

字体具有固定宽度的字符。


enum StructuredTextParser: 🔗

StructuredTextParser STRUCTURED_TEXT_DEFAULT = 0

使用默认的Unicode BiDi算法。

StructuredTextParser STRUCTURED_TEXT_URI = 1

URI的BiDi覆盖。

StructuredTextParser STRUCTURED_TEXT_FILE = 2

BiDi覆盖文件路径。

StructuredTextParser STRUCTURED_TEXT_EMAIL = 3

BiDi覆盖电子邮件。

StructuredTextParser STRUCTURED_TEXT_LIST = 4

BiDi覆盖列表。结构化文本选项:列表分隔符String

StructuredTextParser STRUCTURED_TEXT_S3SCRIPT = 5

S3Script的BiDi覆盖。

StructuredTextParser STRUCTURED_TEXT_CUSTOM = 6

用户定义的结构化文本BiDi覆盖功能。


enum FixedSizeScaleMode: 🔗

FixedSizeScaleMode FIXED_SIZE_SCALE_DISABLE = 0

位图字体不缩放。

FixedSizeScaleMode FIXED_SIZE_SCALE_INTEGER_ONLY = 1

位图字体缩放到字体固定大小的最接近整数倍。这是像素艺术字体的推荐选项。

FixedSizeScaleMode FIXED_SIZE_SCALE_ENABLED = 2

位图字体缩放为任意(小数)大小。这是非像素艺术字体的推荐选项。


方法说明

RID create_font() 🔗

创建一个新的空字体缓存条目资源。要释放生成的资源,请使用free_rid()方法。


RID create_font_linked_variation(font_rid: RID) 🔗

创建一个新的变体现有字体,该字体正在重用相同的字形缓存和字体数据。要释放生成的资源,请使用free_rid()方法。


RID create_shaped_text(direction: Direction = 0, orientation: Orientation = 0) 🔗

使用给定的directiondirection为复杂文本布局创建一个新缓冲区。要释放生成的缓冲区,请使用free_rid()方法。

注意:如果服务器不支持FEATURE_BIDI_LAYOUT功能(由TextServerAdvanced支持),则忽略方向。

注意:如果服务器不支持FEATURE_VERTICAL_LAYOUT功能(由TextServerAdvanced支持),则忽略方向。


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

绘制显示字符十六进制代码的框。用于替换缺失的字符。


void font_clear_glyphs(font_rid: RID, size: Vector2i) 🔗

从缓存条目中删除所有呈现的字形信息。

注意:此功能不会删除与字形关联的纹理,使用font_remove_texture()手动删除它们。


void font_clear_kerning_map(font_rid: RID, size: int) 🔗

删除所有字距调整覆盖。


void font_clear_size_cache(font_rid: RID) 🔗

从缓存条目中删除所有字体大小。


void font_clear_textures(font_rid: RID, size: Vector2i) 🔗

从字体缓存条目中删除所有纹理。

注意:此功能不会删除与纹理关联的字形,使用font_remove_glyph()手动删除它们。


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

在该位置使用sizefont_rid将单个字形绘制到画布项目中。

注意:字形索引特定于字体,使用shaped_text_get_glyphs()font_get_glyph_index()返回的字形索引。

注意:如果有待渲染的字形,调用此函数可能会触发纹理缓存更新。


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

使用sizeoutline_size处的font_rid将sizeoutline_size的单个字形轮廓绘制到该位置的画布项目中。

注意:字形索引特定于字体,使用shaped_text_get_glyphs()font_get_glyph_index()返回的字形索引。

注意:如果有待渲染的字形,调用此函数可能会触发纹理缓存更新。


FontAntialiasing font_get_antialiasing(font_rid: RID) const 🔗

返回字体抗混淆现象模式。


float font_get_ascent(font_rid: RID, size: int) const 🔗

返回字体上升(基线上方的像素数)。


float font_get_baseline_offset(font_rid: RID) const 🔗

返回额外的基线偏移量(作为字体高度的一小部分)。


int font_get_char_from_glyph_index(font_rid: RID, size: int, glyph_index: int) const 🔗

返回与glyph_index关联的字符代码,如果glyph_index无效,则返回0。参见font_get_glyph_index()


float font_get_descent(font_rid: RID, size: int) const 🔗

返回字体下降(基线以下的像素数)。


bool font_get_disable_embedded_bitmaps(font_rid: RID) const 🔗

返回是否禁用字体的嵌入位图加载。


float font_get_embolden(font_rid: RID) const 🔗

返回字体加粗强度。


int font_get_face_count(font_rid: RID) const 🔗

返回TrueType/OpenType集合中的面数。


int font_get_face_index(font_rid: RID) const 🔗

返回TrueType/OpenType集合中的活动面部索引。


int font_get_fixed_size(font_rid: RID) const 🔗

返回位图字体固定大小。


FixedSizeScaleMode font_get_fixed_size_scale_mode(font_rid: RID) const 🔗

返回位图字体缩放模式。


bool font_get_generate_mipmaps(font_rid: RID) const 🔗

如果启用了字体纹理mipmap生成,则返回true


float font_get_global_oversampling() const 🔗

返回字体过采样因子,由TextServer中的所有字体共享。


Vector2 font_get_glyph_advance(font_rid: RID, size: int, glyph: int) const 🔗

返回字形前进(下一个字形的偏移量)。

注意:字形提前量与基本字形提前量相同,不保存。


Dictionary font_get_glyph_contours(font: RID, size: int, index: int) const 🔗

Dictionary形式返回字形的轮廓轮廓,内容如下:

point-PackedVector3Array,包含轮廓点。xy是点坐标。z是点的类型,使用ContourPointTag值。

轮廓-PackedInt32Array,包含每个轮廓的端点的索引。

方向-bool,轮廓方向。如果true,则必须按顺时针方向填充轮廓。

-两个连续的CONTOUR_CURVE_TAG_ON点表示线段。

-两个CONTOUR_CURVE_TAG_ON点之间的一个CONTOUR_CURVE_TAG_OFF_CONIC点表示单个二次曲线(二次)贝塞尔弧。

-两个CONTOUR_CURVE_TAG_OFF_CUBIC点之间的两个CONTOUR_CURVE_TAG_ON点表示单个立方贝塞尔弧。

-两个连续的CONTOUR_CURVE_TAG_OFF_CONIC点表示两个连续的圆锥(二次)贝塞尔弧,中间有一个虚拟的CONTOUR_CURVE_TAG_ON点。

-每个轮廓都是闭合的。轮廓的最后一点使用轮廓的第一点作为下一点,反之亦然。第一点可以是CONTOUR_CURVE_TAG_OFF_CONIC点。


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

返回char的字形索引,可选择由variation_selector修改。请参见font_get_char_from_glyph_index()


PackedInt32Array font_get_glyph_list(font_rid: RID, size: Vector2i) const 🔗

返回缓存条目中呈现的字形列表。


Vector2 font_get_glyph_offset(font_rid: RID, size: Vector2i, glyph: int) const 🔗

返回与基线的字形偏移量。


Vector2 font_get_glyph_size(font_rid: RID, size: Vector2i, glyph: int) const 🔗

返回字形的大小。


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

返回包含字形的缓存纹理的索引。


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

返回包含字形的缓存纹理的资源ID。

注意:如果有待渲染的字形,调用此函数可能会触发纹理缓存更新。


Vector2 font_get_glyph_texture_size(font_rid: RID, size: Vector2i, glyph: int) const 🔗

返回包含字形的缓存纹理的大小。

注意:如果有待渲染的字形,调用此函数可能会触发纹理缓存更新。


Rect2 font_get_glyph_uv_rect(font_rid: RID, size: Vector2i, glyph: int) const 🔗

返回包含字形的缓存纹理中的矩形。


Hinting font_get_hinting(font_rid: RID) const 🔗

返回字体提示模式。仅由动态字体使用。


bool font_get_keep_rounding_remainders(font_rid: RID) const 🔗

返回字形位置舍入行为。如果设置为true,则在将字形与像素边界对齐时,舍入余数会累积以确保字形分布更均匀。如果启用子像素定位,此设置无效。


Vector2 font_get_kerning(font_rid: RID, size: int, glyph_pair: Vector2i) const 🔗

返回这对字形的字距调整。


Array[Vector2i] font_get_kerning_list(font_rid: RID, size: int) const 🔗

返回字距覆盖的列表。


bool font_get_language_support_override(font_rid: RID, language: String) 🔗

如果为language启用了支持覆盖,则返回true


PackedStringArray font_get_language_support_overrides(font_rid: RID) 🔗

返回语言支持覆盖列表。


int font_get_msdf_pixel_range(font_rid: RID) const 🔗

返回形状周围最小和最大可表示符号距离之间的范围的宽度。


int font_get_msdf_size(font_rid: RID) const 🔗

返回用于生成MSDF纹理的源字体大小。


String font_get_name(font_rid: RID) const 🔗

返回字体族名。


Dictionary font_get_opentype_feature_overrides(font_rid: RID) const 🔗

返回字体OpenType功能集覆盖。


Dictionary font_get_ot_name_strings(font_rid: RID) const 🔗

返回带有OpenType字体名称字符串(本地化字体名称、版本、描述、许可证信息、示例文本等)的Dictionary


float font_get_oversampling(font_rid: RID) const 🔗

返回字体过采样因子,如果设置为0.0则使用全局过采样因子。仅由动态字体使用。


float font_get_scale(font_rid: RID, size: int) const 🔗

返回颜色位图字体的缩放因子。


bool font_get_script_support_override(font_rid: RID, script: String) 🔗

如果为script启用了支持覆盖,则返回true


PackedStringArray font_get_script_support_overrides(font_rid: RID) 🔗

返回脚本支持覆盖列表。


Array[Vector2i] font_get_size_cache_list(font_rid: RID) const 🔗

返回缓存中字体大小的列表。每个大小是Vector2i,带有字体大小和轮廓大小。


int font_get_spacing(font_rid: RID, spacing: SpacingType) const 🔗

返回spacing(参见SpacingType)的行间距,以像素为单位(与字体大小无关)。


int font_get_stretch(font_rid: RID) const 🔗

与正常宽度相比,返回字体拉伸量。50%200%之间的百分比值。


BitField[FontStyle] font_get_style(font_rid: RID) const 🔗

返回字体样式标志,请参阅FontStyle


String font_get_style_name(font_rid: RID) const 🔗

返回字体样式名称。


SubpixelPositioning font_get_subpixel_positioning(font_rid: RID) const 🔗

返回字体亚像素字形定位模式。


String font_get_supported_chars(font_rid: RID) const 🔗

返回包含字体中所有可用字符的字符串。


PackedInt32Array font_get_supported_glyphs(font_rid: RID) const 🔗

返回包含字体中所有字形索引的数组。


int font_get_texture_count(font_rid: RID, size: Vector2i) const 🔗

返回字体缓存条目使用的纹理数量。


Image font_get_texture_image(font_rid: RID, size: Vector2i, texture_index: int) const 🔗

返回字体缓存纹理图像数据。


PackedInt32Array font_get_texture_offsets(font_rid: RID, size: Vector2i, texture_index: int) const 🔗

返回包含字形打包数据的数组。


Transform2D font_get_transform(font_rid: RID) const 🔗

返回应用于字体轮廓的2D变换。


float font_get_underline_position(font_rid: RID, size: int) const 🔗

返回基线下方下划线的像素偏移量。


float font_get_underline_thickness(font_rid: RID, size: int) const 🔗

返回下划线的粗细(以像素为单位)。


Dictionary font_get_variation_coordinates(font_rid: RID) const 🔗

返回指定字体缓存项的变化坐标。有关详细信息,请参阅font_supported_variation_list()


int font_get_weight(font_rid: RID) const 🔗

返回字体的权重(粗体)。100…999范围内的值,正常字体权重为400,粗体字体权重为700


bool font_has_char(font_rid: RID, char: int) const 🔗

如果字体中有Unicodechar,则返回true


bool font_is_allow_system_fallback(font_rid: RID) const 🔗

如果系统字体可以自动用作后备,则返回true


bool font_is_force_autohinter(font_rid: RID) const 🔗

如果支持自动提示并且首选字体内置提示,则返回true。仅由动态字体使用。


bool font_is_language_supported(font_rid: RID, language: String) const 🔗

如果字体支持给定的语言(ISO 639代码),则返回true


bool font_is_multichannel_signed_distance_field(font_rid: RID) const 🔗

如果使用从动态字体矢量数据生成的单个多通道有符号距离字段渲染所有大小的字形,则返回true


bool font_is_script_supported(font_rid: RID, script: String) const 🔗

如果字体支持给定脚本(ISO 15924代码),则返回true


void font_remove_glyph(font_rid: RID, size: Vector2i, glyph: int) 🔗

从缓存条目中删除指定的呈现字形信息。

注意:此功能不会删除与字形关联的纹理,使用font_remove_texture()手动删除它们。


void font_remove_kerning(font_rid: RID, size: int, glyph_pair: Vector2i) 🔗

删除字形对的字距覆盖。


void font_remove_language_support_override(font_rid: RID, language: String) 🔗

删除语言支持覆盖。


void font_remove_script_support_override(font_rid: RID, script: String) 🔗

删除脚本支持覆盖。


void font_remove_size_cache(font_rid: RID, size: Vector2i) 🔗

从缓存条目中删除指定的字体大小。


void font_remove_texture(font_rid: RID, size: Vector2i, texture_index: int) 🔗

从缓存条目中删除指定的纹理。

注意:此功能不会删除与纹理相关的字形,使用font_remove_glyph()手动删除它们。


void font_render_glyph(font_rid: RID, size: Vector2i, index: int) 🔗

将指定的字形呈现到字体缓存纹理中。


void font_render_range(font_rid: RID, size: Vector2i, start: int, end: int) 🔗

将字符范围呈现到字体缓存纹理。


void font_set_allow_system_fallback(font_rid: RID, allow_system_fallback: bool) 🔗

如果设置为true,系统字体可以自动用作后备。


void font_set_antialiasing(font_rid: RID, antialiasing: FontAntialiasing) 🔗

设置字体防混淆现象模式。


void font_set_ascent(font_rid: RID, size: int, ascent: float) 🔗

设置字体上升(基线上方的像素数)。


void font_set_baseline_offset(font_rid: RID, baseline_offset: float) 🔗

设置额外的基线偏移量(作为字体高度的一小部分)。


void font_set_data(font_rid: RID, data: PackedByteArray) 🔗

设置字体源数据,例如动态字体源文件的内容。


void font_set_descent(font_rid: RID, size: int, descent: float) 🔗

设置字体下降(基线以下的像素数)。


void font_set_disable_embedded_bitmaps(font_rid: RID, disable_embedded_bitmaps: bool) 🔗

如果设置为true,则禁用嵌入字体位图加载(仅位图和彩色字体忽略此属性)。


void font_set_embolden(font_rid: RID, strength: float) 🔗

设置字体加粗强度。如果strength不等于零,则加粗字体轮廓。负值减小轮廓厚度。


void font_set_face_index(font_rid: RID, face_index: int) 🔗

在TrueType/OpenType集合中设置活动面部索引。


void font_set_fixed_size(font_rid: RID, fixed_size: int) 🔗

设置位图字体固定大小。如果设置为大于零,则所有字体大小都将使用相同的缓存条目。


void font_set_fixed_size_scale_mode(font_rid: RID, fixed_size_scale_mode: FixedSizeScaleMode) 🔗

设置位图字体缩放模式。此属性仅在fixed_size大于零时使用。


void font_set_force_autohinter(font_rid: RID, force_autohinter: bool) 🔗

如果设置为true,则自动提示优于字体内置提示。


void font_set_generate_mipmaps(font_rid: RID, generate_mipmaps: bool) 🔗

如果设置为true字体纹理mipmap生成已启用。


void font_set_global_oversampling(oversampling: float) 🔗

设置TextServer中所有字体共享的过采样因子。

注意:此值可以由显示服务器自动更改。


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

设置字形前进(下一个字形的偏移量)。

注意:字形提前量与基本字形提前量相同,不保存。


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

设置字形与基线的偏移量。


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

设置字形的大小。


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

设置包含字形的缓存纹理的索引。


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

在包含字形的缓存纹理中设置矩形。


void font_set_hinting(font_rid: RID, hinting: Hinting) 🔗

设置字体提示模式。仅由动态字体使用。


void font_set_keep_rounding_remainders(font_rid: RID, keep_rounding_remainders: bool) 🔗

设置字形位置舍入行为。如果设置为true,则在将字形与像素边界对齐时,舍入余数会累积以确保字形分布更均匀。如果启用子像素定位,此设置无效。


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

设置字形对的字距。


void font_set_language_support_override(font_rid: RID, language: String, supported: bool) 🔗

font_is_language_supported()添加覆盖。


void font_set_msdf_pixel_range(font_rid: RID, msdf_pixel_range: int) 🔗

设置形状周围最小和最大可表示符号距离之间的范围的宽度。


void font_set_msdf_size(font_rid: RID, msdf_size: int) 🔗

设置用于生成MSDF纹理的源字体大小。


void font_set_multichannel_signed_distance_field(font_rid: RID, msdf: bool) 🔗

如果设置为true,则使用从动态字体矢量数据生成的单个多通道有符号距离字段渲染所有大小的字形。MSDF渲染允许以任何缩放因子显示字体而不会模糊,并且在字体大小更改时不会产生CPU成本(因为字体不再需要在CPU上光栅化)。缺点是,MSDF不提供字体提示。缺少字体提示可能会导致小尺寸字体不清晰且可读性较差。

注意:MSDF字体渲染不能正确渲染具有重叠形状的字形。根据OpenType标准,重叠形状无效,但在许多字体文件中仍然很常见,尤其是那些由Google Fonts转换的字体文件。为了避免重叠字形的问题,请考虑直接从字体铸造厂下载字体文件,而不是依赖Google Fonts。


void font_set_name(font_rid: RID, name: String) 🔗

设置字体系列名称。


void font_set_opentype_feature_overrides(font_rid: RID, overrides: Dictionary) 🔗

设置字体OpenType功能集覆盖。


void font_set_oversampling(font_rid: RID, oversampling: float) 🔗

设置字体过采样因子,如果设置为0.0则使用全局过采样因子。仅由动态字体使用。


void font_set_scale(font_rid: RID, size: int, scale: float) 🔗

设置颜色位图字体的比例因子。


void font_set_script_support_override(font_rid: RID, script: String, supported: bool) 🔗

font_is_script_supported()添加覆盖。


void font_set_spacing(font_rid: RID, spacing: SpacingType, value: int) 🔗

spacing(参见SpacingType)的行间距设置为value(以像素为单位)(与字体大小无关)。


void font_set_stretch(font_rid: RID, weight: int) 🔗

与正常宽度相比,设置字体拉伸量。50%200%之间的百分比值。

注意:此值仅用于字体匹配,不会影响字体呈现,改用font_set_face_index()font_set_variation_coordinates()font_set_transform()


void font_set_style(font_rid: RID, style: BitField[FontStyle]) 🔗

设置字体样式标志,请参阅FontStyle

注意:此值仅用于字体匹配,不会影响字体呈现,改用font_set_face_index()font_set_variation_coordinates()font_set_embolden()font_set_transform()


void font_set_style_name(font_rid: RID, name: String) 🔗

设置字体样式名称。


void font_set_subpixel_positioning(font_rid: RID, subpixel_positioning: SubpixelPositioning) 🔗

设置字体子像素字形定位模式。


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

设置字体缓存纹理图像数据。


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

设置包含字形打包数据的数组。


void font_set_transform(font_rid: RID, transform: Transform2D) 🔗

设置2D变换,应用于字体轮廓,可用于倾斜、翻转和旋转字形。

例如,要通过倾斜来模拟斜体字字体,请应用以下变换Transform2D(1.0, slant,0.0,1.0,0.0,0.0)


void font_set_underline_position(font_rid: RID, size: int, underline_position: float) 🔗

设置基线下方下划线的像素偏移量。


void font_set_underline_thickness(font_rid: RID, size: int, underline_thickness: float) 🔗

设置下划线的粗细(以像素为单位)。


void font_set_variation_coordinates(font_rid: RID, variation_coordinates: Dictionary) 🔗

设置指定字体缓存项的变化坐标。有关详细信息,请参阅font_supported_variation_list()


void font_set_weight(font_rid: RID, weight: int) 🔗

设置字体的权重(粗体)。100…999范围内的值,正常字体权重为400,粗体字体权重为700

注意:此值仅用于字体匹配,不会影响字体呈现,改用font_set_face_index()font_set_variation_coordinates()font_set_embolden()


Dictionary font_supported_feature_list(font_rid: RID) const 🔗

返回支持的OpenType功能的字典。


Dictionary font_supported_variation_list(font_rid: RID) const 🔗

返回支持的OpenType变体坐标的字典。


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

将数字从西方阿拉伯语(0…9)转换为language中使用的数字系统。

如果省略language,将使用活动的语言环境。


void free_rid(rid: RID) 🔗

释放由thisTextServer创建的对象。


int get_features() const 🔗

返回文本服务器功能,请参阅Feature


Vector2 get_hex_code_box_size(size: int, index: int) const 🔗

返回替换字符的大小(带有代替无效字符绘制的字符十六进制代码的框)。


String get_name() const 🔗

返回服务器接口的名称。


PackedByteArray get_support_data() const 🔗

返回默认的TextServer数据库(例如ICU中断迭代器和字典)。


String get_support_data_filename() const 🔗

返回默认的TextServer数据库(例如ICU中断迭代器和字典)文件名。


String get_support_data_info() const 🔗

返回TextServer数据库(例如ICU中断迭代器和字典)描述。


bool has(rid: RID) 🔗

如果rid是此文本服务器拥有的有效资源,则返回true


bool has_feature(feature: Feature) const 🔗

如果服务器支持某个功能,则返回true


int is_confusable(string: String, dict: PackedStringArray) const 🔗

(C++11起)返回索引的第一个字符串在视觉上与string混淆,或-1如果没有找到。

注意:此方法不检测不可见字符,对于欺骗检测,请将其与spoof_check()结合使用。

注意:如果服务器不支持FEATURE_UNICODE_SECURITY功能,则始终返回-1


bool is_locale_right_to_left(locale: String) const 🔗

如果语言环境从右到左,则返回true


bool is_valid_identifier(string: String) const 🔗

如果string是有效标识符,则返回true

如果文本服务器支持FEATURE_UNICODE_IDENTIFIERS功能,则有效标识符必须:

-符合标准化表格C。

-以类XID_Start或"_"的Unicode字符开始。

-在其他位置可能包含类XID_Continue的Unicode字符。

-仅使用UAX#31推荐的脚本(允许混合脚本)。

如果不支持FEATURE_UNICODE_IDENTIFIERS功能,则有效标识符必须:

-以类XID_Start或"_"的Unicode字符开始。

-在其他位置可能包含类XID_Continue的Unicode字符。


bool is_valid_letter(unicode: int) const 🔗

如果给定的代码点是一个有效的字母,即它属于Unicode类别“L”,则返回true


bool load_support_data(filename: String) 🔗

加载可选的TextServer数据库(例如ICU中断迭代器和字典)。

注意:此函数应在使用任何其他TextServer函数之前调用,否则不会产生任何影响。


int name_to_tag(name: String) const 🔗

将可读功能、变体、脚本或语言名称转换为OpenType标记。


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

numberlanguage中使用的数字系统转换为西方阿拉伯语(0…9)。


Array[Vector3i] parse_structured_text(parser_type: StructuredTextParser, args: Array, text: String) const 🔗

BiDi算法覆盖函数的默认实现。有关详细信息,请参阅StructuredTextParser


String percent_sign(language: String = "") const 🔗

返回language中使用的百分号。


bool save_support_data(filename: String) const 🔗

将可选的TextServer数据库(例如ICU中断迭代器和字典)保存到文件中。

注意:此函数在项目导出期间使用,以包含TextServer数据库。


int shaped_get_span_count(shaped: RID) const 🔗

返回使用shaped_text_add_string()shaped_text_add_object()添加的文本跨度数。


Variant shaped_get_span_embedded_object(shaped: RID, index: int) const 🔗

返回文本嵌入对象键。


Variant shaped_get_span_meta(shaped: RID, index: int) const 🔗

返回文本跨度元数据。


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

更改文本跨度字体、字体大小和OpenType功能,而不更改文本。


bool shaped_text_add_object(shaped: RID, key: Variant, size: Vector2, inline_align: InlineAlignment = 5, length: int = 1, baseline: float = 0.0) 🔗

将内联对象添加到文本缓冲区,key必须是唯一的。在文本中,对象表示为length对象替换字符。


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

添加文本跨度和字体以将其绘制到文本缓冲区。


void shaped_text_clear(rid: RID) 🔗

清除文本缓冲区(删除文本和内联对象)。


int shaped_text_closest_character_pos(shaped: RID, pos: int) const 🔗

返回最接近pos的复合字符位置。


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

使用color在给定位置将形状文本绘制到画布项目中。pos指定基线的最左侧点(用于水平布局)或基线的最顶点(用于垂直布局)。


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

使用color将形状文本的轮廓绘制到给定位置的画布项目中。pos指定基线的最左侧点(用于水平布局)或基线的最顶点(用于垂直布局)。


float shaped_text_fit_to_width(shaped: RID, width: float, justification_flags: BitField[JustificationFlag] = 3) 🔗

调整文本宽度以适合指定的宽度,返回新的文本宽度。


float shaped_text_get_ascent(shaped: RID) const 🔗

返回文本上升(水平布局基线上方的像素数或垂直布局基线左侧的像素数)。

注意:如果某些字形从基线移位,则整体上升可能高于字体上升。


Dictionary shaped_text_get_carets(shaped: RID, position: int) const 🔗

返回文本中字符偏移量position对应的插入符号形状。返回的插入符号形状为1像素宽的矩形。


PackedInt32Array shaped_text_get_character_breaks(shaped: RID) const 🔗

返回复合字符边界的数组。


int shaped_text_get_custom_ellipsis(shaped: RID) const 🔗

返回用于文本剪辑的省略号字符。


String shaped_text_get_custom_punctuation(shaped: RID) const 🔗

返回自定义标点符号字符列表,用于分词。如果设置为空字符串,则使用服务器默认值。


float shaped_text_get_descent(shaped: RID) const 🔗

返回文本下降(水平布局基线下方的像素数或垂直布局基线右侧的像素数)。

注意:如果某些字形从基线移位,则整体下降可能高于字体下降。


Direction shaped_text_get_direction(shaped: RID) const 🔗

返回文本的方向。


Direction shaped_text_get_dominant_direction_in_range(shaped: RID, start: int, end: int) const 🔗

返回文本范围内的主要方向。


int shaped_text_get_ellipsis_glyph_count(shaped: RID) const 🔗

返回省略号中的字形数。


Array[Dictionary] shaped_text_get_ellipsis_glyphs(shaped: RID) const 🔗

返回省略号中的字形数组。


int shaped_text_get_ellipsis_pos(shaped: RID) const 🔗

返回省略号的位置。


int shaped_text_get_glyph_count(shaped: RID) const 🔗

返回缓冲区中的字形数。


Array[Dictionary] shaped_text_get_glyphs(shaped: RID) const 🔗

按可视顺序返回字形数组。


Vector2 shaped_text_get_grapheme_bounds(shaped: RID, pos: int) const 🔗

返回复合字符的边界作为从行首开始的偏移量。


Direction shaped_text_get_inferred_direction(shaped: RID) const 🔗

返回由BiDi算法推断的文本方向。


PackedInt32Array shaped_text_get_line_breaks(shaped: RID, width: float, start: int = 0, break_flags: BitField[LineBreakFlag] = 3) const 🔗

将文本中断为行并返回每行的字符范围。


PackedInt32Array shaped_text_get_line_breaks_adv(shaped: RID, width: PackedFloat32Array, start: int = 0, once: bool = true, break_flags: BitField[LineBreakFlag] = 3) const 🔗

将文本分成行和列。返回每个段的字符范围。


int shaped_text_get_object_glyph(shaped: RID, key: Variant) const 🔗

返回内联对象的字形索引。


Vector2i shaped_text_get_object_range(shaped: RID, key: Variant) const 🔗

返回内联对象的字符范围。


Rect2 shaped_text_get_object_rect(shaped: RID, key: Variant) const 🔗

返回内联对象的边界矩形。


Array shaped_text_get_objects(shaped: RID) const 🔗

返回内联对象数组。


Orientation shaped_text_get_orientation(shaped: RID) const 🔗

返回文本方向。


RID shaped_text_get_parent(shaped: RID) const 🔗

返回子字符串源自的父缓冲区。


bool shaped_text_get_preserve_control(shaped: RID) const 🔗

如果文本缓冲区配置为显示控制字符,则返回true


bool shaped_text_get_preserve_invalid(shaped: RID) const 🔗

如果文本缓冲区配置为显示十六进制代码代替无效字符,则返回true

注意:如果设置为false,则不会显示任何内容来代替无效字符。


Vector2i shaped_text_get_range(shaped: RID) const 🔗

返回父缓冲区中的子字符串缓冲区字符范围。


PackedVector2Array shaped_text_get_selection(shaped: RID, start: int, end: int) const 🔗

返回指定字符范围的选择矩形。


Vector2 shaped_text_get_size(shaped: RID) const 🔗

返回文本的大小。


int shaped_text_get_spacing(shaped: RID, spacing: SpacingType) const 🔗

返回以像素为单位的字形或线条之间添加的额外行间距。


int shaped_text_get_trim_pos(shaped: RID) const 🔗

返回超限修剪的位置。


float shaped_text_get_underline_position(shaped: RID) const 🔗

返回基线下方下划线的像素偏移量。


float shaped_text_get_underline_thickness(shaped: RID) const 🔗

返回下划线的粗细。


float shaped_text_get_width(shaped: RID) const 🔗

返回文本的宽度(用于水平布局)或高度(用于垂直)。


PackedInt32Array shaped_text_get_word_breaks(shaped: RID, grapheme_flags: BitField[GraphemeFlag] = 264, skip_grapheme_flags: BitField[GraphemeFlag] = 4) const 🔗

将文本分解为单词并返回字符范围数组。使用grapheme_flags设置用于分解的字符(请参阅GraphemeFlag)。


bool shaped_text_has_visible_chars(shaped: RID) const 🔗

如果文本缓冲区包含任何可见字符,则返回true


int shaped_text_hit_test_grapheme(shaped: RID, coords: float) const 🔗

返回基线指定像素偏移处的字位索引,如果未找到,则返回-1


int shaped_text_hit_test_position(shaped: RID, coords: float) const 🔗

返回基线指定像素偏移处的插入符号字符偏移量。此函数始终返回有效位置。


bool shaped_text_is_ready(shaped: RID) const 🔗

如果缓冲区整形成功,则返回true


int shaped_text_next_character_pos(shaped: RID, pos: int) const 🔗

返回最接近pos的复合字符结束位置。


int shaped_text_next_grapheme_pos(shaped: RID, pos: int) const 🔗

返回最接近pos的字位结束位置。


void shaped_text_overrun_trim_to_width(shaped: RID, width: float = 0, overrun_trim_flags: BitField[TextOverrunFlag] = 0) 🔗

如果超过给定宽度,则修剪文本。


int shaped_text_prev_character_pos(shaped: RID, pos: int) const 🔗

返回最接近pos的复合字符起始位置。


int shaped_text_prev_grapheme_pos(shaped: RID, pos: int) const 🔗

返回最接近pos的字位起始位置。


bool shaped_text_resize_object(shaped: RID, key: Variant, size: Vector2, inline_align: InlineAlignment = 5, baseline: float = 0.0) 🔗

设置嵌入对象的新大小和对齐方式。


void shaped_text_set_bidi_override(shaped: RID, override: Array) 🔗

覆盖结构化文本的BiDi。

覆盖范围应覆盖没有重叠的完整源代码文本。BiDi算法将分别用于每个范围。


void shaped_text_set_custom_ellipsis(shaped: RID, char: int) 🔗

设置用于文本剪辑的省略号字符。


void shaped_text_set_custom_punctuation(shaped: RID, punct: String) 🔗

设置自定义标点符号字符列表,用于分词。如果设置为空字符串,则使用服务器默认值。


void shaped_text_set_direction(shaped: RID, direction: Direction = 0) 🔗

设置所需的文本方向。如果设置为DIRECTION_AUTO,将根据缓冲区内容和当前区域设置检测方向。

注意:如果服务器不支持FEATURE_BIDI_LAYOUT功能(由TextServerAdvanced支持),则忽略方向。


void shaped_text_set_orientation(shaped: RID, orientation: Orientation = 0) 🔗

设置所需的文本方向。

注意:如果服务器不支持FEATURE_VERTICAL_LAYOUT功能(由TextServerAdvanced支持),则忽略方向。


void shaped_text_set_preserve_control(shaped: RID, enabled: bool) 🔗

如果设置为true文本缓冲区将显示控制字符。


void shaped_text_set_preserve_invalid(shaped: RID, enabled: bool) 🔗

如果设置为true文本缓冲区将无效字符显示为十六进制代码,否则不显示任何内容。


void shaped_text_set_spacing(shaped: RID, spacing: SpacingType, value: int) 🔗

设置以像素为单位的字形或线条之间添加的额外行间距。


bool shaped_text_shape(shaped: RID) 🔗

如果未整形,则缓冲形状。如果字符串整形成功,则返回true

注意:无需手动调用此函数,只要请求任何输出数据,缓冲区就会自动成型。


Array[Dictionary] shaped_text_sort_logical(shaped: RID) 🔗

按逻辑顺序返回文本字形。


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

返回shaped文本缓冲区(包括内联对象)中文本子字符串的文本缓冲区。


float shaped_text_tab_align(shaped: RID, tab_stops: PackedFloat32Array) 🔗

将形状文本与给定的制表符对齐。


bool spoof_check(string: String) const 🔗

如果string可能试图混淆读者,则返回true

注意:如果服务器不支持FEATURE_UNICODE_SECURITY功能,则始终返回false


PackedInt32Array string_get_character_breaks(string: String, language: String = "") const 🔗

返回由复合字符边界组成的数组。.

var ts = TextServerManager.get_primary_interface()
print(ts.string_get_character_breaks("Test ❤️‍🔥 Test")) # Prints [1, 2, 3, 4, 5, 9, 10, 11, 12, 13, 14]

PackedInt32Array string_get_word_breaks(string: String, language: String = "", chars_per_line: int = 0) const 🔗

返回一个包含单词断行边界的数组。返回数组中的元素是单词起始和结束位置的偏移量。因此,该数组的长度始终为偶数。

chars_per_line 大于零时,将返回换行边界。

var ts = TextServerManager.get_primary_interface()
# 对应于子字符串 "The", "i3D", "Engine", 和 "4"。
print(ts.string_get_word_breaks("The i3D Engine, 4")) # Prints [0, 3, 4, 9, 10, 16, 18, 19]
# 对应于子字符串 "The", "i3D", "Engin", 和 "e, 4"。
print(ts.string_get_word_breaks("The i3D Engine, 4", "en", 5)) # Prints [0, 3, 4, 9, 10, 15, 15, 19]
# 对应于子字符串 "The i3D" 和 "Engine, 4"。
print(ts.string_get_word_breaks("The i3D Engine, 4", "en", 10)) # Prints [0, 9, 10, 19]

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

返回转换为小写的字符串。

注意:如果服务器支持FEATURE_CONTEXT_SENSITIVE_CASE_CONVERSION功能(由TextServerAdvanced支持),则外壳依赖于区域设置并且对上下文敏感。

注:结果可能比原来的长或短。


String string_to_title(string: String, language: String = "") const 🔗

返回转换为标题大小写的字符串。

注意:如果服务器支持FEATURE_CONTEXT_SENSITIVE_CASE_CONVERSION功能(由TextServerAdvanced支持),则外壳依赖于区域设置并且对上下文敏感。

注:结果可能比原来的长或短。


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

返回转换为大写的字符串。

注意:如果服务器支持FEATURE_CONTEXT_SENSITIVE_CASE_CONVERSION功能(由TextServerAdvanced支持),则外壳依赖于区域设置并且对上下文敏感。

注:结果可能比原来的长或短。


String strip_diacritics(string: String) const 🔗

从字符串中去除变音符号。

注:结果可能比原来的长或短。


String tag_to_name(tag: int) const 🔗

将OpenType标记转换为可读的功能、变体、脚本或语言名称。