text_server_adv.h 39 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002
  1. /**************************************************************************/
  2. /* text_server_adv.h */
  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. #ifndef TEXT_SERVER_ADV_H
  31. #define TEXT_SERVER_ADV_H
  32. /*************************************************************************/
  33. /* ICU/HarfBuzz/Graphite backed Text Server implementation with BiDi, */
  34. /* shaping and advanced font features support. */
  35. /*************************************************************************/
  36. #include "script_iterator.h"
  37. #ifdef GDEXTENSION
  38. // Headers for building as GDExtension plug-in.
  39. #include <godot_cpp/godot.hpp>
  40. #include <godot_cpp/core/class_db.hpp>
  41. #include <godot_cpp/core/ext_wrappers.gen.inc>
  42. #include <godot_cpp/core/mutex_lock.hpp>
  43. #include <godot_cpp/variant/array.hpp>
  44. #include <godot_cpp/variant/dictionary.hpp>
  45. #include <godot_cpp/variant/packed_int32_array.hpp>
  46. #include <godot_cpp/variant/packed_string_array.hpp>
  47. #include <godot_cpp/variant/packed_vector2_array.hpp>
  48. #include <godot_cpp/variant/rect2.hpp>
  49. #include <godot_cpp/variant/rid.hpp>
  50. #include <godot_cpp/variant/string.hpp>
  51. #include <godot_cpp/variant/typed_array.hpp>
  52. #include <godot_cpp/variant/vector2.hpp>
  53. #include <godot_cpp/variant/vector2i.hpp>
  54. #include <godot_cpp/classes/text_server.hpp>
  55. #include <godot_cpp/classes/text_server_extension.hpp>
  56. #include <godot_cpp/classes/text_server_manager.hpp>
  57. #include <godot_cpp/classes/caret_info.hpp>
  58. #include <godot_cpp/classes/global_constants_binds.hpp>
  59. #include <godot_cpp/classes/glyph.hpp>
  60. #include <godot_cpp/classes/image.hpp>
  61. #include <godot_cpp/classes/image_texture.hpp>
  62. #include <godot_cpp/classes/ref.hpp>
  63. #include <godot_cpp/classes/worker_thread_pool.hpp>
  64. #include <godot_cpp/templates/hash_map.hpp>
  65. #include <godot_cpp/templates/hash_set.hpp>
  66. #include <godot_cpp/templates/rid_owner.hpp>
  67. #include <godot_cpp/templates/vector.hpp>
  68. using namespace godot;
  69. #elif defined(GODOT_MODULE)
  70. // Headers for building as built-in module.
  71. #include "core/extension/ext_wrappers.gen.inc"
  72. #include "core/object/worker_thread_pool.h"
  73. #include "core/templates/hash_map.h"
  74. #include "core/templates/rid_owner.h"
  75. #include "scene/resources/image_texture.h"
  76. #include "servers/text/text_server_extension.h"
  77. #include "modules/modules_enabled.gen.h" // For freetype, msdfgen, svg.
  78. #endif
  79. // Thirdparty headers.
  80. #include <unicode/ubidi.h>
  81. #include <unicode/ubrk.h>
  82. #include <unicode/uchar.h>
  83. #include <unicode/uclean.h>
  84. #include <unicode/udata.h>
  85. #include <unicode/uiter.h>
  86. #include <unicode/uloc.h>
  87. #include <unicode/unorm2.h>
  88. #include <unicode/uscript.h>
  89. #include <unicode/uspoof.h>
  90. #include <unicode/ustring.h>
  91. #include <unicode/utypes.h>
  92. #ifdef MODULE_FREETYPE_ENABLED
  93. #include <ft2build.h>
  94. #include FT_FREETYPE_H
  95. #include FT_TRUETYPE_TABLES_H
  96. #include FT_STROKER_H
  97. #include FT_ADVANCES_H
  98. #include FT_MULTIPLE_MASTERS_H
  99. #include FT_BBOX_H
  100. #include FT_MODULE_H
  101. #include FT_CONFIG_OPTIONS_H
  102. #if !defined(FT_CONFIG_OPTION_USE_BROTLI) && !defined(_MSC_VER)
  103. #warning FreeType is configured without Brotli support, built-in fonts will not be available.
  104. #endif
  105. #include <hb-ft.h>
  106. #include <hb-ot.h>
  107. #endif
  108. #include <hb-icu.h>
  109. #include <hb.h>
  110. /*************************************************************************/
  111. class TextServerAdvanced : public TextServerExtension {
  112. GDCLASS(TextServerAdvanced, TextServerExtension);
  113. _THREAD_SAFE_CLASS_
  114. struct NumSystemData {
  115. HashSet<StringName> lang;
  116. String digits;
  117. String percent_sign;
  118. String exp;
  119. };
  120. Vector<NumSystemData> num_systems;
  121. struct FeatureInfo {
  122. StringName name;
  123. Variant::Type vtype = Variant::INT;
  124. bool hidden = false;
  125. };
  126. HashMap<StringName, int32_t> feature_sets;
  127. HashMap<int32_t, FeatureInfo> feature_sets_inv;
  128. void _insert_num_systems_lang();
  129. void _insert_feature_sets();
  130. _FORCE_INLINE_ void _insert_feature(const StringName &p_name, int32_t p_tag, Variant::Type p_vtype = Variant::INT, bool p_hidden = false);
  131. // ICU support data.
  132. static bool icu_data_loaded;
  133. static PackedByteArray icu_data;
  134. mutable USet *allowed = nullptr;
  135. mutable USpoofChecker *sc_spoof = nullptr;
  136. mutable USpoofChecker *sc_conf = nullptr;
  137. // Font cache data.
  138. #ifdef MODULE_FREETYPE_ENABLED
  139. mutable FT_Library ft_library = nullptr;
  140. #endif
  141. const int rect_range = 1;
  142. struct FontTexturePosition {
  143. int32_t index = -1;
  144. int32_t x = 0;
  145. int32_t y = 0;
  146. FontTexturePosition() {}
  147. FontTexturePosition(int32_t p_id, int32_t p_x, int32_t p_y) :
  148. index(p_id), x(p_x), y(p_y) {}
  149. };
  150. struct Shelf {
  151. int32_t x = 0;
  152. int32_t y = 0;
  153. int32_t w = 0;
  154. int32_t h = 0;
  155. FontTexturePosition alloc_shelf(int32_t p_id, int32_t p_w, int32_t p_h) {
  156. if (p_w > w || p_h > h) {
  157. return FontTexturePosition(-1, 0, 0);
  158. }
  159. int32_t xx = x;
  160. x += p_w;
  161. w -= p_w;
  162. return FontTexturePosition(p_id, xx, y);
  163. }
  164. Shelf() {}
  165. Shelf(int32_t p_x, int32_t p_y, int32_t p_w, int32_t p_h) :
  166. x(p_x), y(p_y), w(p_w), h(p_h) {}
  167. };
  168. struct ShelfPackTexture {
  169. int32_t texture_w = 1024;
  170. int32_t texture_h = 1024;
  171. Ref<Image> image;
  172. Ref<ImageTexture> texture;
  173. bool dirty = true;
  174. List<Shelf> shelves;
  175. FontTexturePosition pack_rect(int32_t p_id, int32_t p_h, int32_t p_w) {
  176. int32_t y = 0;
  177. int32_t waste = 0;
  178. Shelf *best_shelf = nullptr;
  179. int32_t best_waste = std::numeric_limits<std::int32_t>::max();
  180. for (Shelf &E : shelves) {
  181. y += E.h;
  182. if (p_w > E.w) {
  183. continue;
  184. }
  185. if (p_h == E.h) {
  186. return E.alloc_shelf(p_id, p_w, p_h);
  187. }
  188. if (p_h > E.h) {
  189. continue;
  190. }
  191. if (p_h < E.h) {
  192. waste = (E.h - p_h) * p_w;
  193. if (waste < best_waste) {
  194. best_waste = waste;
  195. best_shelf = &E;
  196. }
  197. }
  198. }
  199. if (best_shelf) {
  200. return best_shelf->alloc_shelf(p_id, p_w, p_h);
  201. }
  202. if (p_h <= (texture_h - y) && p_w <= texture_w) {
  203. List<Shelf>::Element *E = shelves.push_back(Shelf(0, y, texture_w, p_h));
  204. return E->get().alloc_shelf(p_id, p_w, p_h);
  205. }
  206. return FontTexturePosition(-1, 0, 0);
  207. }
  208. ShelfPackTexture() {}
  209. ShelfPackTexture(int32_t p_w, int32_t p_h) :
  210. texture_w(p_w), texture_h(p_h) {}
  211. };
  212. struct FontGlyph {
  213. bool found = false;
  214. int texture_idx = -1;
  215. Rect2 rect;
  216. Rect2 uv_rect;
  217. Vector2 advance;
  218. };
  219. struct FontForSizeAdvanced {
  220. double ascent = 0.0;
  221. double descent = 0.0;
  222. double underline_position = 0.0;
  223. double underline_thickness = 0.0;
  224. double scale = 1.0;
  225. double oversampling = 1.0;
  226. Vector2i size;
  227. Vector<ShelfPackTexture> textures;
  228. HashMap<int64_t, int64_t> inv_glyph_map;
  229. HashMap<int32_t, FontGlyph> glyph_map;
  230. HashMap<Vector2i, Vector2> kerning_map;
  231. hb_font_t *hb_handle = nullptr;
  232. #ifdef MODULE_FREETYPE_ENABLED
  233. FT_Face face = nullptr;
  234. FT_StreamRec stream;
  235. #endif
  236. ~FontForSizeAdvanced() {
  237. if (hb_handle != nullptr) {
  238. hb_font_destroy(hb_handle);
  239. }
  240. #ifdef MODULE_FREETYPE_ENABLED
  241. if (face != nullptr) {
  242. FT_Done_Face(face);
  243. }
  244. #endif
  245. }
  246. };
  247. struct FontAdvancedLinkedVariation {
  248. RID base_font;
  249. int extra_spacing[4] = { 0, 0, 0, 0 };
  250. float baseline_offset = 0.0;
  251. };
  252. struct FontAdvanced {
  253. Mutex mutex;
  254. TextServer::FontAntialiasing antialiasing = TextServer::FONT_ANTIALIASING_GRAY;
  255. bool disable_embedded_bitmaps = true;
  256. bool mipmaps = false;
  257. bool msdf = false;
  258. int msdf_range = 14;
  259. FixedSizeScaleMode fixed_size_scale_mode = FIXED_SIZE_SCALE_DISABLE;
  260. int msdf_source_size = 48;
  261. int fixed_size = 0;
  262. bool allow_system_fallback = true;
  263. bool force_autohinter = false;
  264. TextServer::Hinting hinting = TextServer::HINTING_LIGHT;
  265. TextServer::SubpixelPositioning subpixel_positioning = TextServer::SUBPIXEL_POSITIONING_AUTO;
  266. Dictionary variation_coordinates;
  267. double oversampling = 0.0;
  268. double embolden = 0.0;
  269. Transform2D transform;
  270. BitField<TextServer::FontStyle> style_flags = 0;
  271. String font_name;
  272. String style_name;
  273. int weight = 400;
  274. int stretch = 100;
  275. int extra_spacing[4] = { 0, 0, 0, 0 };
  276. float baseline_offset = 0.0;
  277. HashMap<Vector2i, FontForSizeAdvanced *, VariantHasher, VariantComparator> cache;
  278. bool face_init = false;
  279. HashSet<uint32_t> supported_scripts;
  280. Dictionary supported_features;
  281. Dictionary supported_varaitions;
  282. Dictionary feature_overrides;
  283. // Language/script support override.
  284. HashMap<String, bool> language_support_overrides;
  285. HashMap<String, bool> script_support_overrides;
  286. PackedByteArray data;
  287. const uint8_t *data_ptr;
  288. size_t data_size;
  289. int face_index = 0;
  290. ~FontAdvanced() {
  291. for (const KeyValue<Vector2i, FontForSizeAdvanced *> &E : cache) {
  292. memdelete(E.value);
  293. }
  294. cache.clear();
  295. }
  296. };
  297. _FORCE_INLINE_ FontTexturePosition find_texture_pos_for_glyph(FontForSizeAdvanced *p_data, int p_color_size, Image::Format p_image_format, int p_width, int p_height, bool p_msdf) const;
  298. #ifdef MODULE_MSDFGEN_ENABLED
  299. _FORCE_INLINE_ FontGlyph rasterize_msdf(FontAdvanced *p_font_data, FontForSizeAdvanced *p_data, int p_pixel_range, int p_rect_margin, FT_Outline *p_outline, const Vector2 &p_advance) const;
  300. #endif
  301. #ifdef MODULE_FREETYPE_ENABLED
  302. _FORCE_INLINE_ FontGlyph rasterize_bitmap(FontForSizeAdvanced *p_data, int p_rect_margin, FT_Bitmap p_bitmap, int p_yofs, int p_xofs, const Vector2 &p_advance, bool p_bgra) const;
  303. #endif
  304. _FORCE_INLINE_ bool _ensure_glyph(FontAdvanced *p_font_data, const Vector2i &p_size, int32_t p_glyph) const;
  305. _FORCE_INLINE_ bool _ensure_cache_for_size(FontAdvanced *p_font_data, const Vector2i &p_size) const;
  306. _FORCE_INLINE_ void _font_clear_cache(FontAdvanced *p_font_data);
  307. static void _generateMTSDF_threaded(void *p_td, uint32_t p_y);
  308. _FORCE_INLINE_ Vector2i _get_size(const FontAdvanced *p_font_data, int p_size) const {
  309. if (p_font_data->msdf) {
  310. return Vector2i(p_font_data->msdf_source_size, 0);
  311. } else if (p_font_data->fixed_size > 0) {
  312. return Vector2i(p_font_data->fixed_size, 0);
  313. } else {
  314. return Vector2i(p_size, 0);
  315. }
  316. }
  317. _FORCE_INLINE_ Vector2i _get_size_outline(const FontAdvanced *p_font_data, const Vector2i &p_size) const {
  318. if (p_font_data->msdf) {
  319. return Vector2i(p_font_data->msdf_source_size, 0);
  320. } else if (p_font_data->fixed_size > 0) {
  321. return Vector2i(p_font_data->fixed_size, MIN(p_size.y, 1));
  322. } else {
  323. return p_size;
  324. }
  325. }
  326. _FORCE_INLINE_ double _get_extra_advance(RID p_font_rid, int p_font_size) const;
  327. _FORCE_INLINE_ Variant::Type _get_tag_type(int64_t p_tag) const;
  328. _FORCE_INLINE_ bool _get_tag_hidden(int64_t p_tag) const;
  329. _FORCE_INLINE_ int _font_get_weight_by_name(const String &p_sty_name) const {
  330. String sty_name = p_sty_name.replace(" ", "").replace("-", "");
  331. if (sty_name.find("thin") >= 0 || sty_name.find("hairline") >= 0) {
  332. return 100;
  333. } else if (sty_name.find("extralight") >= 0 || sty_name.find("ultralight") >= 0) {
  334. return 200;
  335. } else if (sty_name.find("light") >= 0) {
  336. return 300;
  337. } else if (sty_name.find("semilight") >= 0) {
  338. return 350;
  339. } else if (sty_name.find("regular") >= 0) {
  340. return 400;
  341. } else if (sty_name.find("medium") >= 0) {
  342. return 500;
  343. } else if (sty_name.find("semibold") >= 0 || sty_name.find("demibold") >= 0) {
  344. return 600;
  345. } else if (sty_name.find("bold") >= 0) {
  346. return 700;
  347. } else if (sty_name.find("extrabold") >= 0 || sty_name.find("ultrabold") >= 0) {
  348. return 800;
  349. } else if (sty_name.find("black") >= 0 || sty_name.find("heavy") >= 0) {
  350. return 900;
  351. } else if (sty_name.find("extrablack") >= 0 || sty_name.find("ultrablack") >= 0) {
  352. return 950;
  353. }
  354. return 400;
  355. }
  356. _FORCE_INLINE_ int _font_get_stretch_by_name(const String &p_sty_name) const {
  357. String sty_name = p_sty_name.replace(" ", "").replace("-", "");
  358. if (sty_name.find("ultracondensed") >= 0) {
  359. return 50;
  360. } else if (sty_name.find("extracondensed") >= 0) {
  361. return 63;
  362. } else if (sty_name.find("condensed") >= 0) {
  363. return 75;
  364. } else if (sty_name.find("semicondensed") >= 0) {
  365. return 87;
  366. } else if (sty_name.find("semiexpanded") >= 0) {
  367. return 113;
  368. } else if (sty_name.find("expanded") >= 0) {
  369. return 125;
  370. } else if (sty_name.find("extraexpanded") >= 0) {
  371. return 150;
  372. } else if (sty_name.find("ultraexpanded") >= 0) {
  373. return 200;
  374. }
  375. return 100;
  376. }
  377. _FORCE_INLINE_ bool _is_ital_style(const String &p_sty_name) const {
  378. return (p_sty_name.find("italic") >= 0) || (p_sty_name.find("oblique") >= 0);
  379. }
  380. // Shaped text cache data.
  381. struct TrimData {
  382. int trim_pos = -1;
  383. int ellipsis_pos = -1;
  384. Vector<Glyph> ellipsis_glyph_buf;
  385. };
  386. struct ShapedTextDataAdvanced {
  387. Mutex mutex;
  388. /* Source data */
  389. RID parent; // Substring parent ShapedTextData.
  390. int start = 0; // Substring start offset in the parent string.
  391. int end = 0; // Substring end offset in the parent string.
  392. String text;
  393. String custom_punct;
  394. TextServer::Direction direction = DIRECTION_LTR; // Desired text direction.
  395. TextServer::Orientation orientation = ORIENTATION_HORIZONTAL;
  396. struct Span {
  397. int start = -1;
  398. int end = -1;
  399. Array fonts;
  400. int font_size = 0;
  401. Variant embedded_key;
  402. String language;
  403. Dictionary features;
  404. Variant meta;
  405. };
  406. Vector<Span> spans;
  407. struct EmbeddedObject {
  408. int start = -1;
  409. int end = -1;
  410. InlineAlignment inline_align = INLINE_ALIGNMENT_CENTER;
  411. Rect2 rect;
  412. double baseline = 0;
  413. };
  414. HashMap<Variant, EmbeddedObject, VariantHasher, VariantComparator> objects;
  415. /* Shaped data */
  416. TextServer::Direction para_direction = DIRECTION_LTR; // Detected text direction.
  417. int base_para_direction = UBIDI_DEFAULT_LTR;
  418. bool valid = false; // String is shaped.
  419. bool line_breaks_valid = false; // Line and word break flags are populated (and virtual zero width spaces inserted).
  420. bool justification_ops_valid = false; // Virtual elongation glyphs are added to the string.
  421. bool sort_valid = false;
  422. bool text_trimmed = false;
  423. bool preserve_invalid = true; // Draw hex code box instead of missing characters.
  424. bool preserve_control = false; // Draw control characters.
  425. double ascent = 0.0; // Ascent for horizontal layout, 1/2 of width for vertical.
  426. double descent = 0.0; // Descent for horizontal layout, 1/2 of width for vertical.
  427. double width = 0.0; // Width for horizontal layout, height for vertical.
  428. double width_trimmed = 0.0;
  429. int extra_spacing[4] = { 0, 0, 0, 0 };
  430. double upos = 0.0;
  431. double uthk = 0.0;
  432. char32_t el_char = 0x2026;
  433. TrimData overrun_trim_data;
  434. bool fit_width_minimum_reached = false;
  435. Vector<Glyph> glyphs;
  436. Vector<Glyph> glyphs_logical;
  437. /* Intermediate data */
  438. Char16String utf16;
  439. Vector<UBiDi *> bidi_iter;
  440. Vector<Vector3i> bidi_override;
  441. ScriptIterator *script_iter = nullptr;
  442. hb_buffer_t *hb_buffer = nullptr;
  443. HashMap<int, bool> jstops;
  444. HashMap<int, bool> breaks;
  445. PackedInt32Array chars;
  446. int break_inserts = 0;
  447. bool break_ops_valid = false;
  448. bool js_ops_valid = false;
  449. bool chars_valid = false;
  450. ~ShapedTextDataAdvanced() {
  451. for (int i = 0; i < bidi_iter.size(); i++) {
  452. if (bidi_iter[i]) {
  453. ubidi_close(bidi_iter[i]);
  454. }
  455. }
  456. if (script_iter) {
  457. memdelete(script_iter);
  458. }
  459. if (hb_buffer) {
  460. hb_buffer_destroy(hb_buffer);
  461. }
  462. }
  463. };
  464. // Common data.
  465. double oversampling = 1.0;
  466. mutable RID_PtrOwner<FontAdvancedLinkedVariation> font_var_owner;
  467. mutable RID_PtrOwner<FontAdvanced> font_owner;
  468. mutable RID_PtrOwner<ShapedTextDataAdvanced> shaped_owner;
  469. _FORCE_INLINE_ FontAdvanced *_get_font_data(const RID &p_font_rid) const {
  470. RID rid = p_font_rid;
  471. FontAdvancedLinkedVariation *fdv = font_var_owner.get_or_null(rid);
  472. if (unlikely(fdv)) {
  473. rid = fdv->base_font;
  474. }
  475. return font_owner.get_or_null(rid);
  476. }
  477. struct SystemFontKey {
  478. String font_name;
  479. TextServer::FontAntialiasing antialiasing = TextServer::FONT_ANTIALIASING_GRAY;
  480. bool disable_embedded_bitmaps = true;
  481. bool italic = false;
  482. bool mipmaps = false;
  483. bool msdf = false;
  484. bool force_autohinter = false;
  485. int weight = 400;
  486. int stretch = 100;
  487. int msdf_range = 14;
  488. int msdf_source_size = 48;
  489. int fixed_size = 0;
  490. TextServer::Hinting hinting = TextServer::HINTING_LIGHT;
  491. TextServer::SubpixelPositioning subpixel_positioning = TextServer::SUBPIXEL_POSITIONING_AUTO;
  492. Dictionary variation_coordinates;
  493. double oversampling = 0.0;
  494. double embolden = 0.0;
  495. Transform2D transform;
  496. int extra_spacing[4] = { 0, 0, 0, 0 };
  497. float baseline_offset = 0.0;
  498. bool operator==(const SystemFontKey &p_b) const {
  499. return (font_name == p_b.font_name) && (antialiasing == p_b.antialiasing) && (italic == p_b.italic) && (disable_embedded_bitmaps == p_b.disable_embedded_bitmaps) && (mipmaps == p_b.mipmaps) && (msdf == p_b.msdf) && (force_autohinter == p_b.force_autohinter) && (weight == p_b.weight) && (stretch == p_b.stretch) && (msdf_range == p_b.msdf_range) && (msdf_source_size == p_b.msdf_source_size) && (fixed_size == p_b.fixed_size) && (hinting == p_b.hinting) && (subpixel_positioning == p_b.subpixel_positioning) && (variation_coordinates == p_b.variation_coordinates) && (oversampling == p_b.oversampling) && (embolden == p_b.embolden) && (transform == p_b.transform) && (extra_spacing[SPACING_TOP] == p_b.extra_spacing[SPACING_TOP]) && (extra_spacing[SPACING_BOTTOM] == p_b.extra_spacing[SPACING_BOTTOM]) && (extra_spacing[SPACING_SPACE] == p_b.extra_spacing[SPACING_SPACE]) && (extra_spacing[SPACING_GLYPH] == p_b.extra_spacing[SPACING_GLYPH]) && (baseline_offset == p_b.baseline_offset);
  500. }
  501. SystemFontKey(const String &p_font_name, bool p_italic, int p_weight, int p_stretch, RID p_font, const TextServerAdvanced *p_fb) {
  502. font_name = p_font_name;
  503. italic = p_italic;
  504. weight = p_weight;
  505. stretch = p_stretch;
  506. antialiasing = p_fb->_font_get_antialiasing(p_font);
  507. disable_embedded_bitmaps = p_fb->_font_get_disable_embedded_bitmaps(p_font);
  508. mipmaps = p_fb->_font_get_generate_mipmaps(p_font);
  509. msdf = p_fb->_font_is_multichannel_signed_distance_field(p_font);
  510. msdf_range = p_fb->_font_get_msdf_pixel_range(p_font);
  511. msdf_source_size = p_fb->_font_get_msdf_size(p_font);
  512. fixed_size = p_fb->_font_get_fixed_size(p_font);
  513. force_autohinter = p_fb->_font_is_force_autohinter(p_font);
  514. hinting = p_fb->_font_get_hinting(p_font);
  515. subpixel_positioning = p_fb->_font_get_subpixel_positioning(p_font);
  516. variation_coordinates = p_fb->_font_get_variation_coordinates(p_font);
  517. oversampling = p_fb->_font_get_oversampling(p_font);
  518. embolden = p_fb->_font_get_embolden(p_font);
  519. transform = p_fb->_font_get_transform(p_font);
  520. extra_spacing[SPACING_TOP] = p_fb->_font_get_spacing(p_font, SPACING_TOP);
  521. extra_spacing[SPACING_BOTTOM] = p_fb->_font_get_spacing(p_font, SPACING_BOTTOM);
  522. extra_spacing[SPACING_SPACE] = p_fb->_font_get_spacing(p_font, SPACING_SPACE);
  523. extra_spacing[SPACING_GLYPH] = p_fb->_font_get_spacing(p_font, SPACING_GLYPH);
  524. baseline_offset = p_fb->_font_get_baseline_offset(p_font);
  525. }
  526. };
  527. struct SystemFontCacheRec {
  528. RID rid;
  529. int index = 0;
  530. };
  531. struct SystemFontCache {
  532. Vector<SystemFontCacheRec> var;
  533. int max_var = 0;
  534. };
  535. struct SystemFontKeyHasher {
  536. _FORCE_INLINE_ static uint32_t hash(const SystemFontKey &p_a) {
  537. uint32_t hash = p_a.font_name.hash();
  538. hash = hash_murmur3_one_32(p_a.variation_coordinates.hash(), hash);
  539. hash = hash_murmur3_one_32(p_a.weight, hash);
  540. hash = hash_murmur3_one_32(p_a.stretch, hash);
  541. hash = hash_murmur3_one_32(p_a.msdf_range, hash);
  542. hash = hash_murmur3_one_32(p_a.msdf_source_size, hash);
  543. hash = hash_murmur3_one_32(p_a.fixed_size, hash);
  544. hash = hash_murmur3_one_double(p_a.oversampling, hash);
  545. hash = hash_murmur3_one_double(p_a.embolden, hash);
  546. hash = hash_murmur3_one_real(p_a.transform[0].x, hash);
  547. hash = hash_murmur3_one_real(p_a.transform[0].y, hash);
  548. hash = hash_murmur3_one_real(p_a.transform[1].x, hash);
  549. hash = hash_murmur3_one_real(p_a.transform[1].y, hash);
  550. hash = hash_murmur3_one_32(p_a.extra_spacing[SPACING_TOP], hash);
  551. hash = hash_murmur3_one_32(p_a.extra_spacing[SPACING_BOTTOM], hash);
  552. hash = hash_murmur3_one_32(p_a.extra_spacing[SPACING_SPACE], hash);
  553. hash = hash_murmur3_one_32(p_a.extra_spacing[SPACING_GLYPH], hash);
  554. hash = hash_murmur3_one_double(p_a.baseline_offset, hash);
  555. return hash_fmix32(hash_murmur3_one_32(((int)p_a.mipmaps) | ((int)p_a.msdf << 1) | ((int)p_a.italic << 2) | ((int)p_a.force_autohinter << 3) | ((int)p_a.hinting << 4) | ((int)p_a.subpixel_positioning << 8) | ((int)p_a.antialiasing << 12) | ((int)p_a.disable_embedded_bitmaps << 14), hash));
  556. }
  557. };
  558. mutable HashMap<SystemFontKey, SystemFontCache, SystemFontKeyHasher> system_fonts;
  559. mutable HashMap<String, PackedByteArray> system_font_data;
  560. void _update_chars(ShapedTextDataAdvanced *p_sd) const;
  561. void _realign(ShapedTextDataAdvanced *p_sd) const;
  562. int64_t _convert_pos(const String &p_utf32, const Char16String &p_utf16, int64_t p_pos) const;
  563. int64_t _convert_pos(const ShapedTextDataAdvanced *p_sd, int64_t p_pos) const;
  564. int64_t _convert_pos_inv(const ShapedTextDataAdvanced *p_sd, int64_t p_pos) const;
  565. bool _shape_substr(ShapedTextDataAdvanced *p_new_sd, const ShapedTextDataAdvanced *p_sd, int64_t p_start, int64_t p_length) const;
  566. void _shape_run(ShapedTextDataAdvanced *p_sd, int64_t p_start, int64_t p_end, hb_script_t p_script, hb_direction_t p_direction, TypedArray<RID> p_fonts, int64_t p_span, int64_t p_fb_index, int64_t p_prev_start, int64_t p_prev_end, RID p_prev_font);
  567. Glyph _shape_single_glyph(ShapedTextDataAdvanced *p_sd, char32_t p_char, hb_script_t p_script, hb_direction_t p_direction, const RID &p_font, int64_t p_font_size);
  568. _FORCE_INLINE_ RID _find_sys_font_for_text(const RID &p_fdef, const String &p_script_code, const String &p_language, const String &p_text);
  569. _FORCE_INLINE_ void _add_featuers(const Dictionary &p_source, Vector<hb_feature_t> &r_ftrs);
  570. Mutex ft_mutex;
  571. // HarfBuzz bitmap font interface.
  572. static hb_font_funcs_t *funcs;
  573. struct bmp_font_t {
  574. TextServerAdvanced::FontForSizeAdvanced *face = nullptr;
  575. bool unref = false; /* Whether to destroy bm_face when done. */
  576. };
  577. static bmp_font_t *_bmp_font_create(TextServerAdvanced::FontForSizeAdvanced *p_face, bool p_unref);
  578. static void _bmp_font_destroy(void *p_data);
  579. static hb_bool_t _bmp_get_nominal_glyph(hb_font_t *p_font, void *p_font_data, hb_codepoint_t p_unicode, hb_codepoint_t *r_glyph, void *p_user_data);
  580. static hb_position_t _bmp_get_glyph_h_advance(hb_font_t *p_font, void *p_font_data, hb_codepoint_t p_glyph, void *p_user_data);
  581. static hb_position_t _bmp_get_glyph_v_advance(hb_font_t *p_font, void *p_font_data, hb_codepoint_t p_glyph, void *p_user_data);
  582. static hb_position_t _bmp_get_glyph_h_kerning(hb_font_t *p_font, void *p_font_data, hb_codepoint_t p_left_glyph, hb_codepoint_t p_right_glyph, void *p_user_data);
  583. static hb_bool_t _bmp_get_glyph_v_origin(hb_font_t *p_font, void *p_font_data, hb_codepoint_t p_glyph, hb_position_t *r_x, hb_position_t *r_y, void *p_user_data);
  584. static hb_bool_t _bmp_get_glyph_extents(hb_font_t *p_font, void *p_font_data, hb_codepoint_t p_glyph, hb_glyph_extents_t *r_extents, void *p_user_data);
  585. static hb_bool_t _bmp_get_font_h_extents(hb_font_t *p_font, void *p_font_data, hb_font_extents_t *r_metrics, void *p_user_data);
  586. static void _bmp_create_font_funcs();
  587. static void _bmp_free_font_funcs();
  588. static void _bmp_font_set_funcs(hb_font_t *p_font, TextServerAdvanced::FontForSizeAdvanced *p_face, bool p_unref);
  589. static hb_font_t *_bmp_font_create(TextServerAdvanced::FontForSizeAdvanced *p_face, hb_destroy_func_t p_destroy);
  590. hb_font_t *_font_get_hb_handle(const RID &p_font, int64_t p_font_size) const;
  591. struct GlyphCompare { // For line breaking reordering.
  592. _FORCE_INLINE_ bool operator()(const Glyph &l, const Glyph &r) const {
  593. if (l.start == r.start) {
  594. if (l.count == r.count) {
  595. return (l.flags & TextServer::GRAPHEME_IS_VIRTUAL) < (r.flags & TextServer::GRAPHEME_IS_VIRTUAL);
  596. }
  597. return l.count > r.count; // Sort first glyph with count & flags, order of the rest are irrelevant.
  598. } else {
  599. return l.start < r.start;
  600. }
  601. }
  602. };
  603. protected:
  604. static void _bind_methods(){};
  605. void full_copy(ShapedTextDataAdvanced *p_shaped);
  606. void invalidate(ShapedTextDataAdvanced *p_shaped, bool p_text = false);
  607. public:
  608. MODBIND1RC(bool, has_feature, Feature);
  609. MODBIND0RC(String, get_name);
  610. MODBIND0RC(int64_t, get_features);
  611. MODBIND1(free_rid, const RID &);
  612. MODBIND1R(bool, has, const RID &);
  613. MODBIND1R(bool, load_support_data, const String &);
  614. MODBIND0RC(String, get_support_data_filename);
  615. MODBIND0RC(String, get_support_data_info);
  616. MODBIND1RC(bool, save_support_data, const String &);
  617. MODBIND1RC(bool, is_locale_right_to_left, const String &);
  618. MODBIND1RC(int64_t, name_to_tag, const String &);
  619. MODBIND1RC(String, tag_to_name, int64_t);
  620. /* Font interface */
  621. MODBIND0R(RID, create_font);
  622. MODBIND1R(RID, create_font_linked_variation, const RID &);
  623. MODBIND2(font_set_data, const RID &, const PackedByteArray &);
  624. MODBIND3(font_set_data_ptr, const RID &, const uint8_t *, int64_t);
  625. MODBIND2(font_set_face_index, const RID &, int64_t);
  626. MODBIND1RC(int64_t, font_get_face_index, const RID &);
  627. MODBIND1RC(int64_t, font_get_face_count, const RID &);
  628. MODBIND2(font_set_style, const RID &, BitField<FontStyle>);
  629. MODBIND1RC(BitField<FontStyle>, font_get_style, const RID &);
  630. MODBIND2(font_set_style_name, const RID &, const String &);
  631. MODBIND1RC(String, font_get_style_name, const RID &);
  632. MODBIND2(font_set_weight, const RID &, int64_t);
  633. MODBIND1RC(int64_t, font_get_weight, const RID &);
  634. MODBIND2(font_set_stretch, const RID &, int64_t);
  635. MODBIND1RC(int64_t, font_get_stretch, const RID &);
  636. MODBIND2(font_set_name, const RID &, const String &);
  637. MODBIND1RC(String, font_get_name, const RID &);
  638. MODBIND1RC(Dictionary, font_get_ot_name_strings, const RID &);
  639. MODBIND2(font_set_antialiasing, const RID &, TextServer::FontAntialiasing);
  640. MODBIND1RC(TextServer::FontAntialiasing, font_get_antialiasing, const RID &);
  641. MODBIND2(font_set_disable_embedded_bitmaps, const RID &, bool);
  642. MODBIND1RC(bool, font_get_disable_embedded_bitmaps, const RID &);
  643. MODBIND2(font_set_generate_mipmaps, const RID &, bool);
  644. MODBIND1RC(bool, font_get_generate_mipmaps, const RID &);
  645. MODBIND2(font_set_multichannel_signed_distance_field, const RID &, bool);
  646. MODBIND1RC(bool, font_is_multichannel_signed_distance_field, const RID &);
  647. MODBIND2(font_set_msdf_pixel_range, const RID &, int64_t);
  648. MODBIND1RC(int64_t, font_get_msdf_pixel_range, const RID &);
  649. MODBIND2(font_set_msdf_size, const RID &, int64_t);
  650. MODBIND1RC(int64_t, font_get_msdf_size, const RID &);
  651. MODBIND2(font_set_fixed_size, const RID &, int64_t);
  652. MODBIND1RC(int64_t, font_get_fixed_size, const RID &);
  653. MODBIND2(font_set_fixed_size_scale_mode, const RID &, FixedSizeScaleMode);
  654. MODBIND1RC(FixedSizeScaleMode, font_get_fixed_size_scale_mode, const RID &);
  655. MODBIND2(font_set_allow_system_fallback, const RID &, bool);
  656. MODBIND1RC(bool, font_is_allow_system_fallback, const RID &);
  657. MODBIND2(font_set_force_autohinter, const RID &, bool);
  658. MODBIND1RC(bool, font_is_force_autohinter, const RID &);
  659. MODBIND2(font_set_subpixel_positioning, const RID &, SubpixelPositioning);
  660. MODBIND1RC(SubpixelPositioning, font_get_subpixel_positioning, const RID &);
  661. MODBIND2(font_set_embolden, const RID &, double);
  662. MODBIND1RC(double, font_get_embolden, const RID &);
  663. MODBIND3(font_set_spacing, const RID &, SpacingType, int64_t);
  664. MODBIND2RC(int64_t, font_get_spacing, const RID &, SpacingType);
  665. MODBIND2(font_set_baseline_offset, const RID &, float);
  666. MODBIND1RC(float, font_get_baseline_offset, const RID &);
  667. MODBIND2(font_set_transform, const RID &, const Transform2D &);
  668. MODBIND1RC(Transform2D, font_get_transform, const RID &);
  669. MODBIND2(font_set_variation_coordinates, const RID &, const Dictionary &);
  670. MODBIND1RC(Dictionary, font_get_variation_coordinates, const RID &);
  671. MODBIND2(font_set_hinting, const RID &, TextServer::Hinting);
  672. MODBIND1RC(TextServer::Hinting, font_get_hinting, const RID &);
  673. MODBIND2(font_set_oversampling, const RID &, double);
  674. MODBIND1RC(double, font_get_oversampling, const RID &);
  675. MODBIND1RC(TypedArray<Vector2i>, font_get_size_cache_list, const RID &);
  676. MODBIND1(font_clear_size_cache, const RID &);
  677. MODBIND2(font_remove_size_cache, const RID &, const Vector2i &);
  678. MODBIND3(font_set_ascent, const RID &, int64_t, double);
  679. MODBIND2RC(double, font_get_ascent, const RID &, int64_t);
  680. MODBIND3(font_set_descent, const RID &, int64_t, double);
  681. MODBIND2RC(double, font_get_descent, const RID &, int64_t);
  682. MODBIND3(font_set_underline_position, const RID &, int64_t, double);
  683. MODBIND2RC(double, font_get_underline_position, const RID &, int64_t);
  684. MODBIND3(font_set_underline_thickness, const RID &, int64_t, double);
  685. MODBIND2RC(double, font_get_underline_thickness, const RID &, int64_t);
  686. MODBIND3(font_set_scale, const RID &, int64_t, double);
  687. MODBIND2RC(double, font_get_scale, const RID &, int64_t);
  688. MODBIND2RC(int64_t, font_get_texture_count, const RID &, const Vector2i &);
  689. MODBIND2(font_clear_textures, const RID &, const Vector2i &);
  690. MODBIND3(font_remove_texture, const RID &, const Vector2i &, int64_t);
  691. MODBIND4(font_set_texture_image, const RID &, const Vector2i &, int64_t, const Ref<Image> &);
  692. MODBIND3RC(Ref<Image>, font_get_texture_image, const RID &, const Vector2i &, int64_t);
  693. MODBIND4(font_set_texture_offsets, const RID &, const Vector2i &, int64_t, const PackedInt32Array &);
  694. MODBIND3RC(PackedInt32Array, font_get_texture_offsets, const RID &, const Vector2i &, int64_t);
  695. MODBIND2RC(PackedInt32Array, font_get_glyph_list, const RID &, const Vector2i &);
  696. MODBIND2(font_clear_glyphs, const RID &, const Vector2i &);
  697. MODBIND3(font_remove_glyph, const RID &, const Vector2i &, int64_t);
  698. MODBIND3RC(Vector2, font_get_glyph_advance, const RID &, int64_t, int64_t);
  699. MODBIND4(font_set_glyph_advance, const RID &, int64_t, int64_t, const Vector2 &);
  700. MODBIND3RC(Vector2, font_get_glyph_offset, const RID &, const Vector2i &, int64_t);
  701. MODBIND4(font_set_glyph_offset, const RID &, const Vector2i &, int64_t, const Vector2 &);
  702. MODBIND3RC(Vector2, font_get_glyph_size, const RID &, const Vector2i &, int64_t);
  703. MODBIND4(font_set_glyph_size, const RID &, const Vector2i &, int64_t, const Vector2 &);
  704. MODBIND3RC(Rect2, font_get_glyph_uv_rect, const RID &, const Vector2i &, int64_t);
  705. MODBIND4(font_set_glyph_uv_rect, const RID &, const Vector2i &, int64_t, const Rect2 &);
  706. MODBIND3RC(int64_t, font_get_glyph_texture_idx, const RID &, const Vector2i &, int64_t);
  707. MODBIND4(font_set_glyph_texture_idx, const RID &, const Vector2i &, int64_t, int64_t);
  708. MODBIND3RC(RID, font_get_glyph_texture_rid, const RID &, const Vector2i &, int64_t);
  709. MODBIND3RC(Size2, font_get_glyph_texture_size, const RID &, const Vector2i &, int64_t);
  710. MODBIND3RC(Dictionary, font_get_glyph_contours, const RID &, int64_t, int64_t);
  711. MODBIND2RC(TypedArray<Vector2i>, font_get_kerning_list, const RID &, int64_t);
  712. MODBIND2(font_clear_kerning_map, const RID &, int64_t);
  713. MODBIND3(font_remove_kerning, const RID &, int64_t, const Vector2i &);
  714. MODBIND4(font_set_kerning, const RID &, int64_t, const Vector2i &, const Vector2 &);
  715. MODBIND3RC(Vector2, font_get_kerning, const RID &, int64_t, const Vector2i &);
  716. MODBIND4RC(int64_t, font_get_glyph_index, const RID &, int64_t, int64_t, int64_t);
  717. MODBIND3RC(int64_t, font_get_char_from_glyph_index, const RID &, int64_t, int64_t);
  718. MODBIND2RC(bool, font_has_char, const RID &, int64_t);
  719. MODBIND1RC(String, font_get_supported_chars, const RID &);
  720. MODBIND4(font_render_range, const RID &, const Vector2i &, int64_t, int64_t);
  721. MODBIND3(font_render_glyph, const RID &, const Vector2i &, int64_t);
  722. MODBIND6C(font_draw_glyph, const RID &, const RID &, int64_t, const Vector2 &, int64_t, const Color &);
  723. MODBIND7C(font_draw_glyph_outline, const RID &, const RID &, int64_t, int64_t, const Vector2 &, int64_t, const Color &);
  724. MODBIND2RC(bool, font_is_language_supported, const RID &, const String &);
  725. MODBIND3(font_set_language_support_override, const RID &, const String &, bool);
  726. MODBIND2R(bool, font_get_language_support_override, const RID &, const String &);
  727. MODBIND2(font_remove_language_support_override, const RID &, const String &);
  728. MODBIND1R(PackedStringArray, font_get_language_support_overrides, const RID &);
  729. MODBIND2RC(bool, font_is_script_supported, const RID &, const String &);
  730. MODBIND3(font_set_script_support_override, const RID &, const String &, bool);
  731. MODBIND2R(bool, font_get_script_support_override, const RID &, const String &);
  732. MODBIND2(font_remove_script_support_override, const RID &, const String &);
  733. MODBIND1R(PackedStringArray, font_get_script_support_overrides, const RID &);
  734. MODBIND2(font_set_opentype_feature_overrides, const RID &, const Dictionary &);
  735. MODBIND1RC(Dictionary, font_get_opentype_feature_overrides, const RID &);
  736. MODBIND1RC(Dictionary, font_supported_feature_list, const RID &);
  737. MODBIND1RC(Dictionary, font_supported_variation_list, const RID &);
  738. MODBIND0RC(double, font_get_global_oversampling);
  739. MODBIND1(font_set_global_oversampling, double);
  740. /* Shaped text buffer interface */
  741. MODBIND2R(RID, create_shaped_text, Direction, Orientation);
  742. MODBIND1(shaped_text_clear, const RID &);
  743. MODBIND2(shaped_text_set_direction, const RID &, Direction);
  744. MODBIND1RC(Direction, shaped_text_get_direction, const RID &);
  745. MODBIND1RC(Direction, shaped_text_get_inferred_direction, const RID &);
  746. MODBIND2(shaped_text_set_bidi_override, const RID &, const Array &);
  747. MODBIND2(shaped_text_set_custom_punctuation, const RID &, const String &);
  748. MODBIND1RC(String, shaped_text_get_custom_punctuation, const RID &);
  749. MODBIND2(shaped_text_set_custom_ellipsis, const RID &, int64_t);
  750. MODBIND1RC(int64_t, shaped_text_get_custom_ellipsis, const RID &);
  751. MODBIND2(shaped_text_set_orientation, const RID &, Orientation);
  752. MODBIND1RC(Orientation, shaped_text_get_orientation, const RID &);
  753. MODBIND2(shaped_text_set_preserve_invalid, const RID &, bool);
  754. MODBIND1RC(bool, shaped_text_get_preserve_invalid, const RID &);
  755. MODBIND2(shaped_text_set_preserve_control, const RID &, bool);
  756. MODBIND1RC(bool, shaped_text_get_preserve_control, const RID &);
  757. MODBIND3(shaped_text_set_spacing, const RID &, SpacingType, int64_t);
  758. MODBIND2RC(int64_t, shaped_text_get_spacing, const RID &, SpacingType);
  759. MODBIND7R(bool, shaped_text_add_string, const RID &, const String &, const TypedArray<RID> &, int64_t, const Dictionary &, const String &, const Variant &);
  760. MODBIND6R(bool, shaped_text_add_object, const RID &, const Variant &, const Size2 &, InlineAlignment, int64_t, double);
  761. MODBIND5R(bool, shaped_text_resize_object, const RID &, const Variant &, const Size2 &, InlineAlignment, double);
  762. MODBIND1RC(int64_t, shaped_get_span_count, const RID &);
  763. MODBIND2RC(Variant, shaped_get_span_meta, const RID &, int64_t);
  764. MODBIND5(shaped_set_span_update_font, const RID &, int64_t, const TypedArray<RID> &, int64_t, const Dictionary &);
  765. MODBIND3RC(RID, shaped_text_substr, const RID &, int64_t, int64_t);
  766. MODBIND1RC(RID, shaped_text_get_parent, const RID &);
  767. MODBIND3R(double, shaped_text_fit_to_width, const RID &, double, BitField<TextServer::JustificationFlag>);
  768. MODBIND2R(double, shaped_text_tab_align, const RID &, const PackedFloat32Array &);
  769. MODBIND1R(bool, shaped_text_shape, const RID &);
  770. MODBIND1R(bool, shaped_text_update_breaks, const RID &);
  771. MODBIND1R(bool, shaped_text_update_justification_ops, const RID &);
  772. MODBIND1RC(int64_t, shaped_text_get_trim_pos, const RID &);
  773. MODBIND1RC(int64_t, shaped_text_get_ellipsis_pos, const RID &);
  774. MODBIND1RC(const Glyph *, shaped_text_get_ellipsis_glyphs, const RID &);
  775. MODBIND1RC(int64_t, shaped_text_get_ellipsis_glyph_count, const RID &);
  776. MODBIND3(shaped_text_overrun_trim_to_width, const RID &, double, BitField<TextServer::TextOverrunFlag>);
  777. MODBIND1RC(bool, shaped_text_is_ready, const RID &);
  778. MODBIND1RC(const Glyph *, shaped_text_get_glyphs, const RID &);
  779. MODBIND1R(const Glyph *, shaped_text_sort_logical, const RID &);
  780. MODBIND1RC(int64_t, shaped_text_get_glyph_count, const RID &);
  781. MODBIND1RC(Vector2i, shaped_text_get_range, const RID &);
  782. MODBIND1RC(Array, shaped_text_get_objects, const RID &);
  783. MODBIND2RC(Rect2, shaped_text_get_object_rect, const RID &, const Variant &);
  784. MODBIND2RC(Vector2i, shaped_text_get_object_range, const RID &, const Variant &);
  785. MODBIND2RC(int64_t, shaped_text_get_object_glyph, const RID &, const Variant &);
  786. MODBIND1RC(Size2, shaped_text_get_size, const RID &);
  787. MODBIND1RC(double, shaped_text_get_ascent, const RID &);
  788. MODBIND1RC(double, shaped_text_get_descent, const RID &);
  789. MODBIND1RC(double, shaped_text_get_width, const RID &);
  790. MODBIND1RC(double, shaped_text_get_underline_position, const RID &);
  791. MODBIND1RC(double, shaped_text_get_underline_thickness, const RID &);
  792. MODBIND1RC(PackedInt32Array, shaped_text_get_character_breaks, const RID &);
  793. MODBIND2RC(String, format_number, const String &, const String &);
  794. MODBIND2RC(String, parse_number, const String &, const String &);
  795. MODBIND1RC(String, percent_sign, const String &);
  796. MODBIND3RC(PackedInt32Array, string_get_word_breaks, const String &, const String &, int64_t);
  797. MODBIND2RC(PackedInt32Array, string_get_character_breaks, const String &, const String &);
  798. MODBIND2RC(int64_t, is_confusable, const String &, const PackedStringArray &);
  799. MODBIND1RC(bool, spoof_check, const String &);
  800. MODBIND1RC(String, strip_diacritics, const String &);
  801. MODBIND1RC(bool, is_valid_identifier, const String &);
  802. MODBIND2RC(String, string_to_upper, const String &, const String &);
  803. MODBIND2RC(String, string_to_lower, const String &, const String &);
  804. MODBIND2RC(String, string_to_title, const String &, const String &);
  805. MODBIND0(cleanup);
  806. TextServerAdvanced();
  807. ~TextServerAdvanced();
  808. };
  809. #endif // TEXT_SERVER_ADV_H