text_server.cpp 100 KB

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