Attention: Here be dragons

This is the latest (unstable) version of this documentation, which may document features not available in or compatible with released stable versions of Godot.

TextParagraph

繼承: RefCounted < Object

持有一個文字段落。

說明

TextServer 的抽象,用於處理單個文字段落。

屬性

HorizontalAlignment

alignment

0

BitField[LineBreakFlag]

break_flags

3

String

custom_punctuation

""

Direction

direction

0

String

ellipsis_char

"…"

BitField[JustificationFlag]

justification_flags

163

float

line_spacing

0.0

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(key: Variant, size: Vector2, inline_align: InlineAlignment = 5, length: int = 1, baseline: float = 0.0)

bool

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

void

clear()

void

clear_dropcap()

void

draw(canvas: RID, pos: Vector2, color: Color = Color(1, 1, 1, 1), dc_color: Color = Color(1, 1, 1, 1), oversampling: float = 0.0) const

void

draw_dropcap(canvas: RID, pos: Vector2, color: Color = Color(1, 1, 1, 1), oversampling: float = 0.0) const

void

draw_dropcap_outline(canvas: RID, pos: Vector2, outline_size: int = 1, color: Color = Color(1, 1, 1, 1), oversampling: float = 0.0) const

void

draw_line(canvas: RID, pos: Vector2, line: int, color: Color = Color(1, 1, 1, 1), oversampling: float = 0.0) const

void

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

void

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

TextParagraph

duplicate() const

int

get_dropcap_lines() const

RID

get_dropcap_rid() const

Vector2

get_dropcap_size() const

Direction

get_inferred_direction() const

float

get_line_ascent(line: int) const

int

get_line_count() const

float

get_line_descent(line: int) const

Rect2

get_line_object_rect(line: int, key: Variant) const

Array

get_line_objects(line: int) const

Vector2i

get_line_range(line: int) const

RID

get_line_rid(line: int) const

Vector2

get_line_size(line: int) const

float

get_line_underline_position(line: int) const

float

get_line_underline_thickness(line: int) const

float

get_line_width(line: int) const

Vector2

get_non_wrapped_size() const

Vector2i

get_range() const

RID

get_rid() const

Vector2

get_size() const

bool

has_object(key: Variant) const

int

hit_test(coords: Vector2) const

bool

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

void

set_bidi_override(override: Array)

bool

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

void

tab_align(tab_stops: PackedFloat32Array)


屬性說明

HorizontalAlignment alignment = 0 🔗

段落的水平對齊。


BitField[LineBreakFlag] break_flags = 3 🔗

斷行規則。詳情見 TextServer


String custom_punctuation = "" 🔗

  • void set_custom_punctuation(value: String)

  • String get_custom_punctuation()

自訂標點字元列表,用於分詞。如果設定為空字串,則使用伺服器的預設值。


Direction direction = 0 🔗

文字書寫方向。


String ellipsis_char = "…" 🔗

  • void set_ellipsis_char(value: String)

  • String get_ellipsis_char()

Ellipsis character used for text clipping.


BitField[JustificationFlag] justification_flags = 163 🔗

Line fill alignment rules.


float line_spacing = 0.0 🔗

  • void set_line_spacing(value: float)

  • float get_line_spacing()

Additional vertical spacing between lines (in pixels), spacing is added to line descent. This value can be negative.


int max_lines_visible = -1 🔗

  • void set_max_lines_visible(value: int)

  • int get_max_lines_visible()

限制顯示文字的行數。


Orientation orientation = 0 🔗

文字朝向。


bool preserve_control = false 🔗

  • void set_preserve_control(value: bool)

  • bool get_preserve_control()

如果設定為 true,則將在文字中顯示控制字元。


bool preserve_invalid = true 🔗

  • void set_preserve_invalid(value: bool)

  • bool get_preserve_invalid()

如果設定為 true,則將在文字中顯示無效字元。


OverrunBehavior text_overrun_behavior = 0 🔗

The clipping behavior when the text exceeds the paragraph's set width.


float width = -1.0 🔗

段落寬度。


方法說明

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

向文字緩衝中新增行內物件,key 必須唯一。在文字中,物件使用 length 個物件替換字元表示。


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

新增文字區間以及用於繪製的字形。


void clear() 🔗

清空文字段落(移除文字和行內物件)。


void clear_dropcap() 🔗

移除首字下沉。


void draw(canvas: RID, pos: Vector2, color: Color = Color(1, 1, 1, 1), dc_color: Color = Color(1, 1, 1, 1), oversampling: float = 0.0) const 🔗

Draw all lines of the text and drop cap into a canvas item at a given position, with color. pos specifies the top left corner of the bounding box. If oversampling is greater than zero, it is used as font oversampling factor, otherwise viewport oversampling settings are used.


