text_server_gdnative.cpp 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873
  1. /*************************************************************************/
  2. /* text_server_gdnative.cpp */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */
  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 "text_server_gdnative.h"
  31. bool TextServerGDNative::has_feature(Feature p_feature) {
  32. ERR_FAIL_COND_V(interface == nullptr, false);
  33. return interface->has_feature(data, (godot_int)p_feature);
  34. }
  35. String TextServerGDNative::get_name() const {
  36. ERR_FAIL_COND_V(interface == nullptr, String());
  37. godot_string result = interface->get_name(data);
  38. String name = *(String *)&result;
  39. godot_string_destroy(&result);
  40. return name;
  41. }
  42. void TextServerGDNative::free(RID p_rid) {
  43. ERR_FAIL_COND(interface == nullptr);
  44. interface->free(data, (godot_rid *)&p_rid);
  45. }
  46. bool TextServerGDNative::has(RID p_rid) {
  47. ERR_FAIL_COND_V(interface == nullptr, false);
  48. return interface->has(data, (godot_rid *)&p_rid);
  49. }
  50. bool TextServerGDNative::load_support_data(const String &p_filename) {
  51. ERR_FAIL_COND_V(interface == nullptr, false);
  52. return interface->load_support_data(data, (godot_string *)&p_filename);
  53. }
  54. #ifdef TOOLS_ENABLED
  55. String TextServerGDNative::get_support_data_filename() {
  56. ERR_FAIL_COND_V(interface == nullptr, String());
  57. godot_string result = interface->get_support_data_filename(data);
  58. String name = *(String *)&result;
  59. godot_string_destroy(&result);
  60. return name;
  61. }
  62. String TextServerGDNative::get_support_data_info() {
  63. ERR_FAIL_COND_V(interface == nullptr, String());
  64. godot_string result = interface->get_support_data_info(data);
  65. String info = *(String *)&result;
  66. godot_string_destroy(&result);
  67. return info;
  68. }
  69. bool TextServerGDNative::save_support_data(const String &p_filename) {
  70. ERR_FAIL_COND_V(interface == nullptr, false);
  71. return interface->save_support_data(data, (godot_string *)&p_filename);
  72. }
  73. #endif
  74. bool TextServerGDNative::is_locale_right_to_left(const String &p_locale) {
  75. ERR_FAIL_COND_V(interface == nullptr, false);
  76. return interface->is_locale_right_to_left(data, (godot_string *)&p_locale);
  77. }
  78. /*************************************************************************/
  79. /* Font interface */
  80. /*************************************************************************/
  81. RID TextServerGDNative::create_font_system(const String &p_name, int p_base_size) {
  82. ERR_FAIL_COND_V(interface == nullptr, RID());
  83. godot_rid result = interface->create_font_system(data, (const godot_string *)&p_name, p_base_size);
  84. RID rid = *(RID *)&result;
  85. return rid;
  86. }
  87. RID TextServerGDNative::create_font_resource(const String &p_filename, int p_base_size) {
  88. ERR_FAIL_COND_V(interface == nullptr, RID());
  89. godot_rid result = interface->create_font_resource(data, (const godot_string *)&p_filename, p_base_size);
  90. RID rid = *(RID *)&result;
  91. return rid;
  92. }
  93. RID TextServerGDNative::create_font_memory(const uint8_t *p_data, size_t p_size, const String &p_type, int p_base_size) {
  94. ERR_FAIL_COND_V(interface == nullptr, RID());
  95. godot_rid result = interface->create_font_memory(data, p_data, p_size, (godot_string *)&p_type, p_base_size);
  96. RID rid = *(RID *)&result;
  97. return rid;
  98. }
  99. float TextServerGDNative::font_get_height(RID p_font, int p_size) const {
  100. ERR_FAIL_COND_V(interface == nullptr, 0.f);
  101. return interface->font_get_height(data, (godot_rid *)&p_font, p_size);
  102. }
  103. float TextServerGDNative::font_get_ascent(RID p_font, int p_size) const {
  104. ERR_FAIL_COND_V(interface == nullptr, 0.f);
  105. return interface->font_get_ascent(data, (godot_rid *)&p_font, p_size);
  106. }
  107. float TextServerGDNative::font_get_descent(RID p_font, int p_size) const {
  108. ERR_FAIL_COND_V(interface == nullptr, 0.f);
  109. return interface->font_get_descent(data, (godot_rid *)&p_font, p_size);
  110. }
  111. float TextServerGDNative::font_get_underline_position(RID p_font, int p_size) const {
  112. ERR_FAIL_COND_V(interface == nullptr, 0.f);
  113. return interface->font_get_underline_position(data, (godot_rid *)&p_font, p_size);
  114. }
  115. float TextServerGDNative::font_get_underline_thickness(RID p_font, int p_size) const {
  116. ERR_FAIL_COND_V(interface == nullptr, 0.f);
  117. return interface->font_get_underline_thickness(data, (godot_rid *)&p_font, p_size);
  118. }
  119. int TextServerGDNative::font_get_spacing_space(RID p_font) const {
  120. ERR_FAIL_COND_V(interface == nullptr, 0);
  121. return interface->font_get_spacing_space(data, (godot_rid *)&p_font);
  122. }
  123. void TextServerGDNative::font_set_spacing_space(RID p_font, int p_value) {
  124. ERR_FAIL_COND(interface == nullptr);
  125. interface->font_set_spacing_space(data, (godot_rid *)&p_font, p_value);
  126. }
  127. int TextServerGDNative::font_get_spacing_glyph(RID p_font) const {
  128. ERR_FAIL_COND_V(interface == nullptr, 0);
  129. return interface->font_get_spacing_glyph(data, (godot_rid *)&p_font);
  130. }
  131. void TextServerGDNative::font_set_spacing_glyph(RID p_font, int p_value) {
  132. ERR_FAIL_COND(interface == nullptr);
  133. interface->font_set_spacing_glyph(data, (godot_rid *)&p_font, p_value);
  134. }
  135. void TextServerGDNative::font_set_antialiased(RID p_font, bool p_antialiased) {
  136. ERR_FAIL_COND(interface == nullptr);
  137. interface->font_set_antialiased(data, (godot_rid *)&p_font, p_antialiased);
  138. }
  139. bool TextServerGDNative::font_get_antialiased(RID p_font) const {
  140. ERR_FAIL_COND_V(interface == nullptr, false);
  141. return interface->font_get_antialiased(data, (godot_rid *)&p_font);
  142. }
  143. Dictionary TextServerGDNative::font_get_variation_list(RID p_font) const {
  144. ERR_FAIL_COND_V(interface == nullptr, Dictionary());
  145. godot_dictionary result = interface->font_get_variation_list(data, (godot_rid *)&p_font);
  146. Dictionary info = *(Dictionary *)&result;
  147. godot_dictionary_destroy(&result);
  148. return info;
  149. }
  150. void TextServerGDNative::font_set_variation(RID p_font, const String &p_name, double p_value) {
  151. ERR_FAIL_COND(interface == nullptr);
  152. interface->font_set_variation(data, (godot_rid *)&p_font, (godot_string *)&p_name, p_value);
  153. }
  154. double TextServerGDNative::font_get_variation(RID p_font, const String &p_name) const {
  155. return interface->font_get_variation(data, (godot_rid *)&p_font, (godot_string *)&p_name);
  156. }
  157. void TextServerGDNative::font_set_hinting(RID p_font, TextServer::Hinting p_hinting) {
  158. ERR_FAIL_COND(interface == nullptr);
  159. interface->font_set_hinting(data, (godot_rid *)&p_font, (godot_int)p_hinting);
  160. }
  161. TextServer::Hinting TextServerGDNative::font_get_hinting(RID p_font) const {
  162. ERR_FAIL_COND_V(interface == nullptr, TextServer::HINTING_NONE);
  163. return (TextServer::Hinting)interface->font_get_hinting(data, (godot_rid *)&p_font);
  164. }
  165. Dictionary TextServerGDNative::font_get_feature_list(RID p_font) const {
  166. ERR_FAIL_COND_V(interface == nullptr, Dictionary());
  167. godot_dictionary result = interface->font_get_feature_list(data, (godot_rid *)&p_font);
  168. Dictionary info = *(Dictionary *)&result;
  169. godot_dictionary_destroy(&result);
  170. return info;
  171. }
  172. void TextServerGDNative::font_set_distance_field_hint(RID p_font, bool p_distance_field) {
  173. ERR_FAIL_COND(interface == nullptr);
  174. interface->font_set_distance_field_hint(data, (godot_rid *)&p_font, p_distance_field);
  175. }
  176. bool TextServerGDNative::font_get_distance_field_hint(RID p_font) const {
  177. ERR_FAIL_COND_V(interface == nullptr, false);
  178. return interface->font_get_distance_field_hint(data, (godot_rid *)&p_font);
  179. }
  180. void TextServerGDNative::font_set_force_autohinter(RID p_font, bool p_enabeld) {
  181. ERR_FAIL_COND(interface == nullptr);
  182. interface->font_set_force_autohinter(data, (godot_rid *)&p_font, p_enabeld);
  183. }
  184. bool TextServerGDNative::font_get_force_autohinter(RID p_font) const {
  185. ERR_FAIL_COND_V(interface == nullptr, false);
  186. return interface->font_get_force_autohinter(data, (godot_rid *)&p_font);
  187. }
  188. bool TextServerGDNative::font_has_char(RID p_font, char32_t p_char) const {
  189. ERR_FAIL_COND_V(interface == nullptr, false);
  190. return interface->font_has_char(data, (godot_rid *)&p_font, p_char);
  191. }
  192. String TextServerGDNative::font_get_supported_chars(RID p_font) const {
  193. ERR_FAIL_COND_V(interface == nullptr, String());
  194. godot_string result = interface->font_get_supported_chars(data, (godot_rid *)&p_font);
  195. String ret = *(String *)&result;
  196. godot_string_destroy(&result);
  197. return ret;
  198. }
  199. bool TextServerGDNative::font_has_outline(RID p_font) const {
  200. ERR_FAIL_COND_V(interface == nullptr, false);
  201. return interface->font_has_outline(data, (godot_rid *)&p_font);
  202. }
  203. float TextServerGDNative::font_get_base_size(RID p_font) const {
  204. ERR_FAIL_COND_V(interface == nullptr, 0.f);
  205. return interface->font_get_base_size(data, (godot_rid *)&p_font);
  206. }
  207. bool TextServerGDNative::font_is_language_supported(RID p_font, const String &p_language) const {
  208. ERR_FAIL_COND_V(interface == nullptr, false);
  209. return interface->font_is_language_supported(data, (godot_rid *)&p_font, (godot_string *)&p_language);
  210. }
  211. void TextServerGDNative::font_set_language_support_override(RID p_font, const String &p_language, bool p_supported) {
  212. ERR_FAIL_COND(interface == nullptr);
  213. return interface->font_set_language_support_override(data, (godot_rid *)&p_font, (godot_string *)&p_language, p_supported);
  214. }
  215. bool TextServerGDNative::font_get_language_support_override(RID p_font, const String &p_language) {
  216. ERR_FAIL_COND_V(interface == nullptr, false);
  217. return interface->font_get_language_support_override(data, (godot_rid *)&p_font, (godot_string *)&p_language);
  218. }
  219. void TextServerGDNative::font_remove_language_support_override(RID p_font, const String &p_language) {
  220. ERR_FAIL_COND(interface == nullptr);
  221. interface->font_remove_language_support_override(data, (godot_rid *)&p_font, (godot_string *)&p_language);
  222. }
  223. Vector<String> TextServerGDNative::font_get_language_support_overrides(RID p_font) {
  224. ERR_FAIL_COND_V(interface == nullptr, Vector<String>());
  225. godot_packed_string_array result = interface->font_get_language_support_overrides(data, (godot_rid *)&p_font);
  226. Vector<String> ret = *(Vector<String> *)&result;
  227. godot_packed_string_array_destroy(&result);
  228. return ret;
  229. }
  230. bool TextServerGDNative::font_is_script_supported(RID p_font, const String &p_script) const {
  231. ERR_FAIL_COND_V(interface == nullptr, false);
  232. return interface->font_is_script_supported(data, (godot_rid *)&p_font, (godot_string *)&p_script);
  233. }
  234. void TextServerGDNative::font_set_script_support_override(RID p_font, const String &p_script, bool p_supported) {
  235. ERR_FAIL_COND(interface == nullptr);
  236. return interface->font_set_script_support_override(data, (godot_rid *)&p_font, (godot_string *)&p_script, p_supported);
  237. }
  238. bool TextServerGDNative::font_get_script_support_override(RID p_font, const String &p_script) {
  239. ERR_FAIL_COND_V(interface == nullptr, false);
  240. return interface->font_get_script_support_override(data, (godot_rid *)&p_font, (godot_string *)&p_script);
  241. }
  242. void TextServerGDNative::font_remove_script_support_override(RID p_font, const String &p_script) {
  243. ERR_FAIL_COND(interface == nullptr);
  244. interface->font_remove_script_support_override(data, (godot_rid *)&p_font, (godot_string *)&p_script);
  245. }
  246. Vector<String> TextServerGDNative::font_get_script_support_overrides(RID p_font) {
  247. ERR_FAIL_COND_V(interface == nullptr, Vector<String>());
  248. godot_packed_string_array result = interface->font_get_script_support_overrides(data, (godot_rid *)&p_font);
  249. Vector<String> ret = *(Vector<String> *)&result;
  250. godot_packed_string_array_destroy(&result);
  251. return ret;
  252. }
  253. uint32_t TextServerGDNative::font_get_glyph_index(RID p_font, char32_t p_char, char32_t p_variation_selector) const {
  254. ERR_FAIL_COND_V(interface == nullptr, 0);
  255. return interface->font_get_glyph_index(data, (godot_rid *)&p_font, p_char, p_variation_selector);
  256. }
  257. Vector2 TextServerGDNative::font_get_glyph_advance(RID p_font, uint32_t p_index, int p_size) const {
  258. ERR_FAIL_COND_V(interface == nullptr, Vector2());
  259. godot_vector2 result = interface->font_get_glyph_advance(data, (godot_rid *)&p_font, p_index, p_size);
  260. Vector2 advance = *(Vector2 *)&result;
  261. return advance;
  262. }
  263. Vector2 TextServerGDNative::font_get_glyph_kerning(RID p_font, uint32_t p_index_a, uint32_t p_index_b, int p_size) const {
  264. ERR_FAIL_COND_V(interface == nullptr, Vector2());
  265. godot_vector2 result = interface->font_get_glyph_kerning(data, (godot_rid *)&p_font, p_index_a, p_index_b, p_size);
  266. Vector2 kerning = *(Vector2 *)&result;
  267. return kerning;
  268. }
  269. Vector2 TextServerGDNative::font_draw_glyph(RID p_font, RID p_canvas, int p_size, const Vector2 &p_pos, uint32_t p_index, const Color &p_color) const {
  270. ERR_FAIL_COND_V(interface == nullptr, Vector2());
  271. godot_vector2 result = interface->font_draw_glyph(data, (godot_rid *)&p_font, (godot_rid *)&p_canvas, p_size, (const godot_vector2 *)&p_pos, p_index, (const godot_color *)&p_color);
  272. Vector2 advance = *(Vector2 *)&result;
  273. return advance;
  274. }
  275. Vector2 TextServerGDNative::font_draw_glyph_outline(RID p_font, RID p_canvas, int p_size, int p_outline_size, const Vector2 &p_pos, uint32_t p_index, const Color &p_color) const {
  276. ERR_FAIL_COND_V(interface == nullptr, Vector2());
  277. godot_vector2 result = interface->font_draw_glyph_outline(data, (godot_rid *)&p_font, (godot_rid *)&p_canvas, p_size, p_outline_size, (const godot_vector2 *)&p_pos, p_index, (const godot_color *)&p_color);
  278. Vector2 advance = *(Vector2 *)&result;
  279. return advance;
  280. }
  281. float TextServerGDNative::font_get_oversampling() const {
  282. ERR_FAIL_COND_V(interface == nullptr, 1.f);
  283. return interface->font_get_oversampling(data);
  284. }
  285. void TextServerGDNative::font_set_oversampling(float p_oversampling) {
  286. ERR_FAIL_COND(interface == nullptr);
  287. return interface->font_set_oversampling(data, p_oversampling);
  288. }
  289. Vector<String> TextServerGDNative::get_system_fonts() const {
  290. ERR_FAIL_COND_V(interface == nullptr, Vector<String>());
  291. godot_packed_string_array result = interface->get_system_fonts(data);
  292. Vector<String> fonts = *(Vector<String> *)&result;
  293. godot_packed_string_array_destroy(&result);
  294. return fonts;
  295. }
  296. /*************************************************************************/
  297. /* Shaped text buffer interface */
  298. /*************************************************************************/
  299. RID TextServerGDNative::create_shaped_text(TextServer::Direction p_direction, TextServer::Orientation p_orientation) {
  300. ERR_FAIL_COND_V(interface == nullptr, RID());
  301. godot_rid result = interface->create_shaped_text(data, (godot_int)p_direction, (godot_int)p_orientation);
  302. RID rid = *(RID *)&result;
  303. return rid;
  304. }
  305. void TextServerGDNative::shaped_text_clear(RID p_shaped) {
  306. ERR_FAIL_COND(interface == nullptr);
  307. interface->shaped_text_clear(data, (godot_rid *)&p_shaped);
  308. }
  309. void TextServerGDNative::shaped_text_set_direction(RID p_shaped, TextServer::Direction p_direction) {
  310. ERR_FAIL_COND(interface == nullptr);
  311. interface->shaped_text_set_direction(data, (godot_rid *)&p_shaped, (godot_int)p_direction);
  312. }
  313. TextServer::Direction TextServerGDNative::shaped_text_get_direction(RID p_shaped) const {
  314. ERR_FAIL_COND_V(interface == nullptr, TextServer::DIRECTION_LTR);
  315. return (TextServer::Direction)interface->shaped_text_get_direction(data, (godot_rid *)&p_shaped);
  316. }
  317. void TextServerGDNative::shaped_text_set_orientation(RID p_shaped, TextServer::Orientation p_orientation) {
  318. ERR_FAIL_COND(interface == nullptr);
  319. interface->shaped_text_set_orientation(data, (godot_rid *)&p_shaped, (godot_int)p_orientation);
  320. }
  321. TextServer::Orientation TextServerGDNative::shaped_text_get_orientation(RID p_shaped) const {
  322. ERR_FAIL_COND_V(interface == nullptr, TextServer::ORIENTATION_HORIZONTAL);
  323. return (TextServer::Orientation)interface->shaped_text_get_orientation(data, (godot_rid *)&p_shaped);
  324. }
  325. void TextServerGDNative::shaped_text_set_bidi_override(RID p_shaped, const Vector<Vector2i> &p_override) {
  326. ERR_FAIL_COND(interface == nullptr);
  327. interface->shaped_text_set_bidi_override(data, (godot_rid *)&p_shaped, (const godot_packed_vector2i_array *)&p_override);
  328. }
  329. void TextServerGDNative::shaped_text_set_preserve_invalid(RID p_shaped, bool p_enabled) {
  330. ERR_FAIL_COND(interface == nullptr);
  331. interface->shaped_text_set_preserve_invalid(data, (godot_rid *)&p_shaped, p_enabled);
  332. }
  333. bool TextServerGDNative::shaped_text_get_preserve_invalid(RID p_shaped) const {
  334. ERR_FAIL_COND_V(interface == nullptr, false);
  335. return (TextServer::Orientation)interface->shaped_text_get_preserve_invalid(data, (godot_rid *)&p_shaped);
  336. }
  337. void TextServerGDNative::shaped_text_set_preserve_control(RID p_shaped, bool p_enabled) {
  338. ERR_FAIL_COND(interface == nullptr);
  339. interface->shaped_text_set_preserve_control(data, (godot_rid *)&p_shaped, p_enabled);
  340. }
  341. bool TextServerGDNative::shaped_text_get_preserve_control(RID p_shaped) const {
  342. ERR_FAIL_COND_V(interface == nullptr, false);
  343. return (TextServer::Orientation)interface->shaped_text_get_preserve_control(data, (godot_rid *)&p_shaped);
  344. }
  345. bool TextServerGDNative::shaped_text_add_string(RID p_shaped, const String &p_text, const Vector<RID> &p_fonts, int p_size, const Dictionary &p_opentype_features, const String &p_language) {
  346. ERR_FAIL_COND_V(interface == nullptr, false);
  347. return interface->shaped_text_add_string(data, (godot_rid *)&p_shaped, (const godot_string *)&p_text, (const godot_rid **)p_fonts.ptr(), p_size, (const godot_dictionary *)&p_opentype_features, (const godot_string *)&p_language);
  348. }
  349. bool TextServerGDNative::shaped_text_add_object(RID p_shaped, Variant p_key, const Size2 &p_size, VAlign p_inline_align, int p_length) {
  350. ERR_FAIL_COND_V(interface == nullptr, false);
  351. return interface->shaped_text_add_object(data, (godot_rid *)&p_shaped, (const godot_variant *)&p_key, (const godot_vector2 *)&p_size, (godot_int)p_inline_align, p_length);
  352. }
  353. bool TextServerGDNative::shaped_text_resize_object(RID p_shaped, Variant p_key, const Size2 &p_size, VAlign p_inline_align) {
  354. ERR_FAIL_COND_V(interface == nullptr, false);
  355. return interface->shaped_text_resize_object(data, (godot_rid *)&p_shaped, (const godot_variant *)&p_key, (const godot_vector2 *)&p_size, (godot_int)p_inline_align);
  356. }
  357. RID TextServerGDNative::shaped_text_substr(RID p_shaped, int p_start, int p_length) const {
  358. ERR_FAIL_COND_V(interface == nullptr, RID());
  359. godot_rid result = interface->shaped_text_substr(data, (godot_rid *)&p_shaped, (godot_int)p_start, (godot_int)p_length);
  360. RID rid = *(RID *)&result;
  361. return rid;
  362. }
  363. RID TextServerGDNative::shaped_text_get_parent(RID p_shaped) const {
  364. ERR_FAIL_COND_V(interface == nullptr, RID());
  365. godot_rid result = interface->shaped_text_get_parent(data, (godot_rid *)&p_shaped);
  366. RID rid = *(RID *)&result;
  367. return rid;
  368. }
  369. float TextServerGDNative::shaped_text_fit_to_width(RID p_shaped, float p_width, uint8_t p_jst_flags) {
  370. ERR_FAIL_COND_V(interface == nullptr, 0.f);
  371. return interface->shaped_text_fit_to_width(data, (godot_rid *)&p_shaped, p_width, p_jst_flags);
  372. }
  373. float TextServerGDNative::shaped_text_tab_align(RID p_shaped, const Vector<float> &p_tab_stops) {
  374. ERR_FAIL_COND_V(interface == nullptr, 0.f);
  375. return interface->shaped_text_tab_align(data, (godot_rid *)&p_shaped, (godot_packed_float32_array *)&p_tab_stops);
  376. }
  377. bool TextServerGDNative::shaped_text_shape(RID p_shaped) {
  378. ERR_FAIL_COND_V(interface == nullptr, false);
  379. return interface->shaped_text_shape(data, (godot_rid *)&p_shaped);
  380. }
  381. bool TextServerGDNative::shaped_text_update_breaks(RID p_shaped) {
  382. ERR_FAIL_COND_V(interface == nullptr, false);
  383. return interface->shaped_text_update_breaks(data, (godot_rid *)&p_shaped);
  384. }
  385. bool TextServerGDNative::shaped_text_update_justification_ops(RID p_shaped) {
  386. ERR_FAIL_COND_V(interface == nullptr, false);
  387. return interface->shaped_text_update_justification_ops(data, (godot_rid *)&p_shaped);
  388. }
  389. bool TextServerGDNative::shaped_text_is_ready(RID p_shaped) const {
  390. ERR_FAIL_COND_V(interface == nullptr, false);
  391. return interface->shaped_text_is_ready(data, (godot_rid *)&p_shaped);
  392. }
  393. Vector<TextServer::Glyph> TextServerGDNative::shaped_text_get_glyphs(RID p_shaped) const {
  394. ERR_FAIL_COND_V(interface == nullptr, Vector<TextServer::Glyph>());
  395. godot_packed_glyph_array result = interface->shaped_text_get_glyphs(data, (godot_rid *)&p_shaped);
  396. Vector<TextServer::Glyph> glyphs = *(Vector<TextServer::Glyph> *)&result;
  397. godot_packed_glyph_array_destroy(&result);
  398. return glyphs;
  399. }
  400. Vector2i TextServerGDNative::shaped_text_get_range(RID p_shaped) const {
  401. ERR_FAIL_COND_V(interface == nullptr, Vector2i());
  402. godot_vector2i result = interface->shaped_text_get_range(data, (godot_rid *)&p_shaped);
  403. Vector2i range = *(Vector2i *)&result;
  404. return range;
  405. }
  406. Vector<TextServer::Glyph> TextServerGDNative::shaped_text_sort_logical(RID p_shaped) {
  407. ERR_FAIL_COND_V(interface == nullptr, Vector<TextServer::Glyph>());
  408. godot_packed_glyph_array result = interface->shaped_text_sort_logical(data, (godot_rid *)&p_shaped);
  409. Vector<TextServer::Glyph> glyphs = *(Vector<TextServer::Glyph> *)&result;
  410. godot_packed_glyph_array_destroy(&result);
  411. return glyphs;
  412. }
  413. Vector<Vector2i> TextServerGDNative::shaped_text_get_line_breaks_adv(RID p_shaped, const Vector<float> &p_width, int p_start, bool p_once, uint8_t p_break_flags) const {
  414. ERR_FAIL_COND_V(interface == nullptr, Vector<Vector2i>());
  415. if (interface->shaped_text_get_line_breaks_adv != nullptr) {
  416. godot_packed_vector2i_array result = interface->shaped_text_get_line_breaks_adv(data, (godot_rid *)&p_shaped, (godot_packed_float32_array *)&p_width, p_start, p_once, p_break_flags);
  417. Vector<Vector2i> breaks = *(Vector<Vector2i> *)&result;
  418. godot_packed_vector2i_array_destroy(&result);
  419. return breaks;
  420. } else {
  421. return TextServer::shaped_text_get_line_breaks_adv(p_shaped, p_width, p_break_flags);
  422. }
  423. }
  424. Vector<Vector2i> TextServerGDNative::shaped_text_get_line_breaks(RID p_shaped, float p_width, int p_start, uint8_t p_break_flags) const {
  425. ERR_FAIL_COND_V(interface == nullptr, Vector<Vector2i>());
  426. if (interface->shaped_text_get_line_breaks != nullptr) {
  427. godot_packed_vector2i_array result = interface->shaped_text_get_line_breaks(data, (godot_rid *)&p_shaped, p_width, p_start, p_break_flags);
  428. Vector<Vector2i> breaks = *(Vector<Vector2i> *)&result;
  429. godot_packed_vector2i_array_destroy(&result);
  430. return breaks;
  431. } else {
  432. return TextServer::shaped_text_get_line_breaks(p_shaped, p_width, p_break_flags);
  433. }
  434. }
  435. Vector<Vector2i> TextServerGDNative::shaped_text_get_word_breaks(RID p_shaped) const {
  436. ERR_FAIL_COND_V(interface == nullptr, Vector<Vector2i>());
  437. if (interface->shaped_text_get_word_breaks != nullptr) {
  438. godot_packed_vector2i_array result = interface->shaped_text_get_word_breaks(data, (godot_rid *)&p_shaped);
  439. Vector<Vector2i> breaks = *(Vector<Vector2i> *)&result;
  440. godot_packed_vector2i_array_destroy(&result);
  441. return breaks;
  442. } else {
  443. return TextServer::shaped_text_get_word_breaks(p_shaped);
  444. }
  445. }
  446. Array TextServerGDNative::shaped_text_get_objects(RID p_shaped) const {
  447. ERR_FAIL_COND_V(interface == nullptr, Array());
  448. godot_array result = interface->shaped_text_get_objects(data, (godot_rid *)&p_shaped);
  449. Array rect = *(Array *)&result;
  450. return rect;
  451. }
  452. Rect2 TextServerGDNative::shaped_text_get_object_rect(RID p_shaped, Variant p_key) const {
  453. ERR_FAIL_COND_V(interface == nullptr, Rect2());
  454. godot_rect2 result = interface->shaped_text_get_object_rect(data, (godot_rid *)&p_shaped, (const godot_variant *)&p_key);
  455. Rect2 rect = *(Rect2 *)&result;
  456. return rect;
  457. }
  458. Size2 TextServerGDNative::shaped_text_get_size(RID p_shaped) const {
  459. ERR_FAIL_COND_V(interface == nullptr, Size2());
  460. godot_vector2 result = interface->shaped_text_get_size(data, (godot_rid *)&p_shaped);
  461. Size2 size = *(Size2 *)&result;
  462. return size;
  463. }
  464. float TextServerGDNative::shaped_text_get_ascent(RID p_shaped) const {
  465. ERR_FAIL_COND_V(interface == nullptr, 0.f);
  466. return interface->shaped_text_get_ascent(data, (godot_rid *)&p_shaped);
  467. }
  468. float TextServerGDNative::shaped_text_get_descent(RID p_shaped) const {
  469. ERR_FAIL_COND_V(interface == nullptr, 0.f);
  470. return interface->shaped_text_get_descent(data, (godot_rid *)&p_shaped);
  471. }
  472. float TextServerGDNative::shaped_text_get_width(RID p_shaped) const {
  473. ERR_FAIL_COND_V(interface == nullptr, 0.f);
  474. return interface->shaped_text_get_width(data, (godot_rid *)&p_shaped);
  475. }
  476. float TextServerGDNative::shaped_text_get_underline_position(RID p_shaped) const {
  477. ERR_FAIL_COND_V(interface == nullptr, 0.f);
  478. return interface->shaped_text_get_underline_position(data, (godot_rid *)&p_shaped);
  479. }
  480. float TextServerGDNative::shaped_text_get_underline_thickness(RID p_shaped) const {
  481. ERR_FAIL_COND_V(interface == nullptr, 0.f);
  482. return interface->shaped_text_get_underline_thickness(data, (godot_rid *)&p_shaped);
  483. }
  484. String TextServerGDNative::format_number(const String &p_string, const String &p_language) const {
  485. ERR_FAIL_COND_V(interface == nullptr, String());
  486. godot_string result = interface->format_number(data, (const godot_string *)&p_string, (const godot_string *)&p_language);
  487. if (interface->format_number == nullptr) {
  488. return p_string;
  489. }
  490. String ret = *(String *)&result;
  491. godot_string_destroy(&result);
  492. return ret;
  493. }
  494. String TextServerGDNative::parse_number(const String &p_string, const String &p_language) const {
  495. ERR_FAIL_COND_V(interface == nullptr, String());
  496. if (interface->parse_number == nullptr) {
  497. return p_string;
  498. }
  499. godot_string result = interface->parse_number(data, (const godot_string *)&p_string, (const godot_string *)&p_language);
  500. String ret = *(String *)&result;
  501. godot_string_destroy(&result);
  502. return ret;
  503. }
  504. String TextServerGDNative::percent_sign(const String &p_language) const {
  505. ERR_FAIL_COND_V(interface == nullptr, String());
  506. if (interface->percent_sign == nullptr) {
  507. return "%";
  508. }
  509. godot_string result = interface->percent_sign(data, (const godot_string *)&p_language);
  510. String ret = *(String *)&result;
  511. godot_string_destroy(&result);
  512. return ret;
  513. }
  514. TextServer *TextServerGDNative::create_func(Error &r_error, void *p_user_data) {
  515. const godot_text_interface_gdnative *interface = (const godot_text_interface_gdnative *)p_user_data;
  516. r_error = OK;
  517. TextServerGDNative *server = memnew(TextServerGDNative());
  518. server->interface = interface;
  519. server->data = interface->constructor((godot_object *)server);
  520. return server;
  521. }
  522. TextServerGDNative::TextServerGDNative() {
  523. data = nullptr;
  524. interface = nullptr;
  525. }
  526. TextServerGDNative::~TextServerGDNative() {
  527. if (interface != nullptr) {
  528. interface->destructor(data);
  529. data = nullptr;
  530. interface = nullptr;
  531. }
  532. }
  533. /*************************************************************************/
  534. /* GDNative functions */
  535. /*************************************************************************/
  536. #ifdef __cplusplus
  537. extern "C" {
  538. #endif
  539. static_assert(sizeof(godot_glyph) == sizeof(TextServer::Glyph), "Glyph size mismatch");
  540. static_assert(sizeof(godot_packed_glyph_array) == sizeof(Vector<TextServer::Glyph>), "Vector<Glyph> size mismatch");
  541. void GDAPI godot_text_register_interface(const godot_text_interface_gdnative *p_interface, const godot_string *p_name, uint32_t p_features) {
  542. ERR_FAIL_COND(p_interface->version.major != 1);
  543. String name = *(String *)p_name;
  544. TextServerManager::register_create_function(name + "(GDNative)", p_features, TextServerGDNative::create_func, (void *)p_interface);
  545. }
  546. // Glyph
  547. void GDAPI godot_glyph_new(godot_glyph *r_dest) {
  548. TextServer::Glyph *dest = (TextServer::Glyph *)r_dest;
  549. *dest = TextServer::Glyph();
  550. }
  551. godot_vector2i GDAPI godot_glyph_get_range(const godot_glyph *p_self) {
  552. godot_vector2i dest;
  553. Vector2i *d = (Vector2i *)&dest;
  554. const TextServer::Glyph *self = (const TextServer::Glyph *)p_self;
  555. d->x = self->start;
  556. d->y = self->end;
  557. return dest;
  558. }
  559. void GDAPI godot_glyph_set_range(godot_glyph *p_self, const godot_vector2i *p_range) {
  560. TextServer::Glyph *self = (TextServer::Glyph *)p_self;
  561. const Vector2i *range = (const Vector2i *)p_range;
  562. self->start = range->x;
  563. self->end = range->y;
  564. }
  565. godot_int GDAPI godot_glyph_get_count(const godot_glyph *p_self) {
  566. const TextServer::Glyph *self = (const TextServer::Glyph *)p_self;
  567. return self->count;
  568. }
  569. void GDAPI godot_glyph_set_count(godot_glyph *p_self, godot_int p_count) {
  570. TextServer::Glyph *self = (TextServer::Glyph *)p_self;
  571. self->count = p_count;
  572. }
  573. godot_int GDAPI godot_glyph_get_repeat(const godot_glyph *p_self) {
  574. const TextServer::Glyph *self = (const TextServer::Glyph *)p_self;
  575. return self->repeat;
  576. }
  577. void GDAPI godot_glyph_set_repeat(godot_glyph *p_self, godot_int p_repeat) {
  578. TextServer::Glyph *self = (TextServer::Glyph *)p_self;
  579. self->repeat = p_repeat;
  580. }
  581. godot_int GDAPI godot_glyph_get_flags(const godot_glyph *p_self) {
  582. const TextServer::Glyph *self = (const TextServer::Glyph *)p_self;
  583. return self->flags;
  584. }
  585. void GDAPI godot_glyph_set_flags(godot_glyph *p_self, godot_int p_flags) {
  586. TextServer::Glyph *self = (TextServer::Glyph *)p_self;
  587. self->flags = p_flags;
  588. }
  589. godot_vector2 GDAPI godot_glyph_get_offset(const godot_glyph *p_self) {
  590. godot_vector2 dest;
  591. Vector2 *d = (Vector2 *)&dest;
  592. const TextServer::Glyph *self = (const TextServer::Glyph *)p_self;
  593. d->x = self->x_off;
  594. d->y = self->y_off;
  595. return dest;
  596. }
  597. void GDAPI godot_glyph_set_offset(godot_glyph *p_self, const godot_vector2 *p_offset) {
  598. TextServer::Glyph *self = (TextServer::Glyph *)p_self;
  599. const Vector2 *offset = (const Vector2 *)p_offset;
  600. self->x_off = offset->x;
  601. self->y_off = offset->y;
  602. }
  603. godot_float GDAPI godot_glyph_get_advance(const godot_glyph *p_self) {
  604. const TextServer::Glyph *self = (const TextServer::Glyph *)p_self;
  605. return self->advance;
  606. }
  607. void GDAPI godot_glyph_set_advance(godot_glyph *p_self, godot_float p_advance) {
  608. TextServer::Glyph *self = (TextServer::Glyph *)p_self;
  609. self->advance = p_advance;
  610. }
  611. godot_rid GDAPI godot_glyph_get_font(const godot_glyph *p_self) {
  612. godot_rid dest;
  613. RID *d = (RID *)&dest;
  614. const TextServer::Glyph *self = (const TextServer::Glyph *)p_self;
  615. *d = self->font_rid;
  616. return dest;
  617. }
  618. void GDAPI godot_glyph_set_font(godot_glyph *p_self, godot_rid *p_font) {
  619. TextServer::Glyph *self = (TextServer::Glyph *)p_self;
  620. const RID *font = (const RID *)p_font;
  621. self->font_rid = *font;
  622. }
  623. godot_int GDAPI godot_glyph_get_font_size(const godot_glyph *p_self) {
  624. const TextServer::Glyph *self = (const TextServer::Glyph *)p_self;
  625. return self->font_size;
  626. }
  627. void GDAPI godot_glyph_set_font_size(godot_glyph *p_self, godot_int p_size) {
  628. TextServer::Glyph *self = (TextServer::Glyph *)p_self;
  629. self->font_size = p_size;
  630. }
  631. godot_int GDAPI godot_glyph_get_index(const godot_glyph *p_self) {
  632. const TextServer::Glyph *self = (const TextServer::Glyph *)p_self;
  633. return self->index;
  634. }
  635. void GDAPI godot_glyph_set_index(godot_glyph *p_self, godot_int p_index) {
  636. TextServer::Glyph *self = (TextServer::Glyph *)p_self;
  637. self->index = p_index;
  638. }
  639. // GlyphArray
  640. void GDAPI godot_packed_glyph_array_new(godot_packed_glyph_array *r_dest) {
  641. Vector<TextServer::Glyph> *dest = (Vector<TextServer::Glyph> *)r_dest;
  642. memnew_placement(dest, Vector<TextServer::Glyph>);
  643. }
  644. void GDAPI godot_packed_glyph_array_new_copy(godot_packed_glyph_array *r_dest, const godot_packed_glyph_array *p_src) {
  645. Vector<TextServer::Glyph> *dest = (Vector<TextServer::Glyph> *)r_dest;
  646. const Vector<TextServer::Glyph> *src = (const Vector<TextServer::Glyph> *)p_src;
  647. memnew_placement(dest, Vector<TextServer::Glyph>(*src));
  648. }
  649. const godot_glyph GDAPI *godot_packed_glyph_array_ptr(const godot_packed_glyph_array *p_self) {
  650. const Vector<TextServer::Glyph> *self = (const Vector<TextServer::Glyph> *)p_self;
  651. return (const godot_glyph *)self->ptr();
  652. }
  653. godot_glyph GDAPI *godot_packed_glyph_array_ptrw(godot_packed_glyph_array *p_self) {
  654. Vector<TextServer::Glyph> *self = (Vector<TextServer::Glyph> *)p_self;
  655. return (godot_glyph *)self->ptrw();
  656. }
  657. void GDAPI godot_packed_glyph_array_append(godot_packed_glyph_array *p_self, const godot_glyph *p_data) {
  658. Vector<TextServer::Glyph> *self = (Vector<TextServer::Glyph> *)p_self;
  659. TextServer::Glyph &s = *(TextServer::Glyph *)p_data;
  660. self->push_back(s);
  661. }
  662. void GDAPI godot_packed_glyph_array_append_array(godot_packed_glyph_array *p_self, const godot_packed_glyph_array *p_array) {
  663. Vector<TextServer::Glyph> *self = (Vector<TextServer::Glyph> *)p_self;
  664. Vector<TextServer::Glyph> *array = (Vector<TextServer::Glyph> *)p_array;
  665. self->append_array(*array);
  666. }
  667. godot_error GDAPI godot_packed_glyph_array_insert(godot_packed_glyph_array *p_self, const godot_int p_idx, const godot_glyph *p_data) {
  668. Vector<TextServer::Glyph> *self = (Vector<TextServer::Glyph> *)p_self;
  669. TextServer::Glyph &s = *(TextServer::Glyph *)p_data;
  670. return (godot_error)self->insert(p_idx, s);
  671. }
  672. godot_bool GDAPI godot_packed_glyph_array_has(godot_packed_glyph_array *p_self, const godot_glyph *p_value) {
  673. Vector<TextServer::Glyph> *self = (Vector<TextServer::Glyph> *)p_self;
  674. TextServer::Glyph &v = *(TextServer::Glyph *)p_value;
  675. return (godot_bool)self->has(v);
  676. }
  677. void GDAPI godot_packed_glyph_array_sort(godot_packed_glyph_array *p_self) {
  678. Vector<TextServer::Glyph> *self = (Vector<TextServer::Glyph> *)p_self;
  679. self->sort();
  680. }
  681. void GDAPI godot_packed_glyph_array_invert(godot_packed_glyph_array *p_self) {
  682. Vector<TextServer::Glyph> *self = (Vector<TextServer::Glyph> *)p_self;
  683. self->invert();
  684. }
  685. void GDAPI godot_packed_glyph_array_push_back(godot_packed_glyph_array *p_self, const godot_glyph *p_data) {
  686. Vector<TextServer::Glyph> *self = (Vector<TextServer::Glyph> *)p_self;
  687. TextServer::Glyph &s = *(TextServer::Glyph *)p_data;
  688. self->push_back(s);
  689. }
  690. void GDAPI godot_packed_glyph_array_remove(godot_packed_glyph_array *p_self, const godot_int p_idx) {
  691. Vector<TextServer::Glyph> *self = (Vector<TextServer::Glyph> *)p_self;
  692. self->remove(p_idx);
  693. }
  694. void GDAPI godot_packed_glyph_array_resize(godot_packed_glyph_array *p_self, const godot_int p_size) {
  695. Vector<TextServer::Glyph> *self = (Vector<TextServer::Glyph> *)p_self;
  696. self->resize(p_size);
  697. }
  698. void GDAPI godot_packed_glyph_array_set(godot_packed_glyph_array *p_self, const godot_int p_idx, const godot_glyph *p_data) {
  699. Vector<TextServer::Glyph> *self = (Vector<TextServer::Glyph> *)p_self;
  700. TextServer::Glyph &s = *(TextServer::Glyph *)p_data;
  701. self->set(p_idx, s);
  702. }
  703. godot_glyph GDAPI godot_packed_glyph_array_get(const godot_packed_glyph_array *p_self, const godot_int p_idx) {
  704. const Vector<TextServer::Glyph> *self = (const Vector<TextServer::Glyph> *)p_self;
  705. godot_glyph v;
  706. TextServer::Glyph *s = (TextServer::Glyph *)&v;
  707. *s = self->get(p_idx);
  708. return v;
  709. }
  710. godot_int GDAPI godot_packed_glyph_array_size(const godot_packed_glyph_array *p_self) {
  711. const Vector<TextServer::Glyph> *self = (const Vector<TextServer::Glyph> *)p_self;
  712. return self->size();
  713. }
  714. godot_bool GDAPI godot_packed_glyph_array_is_empty(const godot_packed_glyph_array *p_self) {
  715. const Vector<TextServer::Glyph> *self = (const Vector<TextServer::Glyph> *)p_self;
  716. return self->is_empty();
  717. }
  718. void GDAPI godot_packed_glyph_array_destroy(godot_packed_glyph_array *p_self) {
  719. ((Vector<TextServer::Glyph> *)p_self)->~Vector();
  720. }
  721. #ifdef __cplusplus
  722. }
  723. #endif