Up to date

This page is up to date for Godot 4.2. If you still find outdated information, please open an issue.

TextParagraph

继承: RefCounted < Object

持有一个文本段落。

描述

TextServer 的抽象,用于处理单个文本段落。

属性

HorizontalAlignment

alignment

0

BitField<LineBreakFlag>

break_flags

3

String

custom_punctuation

""

Direction

direction

0

BitField<JustificationFlag>

justification_flags

163

int

max_lines_visible

-1

Orientation

orientation

0

bool

preserve_control

false

bool

preserve_invalid

true

OverrunBehavior

text_overrun_behavior

0

float

width

-1.0

方法

bool

add_object ( Variant key, Vector2 size, InlineAlignment inline_align=5, int length=1, float baseline=0.0 )

bool

add_string ( String text, Font font, int font_size, String language="", Variant meta=null )

void

clear ( )

void

clear_dropcap ( )

void

draw ( RID canvas, Vector2 pos, Color color=Color(1, 1, 1, 1), Color dc_color=Color(1, 1, 1, 1) ) const

void

draw_dropcap ( RID canvas, Vector2 pos, Color color=Color(1, 1, 1, 1) ) const

void

draw_dropcap_outline ( RID canvas, Vector2 pos, int outline_size=1, Color color=Color(1, 1, 1, 1) ) const

void

draw_line ( RID canvas, Vector2 pos, int line, Color color=Color(1, 1, 1, 1) ) const

void

draw_line_outline ( RID canvas, Vector2 pos, int line, int outline_size=1, Color color=Color(1, 1, 1, 1) ) const

void

draw_outline ( RID canvas, Vector2 pos, int outline_size=1, Color color=Color(1, 1, 1, 1), Color dc_color=Color(1, 1, 1, 1) ) const

int

get_dropcap_lines ( ) const

RID

get_dropcap_rid ( ) const

Vector2

get_dropcap_size ( ) const

float

get_line_ascent ( int line ) const

int

get_line_count ( ) const

float

get_line_descent ( int line ) const

Rect2

get_line_object_rect ( int line, Variant key ) const

Array

get_line_objects ( int line ) const

Vector2i

get_line_range ( int line ) const

RID

get_line_rid ( int line ) const

Vector2

get_line_size ( int line ) const

float

get_line_underline_position ( int line ) const

float

get_line_underline_thickness ( int line ) const

float

get_line_width ( int line ) const

Vector2

get_non_wrapped_size ( ) const

RID

get_rid ( ) const

Vector2

get_size ( ) const

int

hit_test ( Vector2 coords ) const

bool

resize_object ( Variant key, Vector2 size, InlineAlignment inline_align=5, float baseline=0.0 )

void

set_bidi_override ( Array override )

bool

set_dropcap ( String text, Font font, int font_size, Rect2 dropcap_margins=Rect2(0, 0, 0, 0), String language="" )

void

tab_align ( PackedFloat32Array tab_stops )


属性说明

HorizontalAlignment alignment = 0

段落的水平对齐。


BitField<LineBreakFlag> break_flags = 3

断行规则。详情见 TextServer


String custom_punctuation = ""

  • void set_custom_punctuation ( String value )

  • String get_custom_punctuation ( )

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


Direction direction = 0

文本书写方向。


BitField<JustificationFlag> justification_flags = 163

行两端对齐规则。详见 JustificationFlag


int max_lines_visible = -1

  • void set_max_lines_visible ( int value )

  • int get_max_lines_visible ( )

限制显示文本的行数。


Orientation orientation = 0

文本朝向。


bool preserve_control = false

  • void set_preserve_control ( bool value )

  • bool get_preserve_control ( )

如果设置为 true,则将在文本中显示控制字符。


bool preserve_invalid = true

  • void set_preserve_invalid ( bool value )

  • bool get_preserve_invalid ( )

如果设置为 true,则将在文本中显示无效字符。


OverrunBehavior text_overrun_behavior = 0

设置当文本超过段落的设置宽度时的裁剪行为。有关所有模式的描述,请参阅 OverrunBehavior


float width = -1.0

  • void set_width ( float value )

  • float get_width ( )

段落宽度。


方法说明

