| 1 | /**************************************************************************/ |
| 2 | /* text_server.cpp */ |
| 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 | #include "text_server.h" |
| 32 | #include "text_server.compat.inc" |
| 33 | |
| 34 | #include "core/config/project_settings.h" |
| 35 | #include "core/os/main_loop.h" |
| 36 | #include "core/variant/typed_array.h" |
| 37 | #include "servers/rendering/rendering_server.h" |
| 38 | |
| 39 | #ifndef DISABLE_DEPRECATED |
| 40 | #include "core/string/translation_server.h" |
| 41 | #endif // DISABLE_DEPRECATED |
| 42 | |
| 43 | TextServerManager *TextServerManager::singleton = nullptr; |
| 44 | |
| 45 | void TextServerManager::_bind_methods() { |
| 46 | ClassDB::bind_method(D_METHOD("add_interface", "interface"), &TextServerManager::add_interface); |
| 47 | ClassDB::bind_method(D_METHOD("get_interface_count"), &TextServerManager::get_interface_count); |
| 48 | ClassDB::bind_method(D_METHOD("remove_interface", "interface"), &TextServerManager::remove_interface); |
| 49 | ClassDB::bind_method(D_METHOD("get_interface", "idx"), &TextServerManager::get_interface); |
| 50 | ClassDB::bind_method(D_METHOD("get_interfaces"), &TextServerManager::get_interfaces); |
| 51 | ClassDB::bind_method(D_METHOD("find_interface", "name"), &TextServerManager::find_interface); |
| 52 | |
| 53 | ClassDB::bind_method(D_METHOD("set_primary_interface", "index"), &TextServerManager::set_primary_interface); |
| 54 | ClassDB::bind_method(D_METHOD("get_primary_interface"), &TextServerManager::get_primary_interface); |
| 55 | |
| 56 | ADD_SIGNAL(MethodInfo("interface_added", PropertyInfo(Variant::STRING_NAME, "interface_name"))); |
| 57 | ADD_SIGNAL(MethodInfo("interface_removed", PropertyInfo(Variant::STRING_NAME, "interface_name"))); |
| 58 | } |
| 59 | |
| 60 | void TextServerManager::add_interface(const Ref<TextServer> &p_interface) { |
| 61 | ERR_FAIL_COND(p_interface.is_null()); |
| 62 | |
| 63 | for (int i = 0; i < interfaces.size(); i++) { |
| 64 | if (interfaces[i] == p_interface) { |
| 65 | ERR_PRINT("TextServer: Interface was already added."); |
| 66 | return; |
| 67 | }; |
| 68 | }; |
| 69 | |
| 70 | interfaces.push_back(p_interface); |
| 71 | print_verbose("TextServer: Added interface \"" + p_interface->get_name() + "\""); |
| 72 | emit_signal(SNAME("interface_added"), p_interface->get_name()); |
| 73 | } |
| 74 | |
| 75 | void TextServerManager::remove_interface(const Ref<TextServer> &p_interface) { |
| 76 | ERR_FAIL_COND(p_interface.is_null()); |
| 77 | ERR_FAIL_COND_MSG(p_interface == primary_interface, "TextServer: Can't remove primary interface."); |
| 78 | |
| 79 | int idx = -1; |
| 80 | for (int i = 0; i < interfaces.size(); i++) { |
| 81 | if (interfaces[i] == p_interface) { |
| 82 | idx = i; |
| 83 | break; |
| 84 | }; |
| 85 | }; |
| 86 | |
| 87 | ERR_FAIL_COND_MSG(idx == -1, "Interface not found."); |
| 88 | print_verbose("TextServer: Removed interface \"" + p_interface->get_name() + "\""); |
| 89 | emit_signal(SNAME("interface_removed"), p_interface->get_name()); |
| 90 | interfaces.remove_at(idx); |
| 91 | } |
| 92 | |
| 93 | int TextServerManager::get_interface_count() const { |
| 94 | return interfaces.size(); |
| 95 | } |
| 96 | |
| 97 | Ref<TextServer> TextServerManager::get_interface(int p_index) const { |
| 98 | ERR_FAIL_INDEX_V(p_index, interfaces.size(), nullptr); |
| 99 | return interfaces[p_index]; |
| 100 | } |
| 101 | |
| 102 | Ref<TextServer> TextServerManager::find_interface(const String &p_name) const { |
| 103 | int idx = -1; |
| 104 | for (int i = 0; i < interfaces.size(); i++) { |
| 105 | if (interfaces[i]->get_name() == p_name) { |
| 106 | idx = i; |
| 107 | break; |
| 108 | }; |
| 109 | }; |
| 110 | |
| 111 | ERR_FAIL_COND_V_MSG(idx == -1, nullptr, "Interface not found."); |
| 112 | return interfaces[idx]; |
| 113 | } |
| 114 | |
| 115 | TypedArray<Dictionary> TextServerManager::get_interfaces() const { |
| 116 | TypedArray<Dictionary> ret; |
| 117 | |
| 118 | for (int i = 0; i < interfaces.size(); i++) { |
| 119 | Dictionary iface_info; |
| 120 | |
| 121 | iface_info["id"] = i; |
| 122 | iface_info["name"] = interfaces[i]->get_name(); |
| 123 | |
| 124 | ret.push_back(iface_info); |
| 125 | }; |
| 126 | |
| 127 | return ret; |
| 128 | } |
| 129 | |
| 130 | void TextServerManager::set_primary_interface(const Ref<TextServer> &p_primary_interface) { |
| 131 | if (p_primary_interface.is_null()) { |
| 132 | print_verbose("TextServer: Clearing primary interface"); |
| 133 | primary_interface.unref(); |
| 134 | } else { |
| 135 | primary_interface = p_primary_interface; |
| 136 | print_verbose("TextServer: Primary interface set to: \"" + primary_interface->get_name() + "\"."); |
| 137 | |
| 138 | if (OS::get_singleton()->get_main_loop()) { |
| 139 | OS::get_singleton()->get_main_loop()->notification(MainLoop::NOTIFICATION_TEXT_SERVER_CHANGED); |
| 140 | } |
| 141 | } |
| 142 | } |
| 143 | |
| 144 | TextServerManager::TextServerManager() { |
| 145 | singleton = this; |
| 146 | } |
| 147 | |
| 148 | TextServerManager::~TextServerManager() { |
| 149 | if (primary_interface.is_valid()) { |
| 150 | primary_interface.unref(); |
| 151 | } |
| 152 | while (interfaces.size() > 0) { |
| 153 | interfaces.remove_at(0); |
| 154 | } |
| 155 | singleton = nullptr; |
| 156 | } |
| 157 | |
| 158 | /*************************************************************************/ |
| 159 | |
| 160 | bool Glyph::operator==(const Glyph &p_a) const { |
| 161 | return (p_a.index == index) && (p_a.font_rid == font_rid) && (p_a.font_size == font_size) && (p_a.start == start); |
| 162 | } |
| 163 | |
| 164 | bool Glyph::operator!=(const Glyph &p_a) const { |
| 165 | return (p_a.index != index) || (p_a.font_rid != font_rid) || (p_a.font_size != font_size) || (p_a.start != start); |
| 166 | } |
| 167 | |
| 168 | bool Glyph::operator<(const Glyph &p_a) const { |
| 169 | if (p_a.start == start) { |
| 170 | if (p_a.count == count) { |
| 171 | if ((p_a.flags & TextServer::GRAPHEME_IS_VIRTUAL) == TextServer::GRAPHEME_IS_VIRTUAL) { |
| 172 | return true; |
| 173 | } else { |
| 174 | return false; |
| 175 | } |
| 176 | } |
| 177 | return p_a.count > count; |
| 178 | } |
| 179 | return p_a.start < start; |
| 180 | } |
| 181 | |
| 182 | bool Glyph::operator>(const Glyph &p_a) const { |
| 183 | if (p_a.start == start) { |
| 184 | if (p_a.count == count) { |
| 185 | if ((p_a.flags & TextServer::GRAPHEME_IS_VIRTUAL) == TextServer::GRAPHEME_IS_VIRTUAL) { |
| 186 | return false; |
| 187 | } else { |
| 188 | return true; |
| 189 | } |
| 190 | } |
| 191 | return p_a.count < count; |
| 192 | } |
| 193 | return p_a.start > start; |
| 194 | } |
| 195 | |
| 196 | double TextServer::vp_oversampling = 0.0; |
| 197 | |
| 198 | void TextServer::_bind_methods() { |
| 199 | ClassDB::bind_method(D_METHOD("has_feature", "feature"), &TextServer::has_feature); |
| 200 | ClassDB::bind_method(D_METHOD("get_name"), &TextServer::get_name); |
| 201 | ClassDB::bind_method(D_METHOD("get_features"), &TextServer::get_features); |
| 202 | ClassDB::bind_method(D_METHOD("load_support_data", "filename"), &TextServer::load_support_data); |
| 203 | |
| 204 | ClassDB::bind_method(D_METHOD("get_support_data_filename"), &TextServer::get_support_data_filename); |
| 205 | ClassDB::bind_method(D_METHOD("get_support_data_info"), &TextServer::get_support_data_info); |
| 206 | ClassDB::bind_method(D_METHOD("save_support_data", "filename"), &TextServer::save_support_data); |
| 207 | ClassDB::bind_method(D_METHOD("get_support_data"), &TextServer::get_support_data); |
| 208 | ClassDB::bind_method(D_METHOD("is_locale_using_support_data", "locale"), &TextServer::is_locale_using_support_data); |
| 209 | |
| 210 | ClassDB::bind_method(D_METHOD("is_locale_right_to_left", "locale"), &TextServer::is_locale_right_to_left); |
| 211 | |
| 212 | ClassDB::bind_method(D_METHOD("name_to_tag", "name"), &TextServer::name_to_tag); |
| 213 | ClassDB::bind_method(D_METHOD("tag_to_name", "tag"), &TextServer::tag_to_name); |
| 214 | |
| 215 | ClassDB::bind_method(D_METHOD("has", "rid"), &TextServer::has); |
| 216 | ClassDB::bind_method(D_METHOD("free_rid", "rid"), &TextServer::free_rid); |
| 217 | |
| 218 | /* Font Interface */ |
| 219 | |
| 220 | ClassDB::bind_method(D_METHOD("create_font"), &TextServer::create_font); |
| 221 | ClassDB::bind_method(D_METHOD("create_font_linked_variation", "font_rid"), &TextServer::create_font_linked_variation); |
| 222 | |
| 223 | ClassDB::bind_method(D_METHOD("font_set_data", "font_rid", "data"), &TextServer::font_set_data); |
| 224 | |
| 225 | ClassDB::bind_method(D_METHOD("font_set_face_index", "font_rid", "face_index"), &TextServer::font_set_face_index); |
| 226 | ClassDB::bind_method(D_METHOD("font_get_face_index", "font_rid"), &TextServer::font_get_face_index); |
| 227 | |
| 228 | ClassDB::bind_method(D_METHOD("font_get_face_count", "font_rid"), &TextServer::font_get_face_count); |
| 229 | |
| 230 | ClassDB::bind_method(D_METHOD("font_set_style", "font_rid", "style"), &TextServer::font_set_style); |
| 231 | ClassDB::bind_method(D_METHOD("font_get_style", "font_rid"), &TextServer::font_get_style); |
| 232 | |
| 233 | ClassDB::bind_method(D_METHOD("font_set_name", "font_rid", "name"), &TextServer::font_set_name); |
| 234 | ClassDB::bind_method(D_METHOD("font_get_name", "font_rid"), &TextServer::font_get_name); |
| 235 | ClassDB::bind_method(D_METHOD("font_get_ot_name_strings", "font_rid"), &TextServer::font_get_ot_name_strings); |
| 236 | |
| 237 | ClassDB::bind_method(D_METHOD("font_set_style_name", "font_rid", "name"), &TextServer::font_set_style_name); |
| 238 | ClassDB::bind_method(D_METHOD("font_get_style_name", "font_rid"), &TextServer::font_get_style_name); |
| 239 | |
| 240 | ClassDB::bind_method(D_METHOD("font_set_weight", "font_rid", "weight"), &TextServer::font_set_weight); |
| 241 | ClassDB::bind_method(D_METHOD("font_get_weight", "font_rid"), &TextServer::font_get_weight); |
| 242 | |
| 243 | ClassDB::bind_method(D_METHOD("font_set_stretch", "font_rid", "weight"), &TextServer::font_set_stretch); |
| 244 | ClassDB::bind_method(D_METHOD("font_get_stretch", "font_rid"), &TextServer::font_get_stretch); |
| 245 | |
| 246 | ClassDB::bind_method(D_METHOD("font_set_antialiasing", "font_rid", "antialiasing"), &TextServer::font_set_antialiasing); |
| 247 | ClassDB::bind_method(D_METHOD("font_get_antialiasing", "font_rid"), &TextServer::font_get_antialiasing); |
| 248 | |
| 249 | ClassDB::bind_method(D_METHOD("font_set_disable_embedded_bitmaps", "font_rid", "disable_embedded_bitmaps"), &TextServer::font_set_disable_embedded_bitmaps); |
| 250 | ClassDB::bind_method(D_METHOD("font_get_disable_embedded_bitmaps", "font_rid"), &TextServer::font_get_disable_embedded_bitmaps); |
| 251 | |
| 252 | ClassDB::bind_method(D_METHOD("font_set_generate_mipmaps", "font_rid", "generate_mipmaps"), &TextServer::font_set_generate_mipmaps); |
| 253 | ClassDB::bind_method(D_METHOD("font_get_generate_mipmaps", "font_rid"), &TextServer::font_get_generate_mipmaps); |
| 254 | |
| 255 | ClassDB::bind_method(D_METHOD("font_set_multichannel_signed_distance_field", "font_rid", "msdf"), &TextServer::font_set_multichannel_signed_distance_field); |
| 256 | ClassDB::bind_method(D_METHOD("font_is_multichannel_signed_distance_field", "font_rid"), &TextServer::font_is_multichannel_signed_distance_field); |
| 257 | |
| 258 | ClassDB::bind_method(D_METHOD("font_set_msdf_pixel_range", "font_rid", "msdf_pixel_range"), &TextServer::font_set_msdf_pixel_range); |
| 259 | ClassDB::bind_method(D_METHOD("font_get_msdf_pixel_range", "font_rid"), &TextServer::font_get_msdf_pixel_range); |
| 260 | |
| 261 | ClassDB::bind_method(D_METHOD("font_set_msdf_size", "font_rid", "msdf_size"), &TextServer::font_set_msdf_size); |
| 262 | ClassDB::bind_method(D_METHOD("font_get_msdf_size", "font_rid"), &TextServer::font_get_msdf_size); |
| 263 | |
| 264 | ClassDB::bind_method(D_METHOD("font_set_fixed_size", "font_rid", "fixed_size"), &TextServer::font_set_fixed_size); |
| 265 | ClassDB::bind_method(D_METHOD("font_get_fixed_size", "font_rid"), &TextServer::font_get_fixed_size); |
| 266 | |
| 267 | ClassDB::bind_method(D_METHOD("font_set_fixed_size_scale_mode", "font_rid", "fixed_size_scale_mode"), &TextServer::font_set_fixed_size_scale_mode); |
| 268 | ClassDB::bind_method(D_METHOD("font_get_fixed_size_scale_mode", "font_rid"), &TextServer::font_get_fixed_size_scale_mode); |
| 269 | |
| 270 | ClassDB::bind_method(D_METHOD("font_set_allow_system_fallback", "font_rid", "allow_system_fallback"), &TextServer::font_set_allow_system_fallback); |
| 271 | ClassDB::bind_method(D_METHOD("font_is_allow_system_fallback", "font_rid"), &TextServer::font_is_allow_system_fallback); |
| 272 | ClassDB::bind_method(D_METHOD("font_clear_system_fallback_cache"), &TextServer::font_clear_system_fallback_cache); |
| 273 | |
| 274 | ClassDB::bind_method(D_METHOD("font_set_force_autohinter", "font_rid", "force_autohinter"), &TextServer::font_set_force_autohinter); |
| 275 | ClassDB::bind_method(D_METHOD("font_is_force_autohinter", "font_rid"), &TextServer::font_is_force_autohinter); |
| 276 | |
| 277 | ClassDB::bind_method(D_METHOD("font_set_modulate_color_glyphs", "font_rid", "force_autohinter"), &TextServer::font_set_modulate_color_glyphs); |
| 278 | ClassDB::bind_method(D_METHOD("font_is_modulate_color_glyphs", "font_rid"), &TextServer::font_is_modulate_color_glyphs); |
| 279 | |
| 280 | ClassDB::bind_method(D_METHOD("font_set_hinting", "font_rid", "hinting"), &TextServer::font_set_hinting); |
| 281 | ClassDB::bind_method(D_METHOD("font_get_hinting", "font_rid"), &TextServer::font_get_hinting); |
| 282 | |
| 283 | ClassDB::bind_method(D_METHOD("font_set_subpixel_positioning", "font_rid", "subpixel_positioning"), &TextServer::font_set_subpixel_positioning); |
| 284 | ClassDB::bind_method(D_METHOD("font_get_subpixel_positioning", "font_rid"), &TextServer::font_get_subpixel_positioning); |
| 285 | |
| 286 | ClassDB::bind_method(D_METHOD("font_set_keep_rounding_remainders", "font_rid", "keep_rounding_remainders"), &TextServer::font_set_keep_rounding_remainders); |
| 287 | ClassDB::bind_method(D_METHOD("font_get_keep_rounding_remainders", "font_rid"), &TextServer::font_get_keep_rounding_remainders); |
| 288 | |
| 289 | ClassDB::bind_method(D_METHOD("font_set_embolden", "font_rid", "strength"), &TextServer::font_set_embolden); |
| 290 | ClassDB::bind_method(D_METHOD("font_get_embolden", "font_rid"), &TextServer::font_get_embolden); |
| 291 | |
| 292 | ClassDB::bind_method(D_METHOD("font_set_spacing", "font_rid", "spacing", "value"), &TextServer::font_set_spacing); |
| 293 | ClassDB::bind_method(D_METHOD("font_get_spacing", "font_rid", "spacing"), &TextServer::font_get_spacing); |
| 294 | |
| 295 | ClassDB::bind_method(D_METHOD("font_set_baseline_offset", "font_rid", "baseline_offset"), &TextServer::font_set_baseline_offset); |
| 296 | ClassDB::bind_method(D_METHOD("font_get_baseline_offset", "font_rid"), &TextServer::font_get_baseline_offset); |
| 297 | |
| 298 | ClassDB::bind_method(D_METHOD("font_set_transform", "font_rid", "transform"), &TextServer::font_set_transform); |
| 299 | ClassDB::bind_method(D_METHOD("font_get_transform", "font_rid"), &TextServer::font_get_transform); |
| 300 | |
| 301 | ClassDB::bind_method(D_METHOD("font_set_variation_coordinates", "font_rid", "variation_coordinates"), &TextServer::font_set_variation_coordinates); |
| 302 | ClassDB::bind_method(D_METHOD("font_get_variation_coordinates", "font_rid"), &TextServer::font_get_variation_coordinates); |
| 303 | |
| 304 | ClassDB::bind_method(D_METHOD("font_set_oversampling", "font_rid", "oversampling"), &TextServer::font_set_oversampling); |
| 305 | ClassDB::bind_method(D_METHOD("font_get_oversampling", "font_rid"), &TextServer::font_get_oversampling); |
| 306 | |
| 307 | ClassDB::bind_method(D_METHOD("font_get_size_cache_list", "font_rid"), &TextServer::font_get_size_cache_list); |
| 308 | ClassDB::bind_method(D_METHOD("font_clear_size_cache", "font_rid"), &TextServer::font_clear_size_cache); |
| 309 | ClassDB::bind_method(D_METHOD("font_remove_size_cache", "font_rid", "size"), &TextServer::font_remove_size_cache); |
| 310 | ClassDB::bind_method(D_METHOD("font_get_size_cache_info", "font_rid"), &TextServer::font_get_size_cache_info); |
| 311 | |
| 312 | ClassDB::bind_method(D_METHOD("font_set_ascent", "font_rid", "size", "ascent"), &TextServer::font_set_ascent); |
| 313 | ClassDB::bind_method(D_METHOD("font_get_ascent", "font_rid", "size"), &TextServer::font_get_ascent); |
| 314 | |
| 315 | ClassDB::bind_method(D_METHOD("font_set_descent", "font_rid", "size", "descent"), &TextServer::font_set_descent); |
| 316 | ClassDB::bind_method(D_METHOD("font_get_descent", "font_rid", "size"), &TextServer::font_get_descent); |
| 317 | |
| 318 | ClassDB::bind_method(D_METHOD("font_set_underline_position", "font_rid", "size", "underline_position"), &TextServer::font_set_underline_position); |
| 319 | ClassDB::bind_method(D_METHOD("font_get_underline_position", "font_rid", "size"), &TextServer::font_get_underline_position); |
| 320 | |
| 321 | ClassDB::bind_method(D_METHOD("font_set_underline_thickness", "font_rid", "size", "underline_thickness"), &TextServer::font_set_underline_thickness); |
| 322 | ClassDB::bind_method(D_METHOD("font_get_underline_thickness", "font_rid", "size"), &TextServer::font_get_underline_thickness); |
| 323 | |
| 324 | ClassDB::bind_method(D_METHOD("font_set_scale", "font_rid", "size", "scale"), &TextServer::font_set_scale); |
| 325 | ClassDB::bind_method(D_METHOD("font_get_scale", "font_rid", "size"), &TextServer::font_get_scale); |
| 326 | |
| 327 | ClassDB::bind_method(D_METHOD("font_get_texture_count", "font_rid", "size"), &TextServer::font_get_texture_count); |
| 328 | ClassDB::bind_method(D_METHOD("font_clear_textures", "font_rid", "size"), &TextServer::font_clear_textures); |
| 329 | ClassDB::bind_method(D_METHOD("font_remove_texture", "font_rid", "size", "texture_index"), &TextServer::font_remove_texture); |
| 330 | |
| 331 | ClassDB::bind_method(D_METHOD("font_set_texture_image", "font_rid", "size", "texture_index", "image"), &TextServer::font_set_texture_image); |
| 332 | ClassDB::bind_method(D_METHOD("font_get_texture_image", "font_rid", "size", "texture_index"), &TextServer::font_get_texture_image); |
| 333 | |
| 334 | ClassDB::bind_method(D_METHOD("font_set_texture_offsets", "font_rid", "size", "texture_index", "offset"), &TextServer::font_set_texture_offsets); |
| 335 | ClassDB::bind_method(D_METHOD("font_get_texture_offsets", "font_rid", "size", "texture_index"), &TextServer::font_get_texture_offsets); |
| 336 | |
| 337 | ClassDB::bind_method(D_METHOD("font_get_glyph_list", "font_rid", "size"), &TextServer::font_get_glyph_list); |
| 338 | ClassDB::bind_method(D_METHOD("font_clear_glyphs", "font_rid", "size"), &TextServer::font_clear_glyphs); |
| 339 | ClassDB::bind_method(D_METHOD("font_remove_glyph", "font_rid", "size", "glyph"), &TextServer::font_remove_glyph); |
| 340 | |
| 341 | ClassDB::bind_method(D_METHOD("font_get_glyph_advance", "font_rid", "size", "glyph"), &TextServer::font_get_glyph_advance); |
| 342 | ClassDB::bind_method(D_METHOD("font_set_glyph_advance", "font_rid", "size", "glyph", "advance"), &TextServer::font_set_glyph_advance); |
| 343 | |
| 344 | ClassDB::bind_method(D_METHOD("font_get_glyph_offset", "font_rid", "size", "glyph"), &TextServer::font_get_glyph_offset); |
| 345 | ClassDB::bind_method(D_METHOD("font_set_glyph_offset", "font_rid", "size", "glyph", "offset"), &TextServer::font_set_glyph_offset); |
| 346 | |
| 347 | ClassDB::bind_method(D_METHOD("font_get_glyph_size", "font_rid", "size", "glyph"), &TextServer::font_get_glyph_size); |
| 348 | ClassDB::bind_method(D_METHOD("font_set_glyph_size", "font_rid", "size", "glyph", "gl_size"), &TextServer::font_set_glyph_size); |
| 349 | |
| 350 | ClassDB::bind_method(D_METHOD("font_get_glyph_uv_rect", "font_rid", "size", "glyph"), &TextServer::font_get_glyph_uv_rect); |
| 351 | ClassDB::bind_method(D_METHOD("font_set_glyph_uv_rect", "font_rid", "size", "glyph", "uv_rect"), &TextServer::font_set_glyph_uv_rect); |
| 352 | |
| 353 | ClassDB::bind_method(D_METHOD("font_get_glyph_texture_idx", "font_rid", "size", "glyph"), &TextServer::font_get_glyph_texture_idx); |
| 354 | ClassDB::bind_method(D_METHOD("font_set_glyph_texture_idx", "font_rid", "size", "glyph", "texture_idx"), &TextServer::font_set_glyph_texture_idx); |
| 355 | |
| 356 | ClassDB::bind_method(D_METHOD("font_get_glyph_texture_rid", "font_rid", "size", "glyph"), &TextServer::font_get_glyph_texture_rid); |
| 357 | ClassDB::bind_method(D_METHOD("font_get_glyph_texture_size", "font_rid", "size", "glyph"), &TextServer::font_get_glyph_texture_size); |
| 358 | |
| 359 | ClassDB::bind_method(D_METHOD("font_get_glyph_contours", "font", "size", "index"), &TextServer::font_get_glyph_contours); |
| 360 | |
| 361 | ClassDB::bind_method(D_METHOD("font_get_kerning_list", "font_rid", "size"), &TextServer::font_get_kerning_list); |
| 362 | ClassDB::bind_method(D_METHOD("font_clear_kerning_map", "font_rid", "size"), &TextServer::font_clear_kerning_map); |
| 363 | ClassDB::bind_method(D_METHOD("font_remove_kerning", "font_rid", "size", "glyph_pair"), &TextServer::font_remove_kerning); |
| 364 | |
| 365 | ClassDB::bind_method(D_METHOD("font_set_kerning", "font_rid", "size", "glyph_pair", "kerning"), &TextServer::font_set_kerning); |
| 366 | ClassDB::bind_method(D_METHOD("font_get_kerning", "font_rid", "size", "glyph_pair"), &TextServer::font_get_kerning); |
| 367 | |
| 368 | ClassDB::bind_method(D_METHOD("font_get_glyph_index", "font_rid", "size", "char", "variation_selector"), &TextServer::font_get_glyph_index); |
| 369 | ClassDB::bind_method(D_METHOD("font_get_char_from_glyph_index", "font_rid", "size", "glyph_index"), &TextServer::font_get_char_from_glyph_index); |
| 370 | |
| 371 | ClassDB::bind_method(D_METHOD("font_has_char", "font_rid", "char"), &TextServer::font_has_char); |
| 372 | ClassDB::bind_method(D_METHOD("font_get_supported_chars", "font_rid"), &TextServer::font_get_supported_chars); |
| 373 | ClassDB::bind_method(D_METHOD("font_get_supported_glyphs", "font_rid"), &TextServer::font_get_supported_glyphs); |
| 374 | |
| 375 | ClassDB::bind_method(D_METHOD("font_render_range", "font_rid", "size", "start", "end"), &TextServer::font_render_range); |
| 376 | ClassDB::bind_method(D_METHOD("font_render_glyph", "font_rid", "size", "index"), &TextServer::font_render_glyph); |
| 377 | |
| 378 | ClassDB::bind_method(D_METHOD("font_draw_glyph", "font_rid", "canvas", "size", "pos", "index", "color", "oversampling"), &TextServer::font_draw_glyph, DEFVAL(Color(1, 1, 1)), DEFVAL(0.0)); |
| 379 | ClassDB::bind_method(D_METHOD("font_draw_glyph_outline", "font_rid", "canvas", "size", "outline_size", "pos", "index", "color", "oversampling"), &TextServer::font_draw_glyph_outline, DEFVAL(Color(1, 1, 1)), DEFVAL(0.0)); |
| 380 | |
| 381 | ClassDB::bind_method(D_METHOD("font_is_language_supported", "font_rid", "language"), &TextServer::font_is_language_supported); |
| 382 | ClassDB::bind_method(D_METHOD("font_set_language_support_override", "font_rid", "language", "supported"), &TextServer::font_set_language_support_override); |
| 383 | ClassDB::bind_method(D_METHOD("font_get_language_support_override", "font_rid", "language"), &TextServer::font_get_language_support_override); |
| 384 | ClassDB::bind_method(D_METHOD("font_remove_language_support_override", "font_rid", "language"), &TextServer::font_remove_language_support_override); |
| 385 | ClassDB::bind_method(D_METHOD("font_get_language_support_overrides", "font_rid"), &TextServer::font_get_language_support_overrides); |
| 386 | |
| 387 | ClassDB::bind_method(D_METHOD("font_is_script_supported", "font_rid", "script"), &TextServer::font_is_script_supported); |
| 388 | ClassDB::bind_method(D_METHOD("font_set_script_support_override", "font_rid", "script", "supported"), &TextServer::font_set_script_support_override); |
| 389 | ClassDB::bind_method(D_METHOD("font_get_script_support_override", "font_rid", "script"), &TextServer::font_get_script_support_override); |
| 390 | ClassDB::bind_method(D_METHOD("font_remove_script_support_override", "font_rid", "script"), &TextServer::font_remove_script_support_override); |
| 391 | ClassDB::bind_method(D_METHOD("font_get_script_support_overrides", "font_rid"), &TextServer::font_get_script_support_overrides); |
| 392 | |
| 393 | ClassDB::bind_method(D_METHOD("font_set_opentype_feature_overrides", "font_rid", "overrides"), &TextServer::font_set_opentype_feature_overrides); |
| 394 | ClassDB::bind_method(D_METHOD("font_get_opentype_feature_overrides", "font_rid"), &TextServer::font_get_opentype_feature_overrides); |
| 395 | |
| 396 | ClassDB::bind_method(D_METHOD("font_supported_feature_list", "font_rid"), &TextServer::font_supported_feature_list); |
| 397 | ClassDB::bind_method(D_METHOD("font_supported_variation_list", "font_rid"), &TextServer::font_supported_variation_list); |
| 398 | |
| 399 | #ifndef DISABLE_DEPRECATED |
| 400 | ClassDB::bind_method(D_METHOD("font_get_global_oversampling"), &TextServer::font_get_global_oversampling); |
| 401 | ClassDB::bind_method(D_METHOD("font_set_global_oversampling", "oversampling"), &TextServer::font_set_global_oversampling); |
| 402 | #endif |
| 403 | |
| 404 | ClassDB::bind_method(D_METHOD("get_hex_code_box_size", "size", "index"), &TextServer::get_hex_code_box_size); |
| 405 | ClassDB::bind_method(D_METHOD("draw_hex_code_box", "canvas", "size", "pos", "index", "color"), &TextServer::draw_hex_code_box); |
| 406 | |
| 407 | /* Shaped text buffer interface */ |
| 408 | |
| 409 | ClassDB::bind_method(D_METHOD("create_shaped_text", "direction", "orientation"), &TextServer::create_shaped_text, DEFVAL(DIRECTION_AUTO), DEFVAL(ORIENTATION_HORIZONTAL)); |
| 410 | |
| 411 | ClassDB::bind_method(D_METHOD("shaped_text_clear", "rid"), &TextServer::shaped_text_clear); |
| 412 | ClassDB::bind_method(D_METHOD("shaped_text_duplicate", "rid"), &TextServer::shaped_text_duplicate); |
| 413 | |
| 414 | ClassDB::bind_method(D_METHOD("shaped_text_set_direction", "shaped", "direction"), &TextServer::shaped_text_set_direction, DEFVAL(DIRECTION_AUTO)); |
| 415 | ClassDB::bind_method(D_METHOD("shaped_text_get_direction", "shaped"), &TextServer::shaped_text_get_direction); |
| 416 | ClassDB::bind_method(D_METHOD("shaped_text_get_inferred_direction", "shaped"), &TextServer::shaped_text_get_inferred_direction); |
| 417 | |
| 418 | ClassDB::bind_method(D_METHOD("shaped_text_set_bidi_override", "shaped", "override"), &TextServer::shaped_text_set_bidi_override); |
| 419 | |
| 420 | ClassDB::bind_method(D_METHOD("shaped_text_set_custom_punctuation", "shaped", "punct"), &TextServer::shaped_text_set_custom_punctuation); |
| 421 | ClassDB::bind_method(D_METHOD("shaped_text_get_custom_punctuation", "shaped"), &TextServer::shaped_text_get_custom_punctuation); |
| 422 | |
| 423 | ClassDB::bind_method(D_METHOD("shaped_text_set_custom_ellipsis", "shaped", "char"), &TextServer::shaped_text_set_custom_ellipsis); |
| 424 | ClassDB::bind_method(D_METHOD("shaped_text_get_custom_ellipsis", "shaped"), &TextServer::shaped_text_get_custom_ellipsis); |
| 425 | |
| 426 | ClassDB::bind_method(D_METHOD("shaped_text_set_orientation", "shaped", "orientation"), &TextServer::shaped_text_set_orientation, DEFVAL(ORIENTATION_HORIZONTAL)); |
| 427 | ClassDB::bind_method(D_METHOD("shaped_text_get_orientation", "shaped"), &TextServer::shaped_text_get_orientation); |
| 428 | |
| 429 | ClassDB::bind_method(D_METHOD("shaped_text_set_preserve_invalid", "shaped", "enabled"), &TextServer::shaped_text_set_preserve_invalid); |
| 430 | ClassDB::bind_method(D_METHOD("shaped_text_get_preserve_invalid", "shaped"), &TextServer::shaped_text_get_preserve_invalid); |
| 431 | |
| 432 | ClassDB::bind_method(D_METHOD("shaped_text_set_preserve_control", "shaped", "enabled"), &TextServer::shaped_text_set_preserve_control); |
| 433 | ClassDB::bind_method(D_METHOD("shaped_text_get_preserve_control", "shaped"), &TextServer::shaped_text_get_preserve_control); |
| 434 | |
| 435 | ClassDB::bind_method(D_METHOD("shaped_text_set_spacing", "shaped", "spacing", "value"), &TextServer::shaped_text_set_spacing); |
| 436 | ClassDB::bind_method(D_METHOD("shaped_text_get_spacing", "shaped", "spacing"), &TextServer::shaped_text_get_spacing); |
| 437 | |
| 438 | ClassDB::bind_method(D_METHOD("shaped_text_add_string", "shaped", "text", "fonts", "size", "opentype_features", "language", "meta"), &TextServer::shaped_text_add_string, DEFVAL(Dictionary()), DEFVAL(""), DEFVAL(Variant())); |
| 439 | ClassDB::bind_method(D_METHOD("shaped_text_add_object", "shaped", "key", "size", "inline_align", "length", "baseline"), &TextServer::shaped_text_add_object, DEFVAL(INLINE_ALIGNMENT_CENTER), DEFVAL(1), DEFVAL(0.0)); |
| 440 | ClassDB::bind_method(D_METHOD("shaped_text_resize_object", "shaped", "key", "size", "inline_align", "baseline"), &TextServer::shaped_text_resize_object, DEFVAL(INLINE_ALIGNMENT_CENTER), DEFVAL(0.0)); |
| 441 | ClassDB::bind_method(D_METHOD("shaped_text_has_object", "shaped", "key"), &TextServer::shaped_text_has_object); |
| 442 | ClassDB::bind_method(D_METHOD("shaped_get_text", "shaped"), &TextServer::shaped_get_text); |
| 443 | |
| 444 | ClassDB::bind_method(D_METHOD("shaped_get_span_count", "shaped"), &TextServer::shaped_get_span_count); |
| 445 | ClassDB::bind_method(D_METHOD("shaped_get_span_meta", "shaped", "index"), &TextServer::shaped_get_span_meta); |
| 446 | ClassDB::bind_method(D_METHOD("shaped_get_span_embedded_object", "shaped", "index"), &TextServer::shaped_get_span_embedded_object); |
| 447 | ClassDB::bind_method(D_METHOD("shaped_get_span_text", "shaped", "index"), &TextServer::shaped_get_span_text); |
| 448 | ClassDB::bind_method(D_METHOD("shaped_get_span_object", "shaped", "index"), &TextServer::shaped_get_span_object); |
| 449 | ClassDB::bind_method(D_METHOD("shaped_set_span_update_font", "shaped", "index", "fonts", "size", "opentype_features"), &TextServer::shaped_set_span_update_font, DEFVAL(Dictionary())); |
| 450 | |
| 451 | ClassDB::bind_method(D_METHOD("shaped_get_run_count", "shaped"), &TextServer::shaped_get_run_count); |
| 452 | ClassDB::bind_method(D_METHOD("shaped_get_run_text", "shaped", "index"), &TextServer::shaped_get_run_text); |
| 453 | ClassDB::bind_method(D_METHOD("shaped_get_run_range", "shaped", "index"), &TextServer::shaped_get_run_range); |
| 454 | ClassDB::bind_method(D_METHOD("shaped_get_run_glyph_range", "shaped", "index"), &TextServer::shaped_get_run_glyph_range); |
| 455 | ClassDB::bind_method(D_METHOD("shaped_get_run_font_rid", "shaped", "index"), &TextServer::shaped_get_run_font_rid); |
| 456 | ClassDB::bind_method(D_METHOD("shaped_get_run_font_size", "shaped", "index"), &TextServer::shaped_get_run_font_size); |
| 457 | ClassDB::bind_method(D_METHOD("shaped_get_run_language", "shaped", "index"), &TextServer::shaped_get_run_language); |
| 458 | ClassDB::bind_method(D_METHOD("shaped_get_run_direction", "shaped", "index"), &TextServer::shaped_get_run_direction); |
| 459 | ClassDB::bind_method(D_METHOD("shaped_get_run_object", "shaped", "index"), &TextServer::shaped_get_run_object); |
| 460 | |
| 461 | ClassDB::bind_method(D_METHOD("shaped_text_substr", "shaped", "start", "length"), &TextServer::shaped_text_substr); |
| 462 | ClassDB::bind_method(D_METHOD("shaped_text_get_parent", "shaped"), &TextServer::shaped_text_get_parent); |
| 463 | ClassDB::bind_method(D_METHOD("shaped_text_fit_to_width", "shaped", "width", "justification_flags"), &TextServer::shaped_text_fit_to_width, DEFVAL(JUSTIFICATION_WORD_BOUND | JUSTIFICATION_KASHIDA)); |
| 464 | ClassDB::bind_method(D_METHOD("shaped_text_tab_align", "shaped", "tab_stops"), &TextServer::shaped_text_tab_align); |
| 465 | |
| 466 | ClassDB::bind_method(D_METHOD("shaped_text_shape", "shaped"), &TextServer::shaped_text_shape); |
| 467 | ClassDB::bind_method(D_METHOD("shaped_text_is_ready", "shaped"), &TextServer::shaped_text_is_ready); |
| 468 | ClassDB::bind_method(D_METHOD("shaped_text_has_visible_chars", "shaped"), &TextServer::shaped_text_has_visible_chars); |
| 469 | |
| 470 | ClassDB::bind_method(D_METHOD("shaped_text_get_glyphs", "shaped"), &TextServer::_shaped_text_get_glyphs_wrapper); |
| 471 | ClassDB::bind_method(D_METHOD("shaped_text_sort_logical", "shaped"), &TextServer::_shaped_text_sort_logical_wrapper); |
| 472 | ClassDB::bind_method(D_METHOD("shaped_text_get_glyph_count", "shaped"), &TextServer::shaped_text_get_glyph_count); |
| 473 | |
| 474 | ClassDB::bind_method(D_METHOD("shaped_text_get_range", "shaped"), &TextServer::shaped_text_get_range); |
| 475 | ClassDB::bind_method(D_METHOD("shaped_text_get_line_breaks_adv", "shaped", "width", "start", "once", "break_flags"), &TextServer::shaped_text_get_line_breaks_adv, DEFVAL(0), DEFVAL(true), DEFVAL(BREAK_MANDATORY | BREAK_WORD_BOUND)); |
| 476 | ClassDB::bind_method(D_METHOD("shaped_text_get_line_breaks", "shaped", "width", "start", "break_flags"), &TextServer::shaped_text_get_line_breaks, DEFVAL(0), DEFVAL(BREAK_MANDATORY | BREAK_WORD_BOUND)); |
| 477 | ClassDB::bind_method(D_METHOD("shaped_text_get_word_breaks", "shaped", "grapheme_flags", "skip_grapheme_flags"), &TextServer::shaped_text_get_word_breaks, DEFVAL(GRAPHEME_IS_SPACE | GRAPHEME_IS_PUNCTUATION), DEFVAL(GRAPHEME_IS_VIRTUAL)); |
| 478 | |
| 479 | ClassDB::bind_method(D_METHOD("shaped_text_get_trim_pos", "shaped"), &TextServer::shaped_text_get_trim_pos); |
| 480 | ClassDB::bind_method(D_METHOD("shaped_text_get_ellipsis_pos", "shaped"), &TextServer::shaped_text_get_ellipsis_pos); |
| 481 | ClassDB::bind_method(D_METHOD("shaped_text_get_ellipsis_glyphs", "shaped"), &TextServer::_shaped_text_get_ellipsis_glyphs_wrapper); |
| 482 | ClassDB::bind_method(D_METHOD("shaped_text_get_ellipsis_glyph_count", "shaped"), &TextServer::shaped_text_get_ellipsis_glyph_count); |
| 483 | |
| 484 | ClassDB::bind_method(D_METHOD("shaped_text_overrun_trim_to_width", "shaped", "width", "overrun_trim_flags"), &TextServer::shaped_text_overrun_trim_to_width, DEFVAL(0), DEFVAL(OVERRUN_NO_TRIM)); |
| 485 | |
| 486 | ClassDB::bind_method(D_METHOD("shaped_text_get_objects", "shaped"), &TextServer::shaped_text_get_objects); |
| 487 | ClassDB::bind_method(D_METHOD("shaped_text_get_object_rect", "shaped", "key"), &TextServer::shaped_text_get_object_rect); |
| 488 | ClassDB::bind_method(D_METHOD("shaped_text_get_object_range", "shaped", "key"), &TextServer::shaped_text_get_object_range); |
| 489 | ClassDB::bind_method(D_METHOD("shaped_text_get_object_glyph", "shaped", "key"), &TextServer::shaped_text_get_object_glyph); |
| 490 | |
| 491 | ClassDB::bind_method(D_METHOD("shaped_text_get_size", "shaped"), &TextServer::shaped_text_get_size); |
| 492 | ClassDB::bind_method(D_METHOD("shaped_text_get_ascent", "shaped"), &TextServer::shaped_text_get_ascent); |
| 493 | ClassDB::bind_method(D_METHOD("shaped_text_get_descent", "shaped"), &TextServer::shaped_text_get_descent); |
| 494 | ClassDB::bind_method(D_METHOD("shaped_text_get_width", "shaped"), &TextServer::shaped_text_get_width); |
| 495 | ClassDB::bind_method(D_METHOD("shaped_text_get_underline_position", "shaped"), &TextServer::shaped_text_get_underline_position); |
| 496 | ClassDB::bind_method(D_METHOD("shaped_text_get_underline_thickness", "shaped"), &TextServer::shaped_text_get_underline_thickness); |
| 497 | |
| 498 | ClassDB::bind_method(D_METHOD("shaped_text_get_carets", "shaped", "position"), &TextServer::_shaped_text_get_carets_wrapper); |
| 499 | ClassDB::bind_method(D_METHOD("shaped_text_get_selection", "shaped", "start", "end"), &TextServer::shaped_text_get_selection); |
| 500 | |
| 501 | ClassDB::bind_method(D_METHOD("shaped_text_hit_test_grapheme", "shaped", "coords"), &TextServer::shaped_text_hit_test_grapheme); |
| 502 | ClassDB::bind_method(D_METHOD("shaped_text_hit_test_position", "shaped", "coords"), &TextServer::shaped_text_hit_test_position); |
| 503 | |
| 504 | ClassDB::bind_method(D_METHOD("shaped_text_get_grapheme_bounds", "shaped", "pos"), &TextServer::shaped_text_get_grapheme_bounds); |
| 505 | ClassDB::bind_method(D_METHOD("shaped_text_next_grapheme_pos", "shaped", "pos"), &TextServer::shaped_text_next_grapheme_pos); |
| 506 | ClassDB::bind_method(D_METHOD("shaped_text_prev_grapheme_pos", "shaped", "pos"), &TextServer::shaped_text_prev_grapheme_pos); |
| 507 | |
| 508 | ClassDB::bind_method(D_METHOD("shaped_text_get_character_breaks", "shaped"), &TextServer::shaped_text_get_character_breaks); |
| 509 | ClassDB::bind_method(D_METHOD("shaped_text_next_character_pos", "shaped", "pos"), &TextServer::shaped_text_next_character_pos); |
| 510 | ClassDB::bind_method(D_METHOD("shaped_text_prev_character_pos", "shaped", "pos"), &TextServer::shaped_text_prev_character_pos); |
| 511 | ClassDB::bind_method(D_METHOD("shaped_text_closest_character_pos", "shaped", "pos"), &TextServer::shaped_text_closest_character_pos); |
| 512 | |
| 513 | ClassDB::bind_method(D_METHOD("shaped_text_draw", "shaped", "canvas", "pos", "clip_l", "clip_r", "color", "oversampling"), &TextServer::shaped_text_draw, DEFVAL(-1), DEFVAL(-1), DEFVAL(Color(1, 1, 1)), DEFVAL(0.0)); |
| 514 | ClassDB::bind_method(D_METHOD("shaped_text_draw_outline", "shaped", "canvas", "pos", "clip_l", "clip_r", "outline_size", "color", "oversampling"), &TextServer::shaped_text_draw_outline, DEFVAL(-1), DEFVAL(-1), DEFVAL(1), DEFVAL(Color(1, 1, 1)), DEFVAL(0.0)); |
| 515 | |
| 516 | ClassDB::bind_method(D_METHOD("shaped_text_get_dominant_direction_in_range", "shaped", "start", "end"), &TextServer::shaped_text_get_dominant_direction_in_range); |
| 517 | |
| 518 | #ifndef DISABLE_DEPRECATED |
| 519 | ClassDB::bind_method(D_METHOD("format_number", "number", "language"), &TextServer::format_number, DEFVAL("")); |
| 520 | ClassDB::bind_method(D_METHOD("parse_number", "number", "language"), &TextServer::parse_number, DEFVAL("")); |
| 521 | ClassDB::bind_method(D_METHOD("percent_sign", "language"), &TextServer::percent_sign, DEFVAL("")); |
| 522 | #endif // DISABLE_DEPRECATED |
| 523 | |
| 524 | ClassDB::bind_method(D_METHOD("string_get_word_breaks", "string", "language", "chars_per_line"), &TextServer::string_get_word_breaks, DEFVAL(""), DEFVAL(0)); |
| 525 | ClassDB::bind_method(D_METHOD("string_get_character_breaks", "string", "language"), &TextServer::string_get_character_breaks, DEFVAL("")); |
| 526 | |
| 527 | ClassDB::bind_method(D_METHOD("is_confusable", "string", "dict"), &TextServer::is_confusable); |
| 528 | ClassDB::bind_method(D_METHOD("spoof_check", "string"), &TextServer::spoof_check); |
| 529 | |
| 530 | ClassDB::bind_method(D_METHOD("strip_diacritics", "string"), &TextServer::strip_diacritics); |
| 531 | ClassDB::bind_method(D_METHOD("is_valid_identifier", "string"), &TextServer::is_valid_identifier); |
| 532 | ClassDB::bind_method(D_METHOD("is_valid_letter", "unicode"), &TextServer::is_valid_letter); |
| 533 | |
| 534 | ClassDB::bind_method(D_METHOD("string_to_upper", "string", "language"), &TextServer::string_to_upper, DEFVAL("")); |
| 535 | ClassDB::bind_method(D_METHOD("string_to_lower", "string", "language"), &TextServer::string_to_lower, DEFVAL("")); |
| 536 | ClassDB::bind_method(D_METHOD("string_to_title", "string", "language"), &TextServer::string_to_title, DEFVAL("")); |
| 537 | |
| 538 | ClassDB::bind_method(D_METHOD("parse_structured_text", "parser_type", "args", "text"), &TextServer::parse_structured_text); |
| 539 | |
| 540 | /* Font AA */ |
| 541 | BIND_ENUM_CONSTANT(FONT_ANTIALIASING_NONE); |
| 542 | BIND_ENUM_CONSTANT(FONT_ANTIALIASING_GRAY); |
| 543 | BIND_ENUM_CONSTANT(FONT_ANTIALIASING_LCD); |
| 544 | |
| 545 | BIND_ENUM_CONSTANT(FONT_LCD_SUBPIXEL_LAYOUT_NONE); |
| 546 | BIND_ENUM_CONSTANT(FONT_LCD_SUBPIXEL_LAYOUT_HRGB); |
| 547 | BIND_ENUM_CONSTANT(FONT_LCD_SUBPIXEL_LAYOUT_HBGR); |
| 548 | BIND_ENUM_CONSTANT(FONT_LCD_SUBPIXEL_LAYOUT_VRGB); |
| 549 | BIND_ENUM_CONSTANT(FONT_LCD_SUBPIXEL_LAYOUT_VBGR); |
| 550 | BIND_ENUM_CONSTANT(FONT_LCD_SUBPIXEL_LAYOUT_MAX); |
| 551 | |
| 552 | /* Direction */ |
| 553 | BIND_ENUM_CONSTANT(DIRECTION_AUTO); |
| 554 | BIND_ENUM_CONSTANT(DIRECTION_LTR); |
| 555 | BIND_ENUM_CONSTANT(DIRECTION_RTL); |
| 556 | BIND_ENUM_CONSTANT(DIRECTION_INHERITED); |
| 557 | |
| 558 | /* Orientation */ |
| 559 | BIND_ENUM_CONSTANT(ORIENTATION_HORIZONTAL); |
| 560 | BIND_ENUM_CONSTANT(ORIENTATION_VERTICAL); |
| 561 | |
| 562 | /* JustificationFlag */ |
| 563 | BIND_BITFIELD_FLAG(JUSTIFICATION_NONE); |
| 564 | BIND_BITFIELD_FLAG(JUSTIFICATION_KASHIDA); |
| 565 | BIND_BITFIELD_FLAG(JUSTIFICATION_WORD_BOUND); |
| 566 | BIND_BITFIELD_FLAG(JUSTIFICATION_TRIM_EDGE_SPACES); |
| 567 | BIND_BITFIELD_FLAG(JUSTIFICATION_AFTER_LAST_TAB); |
| 568 | BIND_BITFIELD_FLAG(JUSTIFICATION_CONSTRAIN_ELLIPSIS); |
| 569 | BIND_BITFIELD_FLAG(JUSTIFICATION_SKIP_LAST_LINE); |
| 570 | BIND_BITFIELD_FLAG(JUSTIFICATION_SKIP_LAST_LINE_WITH_VISIBLE_CHARS); |
| 571 | BIND_BITFIELD_FLAG(JUSTIFICATION_DO_NOT_SKIP_SINGLE_LINE); |
| 572 | |
| 573 | /* AutowrapMode */ |
| 574 | BIND_ENUM_CONSTANT(AUTOWRAP_OFF); |
| 575 | BIND_ENUM_CONSTANT(AUTOWRAP_ARBITRARY); |
| 576 | BIND_ENUM_CONSTANT(AUTOWRAP_WORD); |
| 577 | BIND_ENUM_CONSTANT(AUTOWRAP_WORD_SMART); |
| 578 | |
| 579 | /* LineBreakFlag */ |
| 580 | BIND_BITFIELD_FLAG(BREAK_NONE); |
| 581 | BIND_BITFIELD_FLAG(BREAK_MANDATORY); |
| 582 | BIND_BITFIELD_FLAG(BREAK_WORD_BOUND); |
| 583 | BIND_BITFIELD_FLAG(BREAK_GRAPHEME_BOUND); |
| 584 | BIND_BITFIELD_FLAG(BREAK_ADAPTIVE); |
| 585 | #ifndef DISABLE_DEPRECATED |
| 586 | BIND_BITFIELD_FLAG(BREAK_TRIM_EDGE_SPACES); |
| 587 | #endif |
| 588 | BIND_BITFIELD_FLAG(BREAK_TRIM_INDENT); |
| 589 | BIND_BITFIELD_FLAG(BREAK_TRIM_START_EDGE_SPACES); |
| 590 | BIND_BITFIELD_FLAG(BREAK_TRIM_END_EDGE_SPACES); |
| 591 | |
| 592 | /* VisibleCharactersBehavior */ |
| 593 | BIND_ENUM_CONSTANT(VC_CHARS_BEFORE_SHAPING); |
| 594 | BIND_ENUM_CONSTANT(VC_CHARS_AFTER_SHAPING); |
| 595 | BIND_ENUM_CONSTANT(VC_GLYPHS_AUTO); |
| 596 | BIND_ENUM_CONSTANT(VC_GLYPHS_LTR); |
| 597 | BIND_ENUM_CONSTANT(VC_GLYPHS_RTL); |
| 598 | |
| 599 | /* OverrunBehavior */ |
| 600 | BIND_ENUM_CONSTANT(OVERRUN_NO_TRIMMING); |
| 601 | BIND_ENUM_CONSTANT(OVERRUN_TRIM_CHAR); |
| 602 | BIND_ENUM_CONSTANT(OVERRUN_TRIM_WORD); |
| 603 | BIND_ENUM_CONSTANT(OVERRUN_TRIM_ELLIPSIS); |
| 604 | BIND_ENUM_CONSTANT(OVERRUN_TRIM_WORD_ELLIPSIS); |
| 605 | BIND_ENUM_CONSTANT(OVERRUN_TRIM_ELLIPSIS_FORCE); |
| 606 | BIND_ENUM_CONSTANT(OVERRUN_TRIM_WORD_ELLIPSIS_FORCE); |
| 607 | |
| 608 | /* TextOverrunFlag */ |
| 609 | BIND_BITFIELD_FLAG(OVERRUN_NO_TRIM); |
| 610 | BIND_BITFIELD_FLAG(OVERRUN_TRIM); |
| 611 | BIND_BITFIELD_FLAG(OVERRUN_TRIM_WORD_ONLY); |
| 612 | BIND_BITFIELD_FLAG(OVERRUN_ADD_ELLIPSIS); |
| 613 | BIND_BITFIELD_FLAG(OVERRUN_ENFORCE_ELLIPSIS); |
| 614 | BIND_BITFIELD_FLAG(OVERRUN_JUSTIFICATION_AWARE); |
| 615 | BIND_BITFIELD_FLAG(OVERRUN_SHORT_STRING_ELLIPSIS); |
| 616 | |
| 617 | /* GraphemeFlag */ |
| 618 | BIND_BITFIELD_FLAG(GRAPHEME_IS_VALID); |
| 619 | BIND_BITFIELD_FLAG(GRAPHEME_IS_RTL); |
| 620 | BIND_BITFIELD_FLAG(GRAPHEME_IS_VIRTUAL); |
| 621 | BIND_BITFIELD_FLAG(GRAPHEME_IS_SPACE); |
| 622 | BIND_BITFIELD_FLAG(GRAPHEME_IS_BREAK_HARD); |
| 623 | BIND_BITFIELD_FLAG(GRAPHEME_IS_BREAK_SOFT); |
| 624 | BIND_BITFIELD_FLAG(GRAPHEME_IS_TAB); |
| 625 | BIND_BITFIELD_FLAG(GRAPHEME_IS_ELONGATION); |
| 626 | BIND_BITFIELD_FLAG(GRAPHEME_IS_PUNCTUATION); |
| 627 | BIND_BITFIELD_FLAG(GRAPHEME_IS_UNDERSCORE); |
| 628 | BIND_BITFIELD_FLAG(GRAPHEME_IS_CONNECTED); |
| 629 | BIND_BITFIELD_FLAG(GRAPHEME_IS_SAFE_TO_INSERT_TATWEEL); |
| 630 | BIND_BITFIELD_FLAG(GRAPHEME_IS_EMBEDDED_OBJECT); |
| 631 | BIND_BITFIELD_FLAG(GRAPHEME_IS_SOFT_HYPHEN); |
| 632 | |
| 633 | /* Hinting */ |
| 634 | BIND_ENUM_CONSTANT(HINTING_NONE); |
| 635 | BIND_ENUM_CONSTANT(HINTING_LIGHT); |
| 636 | BIND_ENUM_CONSTANT(HINTING_NORMAL); |
| 637 | |
| 638 | /* SubpixelPositioning */ |
| 639 | BIND_ENUM_CONSTANT(SUBPIXEL_POSITIONING_DISABLED); |
| 640 | BIND_ENUM_CONSTANT(SUBPIXEL_POSITIONING_AUTO); |
| 641 | BIND_ENUM_CONSTANT(SUBPIXEL_POSITIONING_ONE_HALF); |
| 642 | BIND_ENUM_CONSTANT(SUBPIXEL_POSITIONING_ONE_QUARTER); |
| 643 | BIND_ENUM_CONSTANT(SUBPIXEL_POSITIONING_ONE_HALF_MAX_SIZE); |
| 644 | BIND_ENUM_CONSTANT(SUBPIXEL_POSITIONING_ONE_QUARTER_MAX_SIZE); |
| 645 | |
| 646 | /* Feature */ |
| 647 | BIND_ENUM_CONSTANT(FEATURE_SIMPLE_LAYOUT); |
| 648 | BIND_ENUM_CONSTANT(FEATURE_BIDI_LAYOUT); |
| 649 | BIND_ENUM_CONSTANT(FEATURE_VERTICAL_LAYOUT); |
| 650 | BIND_ENUM_CONSTANT(FEATURE_SHAPING); |
| 651 | BIND_ENUM_CONSTANT(FEATURE_KASHIDA_JUSTIFICATION); |
| 652 | BIND_ENUM_CONSTANT(FEATURE_BREAK_ITERATORS); |
| 653 | BIND_ENUM_CONSTANT(FEATURE_FONT_BITMAP); |
| 654 | BIND_ENUM_CONSTANT(FEATURE_FONT_DYNAMIC); |
| 655 | BIND_ENUM_CONSTANT(FEATURE_FONT_MSDF); |
| 656 | BIND_ENUM_CONSTANT(FEATURE_FONT_SYSTEM); |
| 657 | BIND_ENUM_CONSTANT(FEATURE_FONT_VARIABLE); |
| 658 | BIND_ENUM_CONSTANT(FEATURE_CONTEXT_SENSITIVE_CASE_CONVERSION); |
| 659 | BIND_ENUM_CONSTANT(FEATURE_USE_SUPPORT_DATA); |
| 660 | BIND_ENUM_CONSTANT(FEATURE_UNICODE_IDENTIFIERS); |
| 661 | BIND_ENUM_CONSTANT(FEATURE_UNICODE_SECURITY); |
| 662 | |
| 663 | /* FT Contour Point Types */ |
| 664 | BIND_ENUM_CONSTANT(CONTOUR_CURVE_TAG_ON); |
| 665 | BIND_ENUM_CONSTANT(CONTOUR_CURVE_TAG_OFF_CONIC); |
| 666 | BIND_ENUM_CONSTANT(CONTOUR_CURVE_TAG_OFF_CUBIC); |
| 667 | |
| 668 | /* Font Spacing */ |
| 669 | BIND_ENUM_CONSTANT(SPACING_GLYPH); |
| 670 | BIND_ENUM_CONSTANT(SPACING_SPACE); |
| 671 | BIND_ENUM_CONSTANT(SPACING_TOP); |
| 672 | BIND_ENUM_CONSTANT(SPACING_BOTTOM); |
| 673 | BIND_ENUM_CONSTANT(SPACING_MAX); |
| 674 | |
| 675 | /* Font Style */ |
| 676 | BIND_BITFIELD_FLAG(FONT_BOLD); |
| 677 | BIND_BITFIELD_FLAG(FONT_ITALIC); |
| 678 | BIND_BITFIELD_FLAG(FONT_FIXED_WIDTH); |
| 679 | |
| 680 | /* Structured text parser */ |
| 681 | BIND_ENUM_CONSTANT(STRUCTURED_TEXT_DEFAULT); |
| 682 | BIND_ENUM_CONSTANT(STRUCTURED_TEXT_URI); |
| 683 | BIND_ENUM_CONSTANT(STRUCTURED_TEXT_FILE); |
| 684 | BIND_ENUM_CONSTANT(STRUCTURED_TEXT_EMAIL); |
| 685 | BIND_ENUM_CONSTANT(STRUCTURED_TEXT_LIST); |
| 686 | BIND_ENUM_CONSTANT(STRUCTURED_TEXT_GDSCRIPT); |
| 687 | BIND_ENUM_CONSTANT(STRUCTURED_TEXT_CUSTOM); |
| 688 | |
| 689 | /* Fixed size scale mode */ |
| 690 | BIND_ENUM_CONSTANT(FIXED_SIZE_SCALE_DISABLE); |
| 691 | BIND_ENUM_CONSTANT(FIXED_SIZE_SCALE_INTEGER_ONLY); |
| 692 | BIND_ENUM_CONSTANT(FIXED_SIZE_SCALE_ENABLED); |
| 693 | } |
| 694 | |
| 695 | _FORCE_INLINE_ int32_t ot_tag_from_string(const char *p_str, int p_len) { |
| 696 | char tag[4]; |
| 697 | uint32_t i; |
| 698 | |
| 699 | if (!p_str || !p_len || !*p_str) { |
| 700 | return OT_TAG(0, 0, 0, 0); |
| 701 | } |
| 702 | |
| 703 | if (p_len < 0 || p_len > 4) { |
| 704 | p_len = 4; |
| 705 | } |
| 706 | for (i = 0; i < (uint32_t)p_len && p_str[i]; i++) { |
| 707 | tag[i] = p_str[i]; |
| 708 | } |
| 709 | |
| 710 | for (; i < 4; i++) { |
| 711 | tag[i] = ' '; |
| 712 | } |
| 713 | |
| 714 | return OT_TAG(tag[0], tag[1], tag[2], tag[3]); |
| 715 | } |
| 716 | |
| 717 | int64_t TextServer::name_to_tag(const String &p_name) const { |
| 718 | // No readable name, use tag string. |
| 719 | return ot_tag_from_string(p_name.replace("custom_", "").ascii().get_data(), -1); |
| 720 | } |
| 721 | |
| 722 | _FORCE_INLINE_ void ot_tag_to_string(int32_t p_tag, char *p_buf) { |
| 723 | p_buf[0] = (char)(uint8_t)(p_tag >> 24); |
| 724 | p_buf[1] = (char)(uint8_t)(p_tag >> 16); |
| 725 | p_buf[2] = (char)(uint8_t)(p_tag >> 8); |
| 726 | p_buf[3] = (char)(uint8_t)(p_tag >> 0); |
| 727 | } |
| 728 | |
| 729 | String TextServer::tag_to_name(int64_t p_tag) const { |
| 730 | // No readable name, use tag string. |
| 731 | char name[5]; |
| 732 | memset(name, 0, 5); |
| 733 | ot_tag_to_string(p_tag, name); |
| 734 | return String("custom_") + String(name); |
| 735 | } |
| 736 | |
| 737 | Vector2 TextServer::get_hex_code_box_size(int64_t p_size, int64_t p_index) const { |
| 738 | int w = ((p_index <= 0xFF) ? 1 : ((p_index <= 0xFFFF) ? 2 : 3)); |
| 739 | int sp = MAX(0, w - 1); |
| 740 | int sz = MAX(1, Math::round(p_size / 15.f)); |
| 741 | |
| 742 | return Vector2(4 + 3 * w + sp + 1, 15) * sz; |
| 743 | } |
| 744 | |
| 745 | void TextServer::_draw_hex_code_box_number(const RID &p_canvas, int64_t p_size, const Vector2 &p_pos, uint8_t p_index, const Color &p_color) const { |
| 746 | static uint8_t chars[] = { 0x7E, 0x30, 0x6D, 0x79, 0x33, 0x5B, 0x5F, 0x70, 0x7F, 0x7B, 0x77, 0x1F, 0x4E, 0x3D, 0x4F, 0x47, 0x00 }; |
| 747 | uint8_t x = chars[p_index]; |
| 748 | if (x & (1 << 6)) { |
| 749 | RenderingServer::get_singleton()->canvas_item_add_rect(p_canvas, Rect2(p_pos, Size2(3, 1) * p_size), p_color); |
| 750 | } |
| 751 | if (x & (1 << 5)) { |
| 752 | RenderingServer::get_singleton()->canvas_item_add_rect(p_canvas, Rect2(p_pos + Point2(2, 0) * p_size, Size2(1, 3) * p_size), p_color); |
| 753 | } |
| 754 | if (x & (1 << 4)) { |
| 755 | RenderingServer::get_singleton()->canvas_item_add_rect(p_canvas, Rect2(p_pos + Point2(2, 2) * p_size, Size2(1, 3) * p_size), p_color); |
| 756 | } |
| 757 | if (x & (1 << 3)) { |
| 758 | RenderingServer::get_singleton()->canvas_item_add_rect(p_canvas, Rect2(p_pos + Point2(0, 4) * p_size, Size2(3, 1) * p_size), p_color); |
| 759 | } |
| 760 | if (x & (1 << 2)) { |
| 761 | RenderingServer::get_singleton()->canvas_item_add_rect(p_canvas, Rect2(p_pos + Point2(0, 2) * p_size, Size2(1, 3) * p_size), p_color); |
| 762 | } |
| 763 | if (x & (1 << 1)) { |
| 764 | RenderingServer::get_singleton()->canvas_item_add_rect(p_canvas, Rect2(p_pos, Size2(1, 3) * p_size), p_color); |
| 765 | } |
| 766 | if (x & (1 << 0)) { |
| 767 | RenderingServer::get_singleton()->canvas_item_add_rect(p_canvas, Rect2(p_pos + Point2(0, 2) * p_size, Size2(3, 1) * p_size), p_color); |
| 768 | } |
| 769 | } |
| 770 | |
| 771 | void TextServer::draw_hex_code_box(const RID &p_canvas, int64_t p_size, const Vector2 &p_pos, int64_t p_index, const Color &p_color) const { |
| 772 | if (p_index == 0) { |
| 773 | return; |
| 774 | } |
| 775 | |
| 776 | int w = ((p_index <= 0xFF) ? 1 : ((p_index <= 0xFFFF) ? 2 : 3)); |
| 777 | int sp = MAX(0, w - 1); |
| 778 | int sz = MAX(1, Math::round(p_size / 15.f)); |
| 779 | |
| 780 | Size2 size = Vector2(4 + 3 * w + sp, 15) * sz; |
| 781 | Point2 pos = p_pos - Point2i(0, size.y * 0.85); |
| 782 | |
| 783 | // Draw frame. |
| 784 | RenderingServer::get_singleton()->canvas_item_add_rect(p_canvas, Rect2(pos + Point2(0, 0), Size2(sz, size.y)), p_color); |
| 785 | RenderingServer::get_singleton()->canvas_item_add_rect(p_canvas, Rect2(pos + Point2(size.x - sz, 0), Size2(sz, size.y)), p_color); |
| 786 | RenderingServer::get_singleton()->canvas_item_add_rect(p_canvas, Rect2(pos + Point2(0, 0), Size2(size.x, sz)), p_color); |
| 787 | RenderingServer::get_singleton()->canvas_item_add_rect(p_canvas, Rect2(pos + Point2(0, size.y - sz), Size2(size.x, sz)), p_color); |
| 788 | |
| 789 | uint8_t a = p_index & 0x0F; |
| 790 | uint8_t b = (p_index >> 4) & 0x0F; |
| 791 | uint8_t c = (p_index >> 8) & 0x0F; |
| 792 | uint8_t d = (p_index >> 12) & 0x0F; |
| 793 | uint8_t e = (p_index >> 16) & 0x0F; |
| 794 | uint8_t f = (p_index >> 20) & 0x0F; |
| 795 | |
| 796 | // Draw hex code. |
| 797 | if (p_index <= 0xFF) { |
| 798 | _draw_hex_code_box_number(p_canvas, sz, pos + Point2(2, 2) * sz, b, p_color); |
| 799 | _draw_hex_code_box_number(p_canvas, sz, pos + Point2(2, 8) * sz, a, p_color); |
| 800 | } else if (p_index <= 0xFFFF) { |
| 801 | _draw_hex_code_box_number(p_canvas, sz, pos + Point2(2, 2) * sz, d, p_color); |
| 802 | _draw_hex_code_box_number(p_canvas, sz, pos + Point2(6, 2) * sz, c, p_color); |
| 803 | _draw_hex_code_box_number(p_canvas, sz, pos + Point2(2, 8) * sz, b, p_color); |
| 804 | _draw_hex_code_box_number(p_canvas, sz, pos + Point2(6, 8) * sz, a, p_color); |
| 805 | } else { |
| 806 | _draw_hex_code_box_number(p_canvas, sz, pos + Point2(2, 2) * sz, f, p_color); |
| 807 | _draw_hex_code_box_number(p_canvas, sz, pos + Point2(6, 2) * sz, e, p_color); |
| 808 | _draw_hex_code_box_number(p_canvas, sz, pos + Point2(10, 2) * sz, d, p_color); |
| 809 | _draw_hex_code_box_number(p_canvas, sz, pos + Point2(2, 8) * sz, c, p_color); |
| 810 | _draw_hex_code_box_number(p_canvas, sz, pos + Point2(6, 8) * sz, b, p_color); |
| 811 | _draw_hex_code_box_number(p_canvas, sz, pos + Point2(10, 8) * sz, a, p_color); |
| 812 | } |
| 813 | } |
| 814 | |
| 815 | bool TextServer::shaped_text_has_visible_chars(const RID &p_shaped) const { |
| 816 | int v_size = shaped_text_get_glyph_count(p_shaped); |
| 817 | if (v_size == 0) { |
| 818 | return false; |
| 819 | } |
| 820 | |
| 821 | const Glyph *glyphs = shaped_text_get_glyphs(p_shaped); |
| 822 | for (int i = 0; i < v_size; i++) { |
| 823 | if (glyphs[i].index != 0 && (glyphs[i].flags & GRAPHEME_IS_VIRTUAL) != GRAPHEME_IS_VIRTUAL) { |
| 824 | return true; |
| 825 | } |
| 826 | } |
| 827 | return false; |
| 828 | } |
| 829 | |
| 830 | PackedInt32Array TextServer::shaped_text_get_line_breaks_adv(const RID &p_shaped, const PackedFloat32Array &p_width, int64_t p_start, bool p_once, BitField<TextServer::LineBreakFlag> p_break_flags) const { |
| 831 | PackedInt32Array lines; |
| 832 | |
| 833 | ERR_FAIL_COND_V(p_width.is_empty(), lines); |
| 834 | |
| 835 | TextServer::Orientation orientation = shaped_text_get_orientation(p_shaped); |
| 836 | const_cast<TextServer *>(this)->shaped_text_update_breaks(p_shaped); |
| 837 | const Vector2i &range = shaped_text_get_range(p_shaped); |
| 838 | |
| 839 | real_t width = 0.f; |
| 840 | int line_start = MAX(p_start, range.x); |
| 841 | int last_end = line_start; |
| 842 | int prev_safe_break = 0; |
| 843 | int last_safe_break = -1; |
| 844 | int word_count = 0; |
| 845 | int chunk = 0; |
| 846 | int prev_chunk = -1; |
| 847 | bool trim_next = false; |
| 848 | |
| 849 | #ifndef DISABLE_DEPRECATED |
| 850 | if (p_break_flags.has_flag(BREAK_TRIM_EDGE_SPACES)) { |
| 851 | p_break_flags = p_break_flags | BREAK_TRIM_START_EDGE_SPACES | BREAK_TRIM_END_EDGE_SPACES; |
| 852 | } |
| 853 | #endif |
| 854 | |
| 855 | int l_size = shaped_text_get_glyph_count(p_shaped); |
| 856 | const Glyph *l_gl = const_cast<TextServer *>(this)->shaped_text_sort_logical(p_shaped); |
| 857 | |
| 858 | int indent_end = 0; |
| 859 | double indent = 0.0; |
| 860 | |
| 861 | for (int i = 0; i < l_size; i++) { |
| 862 | double l_width = p_width[chunk]; |
| 863 | |
| 864 | if (p_break_flags.has_flag(BREAK_TRIM_INDENT) && chunk != prev_chunk) { |
| 865 | indent = 0.0; |
| 866 | for (int j = indent_end; j < l_size; j++) { |
| 867 | if ((l_gl[j].flags & GRAPHEME_IS_TAB) == GRAPHEME_IS_TAB || (l_gl[j].flags & GRAPHEME_IS_SPACE) == GRAPHEME_IS_SPACE) { |
| 868 | if (indent + l_gl[j].advance * l_gl[j].repeat > l_width) { |
| 869 | indent = 0.0; |
| 870 | } |
| 871 | indent += l_gl[j].advance * l_gl[j].repeat; |
| 872 | indent_end = l_gl[j].end; |
| 873 | } else { |
| 874 | break; |
| 875 | } |
| 876 | } |
| 877 | indent = MIN(indent, 0.6 * l_width); |
| 878 | prev_chunk = chunk; |
| 879 | } |
| 880 | |
| 881 | if (l_width > indent && i > indent_end) { |
| 882 | l_width -= indent; |
| 883 | } |
| 884 | if (l_gl[i].start < p_start) { |
| 885 | prev_safe_break = i + 1; |
| 886 | continue; |
| 887 | } |
| 888 | if (l_gl[i].count > 0) { |
| 889 | float adv = 0.0; |
| 890 | for (int j = i; j < l_size && l_gl[i].end == l_gl[j].end && l_gl[i].start == l_gl[j].start; j++) { |
| 891 | adv += l_gl[j].advance * l_gl[j].repeat; |
| 892 | } |
| 893 | if ((l_width > 0) && (width + adv > l_width) && (last_safe_break >= 0)) { |
| 894 | int cur_safe_brk = last_safe_break; |
| 895 | if (p_break_flags.has_flag(BREAK_TRIM_START_EDGE_SPACES) || p_break_flags.has_flag(BREAK_TRIM_END_EDGE_SPACES)) { |
| 896 | int start_pos = prev_safe_break; |
| 897 | int end_pos = last_safe_break; |
| 898 | while (p_break_flags.has_flag(BREAK_TRIM_START_EDGE_SPACES) && trim_next && (start_pos < end_pos) && ((l_gl[start_pos].flags & GRAPHEME_IS_SOFT_HYPHEN) != GRAPHEME_IS_SOFT_HYPHEN) && ((l_gl[start_pos].flags & GRAPHEME_IS_SPACE) == GRAPHEME_IS_SPACE || (l_gl[start_pos].flags & GRAPHEME_IS_BREAK_HARD) == GRAPHEME_IS_BREAK_HARD || (l_gl[start_pos].flags & GRAPHEME_IS_BREAK_SOFT) == GRAPHEME_IS_BREAK_SOFT)) { |
| 899 | start_pos += l_gl[start_pos].count; |
| 900 | } |
| 901 | while (p_break_flags.has_flag(BREAK_TRIM_END_EDGE_SPACES) && (start_pos <= end_pos) && (end_pos > 0) && ((l_gl[end_pos].flags & GRAPHEME_IS_SOFT_HYPHEN) != GRAPHEME_IS_SOFT_HYPHEN) && ((l_gl[end_pos].flags & GRAPHEME_IS_SPACE) == GRAPHEME_IS_SPACE || (l_gl[end_pos].flags & GRAPHEME_IS_BREAK_HARD) == GRAPHEME_IS_BREAK_HARD || (l_gl[end_pos].flags & GRAPHEME_IS_BREAK_SOFT) == GRAPHEME_IS_BREAK_SOFT)) { |
| 902 | end_pos -= l_gl[end_pos].count; |
| 903 | } |
| 904 | if (last_end <= l_gl[start_pos].start && l_gl[start_pos].start != l_gl[end_pos].end) { |
| 905 | lines.push_back(l_gl[start_pos].start); |
| 906 | lines.push_back(l_gl[end_pos].end); |
| 907 | cur_safe_brk = last_safe_break; |
| 908 | last_end = l_gl[end_pos].end; |
| 909 | } |
| 910 | trim_next = true; |
| 911 | } else { |
| 912 | if (last_end <= line_start) { |
| 913 | lines.push_back(line_start); |
| 914 | lines.push_back(l_gl[last_safe_break].end); |
| 915 | last_end = l_gl[last_safe_break].end; |
| 916 | } |
| 917 | } |
| 918 | line_start = l_gl[cur_safe_brk].end; |
| 919 | prev_safe_break = cur_safe_brk + 1; |
| 920 | while (prev_safe_break < l_size && l_gl[prev_safe_break].end == line_start) { |
| 921 | prev_safe_break++; |
| 922 | } |
| 923 | i = cur_safe_brk; |
| 924 | last_safe_break = -1; |
| 925 | width = 0; |
| 926 | word_count = 0; |
| 927 | chunk++; |
| 928 | if (chunk >= p_width.size()) { |
| 929 | chunk = 0; |
| 930 | if (p_once) { |
| 931 | return lines; |
| 932 | } |
| 933 | } |
| 934 | continue; |
| 935 | } |
| 936 | if (p_break_flags.has_flag(BREAK_MANDATORY)) { |
| 937 | if ((l_gl[i].flags & GRAPHEME_IS_BREAK_HARD) == GRAPHEME_IS_BREAK_HARD) { |
| 938 | int cur_safe_brk = i; |
| 939 | if (p_break_flags.has_flag(BREAK_TRIM_START_EDGE_SPACES) || p_break_flags.has_flag(BREAK_TRIM_END_EDGE_SPACES)) { |
| 940 | int start_pos = prev_safe_break; |
| 941 | int end_pos = i; |
| 942 | while (p_break_flags.has_flag(BREAK_TRIM_START_EDGE_SPACES) && trim_next && (start_pos < end_pos) && ((l_gl[start_pos].flags & GRAPHEME_IS_SPACE) == GRAPHEME_IS_SPACE || (l_gl[start_pos].flags & GRAPHEME_IS_BREAK_HARD) == GRAPHEME_IS_BREAK_HARD || (l_gl[start_pos].flags & GRAPHEME_IS_BREAK_SOFT) == GRAPHEME_IS_BREAK_SOFT)) { |
| 943 | start_pos += l_gl[start_pos].count; |
| 944 | } |
| 945 | while (p_break_flags.has_flag(BREAK_TRIM_END_EDGE_SPACES) && (start_pos <= end_pos) && (end_pos > 0) && ((l_gl[end_pos].flags & GRAPHEME_IS_SPACE) == GRAPHEME_IS_SPACE || (l_gl[end_pos].flags & GRAPHEME_IS_BREAK_HARD) == GRAPHEME_IS_BREAK_HARD || (l_gl[end_pos].flags & GRAPHEME_IS_BREAK_SOFT) == GRAPHEME_IS_BREAK_SOFT)) { |
| 946 | end_pos -= l_gl[end_pos].count; |
| 947 | } |
| 948 | if (last_end <= l_gl[start_pos].start && l_gl[start_pos].start != l_gl[end_pos].end) { |
| 949 | lines.push_back(l_gl[start_pos].start); |
| 950 | lines.push_back(l_gl[end_pos].end); |
| 951 | last_end = l_gl[i].end; |
| 952 | cur_safe_brk = i; |
| 953 | } |
| 954 | trim_next = true; |
| 955 | } else { |
| 956 | if (last_end <= line_start) { |
| 957 | lines.push_back(line_start); |
| 958 | lines.push_back(l_gl[i].end); |
| 959 | last_end = l_gl[i].end; |
| 960 | } |
| 961 | } |
| 962 | line_start = l_gl[cur_safe_brk].end; |
| 963 | prev_safe_break = cur_safe_brk + 1; |
| 964 | while (prev_safe_break < l_size && l_gl[prev_safe_break].end == line_start) { |
| 965 | prev_safe_break++; |
| 966 | } |
| 967 | last_safe_break = -1; |
| 968 | width = 0; |
| 969 | chunk = 0; |
| 970 | if (p_once) { |
| 971 | return lines; |
| 972 | } |
| 973 | continue; |
| 974 | } |
| 975 | } |
| 976 | if (p_break_flags.has_flag(BREAK_WORD_BOUND)) { |
| 977 | if ((l_gl[i].flags & GRAPHEME_IS_BREAK_SOFT) == GRAPHEME_IS_BREAK_SOFT) { |
| 978 | if ((l_gl[i].flags & GRAPHEME_IS_SOFT_HYPHEN) == GRAPHEME_IS_SOFT_HYPHEN) { |
| 979 | uint32_t gl = font_get_glyph_index(l_gl[i].font_rid, l_gl[i].font_size, 0x00ad, 0); |
| 980 | float w = font_get_glyph_advance(l_gl[i].font_rid, l_gl[i].font_size, gl)[(orientation == ORIENTATION_HORIZONTAL) ? 0 : 1]; |
| 981 | if (width + adv + w <= p_width[chunk] || w >= p_width[chunk]) { |
| 982 | last_safe_break = i; |
| 983 | word_count++; |
| 984 | } |
| 985 | } else if (i >= indent_end) { |
| 986 | last_safe_break = i; |
| 987 | word_count++; |
| 988 | } |
| 989 | } |
| 990 | } |
| 991 | if (p_break_flags.has_flag(BREAK_GRAPHEME_BOUND) && word_count == 0) { |
| 992 | last_safe_break = i; |
| 993 | } |
| 994 | } |
| 995 | width += l_gl[i].advance * l_gl[i].repeat; |
| 996 | } |
| 997 | |
| 998 | if (l_size > 0) { |
| 999 | if (lines.is_empty() || (lines[lines.size() - 1] < range.y && prev_safe_break < l_size)) { |
| 1000 | if (p_break_flags.has_flag(BREAK_TRIM_START_EDGE_SPACES)) { |
| 1001 | int start_pos = (prev_safe_break < l_size) ? prev_safe_break : l_size - 1; |
| 1002 | if (last_end <= l_gl[start_pos].start) { |
| 1003 | int end_pos = l_size - 1; |
| 1004 | while (trim_next && (start_pos < end_pos) && ((l_gl[start_pos].flags & GRAPHEME_IS_SPACE) == GRAPHEME_IS_SPACE || (l_gl[start_pos].flags & GRAPHEME_IS_BREAK_HARD) == GRAPHEME_IS_BREAK_HARD || (l_gl[start_pos].flags & GRAPHEME_IS_BREAK_SOFT) == GRAPHEME_IS_BREAK_SOFT)) { |
| 1005 | start_pos += l_gl[start_pos].count; |
| 1006 | } |
| 1007 | lines.push_back(l_gl[start_pos].start); |
| 1008 | } else { |
| 1009 | lines.push_back(last_end); |
| 1010 | } |
| 1011 | } else { |
| 1012 | lines.push_back(MAX(last_end, line_start)); |
| 1013 | } |
| 1014 | lines.push_back(range.y); |
| 1015 | } |
| 1016 | } else { |
| 1017 | lines.push_back(0); |
| 1018 | lines.push_back(0); |
| 1019 | } |
| 1020 | |
| 1021 | return lines; |
| 1022 | } |
| 1023 | |
| 1024 | PackedInt32Array TextServer::shaped_text_get_line_breaks(const RID &p_shaped, double p_width, int64_t p_start, BitField<TextServer::LineBreakFlag> p_break_flags) const { |
| 1025 | PackedInt32Array lines; |
| 1026 | |
| 1027 | const_cast<TextServer *>(this)->shaped_text_update_breaks(p_shaped); |
| 1028 | const Vector2i &range = shaped_text_get_range(p_shaped); |
| 1029 | |
| 1030 | double width = 0.f; |
| 1031 | int line_start = MAX(p_start, range.x); |
| 1032 | int last_end = line_start; |
| 1033 | int prev_safe_break = 0; |
| 1034 | int last_safe_break = -1; |
| 1035 | int word_count = 0; |
| 1036 | bool trim_next = false; |
| 1037 | |
| 1038 | #ifndef DISABLE_DEPRECATED |
| 1039 | if (p_break_flags.has_flag(BREAK_TRIM_EDGE_SPACES)) { |
| 1040 | p_break_flags = p_break_flags | BREAK_TRIM_START_EDGE_SPACES | BREAK_TRIM_END_EDGE_SPACES; |
| 1041 | } |
| 1042 | #endif |
| 1043 | |
| 1044 | TextServer::Orientation orientation = shaped_text_get_orientation(p_shaped); |
| 1045 | int l_size = shaped_text_get_glyph_count(p_shaped); |
| 1046 | const Glyph *l_gl = const_cast<TextServer *>(this)->shaped_text_sort_logical(p_shaped); |
| 1047 | |
| 1048 | int indent_end = 0; |
| 1049 | double indent = 0.0; |
| 1050 | if (p_break_flags.has_flag(BREAK_TRIM_INDENT)) { |
| 1051 | for (int i = 0; i < l_size; i++) { |
| 1052 | if ((l_gl[i].flags & GRAPHEME_IS_TAB) == GRAPHEME_IS_TAB || (l_gl[i].flags & GRAPHEME_IS_SPACE) == GRAPHEME_IS_SPACE) { |
| 1053 | if (indent + l_gl[i].advance * l_gl[i].repeat > p_width) { |
| 1054 | indent = 0.0; |
| 1055 | } |
| 1056 | indent += l_gl[i].advance * l_gl[i].repeat; |
| 1057 | indent_end = l_gl[i].end; |
| 1058 | } else { |
| 1059 | break; |
| 1060 | } |
| 1061 | } |
| 1062 | indent = MIN(indent, 0.6 * p_width); |
| 1063 | } |
| 1064 | |
| 1065 | double l_width = p_width; |
| 1066 | for (int i = 0; i < l_size; i++) { |
| 1067 | if (l_gl[i].start < p_start) { |
| 1068 | prev_safe_break = i + 1; |
| 1069 | continue; |
| 1070 | } |
| 1071 | if (l_gl[i].count > 0) { |
| 1072 | float adv = 0.0; |
| 1073 | for (int j = i; j < l_size && l_gl[i].end == l_gl[j].end && l_gl[i].start == l_gl[j].start; j++) { |
| 1074 | adv += l_gl[j].advance * l_gl[j].repeat; |
| 1075 | } |
| 1076 | if ((l_width > 0) && (width + adv > l_width) && (last_safe_break >= 0)) { |
| 1077 | int cur_safe_brk = last_safe_break; |
| 1078 | if (p_break_flags.has_flag(BREAK_TRIM_START_EDGE_SPACES) || p_break_flags.has_flag(BREAK_TRIM_END_EDGE_SPACES)) { |
| 1079 | int start_pos = prev_safe_break; |
| 1080 | int end_pos = last_safe_break; |
| 1081 | while (p_break_flags.has_flag(BREAK_TRIM_START_EDGE_SPACES) && trim_next && (start_pos < end_pos) && ((l_gl[start_pos].flags & GRAPHEME_IS_SOFT_HYPHEN) != GRAPHEME_IS_SOFT_HYPHEN) && ((l_gl[start_pos].flags & GRAPHEME_IS_SPACE) == GRAPHEME_IS_SPACE || (l_gl[start_pos].flags & GRAPHEME_IS_BREAK_HARD) == GRAPHEME_IS_BREAK_HARD || (l_gl[start_pos].flags & GRAPHEME_IS_BREAK_SOFT) == GRAPHEME_IS_BREAK_SOFT)) { |
| 1082 | start_pos += l_gl[start_pos].count; |
| 1083 | } |
| 1084 | while (p_break_flags.has_flag(BREAK_TRIM_END_EDGE_SPACES) && (start_pos <= end_pos) && (end_pos > 0) && ((l_gl[end_pos].flags & GRAPHEME_IS_SOFT_HYPHEN) != GRAPHEME_IS_SOFT_HYPHEN) && ((l_gl[end_pos].flags & GRAPHEME_IS_SPACE) == GRAPHEME_IS_SPACE || (l_gl[end_pos].flags & GRAPHEME_IS_BREAK_HARD) == GRAPHEME_IS_BREAK_HARD || (l_gl[end_pos].flags & GRAPHEME_IS_BREAK_SOFT) == GRAPHEME_IS_BREAK_SOFT)) { |
| 1085 | end_pos -= l_gl[end_pos].count; |
| 1086 | } |
| 1087 | if (last_end <= l_gl[start_pos].start && l_gl[start_pos].start != l_gl[end_pos].end) { |
| 1088 | lines.push_back(l_gl[start_pos].start); |
| 1089 | lines.push_back(l_gl[end_pos].end); |
| 1090 | if (p_width > indent && i > indent_end) { |
| 1091 | l_width = p_width - indent; |
| 1092 | } |
| 1093 | cur_safe_brk = last_safe_break; |
| 1094 | last_end = l_gl[end_pos].end; |
| 1095 | } |
| 1096 | trim_next = true; |
| 1097 | } else { |
| 1098 | if (last_end <= line_start) { |
| 1099 | lines.push_back(line_start); |
| 1100 | lines.push_back(l_gl[last_safe_break].end); |
| 1101 | if (p_width > indent && i > indent_end) { |
| 1102 | l_width = p_width - indent; |
| 1103 | } |
| 1104 | last_end = l_gl[last_safe_break].end; |
| 1105 | } |
| 1106 | } |
| 1107 | line_start = l_gl[cur_safe_brk].end; |
| 1108 | prev_safe_break = cur_safe_brk + 1; |
| 1109 | while (prev_safe_break < l_size && l_gl[prev_safe_break].end == line_start) { |
| 1110 | prev_safe_break++; |
| 1111 | } |
| 1112 | i = cur_safe_brk; |
| 1113 | last_safe_break = -1; |
| 1114 | width = 0; |
| 1115 | word_count = 0; |
| 1116 | continue; |
| 1117 | } |
| 1118 | if (p_break_flags.has_flag(BREAK_MANDATORY)) { |
| 1119 | if ((l_gl[i].flags & GRAPHEME_IS_BREAK_HARD) == GRAPHEME_IS_BREAK_HARD) { |
| 1120 | int cur_safe_brk = i; |
| 1121 | if (p_break_flags.has_flag(BREAK_TRIM_START_EDGE_SPACES) || p_break_flags.has_flag(BREAK_TRIM_END_EDGE_SPACES)) { |
| 1122 | int start_pos = prev_safe_break; |
| 1123 | int end_pos = i; |
| 1124 | while (p_break_flags.has_flag(BREAK_TRIM_START_EDGE_SPACES) && trim_next && (start_pos < end_pos) && ((l_gl[start_pos].flags & GRAPHEME_IS_SPACE) == GRAPHEME_IS_SPACE || (l_gl[start_pos].flags & GRAPHEME_IS_BREAK_HARD) == GRAPHEME_IS_BREAK_HARD || (l_gl[start_pos].flags & GRAPHEME_IS_BREAK_SOFT) == GRAPHEME_IS_BREAK_SOFT)) { |
| 1125 | start_pos += l_gl[start_pos].count; |
| 1126 | } |
| 1127 | while (p_break_flags.has_flag(BREAK_TRIM_END_EDGE_SPACES) && (start_pos <= end_pos) && (end_pos > 0) && ((l_gl[end_pos].flags & GRAPHEME_IS_SPACE) == GRAPHEME_IS_SPACE || (l_gl[end_pos].flags & GRAPHEME_IS_BREAK_HARD) == GRAPHEME_IS_BREAK_HARD || (l_gl[end_pos].flags & GRAPHEME_IS_BREAK_SOFT) == GRAPHEME_IS_BREAK_SOFT)) { |
| 1128 | end_pos -= l_gl[end_pos].count; |
| 1129 | } |
| 1130 | trim_next = true; |
| 1131 | if (last_end <= l_gl[start_pos].start && l_gl[start_pos].start != l_gl[end_pos].end) { |
| 1132 | lines.push_back(l_gl[start_pos].start); |
| 1133 | lines.push_back(l_gl[end_pos].end); |
| 1134 | if (p_width > indent && i > indent_end) { |
| 1135 | l_width = p_width - indent; |
| 1136 | } |
| 1137 | last_end = l_gl[i].end; |
| 1138 | cur_safe_brk = i; |
| 1139 | } |
| 1140 | } else { |
| 1141 | if (last_end <= line_start) { |
| 1142 | lines.push_back(line_start); |
| 1143 | lines.push_back(l_gl[i].end); |
| 1144 | if (p_width > indent && i > indent_end) { |
| 1145 | l_width = p_width - indent; |
| 1146 | } |
| 1147 | last_end = l_gl[i].end; |
| 1148 | } |
| 1149 | } |
| 1150 | line_start = l_gl[cur_safe_brk].end; |
| 1151 | prev_safe_break = cur_safe_brk + 1; |
| 1152 | while (prev_safe_break < l_size && l_gl[prev_safe_break].end == line_start) { |
| 1153 | prev_safe_break++; |
| 1154 | } |
| 1155 | last_safe_break = -1; |
| 1156 | width = 0; |
| 1157 | continue; |
| 1158 | } |
| 1159 | } |
| 1160 | if (p_break_flags.has_flag(BREAK_WORD_BOUND)) { |
| 1161 | if ((l_gl[i].flags & GRAPHEME_IS_BREAK_SOFT) == GRAPHEME_IS_BREAK_SOFT) { |
| 1162 | if ((l_gl[i].flags & GRAPHEME_IS_SOFT_HYPHEN) == GRAPHEME_IS_SOFT_HYPHEN) { |
| 1163 | uint32_t gl = font_get_glyph_index(l_gl[i].font_rid, l_gl[i].font_size, 0x00AD, 0); |
| 1164 | float w = font_get_glyph_advance(l_gl[i].font_rid, l_gl[i].font_size, gl)[(orientation == ORIENTATION_HORIZONTAL) ? 0 : 1]; |
| 1165 | if (width + adv + w <= p_width || w >= p_width) { |
| 1166 | last_safe_break = i; |
| 1167 | word_count++; |
| 1168 | } |
| 1169 | } else if (i >= indent_end) { |
| 1170 | last_safe_break = i; |
| 1171 | word_count++; |
| 1172 | } |
| 1173 | } |
| 1174 | if (p_break_flags.has_flag(BREAK_ADAPTIVE) && word_count == 0) { |
| 1175 | last_safe_break = i; |
| 1176 | } |
| 1177 | } |
| 1178 | if (p_break_flags.has_flag(BREAK_GRAPHEME_BOUND)) { |
| 1179 | last_safe_break = i; |
| 1180 | } |
| 1181 | } |
| 1182 | width += l_gl[i].advance * l_gl[i].repeat; |
| 1183 | } |
| 1184 | |
| 1185 | if (l_size > 0) { |
| 1186 | if (lines.is_empty() || (lines[lines.size() - 1] < range.y && prev_safe_break < l_size)) { |
| 1187 | if (p_break_flags.has_flag(BREAK_TRIM_START_EDGE_SPACES)) { |
| 1188 | int start_pos = (prev_safe_break < l_size) ? prev_safe_break : l_size - 1; |
| 1189 | if (last_end <= l_gl[start_pos].start) { |
| 1190 | int end_pos = l_size - 1; |
| 1191 | while (trim_next && (start_pos < end_pos) && ((l_gl[start_pos].flags & GRAPHEME_IS_SPACE) == GRAPHEME_IS_SPACE || (l_gl[start_pos].flags & GRAPHEME_IS_BREAK_HARD) == GRAPHEME_IS_BREAK_HARD || (l_gl[start_pos].flags & GRAPHEME_IS_BREAK_SOFT) == GRAPHEME_IS_BREAK_SOFT)) { |
| 1192 | start_pos += l_gl[start_pos].count; |
| 1193 | } |
| 1194 | lines.push_back(l_gl[start_pos].start); |
| 1195 | } else { |
| 1196 | lines.push_back(last_end); |
| 1197 | } |
| 1198 | } else { |
| 1199 | lines.push_back(MAX(last_end, line_start)); |
| 1200 | } |
| 1201 | lines.push_back(range.y); |
| 1202 | } |
| 1203 | } else { |
| 1204 | lines.push_back(0); |
| 1205 | lines.push_back(0); |
| 1206 | } |
| 1207 | |
| 1208 | return lines; |
| 1209 | } |
| 1210 | |
| 1211 | PackedInt32Array TextServer::shaped_text_get_word_breaks(const RID &p_shaped, BitField<TextServer::GraphemeFlag> p_grapheme_flags, BitField<TextServer::GraphemeFlag> p_skip_grapheme_flags) const { |
| 1212 | PackedInt32Array words; |
| 1213 | |
| 1214 | const_cast<TextServer *>(this)->shaped_text_update_justification_ops(p_shaped); |
| 1215 | const Vector2i &range = shaped_text_get_range(p_shaped); |
| 1216 | |
| 1217 | int word_start = range.x; |
| 1218 | |
| 1219 | const int l_size = shaped_text_get_glyph_count(p_shaped); |
| 1220 | const Glyph *l_gl = const_cast<TextServer *>(this)->shaped_text_sort_logical(p_shaped); |
| 1221 | |
| 1222 | for (int i = 0; i < l_size; i++) { |
| 1223 | if (l_gl[i].count > 0) { |
| 1224 | if ((l_gl[i].flags & p_grapheme_flags) != 0 && (l_gl[i].flags & p_skip_grapheme_flags) == 0) { |
| 1225 | int next = (i == 0) ? l_gl[i].start : l_gl[i - 1].end; |
| 1226 | if (word_start < next) { |
| 1227 | words.push_back(word_start); |
| 1228 | words.push_back(next); |
| 1229 | } |
| 1230 | word_start = l_gl[i].end; |
| 1231 | } |
| 1232 | } |
| 1233 | } |
| 1234 | if (l_size > 0) { |
| 1235 | if (word_start != range.y) { |
| 1236 | words.push_back(word_start); |
| 1237 | words.push_back(range.y); |
| 1238 | } |
| 1239 | } |
| 1240 | |
| 1241 | return words; |
| 1242 | } |
| 1243 | |
| 1244 | CaretInfo TextServer::shaped_text_get_carets(const RID &p_shaped, int64_t p_position) const { |
| 1245 | Vector<Rect2> carets; |
| 1246 | |
| 1247 | TextServer::Orientation orientation = shaped_text_get_orientation(p_shaped); |
| 1248 | const Vector2 &range = shaped_text_get_range(p_shaped); |
| 1249 | real_t ascent = shaped_text_get_ascent(p_shaped); |
| 1250 | real_t descent = shaped_text_get_descent(p_shaped); |
| 1251 | real_t height = (ascent + descent) / 2; |
| 1252 | |
| 1253 | real_t off = 0.0f; |
| 1254 | real_t obj_off = -1.0f; |
| 1255 | CaretInfo caret; |
| 1256 | caret.l_dir = DIRECTION_AUTO; |
| 1257 | caret.t_dir = DIRECTION_AUTO; |
| 1258 | |
| 1259 | int v_size = shaped_text_get_glyph_count(p_shaped); |
| 1260 | const Glyph *glyphs = shaped_text_get_glyphs(p_shaped); |
| 1261 | |
| 1262 | for (int i = 0; i < v_size; i++) { |
| 1263 | if (glyphs[i].count > 0) { |
| 1264 | // Skip inline objects. |
| 1265 | if ((glyphs[i].flags & GRAPHEME_IS_EMBEDDED_OBJECT) == GRAPHEME_IS_EMBEDDED_OBJECT && glyphs[i].start == glyphs[i].end) { |
| 1266 | obj_off = glyphs[i].advance; |
| 1267 | continue; |
| 1268 | } |
| 1269 | // Caret before grapheme (top / left). |
| 1270 | if (p_position == glyphs[i].start && ((glyphs[i].flags & GRAPHEME_IS_VIRTUAL) != GRAPHEME_IS_VIRTUAL)) { |
| 1271 | real_t advance = 0.f; |
| 1272 | for (int j = 0; j < glyphs[i].count; j++) { |
| 1273 | advance += glyphs[i + j].advance * glyphs[i + j].repeat; |
| 1274 | } |
| 1275 | real_t char_adv = advance / (real_t)(glyphs[i].end - glyphs[i].start); |
| 1276 | Rect2 cr; |
| 1277 | if (orientation == ORIENTATION_HORIZONTAL) { |
| 1278 | if (glyphs[i].start == range.x) { |
| 1279 | cr.size.y = height * 2; |
| 1280 | } else { |
| 1281 | cr.size.y = height; |
| 1282 | } |
| 1283 | cr.position.y = -ascent; |
| 1284 | cr.position.x = off; |
| 1285 | if ((glyphs[i].flags & GRAPHEME_IS_RTL) == GRAPHEME_IS_RTL) { |
| 1286 | caret.t_dir = DIRECTION_RTL; |
| 1287 | cr.position.x += advance; |
| 1288 | cr.size.x = -char_adv; |
| 1289 | } else { |
| 1290 | caret.t_dir = DIRECTION_LTR; |
| 1291 | cr.size.x = char_adv; |
| 1292 | } |
| 1293 | } else { |
| 1294 | if (glyphs[i].start == range.x) { |
| 1295 | cr.size.x = height * 2; |
| 1296 | } else { |
| 1297 | cr.size.x = height; |
| 1298 | } |
| 1299 | cr.position.x = -ascent; |
| 1300 | cr.position.y = off; |
| 1301 | if ((glyphs[i].flags & GRAPHEME_IS_RTL) == GRAPHEME_IS_RTL) { |
| 1302 | caret.t_dir = DIRECTION_RTL; |
| 1303 | cr.position.y += advance; |
| 1304 | cr.size.y = -char_adv; |
| 1305 | } else { |
| 1306 | caret.t_dir = DIRECTION_LTR; |
| 1307 | cr.size.y = char_adv; |
| 1308 | } |
| 1309 | } |
| 1310 | caret.t_caret = cr; |
| 1311 | } |
| 1312 | // Caret after grapheme (bottom / right). |
| 1313 | if (p_position == glyphs[i].end && ((glyphs[i].flags & GRAPHEME_IS_VIRTUAL) != GRAPHEME_IS_VIRTUAL)) { |
| 1314 | real_t advance = 0.f; |
| 1315 | for (int j = 0; j < glyphs[i].count; j++) { |
| 1316 | advance += glyphs[i + j].advance * glyphs[i + j].repeat; |
| 1317 | } |
| 1318 | real_t char_adv = advance / (real_t)(glyphs[i].end - glyphs[i].start); |
| 1319 | Rect2 cr; |
| 1320 | if (orientation == ORIENTATION_HORIZONTAL) { |
| 1321 | if (glyphs[i].end == range.y) { |
| 1322 | cr.size.y = height * 2; |
| 1323 | cr.position.y = -ascent; |
| 1324 | } else { |
| 1325 | cr.size.y = height; |
| 1326 | cr.position.y = -ascent + height; |
| 1327 | } |
| 1328 | cr.position.x = off; |
| 1329 | if ((glyphs[i].flags & GRAPHEME_IS_RTL) != GRAPHEME_IS_RTL) { |
| 1330 | caret.l_dir = DIRECTION_LTR; |
| 1331 | cr.position.x += advance; |
| 1332 | cr.size.x = -char_adv; |
| 1333 | } else { |
| 1334 | caret.l_dir = DIRECTION_RTL; |
| 1335 | cr.size.x = char_adv; |
| 1336 | } |
| 1337 | } else { |
| 1338 | cr.size.y = 1.0f; |
| 1339 | if (glyphs[i].end == range.y) { |
| 1340 | cr.size.x = height * 2; |
| 1341 | cr.position.x = -ascent; |
| 1342 | } else { |
| 1343 | cr.size.x = height; |
| 1344 | cr.position.x = -ascent + height; |
| 1345 | } |
| 1346 | cr.position.y = off; |
| 1347 | if ((glyphs[i].flags & GRAPHEME_IS_RTL) != GRAPHEME_IS_RTL) { |
| 1348 | caret.l_dir = DIRECTION_LTR; |
| 1349 | cr.position.y += advance; |
| 1350 | cr.size.y = -char_adv; |
| 1351 | } else { |
| 1352 | caret.l_dir = DIRECTION_RTL; |
| 1353 | cr.position.x += advance; |
| 1354 | cr.size.y = char_adv; |
| 1355 | } |
| 1356 | } |
| 1357 | cr.position.x += MAX(0.0, obj_off); // Prevent split caret when on an inline object. |
| 1358 | caret.l_caret = cr; |
| 1359 | } |
| 1360 | // Caret inside grapheme (middle). |
| 1361 | if (p_position > glyphs[i].start && p_position < glyphs[i].end && (glyphs[i].flags & GRAPHEME_IS_VIRTUAL) != GRAPHEME_IS_VIRTUAL) { |
| 1362 | real_t advance = 0.f; |
| 1363 | for (int j = 0; j < glyphs[i].count; j++) { |
| 1364 | advance += glyphs[i + j].advance * glyphs[i + j].repeat; |
| 1365 | } |
| 1366 | real_t char_adv = advance / (real_t)(glyphs[i].end - glyphs[i].start); |
| 1367 | Rect2 cr; |
| 1368 | if (orientation == ORIENTATION_HORIZONTAL) { |
| 1369 | cr.size.y = height * 2; |
| 1370 | cr.position.y = -ascent; |
| 1371 | if ((glyphs[i].flags & GRAPHEME_IS_RTL) == GRAPHEME_IS_RTL) { |
| 1372 | cr.position.x = off + char_adv * (glyphs[i].end - p_position); |
| 1373 | cr.size.x = -char_adv; |
| 1374 | } else { |
| 1375 | cr.position.x = off + char_adv * (p_position - glyphs[i].start); |
| 1376 | cr.size.x = char_adv; |
| 1377 | } |
| 1378 | } else { |
| 1379 | cr.size.x = height * 2; |
| 1380 | cr.position.x = -ascent; |
| 1381 | if ((glyphs[i].flags & GRAPHEME_IS_RTL) == GRAPHEME_IS_RTL) { |
| 1382 | cr.position.y = off + char_adv * (glyphs[i].end - p_position); |
| 1383 | cr.size.y = -char_adv; |
| 1384 | } else { |
| 1385 | cr.position.y = off + char_adv * (p_position - glyphs[i].start); |
| 1386 | cr.size.y = char_adv; |
| 1387 | } |
| 1388 | } |
| 1389 | caret.t_caret = cr; |
| 1390 | caret.l_caret = cr; |
| 1391 | } |
| 1392 | } |
| 1393 | off += glyphs[i].advance * glyphs[i].repeat; |
| 1394 | if (obj_off >= 0.0) { |
| 1395 | off += obj_off; |
| 1396 | obj_off = -1.0; |
| 1397 | } |
| 1398 | } |
| 1399 | return caret; |
| 1400 | } |
| 1401 | |
| 1402 | Dictionary TextServer::_shaped_text_get_carets_wrapper(const RID &p_shaped, int64_t p_position) const { |
| 1403 | Dictionary ret; |
| 1404 | |
| 1405 | CaretInfo caret = shaped_text_get_carets(p_shaped, p_position); |
| 1406 | |
| 1407 | ret["leading_rect"] = caret.l_caret; |
| 1408 | ret["leading_direction"] = caret.l_dir; |
| 1409 | ret["trailing_rect"] = caret.t_caret; |
| 1410 | ret["trailing_direction"] = caret.t_dir; |
| 1411 | |
| 1412 | return ret; |
| 1413 | } |
| 1414 | |
| 1415 | TextServer::Direction TextServer::shaped_text_get_dominant_direction_in_range(const RID &p_shaped, int64_t p_start, int64_t p_end) const { |
| 1416 | if (p_start == p_end) { |
| 1417 | return DIRECTION_AUTO; |
| 1418 | } |
| 1419 | |
| 1420 | int start = MIN(p_start, p_end); |
| 1421 | int end = MAX(p_start, p_end); |
| 1422 | |
| 1423 | int rtl = 0; |
| 1424 | int ltr = 0; |
| 1425 | |
| 1426 | int v_size = shaped_text_get_glyph_count(p_shaped); |
| 1427 | const Glyph *glyphs = shaped_text_get_glyphs(p_shaped); |
| 1428 | |
| 1429 | for (int i = 0; i < v_size; i++) { |
| 1430 | if ((glyphs[i].end > start) && (glyphs[i].start < end)) { |
| 1431 | if (glyphs[i].count > 0) { |
| 1432 | if ((glyphs[i].flags & GRAPHEME_IS_RTL) == GRAPHEME_IS_RTL) { |
| 1433 | rtl++; |
| 1434 | } else { |
| 1435 | ltr++; |
| 1436 | } |
| 1437 | } |
| 1438 | } |
| 1439 | } |
| 1440 | if (ltr == rtl) { |
| 1441 | return DIRECTION_AUTO; |
| 1442 | } else if (ltr > rtl) { |
| 1443 | return DIRECTION_LTR; |
| 1444 | } else { |
| 1445 | return DIRECTION_RTL; |
| 1446 | } |
| 1447 | } |
| 1448 | |
| 1449 | _FORCE_INLINE_ void _push_range(Vector<Vector2> &r_vector, real_t p_start, real_t p_end) { |
| 1450 | if (!r_vector.is_empty() && Math::is_equal_approx(r_vector[r_vector.size() - 1].y, p_start, (real_t)UNIT_EPSILON)) { |
| 1451 | r_vector.write[r_vector.size() - 1].y = p_end; |
| 1452 | } else { |
| 1453 | r_vector.push_back(Vector2(p_start, p_end)); |
| 1454 | } |
| 1455 | } |
| 1456 | |
| 1457 | Vector<Vector2> TextServer::shaped_text_get_selection(const RID &p_shaped, int64_t p_start, int64_t p_end) const { |
| 1458 | Vector<Vector2> ranges; |
| 1459 | |
| 1460 | if (p_start == p_end) { |
| 1461 | return ranges; |
| 1462 | } |
| 1463 | |
| 1464 | int start = MIN(p_start, p_end); |
| 1465 | int end = MAX(p_start, p_end); |
| 1466 | |
| 1467 | int v_size = shaped_text_get_glyph_count(p_shaped); |
| 1468 | const Glyph *glyphs = shaped_text_get_glyphs(p_shaped); |
| 1469 | |
| 1470 | real_t off = 0.0f; |
| 1471 | for (int i = 0; i < v_size; i++) { |
| 1472 | for (int k = 0; k < glyphs[i].repeat; k++) { |
| 1473 | if ((glyphs[i].count > 0) && ((glyphs[i].index != 0) || ((glyphs[i].flags & GRAPHEME_IS_SPACE) == GRAPHEME_IS_SPACE))) { |
| 1474 | if (glyphs[i].start < end && glyphs[i].end > start) { |
| 1475 | // Grapheme fully in selection range. |
| 1476 | if (glyphs[i].start >= start && glyphs[i].end <= end) { |
| 1477 | real_t advance = 0.f; |
| 1478 | for (int j = 0; j < glyphs[i].count; j++) { |
| 1479 | advance += glyphs[i + j].advance; |
| 1480 | } |
| 1481 | _push_range(ranges, off, off + advance); |
| 1482 | } |
| 1483 | // Only start of grapheme is in selection range. |
| 1484 | if (glyphs[i].start >= start && glyphs[i].end > end) { |
| 1485 | real_t advance = 0.f; |
| 1486 | for (int j = 0; j < glyphs[i].count; j++) { |
| 1487 | advance += glyphs[i + j].advance; |
| 1488 | } |
| 1489 | real_t char_adv = advance / (real_t)(glyphs[i].end - glyphs[i].start); |
| 1490 | if ((glyphs[i].flags & GRAPHEME_IS_RTL) == GRAPHEME_IS_RTL) { |
| 1491 | _push_range(ranges, off + char_adv * (glyphs[i].end - end), off + advance); |
| 1492 | } else { |
| 1493 | _push_range(ranges, off, off + char_adv * (end - glyphs[i].start)); |
| 1494 | } |
| 1495 | } |
| 1496 | // Only end of grapheme is in selection range. |
| 1497 | if (glyphs[i].start < start && glyphs[i].end <= end) { |
| 1498 | real_t advance = 0.f; |
| 1499 | for (int j = 0; j < glyphs[i].count; j++) { |
| 1500 | advance += glyphs[i + j].advance; |
| 1501 | } |
| 1502 | real_t char_adv = advance / (real_t)(glyphs[i].end - glyphs[i].start); |
| 1503 | if ((glyphs[i].flags & GRAPHEME_IS_RTL) == GRAPHEME_IS_RTL) { |
| 1504 | _push_range(ranges, off, off + char_adv * (glyphs[i].end - start)); |
| 1505 | } else { |
| 1506 | _push_range(ranges, off + char_adv * (start - glyphs[i].start), off + advance); |
| 1507 | } |
| 1508 | } |
| 1509 | // Selection range is within grapheme. |
| 1510 | if (glyphs[i].start < start && glyphs[i].end > end) { |
| 1511 | real_t advance = 0.f; |
| 1512 | for (int j = 0; j < glyphs[i].count; j++) { |
| 1513 | advance += glyphs[i + j].advance; |
| 1514 | } |
| 1515 | real_t char_adv = advance / (real_t)(glyphs[i].end - glyphs[i].start); |
| 1516 | if ((glyphs[i].flags & GRAPHEME_IS_RTL) == GRAPHEME_IS_RTL) { |
| 1517 | _push_range(ranges, off + char_adv * (glyphs[i].end - end), off + char_adv * (glyphs[i].end - start)); |
| 1518 | } else { |
| 1519 | _push_range(ranges, off + char_adv * (start - glyphs[i].start), off + char_adv * (end - glyphs[i].start)); |
| 1520 | } |
| 1521 | } |
| 1522 | } |
| 1523 | } |
| 1524 | off += glyphs[i].advance; |
| 1525 | } |
| 1526 | } |
| 1527 | |
| 1528 | return ranges; |
| 1529 | } |
| 1530 | |
| 1531 | int64_t TextServer::shaped_text_hit_test_grapheme(const RID &p_shaped, double p_coords) const { |
| 1532 | // Exact grapheme hit test, return -1 if missed. |
| 1533 | double off = 0.0f; |
| 1534 | |
| 1535 | int v_size = shaped_text_get_glyph_count(p_shaped); |
| 1536 | const Glyph *glyphs = shaped_text_get_glyphs(p_shaped); |
| 1537 | |
| 1538 | for (int i = 0; i < v_size; i++) { |
| 1539 | for (int j = 0; j < glyphs[i].repeat; j++) { |
| 1540 | if (p_coords >= off && p_coords < off + glyphs[i].advance) { |
| 1541 | return i; |
| 1542 | } |
| 1543 | off += glyphs[i].advance; |
| 1544 | } |
| 1545 | } |
| 1546 | return -1; |
| 1547 | } |
| 1548 | |
| 1549 | int64_t TextServer::shaped_text_hit_test_position(const RID &p_shaped, double p_coords) const { |
| 1550 | int v_size = shaped_text_get_glyph_count(p_shaped); |
| 1551 | const Glyph *glyphs = shaped_text_get_glyphs(p_shaped); |
| 1552 | |
| 1553 | // Cursor placement hit test. |
| 1554 | |
| 1555 | // Place caret to the left of the leftmost grapheme, or to position 0 if string is empty. |
| 1556 | if (Math::floor(p_coords) <= 0) { |
| 1557 | if (v_size > 0) { |
| 1558 | if ((glyphs[0].flags & GRAPHEME_IS_RTL) == GRAPHEME_IS_RTL) { |
| 1559 | return glyphs[0].end; |
| 1560 | } else { |
| 1561 | return glyphs[0].start; |
| 1562 | } |
| 1563 | } else { |
| 1564 | return 0; |
| 1565 | } |
| 1566 | } |
| 1567 | |
| 1568 | // Place caret to the right of the rightmost grapheme, or to position 0 if string is empty. |
| 1569 | if (Math::ceil(p_coords) >= shaped_text_get_width(p_shaped)) { |
| 1570 | if (v_size > 0) { |
| 1571 | if ((glyphs[v_size - 1].flags & GRAPHEME_IS_RTL) == GRAPHEME_IS_RTL) { |
| 1572 | return glyphs[v_size - 1].start; |
| 1573 | } else { |
| 1574 | return glyphs[v_size - 1].end; |
| 1575 | } |
| 1576 | } else { |
| 1577 | return 0; |
| 1578 | } |
| 1579 | } |
| 1580 | |
| 1581 | real_t off = 0.0f; |
| 1582 | for (int i = 0; i < v_size; i++) { |
| 1583 | if (glyphs[i].count > 0) { |
| 1584 | real_t advance = 0.f; |
| 1585 | for (int j = 0; j < glyphs[i].count; j++) { |
| 1586 | advance += glyphs[i + j].advance * glyphs[i + j].repeat; |
| 1587 | } |
| 1588 | if (((glyphs[i].flags & GRAPHEME_IS_VIRTUAL) == GRAPHEME_IS_VIRTUAL) && (p_coords >= off && p_coords < off + advance)) { |
| 1589 | if ((glyphs[i].flags & GRAPHEME_IS_RTL) == GRAPHEME_IS_RTL) { |
| 1590 | return glyphs[i].end; |
| 1591 | } else { |
| 1592 | return glyphs[i].start; |
| 1593 | } |
| 1594 | } |
| 1595 | // Ligature, handle mid-grapheme hit. |
| 1596 | if (p_coords >= off && p_coords < off + advance && glyphs[i].end > glyphs[i].start + 1) { |
| 1597 | int cnt = glyphs[i].end - glyphs[i].start; |
| 1598 | real_t char_adv = advance / (real_t)(cnt); |
| 1599 | real_t sub_off = off; |
| 1600 | for (int j = 0; j < cnt; j++) { |
| 1601 | // Place caret to the left of clicked sub-grapheme. |
| 1602 | if (p_coords >= sub_off && p_coords < sub_off + char_adv / 2) { |
| 1603 | if ((glyphs[i].flags & GRAPHEME_IS_RTL) == GRAPHEME_IS_RTL) { |
| 1604 | return glyphs[i].end - j; |
| 1605 | } else { |
| 1606 | return glyphs[i].start + j; |
| 1607 | } |
| 1608 | } |
| 1609 | // Place caret to the right of clicked sub-grapheme. |
| 1610 | if (p_coords >= sub_off + char_adv / 2 && p_coords < sub_off + char_adv) { |
| 1611 | if ((glyphs[i].flags & GRAPHEME_IS_RTL) == GRAPHEME_IS_RTL) { |
| 1612 | return glyphs[i].start + (cnt - 1) - j; |
| 1613 | } else { |
| 1614 | return glyphs[i].end - (cnt - 1) + j; |
| 1615 | } |
| 1616 | } |
| 1617 | sub_off += char_adv; |
| 1618 | } |
| 1619 | } |
| 1620 | // Place caret to the left of clicked grapheme. |
| 1621 | if (p_coords >= off && p_coords < off + advance / 2) { |
| 1622 | if ((glyphs[i].flags & GRAPHEME_IS_RTL) == GRAPHEME_IS_RTL) { |
| 1623 | return glyphs[i].end; |
| 1624 | } else { |
| 1625 | return glyphs[i].start; |
| 1626 | } |
| 1627 | } |
| 1628 | // Place caret to the right of clicked grapheme. |
| 1629 | if (p_coords >= off + advance / 2 && p_coords < off + advance) { |
| 1630 | if ((glyphs[i].flags & GRAPHEME_IS_RTL) == GRAPHEME_IS_RTL) { |
| 1631 | return glyphs[i].start; |
| 1632 | } else { |
| 1633 | return glyphs[i].end; |
| 1634 | } |
| 1635 | } |
| 1636 | } |
| 1637 | off += glyphs[i].advance * glyphs[i].repeat; |
| 1638 | } |
| 1639 | |
| 1640 | return -1; |
| 1641 | } |
| 1642 | |
| 1643 | Vector2 TextServer::shaped_text_get_grapheme_bounds(const RID &p_shaped, int64_t p_pos) const { |
| 1644 | int v_size = shaped_text_get_glyph_count(p_shaped); |
| 1645 | const Glyph *glyphs = shaped_text_get_glyphs(p_shaped); |
| 1646 | |
| 1647 | real_t off = 0.0f; |
| 1648 | for (int i = 0; i < v_size; i++) { |
| 1649 | if ((glyphs[i].count > 0) && ((glyphs[i].index != 0) || ((glyphs[i].flags & GRAPHEME_IS_SPACE) == GRAPHEME_IS_SPACE))) { |
| 1650 | if (glyphs[i].start <= p_pos && glyphs[i].end >= p_pos) { |
| 1651 | real_t advance = 0.f; |
| 1652 | for (int j = 0; j < glyphs[i].count; j++) { |
| 1653 | advance += glyphs[i + j].advance; |
| 1654 | } |
| 1655 | return Vector2(off, off + advance); |
| 1656 | } |
| 1657 | } |
| 1658 | off += glyphs[i].advance * glyphs[i].repeat; |
| 1659 | } |
| 1660 | |
| 1661 | return Vector2(); |
| 1662 | } |
| 1663 | |
| 1664 | int64_t TextServer::shaped_text_next_grapheme_pos(const RID &p_shaped, int64_t p_pos) const { |
| 1665 | int v_size = shaped_text_get_glyph_count(p_shaped); |
| 1666 | const Glyph *glyphs = shaped_text_get_glyphs(p_shaped); |
| 1667 | for (int i = 0; i < v_size; i++) { |
| 1668 | if (p_pos >= glyphs[i].start && p_pos < glyphs[i].end) { |
| 1669 | return glyphs[i].end; |
| 1670 | } |
| 1671 | } |
| 1672 | return p_pos; |
| 1673 | } |
| 1674 | |
| 1675 | int64_t TextServer::shaped_text_prev_grapheme_pos(const RID &p_shaped, int64_t p_pos) const { |
| 1676 | int v_size = shaped_text_get_glyph_count(p_shaped); |
| 1677 | const Glyph *glyphs = shaped_text_get_glyphs(p_shaped); |
| 1678 | for (int i = 0; i < v_size; i++) { |
| 1679 | if (p_pos > glyphs[i].start && p_pos <= glyphs[i].end) { |
| 1680 | return glyphs[i].start; |
| 1681 | } |
| 1682 | } |
| 1683 | |
| 1684 | return p_pos; |
| 1685 | } |
| 1686 | |
| 1687 | int64_t TextServer::shaped_text_prev_character_pos(const RID &p_shaped, int64_t p_pos) const { |
| 1688 | const PackedInt32Array &chars = shaped_text_get_character_breaks(p_shaped); |
| 1689 | int64_t prev = shaped_text_get_range(p_shaped).x; |
| 1690 | for (const int32_t &E : chars) { |
| 1691 | if (E >= p_pos) { |
| 1692 | return prev; |
| 1693 | } |
| 1694 | prev = E; |
| 1695 | } |
| 1696 | return prev; |
| 1697 | } |
| 1698 | |
| 1699 | int64_t TextServer::shaped_text_next_character_pos(const RID &p_shaped, int64_t p_pos) const { |
| 1700 | const PackedInt32Array &chars = shaped_text_get_character_breaks(p_shaped); |
| 1701 | int64_t prev = shaped_text_get_range(p_shaped).x; |
| 1702 | for (const int32_t &E : chars) { |
| 1703 | if (E > p_pos) { |
| 1704 | return E; |
| 1705 | } |
| 1706 | prev = E; |
| 1707 | } |
| 1708 | return prev; |
| 1709 | } |
| 1710 | |
| 1711 | int64_t TextServer::shaped_text_closest_character_pos(const RID &p_shaped, int64_t p_pos) const { |
| 1712 | const PackedInt32Array &chars = shaped_text_get_character_breaks(p_shaped); |
| 1713 | int64_t prev = shaped_text_get_range(p_shaped).x; |
| 1714 | for (const int32_t &E : chars) { |
| 1715 | if (E == p_pos) { |
| 1716 | return E; |
| 1717 | } else if (E > p_pos) { |
| 1718 | if ((E - p_pos) < (p_pos - prev)) { |
| 1719 | return E; |
| 1720 | } else { |
| 1721 | return prev; |
| 1722 | } |
| 1723 | } |
| 1724 | prev = E; |
| 1725 | } |
| 1726 | return prev; |
| 1727 | } |
| 1728 | |
| 1729 | PackedInt32Array TextServer::string_get_character_breaks(const String &p_string, const String &p_language) const { |
| 1730 | PackedInt32Array ret; |
| 1731 | if (!p_string.is_empty()) { |
| 1732 | ret.resize(p_string.size() - 1); |
| 1733 | for (int i = 0; i < p_string.size() - 1; i++) { |
| 1734 | ret.write[i] = i + 1; |
| 1735 | } |
| 1736 | } |
| 1737 | return ret; |
| 1738 | } |
| 1739 | |
| 1740 | void TextServer::shaped_text_draw(const RID &p_shaped, const RID &p_canvas, const Vector2 &p_pos, double p_clip_l, double p_clip_r, const Color &p_color, float p_oversampling) const { |
| 1741 | TextServer::Orientation orientation = shaped_text_get_orientation(p_shaped); |
| 1742 | bool hex_codes = shaped_text_get_preserve_control(p_shaped) || shaped_text_get_preserve_invalid(p_shaped); |
| 1743 | |
| 1744 | bool rtl = shaped_text_get_direction(p_shaped) == DIRECTION_RTL; |
| 1745 | |
| 1746 | int ellipsis_pos = shaped_text_get_ellipsis_pos(p_shaped); |
| 1747 | int trim_pos = shaped_text_get_trim_pos(p_shaped); |
| 1748 | |
| 1749 | const Glyph *ellipsis_glyphs = shaped_text_get_ellipsis_glyphs(p_shaped); |
| 1750 | int ellipsis_gl_size = shaped_text_get_ellipsis_glyph_count(p_shaped); |
| 1751 | |
| 1752 | int v_size = shaped_text_get_glyph_count(p_shaped); |
| 1753 | const Glyph *glyphs = shaped_text_get_glyphs(p_shaped); |
| 1754 | |
| 1755 | Vector2 ofs; |
| 1756 | // Draw RTL ellipsis string when needed. |
| 1757 | if (rtl && ellipsis_pos >= 0) { |
| 1758 | for (int i = ellipsis_gl_size - 1; i >= 0; i--) { |
| 1759 | for (int j = 0; j < ellipsis_glyphs[i].repeat; j++) { |
| 1760 | font_draw_glyph(ellipsis_glyphs[i].font_rid, p_canvas, ellipsis_glyphs[i].font_size, ofs + p_pos + Vector2(ellipsis_glyphs[i].x_off, ellipsis_glyphs[i].y_off), ellipsis_glyphs[i].index, p_color, p_oversampling); |
| 1761 | if (orientation == ORIENTATION_HORIZONTAL) { |
| 1762 | ofs.x += ellipsis_glyphs[i].advance; |
| 1763 | } else { |
| 1764 | ofs.y += ellipsis_glyphs[i].advance; |
| 1765 | } |
| 1766 | } |
| 1767 | } |
| 1768 | } |
| 1769 | // Draw at the baseline. |
| 1770 | for (int i = 0; i < v_size; i++) { |
| 1771 | if (trim_pos >= 0) { |
| 1772 | if (rtl) { |
| 1773 | if (i < trim_pos) { |
| 1774 | continue; |
| 1775 | } |
| 1776 | } else { |
| 1777 | if (i >= trim_pos) { |
| 1778 | break; |
| 1779 | } |
| 1780 | } |
| 1781 | } |
| 1782 | for (int j = 0; j < glyphs[i].repeat; j++) { |
| 1783 | if (p_clip_r > 0) { |
| 1784 | // Clip right / bottom. |
| 1785 | if (orientation == ORIENTATION_HORIZONTAL) { |
| 1786 | if (ofs.x + glyphs[i].advance > p_clip_r) { |
| 1787 | return; |
| 1788 | } |
| 1789 | } else { |
| 1790 | if (ofs.y + glyphs[i].advance > p_clip_r) { |
| 1791 | return; |
| 1792 | } |
| 1793 | } |
| 1794 | } |
| 1795 | if (p_clip_l > 0) { |
| 1796 | // Clip left / top. |
| 1797 | if (orientation == ORIENTATION_HORIZONTAL) { |
| 1798 | if (ofs.x < p_clip_l) { |
| 1799 | ofs.x += glyphs[i].advance; |
| 1800 | continue; |
| 1801 | } |
| 1802 | } else { |
| 1803 | if (ofs.y < p_clip_l) { |
| 1804 | ofs.y += glyphs[i].advance; |
| 1805 | continue; |
| 1806 | } |
| 1807 | } |
| 1808 | } |
| 1809 | |
| 1810 | if (glyphs[i].font_rid != RID()) { |
| 1811 | font_draw_glyph(glyphs[i].font_rid, p_canvas, glyphs[i].font_size, ofs + p_pos + Vector2(glyphs[i].x_off, glyphs[i].y_off), glyphs[i].index, p_color, p_oversampling); |
| 1812 | } else if (hex_codes && ((glyphs[i].flags & GRAPHEME_IS_VIRTUAL) != GRAPHEME_IS_VIRTUAL) && ((glyphs[i].flags & GRAPHEME_IS_EMBEDDED_OBJECT) != GRAPHEME_IS_EMBEDDED_OBJECT)) { |
| 1813 | TextServer::draw_hex_code_box(p_canvas, glyphs[i].font_size, ofs + p_pos + Vector2(glyphs[i].x_off, glyphs[i].y_off), glyphs[i].index, p_color); |
| 1814 | } |
| 1815 | if (orientation == ORIENTATION_HORIZONTAL) { |
| 1816 | ofs.x += glyphs[i].advance; |
| 1817 | } else { |
| 1818 | ofs.y += glyphs[i].advance; |
| 1819 | } |
| 1820 | } |
| 1821 | } |
| 1822 | // Draw LTR ellipsis string when needed. |
| 1823 | if (!rtl && ellipsis_pos >= 0) { |
| 1824 | for (int i = 0; i < ellipsis_gl_size; i++) { |
| 1825 | for (int j = 0; j < ellipsis_glyphs[i].repeat; j++) { |
| 1826 | font_draw_glyph(ellipsis_glyphs[i].font_rid, p_canvas, ellipsis_glyphs[i].font_size, ofs + p_pos + Vector2(ellipsis_glyphs[i].x_off, ellipsis_glyphs[i].y_off), ellipsis_glyphs[i].index, p_color, p_oversampling); |
| 1827 | if (orientation == ORIENTATION_HORIZONTAL) { |
| 1828 | ofs.x += ellipsis_glyphs[i].advance; |
| 1829 | } else { |
| 1830 | ofs.y += ellipsis_glyphs[i].advance; |
| 1831 | } |
| 1832 | } |
| 1833 | } |
| 1834 | } |
| 1835 | } |
| 1836 | |
| 1837 | void TextServer::shaped_text_draw_outline(const RID &p_shaped, const RID &p_canvas, const Vector2 &p_pos, double p_clip_l, double p_clip_r, int64_t p_outline_size, const Color &p_color, float p_oversampling) const { |
| 1838 | TextServer::Orientation orientation = shaped_text_get_orientation(p_shaped); |
| 1839 | |
| 1840 | bool rtl = (shaped_text_get_inferred_direction(p_shaped) == DIRECTION_RTL); |
| 1841 | |
| 1842 | int ellipsis_pos = shaped_text_get_ellipsis_pos(p_shaped); |
| 1843 | int trim_pos = shaped_text_get_trim_pos(p_shaped); |
| 1844 | |
| 1845 | const Glyph *ellipsis_glyphs = shaped_text_get_ellipsis_glyphs(p_shaped); |
| 1846 | int ellipsis_gl_size = shaped_text_get_ellipsis_glyph_count(p_shaped); |
| 1847 | |
| 1848 | int v_size = shaped_text_get_glyph_count(p_shaped); |
| 1849 | const Glyph *glyphs = shaped_text_get_glyphs(p_shaped); |
| 1850 | |
| 1851 | Vector2 ofs; |
| 1852 | // Draw RTL ellipsis string when needed. |
| 1853 | if (rtl && ellipsis_pos >= 0) { |
| 1854 | for (int i = ellipsis_gl_size - 1; i >= 0; i--) { |
| 1855 | for (int j = 0; j < ellipsis_glyphs[i].repeat; j++) { |
| 1856 | font_draw_glyph_outline(ellipsis_glyphs[i].font_rid, p_canvas, ellipsis_glyphs[i].font_size, p_outline_size, ofs + p_pos + Vector2(ellipsis_glyphs[i].x_off, ellipsis_glyphs[i].y_off), ellipsis_glyphs[i].index, p_color, p_oversampling); |
| 1857 | if (orientation == ORIENTATION_HORIZONTAL) { |
| 1858 | ofs.x += ellipsis_glyphs[i].advance; |
| 1859 | } else { |
| 1860 | ofs.y += ellipsis_glyphs[i].advance; |
| 1861 | } |
| 1862 | } |
| 1863 | } |
| 1864 | } |
| 1865 | // Draw at the baseline. |
| 1866 | for (int i = 0; i < v_size; i++) { |
| 1867 | if (trim_pos >= 0) { |
| 1868 | if (rtl) { |
| 1869 | if (i < trim_pos) { |
| 1870 | continue; |
| 1871 | } |
| 1872 | } else { |
| 1873 | if (i >= trim_pos) { |
| 1874 | break; |
| 1875 | } |
| 1876 | } |
| 1877 | } |
| 1878 | for (int j = 0; j < glyphs[i].repeat; j++) { |
| 1879 | if (p_clip_r > 0) { |
| 1880 | // Clip right / bottom. |
| 1881 | if (orientation == ORIENTATION_HORIZONTAL) { |
| 1882 | if (ofs.x + glyphs[i].advance > p_clip_r) { |
| 1883 | return; |
| 1884 | } |
| 1885 | } else { |
| 1886 | if (ofs.y + glyphs[i].advance > p_clip_r) { |
| 1887 | return; |
| 1888 | } |
| 1889 | } |
| 1890 | } |
| 1891 | if (p_clip_l > 0) { |
| 1892 | // Clip left / top. |
| 1893 | if (orientation == ORIENTATION_HORIZONTAL) { |
| 1894 | if (ofs.x < p_clip_l) { |
| 1895 | ofs.x += glyphs[i].advance; |
| 1896 | continue; |
| 1897 | } |
| 1898 | } else { |
| 1899 | if (ofs.y < p_clip_l) { |
| 1900 | ofs.y += glyphs[i].advance; |
| 1901 | continue; |
| 1902 | } |
| 1903 | } |
| 1904 | } |
| 1905 | if (glyphs[i].font_rid != RID()) { |
| 1906 | font_draw_glyph_outline(glyphs[i].font_rid, p_canvas, glyphs[i].font_size, p_outline_size, ofs + p_pos + Vector2(glyphs[i].x_off, glyphs[i].y_off), glyphs[i].index, p_color, p_oversampling); |
| 1907 | } |
| 1908 | if (orientation == ORIENTATION_HORIZONTAL) { |
| 1909 | ofs.x += glyphs[i].advance; |
| 1910 | } else { |
| 1911 | ofs.y += glyphs[i].advance; |
| 1912 | } |
| 1913 | } |
| 1914 | } |
| 1915 | // Draw LTR ellipsis string when needed. |
| 1916 | if (!rtl && ellipsis_pos >= 0) { |
| 1917 | for (int i = 0; i < ellipsis_gl_size; i++) { |
| 1918 | for (int j = 0; j < ellipsis_glyphs[i].repeat; j++) { |
| 1919 | font_draw_glyph_outline(ellipsis_glyphs[i].font_rid, p_canvas, ellipsis_glyphs[i].font_size, p_outline_size, ofs + p_pos + Vector2(ellipsis_glyphs[i].x_off, ellipsis_glyphs[i].y_off), ellipsis_glyphs[i].index, p_color, p_oversampling); |
| 1920 | if (orientation == ORIENTATION_HORIZONTAL) { |
| 1921 | ofs.x += ellipsis_glyphs[i].advance; |
| 1922 | } else { |
| 1923 | ofs.y += ellipsis_glyphs[i].advance; |
| 1924 | } |
| 1925 | } |
| 1926 | } |
| 1927 | } |
| 1928 | } |
| 1929 | |
| 1930 | #ifdef DEBUG_ENABLED |
| 1931 | |
| 1932 | void TextServer::debug_print_glyph(int p_idx, const Glyph &p_glyph) const { |
| 1933 | String flags; |
| 1934 | if (p_glyph.flags & GRAPHEME_IS_VALID) { |
| 1935 | flags += "v"; |
| 1936 | } |
| 1937 | if (p_glyph.flags & GRAPHEME_IS_RTL) { |
| 1938 | flags += "R"; |
| 1939 | } |
| 1940 | if (p_glyph.flags & GRAPHEME_IS_VIRTUAL) { |
| 1941 | flags += "V"; |
| 1942 | } |
| 1943 | if (p_glyph.flags & GRAPHEME_IS_SPACE) { |
| 1944 | flags += "w"; |
| 1945 | } |
| 1946 | if (p_glyph.flags & GRAPHEME_IS_BREAK_HARD) { |
| 1947 | flags += "h"; |
| 1948 | } |
| 1949 | if (p_glyph.flags & GRAPHEME_IS_BREAK_SOFT) { |
| 1950 | flags += "s"; |
| 1951 | } |
| 1952 | if (p_glyph.flags & GRAPHEME_IS_TAB) { |
| 1953 | flags += "t"; |
| 1954 | } |
| 1955 | if (p_glyph.flags & GRAPHEME_IS_ELONGATION) { |
| 1956 | flags += "e"; |
| 1957 | } |
| 1958 | if (p_glyph.flags & GRAPHEME_IS_PUNCTUATION) { |
| 1959 | flags += "p"; |
| 1960 | } |
| 1961 | if (p_glyph.flags & GRAPHEME_IS_UNDERSCORE) { |
| 1962 | flags += "u"; |
| 1963 | } |
| 1964 | if (p_glyph.flags & GRAPHEME_IS_CONNECTED) { |
| 1965 | flags += "C"; |
| 1966 | } |
| 1967 | if (p_glyph.flags & GRAPHEME_IS_SAFE_TO_INSERT_TATWEEL) { |
| 1968 | flags += "S"; |
| 1969 | } |
| 1970 | if (p_glyph.flags & GRAPHEME_IS_EMBEDDED_OBJECT) { |
| 1971 | flags += "E"; |
| 1972 | } |
| 1973 | if (p_glyph.flags & GRAPHEME_IS_SOFT_HYPHEN) { |
| 1974 | flags += "h"; |
| 1975 | } |
| 1976 | print_line(vformat(" %d => range: %d-%d cnt:%d index:%x font:%x(%d) offset:%fx%f adv:%f rep:%d flags:%s", p_idx, p_glyph.start, p_glyph.end, p_glyph.count, p_glyph.index, p_glyph.font_rid.get_id(), p_glyph.font_size, p_glyph.x_off, p_glyph.y_off, p_glyph.advance, p_glyph.repeat, flags)); |
| 1977 | } |
| 1978 | |
| 1979 | void TextServer::shaped_text_debug_print(const RID &p_shaped) const { |
| 1980 | int ellipsis_pos = shaped_text_get_ellipsis_pos(p_shaped); |
| 1981 | int trim_pos = shaped_text_get_trim_pos(p_shaped); |
| 1982 | const Vector2i &range = shaped_text_get_range(p_shaped); |
| 1983 | int v_size = shaped_text_get_glyph_count(p_shaped); |
| 1984 | const Glyph *glyphs = shaped_text_get_glyphs(p_shaped); |
| 1985 | |
| 1986 | print_line(vformat("%x: range: %d-%d glyps: %d trim: %d ellipsis: %d", p_shaped.get_id(), range.x, range.y, v_size, trim_pos, ellipsis_pos)); |
| 1987 | |
| 1988 | for (int i = 0; i < v_size; i++) { |
| 1989 | debug_print_glyph(i, glyphs[i]); |
| 1990 | } |
| 1991 | } |
| 1992 | |
| 1993 | #endif // DEBUG_ENABLED |
| 1994 | |
| 1995 | void TextServer::_diacritics_map_add(const String &p_from, char32_t p_to) { |
| 1996 | for (int i = 0; i < p_from.size(); i++) { |
| 1997 | diacritics_map[p_from[i]] = p_to; |
| 1998 | } |
| 1999 | } |
| 2000 | |
| 2001 | void TextServer::_init_diacritics_map() { |
| 2002 | diacritics_map.clear(); |
| 2003 | |
| 2004 | // Latin. |
| 2005 | _diacritics_map_add(U"ÀÁÂÃÄÅĀĂĄǍǞǠǺȀȂȦḀẠẢẤẦẨẪẬẮẰẲẴẶ", U'A'); |
| 2006 | _diacritics_map_add(U"àáâãäåāăąǎǟǡǻȁȃȧḁẚạảấầẩẫậắằẳẵặ", U'a'); |
| 2007 | _diacritics_map_add(U"ǢǼ", U'Æ'); |
| 2008 | _diacritics_map_add(U"ǣǽ", U'æ'); |
| 2009 | _diacritics_map_add(U"ḂḄḆ", U'B'); |
| 2010 | _diacritics_map_add(U"ḃḅḇ", U'b'); |
| 2011 | _diacritics_map_add(U"ÇĆĈĊČḈ", U'C'); |
| 2012 | _diacritics_map_add(U"çćĉċčḉ", U'c'); |
| 2013 | _diacritics_map_add(U"ĎḊḌḎḐḒ", U'D'); |
| 2014 | _diacritics_map_add(U"ďḋḍḏḑḓ", U'd'); |
| 2015 | _diacritics_map_add(U"ÈÉÊËĒĔĖĘĚȆȨḔḖḘḚḜẸẺẼẾỀỂỄỆ", U'E'); |
| 2016 | _diacritics_map_add(U"èéêëēĕėęěȇȩḕḗḙḛḝẹẻẽếềểễệ", U'e'); |
| 2017 | _diacritics_map_add(U"Ḟ", U'F'); |
| 2018 | _diacritics_map_add(U"ḟ", U'f'); |
| 2019 | _diacritics_map_add(U"ĜĞĠĢǦǴḠ", U'G'); |
| 2020 | _diacritics_map_add(U"ĝğġģǧǵḡ", U'g'); |
| 2021 | _diacritics_map_add(U"ĤȞḢḤḦḨḪ", U'H'); |
| 2022 | _diacritics_map_add(U"ĥȟḣḥḧḩḫẖ", U'h'); |
| 2023 | _diacritics_map_add(U"ÌÍÎÏĨĪĬĮİǏȈȊḬḮỈỊ", U'I'); |
| 2024 | _diacritics_map_add(U"ìíîïĩīĭįıǐȉȋḭḯỉị", U'i'); |
| 2025 | _diacritics_map_add(U"Ĵ", U'J'); |
| 2026 | _diacritics_map_add(U"ĵ", U'j'); |
| 2027 | _diacritics_map_add(U"ĶǨḰḲḴ", U'K'); |
| 2028 | _diacritics_map_add(U"ķĸǩḱḳḵ", U'k'); |
| 2029 | _diacritics_map_add(U"ĹĻĽĿḶḸḺḼ", U'L'); |
| 2030 | _diacritics_map_add(U"ĺļľŀḷḹḻḽ", U'l'); |
| 2031 | _diacritics_map_add(U"ḾṀṂ", U'M'); |
| 2032 | _diacritics_map_add(U"ḿṁṃ", U'm'); |
| 2033 | _diacritics_map_add(U"ÑŃŅŇǸṄṆṈṊ", U'N'); |
| 2034 | _diacritics_map_add(U"ñńņňʼnǹṅṇṉṋ", U'n'); |
| 2035 | _diacritics_map_add(U"ÒÓÔÕÖŌŎŐƠǑǪǬȌȎȪȬȮȰṌṎṐṒỌỎỐỒỔỖỘỚỜỞỠỢ", U'O'); |
| 2036 | _diacritics_map_add(U"òóôõöōŏőơǒǫǭȍȏȫȭȯȱṍṏṑṓọỏốồổỗộớờởỡợ", U'o'); |
| 2037 | _diacritics_map_add(U"ṔṖ", U'P'); |
| 2038 | _diacritics_map_add(U"ṗṕ", U'p'); |
| 2039 | _diacritics_map_add(U"ŔŖŘȐȒṘṚṜṞ", U'R'); |
| 2040 | _diacritics_map_add(U"ŕŗřȑȓṙṛṝṟ", U'r'); |
| 2041 | _diacritics_map_add(U"ŚŜŞŠȘṠṢṤṦṨ", U'S'); |
| 2042 | _diacritics_map_add(U"śŝşšſșṡṣṥṧṩẛẜẝ", U's'); |
| 2043 | _diacritics_map_add(U"ŢŤȚṪṬṮṰ", U'T'); |
| 2044 | _diacritics_map_add(U"ţťțṫṭṯṱẗ", U't'); |
| 2045 | _diacritics_map_add(U"ÙÚÛÜŨŪŬŮŰŲƯǓǕǗǙǛȔȖṲṴṶṸṺỤỦỨỪỬỮỰ", U'U'); |
| 2046 | _diacritics_map_add(U"ùúûüũūŭůűųưǔǖǘǚǜȕȗṳṵṷṹṻụủứừửữự", U'u'); |
| 2047 | _diacritics_map_add(U"ṼṾ", U'V'); |
| 2048 | _diacritics_map_add(U"ṽṿ", U'v'); |
| 2049 | _diacritics_map_add(U"ŴẀẂẄẆẈ", U'W'); |
| 2050 | _diacritics_map_add(U"ŵẁẃẅẇẉẘ", U'w'); |
| 2051 | _diacritics_map_add(U"ẊẌ", U'X'); |
| 2052 | _diacritics_map_add(U"ẋẍ", U'x'); |
| 2053 | _diacritics_map_add(U"ÝŶẎỲỴỶỸỾ", U'Y'); |
| 2054 | _diacritics_map_add(U"ýÿŷẏẙỳỵỷỹỿ", U'y'); |
| 2055 | _diacritics_map_add(U"ŹŻŽẐẒẔ", U'Z'); |
| 2056 | _diacritics_map_add(U"źżžẑẓẕ", U'z'); |
| 2057 | |
| 2058 | // Greek. |
| 2059 | _diacritics_map_add(U"ΆἈἉἊἋἌἍἎἏᾈᾉᾊᾋᾌᾍᾎᾏᾸᾹᾺΆᾼ", U'Α'); |
| 2060 | _diacritics_map_add(U"άἀἁἂἃἄἅἆἇὰάᾀᾁᾂᾃᾄᾅᾆᾇᾰᾱᾲᾳᾴᾶᾷ", U'α'); |
| 2061 | _diacritics_map_add(U"ΈἘἙἚἛἜἝῈΈ", U'Ε'); |
| 2062 | _diacritics_map_add(U"έἐἑἒἓἔἕὲέ", U'ε'); |
| 2063 | _diacritics_map_add(U"ΉἨἩἪἫἬἭἮἯᾘᾙᾚᾛᾜᾝᾞᾟῊΉῌ", U'Η'); |
| 2064 | _diacritics_map_add(U"ήἠἡἢἣἤἥἦἧὴήᾐᾑᾒᾓᾔᾕᾖᾗῂῃῄῆῇ", U'η'); |
| 2065 | _diacritics_map_add(U"ΊΪἸἹἺἻἼἽἾἿῘῙῚΊ", U'Ι'); |
| 2066 | _diacritics_map_add(U"ίΐϊἰἱἲἳἴἵἶἷὶίῐῑῒΐῖῗ", U'ι'); |
| 2067 | _diacritics_map_add(U"ΌὈὉὊὋὌὍῸΌ", U'Ο'); |
| 2068 | _diacritics_map_add(U"όὀὁὂὃὄὅὸό", U'ο'); |
| 2069 | _diacritics_map_add(U"Ῥ", U'Ρ'); |
| 2070 | _diacritics_map_add(U"ῤῥ", U'ρ'); |
| 2071 | _diacritics_map_add(U"ΎΫϓϔὙὛὝὟῨῩῪΎ", U'Υ'); |
| 2072 | _diacritics_map_add(U"ΰϋύὐὑὒὓὔὕὖὗὺύῠῡῢΰῦῧ", U'υ'); |
| 2073 | _diacritics_map_add(U"ΏὨὩὪὫὬὭὮὯᾨᾩᾪᾫᾬᾭᾮᾯῺΏῼ", U'Ω'); |
| 2074 | _diacritics_map_add(U"ώὠὡὢὣὤὥὦὧὼώᾠᾡᾢᾣᾤᾥᾦᾧῲῳῴῶῷ", U'ω'); |
| 2075 | |
| 2076 | // Cyrillic. |
| 2077 | _diacritics_map_add(U"ӐӒ", U'А'); |
| 2078 | _diacritics_map_add(U"ӑӓ", U'а'); |
| 2079 | _diacritics_map_add(U"ЀЁӖ", U'Е'); |
| 2080 | _diacritics_map_add(U"ѐёӗ", U'е'); |
| 2081 | _diacritics_map_add(U"Ӛ", U'Ә'); |
| 2082 | _diacritics_map_add(U"ӛ", U'ә'); |
| 2083 | _diacritics_map_add(U"Ӝ", U'Ж'); |
| 2084 | _diacritics_map_add(U"ӝ", U'ж'); |
| 2085 | _diacritics_map_add(U"Ӟ", U'З'); |
| 2086 | _diacritics_map_add(U"ӟ", U'з'); |
| 2087 | _diacritics_map_add(U"Ѓ", U'Г'); |
| 2088 | _diacritics_map_add(U"ѓ", U'г'); |
| 2089 | _diacritics_map_add(U"Ї", U'І'); |
| 2090 | _diacritics_map_add(U"ї", U'і'); |
| 2091 | _diacritics_map_add(U"ЍӢӤЙ", U'И'); |
| 2092 | _diacritics_map_add(U"ѝӣӥй", U'и'); |
| 2093 | _diacritics_map_add(U"Ќ", U'К'); |
| 2094 | _diacritics_map_add(U"ќ", U'к'); |
| 2095 | _diacritics_map_add(U"Ӧ", U'О'); |
| 2096 | _diacritics_map_add(U"ӧ", U'о'); |
| 2097 | _diacritics_map_add(U"Ӫ", U'Ө'); |
| 2098 | _diacritics_map_add(U"ӫ", U'ө'); |
| 2099 | _diacritics_map_add(U"Ӭ", U'Э'); |
| 2100 | _diacritics_map_add(U"ӭ", U'э'); |
| 2101 | _diacritics_map_add(U"ЎӮӰӲ", U'У'); |
| 2102 | _diacritics_map_add(U"ўӯӱӳ", U'у'); |
| 2103 | _diacritics_map_add(U"Ӵ", U'Ч'); |
| 2104 | _diacritics_map_add(U"ӵ", U'ч'); |
| 2105 | _diacritics_map_add(U"Ӹ", U'Ы'); |
| 2106 | _diacritics_map_add(U"ӹ", U'ы'); |
| 2107 | } |
| 2108 | |
| 2109 | String TextServer::strip_diacritics(const String &p_string) const { |
| 2110 | String result; |
| 2111 | for (int i = 0; i < p_string.length(); i++) { |
| 2112 | if (p_string[i] < 0x02B0 || p_string[i] > 0x036F) { // Skip combining diacritics. |
| 2113 | if (diacritics_map.has(p_string[i])) { |
| 2114 | result += diacritics_map[p_string[i]]; |
| 2115 | } else { |
| 2116 | result += p_string[i]; |
| 2117 | } |
| 2118 | } |
| 2119 | } |
| 2120 | return result; |
| 2121 | } |
| 2122 | |
| 2123 | #ifndef DISABLE_DEPRECATED |
| 2124 | String TextServer::format_number(const String &p_string, const String &p_language) const { |
| 2125 | const StringName lang = p_language.is_empty() ? TranslationServer::get_singleton()->get_tool_locale() : p_language; |
| 2126 | return TranslationServer::get_singleton()->format_number(p_string, lang); |
| 2127 | } |
| 2128 | |
| 2129 | String TextServer::parse_number(const String &p_string, const String &p_language) const { |
| 2130 | const StringName lang = p_language.is_empty() ? TranslationServer::get_singleton()->get_tool_locale() : p_language; |
| 2131 | return TranslationServer::get_singleton()->parse_number(p_string, lang); |
| 2132 | } |
| 2133 | |
| 2134 | String TextServer::percent_sign(const String &p_language) const { |
| 2135 | const StringName lang = p_language.is_empty() ? TranslationServer::get_singleton()->get_tool_locale() : p_language; |
| 2136 | return TranslationServer::get_singleton()->get_percent_sign(lang); |
| 2137 | } |
| 2138 | #endif // DISABLE_DEPRECATED |
| 2139 | |
| 2140 | TypedArray<Vector3i> TextServer::parse_structured_text(StructuredTextParser p_parser_type, const Array &p_args, const String &p_text) const { |
| 2141 | TypedArray<Vector3i> ret; |
| 2142 | switch (p_parser_type) { |
| 2143 | case STRUCTURED_TEXT_URI: { |
| 2144 | int prev = 0; |
| 2145 | for (int i = 0; i < p_text.length(); i++) { |
| 2146 | if ((p_text[i] == '\\') || (p_text[i] == '/') || (p_text[i] == '.') || (p_text[i] == ':') || (p_text[i] == '&') || (p_text[i] == '=') || (p_text[i] == '@') || (p_text[i] == '?') || (p_text[i] == '#')) { |
| 2147 | if (prev != i) { |
| 2148 | ret.push_back(Vector3i(prev, i, TextServer::DIRECTION_AUTO)); |
| 2149 | } |
| 2150 | ret.push_back(Vector3i(i, i + 1, TextServer::DIRECTION_LTR)); |
| 2151 | prev = i + 1; |
| 2152 | } |
| 2153 | } |
| 2154 | if (prev != p_text.length()) { |
| 2155 | ret.push_back(Vector3i(prev, p_text.length(), TextServer::DIRECTION_AUTO)); |
| 2156 | } |
| 2157 | } break; |
| 2158 | case STRUCTURED_TEXT_FILE: { |
| 2159 | int prev = 0; |
| 2160 | for (int i = 0; i < p_text.length(); i++) { |
| 2161 | if ((p_text[i] == '\\') || (p_text[i] == '/') || (p_text[i] == ':')) { |
| 2162 | if (prev != i) { |
| 2163 | ret.push_back(Vector3i(prev, i, TextServer::DIRECTION_AUTO)); |
| 2164 | } |
| 2165 | ret.push_back(Vector3i(i, i + 1, TextServer::DIRECTION_LTR)); |
| 2166 | prev = i + 1; |
| 2167 | } |
| 2168 | } |
| 2169 | if (prev != p_text.length()) { |
| 2170 | ret.push_back(Vector3i(prev, p_text.length(), TextServer::DIRECTION_AUTO)); |
| 2171 | } |
| 2172 | } break; |
| 2173 | case STRUCTURED_TEXT_EMAIL: { |
| 2174 | bool local = true; |
| 2175 | int prev = 0; |
| 2176 | for (int i = 0; i < p_text.length(); i++) { |
| 2177 | if ((p_text[i] == '@') && local) { // Add full "local" as single context. |
| 2178 | local = false; |
| 2179 | ret.push_back(Vector3i(prev, i, TextServer::DIRECTION_AUTO)); |
| 2180 | ret.push_back(Vector3i(i, i + 1, TextServer::DIRECTION_LTR)); |
| 2181 | prev = i + 1; |
| 2182 | } else if (!local && (p_text[i] == '.')) { // Add each dot separated "domain" part as context. |
| 2183 | if (prev != i) { |
| 2184 | ret.push_back(Vector3i(prev, i, TextServer::DIRECTION_AUTO)); |
| 2185 | } |
| 2186 | ret.push_back(Vector3i(i, i + 1, TextServer::DIRECTION_LTR)); |
| 2187 | prev = i + 1; |
| 2188 | } |
| 2189 | } |
| 2190 | if (prev != p_text.length()) { |
| 2191 | ret.push_back(Vector3i(prev, p_text.length(), TextServer::DIRECTION_AUTO)); |
| 2192 | } |
| 2193 | } break; |
| 2194 | case STRUCTURED_TEXT_LIST: { |
| 2195 | if (p_args.size() == 1 && p_args[0].is_string()) { |
| 2196 | Vector<String> tags = p_text.split(String(p_args[0])); |
| 2197 | int prev = 0; |
| 2198 | for (int i = 0; i < tags.size(); i++) { |
| 2199 | if (prev != i) { |
| 2200 | ret.push_back(Vector3i(prev, prev + tags[i].length(), TextServer::DIRECTION_INHERITED)); |
| 2201 | } |
| 2202 | ret.push_back(Vector3i(prev + tags[i].length(), prev + tags[i].length() + 1, TextServer::DIRECTION_INHERITED)); |
| 2203 | prev = prev + tags[i].length() + 1; |
| 2204 | } |
| 2205 | } |
| 2206 | } break; |
| 2207 | case STRUCTURED_TEXT_GDSCRIPT: { |
| 2208 | bool in_string_literal = false; |
| 2209 | bool in_string_literal_single = false; |
| 2210 | bool in_id = false; |
| 2211 | |
| 2212 | int prev = 0; |
| 2213 | for (int i = 0; i < p_text.length(); i++) { |
| 2214 | char32_t c = p_text[i]; |
| 2215 | if (in_string_literal) { |
| 2216 | if (c == '\\') { |
| 2217 | i++; |
| 2218 | continue; // Skip escaped chars. |
| 2219 | } else if (c == '\"') { |
| 2220 | // String literal end, push string and ". |
| 2221 | if (prev != i) { |
| 2222 | ret.push_back(Vector3i(prev, i, TextServer::DIRECTION_AUTO)); |
| 2223 | } |
| 2224 | prev = i + 1; |
| 2225 | ret.push_back(Vector3i(i, i + 1, TextServer::DIRECTION_LTR)); |
| 2226 | in_string_literal = false; |
| 2227 | } |
| 2228 | } else if (in_string_literal_single) { |
| 2229 | if (c == '\\') { |
| 2230 | i++; |
| 2231 | continue; // Skip escaped chars. |
| 2232 | } else if (c == '\'') { |
| 2233 | // String literal end, push string and '. |
| 2234 | if (prev != i) { |
| 2235 | ret.push_back(Vector3i(prev, i, TextServer::DIRECTION_AUTO)); |
| 2236 | } |
| 2237 | prev = i + 1; |
| 2238 | ret.push_back(Vector3i(i, i + 1, TextServer::DIRECTION_LTR)); |
| 2239 | in_string_literal_single = false; |
| 2240 | } |
| 2241 | } else if (in_id) { |
| 2242 | if (!is_unicode_identifier_continue(c)) { |
| 2243 | // End of id, push id. |
| 2244 | if (prev != i) { |
| 2245 | ret.push_back(Vector3i(prev, i, TextServer::DIRECTION_AUTO)); |
| 2246 | } |
| 2247 | prev = i; |
| 2248 | in_id = false; |
| 2249 | } |
| 2250 | } else if (is_unicode_identifier_start(c)) { |
| 2251 | // Start of new id, push prev element. |
| 2252 | if (prev != i) { |
| 2253 | ret.push_back(Vector3i(prev, i, TextServer::DIRECTION_AUTO)); |
| 2254 | } |
| 2255 | prev = i; |
| 2256 | in_id = true; |
| 2257 | } else if (c == '\"') { |
| 2258 | // String literal start, push prev element and ". |
| 2259 | if (prev != i) { |
| 2260 | ret.push_back(Vector3i(prev, i, TextServer::DIRECTION_AUTO)); |
| 2261 | } |
| 2262 | prev = i + 1; |
| 2263 | ret.push_back(Vector3i(i, i + 1, TextServer::DIRECTION_LTR)); |
| 2264 | in_string_literal = true; |
| 2265 | } else if (c == '\'') { |
| 2266 | // String literal start, push prev element and '. |
| 2267 | if (prev != i) { |
| 2268 | ret.push_back(Vector3i(prev, i, TextServer::DIRECTION_AUTO)); |
| 2269 | } |
| 2270 | prev = i + 1; |
| 2271 | ret.push_back(Vector3i(i, i + 1, TextServer::DIRECTION_LTR)); |
| 2272 | in_string_literal_single = true; |
| 2273 | } else if (c == '#') { |
| 2274 | // Start of comment, push prev element and #, skip the rest of the text. |
| 2275 | if (prev != i) { |
| 2276 | ret.push_back(Vector3i(prev, i, TextServer::DIRECTION_AUTO)); |
| 2277 | } |
| 2278 | prev = p_text.length(); |
| 2279 | ret.push_back(Vector3i(i, p_text.length(), TextServer::DIRECTION_AUTO)); |
| 2280 | break; |
| 2281 | } |
| 2282 | } |
| 2283 | if (prev < p_text.length()) { |
| 2284 | ret.push_back(Vector3i(prev, p_text.length(), TextServer::DIRECTION_AUTO)); |
| 2285 | } |
| 2286 | } break; |
| 2287 | case STRUCTURED_TEXT_CUSTOM: |
| 2288 | case STRUCTURED_TEXT_DEFAULT: |
| 2289 | default: { |
| 2290 | ret.push_back(Vector3i(0, p_text.length(), TextServer::DIRECTION_INHERITED)); |
| 2291 | } |
| 2292 | } |
| 2293 | return ret; |
| 2294 | } |
| 2295 | |
| 2296 | TypedArray<Dictionary> TextServer::_shaped_text_get_glyphs_wrapper(const RID &p_shaped) const { |
| 2297 | TypedArray<Dictionary> ret; |
| 2298 | |
| 2299 | const Glyph *glyphs = shaped_text_get_glyphs(p_shaped); |
| 2300 | int gl_size = shaped_text_get_glyph_count(p_shaped); |
| 2301 | for (int i = 0; i < gl_size; i++) { |
| 2302 | Dictionary glyph; |
| 2303 | |
| 2304 | glyph["start"] = glyphs[i].start; |
| 2305 | glyph["end"] = glyphs[i].end; |
| 2306 | glyph["repeat"] = glyphs[i].repeat; |
| 2307 | glyph["count"] = glyphs[i].count; |
| 2308 | glyph["flags"] = glyphs[i].flags; |
| 2309 | glyph["offset"] = Vector2(glyphs[i].x_off, glyphs[i].y_off); |
| 2310 | glyph["advance"] = glyphs[i].advance; |
| 2311 | glyph["font_rid"] = glyphs[i].font_rid; |
| 2312 | glyph["font_size"] = glyphs[i].font_size; |
| 2313 | glyph["index"] = glyphs[i].index; |
| 2314 | |
| 2315 | ret.push_back(glyph); |
| 2316 | } |
| 2317 | |
| 2318 | return ret; |
| 2319 | } |
| 2320 | |
| 2321 | TypedArray<Dictionary> TextServer::_shaped_text_sort_logical_wrapper(const RID &p_shaped) { |
| 2322 | Array ret; |
| 2323 | |
| 2324 | const Glyph *glyphs = shaped_text_sort_logical(p_shaped); |
| 2325 | int gl_size = shaped_text_get_glyph_count(p_shaped); |
| 2326 | for (int i = 0; i < gl_size; i++) { |
| 2327 | Dictionary glyph; |
| 2328 | |
| 2329 | glyph["start"] = glyphs[i].start; |
| 2330 | glyph["end"] = glyphs[i].end; |
| 2331 | glyph["repeat"] = glyphs[i].repeat; |
| 2332 | glyph["count"] = glyphs[i].count; |
| 2333 | glyph["flags"] = glyphs[i].flags; |
| 2334 | glyph["offset"] = Vector2(glyphs[i].x_off, glyphs[i].y_off); |
| 2335 | glyph["advance"] = glyphs[i].advance; |
| 2336 | glyph["font_rid"] = glyphs[i].font_rid; |
| 2337 | glyph["font_size"] = glyphs[i].font_size; |
| 2338 | glyph["index"] = glyphs[i].index; |
| 2339 | |
| 2340 | ret.push_back(glyph); |
| 2341 | } |
| 2342 | |
| 2343 | return ret; |
| 2344 | } |
| 2345 | |
| 2346 | TypedArray<Dictionary> TextServer::_shaped_text_get_ellipsis_glyphs_wrapper(const RID &p_shaped) const { |
| 2347 | TypedArray<Dictionary> ret; |
| 2348 | |
| 2349 | const Glyph *glyphs = shaped_text_get_ellipsis_glyphs(p_shaped); |
| 2350 | int gl_size = shaped_text_get_ellipsis_glyph_count(p_shaped); |
| 2351 | for (int i = 0; i < gl_size; i++) { |
| 2352 | Dictionary glyph; |
| 2353 | |
| 2354 | glyph["start"] = glyphs[i].start; |
| 2355 | glyph["end"] = glyphs[i].end; |
| 2356 | glyph["repeat"] = glyphs[i].repeat; |
| 2357 | glyph["count"] = glyphs[i].count; |
| 2358 | glyph["flags"] = glyphs[i].flags; |
| 2359 | glyph["offset"] = Vector2(glyphs[i].x_off, glyphs[i].y_off); |
| 2360 | glyph["advance"] = glyphs[i].advance; |
| 2361 | glyph["font_rid"] = glyphs[i].font_rid; |
| 2362 | glyph["font_size"] = glyphs[i].font_size; |
| 2363 | glyph["index"] = glyphs[i].index; |
| 2364 | |
| 2365 | ret.push_back(glyph); |
| 2366 | } |
| 2367 | |
| 2368 | return ret; |
| 2369 | } |
| 2370 | |
| 2371 | bool TextServer::is_valid_identifier(const String &p_string) const { |
| 2372 | return p_string.is_valid_unicode_identifier(); |
| 2373 | } |
| 2374 | |
| 2375 | bool TextServer::is_valid_letter(uint64_t p_unicode) const { |
| 2376 | return is_unicode_letter(p_unicode); |
| 2377 | } |
| 2378 | |
| 2379 | TextServer::TextServer() { |
| 2380 | // Default font rendering related project settings. |
| 2381 | |
| 2382 | GLOBAL_DEF_RST(PropertyInfo(Variant::INT, "gui/theme/default_font_antialiasing", PROPERTY_HINT_ENUM, "None,Grayscale,LCD Subpixel", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_RESTART_IF_CHANGED), 1); |
| 2383 | GLOBAL_DEF_RST(PropertyInfo(Variant::INT, "gui/theme/default_font_hinting", PROPERTY_HINT_ENUM, "None,Light,Normal", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_RESTART_IF_CHANGED), TextServer::HINTING_LIGHT); |
| 2384 | GLOBAL_DEF_RST(PropertyInfo(Variant::INT, "gui/theme/default_font_subpixel_positioning", PROPERTY_HINT_ENUM, "Disabled,Auto,One Half of a Pixel,One Quarter of a Pixel", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_RESTART_IF_CHANGED), TextServer::SUBPIXEL_POSITIONING_AUTO); |
| 2385 | |
| 2386 | GLOBAL_DEF_RST("gui/theme/default_font_multichannel_signed_distance_field", false); |
| 2387 | GLOBAL_DEF_RST("gui/theme/default_font_generate_mipmaps", false); |
| 2388 | |
| 2389 | GLOBAL_DEF(PropertyInfo(Variant::INT, "gui/theme/lcd_subpixel_layout", PROPERTY_HINT_ENUM, "Disabled,Horizontal RGB,Horizontal BGR,Vertical RGB,Vertical BGR"), 1); |
| 2390 | GLOBAL_DEF_BASIC("internationalization/locale/include_text_server_data", false); |
| 2391 | GLOBAL_DEF_BASIC(PropertyInfo(Variant::INT, "internationalization/locale/line_breaking_strictness", PROPERTY_HINT_ENUM, "Auto,Loose,Normal,Strict"), 0); |
| 2392 | |
| 2393 | _init_diacritics_map(); |
| 2394 | } |
| 2395 | |
| 2396 | TextServer::~TextServer() { |
| 2397 | } |
| 2398 | |
| 2399 | BitField<TextServer::TextOverrunFlag> TextServer::get_overrun_flags_from_behavior(TextServer::OverrunBehavior p_behavior) { |
| 2400 | BitField<TextOverrunFlag> overrun_flags = OVERRUN_NO_TRIM; |
| 2401 | switch (p_behavior) { |
| 2402 | case OVERRUN_TRIM_WORD_ELLIPSIS_FORCE: { |
| 2403 | overrun_flags.set_flag(OVERRUN_TRIM); |
| 2404 | overrun_flags.set_flag(OVERRUN_TRIM_WORD_ONLY); |
| 2405 | overrun_flags.set_flag(OVERRUN_ADD_ELLIPSIS); |
| 2406 | overrun_flags.set_flag(OVERRUN_SHORT_STRING_ELLIPSIS); |
| 2407 | } break; |
| 2408 | case OVERRUN_TRIM_ELLIPSIS_FORCE: { |
| 2409 | overrun_flags.set_flag(OVERRUN_TRIM); |
| 2410 | overrun_flags.set_flag(OVERRUN_ADD_ELLIPSIS); |
| 2411 | overrun_flags.set_flag(OVERRUN_SHORT_STRING_ELLIPSIS); |
| 2412 | } break; |
| 2413 | case OVERRUN_TRIM_WORD_ELLIPSIS: |
| 2414 | overrun_flags.set_flag(OVERRUN_TRIM); |
| 2415 | overrun_flags.set_flag(OVERRUN_TRIM_WORD_ONLY); |
| 2416 | overrun_flags.set_flag(OVERRUN_ADD_ELLIPSIS); |
| 2417 | break; |
| 2418 | case OVERRUN_TRIM_ELLIPSIS: |
| 2419 | overrun_flags.set_flag(OVERRUN_TRIM); |
| 2420 | overrun_flags.set_flag(OVERRUN_ADD_ELLIPSIS); |
| 2421 | break; |
| 2422 | case OVERRUN_TRIM_WORD: |
| 2423 | overrun_flags.set_flag(OVERRUN_TRIM); |
| 2424 | overrun_flags.set_flag(OVERRUN_TRIM_WORD_ONLY); |
| 2425 | break; |
| 2426 | case OVERRUN_TRIM_CHAR: |
| 2427 | overrun_flags.set_flag(OVERRUN_TRIM); |
| 2428 | break; |
| 2429 | case OVERRUN_NO_TRIMMING: |
| 2430 | break; |
| 2431 | } |
| 2432 | return overrun_flags; |
| 2433 | } |