void draw_dropcap(canvas: RID, pos: Vector2, color: Color = Color(1, 1, 1, 1), oversampling: float = 0.0) const 🔗

Draw drop cap into a canvas item at a given position, with color. pos specifies the top left corner of the bounding box. If oversampling is greater than zero, it is used as font oversampling factor, otherwise viewport oversampling settings are used.


void draw_dropcap_outline(canvas: RID, pos: Vector2, outline_size: int = 1, color: Color = Color(1, 1, 1, 1), oversampling: float = 0.0) const 🔗

Draw drop cap outline into a canvas item at a given position, with color. pos specifies the top left corner of the bounding box. If oversampling is greater than zero, it is used as font oversampling factor, otherwise viewport oversampling settings are used.


void draw_line(canvas: RID, pos: Vector2, line: int, color: Color = Color(1, 1, 1, 1), oversampling: float = 0.0) const 🔗

Draw single line of text into a canvas item at a given position, with color. pos specifies the top left corner of the bounding box. If oversampling is greater than zero, it is used as font oversampling factor, otherwise viewport oversampling settings are used.


void draw_line_outline(canvas: RID, pos: Vector2, line: int, outline_size: int = 1, color: Color = Color(1, 1, 1, 1), oversampling: float = 0.0) const 🔗

Draw outline of the single line of text into a canvas item at a given position, with color. pos specifies the top left corner of the bounding box. If oversampling is greater than zero, it is used as font oversampling factor, otherwise viewport oversampling settings are used.


void draw_outline(canvas: RID, pos: Vector2, outline_size: int = 1, color: Color = Color(1, 1, 1, 1), dc_color: Color = Color(1, 1, 1, 1), oversampling: float = 0.0) const 🔗

Draw outlines of all lines of the text and drop cap into a canvas item at a given position, with color. pos specifies the top left corner of the bounding box. If oversampling is greater than zero, it is used as font oversampling factor, otherwise viewport oversampling settings are used.


TextParagraph duplicate() const 🔗

Duplicates this TextParagraph.


int get_dropcap_lines() const 🔗

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


RID get_dropcap_rid() const 🔗

返回首字下沉文字緩衝 RID。


Vector2 get_dropcap_size() const 🔗

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


Direction get_inferred_direction() const 🔗

Returns the text writing direction inferred by the BiDi algorithm.


float get_line_ascent(line: int) const 🔗

返回文字行上高(對於水平佈局,為基線上方的圖元數;或對於垂直佈局,基線左側的圖元數)。


int get_line_count() const 🔗

返回段落中的行數。


float get_line_descent(line: int) const 🔗

返回文字行下深(對於水平佈局,為基線下方的圖元數;或對於垂直佈局,基線右側的圖元數)。


Rect2 get_line_object_rect(line: int, key: Variant) const 🔗

返回行內對象的邊界矩形。


Array get_line_objects(line: int) const 🔗

返回某行中行內物件的陣列。


Vector2i get_line_range(line: int) const 🔗

返回某行中的字元範圍。


RID get_line_rid(line: int) const 🔗

返回 TextServer 行緩衝 RID。


Vector2 get_line_size(line: int) const 🔗

Returns size of the bounding box of the line of text. Returned size is rounded up.


float get_line_underline_position(line: int) const 🔗

返回基線下方底線的圖元偏移。


float get_line_underline_thickness(line: int) const 🔗

返回底線的粗細度。


float get_line_width(line: int) const 🔗

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


Vector2 get_non_wrapped_size() const 🔗

返回段落邊界框的大小,不帶分行符號。


Vector2i get_range() const 🔗

Returns the character range of the paragraph.


RID get_rid() const 🔗

返回 TextServer 完整字串緩衝區的 RID。


Vector2 get_size() const 🔗

返回段落邊界框的大小。


bool has_object(key: Variant) const 🔗

Returns true if an object with key is embedded in this shaped text buffer.


int hit_test(coords: Vector2) const 🔗

返回指定座標處的文字游標的偏移量。該函式始終返回一個有效位置。


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

設定內嵌物件的新大小和對齊方式。


void set_bidi_override(override: Array) 🔗

覆蓋用於結構化文字的 BiDi。

覆蓋範圍應覆蓋完整的源文字而沒有重疊。BiDi 演算法將分別被用於每個範圍。


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

設定首字下沉,會覆蓋之前設定的首字下沉。首字下沉是段落開頭的裝飾元素,比文字的其餘部分大。


void tab_align(tab_stops: PackedFloat32Array) 🔗

將段落與給定的定位停駐點對齊。