text_server_adv.h 41 KB

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