text_server_adv.h 40 KB

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