bool add_object ( Variant key, Vector2 size, InlineAlignment inline_align=5, int length=1, float baseline=0.0 )

向文本缓冲中添加内联对象,key 必须唯一。在文本中,对象使用 length 个对象替换字符表示。


bool add_string ( String text, Font font, int font_size, String language="", Variant meta=null )

添加文本区间以及用于绘制的字体。


void clear ( )

清空文本段落(移除文本和内联对象)。


void clear_dropcap ( )

移除首字下沉。


void draw ( RID canvas, Vector2 pos, Color color=Color(1, 1, 1, 1), Color dc_color=Color(1, 1, 1, 1) ) const

在画布项中的给定位置绘制文本中所有行和首字下沉,颜色为 colorpos 指定的是边界框的左上角。


void draw_dropcap ( RID canvas, Vector2 pos, Color color=Color(1, 1, 1, 1) ) const

在画布项中的给定位置绘制首字下沉,颜色为 colorpos 指定的是边界框的左上角。


void draw_dropcap_outline ( RID canvas, Vector2 pos, int outline_size=1, Color color=Color(1, 1, 1, 1) ) const

在画布项中的给定位置绘制首字下沉的轮廓,颜色为 colorpos 指定的是边界框的左上角。


void draw_line ( RID canvas, Vector2 pos, int line, Color color=Color(1, 1, 1, 1) ) const

在画布项中的给定位置绘制一行文本,颜色为 colorpos 指定的是边界框的左上角。


void draw_line_outline ( RID canvas, Vector2 pos, int line, int outline_size=1, Color color=Color(1, 1, 1, 1) ) const

在画布项中的给定位置绘制一行文本的轮廓,颜色为 colorpos 指定的是边界框的左上角。


void draw_outline ( RID canvas, Vector2 pos, int outline_size=1, Color color=Color(1, 1, 1, 1), Color dc_color=Color(1, 1, 1, 1) ) const

在画布项中的给定位置绘制文本中所有行和首字下沉的轮廓,颜色为 colorpos 指定的是边界框的左上角。


int get_dropcap_lines ( ) const

返回首字下沉使用的行数。


RID get_dropcap_rid ( ) const

返回首字下沉文本缓冲 RID。


Vector2 get_dropcap_size ( ) const

返回首字下沉边界框大小。


float get_line_ascent ( int line ) const

返回文本行上高(对于水平布局,为基线上方的像素数;或对于垂直布局,基线左侧的像素数)。


int get_line_count ( ) const

返回段落中的行数。


float get_line_descent ( int line ) const

返回文本行下深(对于水平布局,为基线下方的像素数;或对于垂直布局,基线右侧的像素数)。


Rect2 get_line_object_rect ( int line, Variant key ) const

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


Array get_line_objects ( int line ) const

返回某行中内联对象的数组。


Vector2i get_line_range ( int line ) const

返回某行中的字符范围。


RID get_line_rid ( int line ) const

返回 TextServer 行缓冲 RID。


Vector2 get_line_size ( int line ) const

返回文本行边界框的大小。


float get_line_underline_position ( int line ) const

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


float get_line_underline_thickness ( int line ) const

返回下划线的粗细度。


float get_line_width ( int line ) const

返回文本行的宽度(水平排版)或高度(垂直排版)。


Vector2 get_non_wrapped_size ( ) const

返回段落边界框的大小,不带换行符。


RID get_rid ( ) const

返回 TextServer 完整字符串缓冲区的 RID。


Vector2 get_size ( ) const

返回段落边界框的大小。


int hit_test ( Vector2 coords ) const

返回指定坐标处的文本光标的偏移量。该函数始终返回一个有效位置。


bool resize_object ( Variant key, Vector2 size, InlineAlignment inline_align=5, float baseline=0.0 )

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


void set_bidi_override ( Array override )

覆盖用于结构化文本的 BiDi。

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


bool set_dropcap ( String text, Font font, int font_size, Rect2 dropcap_margins=Rect2(0, 0, 0, 0), String language="" )

设置首字下沉,会覆盖之前设置的首字下沉。首字下沉是段落开头的装饰元素,比文本的其余部分大。


void tab_align ( PackedFloat32Array tab_stops )

将段落与给定的制表位对齐。