| 
									
										
										
										
											2023-01-05 13:25:55 +01:00
										 |  |  | /**************************************************************************/ | 
					
						
							|  |  |  | /*  text_paragraph.h                                                      */ | 
					
						
							|  |  |  | /**************************************************************************/ | 
					
						
							|  |  |  | /*                         This file is part of:                          */ | 
					
						
							|  |  |  | /*                             GODOT ENGINE                               */ | 
					
						
							|  |  |  | /*                        https://godotengine.org                         */ | 
					
						
							|  |  |  | /**************************************************************************/ | 
					
						
							|  |  |  | /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */ | 
					
						
							|  |  |  | /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur.                  */ | 
					
						
							|  |  |  | /*                                                                        */ | 
					
						
							|  |  |  | /* Permission is hereby granted, free of charge, to any person obtaining  */ | 
					
						
							|  |  |  | /* a copy of this software and associated documentation files (the        */ | 
					
						
							|  |  |  | /* "Software"), to deal in the Software without restriction, including    */ | 
					
						
							|  |  |  | /* without limitation the rights to use, copy, modify, merge, publish,    */ | 
					
						
							|  |  |  | /* distribute, sublicense, and/or sell copies of the Software, and to     */ | 
					
						
							|  |  |  | /* permit persons to whom the Software is furnished to do so, subject to  */ | 
					
						
							|  |  |  | /* the following conditions:                                              */ | 
					
						
							|  |  |  | /*                                                                        */ | 
					
						
							|  |  |  | /* The above copyright notice and this permission notice shall be         */ | 
					
						
							|  |  |  | /* included in all copies or substantial portions of the Software.        */ | 
					
						
							|  |  |  | /*                                                                        */ | 
					
						
							|  |  |  | /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,        */ | 
					
						
							|  |  |  | /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF     */ | 
					
						
							|  |  |  | /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */ | 
					
						
							|  |  |  | /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY   */ | 
					
						
							|  |  |  | /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,   */ | 
					
						
							|  |  |  | /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE      */ | 
					
						
							|  |  |  | /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.                 */ | 
					
						
							|  |  |  | /**************************************************************************/ | 
					
						
							| 
									
										
										
										
											2020-09-03 14:22:16 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | #ifndef TEXT_PARAGRAPH_H
 | 
					
						
							|  |  |  | #define TEXT_PARAGRAPH_H
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-05-18 10:17:55 +03:00
										 |  |  | #include "core/templates/local_vector.h"
 | 
					
						
							| 
									
										
										
										
											2020-09-03 14:22:16 +03:00
										 |  |  | #include "scene/resources/font.h"
 | 
					
						
							|  |  |  | #include "servers/text_server.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /*************************************************************************/ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-06-04 18:03:15 +02:00
										 |  |  | class TextParagraph : public RefCounted { | 
					
						
							|  |  |  | 	GDCLASS(TextParagraph, RefCounted); | 
					
						
							| 
									
										
										
										
											2022-05-18 10:17:55 +03:00
										 |  |  | 	_THREAD_SAFE_CLASS_ | 
					
						
							| 
									
										
										
										
											2020-09-03 14:22:16 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-08-11 00:09:48 +02:00
										 |  |  | private: | 
					
						
							| 
									
										
										
										
											2024-07-29 21:23:12 -07:00
										 |  |  | 	mutable RID dropcap_rid; | 
					
						
							|  |  |  | 	mutable int dropcap_lines = 0; | 
					
						
							| 
									
										
										
										
											2020-11-19 16:45:23 +02:00
										 |  |  | 	Rect2 dropcap_margins; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-03 14:22:16 +03:00
										 |  |  | 	RID rid; | 
					
						
							| 
									
										
										
										
											2024-07-29 21:23:12 -07:00
										 |  |  | 	mutable LocalVector<RID> lines_rid; | 
					
						
							| 
									
										
										
										
											2020-09-03 14:22:16 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-07-29 21:23:12 -07:00
										 |  |  | 	mutable bool lines_dirty = true; | 
					
						
							| 
									
										
										
										
											2020-09-03 14:22:16 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-10-09 19:41:03 +03:00
										 |  |  | 	float line_spacing = 0.0; | 
					
						
							| 
									
										
										
										
											2021-02-09 18:24:36 +01:00
										 |  |  | 	float width = -1.0; | 
					
						
							| 
									
										
										
										
											2021-08-11 00:09:48 +02:00
										 |  |  | 	int max_lines_visible = -1; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-07-11 12:40:31 +03:00
										 |  |  | 	BitField<TextServer::LineBreakFlag> brk_flags = TextServer::BREAK_MANDATORY | TextServer::BREAK_WORD_BOUND; | 
					
						
							| 
									
										
										
										
											2023-03-23 11:22:37 +02:00
										 |  |  | 	BitField<TextServer::JustificationFlag> jst_flags = TextServer::JUSTIFICATION_WORD_BOUND | TextServer::JUSTIFICATION_KASHIDA | TextServer::JUSTIFICATION_SKIP_LAST_LINE | TextServer::JUSTIFICATION_DO_NOT_SKIP_SINGLE_LINE; | 
					
						
							| 
									
										
										
										
											2023-10-01 13:39:13 +03:00
										 |  |  | 	String el_char = U"…"; | 
					
						
							| 
									
										
										
										
											2022-06-15 11:01:45 +03:00
										 |  |  | 	TextServer::OverrunBehavior overrun_behavior = TextServer::OVERRUN_NO_TRIMMING; | 
					
						
							| 
									
										
										
										
											2021-08-11 00:09:48 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-11-24 20:58:47 -06:00
										 |  |  | 	HorizontalAlignment alignment = HORIZONTAL_ALIGNMENT_LEFT; | 
					
						
							| 
									
										
										
										
											2020-09-03 14:22:16 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	Vector<float> tab_stops; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | protected: | 
					
						
							|  |  |  | 	static void _bind_methods(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-07-29 21:23:12 -07:00
										 |  |  | 	void _shape_lines() const; | 
					
						
							| 
									
										
										
										
											2020-09-03 14:22:16 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | public: | 
					
						
							|  |  |  | 	RID get_rid() const; | 
					
						
							|  |  |  | 	RID get_line_rid(int p_line) const; | 
					
						
							| 
									
										
										
										
											2020-11-19 16:45:23 +02:00
										 |  |  | 	RID get_dropcap_rid() const; | 
					
						
							| 
									
										
										
										
											2020-09-03 14:22:16 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	void clear(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	void set_direction(TextServer::Direction p_direction); | 
					
						
							|  |  |  | 	TextServer::Direction get_direction() const; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	void set_orientation(TextServer::Orientation p_orientation); | 
					
						
							|  |  |  | 	TextServer::Orientation get_orientation() const; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	void set_preserve_invalid(bool p_enabled); | 
					
						
							|  |  |  | 	bool get_preserve_invalid() const; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	void set_preserve_control(bool p_enabled); | 
					
						
							|  |  |  | 	bool get_preserve_control() const; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-08-28 00:19:51 +03:00
										 |  |  | 	void set_bidi_override(const Array &p_override); | 
					
						
							| 
									
										
										
										
											2020-09-03 14:22:16 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-03-06 11:52:16 +02:00
										 |  |  | 	void set_custom_punctuation(const String &p_punct); | 
					
						
							|  |  |  | 	String get_custom_punctuation() const; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-05-09 12:47:10 +03:00
										 |  |  | 	bool set_dropcap(const String &p_text, const Ref<Font> &p_font, int p_font_size, const Rect2 &p_dropcap_margins = Rect2(), const String &p_language = ""); | 
					
						
							| 
									
										
										
										
											2020-11-19 16:45:23 +02:00
										 |  |  | 	void clear_dropcap(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-05-09 12:47:10 +03:00
										 |  |  | 	bool add_string(const String &p_text, const Ref<Font> &p_font, int p_font_size, const String &p_language = "", const Variant &p_meta = Variant()); | 
					
						
							| 
									
										
										
										
											2022-12-08 22:01:07 +02:00
										 |  |  | 	bool add_object(Variant p_key, const Size2 &p_size, InlineAlignment p_inline_align = INLINE_ALIGNMENT_CENTER, int p_length = 1, float p_baseline = 0.0); | 
					
						
							|  |  |  | 	bool resize_object(Variant p_key, const Size2 &p_size, InlineAlignment p_inline_align = INLINE_ALIGNMENT_CENTER, float p_baseline = 0.0); | 
					
						
							| 
									
										
										
										
											2020-09-03 14:22:16 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-11-24 20:58:47 -06:00
										 |  |  | 	void set_alignment(HorizontalAlignment p_alignment); | 
					
						
							|  |  |  | 	HorizontalAlignment get_alignment() const; | 
					
						
							| 
									
										
										
										
											2020-09-03 14:22:16 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	void tab_align(const Vector<float> &p_tab_stops); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-07-11 12:40:31 +03:00
										 |  |  | 	void set_justification_flags(BitField<TextServer::JustificationFlag> p_flags); | 
					
						
							|  |  |  | 	BitField<TextServer::JustificationFlag> get_justification_flags() const; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	void set_break_flags(BitField<TextServer::LineBreakFlag> p_flags); | 
					
						
							|  |  |  | 	BitField<TextServer::LineBreakFlag> get_break_flags() const; | 
					
						
							| 
									
										
										
										
											2020-09-03 14:22:16 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-06-15 11:01:45 +03:00
										 |  |  | 	void set_text_overrun_behavior(TextServer::OverrunBehavior p_behavior); | 
					
						
							|  |  |  | 	TextServer::OverrunBehavior get_text_overrun_behavior() const; | 
					
						
							| 
									
										
										
										
											2021-08-11 00:09:48 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-10-01 13:39:13 +03:00
										 |  |  | 	void set_ellipsis_char(const String &p_char); | 
					
						
							|  |  |  | 	String get_ellipsis_char() const; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-03 14:22:16 +03:00
										 |  |  | 	void set_width(float p_width); | 
					
						
							|  |  |  | 	float get_width() const; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-08-11 00:09:48 +02:00
										 |  |  | 	void set_max_lines_visible(int p_lines); | 
					
						
							|  |  |  | 	int get_max_lines_visible() const; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-10-09 19:41:03 +03:00
										 |  |  | 	void set_line_spacing(float p_spacing); | 
					
						
							|  |  |  | 	float get_line_spacing() const; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-10-19 16:38:58 -03:00
										 |  |  | 	Size2 get_non_wrapped_size() const; | 
					
						
							| 
									
										
										
										
											2020-09-03 14:22:16 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	Size2 get_size() const; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	int get_line_count() const; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	Array get_line_objects(int p_line) const; | 
					
						
							|  |  |  | 	Rect2 get_line_object_rect(int p_line, Variant p_key) const; | 
					
						
							|  |  |  | 	Size2 get_line_size(int p_line) const; | 
					
						
							|  |  |  | 	float get_line_ascent(int p_line) const; | 
					
						
							|  |  |  | 	float get_line_descent(int p_line) const; | 
					
						
							|  |  |  | 	float get_line_width(int p_line) const; | 
					
						
							|  |  |  | 	Vector2i get_line_range(int p_line) const; | 
					
						
							|  |  |  | 	float get_line_underline_position(int p_line) const; | 
					
						
							|  |  |  | 	float get_line_underline_thickness(int p_line) const; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-11-19 16:45:23 +02:00
										 |  |  | 	Size2 get_dropcap_size() const; | 
					
						
							|  |  |  | 	int get_dropcap_lines() const; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	void draw(RID p_canvas, const Vector2 &p_pos, const Color &p_color = Color(1, 1, 1), const Color &p_dc_color = Color(1, 1, 1)) const; | 
					
						
							|  |  |  | 	void draw_outline(RID p_canvas, const Vector2 &p_pos, int p_outline_size = 1, const Color &p_color = Color(1, 1, 1), const Color &p_dc_color = Color(1, 1, 1)) const; | 
					
						
							| 
									
										
										
										
											2020-09-03 14:22:16 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	void draw_line(RID p_canvas, const Vector2 &p_pos, int p_line, const Color &p_color = Color(1, 1, 1)) const; | 
					
						
							|  |  |  | 	void draw_line_outline(RID p_canvas, const Vector2 &p_pos, int p_line, int p_outline_size = 1, const Color &p_color = Color(1, 1, 1)) const; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-11-19 16:45:23 +02:00
										 |  |  | 	void draw_dropcap(RID p_canvas, const Vector2 &p_pos, const Color &p_color = Color(1, 1, 1)) const; | 
					
						
							|  |  |  | 	void draw_dropcap_outline(RID p_canvas, const Vector2 &p_pos, int p_outline_size = 1, const Color &p_color = Color(1, 1, 1)) const; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-03 14:22:16 +03:00
										 |  |  | 	int hit_test(const Point2 &p_coords) const; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-11-07 03:28:08 +08:00
										 |  |  | 	bool is_dirty(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-10-07 10:57:21 -04:00
										 |  |  | 	Mutex &get_mutex() const { return _thread_safe_; } | 
					
						
							| 
									
										
										
										
											2022-05-18 10:17:55 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-05-09 12:47:10 +03:00
										 |  |  | 	TextParagraph(const String &p_text, const Ref<Font> &p_font, int p_font_size, const String &p_language = "", float p_width = -1.f, TextServer::Direction p_direction = TextServer::DIRECTION_AUTO, TextServer::Orientation p_orientation = TextServer::ORIENTATION_HORIZONTAL); | 
					
						
							| 
									
										
										
										
											2020-09-03 14:22:16 +03:00
										 |  |  | 	TextParagraph(); | 
					
						
							|  |  |  | 	~TextParagraph(); | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #endif // TEXT_PARAGRAPH_H
 |