| 1 | /**************************************************************************/ |
| 2 | /* text_paragraph.h */ |
| 3 | /**************************************************************************/ |
| 4 | /* This file is part of: */ |
| 5 | /* GODOT ENGINE */ |
| 6 | /* https://godotengine.org */ |
| 7 | /**************************************************************************/ |
| 8 | /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */ |
| 9 | /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ |
| 10 | /* */ |
| 11 | /* Permission is hereby granted, free of charge, to any person obtaining */ |
| 12 | /* a copy of this software and associated documentation files (the */ |
| 13 | /* "Software"), to deal in the Software without restriction, including */ |
| 14 | /* without limitation the rights to use, copy, modify, merge, publish, */ |
| 15 | /* distribute, sublicense, and/or sell copies of the Software, and to */ |
| 16 | /* permit persons to whom the Software is furnished to do so, subject to */ |
| 17 | /* the following conditions: */ |
| 18 | /* */ |
| 19 | /* The above copyright notice and this permission notice shall be */ |
| 20 | /* included in all copies or substantial portions of the Software. */ |
| 21 | /* */ |
| 22 | /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ |
| 23 | /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ |
| 24 | /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */ |
| 25 | /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ |
| 26 | /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ |
| 27 | /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ |
| 28 | /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ |
| 29 | /**************************************************************************/ |
| 30 | |
| 31 | #ifndef TEXT_PARAGRAPH_H |
| 32 | #define TEXT_PARAGRAPH_H |
| 33 | |
| 34 | #include "core/templates/local_vector.h" |
| 35 | #include "scene/resources/font.h" |
| 36 | #include "servers/text_server.h" |
| 37 | |
| 38 | /*************************************************************************/ |
| 39 | |
| 40 | class TextParagraph : public RefCounted { |
| 41 | GDCLASS(TextParagraph, RefCounted); |
| 42 | _THREAD_SAFE_CLASS_ |
| 43 | |
| 44 | private: |
| 45 | RID dropcap_rid; |
| 46 | int dropcap_lines = 0; |
| 47 | Rect2 dropcap_margins; |
| 48 | |
| 49 | RID rid; |
| 50 | LocalVector<RID> lines_rid; |
| 51 | |
| 52 | bool lines_dirty = true; |
| 53 | |
| 54 | float width = -1.0; |
| 55 | int max_lines_visible = -1; |
| 56 | |
| 57 | BitField<TextServer::LineBreakFlag> brk_flags = TextServer::BREAK_MANDATORY | TextServer::BREAK_WORD_BOUND; |
| 58 | BitField<TextServer::JustificationFlag> jst_flags = TextServer::JUSTIFICATION_WORD_BOUND | TextServer::JUSTIFICATION_KASHIDA | TextServer::JUSTIFICATION_SKIP_LAST_LINE | TextServer::JUSTIFICATION_DO_NOT_SKIP_SINGLE_LINE; |
| 59 | TextServer::OverrunBehavior overrun_behavior = TextServer::OVERRUN_NO_TRIMMING; |
| 60 | |
| 61 | HorizontalAlignment alignment = HORIZONTAL_ALIGNMENT_LEFT; |
| 62 | |
| 63 | Vector<float> tab_stops; |
| 64 | |
| 65 | protected: |
| 66 | static void _bind_methods(); |
| 67 | |
| 68 | void _shape_lines(); |
| 69 | |
| 70 | public: |
| 71 | RID get_rid() const; |
| 72 | RID get_line_rid(int p_line) const; |
| 73 | RID get_dropcap_rid() const; |
| 74 | |
| 75 | void clear(); |
| 76 | |
| 77 | void set_direction(TextServer::Direction p_direction); |
| 78 | TextServer::Direction get_direction() const; |
| 79 | |
| 80 | void set_orientation(TextServer::Orientation p_orientation); |
| 81 | TextServer::Orientation get_orientation() const; |
| 82 | |
| 83 | void set_preserve_invalid(bool p_enabled); |
| 84 | bool get_preserve_invalid() const; |
| 85 | |
| 86 | void set_preserve_control(bool p_enabled); |
| 87 | bool get_preserve_control() const; |
| 88 | |
| 89 | void set_bidi_override(const Array &p_override); |
| 90 | |
| 91 | void set_custom_punctuation(const String &p_punct); |
| 92 | String get_custom_punctuation() const; |
| 93 | |
| 94 | 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 = "" ); |
| 95 | void clear_dropcap(); |
| 96 | |
| 97 | 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()); |
| 98 | 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); |
| 99 | bool resize_object(Variant p_key, const Size2 &p_size, InlineAlignment p_inline_align = INLINE_ALIGNMENT_CENTER, float p_baseline = 0.0); |
| 100 | |
| 101 | void set_alignment(HorizontalAlignment p_alignment); |
| 102 | HorizontalAlignment get_alignment() const; |
| 103 | |
| 104 | void tab_align(const Vector<float> &p_tab_stops); |
| 105 | |
| 106 | void set_justification_flags(BitField<TextServer::JustificationFlag> p_flags); |
| 107 | BitField<TextServer::JustificationFlag> get_justification_flags() const; |
| 108 | |
| 109 | void set_break_flags(BitField<TextServer::LineBreakFlag> p_flags); |
| 110 | BitField<TextServer::LineBreakFlag> get_break_flags() const; |
| 111 | |
| 112 | void set_text_overrun_behavior(TextServer::OverrunBehavior p_behavior); |
| 113 | TextServer::OverrunBehavior get_text_overrun_behavior() const; |
| 114 | |
| 115 | void set_width(float p_width); |
| 116 | float get_width() const; |
| 117 | |
| 118 | void set_max_lines_visible(int p_lines); |
| 119 | int get_max_lines_visible() const; |
| 120 | |
| 121 | Size2 get_non_wrapped_size() const; |
| 122 | |
| 123 | Size2 get_size() const; |
| 124 | |
| 125 | int get_line_count() const; |
| 126 | |
| 127 | Array get_line_objects(int p_line) const; |
| 128 | Rect2 get_line_object_rect(int p_line, Variant p_key) const; |
| 129 | Size2 get_line_size(int p_line) const; |
| 130 | float get_line_ascent(int p_line) const; |
| 131 | float get_line_descent(int p_line) const; |
| 132 | float get_line_width(int p_line) const; |
| 133 | Vector2i get_line_range(int p_line) const; |
| 134 | float get_line_underline_position(int p_line) const; |
| 135 | float get_line_underline_thickness(int p_line) const; |
| 136 | |
| 137 | int get_spacing_top() const; |
| 138 | int get_spacing_bottom() const; |
| 139 | |
| 140 | Size2 get_dropcap_size() const; |
| 141 | int get_dropcap_lines() const; |
| 142 | |
| 143 | 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; |
| 144 | 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; |
| 145 | |
| 146 | void draw_line(RID p_canvas, const Vector2 &p_pos, int p_line, const Color &p_color = Color(1, 1, 1)) const; |
| 147 | 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; |
| 148 | |
| 149 | void draw_dropcap(RID p_canvas, const Vector2 &p_pos, const Color &p_color = Color(1, 1, 1)) const; |
| 150 | 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; |
| 151 | |
| 152 | int hit_test(const Point2 &p_coords) const; |
| 153 | |
| 154 | Mutex &get_mutex() const { return _thread_safe_; }; |
| 155 | |
| 156 | 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); |
| 157 | TextParagraph(); |
| 158 | ~TextParagraph(); |
| 159 | }; |
| 160 | |
| 161 | #endif // TEXT_PARAGRAPH_H |
| 162 | |