text_server.cpp 83 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980
  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. #include "servers/text_server.h"
  31. #include "core/variant/typed_array.h"
  32. #include "servers/rendering_server.h"
  33. TextServerManager *TextServerManager::singleton = nullptr;
  34. void TextServerManager::_bind_methods() {
  35. ClassDB::bind_method(D_METHOD("add_interface", "interface"), &TextServerManager::add_interface);
  36. ClassDB::bind_method(D_METHOD("get_interface_count"), &TextServerManager::get_interface_count);
  37. ClassDB::bind_method(D_METHOD("remove_interface", "interface"), &TextServerManager::remove_interface);
  38. ClassDB::bind_method(D_METHOD("get_interface", "idx"), &TextServerManager::get_interface);
  39. ClassDB::bind_method(D_METHOD("get_interfaces"), &TextServerManager::get_interfaces);
  40. ClassDB::bind_method(D_METHOD("find_interface", "name"), &TextServerManager::find_interface);
  41. ClassDB::bind_method(D_METHOD("set_primary_interface", "index"), &TextServerManager::set_primary_interface);
  42. ClassDB::bind_method(D_METHOD("get_primary_interface"), &TextServerManager::get_primary_interface);
  43. ADD_SIGNAL(MethodInfo("interface_added", PropertyInfo(Variant::STRING_NAME, "interface_name")));
  44. ADD_SIGNAL(MethodInfo("interface_removed", PropertyInfo(Variant::STRING_NAME, "interface_name")));
  45. }
  46. void TextServerManager::add_interface(const Ref<TextServer> &p_interface) {
  47. ERR_FAIL_COND(p_interface.is_null());
  48. for (int i = 0; i < interfaces.size(); i++) {
  49. if (interfaces[i] == p_interface) {
  50. ERR_PRINT("TextServer: Interface was already added.");
  51. return;
  52. };
  53. };
  54. interfaces.push_back(p_interface);
  55. print_verbose("TextServer: Added interface \"" + p_interface->get_name() + "\"");
  56. emit_signal(SNAME("interface_added"), p_interface->get_name());
  57. }
  58. void TextServerManager::remove_interface(const Ref<TextServer> &p_interface) {
  59. ERR_FAIL_COND(p_interface.is_null());
  60. ERR_FAIL_COND_MSG(p_interface == primary_interface, "TextServer: Can't remove primary interface.");
  61. int idx = -1;
  62. for (int i = 0; i < interfaces.size(); i++) {
  63. if (interfaces[i] == p_interface) {
  64. idx = i;
  65. break;
  66. };
  67. };
  68. ERR_FAIL_COND_MSG(idx == -1, "Interface not found.");
  69. print_verbose("TextServer: Removed interface \"" + p_interface->get_name() + "\"");
  70. emit_signal(SNAME("interface_removed"), p_interface->get_name());
  71. interfaces.remove_at(idx);
  72. }
  73. int TextServerManager::get_interface_count() const {
  74. return interfaces.size();
  75. }
  76. Ref<TextServer> TextServerManager::get_interface(int p_index) const {
  77. ERR_FAIL_INDEX_V(p_index, interfaces.size(), nullptr);
  78. return interfaces[p_index];
  79. }
  80. Ref<TextServer> TextServerManager::find_interface(const String &p_name) const {
  81. int idx = -1;
  82. for (int i = 0; i < interfaces.size(); i++) {
  83. if (interfaces[i]->get_name() == p_name) {
  84. idx = i;
  85. break;
  86. };
  87. };
  88. ERR_FAIL_COND_V_MSG(idx == -1, nullptr, "Interface not found.");
  89. return interfaces[idx];
  90. }
  91. TypedArray<Dictionary> TextServerManager::get_interfaces() const {
  92. TypedArray<Dictionary> ret;
  93. for (int i = 0; i < interfaces.size(); i++) {
  94. Dictionary iface_info;
  95. iface_info["id"] = i;
  96. iface_info["name"] = interfaces[i]->get_name();
  97. ret.push_back(iface_info);
  98. };
  99. return ret;
  100. }
  101. void TextServerManager::set_primary_interface(const Ref<TextServer> &p_primary_interface) {
  102. if (p_primary_interface.is_null()) {
  103. print_verbose("TextServer: Clearing primary interface");
  104. primary_interface.unref();
  105. } else {
  106. primary_interface = p_primary_interface;
  107. print_verbose("TextServer: Primary interface set to: \"" + primary_interface->get_name() + "\".");
  108. if (OS::get_singleton()->get_main_loop()) {
  109. OS::get_singleton()->get_main_loop()->notification(MainLoop::NOTIFICATION_TEXT_SERVER_CHANGED);
  110. }
  111. }
  112. }
  113. TextServerManager::TextServerManager() {
  114. singleton = this;
  115. }
  116. TextServerManager::~TextServerManager() {
  117. if (primary_interface.is_valid()) {
  118. primary_interface.unref();
  119. }
  120. while (interfaces.size() > 0) {
  121. interfaces.remove_at(0);
  122. }
  123. singleton = nullptr;
  124. }
  125. /*************************************************************************/
  126. bool Glyph::operator==(const Glyph &p_a) const {
  127. return (p_a.index == index) && (p_a.font_rid == font_rid) && (p_a.font_size == font_size) && (p_a.start == start);
  128. }
  129. bool Glyph::operator!=(const Glyph &p_a) const {
  130. return (p_a.index != index) || (p_a.font_rid != font_rid) || (p_a.font_size != font_size) || (p_a.start != start);
  131. }
  132. bool Glyph::operator<(const Glyph &p_a) const {
  133. if (p_a.start == start) {
  134. if (p_a.count == count) {
  135. if ((p_a.flags & TextServer::GRAPHEME_IS_VIRTUAL) == TextServer::GRAPHEME_IS_VIRTUAL) {
  136. return true;
  137. } else {
  138. return false;
  139. }
  140. }
  141. return p_a.count > count;
  142. }
  143. return p_a.start < start;
  144. }
  145. bool Glyph::operator>(const Glyph &p_a) const {
  146. if (p_a.start == start) {
  147. if (p_a.count == count) {
  148. if ((p_a.flags & TextServer::GRAPHEME_IS_VIRTUAL) == TextServer::GRAPHEME_IS_VIRTUAL) {
  149. return false;
  150. } else {
  151. return true;
  152. }
  153. }
  154. return p_a.count < count;
  155. }
  156. return p_a.start > start;
  157. }
  158. void TextServer::_bind_methods() {
  159. ClassDB::bind_method(D_METHOD("has_feature", "feature"), &TextServer::has_feature);
  160. ClassDB::bind_method(D_METHOD("get_name"), &TextServer::get_name);
  161. ClassDB::bind_method(D_METHOD("get_features"), &TextServer::get_features);
  162. ClassDB::bind_method(D_METHOD("load_support_data", "filename"), &TextServer::load_support_data);
  163. ClassDB::bind_method(D_METHOD("get_support_data_filename"), &TextServer::get_support_data_filename);
  164. ClassDB::bind_method(D_METHOD("get_support_data_info"), &TextServer::get_support_data_info);
  165. ClassDB::bind_method(D_METHOD("save_support_data", "filename"), &TextServer::save_support_data);
  166. ClassDB::bind_method(D_METHOD("is_locale_right_to_left", "locale"), &TextServer::is_locale_right_to_left);
  167. ClassDB::bind_method(D_METHOD("name_to_tag", "name"), &TextServer::name_to_tag);
  168. ClassDB::bind_method(D_METHOD("tag_to_name", "tag"), &TextServer::tag_to_name);
  169. ClassDB::bind_method(D_METHOD("has", "rid"), &TextServer::has);
  170. ClassDB::bind_method(D_METHOD("free_rid", "rid"), &TextServer::free_rid);
  171. /* Font Interface */
  172. ClassDB::bind_method(D_METHOD("create_font"), &TextServer::create_font);
  173. ClassDB::bind_method(D_METHOD("font_set_data", "font_rid", "data"), &TextServer::font_set_data);
  174. ClassDB::bind_method(D_METHOD("font_set_face_index", "font_rid", "face_index"), &TextServer::font_set_face_index);
  175. ClassDB::bind_method(D_METHOD("font_get_face_index", "font_rid"), &TextServer::font_get_face_index);
  176. ClassDB::bind_method(D_METHOD("font_get_face_count", "font_rid"), &TextServer::font_get_face_count);
  177. ClassDB::bind_method(D_METHOD("font_set_style", "font_rid", "style"), &TextServer::font_set_style);
  178. ClassDB::bind_method(D_METHOD("font_get_style", "font_rid"), &TextServer::font_get_style);
  179. ClassDB::bind_method(D_METHOD("font_set_name", "font_rid", "name"), &TextServer::font_set_name);
  180. ClassDB::bind_method(D_METHOD("font_get_name", "font_rid"), &TextServer::font_get_name);
  181. ClassDB::bind_method(D_METHOD("font_set_style_name", "font_rid", "name"), &TextServer::font_set_style_name);
  182. ClassDB::bind_method(D_METHOD("font_get_style_name", "font_rid"), &TextServer::font_get_style_name);
  183. ClassDB::bind_method(D_METHOD("font_set_weight", "font_rid", "weight"), &TextServer::font_set_weight);
  184. ClassDB::bind_method(D_METHOD("font_get_weight", "font_rid"), &TextServer::font_get_weight);
  185. ClassDB::bind_method(D_METHOD("font_set_stretch", "font_rid", "weight"), &TextServer::font_set_stretch);
  186. ClassDB::bind_method(D_METHOD("font_get_stretch", "font_rid"), &TextServer::font_get_stretch);
  187. ClassDB::bind_method(D_METHOD("font_set_antialiasing", "font_rid", "antialiasing"), &TextServer::font_set_antialiasing);
  188. ClassDB::bind_method(D_METHOD("font_get_antialiasing", "font_rid"), &TextServer::font_get_antialiasing);
  189. ClassDB::bind_method(D_METHOD("font_set_generate_mipmaps", "font_rid", "generate_mipmaps"), &TextServer::font_set_generate_mipmaps);
  190. ClassDB::bind_method(D_METHOD("font_get_generate_mipmaps", "font_rid"), &TextServer::font_get_generate_mipmaps);
  191. ClassDB::bind_method(D_METHOD("font_set_multichannel_signed_distance_field", "font_rid", "msdf"), &TextServer::font_set_multichannel_signed_distance_field);
  192. ClassDB::bind_method(D_METHOD("font_is_multichannel_signed_distance_field", "font_rid"), &TextServer::font_is_multichannel_signed_distance_field);
  193. ClassDB::bind_method(D_METHOD("font_set_msdf_pixel_range", "font_rid", "msdf_pixel_range"), &TextServer::font_set_msdf_pixel_range);
  194. ClassDB::bind_method(D_METHOD("font_get_msdf_pixel_range", "font_rid"), &TextServer::font_get_msdf_pixel_range);
  195. ClassDB::bind_method(D_METHOD("font_set_msdf_size", "font_rid", "msdf_size"), &TextServer::font_set_msdf_size);
  196. ClassDB::bind_method(D_METHOD("font_get_msdf_size", "font_rid"), &TextServer::font_get_msdf_size);
  197. ClassDB::bind_method(D_METHOD("font_set_fixed_size", "font_rid", "fixed_size"), &TextServer::font_set_fixed_size);
  198. ClassDB::bind_method(D_METHOD("font_get_fixed_size", "font_rid"), &TextServer::font_get_fixed_size);
  199. ClassDB::bind_method(D_METHOD("font_set_allow_system_fallback", "font_rid", "allow_system_fallback"), &TextServer::font_set_allow_system_fallback);
  200. ClassDB::bind_method(D_METHOD("font_is_allow_system_fallback", "font_rid"), &TextServer::font_is_allow_system_fallback);
  201. ClassDB::bind_method(D_METHOD("font_set_force_autohinter", "font_rid", "force_autohinter"), &TextServer::font_set_force_autohinter);
  202. ClassDB::bind_method(D_METHOD("font_is_force_autohinter", "font_rid"), &TextServer::font_is_force_autohinter);
  203. ClassDB::bind_method(D_METHOD("font_set_hinting", "font_rid", "hinting"), &TextServer::font_set_hinting);
  204. ClassDB::bind_method(D_METHOD("font_get_hinting", "font_rid"), &TextServer::font_get_hinting);
  205. ClassDB::bind_method(D_METHOD("font_set_subpixel_positioning", "font_rid", "subpixel_positioning"), &TextServer::font_set_subpixel_positioning);
  206. ClassDB::bind_method(D_METHOD("font_get_subpixel_positioning", "font_rid"), &TextServer::font_get_subpixel_positioning);
  207. ClassDB::bind_method(D_METHOD("font_set_embolden", "font_rid", "strength"), &TextServer::font_set_embolden);
  208. ClassDB::bind_method(D_METHOD("font_get_embolden", "font_rid"), &TextServer::font_get_embolden);
  209. ClassDB::bind_method(D_METHOD("font_set_transform", "font_rid", "transform"), &TextServer::font_set_transform);
  210. ClassDB::bind_method(D_METHOD("font_get_transform", "font_rid"), &TextServer::font_get_transform);
  211. ClassDB::bind_method(D_METHOD("font_set_variation_coordinates", "font_rid", "variation_coordinates"), &TextServer::font_set_variation_coordinates);
  212. ClassDB::bind_method(D_METHOD("font_get_variation_coordinates", "font_rid"), &TextServer::font_get_variation_coordinates);
  213. ClassDB::bind_method(D_METHOD("font_set_oversampling", "font_rid", "oversampling"), &TextServer::font_set_oversampling);
  214. ClassDB::bind_method(D_METHOD("font_get_oversampling", "font_rid"), &TextServer::font_get_oversampling);
  215. ClassDB::bind_method(D_METHOD("font_get_size_cache_list", "font_rid"), &TextServer::font_get_size_cache_list);
  216. ClassDB::bind_method(D_METHOD("font_clear_size_cache", "font_rid"), &TextServer::font_clear_size_cache);
  217. ClassDB::bind_method(D_METHOD("font_remove_size_cache", "font_rid", "size"), &TextServer::font_remove_size_cache);
  218. ClassDB::bind_method(D_METHOD("font_set_ascent", "font_rid", "size", "ascent"), &TextServer::font_set_ascent);
  219. ClassDB::bind_method(D_METHOD("font_get_ascent", "font_rid", "size"), &TextServer::font_get_ascent);
  220. ClassDB::bind_method(D_METHOD("font_set_descent", "font_rid", "size", "descent"), &TextServer::font_set_descent);
  221. ClassDB::bind_method(D_METHOD("font_get_descent", "font_rid", "size"), &TextServer::font_get_descent);
  222. ClassDB::bind_method(D_METHOD("font_set_underline_position", "font_rid", "size", "underline_position"), &TextServer::font_set_underline_position);
  223. ClassDB::bind_method(D_METHOD("font_get_underline_position", "font_rid", "size"), &TextServer::font_get_underline_position);
  224. ClassDB::bind_method(D_METHOD("font_set_underline_thickness", "font_rid", "size", "underline_thickness"), &TextServer::font_set_underline_thickness);
  225. ClassDB::bind_method(D_METHOD("font_get_underline_thickness", "font_rid", "size"), &TextServer::font_get_underline_thickness);
  226. ClassDB::bind_method(D_METHOD("font_set_scale", "font_rid", "size", "scale"), &TextServer::font_set_scale);
  227. ClassDB::bind_method(D_METHOD("font_get_scale", "font_rid", "size"), &TextServer::font_get_scale);
  228. ClassDB::bind_method(D_METHOD("font_get_texture_count", "font_rid", "size"), &TextServer::font_get_texture_count);
  229. ClassDB::bind_method(D_METHOD("font_clear_textures", "font_rid", "size"), &TextServer::font_clear_textures);
  230. ClassDB::bind_method(D_METHOD("font_remove_texture", "font_rid", "size", "texture_index"), &TextServer::font_remove_texture);
  231. ClassDB::bind_method(D_METHOD("font_set_texture_image", "font_rid", "size", "texture_index", "image"), &TextServer::font_set_texture_image);
  232. ClassDB::bind_method(D_METHOD("font_get_texture_image", "font_rid", "size", "texture_index"), &TextServer::font_get_texture_image);
  233. ClassDB::bind_method(D_METHOD("font_set_texture_offsets", "font_rid", "size", "texture_index", "offset"), &TextServer::font_set_texture_offsets);
  234. ClassDB::bind_method(D_METHOD("font_get_texture_offsets", "font_rid", "size", "texture_index"), &TextServer::font_get_texture_offsets);
  235. ClassDB::bind_method(D_METHOD("font_get_glyph_list", "font_rid", "size"), &TextServer::font_get_glyph_list);
  236. ClassDB::bind_method(D_METHOD("font_clear_glyphs", "font_rid", "size"), &TextServer::font_clear_glyphs);
  237. ClassDB::bind_method(D_METHOD("font_remove_glyph", "font_rid", "size", "glyph"), &TextServer::font_remove_glyph);
  238. ClassDB::bind_method(D_METHOD("font_get_glyph_advance", "font_rid", "size", "glyph"), &TextServer::font_get_glyph_advance);
  239. ClassDB::bind_method(D_METHOD("font_set_glyph_advance", "font_rid", "size", "glyph", "advance"), &TextServer::font_set_glyph_advance);
  240. ClassDB::bind_method(D_METHOD("font_get_glyph_offset", "font_rid", "size", "glyph"), &TextServer::font_get_glyph_offset);
  241. ClassDB::bind_method(D_METHOD("font_set_glyph_offset", "font_rid", "size", "glyph", "offset"), &TextServer::font_set_glyph_offset);
  242. ClassDB::bind_method(D_METHOD("font_get_glyph_size", "font_rid", "size", "glyph"), &TextServer::font_get_glyph_size);
  243. ClassDB::bind_method(D_METHOD("font_set_glyph_size", "font_rid", "size", "glyph", "gl_size"), &TextServer::font_set_glyph_size);
  244. ClassDB::bind_method(D_METHOD("font_get_glyph_uv_rect", "font_rid", "size", "glyph"), &TextServer::font_get_glyph_uv_rect);
  245. ClassDB::bind_method(D_METHOD("font_set_glyph_uv_rect", "font_rid", "size", "glyph", "uv_rect"), &TextServer::font_set_glyph_uv_rect);
  246. ClassDB::bind_method(D_METHOD("font_get_glyph_texture_idx", "font_rid", "size", "glyph"), &TextServer::font_get_glyph_texture_idx);
  247. ClassDB::bind_method(D_METHOD("font_set_glyph_texture_idx", "font_rid", "size", "glyph", "texture_idx"), &TextServer::font_set_glyph_texture_idx);
  248. ClassDB::bind_method(D_METHOD("font_get_glyph_texture_rid", "font_rid", "size", "glyph"), &TextServer::font_get_glyph_texture_rid);
  249. ClassDB::bind_method(D_METHOD("font_get_glyph_texture_size", "font_rid", "size", "glyph"), &TextServer::font_get_glyph_texture_size);
  250. ClassDB::bind_method(D_METHOD("font_get_glyph_contours", "font", "size", "index"), &TextServer::font_get_glyph_contours);
  251. ClassDB::bind_method(D_METHOD("font_get_kerning_list", "font_rid", "size"), &TextServer::font_get_kerning_list);
  252. ClassDB::bind_method(D_METHOD("font_clear_kerning_map", "font_rid", "size"), &TextServer::font_clear_kerning_map);
  253. ClassDB::bind_method(D_METHOD("font_remove_kerning", "font_rid", "size", "glyph_pair"), &TextServer::font_remove_kerning);
  254. ClassDB::bind_method(D_METHOD("font_set_kerning", "font_rid", "size", "glyph_pair", "kerning"), &TextServer::font_set_kerning);
  255. ClassDB::bind_method(D_METHOD("font_get_kerning", "font_rid", "size", "glyph_pair"), &TextServer::font_get_kerning);
  256. ClassDB::bind_method(D_METHOD("font_get_glyph_index", "font_rid", "size", "char", "variation_selector"), &TextServer::font_get_glyph_index);
  257. ClassDB::bind_method(D_METHOD("font_has_char", "font_rid", "char"), &TextServer::font_has_char);
  258. ClassDB::bind_method(D_METHOD("font_get_supported_chars", "font_rid"), &TextServer::font_get_supported_chars);
  259. ClassDB::bind_method(D_METHOD("font_render_range", "font_rid", "size", "start", "end"), &TextServer::font_render_range);
  260. ClassDB::bind_method(D_METHOD("font_render_glyph", "font_rid", "size", "index"), &TextServer::font_render_glyph);
  261. ClassDB::bind_method(D_METHOD("font_draw_glyph", "font_rid", "canvas", "size", "pos", "index", "color"), &TextServer::font_draw_glyph, DEFVAL(Color(1, 1, 1)));
  262. ClassDB::bind_method(D_METHOD("font_draw_glyph_outline", "font_rid", "canvas", "size", "outline_size", "pos", "index", "color"), &TextServer::font_draw_glyph_outline, DEFVAL(Color(1, 1, 1)));
  263. ClassDB::bind_method(D_METHOD("font_is_language_supported", "font_rid", "language"), &TextServer::font_is_language_supported);
  264. ClassDB::bind_method(D_METHOD("font_set_language_support_override", "font_rid", "language", "supported"), &TextServer::font_set_language_support_override);
  265. ClassDB::bind_method(D_METHOD("font_get_language_support_override", "font_rid", "language"), &TextServer::font_get_language_support_override);
  266. ClassDB::bind_method(D_METHOD("font_remove_language_support_override", "font_rid", "language"), &TextServer::font_remove_language_support_override);
  267. ClassDB::bind_method(D_METHOD("font_get_language_support_overrides", "font_rid"), &TextServer::font_get_language_support_overrides);
  268. ClassDB::bind_method(D_METHOD("font_is_script_supported", "font_rid", "script"), &TextServer::font_is_script_supported);
  269. ClassDB::bind_method(D_METHOD("font_set_script_support_override", "font_rid", "script", "supported"), &TextServer::font_set_script_support_override);
  270. ClassDB::bind_method(D_METHOD("font_get_script_support_override", "font_rid", "script"), &TextServer::font_get_script_support_override);
  271. ClassDB::bind_method(D_METHOD("font_remove_script_support_override", "font_rid", "script"), &TextServer::font_remove_script_support_override);
  272. ClassDB::bind_method(D_METHOD("font_get_script_support_overrides", "font_rid"), &TextServer::font_get_script_support_overrides);
  273. ClassDB::bind_method(D_METHOD("font_set_opentype_feature_overrides", "font_rid", "overrides"), &TextServer::font_set_opentype_feature_overrides);
  274. ClassDB::bind_method(D_METHOD("font_get_opentype_feature_overrides", "font_rid"), &TextServer::font_get_opentype_feature_overrides);
  275. ClassDB::bind_method(D_METHOD("font_supported_feature_list", "font_rid"), &TextServer::font_supported_feature_list);
  276. ClassDB::bind_method(D_METHOD("font_supported_variation_list", "font_rid"), &TextServer::font_supported_variation_list);
  277. ClassDB::bind_method(D_METHOD("font_get_global_oversampling"), &TextServer::font_get_global_oversampling);
  278. ClassDB::bind_method(D_METHOD("font_set_global_oversampling", "oversampling"), &TextServer::font_set_global_oversampling);
  279. ClassDB::bind_method(D_METHOD("get_hex_code_box_size", "size", "index"), &TextServer::get_hex_code_box_size);
  280. ClassDB::bind_method(D_METHOD("draw_hex_code_box", "canvas", "size", "pos", "index", "color"), &TextServer::draw_hex_code_box);
  281. /* Shaped text buffer interface */
  282. ClassDB::bind_method(D_METHOD("create_shaped_text", "direction", "orientation"), &TextServer::create_shaped_text, DEFVAL(DIRECTION_AUTO), DEFVAL(ORIENTATION_HORIZONTAL));
  283. ClassDB::bind_method(D_METHOD("shaped_text_clear", "rid"), &TextServer::shaped_text_clear);
  284. ClassDB::bind_method(D_METHOD("shaped_text_set_direction", "shaped", "direction"), &TextServer::shaped_text_set_direction, DEFVAL(DIRECTION_AUTO));
  285. ClassDB::bind_method(D_METHOD("shaped_text_get_direction", "shaped"), &TextServer::shaped_text_get_direction);
  286. ClassDB::bind_method(D_METHOD("shaped_text_get_inferred_direction", "shaped"), &TextServer::shaped_text_get_inferred_direction);
  287. ClassDB::bind_method(D_METHOD("shaped_text_set_bidi_override", "shaped", "override"), &TextServer::shaped_text_set_bidi_override);
  288. ClassDB::bind_method(D_METHOD("shaped_text_set_custom_punctuation", "shaped", "punct"), &TextServer::shaped_text_set_custom_punctuation);
  289. ClassDB::bind_method(D_METHOD("shaped_text_get_custom_punctuation", "shaped"), &TextServer::shaped_text_get_custom_punctuation);
  290. ClassDB::bind_method(D_METHOD("shaped_text_set_orientation", "shaped", "orientation"), &TextServer::shaped_text_set_orientation, DEFVAL(ORIENTATION_HORIZONTAL));
  291. ClassDB::bind_method(D_METHOD("shaped_text_get_orientation", "shaped"), &TextServer::shaped_text_get_orientation);
  292. ClassDB::bind_method(D_METHOD("shaped_text_set_preserve_invalid", "shaped", "enabled"), &TextServer::shaped_text_set_preserve_invalid);
  293. ClassDB::bind_method(D_METHOD("shaped_text_get_preserve_invalid", "shaped"), &TextServer::shaped_text_get_preserve_invalid);
  294. ClassDB::bind_method(D_METHOD("shaped_text_set_preserve_control", "shaped", "enabled"), &TextServer::shaped_text_set_preserve_control);
  295. ClassDB::bind_method(D_METHOD("shaped_text_get_preserve_control", "shaped"), &TextServer::shaped_text_get_preserve_control);
  296. ClassDB::bind_method(D_METHOD("shaped_text_set_spacing", "shaped", "spacing", "value"), &TextServer::shaped_text_set_spacing);
  297. ClassDB::bind_method(D_METHOD("shaped_text_get_spacing", "shaped", "spacing"), &TextServer::shaped_text_get_spacing);
  298. 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()));
  299. 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));
  300. 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));
  301. ClassDB::bind_method(D_METHOD("shaped_get_span_count", "shaped"), &TextServer::shaped_get_span_count);
  302. ClassDB::bind_method(D_METHOD("shaped_get_span_meta", "shaped", "index"), &TextServer::shaped_get_span_meta);
  303. ClassDB::bind_method(D_METHOD("shaped_set_span_update_font", "shaped", "index", "fonts", "size", "opentype_features"), &TextServer::shaped_set_span_update_font, DEFVAL(Dictionary()));
  304. ClassDB::bind_method(D_METHOD("shaped_text_substr", "shaped", "start", "length"), &TextServer::shaped_text_substr);
  305. ClassDB::bind_method(D_METHOD("shaped_text_get_parent", "shaped"), &TextServer::shaped_text_get_parent);
  306. ClassDB::bind_method(D_METHOD("shaped_text_fit_to_width", "shaped", "width", "jst_flags"), &TextServer::shaped_text_fit_to_width, DEFVAL(JUSTIFICATION_WORD_BOUND | JUSTIFICATION_KASHIDA));
  307. ClassDB::bind_method(D_METHOD("shaped_text_tab_align", "shaped", "tab_stops"), &TextServer::shaped_text_tab_align);
  308. ClassDB::bind_method(D_METHOD("shaped_text_shape", "shaped"), &TextServer::shaped_text_shape);
  309. ClassDB::bind_method(D_METHOD("shaped_text_is_ready", "shaped"), &TextServer::shaped_text_is_ready);
  310. ClassDB::bind_method(D_METHOD("shaped_text_get_glyphs", "shaped"), &TextServer::_shaped_text_get_glyphs_wrapper);
  311. ClassDB::bind_method(D_METHOD("shaped_text_sort_logical", "shaped"), &TextServer::_shaped_text_sort_logical_wrapper);
  312. ClassDB::bind_method(D_METHOD("shaped_text_get_glyph_count", "shaped"), &TextServer::shaped_text_get_glyph_count);
  313. ClassDB::bind_method(D_METHOD("shaped_text_get_range", "shaped"), &TextServer::shaped_text_get_range);
  314. 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));
  315. 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));
  316. ClassDB::bind_method(D_METHOD("shaped_text_get_word_breaks", "shaped", "grapheme_flags"), &TextServer::shaped_text_get_word_breaks, DEFVAL(GRAPHEME_IS_SPACE | GRAPHEME_IS_PUNCTUATION));
  317. ClassDB::bind_method(D_METHOD("shaped_text_get_trim_pos", "shaped"), &TextServer::shaped_text_get_trim_pos);
  318. ClassDB::bind_method(D_METHOD("shaped_text_get_ellipsis_pos", "shaped"), &TextServer::shaped_text_get_ellipsis_pos);
  319. ClassDB::bind_method(D_METHOD("shaped_text_get_ellipsis_glyphs", "shaped"), &TextServer::_shaped_text_get_ellipsis_glyphs_wrapper);
  320. ClassDB::bind_method(D_METHOD("shaped_text_get_ellipsis_glyph_count", "shaped"), &TextServer::shaped_text_get_ellipsis_glyph_count);
  321. 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));
  322. ClassDB::bind_method(D_METHOD("shaped_text_get_objects", "shaped"), &TextServer::shaped_text_get_objects);
  323. ClassDB::bind_method(D_METHOD("shaped_text_get_object_rect", "shaped", "key"), &TextServer::shaped_text_get_object_rect);
  324. ClassDB::bind_method(D_METHOD("shaped_text_get_size", "shaped"), &TextServer::shaped_text_get_size);
  325. ClassDB::bind_method(D_METHOD("shaped_text_get_ascent", "shaped"), &TextServer::shaped_text_get_ascent);
  326. ClassDB::bind_method(D_METHOD("shaped_text_get_descent", "shaped"), &TextServer::shaped_text_get_descent);
  327. ClassDB::bind_method(D_METHOD("shaped_text_get_width", "shaped"), &TextServer::shaped_text_get_width);
  328. ClassDB::bind_method(D_METHOD("shaped_text_get_underline_position", "shaped"), &TextServer::shaped_text_get_underline_position);
  329. ClassDB::bind_method(D_METHOD("shaped_text_get_underline_thickness", "shaped"), &TextServer::shaped_text_get_underline_thickness);
  330. ClassDB::bind_method(D_METHOD("shaped_text_get_carets", "shaped", "position"), &TextServer::_shaped_text_get_carets_wrapper);
  331. ClassDB::bind_method(D_METHOD("shaped_text_get_selection", "shaped", "start", "end"), &TextServer::shaped_text_get_selection);
  332. ClassDB::bind_method(D_METHOD("shaped_text_hit_test_grapheme", "shaped", "coords"), &TextServer::shaped_text_hit_test_grapheme);
  333. ClassDB::bind_method(D_METHOD("shaped_text_hit_test_position", "shaped", "coords"), &TextServer::shaped_text_hit_test_position);
  334. ClassDB::bind_method(D_METHOD("shaped_text_get_grapheme_bounds", "shaped", "pos"), &TextServer::shaped_text_get_grapheme_bounds);
  335. ClassDB::bind_method(D_METHOD("shaped_text_next_grapheme_pos", "shaped", "pos"), &TextServer::shaped_text_next_grapheme_pos);
  336. ClassDB::bind_method(D_METHOD("shaped_text_prev_grapheme_pos", "shaped", "pos"), &TextServer::shaped_text_prev_grapheme_pos);
  337. ClassDB::bind_method(D_METHOD("shaped_text_draw", "shaped", "canvas", "pos", "clip_l", "clip_r", "color"), &TextServer::shaped_text_draw, DEFVAL(-1), DEFVAL(-1), DEFVAL(Color(1, 1, 1)));
  338. ClassDB::bind_method(D_METHOD("shaped_text_draw_outline", "shaped", "canvas", "pos", "clip_l", "clip_r", "outline_size", "color"), &TextServer::shaped_text_draw_outline, DEFVAL(-1), DEFVAL(-1), DEFVAL(1), DEFVAL(Color(1, 1, 1)));
  339. ClassDB::bind_method(D_METHOD("shaped_text_get_dominant_direction_in_range", "shaped", "start", "end"), &TextServer::shaped_text_get_dominant_direction_in_range);
  340. ClassDB::bind_method(D_METHOD("format_number", "number", "language"), &TextServer::format_number, DEFVAL(""));
  341. ClassDB::bind_method(D_METHOD("parse_number", "number", "language"), &TextServer::parse_number, DEFVAL(""));
  342. ClassDB::bind_method(D_METHOD("percent_sign", "language"), &TextServer::percent_sign, DEFVAL(""));
  343. ClassDB::bind_method(D_METHOD("string_get_word_breaks", "string", "language", "chars_per_line"), &TextServer::string_get_word_breaks, DEFVAL(""), DEFVAL(0));
  344. ClassDB::bind_method(D_METHOD("is_confusable", "string", "dict"), &TextServer::is_confusable);
  345. ClassDB::bind_method(D_METHOD("spoof_check", "string"), &TextServer::spoof_check);
  346. ClassDB::bind_method(D_METHOD("strip_diacritics", "string"), &TextServer::strip_diacritics);
  347. ClassDB::bind_method(D_METHOD("is_valid_identifier", "string"), &TextServer::is_valid_identifier);
  348. ClassDB::bind_method(D_METHOD("string_to_upper", "string", "language"), &TextServer::string_to_upper, DEFVAL(""));
  349. ClassDB::bind_method(D_METHOD("string_to_lower", "string", "language"), &TextServer::string_to_lower, DEFVAL(""));
  350. ClassDB::bind_method(D_METHOD("parse_structured_text", "parser_type", "args", "text"), &TextServer::parse_structured_text);
  351. /* Font AA */
  352. BIND_ENUM_CONSTANT(FONT_ANTIALIASING_NONE);
  353. BIND_ENUM_CONSTANT(FONT_ANTIALIASING_GRAY);
  354. BIND_ENUM_CONSTANT(FONT_ANTIALIASING_LCD);
  355. BIND_ENUM_CONSTANT(FONT_LCD_SUBPIXEL_LAYOUT_NONE);
  356. BIND_ENUM_CONSTANT(FONT_LCD_SUBPIXEL_LAYOUT_HRGB);
  357. BIND_ENUM_CONSTANT(FONT_LCD_SUBPIXEL_LAYOUT_HBGR);
  358. BIND_ENUM_CONSTANT(FONT_LCD_SUBPIXEL_LAYOUT_VRGB);
  359. BIND_ENUM_CONSTANT(FONT_LCD_SUBPIXEL_LAYOUT_VBGR);
  360. BIND_ENUM_CONSTANT(FONT_LCD_SUBPIXEL_LAYOUT_MAX);
  361. /* Direction */
  362. BIND_ENUM_CONSTANT(DIRECTION_AUTO);
  363. BIND_ENUM_CONSTANT(DIRECTION_LTR);
  364. BIND_ENUM_CONSTANT(DIRECTION_RTL);
  365. BIND_ENUM_CONSTANT(DIRECTION_INHERITED);
  366. /* Orientation */
  367. BIND_ENUM_CONSTANT(ORIENTATION_HORIZONTAL);
  368. BIND_ENUM_CONSTANT(ORIENTATION_VERTICAL);
  369. /* JustificationFlag */
  370. BIND_BITFIELD_FLAG(JUSTIFICATION_NONE);
  371. BIND_BITFIELD_FLAG(JUSTIFICATION_KASHIDA);
  372. BIND_BITFIELD_FLAG(JUSTIFICATION_WORD_BOUND);
  373. BIND_BITFIELD_FLAG(JUSTIFICATION_TRIM_EDGE_SPACES);
  374. BIND_BITFIELD_FLAG(JUSTIFICATION_AFTER_LAST_TAB);
  375. BIND_BITFIELD_FLAG(JUSTIFICATION_CONSTRAIN_ELLIPSIS);
  376. /* AutowrapMode */
  377. BIND_ENUM_CONSTANT(AUTOWRAP_OFF);
  378. BIND_ENUM_CONSTANT(AUTOWRAP_ARBITRARY);
  379. BIND_ENUM_CONSTANT(AUTOWRAP_WORD);
  380. BIND_ENUM_CONSTANT(AUTOWRAP_WORD_SMART);
  381. /* LineBreakFlag */
  382. BIND_BITFIELD_FLAG(BREAK_NONE);
  383. BIND_BITFIELD_FLAG(BREAK_MANDATORY);
  384. BIND_BITFIELD_FLAG(BREAK_WORD_BOUND);
  385. BIND_BITFIELD_FLAG(BREAK_GRAPHEME_BOUND);
  386. BIND_BITFIELD_FLAG(BREAK_ADAPTIVE);
  387. BIND_BITFIELD_FLAG(BREAK_TRIM_EDGE_SPACES);
  388. /* VisibleCharactersBehavior */
  389. BIND_ENUM_CONSTANT(VC_CHARS_BEFORE_SHAPING);
  390. BIND_ENUM_CONSTANT(VC_CHARS_AFTER_SHAPING);
  391. BIND_ENUM_CONSTANT(VC_GLYPHS_AUTO);
  392. BIND_ENUM_CONSTANT(VC_GLYPHS_LTR);
  393. BIND_ENUM_CONSTANT(VC_GLYPHS_RTL);
  394. /* OverrunBehavior */
  395. BIND_ENUM_CONSTANT(OVERRUN_NO_TRIMMING);
  396. BIND_ENUM_CONSTANT(OVERRUN_TRIM_CHAR);
  397. BIND_ENUM_CONSTANT(OVERRUN_TRIM_WORD);
  398. BIND_ENUM_CONSTANT(OVERRUN_TRIM_ELLIPSIS);
  399. BIND_ENUM_CONSTANT(OVERRUN_TRIM_WORD_ELLIPSIS);
  400. /* TextOverrunFlag */
  401. BIND_BITFIELD_FLAG(OVERRUN_NO_TRIM);
  402. BIND_BITFIELD_FLAG(OVERRUN_TRIM);
  403. BIND_BITFIELD_FLAG(OVERRUN_TRIM_WORD_ONLY);
  404. BIND_BITFIELD_FLAG(OVERRUN_ADD_ELLIPSIS);
  405. BIND_BITFIELD_FLAG(OVERRUN_ENFORCE_ELLIPSIS);
  406. BIND_BITFIELD_FLAG(OVERRUN_JUSTIFICATION_AWARE);
  407. /* GraphemeFlag */
  408. BIND_BITFIELD_FLAG(GRAPHEME_IS_VALID);
  409. BIND_BITFIELD_FLAG(GRAPHEME_IS_RTL);
  410. BIND_BITFIELD_FLAG(GRAPHEME_IS_VIRTUAL);
  411. BIND_BITFIELD_FLAG(GRAPHEME_IS_SPACE);
  412. BIND_BITFIELD_FLAG(GRAPHEME_IS_BREAK_HARD);
  413. BIND_BITFIELD_FLAG(GRAPHEME_IS_BREAK_SOFT);
  414. BIND_BITFIELD_FLAG(GRAPHEME_IS_TAB);
  415. BIND_BITFIELD_FLAG(GRAPHEME_IS_ELONGATION);
  416. BIND_BITFIELD_FLAG(GRAPHEME_IS_PUNCTUATION);
  417. BIND_BITFIELD_FLAG(GRAPHEME_IS_UNDERSCORE);
  418. BIND_BITFIELD_FLAG(GRAPHEME_IS_CONNECTED);
  419. BIND_BITFIELD_FLAG(GRAPHEME_IS_SAFE_TO_INSERT_TATWEEL);
  420. BIND_BITFIELD_FLAG(GRAPHEME_IS_EMBEDDED_OBJECT);
  421. /* Hinting */
  422. BIND_ENUM_CONSTANT(HINTING_NONE);
  423. BIND_ENUM_CONSTANT(HINTING_LIGHT);
  424. BIND_ENUM_CONSTANT(HINTING_NORMAL);
  425. /* SubpixelPositioning */
  426. BIND_ENUM_CONSTANT(SUBPIXEL_POSITIONING_DISABLED);
  427. BIND_ENUM_CONSTANT(SUBPIXEL_POSITIONING_AUTO);
  428. BIND_ENUM_CONSTANT(SUBPIXEL_POSITIONING_ONE_HALF);
  429. BIND_ENUM_CONSTANT(SUBPIXEL_POSITIONING_ONE_QUARTER);
  430. BIND_ENUM_CONSTANT(SUBPIXEL_POSITIONING_ONE_HALF_MAX_SIZE);
  431. BIND_ENUM_CONSTANT(SUBPIXEL_POSITIONING_ONE_QUARTER_MAX_SIZE);
  432. /* Feature */
  433. BIND_ENUM_CONSTANT(FEATURE_SIMPLE_LAYOUT);
  434. BIND_ENUM_CONSTANT(FEATURE_BIDI_LAYOUT);
  435. BIND_ENUM_CONSTANT(FEATURE_VERTICAL_LAYOUT);
  436. BIND_ENUM_CONSTANT(FEATURE_SHAPING);
  437. BIND_ENUM_CONSTANT(FEATURE_KASHIDA_JUSTIFICATION);
  438. BIND_ENUM_CONSTANT(FEATURE_BREAK_ITERATORS);
  439. BIND_ENUM_CONSTANT(FEATURE_FONT_BITMAP);
  440. BIND_ENUM_CONSTANT(FEATURE_FONT_DYNAMIC);
  441. BIND_ENUM_CONSTANT(FEATURE_FONT_MSDF);
  442. BIND_ENUM_CONSTANT(FEATURE_FONT_SYSTEM);
  443. BIND_ENUM_CONSTANT(FEATURE_FONT_VARIABLE);
  444. BIND_ENUM_CONSTANT(FEATURE_CONTEXT_SENSITIVE_CASE_CONVERSION);
  445. BIND_ENUM_CONSTANT(FEATURE_USE_SUPPORT_DATA);
  446. BIND_ENUM_CONSTANT(FEATURE_UNICODE_IDENTIFIERS);
  447. BIND_ENUM_CONSTANT(FEATURE_UNICODE_SECURITY);
  448. /* FT Contour Point Types */
  449. BIND_ENUM_CONSTANT(CONTOUR_CURVE_TAG_ON);
  450. BIND_ENUM_CONSTANT(CONTOUR_CURVE_TAG_OFF_CONIC);
  451. BIND_ENUM_CONSTANT(CONTOUR_CURVE_TAG_OFF_CUBIC);
  452. /* Font Spacing */
  453. BIND_ENUM_CONSTANT(SPACING_GLYPH);
  454. BIND_ENUM_CONSTANT(SPACING_SPACE);
  455. BIND_ENUM_CONSTANT(SPACING_TOP);
  456. BIND_ENUM_CONSTANT(SPACING_BOTTOM);
  457. BIND_ENUM_CONSTANT(SPACING_MAX);
  458. /* Font Style */
  459. BIND_BITFIELD_FLAG(FONT_BOLD);
  460. BIND_BITFIELD_FLAG(FONT_ITALIC);
  461. BIND_BITFIELD_FLAG(FONT_FIXED_WIDTH);
  462. /* Structured text parser */
  463. BIND_ENUM_CONSTANT(STRUCTURED_TEXT_DEFAULT);
  464. BIND_ENUM_CONSTANT(STRUCTURED_TEXT_URI);
  465. BIND_ENUM_CONSTANT(STRUCTURED_TEXT_FILE);
  466. BIND_ENUM_CONSTANT(STRUCTURED_TEXT_EMAIL);
  467. BIND_ENUM_CONSTANT(STRUCTURED_TEXT_LIST);
  468. BIND_ENUM_CONSTANT(STRUCTURED_TEXT_GDSCRIPT);
  469. BIND_ENUM_CONSTANT(STRUCTURED_TEXT_CUSTOM);
  470. }
  471. Vector2 TextServer::get_hex_code_box_size(int64_t p_size, int64_t p_index) const {
  472. int w = ((p_index <= 0xFF) ? 1 : ((p_index <= 0xFFFF) ? 2 : 3));
  473. int sp = MAX(0, w - 1);
  474. int sz = MAX(1, Math::round(p_size / 15.f));
  475. return Vector2(4 + 3 * w + sp + 1, 15) * sz;
  476. }
  477. 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 {
  478. static uint8_t chars[] = { 0x7E, 0x30, 0x6D, 0x79, 0x33, 0x5B, 0x5F, 0x70, 0x7F, 0x7B, 0x77, 0x1F, 0x4E, 0x3D, 0x4F, 0x47, 0x00 };
  479. uint8_t x = chars[p_index];
  480. if (x & (1 << 6)) {
  481. RenderingServer::get_singleton()->canvas_item_add_rect(p_canvas, Rect2(p_pos, Size2(3, 1) * p_size), p_color);
  482. }
  483. if (x & (1 << 5)) {
  484. RenderingServer::get_singleton()->canvas_item_add_rect(p_canvas, Rect2(p_pos + Point2(2, 0) * p_size, Size2(1, 3) * p_size), p_color);
  485. }
  486. if (x & (1 << 4)) {
  487. RenderingServer::get_singleton()->canvas_item_add_rect(p_canvas, Rect2(p_pos + Point2(2, 2) * p_size, Size2(1, 3) * p_size), p_color);
  488. }
  489. if (x & (1 << 3)) {
  490. RenderingServer::get_singleton()->canvas_item_add_rect(p_canvas, Rect2(p_pos + Point2(0, 4) * p_size, Size2(3, 1) * p_size), p_color);
  491. }
  492. if (x & (1 << 2)) {
  493. RenderingServer::get_singleton()->canvas_item_add_rect(p_canvas, Rect2(p_pos + Point2(0, 2) * p_size, Size2(1, 3) * p_size), p_color);
  494. }
  495. if (x & (1 << 1)) {
  496. RenderingServer::get_singleton()->canvas_item_add_rect(p_canvas, Rect2(p_pos, Size2(1, 3) * p_size), p_color);
  497. }
  498. if (x & (1 << 0)) {
  499. RenderingServer::get_singleton()->canvas_item_add_rect(p_canvas, Rect2(p_pos + Point2(0, 2) * p_size, Size2(3, 1) * p_size), p_color);
  500. }
  501. }
  502. 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 {
  503. if (p_index == 0) {
  504. return;
  505. }
  506. int w = ((p_index <= 0xFF) ? 1 : ((p_index <= 0xFFFF) ? 2 : 3));
  507. int sp = MAX(0, w - 1);
  508. int sz = MAX(1, Math::round(p_size / 15.f));
  509. Size2 size = Vector2(4 + 3 * w + sp, 15) * sz;
  510. Point2 pos = p_pos - Point2i(0, size.y * 0.85);
  511. // Draw frame.
  512. RenderingServer::get_singleton()->canvas_item_add_rect(p_canvas, Rect2(pos + Point2(0, 0), Size2(sz, size.y)), p_color);
  513. RenderingServer::get_singleton()->canvas_item_add_rect(p_canvas, Rect2(pos + Point2(size.x - sz, 0), Size2(sz, size.y)), p_color);
  514. RenderingServer::get_singleton()->canvas_item_add_rect(p_canvas, Rect2(pos + Point2(0, 0), Size2(size.x, sz)), p_color);
  515. RenderingServer::get_singleton()->canvas_item_add_rect(p_canvas, Rect2(pos + Point2(0, size.y - sz), Size2(size.x, sz)), p_color);
  516. uint8_t a = p_index & 0x0F;
  517. uint8_t b = (p_index >> 4) & 0x0F;
  518. uint8_t c = (p_index >> 8) & 0x0F;
  519. uint8_t d = (p_index >> 12) & 0x0F;
  520. uint8_t e = (p_index >> 16) & 0x0F;
  521. uint8_t f = (p_index >> 20) & 0x0F;
  522. // Draw hex code.
  523. if (p_index <= 0xFF) {
  524. _draw_hex_code_box_number(p_canvas, sz, pos + Point2(2, 2) * sz, b, p_color);
  525. _draw_hex_code_box_number(p_canvas, sz, pos + Point2(2, 8) * sz, a, p_color);
  526. } else if (p_index <= 0xFFFF) {
  527. _draw_hex_code_box_number(p_canvas, sz, pos + Point2(2, 2) * sz, d, p_color);
  528. _draw_hex_code_box_number(p_canvas, sz, pos + Point2(6, 2) * sz, c, p_color);
  529. _draw_hex_code_box_number(p_canvas, sz, pos + Point2(2, 8) * sz, b, p_color);
  530. _draw_hex_code_box_number(p_canvas, sz, pos + Point2(6, 8) * sz, a, p_color);
  531. } else {
  532. _draw_hex_code_box_number(p_canvas, sz, pos + Point2(2, 2) * sz, f, p_color);
  533. _draw_hex_code_box_number(p_canvas, sz, pos + Point2(6, 2) * sz, e, p_color);
  534. _draw_hex_code_box_number(p_canvas, sz, pos + Point2(10, 2) * sz, d, p_color);
  535. _draw_hex_code_box_number(p_canvas, sz, pos + Point2(2, 8) * sz, c, p_color);
  536. _draw_hex_code_box_number(p_canvas, sz, pos + Point2(6, 8) * sz, b, p_color);
  537. _draw_hex_code_box_number(p_canvas, sz, pos + Point2(10, 8) * sz, a, p_color);
  538. }
  539. }
  540. 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 {
  541. PackedInt32Array lines;
  542. ERR_FAIL_COND_V(p_width.is_empty(), lines);
  543. const_cast<TextServer *>(this)->shaped_text_update_breaks(p_shaped);
  544. const Vector2i &range = shaped_text_get_range(p_shaped);
  545. real_t width = 0.f;
  546. int line_start = MAX(p_start, range.x);
  547. int last_end = line_start;
  548. int prev_safe_break = 0;
  549. int last_safe_break = -1;
  550. int word_count = 0;
  551. int chunk = 0;
  552. bool trim_next = false;
  553. int l_size = shaped_text_get_glyph_count(p_shaped);
  554. const Glyph *l_gl = const_cast<TextServer *>(this)->shaped_text_sort_logical(p_shaped);
  555. for (int i = 0; i < l_size; i++) {
  556. if (l_gl[i].start < p_start) {
  557. prev_safe_break = i + 1;
  558. continue;
  559. }
  560. if (l_gl[i].count > 0) {
  561. if ((p_width[chunk] > 0) && (width + l_gl[i].advance > p_width[chunk]) && (last_safe_break >= 0)) {
  562. if (p_break_flags.has_flag(BREAK_TRIM_EDGE_SPACES)) {
  563. int start_pos = prev_safe_break;
  564. int end_pos = last_safe_break;
  565. 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)) {
  566. start_pos += l_gl[start_pos].count;
  567. }
  568. while ((start_pos < end_pos) && ((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)) {
  569. end_pos -= l_gl[end_pos].count;
  570. }
  571. if (last_end <= l_gl[start_pos].start) {
  572. lines.push_back(l_gl[start_pos].start);
  573. lines.push_back(l_gl[end_pos].end);
  574. last_end = l_gl[end_pos].end;
  575. }
  576. trim_next = true;
  577. } else {
  578. if (last_end <= line_start) {
  579. lines.push_back(line_start);
  580. lines.push_back(l_gl[last_safe_break].end);
  581. last_end = l_gl[last_safe_break].end;
  582. }
  583. }
  584. line_start = l_gl[last_safe_break].end;
  585. prev_safe_break = last_safe_break + 1;
  586. i = last_safe_break;
  587. last_safe_break = -1;
  588. width = 0;
  589. word_count = 0;
  590. chunk++;
  591. if (chunk >= p_width.size()) {
  592. chunk = 0;
  593. if (p_once) {
  594. return lines;
  595. }
  596. }
  597. continue;
  598. }
  599. if (p_break_flags.has_flag(BREAK_MANDATORY)) {
  600. if ((l_gl[i].flags & GRAPHEME_IS_BREAK_HARD) == GRAPHEME_IS_BREAK_HARD) {
  601. if (p_break_flags.has_flag(BREAK_TRIM_EDGE_SPACES)) {
  602. int start_pos = prev_safe_break;
  603. int end_pos = i;
  604. 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)) {
  605. start_pos += l_gl[start_pos].count;
  606. }
  607. while ((start_pos < end_pos) && ((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)) {
  608. end_pos -= l_gl[end_pos].count;
  609. }
  610. if (last_end <= l_gl[start_pos].start) {
  611. lines.push_back(l_gl[start_pos].start);
  612. lines.push_back(l_gl[end_pos].end);
  613. last_end = l_gl[end_pos].end;
  614. }
  615. trim_next = false;
  616. } else {
  617. if (last_end <= line_start) {
  618. lines.push_back(line_start);
  619. lines.push_back(l_gl[i].end);
  620. last_end = l_gl[i].end;
  621. }
  622. }
  623. line_start = l_gl[i].end;
  624. prev_safe_break = i + 1;
  625. last_safe_break = -1;
  626. width = 0;
  627. chunk = 0;
  628. if (p_once) {
  629. return lines;
  630. }
  631. continue;
  632. }
  633. }
  634. if (p_break_flags.has_flag(BREAK_WORD_BOUND)) {
  635. if ((l_gl[i].flags & GRAPHEME_IS_BREAK_SOFT) == GRAPHEME_IS_BREAK_SOFT) {
  636. last_safe_break = i;
  637. word_count++;
  638. }
  639. }
  640. if (p_break_flags.has_flag(BREAK_GRAPHEME_BOUND) && word_count == 0) {
  641. last_safe_break = i;
  642. }
  643. }
  644. width += l_gl[i].advance;
  645. }
  646. if (l_size > 0) {
  647. if (lines.size() == 0 || (lines[lines.size() - 1] < range.y && prev_safe_break < l_size)) {
  648. if (p_break_flags.has_flag(BREAK_TRIM_EDGE_SPACES)) {
  649. int start_pos = (prev_safe_break < l_size) ? prev_safe_break : l_size - 1;
  650. int end_pos = l_size - 1;
  651. 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)) {
  652. start_pos += l_gl[start_pos].count;
  653. }
  654. lines.push_back(l_gl[start_pos].start);
  655. } else {
  656. lines.push_back(line_start);
  657. }
  658. lines.push_back(range.y);
  659. }
  660. } else {
  661. lines.push_back(0);
  662. lines.push_back(0);
  663. }
  664. return lines;
  665. }
  666. 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 {
  667. PackedInt32Array lines;
  668. const_cast<TextServer *>(this)->shaped_text_update_breaks(p_shaped);
  669. const Vector2i &range = shaped_text_get_range(p_shaped);
  670. double width = 0.f;
  671. int line_start = MAX(p_start, range.x);
  672. int last_end = line_start;
  673. int prev_safe_break = 0;
  674. int last_safe_break = -1;
  675. int word_count = 0;
  676. bool trim_next = false;
  677. int l_size = shaped_text_get_glyph_count(p_shaped);
  678. const Glyph *l_gl = const_cast<TextServer *>(this)->shaped_text_sort_logical(p_shaped);
  679. for (int i = 0; i < l_size; i++) {
  680. if (l_gl[i].start < p_start) {
  681. prev_safe_break = i + 1;
  682. continue;
  683. }
  684. if (l_gl[i].count > 0) {
  685. if ((p_width > 0) && (width + l_gl[i].advance * l_gl[i].repeat > p_width) && (last_safe_break >= 0)) {
  686. if (p_break_flags.has_flag(BREAK_TRIM_EDGE_SPACES)) {
  687. int start_pos = prev_safe_break;
  688. int end_pos = last_safe_break;
  689. 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)) {
  690. start_pos += l_gl[start_pos].count;
  691. }
  692. while ((start_pos < end_pos) && ((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)) {
  693. end_pos -= l_gl[end_pos].count;
  694. }
  695. if (last_end <= l_gl[start_pos].start) {
  696. lines.push_back(l_gl[start_pos].start);
  697. lines.push_back(l_gl[end_pos].end);
  698. last_end = l_gl[end_pos].end;
  699. }
  700. trim_next = true;
  701. } else {
  702. if (last_end <= line_start) {
  703. lines.push_back(line_start);
  704. lines.push_back(l_gl[last_safe_break].end);
  705. last_end = l_gl[last_safe_break].end;
  706. }
  707. }
  708. line_start = l_gl[last_safe_break].end;
  709. prev_safe_break = last_safe_break + 1;
  710. i = last_safe_break;
  711. last_safe_break = -1;
  712. width = 0;
  713. word_count = 0;
  714. continue;
  715. }
  716. if (p_break_flags.has_flag(BREAK_MANDATORY)) {
  717. if ((l_gl[i].flags & GRAPHEME_IS_BREAK_HARD) == GRAPHEME_IS_BREAK_HARD) {
  718. if (p_break_flags.has_flag(BREAK_TRIM_EDGE_SPACES)) {
  719. int start_pos = prev_safe_break;
  720. int end_pos = i;
  721. 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)) {
  722. start_pos += l_gl[start_pos].count;
  723. }
  724. while ((start_pos < end_pos) && ((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)) {
  725. end_pos -= l_gl[end_pos].count;
  726. }
  727. trim_next = false;
  728. if (last_end <= l_gl[start_pos].start) {
  729. lines.push_back(l_gl[start_pos].start);
  730. lines.push_back(l_gl[end_pos].end);
  731. last_end = l_gl[end_pos].end;
  732. }
  733. } else {
  734. if (last_end <= line_start) {
  735. lines.push_back(line_start);
  736. lines.push_back(l_gl[i].end);
  737. last_end = l_gl[i].end;
  738. }
  739. }
  740. line_start = l_gl[i].end;
  741. prev_safe_break = i + 1;
  742. last_safe_break = -1;
  743. width = 0;
  744. continue;
  745. }
  746. }
  747. if (p_break_flags.has_flag(BREAK_WORD_BOUND)) {
  748. if ((l_gl[i].flags & GRAPHEME_IS_BREAK_SOFT) == GRAPHEME_IS_BREAK_SOFT) {
  749. last_safe_break = i;
  750. word_count++;
  751. }
  752. if (p_break_flags.has_flag(BREAK_ADAPTIVE) && word_count == 0) {
  753. last_safe_break = i;
  754. }
  755. }
  756. if (p_break_flags.has_flag(BREAK_GRAPHEME_BOUND)) {
  757. last_safe_break = i;
  758. }
  759. }
  760. width += l_gl[i].advance * l_gl[i].repeat;
  761. }
  762. if (l_size > 0) {
  763. if (lines.size() == 0 || (lines[lines.size() - 1] < range.y && prev_safe_break < l_size)) {
  764. if (p_break_flags.has_flag(BREAK_TRIM_EDGE_SPACES)) {
  765. int start_pos = (prev_safe_break < l_size) ? prev_safe_break : l_size - 1;
  766. int end_pos = l_size - 1;
  767. 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)) {
  768. start_pos += l_gl[start_pos].count;
  769. }
  770. lines.push_back(l_gl[start_pos].start);
  771. } else {
  772. lines.push_back(line_start);
  773. }
  774. lines.push_back(range.y);
  775. }
  776. } else {
  777. lines.push_back(0);
  778. lines.push_back(0);
  779. }
  780. return lines;
  781. }
  782. PackedInt32Array TextServer::shaped_text_get_word_breaks(const RID &p_shaped, BitField<TextServer::GraphemeFlag> p_grapheme_flags) const {
  783. PackedInt32Array words;
  784. const_cast<TextServer *>(this)->shaped_text_update_justification_ops(p_shaped);
  785. const Vector2i &range = shaped_text_get_range(p_shaped);
  786. int word_start = range.x;
  787. const int l_size = shaped_text_get_glyph_count(p_shaped);
  788. const Glyph *l_gl = const_cast<TextServer *>(this)->shaped_text_sort_logical(p_shaped);
  789. for (int i = 0; i < l_size; i++) {
  790. if (l_gl[i].count > 0) {
  791. if ((l_gl[i].flags & p_grapheme_flags) != 0) {
  792. if (word_start != l_gl[i].start) {
  793. words.push_back(word_start);
  794. words.push_back(l_gl[i].start);
  795. }
  796. word_start = l_gl[i].end;
  797. }
  798. }
  799. }
  800. if (l_size > 0) {
  801. if (word_start != range.y) {
  802. words.push_back(word_start);
  803. words.push_back(range.y);
  804. }
  805. }
  806. return words;
  807. }
  808. CaretInfo TextServer::shaped_text_get_carets(const RID &p_shaped, int64_t p_position) const {
  809. Vector<Rect2> carets;
  810. TextServer::Orientation orientation = shaped_text_get_orientation(p_shaped);
  811. const Vector2 &range = shaped_text_get_range(p_shaped);
  812. real_t ascent = shaped_text_get_ascent(p_shaped);
  813. real_t descent = shaped_text_get_descent(p_shaped);
  814. real_t height = (ascent + descent) / 2;
  815. real_t off = 0.0f;
  816. CaretInfo caret;
  817. caret.l_dir = DIRECTION_AUTO;
  818. caret.t_dir = DIRECTION_AUTO;
  819. int v_size = shaped_text_get_glyph_count(p_shaped);
  820. const Glyph *glyphs = shaped_text_get_glyphs(p_shaped);
  821. for (int i = 0; i < v_size; i++) {
  822. if (glyphs[i].count > 0) {
  823. // Caret before grapheme (top / left).
  824. if (p_position == glyphs[i].start && ((glyphs[i].flags & GRAPHEME_IS_VIRTUAL) != GRAPHEME_IS_VIRTUAL)) {
  825. real_t advance = 0.f;
  826. for (int j = 0; j < glyphs[i].count; j++) {
  827. advance += glyphs[i + j].advance * glyphs[i + j].repeat;
  828. }
  829. real_t char_adv = advance / (real_t)(glyphs[i].end - glyphs[i].start);
  830. Rect2 cr;
  831. if (orientation == ORIENTATION_HORIZONTAL) {
  832. if (glyphs[i].start == range.x) {
  833. cr.size.y = height * 2;
  834. } else {
  835. cr.size.y = height;
  836. }
  837. cr.position.y = -ascent;
  838. cr.position.x = off;
  839. if ((glyphs[i].flags & GRAPHEME_IS_RTL) == GRAPHEME_IS_RTL) {
  840. caret.t_dir = DIRECTION_RTL;
  841. cr.position.x += advance;
  842. cr.size.x = -char_adv;
  843. } else {
  844. caret.t_dir = DIRECTION_LTR;
  845. cr.size.x = char_adv;
  846. }
  847. } else {
  848. if (glyphs[i].start == range.x) {
  849. cr.size.x = height * 2;
  850. } else {
  851. cr.size.x = height;
  852. }
  853. cr.position.x = -ascent;
  854. cr.position.y = off;
  855. if ((glyphs[i].flags & GRAPHEME_IS_RTL) == GRAPHEME_IS_RTL) {
  856. caret.t_dir = DIRECTION_RTL;
  857. cr.position.y += advance;
  858. cr.size.y = -char_adv;
  859. } else {
  860. caret.t_dir = DIRECTION_LTR;
  861. cr.size.y = char_adv;
  862. }
  863. }
  864. caret.t_caret = cr;
  865. }
  866. // Caret after grapheme (bottom / right).
  867. if (p_position == glyphs[i].end && ((glyphs[i].flags & GRAPHEME_IS_VIRTUAL) != GRAPHEME_IS_VIRTUAL)) {
  868. real_t advance = 0.f;
  869. for (int j = 0; j < glyphs[i].count; j++) {
  870. advance += glyphs[i + j].advance * glyphs[i + j].repeat;
  871. }
  872. real_t char_adv = advance / (real_t)(glyphs[i].end - glyphs[i].start);
  873. Rect2 cr;
  874. if (orientation == ORIENTATION_HORIZONTAL) {
  875. if (glyphs[i].end == range.y) {
  876. cr.size.y = height * 2;
  877. cr.position.y = -ascent;
  878. } else {
  879. cr.size.y = height;
  880. cr.position.y = -ascent + height;
  881. }
  882. cr.position.x = off;
  883. if ((glyphs[i].flags & GRAPHEME_IS_RTL) != GRAPHEME_IS_RTL) {
  884. caret.l_dir = DIRECTION_LTR;
  885. cr.position.x += advance;
  886. cr.size.x = -char_adv;
  887. } else {
  888. caret.l_dir = DIRECTION_RTL;
  889. cr.size.x = char_adv;
  890. }
  891. } else {
  892. cr.size.y = 1.0f;
  893. if (glyphs[i].end == range.y) {
  894. cr.size.x = height * 2;
  895. cr.position.x = -ascent;
  896. } else {
  897. cr.size.x = height;
  898. cr.position.x = -ascent + height;
  899. }
  900. cr.position.y = off;
  901. if ((glyphs[i].flags & GRAPHEME_IS_RTL) != GRAPHEME_IS_RTL) {
  902. caret.l_dir = DIRECTION_LTR;
  903. cr.position.y += advance;
  904. cr.size.y = -char_adv;
  905. } else {
  906. caret.l_dir = DIRECTION_RTL;
  907. cr.position.x += advance;
  908. cr.size.y = char_adv;
  909. }
  910. }
  911. caret.l_caret = cr;
  912. }
  913. // Caret inside grapheme (middle).
  914. if (p_position > glyphs[i].start && p_position < glyphs[i].end && (glyphs[i].flags & GRAPHEME_IS_VIRTUAL) != GRAPHEME_IS_VIRTUAL) {
  915. real_t advance = 0.f;
  916. for (int j = 0; j < glyphs[i].count; j++) {
  917. advance += glyphs[i + j].advance * glyphs[i + j].repeat;
  918. }
  919. real_t char_adv = advance / (real_t)(glyphs[i].end - glyphs[i].start);
  920. Rect2 cr;
  921. if (orientation == ORIENTATION_HORIZONTAL) {
  922. cr.size.y = height * 2;
  923. cr.position.y = -ascent;
  924. if ((glyphs[i].flags & GRAPHEME_IS_RTL) == GRAPHEME_IS_RTL) {
  925. cr.position.x = off + char_adv * (glyphs[i].end - p_position);
  926. cr.size.x = -char_adv;
  927. } else {
  928. cr.position.x = off + char_adv * (p_position - glyphs[i].start);
  929. cr.size.x = char_adv;
  930. }
  931. } else {
  932. cr.size.x = height * 2;
  933. cr.position.x = -ascent;
  934. if ((glyphs[i].flags & GRAPHEME_IS_RTL) == GRAPHEME_IS_RTL) {
  935. cr.position.y = off + char_adv * (glyphs[i].end - p_position);
  936. cr.size.y = -char_adv;
  937. } else {
  938. cr.position.y = off + char_adv * (p_position - glyphs[i].start);
  939. cr.size.y = char_adv;
  940. }
  941. }
  942. caret.t_caret = cr;
  943. caret.l_caret = cr;
  944. }
  945. }
  946. off += glyphs[i].advance * glyphs[i].repeat;
  947. }
  948. return caret;
  949. }
  950. Dictionary TextServer::_shaped_text_get_carets_wrapper(const RID &p_shaped, int64_t p_position) const {
  951. Dictionary ret;
  952. CaretInfo caret = shaped_text_get_carets(p_shaped, p_position);
  953. ret["leading_rect"] = caret.l_caret;
  954. ret["leading_direction"] = caret.l_dir;
  955. ret["trailing_rect"] = caret.t_caret;
  956. ret["trailing_direction"] = caret.t_dir;
  957. return ret;
  958. }
  959. TextServer::Direction TextServer::shaped_text_get_dominant_direction_in_range(const RID &p_shaped, int64_t p_start, int64_t p_end) const {
  960. if (p_start == p_end) {
  961. return DIRECTION_AUTO;
  962. }
  963. int start = MIN(p_start, p_end);
  964. int end = MAX(p_start, p_end);
  965. int rtl = 0;
  966. int ltr = 0;
  967. int v_size = shaped_text_get_glyph_count(p_shaped);
  968. const Glyph *glyphs = shaped_text_get_glyphs(p_shaped);
  969. for (int i = 0; i < v_size; i++) {
  970. if ((glyphs[i].end > start) && (glyphs[i].start < end)) {
  971. if (glyphs[i].count > 0) {
  972. if ((glyphs[i].flags & GRAPHEME_IS_RTL) == GRAPHEME_IS_RTL) {
  973. rtl++;
  974. } else {
  975. ltr++;
  976. }
  977. }
  978. }
  979. }
  980. if (ltr == rtl) {
  981. return DIRECTION_AUTO;
  982. } else if (ltr > rtl) {
  983. return DIRECTION_LTR;
  984. } else {
  985. return DIRECTION_RTL;
  986. }
  987. }
  988. _FORCE_INLINE_ void _push_range(Vector<Vector2> &r_vector, real_t p_start, real_t p_end) {
  989. if (!r_vector.is_empty() && Math::is_equal_approx(r_vector[r_vector.size() - 1].y, p_start, (real_t)UNIT_EPSILON)) {
  990. r_vector.write[r_vector.size() - 1].y = p_end;
  991. } else {
  992. r_vector.push_back(Vector2(p_start, p_end));
  993. }
  994. }
  995. Vector<Vector2> TextServer::shaped_text_get_selection(const RID &p_shaped, int64_t p_start, int64_t p_end) const {
  996. Vector<Vector2> ranges;
  997. if (p_start == p_end) {
  998. return ranges;
  999. }
  1000. int start = MIN(p_start, p_end);
  1001. int end = MAX(p_start, p_end);
  1002. int v_size = shaped_text_get_glyph_count(p_shaped);
  1003. const Glyph *glyphs = shaped_text_get_glyphs(p_shaped);
  1004. real_t off = 0.0f;
  1005. for (int i = 0; i < v_size; i++) {
  1006. for (int k = 0; k < glyphs[i].repeat; k++) {
  1007. if ((glyphs[i].count > 0) && ((glyphs[i].index != 0) || ((glyphs[i].flags & GRAPHEME_IS_SPACE) == GRAPHEME_IS_SPACE))) {
  1008. if (glyphs[i].start < end && glyphs[i].end > start) {
  1009. // Grapheme fully in selection range.
  1010. if (glyphs[i].start >= start && glyphs[i].end <= end) {
  1011. real_t advance = 0.f;
  1012. for (int j = 0; j < glyphs[i].count; j++) {
  1013. advance += glyphs[i + j].advance;
  1014. }
  1015. _push_range(ranges, off, off + advance);
  1016. }
  1017. // Only start of grapheme is in selection range.
  1018. if (glyphs[i].start >= start && glyphs[i].end > end) {
  1019. real_t advance = 0.f;
  1020. for (int j = 0; j < glyphs[i].count; j++) {
  1021. advance += glyphs[i + j].advance;
  1022. }
  1023. real_t char_adv = advance / (real_t)(glyphs[i].end - glyphs[i].start);
  1024. if ((glyphs[i].flags & GRAPHEME_IS_RTL) == GRAPHEME_IS_RTL) {
  1025. _push_range(ranges, off + char_adv * (glyphs[i].end - end), off + advance);
  1026. } else {
  1027. _push_range(ranges, off, off + char_adv * (end - glyphs[i].start));
  1028. }
  1029. }
  1030. // Only end of grapheme is in selection range.
  1031. if (glyphs[i].start < start && glyphs[i].end <= end) {
  1032. real_t advance = 0.f;
  1033. for (int j = 0; j < glyphs[i].count; j++) {
  1034. advance += glyphs[i + j].advance;
  1035. }
  1036. real_t char_adv = advance / (real_t)(glyphs[i].end - glyphs[i].start);
  1037. if ((glyphs[i].flags & GRAPHEME_IS_RTL) == GRAPHEME_IS_RTL) {
  1038. _push_range(ranges, off, off + char_adv * (glyphs[i].end - start));
  1039. } else {
  1040. _push_range(ranges, off + char_adv * (start - glyphs[i].start), off + advance);
  1041. }
  1042. }
  1043. // Selection range is within grapheme.
  1044. if (glyphs[i].start < start && glyphs[i].end > end) {
  1045. real_t advance = 0.f;
  1046. for (int j = 0; j < glyphs[i].count; j++) {
  1047. advance += glyphs[i + j].advance;
  1048. }
  1049. real_t char_adv = advance / (real_t)(glyphs[i].end - glyphs[i].start);
  1050. if ((glyphs[i].flags & GRAPHEME_IS_RTL) == GRAPHEME_IS_RTL) {
  1051. _push_range(ranges, off + char_adv * (glyphs[i].end - end), off + char_adv * (glyphs[i].end - start));
  1052. } else {
  1053. _push_range(ranges, off + char_adv * (start - glyphs[i].start), off + char_adv * (end - glyphs[i].start));
  1054. }
  1055. }
  1056. }
  1057. }
  1058. off += glyphs[i].advance;
  1059. }
  1060. }
  1061. return ranges;
  1062. }
  1063. int64_t TextServer::shaped_text_hit_test_grapheme(const RID &p_shaped, double p_coords) const {
  1064. // Exact grapheme hit test, return -1 if missed.
  1065. double off = 0.0f;
  1066. int v_size = shaped_text_get_glyph_count(p_shaped);
  1067. const Glyph *glyphs = shaped_text_get_glyphs(p_shaped);
  1068. for (int i = 0; i < v_size; i++) {
  1069. for (int j = 0; j < glyphs[i].repeat; j++) {
  1070. if (p_coords >= off && p_coords < off + glyphs[i].advance) {
  1071. return i;
  1072. }
  1073. off += glyphs[i].advance;
  1074. }
  1075. }
  1076. return -1;
  1077. }
  1078. int64_t TextServer::shaped_text_hit_test_position(const RID &p_shaped, double p_coords) const {
  1079. int v_size = shaped_text_get_glyph_count(p_shaped);
  1080. const Glyph *glyphs = shaped_text_get_glyphs(p_shaped);
  1081. // Cursor placement hit test.
  1082. // Place caret to the left of the leftmost grapheme, or to position 0 if string is empty.
  1083. if (p_coords <= 0) {
  1084. if (v_size > 0) {
  1085. if ((glyphs[0].flags & GRAPHEME_IS_RTL) == GRAPHEME_IS_RTL) {
  1086. return glyphs[0].end;
  1087. } else {
  1088. return glyphs[0].start;
  1089. }
  1090. } else {
  1091. return 0;
  1092. }
  1093. }
  1094. // Place caret to the right of the rightmost grapheme, or to position 0 if string is empty.
  1095. if (p_coords >= shaped_text_get_width(p_shaped)) {
  1096. if (v_size > 0) {
  1097. if ((glyphs[v_size - 1].flags & GRAPHEME_IS_RTL) == GRAPHEME_IS_RTL) {
  1098. return glyphs[v_size - 1].start;
  1099. } else {
  1100. return glyphs[v_size - 1].end;
  1101. }
  1102. } else {
  1103. return 0;
  1104. }
  1105. }
  1106. real_t off = 0.0f;
  1107. for (int i = 0; i < v_size; i++) {
  1108. if (glyphs[i].count > 0) {
  1109. real_t advance = 0.f;
  1110. for (int j = 0; j < glyphs[i].count; j++) {
  1111. advance += glyphs[i + j].advance * glyphs[i + j].repeat;
  1112. }
  1113. if (((glyphs[i].flags & GRAPHEME_IS_VIRTUAL) == GRAPHEME_IS_VIRTUAL) && (p_coords >= off && p_coords < off + advance)) {
  1114. if ((glyphs[i].flags & GRAPHEME_IS_RTL) == GRAPHEME_IS_RTL) {
  1115. return glyphs[i].end;
  1116. } else {
  1117. return glyphs[i].start;
  1118. }
  1119. }
  1120. // Ligature, handle mid-grapheme hit.
  1121. if (p_coords >= off && p_coords < off + advance && glyphs[i].end > glyphs[i].start + 1) {
  1122. int cnt = glyphs[i].end - glyphs[i].start;
  1123. real_t char_adv = advance / (real_t)(cnt);
  1124. real_t sub_off = off;
  1125. for (int j = 0; j < cnt; j++) {
  1126. // Place caret to the left of clicked sub-grapheme.
  1127. if (p_coords >= sub_off && p_coords < sub_off + char_adv / 2) {
  1128. if ((glyphs[i].flags & GRAPHEME_IS_RTL) == GRAPHEME_IS_RTL) {
  1129. return glyphs[i].end - j;
  1130. } else {
  1131. return glyphs[i].start + j;
  1132. }
  1133. }
  1134. // Place caret to the right of clicked sub-grapheme.
  1135. if (p_coords >= sub_off + char_adv / 2 && p_coords < sub_off + char_adv) {
  1136. if ((glyphs[i].flags & GRAPHEME_IS_RTL) == GRAPHEME_IS_RTL) {
  1137. return glyphs[i].start + (cnt - 1) - j;
  1138. } else {
  1139. return glyphs[i].end - (cnt - 1) + j;
  1140. }
  1141. }
  1142. sub_off += char_adv;
  1143. }
  1144. }
  1145. // Place caret to the left of clicked grapheme.
  1146. if (p_coords >= off && p_coords < off + advance / 2) {
  1147. if ((glyphs[i].flags & GRAPHEME_IS_RTL) == GRAPHEME_IS_RTL) {
  1148. return glyphs[i].end;
  1149. } else {
  1150. return glyphs[i].start;
  1151. }
  1152. }
  1153. // Place caret to the right of clicked grapheme.
  1154. if (p_coords >= off + advance / 2 && p_coords < off + advance) {
  1155. if ((glyphs[i].flags & GRAPHEME_IS_RTL) == GRAPHEME_IS_RTL) {
  1156. return glyphs[i].start;
  1157. } else {
  1158. return glyphs[i].end;
  1159. }
  1160. }
  1161. }
  1162. off += glyphs[i].advance * glyphs[i].repeat;
  1163. }
  1164. return 0;
  1165. }
  1166. Vector2 TextServer::shaped_text_get_grapheme_bounds(const RID &p_shaped, int64_t p_pos) const {
  1167. int v_size = shaped_text_get_glyph_count(p_shaped);
  1168. const Glyph *glyphs = shaped_text_get_glyphs(p_shaped);
  1169. real_t off = 0.0f;
  1170. for (int i = 0; i < v_size; i++) {
  1171. if ((glyphs[i].count > 0) && ((glyphs[i].index != 0) || ((glyphs[i].flags & GRAPHEME_IS_SPACE) == GRAPHEME_IS_SPACE))) {
  1172. if (glyphs[i].start <= p_pos && glyphs[i].end >= p_pos) {
  1173. real_t advance = 0.f;
  1174. for (int j = 0; j < glyphs[i].count; j++) {
  1175. advance += glyphs[i + j].advance;
  1176. }
  1177. return Vector2(off, off + advance);
  1178. }
  1179. }
  1180. off += glyphs[i].advance * glyphs[i].repeat;
  1181. }
  1182. return Vector2();
  1183. }
  1184. int64_t TextServer::shaped_text_next_grapheme_pos(const RID &p_shaped, int64_t p_pos) const {
  1185. int v_size = shaped_text_get_glyph_count(p_shaped);
  1186. const Glyph *glyphs = shaped_text_get_glyphs(p_shaped);
  1187. for (int i = 0; i < v_size; i++) {
  1188. if (p_pos >= glyphs[i].start && p_pos < glyphs[i].end) {
  1189. return glyphs[i].end;
  1190. }
  1191. }
  1192. return p_pos;
  1193. }
  1194. int64_t TextServer::shaped_text_prev_grapheme_pos(const RID &p_shaped, int64_t p_pos) const {
  1195. int v_size = shaped_text_get_glyph_count(p_shaped);
  1196. const Glyph *glyphs = shaped_text_get_glyphs(p_shaped);
  1197. for (int i = 0; i < v_size; i++) {
  1198. if (p_pos > glyphs[i].start && p_pos <= glyphs[i].end) {
  1199. return glyphs[i].start;
  1200. }
  1201. }
  1202. return p_pos;
  1203. }
  1204. 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) const {
  1205. TextServer::Orientation orientation = shaped_text_get_orientation(p_shaped);
  1206. bool hex_codes = shaped_text_get_preserve_control(p_shaped) || shaped_text_get_preserve_invalid(p_shaped);
  1207. bool rtl = shaped_text_get_direction(p_shaped) == DIRECTION_RTL;
  1208. int ellipsis_pos = shaped_text_get_ellipsis_pos(p_shaped);
  1209. int trim_pos = shaped_text_get_trim_pos(p_shaped);
  1210. const Glyph *ellipsis_glyphs = shaped_text_get_ellipsis_glyphs(p_shaped);
  1211. int ellipsis_gl_size = shaped_text_get_ellipsis_glyph_count(p_shaped);
  1212. int v_size = shaped_text_get_glyph_count(p_shaped);
  1213. const Glyph *glyphs = shaped_text_get_glyphs(p_shaped);
  1214. Vector2 ofs = p_pos;
  1215. // Draw RTL ellipsis string when needed.
  1216. if (rtl && ellipsis_pos >= 0) {
  1217. for (int i = ellipsis_gl_size - 1; i >= 0; i--) {
  1218. for (int j = 0; j < ellipsis_glyphs[i].repeat; j++) {
  1219. font_draw_glyph(ellipsis_glyphs[i].font_rid, p_canvas, ellipsis_glyphs[i].font_size, ofs + Vector2(ellipsis_glyphs[i].x_off, ellipsis_glyphs[i].y_off), ellipsis_glyphs[i].index, p_color);
  1220. if (orientation == ORIENTATION_HORIZONTAL) {
  1221. ofs.x += ellipsis_glyphs[i].advance;
  1222. } else {
  1223. ofs.y += ellipsis_glyphs[i].advance;
  1224. }
  1225. }
  1226. }
  1227. }
  1228. // Draw at the baseline.
  1229. for (int i = 0; i < v_size; i++) {
  1230. if (trim_pos >= 0) {
  1231. if (rtl) {
  1232. if (i < trim_pos) {
  1233. continue;
  1234. }
  1235. } else {
  1236. if (i >= trim_pos) {
  1237. break;
  1238. }
  1239. }
  1240. }
  1241. for (int j = 0; j < glyphs[i].repeat; j++) {
  1242. if (p_clip_r > 0) {
  1243. // Clip right / bottom.
  1244. if (orientation == ORIENTATION_HORIZONTAL) {
  1245. if (ofs.x - p_pos.x + glyphs[i].advance > p_clip_r) {
  1246. return;
  1247. }
  1248. } else {
  1249. if (ofs.y - p_pos.y + glyphs[i].advance > p_clip_r) {
  1250. return;
  1251. }
  1252. }
  1253. }
  1254. if (p_clip_l > 0) {
  1255. // Clip left / top.
  1256. if (orientation == ORIENTATION_HORIZONTAL) {
  1257. if (ofs.x - p_pos.x < p_clip_l) {
  1258. ofs.x += glyphs[i].advance;
  1259. continue;
  1260. }
  1261. } else {
  1262. if (ofs.y - p_pos.y < p_clip_l) {
  1263. ofs.y += glyphs[i].advance;
  1264. continue;
  1265. }
  1266. }
  1267. }
  1268. if (glyphs[i].font_rid != RID()) {
  1269. font_draw_glyph(glyphs[i].font_rid, p_canvas, glyphs[i].font_size, ofs + Vector2(glyphs[i].x_off, glyphs[i].y_off), glyphs[i].index, p_color);
  1270. } else if (hex_codes && ((glyphs[i].flags & GRAPHEME_IS_VIRTUAL) != GRAPHEME_IS_VIRTUAL) && ((glyphs[i].flags & GRAPHEME_IS_EMBEDDED_OBJECT) != GRAPHEME_IS_EMBEDDED_OBJECT)) {
  1271. TextServer::draw_hex_code_box(p_canvas, glyphs[i].font_size, ofs + Vector2(glyphs[i].x_off, glyphs[i].y_off), glyphs[i].index, p_color);
  1272. }
  1273. if (orientation == ORIENTATION_HORIZONTAL) {
  1274. ofs.x += glyphs[i].advance;
  1275. } else {
  1276. ofs.y += glyphs[i].advance;
  1277. }
  1278. }
  1279. }
  1280. // Draw LTR ellipsis string when needed.
  1281. if (!rtl && ellipsis_pos >= 0) {
  1282. for (int i = 0; i < ellipsis_gl_size; i++) {
  1283. for (int j = 0; j < ellipsis_glyphs[i].repeat; j++) {
  1284. font_draw_glyph(ellipsis_glyphs[i].font_rid, p_canvas, ellipsis_glyphs[i].font_size, ofs + Vector2(ellipsis_glyphs[i].x_off, ellipsis_glyphs[i].y_off), ellipsis_glyphs[i].index, p_color);
  1285. if (orientation == ORIENTATION_HORIZONTAL) {
  1286. ofs.x += ellipsis_glyphs[i].advance;
  1287. } else {
  1288. ofs.y += ellipsis_glyphs[i].advance;
  1289. }
  1290. }
  1291. }
  1292. }
  1293. }
  1294. 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) const {
  1295. TextServer::Orientation orientation = shaped_text_get_orientation(p_shaped);
  1296. bool rtl = (shaped_text_get_inferred_direction(p_shaped) == DIRECTION_RTL);
  1297. int ellipsis_pos = shaped_text_get_ellipsis_pos(p_shaped);
  1298. int trim_pos = shaped_text_get_trim_pos(p_shaped);
  1299. const Glyph *ellipsis_glyphs = shaped_text_get_ellipsis_glyphs(p_shaped);
  1300. int ellipsis_gl_size = shaped_text_get_ellipsis_glyph_count(p_shaped);
  1301. int v_size = shaped_text_get_glyph_count(p_shaped);
  1302. const Glyph *glyphs = shaped_text_get_glyphs(p_shaped);
  1303. Vector2 ofs = p_pos;
  1304. // Draw RTL ellipsis string when needed.
  1305. if (rtl && ellipsis_pos >= 0) {
  1306. for (int i = ellipsis_gl_size - 1; i >= 0; i--) {
  1307. for (int j = 0; j < ellipsis_glyphs[i].repeat; j++) {
  1308. font_draw_glyph(ellipsis_glyphs[i].font_rid, p_canvas, ellipsis_glyphs[i].font_size, ofs + Vector2(ellipsis_glyphs[i].x_off, ellipsis_glyphs[i].y_off), ellipsis_glyphs[i].index, p_color);
  1309. if (orientation == ORIENTATION_HORIZONTAL) {
  1310. ofs.x += ellipsis_glyphs[i].advance;
  1311. } else {
  1312. ofs.y += ellipsis_glyphs[i].advance;
  1313. }
  1314. }
  1315. }
  1316. }
  1317. // Draw at the baseline.
  1318. for (int i = 0; i < v_size; i++) {
  1319. if (trim_pos >= 0) {
  1320. if (rtl) {
  1321. if (i < trim_pos) {
  1322. continue;
  1323. }
  1324. } else {
  1325. if (i >= trim_pos) {
  1326. break;
  1327. }
  1328. }
  1329. }
  1330. for (int j = 0; j < glyphs[i].repeat; j++) {
  1331. if (p_clip_r > 0) {
  1332. // Clip right / bottom.
  1333. if (orientation == ORIENTATION_HORIZONTAL) {
  1334. if (ofs.x - p_pos.x + glyphs[i].advance > p_clip_r) {
  1335. return;
  1336. }
  1337. } else {
  1338. if (ofs.y - p_pos.y + glyphs[i].advance > p_clip_r) {
  1339. return;
  1340. }
  1341. }
  1342. }
  1343. if (p_clip_l > 0) {
  1344. // Clip left / top.
  1345. if (orientation == ORIENTATION_HORIZONTAL) {
  1346. if (ofs.x - p_pos.x < p_clip_l) {
  1347. ofs.x += glyphs[i].advance;
  1348. continue;
  1349. }
  1350. } else {
  1351. if (ofs.y - p_pos.y < p_clip_l) {
  1352. ofs.y += glyphs[i].advance;
  1353. continue;
  1354. }
  1355. }
  1356. }
  1357. if (glyphs[i].font_rid != RID()) {
  1358. font_draw_glyph_outline(glyphs[i].font_rid, p_canvas, glyphs[i].font_size, p_outline_size, ofs + Vector2(glyphs[i].x_off, glyphs[i].y_off), glyphs[i].index, p_color);
  1359. }
  1360. if (orientation == ORIENTATION_HORIZONTAL) {
  1361. ofs.x += glyphs[i].advance;
  1362. } else {
  1363. ofs.y += glyphs[i].advance;
  1364. }
  1365. }
  1366. }
  1367. // Draw LTR ellipsis string when needed.
  1368. if (!rtl && ellipsis_pos >= 0) {
  1369. for (int i = 0; i < ellipsis_gl_size; i++) {
  1370. for (int j = 0; j < ellipsis_glyphs[i].repeat; j++) {
  1371. font_draw_glyph(ellipsis_glyphs[i].font_rid, p_canvas, ellipsis_glyphs[i].font_size, ofs + Vector2(ellipsis_glyphs[i].x_off, ellipsis_glyphs[i].y_off), ellipsis_glyphs[i].index, p_color);
  1372. if (orientation == ORIENTATION_HORIZONTAL) {
  1373. ofs.x += ellipsis_glyphs[i].advance;
  1374. } else {
  1375. ofs.y += ellipsis_glyphs[i].advance;
  1376. }
  1377. }
  1378. }
  1379. }
  1380. }
  1381. void TextServer::_diacritics_map_add(const String &p_from, char32_t p_to) {
  1382. for (int i = 0; i < p_from.size(); i++) {
  1383. diacritics_map[p_from[i]] = p_to;
  1384. }
  1385. }
  1386. void TextServer::_init_diacritics_map() {
  1387. diacritics_map.clear();
  1388. // Latin.
  1389. _diacritics_map_add(U"ÀÁÂÃÄÅĀĂĄǍǞǠǺȀȂȦḀẠẢẤẦẨẪẬẮẰẲẴẶ", U'A');
  1390. _diacritics_map_add(U"àáâãäåāăąǎǟǡǻȁȃȧḁẚạảấầẩẫậắằẳẵặ", U'a');
  1391. _diacritics_map_add(U"ǢǼ", U'Æ');
  1392. _diacritics_map_add(U"ǣǽ", U'æ');
  1393. _diacritics_map_add(U"ḂḄḆ", U'B');
  1394. _diacritics_map_add(U"ḃḅḇ", U'b');
  1395. _diacritics_map_add(U"ÇĆĈĊČḈ", U'C');
  1396. _diacritics_map_add(U"çćĉċčḉ", U'c');
  1397. _diacritics_map_add(U"ĎḊḌḎḐḒ", U'D');
  1398. _diacritics_map_add(U"ďḋḍḏḑḓ", U'd');
  1399. _diacritics_map_add(U"ÈÉÊËĒĔĖĘĚȆȨḔḖḘḚḜẸẺẼẾỀỂỄỆ", U'E');
  1400. _diacritics_map_add(U"èéêëēĕėęěȇȩḕḗḙḛḝẹẻẽếềểễệ", U'e');
  1401. _diacritics_map_add(U"Ḟ", U'F');
  1402. _diacritics_map_add(U"ḟ", U'f');
  1403. _diacritics_map_add(U"ĜĞĠĢǦǴḠ", U'G');
  1404. _diacritics_map_add(U"ĝğġģǧǵḡ", U'g');
  1405. _diacritics_map_add(U"ĤȞḢḤḦḨḪ", U'H');
  1406. _diacritics_map_add(U"ĥȟḣḥḧḩḫẖ", U'h');
  1407. _diacritics_map_add(U"ÌÍÎÏĨĪĬĮİǏȈȊḬḮỈỊ", U'I');
  1408. _diacritics_map_add(U"ìíîïĩīĭįıǐȉȋḭḯỉị", U'i');
  1409. _diacritics_map_add(U"Ĵ", U'J');
  1410. _diacritics_map_add(U"ĵ", U'j');
  1411. _diacritics_map_add(U"ĶǨḰḲḴ", U'K');
  1412. _diacritics_map_add(U"ķĸǩḱḳḵ", U'k');
  1413. _diacritics_map_add(U"ĹĻĽĿḶḸḺḼ", U'L');
  1414. _diacritics_map_add(U"ĺļľŀḷḹḻḽ", U'l');
  1415. _diacritics_map_add(U"ḾṀṂ", U'M');
  1416. _diacritics_map_add(U"ḿṁṃ", U'm');
  1417. _diacritics_map_add(U"ÑŃŅŇǸṄṆṈṊ", U'N');
  1418. _diacritics_map_add(U"ñńņňʼnǹṅṇṉṋ", U'n');
  1419. _diacritics_map_add(U"ÒÓÔÕÖŌŎŐƠǑǪǬȌȎȪȬȮȰṌṎṐṒỌỎỐỒỔỖỘỚỜỞỠỢ", U'O');
  1420. _diacritics_map_add(U"òóôõöōŏőơǒǫǭȍȏȫȭȯȱṍṏṑṓọỏốồổỗộớờởỡợ", U'o');
  1421. _diacritics_map_add(U"ṔṖ", U'P');
  1422. _diacritics_map_add(U"ṗṕ", U'p');
  1423. _diacritics_map_add(U"ŔŖŘȐȒṘṚṜṞ", U'R');
  1424. _diacritics_map_add(U"ŕŗřȑȓṙṛṝṟ", U'r');
  1425. _diacritics_map_add(U"ŚŜŞŠȘṠṢṤṦṨ", U'S');
  1426. _diacritics_map_add(U"śŝşšſșṡṣṥṧṩẛẜẝ", U's');
  1427. _diacritics_map_add(U"ŢŤȚṪṬṮṰ", U'T');
  1428. _diacritics_map_add(U"ţťțṫṭṯṱẗ", U't');
  1429. _diacritics_map_add(U"ÙÚÛÜŨŪŬŮŰŲƯǓǕǗǙǛȔȖṲṴṶṸṺỤỦỨỪỬỮỰ", U'U');
  1430. _diacritics_map_add(U"ùúûüũūŭůűųưǔǖǘǚǜȕȗṳṵṷṹṻụủứừửữự", U'u');
  1431. _diacritics_map_add(U"ṼṾ", U'V');
  1432. _diacritics_map_add(U"ṽṿ", U'v');
  1433. _diacritics_map_add(U"ŴẀẂẄẆẈ", U'W');
  1434. _diacritics_map_add(U"ŵẁẃẅẇẉẘ", U'w');
  1435. _diacritics_map_add(U"ẊẌ", U'X');
  1436. _diacritics_map_add(U"ẋẍ", U'x');
  1437. _diacritics_map_add(U"ÝŶẎỲỴỶỸỾ", U'Y');
  1438. _diacritics_map_add(U"ýÿŷẏẙỳỵỷỹỿ", U'y');
  1439. _diacritics_map_add(U"ŹŻŽẐẒẔ", U'Z');
  1440. _diacritics_map_add(U"źżžẑẓẕ", U'z');
  1441. // Greek.
  1442. _diacritics_map_add(U"ΆἈἉἊἋἌἍἎἏᾈᾉᾊᾋᾌᾍᾎᾏᾸᾹᾺΆᾼ", U'Α');
  1443. _diacritics_map_add(U"άἀἁἂἃἄἅἆἇὰάᾀᾁᾂᾃᾄᾅᾆᾇᾰᾱᾲᾳᾴᾶᾷ", U'α');
  1444. _diacritics_map_add(U"ΈἘἙἚἛἜἝῈΈ", U'Ε');
  1445. _diacritics_map_add(U"έἐἑἒἓἔἕὲέ", U'ε');
  1446. _diacritics_map_add(U"ΉἨἩἪἫἬἭἮἯᾘᾙᾚᾛᾜᾝᾞᾟῊΉῌ", U'Η');
  1447. _diacritics_map_add(U"ήἠἡἢἣἤἥἦἧὴήᾐᾑᾒᾓᾔᾕᾖᾗῂῃῄῆῇ", U'η');
  1448. _diacritics_map_add(U"ΊΪἸἹἺἻἼἽἾἿῘῙῚΊ", U'Ι');
  1449. _diacritics_map_add(U"ίΐϊἰἱἲἳἴἵἶἷὶίῐῑῒΐῖῗ", U'ι');
  1450. _diacritics_map_add(U"ΌὈὉὊὋὌὍῸΌ", U'Ο');
  1451. _diacritics_map_add(U"όὀὁὂὃὄὅὸό", U'ο');
  1452. _diacritics_map_add(U"Ῥ", U'Ρ');
  1453. _diacritics_map_add(U"ῤῥ", U'ρ');
  1454. _diacritics_map_add(U"ΎΫϓϔὙὛὝὟῨῩῪΎ", U'Υ');
  1455. _diacritics_map_add(U"ΰϋύὐὑὒὓὔὕὖὗὺύῠῡῢΰῦῧ", U'υ');
  1456. _diacritics_map_add(U"ΏὨὩὪὫὬὭὮὯᾨᾩᾪᾫᾬᾭᾮᾯῺΏῼ", U'Ω');
  1457. _diacritics_map_add(U"ώὠὡὢὣὤὥὦὧὼώᾠᾡᾢᾣᾤᾥᾦᾧῲῳῴῶῷ", U'ω');
  1458. // Cyrillic.
  1459. _diacritics_map_add(U"ӐӒ", U'А');
  1460. _diacritics_map_add(U"ӑӓ", U'а');
  1461. _diacritics_map_add(U"ЀЁӖ", U'Е');
  1462. _diacritics_map_add(U"ѐёӗ", U'е');
  1463. _diacritics_map_add(U"Ӛ", U'Ә');
  1464. _diacritics_map_add(U"ӛ", U'ә');
  1465. _diacritics_map_add(U"Ӝ", U'Ж');
  1466. _diacritics_map_add(U"ӝ", U'ж');
  1467. _diacritics_map_add(U"Ӟ", U'З');
  1468. _diacritics_map_add(U"ӟ", U'з');
  1469. _diacritics_map_add(U"Ѓ", U'Г');
  1470. _diacritics_map_add(U"ѓ", U'г');
  1471. _diacritics_map_add(U"Ї", U'І');
  1472. _diacritics_map_add(U"ї", U'і');
  1473. _diacritics_map_add(U"ЍӢӤЙ", U'И');
  1474. _diacritics_map_add(U"ѝӣӥй", U'и');
  1475. _diacritics_map_add(U"Ќ", U'К');
  1476. _diacritics_map_add(U"ќ", U'к');
  1477. _diacritics_map_add(U"Ӧ", U'О');
  1478. _diacritics_map_add(U"ӧ", U'о');
  1479. _diacritics_map_add(U"Ӫ", U'Ө');
  1480. _diacritics_map_add(U"ӫ", U'ө');
  1481. _diacritics_map_add(U"Ӭ", U'Э');
  1482. _diacritics_map_add(U"ӭ", U'э');
  1483. _diacritics_map_add(U"ЎӮӰӲ", U'У');
  1484. _diacritics_map_add(U"ўӯӱӳ", U'у');
  1485. _diacritics_map_add(U"Ӵ", U'Ч');
  1486. _diacritics_map_add(U"ӵ", U'ч');
  1487. _diacritics_map_add(U"Ӹ", U'Ы');
  1488. _diacritics_map_add(U"ӹ", U'ы');
  1489. }
  1490. String TextServer::strip_diacritics(const String &p_string) const {
  1491. String result;
  1492. for (int i = 0; i < p_string.length(); i++) {
  1493. if (p_string[i] < 0x02B0 || p_string[i] > 0x036F) { // Skip combining diacritics.
  1494. if (diacritics_map.has(p_string[i])) {
  1495. result += diacritics_map[p_string[i]];
  1496. } else {
  1497. result += p_string[i];
  1498. }
  1499. }
  1500. }
  1501. return result;
  1502. }
  1503. TypedArray<Vector3i> TextServer::parse_structured_text(StructuredTextParser p_parser_type, const Array &p_args, const String &p_text) const {
  1504. TypedArray<Vector3i> ret;
  1505. switch (p_parser_type) {
  1506. case STRUCTURED_TEXT_URI: {
  1507. int prev = 0;
  1508. for (int i = 0; i < p_text.length(); i++) {
  1509. 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] == '#')) {
  1510. if (prev != i) {
  1511. ret.push_back(Vector3i(prev, i, TextServer::DIRECTION_AUTO));
  1512. }
  1513. ret.push_back(Vector3i(i, i + 1, TextServer::DIRECTION_LTR));
  1514. prev = i + 1;
  1515. }
  1516. }
  1517. if (prev != p_text.length()) {
  1518. ret.push_back(Vector3i(prev, p_text.length(), TextServer::DIRECTION_AUTO));
  1519. }
  1520. } break;
  1521. case STRUCTURED_TEXT_FILE: {
  1522. int prev = 0;
  1523. for (int i = 0; i < p_text.length(); i++) {
  1524. if ((p_text[i] == '\\') || (p_text[i] == '/') || (p_text[i] == ':')) {
  1525. if (prev != i) {
  1526. ret.push_back(Vector3i(prev, i, TextServer::DIRECTION_AUTO));
  1527. }
  1528. ret.push_back(Vector3i(i, i + 1, TextServer::DIRECTION_LTR));
  1529. prev = i + 1;
  1530. }
  1531. }
  1532. if (prev != p_text.length()) {
  1533. ret.push_back(Vector3i(prev, p_text.length(), TextServer::DIRECTION_AUTO));
  1534. }
  1535. } break;
  1536. case STRUCTURED_TEXT_EMAIL: {
  1537. bool local = true;
  1538. int prev = 0;
  1539. for (int i = 0; i < p_text.length(); i++) {
  1540. if ((p_text[i] == '@') && local) { // Add full "local" as single context.
  1541. local = false;
  1542. ret.push_back(Vector3i(prev, i, TextServer::DIRECTION_AUTO));
  1543. ret.push_back(Vector3i(i, i + 1, TextServer::DIRECTION_LTR));
  1544. prev = i + 1;
  1545. } else if (!local && (p_text[i] == '.')) { // Add each dot separated "domain" part as context.
  1546. if (prev != i) {
  1547. ret.push_back(Vector3i(prev, i, TextServer::DIRECTION_AUTO));
  1548. }
  1549. ret.push_back(Vector3i(i, i + 1, TextServer::DIRECTION_LTR));
  1550. prev = i + 1;
  1551. }
  1552. }
  1553. if (prev != p_text.length()) {
  1554. ret.push_back(Vector3i(prev, p_text.length(), TextServer::DIRECTION_AUTO));
  1555. }
  1556. } break;
  1557. case STRUCTURED_TEXT_LIST: {
  1558. if (p_args.size() == 1 && p_args[0].get_type() == Variant::STRING) {
  1559. Vector<String> tags = p_text.split(String(p_args[0]));
  1560. int prev = 0;
  1561. for (int i = 0; i < tags.size(); i++) {
  1562. if (prev != i) {
  1563. ret.push_back(Vector3i(prev, prev + tags[i].length(), TextServer::DIRECTION_INHERITED));
  1564. }
  1565. ret.push_back(Vector3i(prev + tags[i].length(), prev + tags[i].length() + 1, TextServer::DIRECTION_INHERITED));
  1566. prev = prev + tags[i].length() + 1;
  1567. }
  1568. }
  1569. } break;
  1570. case STRUCTURED_TEXT_GDSCRIPT: {
  1571. bool in_string_literal = false;
  1572. bool in_string_literal_single = false;
  1573. bool in_id = false;
  1574. int prev = 0;
  1575. for (int i = 0; i < p_text.length(); i++) {
  1576. char32_t c = p_text[i];
  1577. if (in_string_literal) {
  1578. if (c == '\\') {
  1579. i++;
  1580. continue; // Skip escaped chars.
  1581. } else if (c == '\"') {
  1582. // String literal end, push string and ".
  1583. if (prev != i) {
  1584. ret.push_back(Vector3i(prev, i, TextServer::DIRECTION_AUTO));
  1585. }
  1586. prev = i + 1;
  1587. ret.push_back(Vector3i(i, i + 1, TextServer::DIRECTION_LTR));
  1588. in_string_literal = false;
  1589. }
  1590. } else if (in_string_literal_single) {
  1591. if (c == '\\') {
  1592. i++;
  1593. continue; // Skip escaped chars.
  1594. } else if (c == '\'') {
  1595. // String literal end, push string and '.
  1596. if (prev != i) {
  1597. ret.push_back(Vector3i(prev, i, TextServer::DIRECTION_AUTO));
  1598. }
  1599. prev = i + 1;
  1600. ret.push_back(Vector3i(i, i + 1, TextServer::DIRECTION_LTR));
  1601. in_string_literal_single = false;
  1602. }
  1603. } else if (in_id) {
  1604. if (!is_unicode_identifier_continue(c)) {
  1605. // End of id, push id.
  1606. if (prev != i) {
  1607. ret.push_back(Vector3i(prev, i, TextServer::DIRECTION_AUTO));
  1608. }
  1609. prev = i;
  1610. in_id = false;
  1611. }
  1612. } else if (is_unicode_identifier_start(c)) {
  1613. // Start of new id, push prev element.
  1614. if (prev != i) {
  1615. ret.push_back(Vector3i(prev, i, TextServer::DIRECTION_AUTO));
  1616. }
  1617. prev = i;
  1618. in_id = true;
  1619. } else if (c == '\"') {
  1620. // String literal start, push prev element and ".
  1621. if (prev != i) {
  1622. ret.push_back(Vector3i(prev, i, TextServer::DIRECTION_AUTO));
  1623. }
  1624. prev = i + 1;
  1625. ret.push_back(Vector3i(i, i + 1, TextServer::DIRECTION_LTR));
  1626. in_string_literal = true;
  1627. } else if (c == '\'') {
  1628. // String literal start, push prev element and '.
  1629. if (prev != i) {
  1630. ret.push_back(Vector3i(prev, i, TextServer::DIRECTION_AUTO));
  1631. }
  1632. prev = i + 1;
  1633. ret.push_back(Vector3i(i, i + 1, TextServer::DIRECTION_LTR));
  1634. in_string_literal_single = true;
  1635. } else if (c == '#') {
  1636. // Start of comment, push prev element and #, skip the rest of the text.
  1637. if (prev != i) {
  1638. ret.push_back(Vector3i(prev, i, TextServer::DIRECTION_AUTO));
  1639. }
  1640. prev = i + 1;
  1641. ret.push_back(Vector3i(i, i + 1, TextServer::DIRECTION_LTR));
  1642. break;
  1643. }
  1644. }
  1645. if (prev < p_text.length()) {
  1646. ret.push_back(Vector3i(prev, p_text.length(), TextServer::DIRECTION_AUTO));
  1647. }
  1648. } break;
  1649. case STRUCTURED_TEXT_CUSTOM:
  1650. case STRUCTURED_TEXT_DEFAULT:
  1651. default: {
  1652. ret.push_back(Vector3i(0, p_text.length(), TextServer::DIRECTION_INHERITED));
  1653. }
  1654. }
  1655. return ret;
  1656. }
  1657. TypedArray<Dictionary> TextServer::_shaped_text_get_glyphs_wrapper(const RID &p_shaped) const {
  1658. TypedArray<Dictionary> ret;
  1659. const Glyph *glyphs = shaped_text_get_glyphs(p_shaped);
  1660. int gl_size = shaped_text_get_glyph_count(p_shaped);
  1661. for (int i = 0; i < gl_size; i++) {
  1662. Dictionary glyph;
  1663. glyph["start"] = glyphs[i].start;
  1664. glyph["end"] = glyphs[i].end;
  1665. glyph["repeat"] = glyphs[i].repeat;
  1666. glyph["count"] = glyphs[i].count;
  1667. glyph["flags"] = glyphs[i].flags;
  1668. glyph["offset"] = Vector2(glyphs[i].x_off, glyphs[i].y_off);
  1669. glyph["advance"] = glyphs[i].advance;
  1670. glyph["font_rid"] = glyphs[i].font_rid;
  1671. glyph["font_size"] = glyphs[i].font_size;
  1672. glyph["index"] = glyphs[i].index;
  1673. ret.push_back(glyph);
  1674. }
  1675. return ret;
  1676. }
  1677. TypedArray<Dictionary> TextServer::_shaped_text_sort_logical_wrapper(const RID &p_shaped) {
  1678. Array ret;
  1679. const Glyph *glyphs = shaped_text_sort_logical(p_shaped);
  1680. int gl_size = shaped_text_get_glyph_count(p_shaped);
  1681. for (int i = 0; i < gl_size; i++) {
  1682. Dictionary glyph;
  1683. glyph["start"] = glyphs[i].start;
  1684. glyph["end"] = glyphs[i].end;
  1685. glyph["repeat"] = glyphs[i].repeat;
  1686. glyph["count"] = glyphs[i].count;
  1687. glyph["flags"] = glyphs[i].flags;
  1688. glyph["offset"] = Vector2(glyphs[i].x_off, glyphs[i].y_off);
  1689. glyph["advance"] = glyphs[i].advance;
  1690. glyph["font_rid"] = glyphs[i].font_rid;
  1691. glyph["font_size"] = glyphs[i].font_size;
  1692. glyph["index"] = glyphs[i].index;
  1693. ret.push_back(glyph);
  1694. }
  1695. return ret;
  1696. }
  1697. TypedArray<Dictionary> TextServer::_shaped_text_get_ellipsis_glyphs_wrapper(const RID &p_shaped) const {
  1698. TypedArray<Dictionary> ret;
  1699. const Glyph *glyphs = shaped_text_get_ellipsis_glyphs(p_shaped);
  1700. int gl_size = shaped_text_get_ellipsis_glyph_count(p_shaped);
  1701. for (int i = 0; i < gl_size; i++) {
  1702. Dictionary glyph;
  1703. glyph["start"] = glyphs[i].start;
  1704. glyph["end"] = glyphs[i].end;
  1705. glyph["repeat"] = glyphs[i].repeat;
  1706. glyph["count"] = glyphs[i].count;
  1707. glyph["flags"] = glyphs[i].flags;
  1708. glyph["offset"] = Vector2(glyphs[i].x_off, glyphs[i].y_off);
  1709. glyph["advance"] = glyphs[i].advance;
  1710. glyph["font_rid"] = glyphs[i].font_rid;
  1711. glyph["font_size"] = glyphs[i].font_size;
  1712. glyph["index"] = glyphs[i].index;
  1713. ret.push_back(glyph);
  1714. }
  1715. return ret;
  1716. }
  1717. bool TextServer::is_valid_identifier(const String &p_string) const {
  1718. const char32_t *str = p_string.ptr();
  1719. int len = p_string.length();
  1720. if (len == 0) {
  1721. return false; // Empty string.
  1722. }
  1723. if (!is_unicode_identifier_start(str[0])) {
  1724. return false;
  1725. }
  1726. for (int i = 1; i < len; i++) {
  1727. if (!is_unicode_identifier_continue(str[i])) {
  1728. return false;
  1729. }
  1730. }
  1731. return true;
  1732. }
  1733. TextServer::TextServer() {
  1734. _init_diacritics_map();
  1735. }
  1736. TextServer::~TextServer() {
  1737. }