Class reference
TextParagraph
Inherits RefCounted
Holds a paragraph of text.
Description
Abstraction over TextServer for handling a single paragraph of text.
Properties
int alignment = 0
int alignment = 0Paragraph horizontal alignment.
int break_flags = 3
int break_flags = 3Line breaking rules. For more info see TextServer.
String custom_punctuation = ""
String custom_punctuation = ""Custom punctuation character list, used for word breaking. If set to empty string, server defaults are used.
int direction = 0
int direction = 0Text writing direction.
String ellipsis_char = "…"
String ellipsis_char = "…"Ellipsis character used for text clipping.
int justification_flags = 163
int justification_flags = 163Line fill alignment rules.
float line_spacing = 0.0
float line_spacing = 0.0Additional vertical spacing between lines (in pixels), spacing is added to line descent. This value can be negative.
int max_lines_visible = -1
int max_lines_visible = -1Limits the lines of text shown.
int orientation = 0
int orientation = 0Text orientation.
bool preserve_control = false
bool preserve_control = falseIf set to true text will display control characters.
bool preserve_invalid = true
bool preserve_invalid = trueIf set to true text will display invalid characters.
int text_overrun_behavior = 0
int text_overrun_behavior = 0The clipping behavior when the text exceeds the paragraph's set width.
float width = -1.0
float width = -1.0Paragraph width.
Methods
bool add_object(Variant key, Vector2 size, int inline_align = 5, int length = 1, float baseline = 0.0)
bool add_object(Variant key, Vector2 size, int inline_align = 5, int length = 1, float baseline = 0.0)Adds inline object to the text buffer, key must be unique. In the text, object is represented as length object replacement characters.
bool add_string(String text, Font font, int font_size, String language = "", Variant meta = null)
bool add_string(String text, Font font, int font_size, String language = "", Variant meta = null)Adds text span and font to draw it.
void clear()
Clears text paragraph (removes text and inline objects).
void clear_dropcap()
Removes dropcap.
void draw(RID canvas, Vector2 pos, Color color = Color(1, 1, 1, 1), Color dc_color = Color(1, 1, 1, 1), float oversampling = 0.0) const
RID canvas, Vector2 pos, Color color = Color(1, 1, 1, 1), Color dc_color = Color(1, 1, 1, 1), float oversampling = 0.0) constDraw 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(RID canvas, Vector2 pos, Color color = Color(1, 1, 1, 1), float oversampling = 0.0) const
RID canvas, Vector2 pos, Color color = Color(1, 1, 1, 1), float oversampling = 0.0) constDraw 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(RID canvas, Vector2 pos, int outline_size = 1, Color color = Color(1, 1, 1, 1), float oversampling = 0.0) const
RID canvas, Vector2 pos, int outline_size = 1, Color color = Color(1, 1, 1, 1), float oversampling = 0.0) constDraw 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(RID canvas, Vector2 pos, int line, Color color = Color(1, 1, 1, 1), float oversampling = 0.0) const
RID canvas, Vector2 pos, int line, Color color = Color(1, 1, 1, 1), float oversampling = 0.0) constDraw 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(RID canvas, Vector2 pos, int line, int outline_size = 1, Color color = Color(1, 1, 1, 1), float oversampling = 0.0) const
RID canvas, Vector2 pos, int line, int outline_size = 1, Color color = Color(1, 1, 1, 1), float oversampling = 0.0) constDraw 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(RID canvas, Vector2 pos, int outline_size = 1, Color color = Color(1, 1, 1, 1), Color dc_color = Color(1, 1, 1, 1), float oversampling = 0.0) const
RID canvas, Vector2 pos, int outline_size = 1, Color color = Color(1, 1, 1, 1), Color dc_color = Color(1, 1, 1, 1), float oversampling = 0.0) constDraw 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.
int get_dropcap_lines() const
int get_dropcap_lines() constReturns number of lines used by dropcap.
RID get_dropcap_rid() const
RID get_dropcap_rid() constReturns drop cap text buffer RID.
Vector2 get_dropcap_size() const
Vector2 get_dropcap_size() constReturns drop cap bounding box size.
int get_inferred_direction() const
int get_inferred_direction() constReturns the text writing direction inferred by the BiDi algorithm.
float get_line_ascent(int line) const
float get_line_ascent(int line) constReturns the text line ascent (number of pixels above the baseline for horizontal layout or to the left of baseline for vertical).
int get_line_count() const
int get_line_count() constReturns number of lines in the paragraph.
float get_line_descent(int line) const
float get_line_descent(int line) constReturns the text line descent (number of pixels below the baseline for horizontal layout or to the right of baseline for vertical).
Rect2 get_line_object_rect(int line, Variant key) const
Rect2 get_line_object_rect(int line, Variant key) constReturns bounding rectangle of the inline object.
Array get_line_objects(int line) const
Array get_line_objects(int line) constReturns array of inline objects in the line.
Vector2i get_line_range(int line) const
Vector2i get_line_range(int line) constReturns character range of the line.
RID get_line_rid(int line) const
RID get_line_rid(int line) constReturns TextServer line buffer RID.
Vector2 get_line_size(int line) const
Vector2 get_line_size(int line) constReturns size of the bounding box of the line of text. Returned size is rounded up.
float get_line_underline_position(int line) const
float get_line_underline_position(int line) constReturns pixel offset of the underline below the baseline.
float get_line_underline_thickness(int line) const
float get_line_underline_thickness(int line) constReturns thickness of the underline.
float get_line_width(int line) const
float get_line_width(int line) constReturns width (for horizontal layout) or height (for vertical) of the line of text.
Vector2 get_non_wrapped_size() const
Vector2 get_non_wrapped_size() constReturns the size of the bounding box of the paragraph, without line breaks.
Vector2i get_range() const
Vector2i get_range() constReturns the character range of the paragraph.
RID get_rid() const
RID get_rid() constReturns TextServer full string buffer RID.
Vector2 get_size() const
Vector2 get_size() constReturns the size of the bounding box of the paragraph.
int hit_test(Vector2 coords) const
int hit_test(Vector2 coords) constReturns caret character offset at the specified coordinates. This function always returns a valid position.
bool resize_object(Variant key, Vector2 size, int inline_align = 5, float baseline = 0.0)
bool resize_object(Variant key, Vector2 size, int inline_align = 5, float baseline = 0.0)Sets new size and alignment of embedded object.
void set_bidi_override(Array override)
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.
bool set_dropcap(String text, Font font, int font_size, Rect2 dropcap_margins = Rect2(0, 0, 0, 0), String language = "")
bool set_dropcap(String text, Font font, int font_size, Rect2 dropcap_margins = Rect2(0, 0, 0, 0), String language = "")Sets drop cap, overrides previously set drop cap. Drop cap (dropped capital) is a decorative element at the beginning of a paragraph that is larger than the rest of the text.
void tab_align(PackedFloat32Array tab_stops)
PackedFloat32Array tab_stops)Aligns paragraph to the given tab-stops.