text_server.cpp 82 KB

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