text_server_adv.h 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721
  1. /*************************************************************************/
  2. /* text_server_adv.h */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */
  10. /* */
  11. /* Permission is hereby granted, free of charge, to any person obtaining */
  12. /* a copy of this software and associated documentation files (the */
  13. /* "Software"), to deal in the Software without restriction, including */
  14. /* without limitation the rights to use, copy, modify, merge, publish, */
  15. /* distribute, sublicense, and/or sell copies of the Software, and to */
  16. /* permit persons to whom the Software is furnished to do so, subject to */
  17. /* the following conditions: */
  18. /* */
  19. /* The above copyright notice and this permission notice shall be */
  20. /* included in all copies or substantial portions of the Software. */
  21. /* */
  22. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  23. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  24. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
  25. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  26. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  27. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  28. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  29. /*************************************************************************/
  30. #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. #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/mutex_lock.hpp>
  41. #include <godot_cpp/variant/array.hpp>
  42. #include <godot_cpp/variant/dictionary.hpp>
  43. #include <godot_cpp/variant/packed_int32_array.hpp>
  44. #include <godot_cpp/variant/packed_string_array.hpp>
  45. #include <godot_cpp/variant/packed_vector2_array.hpp>
  46. #include <godot_cpp/variant/rect2.hpp>
  47. #include <godot_cpp/variant/rid.hpp>
  48. #include <godot_cpp/variant/string.hpp>
  49. #include <godot_cpp/variant/vector2.hpp>
  50. #include <godot_cpp/variant/vector2i.hpp>
  51. #include <godot_cpp/classes/text_server.hpp>
  52. #include <godot_cpp/classes/text_server_extension.hpp>
  53. #include <godot_cpp/classes/text_server_manager.hpp>
  54. #include <godot_cpp/classes/caret_info.hpp>
  55. #include <godot_cpp/classes/global_constants_binds.hpp>
  56. #include <godot_cpp/classes/glyph.hpp>
  57. #include <godot_cpp/classes/image.hpp>
  58. #include <godot_cpp/classes/image_texture.hpp>
  59. #include <godot_cpp/classes/ref.hpp>
  60. #include <godot_cpp/classes/worker_thread_pool.hpp>
  61. #include <godot_cpp/templates/hash_map.hpp>
  62. #include <godot_cpp/templates/hash_set.hpp>
  63. #include <godot_cpp/templates/rid_owner.hpp>
  64. #include <godot_cpp/templates/vector.hpp>
  65. using namespace godot;
  66. #else
  67. // Headers for building as built-in module.
  68. #include "core/object/worker_thread_pool.h"
  69. #include "core/templates/hash_map.h"
  70. #include "core/templates/rid_owner.h"
  71. #include "scene/resources/texture.h"
  72. #include "servers/text/text_server_extension.h"
  73. #include "modules/modules_enabled.gen.h" // For freetype, msdfgen.
  74. #endif
  75. #include "script_iterator.h"
  76. // Thirdparty headers.
  77. #include <unicode/ubidi.h>
  78. #include <unicode/ubrk.h>
  79. #include <unicode/uchar.h>
  80. #include <unicode/uclean.h>
  81. #include <unicode/udata.h>
  82. #include <unicode/uiter.h>
  83. #include <unicode/uloc.h>
  84. #include <unicode/unorm2.h>
  85. #include <unicode/uscript.h>
  86. #include <unicode/uspoof.h>
  87. #include <unicode/ustring.h>
  88. #include <unicode/utypes.h>
  89. #ifdef MODULE_FREETYPE_ENABLED
  90. #include <ft2build.h>
  91. #include FT_FREETYPE_H
  92. #include FT_TRUETYPE_TABLES_H
  93. #include FT_STROKER_H
  94. #include FT_ADVANCES_H
  95. #include FT_MULTIPLE_MASTERS_H
  96. #include FT_BBOX_H
  97. #include FT_CONFIG_OPTIONS_H
  98. #if !defined(FT_CONFIG_OPTION_USE_BROTLI) && !defined(_MSC_VER)
  99. #warning FreeType is configured without Brotli support, built-in fonts will not be available.
  100. #endif
  101. #include <hb-ft.h>
  102. #include <hb-ot.h>
  103. #endif
  104. #include <hb-icu.h>
  105. #include <hb.h>
  106. /*************************************************************************/
  107. class TextServerAdvanced : public TextServerExtension {
  108. GDCLASS(TextServerAdvanced, TextServerExtension);
  109. _THREAD_SAFE_CLASS_
  110. struct NumSystemData {
  111. HashSet<StringName> lang;
  112. String digits;
  113. String percent_sign;
  114. String exp;
  115. };
  116. Vector<NumSystemData> num_systems;
  117. struct FeatureInfo {
  118. StringName name;
  119. Variant::Type vtype = Variant::INT;
  120. bool hidden = false;
  121. };
  122. HashMap<StringName, int32_t> feature_sets;
  123. HashMap<int32_t, FeatureInfo> feature_sets_inv;
  124. void _insert_num_systems_lang();
  125. void _insert_feature_sets();
  126. _FORCE_INLINE_ void _insert_feature(const StringName &p_name, int32_t p_tag, Variant::Type p_vtype = Variant::INT, bool p_hidden = false);
  127. // ICU support data.
  128. bool icu_data_loaded = false;
  129. // Font cache data.
  130. #ifdef MODULE_FREETYPE_ENABLED
  131. mutable FT_Library ft_library = nullptr;
  132. #endif
  133. const int rect_range = 1;
  134. struct FontTexture {
  135. Image::Format format;
  136. PackedByteArray imgdata;
  137. int texture_w = 0;
  138. int texture_h = 0;
  139. PackedInt32Array offsets;
  140. Ref<ImageTexture> texture;
  141. bool dirty = true;
  142. };
  143. struct FontTexturePosition {
  144. int index = 0;
  145. int x = 0;
  146. int y = 0;
  147. };
  148. struct FontGlyph {
  149. bool found = false;
  150. int texture_idx = -1;
  151. Rect2 rect;
  152. Rect2 uv_rect;
  153. Vector2 advance;
  154. };
  155. struct FontForSizeAdvanced {
  156. double ascent = 0.0;
  157. double descent = 0.0;
  158. double underline_position = 0.0;
  159. double underline_thickness = 0.0;
  160. double scale = 1.0;
  161. double oversampling = 1.0;
  162. Vector2i size;
  163. Vector<FontTexture> textures;
  164. HashMap<int32_t, FontGlyph> glyph_map;
  165. HashMap<Vector2i, Vector2> kerning_map;
  166. hb_font_t *hb_handle = nullptr;
  167. #ifdef MODULE_FREETYPE_ENABLED
  168. FT_Face face = nullptr;
  169. FT_StreamRec stream;
  170. #endif
  171. ~FontForSizeAdvanced() {
  172. if (hb_handle != nullptr) {
  173. hb_font_destroy(hb_handle);
  174. }
  175. #ifdef MODULE_FREETYPE_ENABLED
  176. if (face != nullptr) {
  177. FT_Done_Face(face);
  178. }
  179. #endif
  180. }
  181. };
  182. struct FontAdvanced {
  183. Mutex mutex;
  184. TextServer::FontAntialiasing antialiasing = TextServer::FONT_ANTIALIASING_GRAY;
  185. bool mipmaps = false;
  186. bool msdf = false;
  187. int msdf_range = 14;
  188. int msdf_source_size = 48;
  189. int fixed_size = 0;
  190. bool force_autohinter = false;
  191. TextServer::Hinting hinting = TextServer::HINTING_LIGHT;
  192. TextServer::SubpixelPositioning subpixel_positioning = TextServer::SUBPIXEL_POSITIONING_AUTO;
  193. Dictionary variation_coordinates;
  194. double oversampling = 0.0;
  195. double embolden = 0.0;
  196. Transform2D transform;
  197. BitField<TextServer::FontStyle> style_flags = 0;
  198. String font_name;
  199. String style_name;
  200. HashMap<Vector2i, FontForSizeAdvanced *, VariantHasher, VariantComparator> cache;
  201. bool face_init = false;
  202. HashSet<uint32_t> supported_scripts;
  203. Dictionary supported_features;
  204. Dictionary supported_varaitions;
  205. Dictionary feature_overrides;
  206. // Language/script support override.
  207. HashMap<String, bool> language_support_overrides;
  208. HashMap<String, bool> script_support_overrides;
  209. PackedByteArray data;
  210. const uint8_t *data_ptr;
  211. size_t data_size;
  212. int face_index = 0;
  213. ~FontAdvanced() {
  214. for (const KeyValue<Vector2i, FontForSizeAdvanced *> &E : cache) {
  215. memdelete(E.value);
  216. }
  217. cache.clear();
  218. }
  219. };
  220. _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;
  221. #ifdef MODULE_MSDFGEN_ENABLED
  222. _FORCE_INLINE_ FontGlyph rasterize_msdf(FontAdvanced *p_font_data, FontForSizeAdvanced *p_data, int p_pixel_range, int p_rect_margin, FT_Outline *outline, const Vector2 &advance) const;
  223. #endif
  224. #ifdef MODULE_FREETYPE_ENABLED
  225. _FORCE_INLINE_ FontGlyph rasterize_bitmap(FontForSizeAdvanced *p_data, int p_rect_margin, FT_Bitmap bitmap, int yofs, int xofs, const Vector2 &advance, bool p_bgra) const;
  226. #endif
  227. _FORCE_INLINE_ bool _ensure_glyph(FontAdvanced *p_font_data, const Vector2i &p_size, int32_t p_glyph) const;
  228. _FORCE_INLINE_ bool _ensure_cache_for_size(FontAdvanced *p_font_data, const Vector2i &p_size) const;
  229. _FORCE_INLINE_ void _font_clear_cache(FontAdvanced *p_font_data);
  230. void _generateMTSDF_threaded(uint32_t y, void *p_td) const;
  231. _FORCE_INLINE_ Vector2i _get_size(const FontAdvanced *p_font_data, int p_size) const {
  232. if (p_font_data->msdf) {
  233. return Vector2i(p_font_data->msdf_source_size, 0);
  234. } else if (p_font_data->fixed_size > 0) {
  235. return Vector2i(p_font_data->fixed_size, 0);
  236. } else {
  237. return Vector2i(p_size, 0);
  238. }
  239. }
  240. _FORCE_INLINE_ Vector2i _get_size_outline(const FontAdvanced *p_font_data, const Vector2i &p_size) const {
  241. if (p_font_data->msdf) {
  242. return Vector2i(p_font_data->msdf_source_size, 0);
  243. } else if (p_font_data->fixed_size > 0) {
  244. return Vector2i(p_font_data->fixed_size, MIN(p_size.y, 1));
  245. } else {
  246. return p_size;
  247. }
  248. }
  249. _FORCE_INLINE_ double _get_extra_advance(RID p_font_rid, int p_font_size) const;
  250. _FORCE_INLINE_ Variant::Type _get_tag_type(int64_t p_tag) const;
  251. _FORCE_INLINE_ bool _get_tag_hidden(int64_t p_tag) const;
  252. // Shaped text cache data.
  253. struct TrimData {
  254. int trim_pos = -1;
  255. int ellipsis_pos = -1;
  256. Vector<Glyph> ellipsis_glyph_buf;
  257. };
  258. struct ShapedTextDataAdvanced {
  259. Mutex mutex;
  260. /* Source data */
  261. RID parent; // Substring parent ShapedTextData.
  262. int start = 0; // Substring start offset in the parent string.
  263. int end = 0; // Substring end offset in the parent string.
  264. String text;
  265. String custom_punct;
  266. TextServer::Direction direction = DIRECTION_LTR; // Desired text direction.
  267. TextServer::Orientation orientation = ORIENTATION_HORIZONTAL;
  268. struct Span {
  269. int start = -1;
  270. int end = -1;
  271. Array fonts;
  272. int font_size = 0;
  273. Variant embedded_key;
  274. String language;
  275. Dictionary features;
  276. Variant meta;
  277. };
  278. Vector<Span> spans;
  279. struct EmbeddedObject {
  280. int pos = 0;
  281. InlineAlignment inline_align = INLINE_ALIGNMENT_CENTER;
  282. Rect2 rect;
  283. };
  284. HashMap<Variant, EmbeddedObject, VariantHasher, VariantComparator> objects;
  285. /* Shaped data */
  286. TextServer::Direction para_direction = DIRECTION_LTR; // Detected text direction.
  287. bool valid = false; // String is shaped.
  288. bool line_breaks_valid = false; // Line and word break flags are populated (and virtual zero width spaces inserted).
  289. bool justification_ops_valid = false; // Virtual elongation glyphs are added to the string.
  290. bool sort_valid = false;
  291. bool text_trimmed = false;
  292. bool preserve_invalid = true; // Draw hex code box instead of missing characters.
  293. bool preserve_control = false; // Draw control characters.
  294. double ascent = 0.0; // Ascent for horizontal layout, 1/2 of width for vertical.
  295. double descent = 0.0; // Descent for horizontal layout, 1/2 of width for vertical.
  296. double width = 0.0; // Width for horizontal layout, height for vertical.
  297. double width_trimmed = 0.0;
  298. int extra_spacing[4] = { 0, 0, 0, 0 };
  299. double upos = 0.0;
  300. double uthk = 0.0;
  301. TrimData overrun_trim_data;
  302. bool fit_width_minimum_reached = false;
  303. Vector<Glyph> glyphs;
  304. Vector<Glyph> glyphs_logical;
  305. /* Intermediate data */
  306. Char16String utf16;
  307. Vector<UBiDi *> bidi_iter;
  308. Vector<Vector2i> bidi_override;
  309. ScriptIterator *script_iter = nullptr;
  310. hb_buffer_t *hb_buffer = nullptr;
  311. HashMap<int, bool> jstops;
  312. HashMap<int, bool> breaks;
  313. bool break_ops_valid = false;
  314. bool js_ops_valid = false;
  315. ~ShapedTextDataAdvanced() {
  316. for (int i = 0; i < bidi_iter.size(); i++) {
  317. ubidi_close(bidi_iter[i]);
  318. }
  319. if (script_iter) {
  320. memdelete(script_iter);
  321. }
  322. if (hb_buffer) {
  323. hb_buffer_destroy(hb_buffer);
  324. }
  325. }
  326. };
  327. // Common data.
  328. double oversampling = 1.0;
  329. mutable RID_PtrOwner<FontAdvanced> font_owner;
  330. mutable RID_PtrOwner<ShapedTextDataAdvanced> shaped_owner;
  331. void _realign(ShapedTextDataAdvanced *p_sd) const;
  332. int64_t _convert_pos(const String &p_utf32, const Char16String &p_utf16, int64_t p_pos) const;
  333. int64_t _convert_pos(const ShapedTextDataAdvanced *p_sd, int64_t p_pos) const;
  334. int64_t _convert_pos_inv(const ShapedTextDataAdvanced *p_sd, int64_t p_pos) const;
  335. bool _shape_substr(ShapedTextDataAdvanced *p_new_sd, const ShapedTextDataAdvanced *p_sd, int64_t p_start, int64_t p_length) const;
  336. void _shape_run(ShapedTextDataAdvanced *p_sd, int64_t p_start, int64_t p_end, hb_script_t p_script, hb_direction_t p_direction, Array p_fonts, int64_t p_span, int64_t p_fb_index);
  337. 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);
  338. _FORCE_INLINE_ void _add_featuers(const Dictionary &p_source, Vector<hb_feature_t> &r_ftrs);
  339. // HarfBuzz bitmap font interface.
  340. static hb_font_funcs_t *funcs;
  341. struct bmp_font_t {
  342. TextServerAdvanced::FontForSizeAdvanced *face = nullptr;
  343. bool unref = false; /* Whether to destroy bm_face when done. */
  344. };
  345. static bmp_font_t *_bmp_font_create(TextServerAdvanced::FontForSizeAdvanced *p_face, bool p_unref);
  346. static void _bmp_font_destroy(void *p_data);
  347. 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);
  348. 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);
  349. 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);
  350. 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);
  351. 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);
  352. 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);
  353. 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);
  354. static void _bmp_create_font_funcs();
  355. static void _bmp_free_font_funcs();
  356. static void _bmp_font_set_funcs(hb_font_t *p_font, TextServerAdvanced::FontForSizeAdvanced *p_face, bool p_unref);
  357. static hb_font_t *_bmp_font_create(TextServerAdvanced::FontForSizeAdvanced *p_face, hb_destroy_func_t p_destroy);
  358. hb_font_t *_font_get_hb_handle(const RID &p_font, int64_t p_font_size) const;
  359. struct GlyphCompare { // For line breaking reordering.
  360. _FORCE_INLINE_ bool operator()(const Glyph &l, const Glyph &r) const {
  361. if (l.start == r.start) {
  362. if (l.count == r.count) {
  363. if ((l.flags & TextServer::GRAPHEME_IS_VIRTUAL) == TextServer::GRAPHEME_IS_VIRTUAL) {
  364. return false;
  365. } else {
  366. return true;
  367. }
  368. }
  369. return l.count > r.count; // Sort first glyph with count & flags, order of the rest are irrelevant.
  370. } else {
  371. return l.start < r.start;
  372. }
  373. }
  374. };
  375. protected:
  376. static void _bind_methods(){};
  377. void full_copy(ShapedTextDataAdvanced *p_shaped);
  378. void invalidate(ShapedTextDataAdvanced *p_shaped, bool p_text = false);
  379. public:
  380. virtual bool has_feature(Feature p_feature) const override;
  381. virtual String get_name() const override;
  382. virtual int64_t get_features() const override;
  383. virtual void free_rid(const RID &p_rid) override;
  384. virtual bool has(const RID &p_rid) override;
  385. virtual bool load_support_data(const String &p_filename) override;
  386. virtual String get_support_data_filename() const override;
  387. virtual String get_support_data_info() const override;
  388. virtual bool save_support_data(const String &p_filename) const override;
  389. virtual bool is_locale_right_to_left(const String &p_locale) const override;
  390. virtual int64_t name_to_tag(const String &p_name) const override;
  391. virtual String tag_to_name(int64_t p_tag) const override;
  392. /* Font interface */
  393. virtual RID create_font() override;
  394. virtual void font_set_data(const RID &p_font_rid, const PackedByteArray &p_data) override;
  395. virtual void font_set_data_ptr(const RID &p_font_rid, const uint8_t *p_data_ptr, int64_t p_data_size) override;
  396. virtual void font_set_face_index(const RID &p_font_rid, int64_t p_index) override;
  397. virtual int64_t font_get_face_index(const RID &p_font_rid) const override;
  398. virtual int64_t font_get_face_count(const RID &p_font_rid) const override;
  399. virtual void font_set_style(const RID &p_font_rid, BitField<FontStyle> p_style) override;
  400. virtual BitField<FontStyle> font_get_style(const RID &p_font_rid) const override;
  401. virtual void font_set_style_name(const RID &p_font_rid, const String &p_name) override;
  402. virtual String font_get_style_name(const RID &p_font_rid) const override;
  403. virtual void font_set_name(const RID &p_font_rid, const String &p_name) override;
  404. virtual String font_get_name(const RID &p_font_rid) const override;
  405. virtual void font_set_antialiasing(RID p_font_rid, TextServer::FontAntialiasing p_antialiasing) override;
  406. virtual TextServer::FontAntialiasing font_get_antialiasing(RID p_font_rid) const override;
  407. virtual void font_set_generate_mipmaps(const RID &p_font_rid, bool p_generate_mipmaps) override;
  408. virtual bool font_get_generate_mipmaps(const RID &p_font_rid) const override;
  409. virtual void font_set_multichannel_signed_distance_field(const RID &p_font_rid, bool p_msdf) override;
  410. virtual bool font_is_multichannel_signed_distance_field(const RID &p_font_rid) const override;
  411. virtual void font_set_msdf_pixel_range(const RID &p_font_rid, int64_t p_msdf_pixel_range) override;
  412. virtual int64_t font_get_msdf_pixel_range(const RID &p_font_rid) const override;
  413. virtual void font_set_msdf_size(const RID &p_font_rid, int64_t p_msdf_size) override;
  414. virtual int64_t font_get_msdf_size(const RID &p_font_rid) const override;
  415. virtual void font_set_fixed_size(const RID &p_font_rid, int64_t p_fixed_size) override;
  416. virtual int64_t font_get_fixed_size(const RID &p_font_rid) const override;
  417. virtual void font_set_force_autohinter(const RID &p_font_rid, bool p_force_autohinter) override;
  418. virtual bool font_is_force_autohinter(const RID &p_font_rid) const override;
  419. virtual void font_set_subpixel_positioning(const RID &p_font_rid, SubpixelPositioning p_subpixel) override;
  420. virtual SubpixelPositioning font_get_subpixel_positioning(const RID &p_font_rid) const override;
  421. virtual void font_set_embolden(const RID &p_font_rid, double p_strength) override;
  422. virtual double font_get_embolden(const RID &p_font_rid) const override;
  423. virtual void font_set_transform(const RID &p_font_rid, const Transform2D &p_transform) override;
  424. virtual Transform2D font_get_transform(const RID &p_font_rid) const override;
  425. virtual void font_set_variation_coordinates(const RID &p_font_rid, const Dictionary &p_variation_coordinates) override;
  426. virtual Dictionary font_get_variation_coordinates(const RID &p_font_rid) const override;
  427. virtual void font_set_hinting(const RID &p_font_rid, TextServer::Hinting p_hinting) override;
  428. virtual TextServer::Hinting font_get_hinting(const RID &p_font_rid) const override;
  429. virtual void font_set_oversampling(const RID &p_font_rid, double p_oversampling) override;
  430. virtual double font_get_oversampling(const RID &p_font_rid) const override;
  431. virtual TypedArray<Vector2i> font_get_size_cache_list(const RID &p_font_rid) const override;
  432. virtual void font_clear_size_cache(const RID &p_font_rid) override;
  433. virtual void font_remove_size_cache(const RID &p_font_rid, const Vector2i &p_size) override;
  434. virtual void font_set_ascent(const RID &p_font_rid, int64_t p_size, double p_ascent) override;
  435. virtual double font_get_ascent(const RID &p_font_rid, int64_t p_size) const override;
  436. virtual void font_set_descent(const RID &p_font_rid, int64_t p_size, double p_descent) override;
  437. virtual double font_get_descent(const RID &p_font_rid, int64_t p_size) const override;
  438. virtual void font_set_underline_position(const RID &p_font_rid, int64_t p_size, double p_underline_position) override;
  439. virtual double font_get_underline_position(const RID &p_font_rid, int64_t p_size) const override;
  440. virtual void font_set_underline_thickness(const RID &p_font_rid, int64_t p_size, double p_underline_thickness) override;
  441. virtual double font_get_underline_thickness(const RID &p_font_rid, int64_t p_size) const override;
  442. virtual void font_set_scale(const RID &p_font_rid, int64_t p_size, double p_scale) override;
  443. virtual double font_get_scale(const RID &p_font_rid, int64_t p_size) const override;
  444. virtual int64_t font_get_texture_count(const RID &p_font_rid, const Vector2i &p_size) const override;
  445. virtual void font_clear_textures(const RID &p_font_rid, const Vector2i &p_size) override;
  446. virtual void font_remove_texture(const RID &p_font_rid, const Vector2i &p_size, int64_t p_texture_index) override;
  447. virtual void font_set_texture_image(const RID &p_font_rid, const Vector2i &p_size, int64_t p_texture_index, const Ref<Image> &p_image) override;
  448. virtual Ref<Image> font_get_texture_image(const RID &p_font_rid, const Vector2i &p_size, int64_t p_texture_index) const override;
  449. virtual void font_set_texture_offsets(const RID &p_font_rid, const Vector2i &p_size, int64_t p_texture_index, const PackedInt32Array &p_offset) override;
  450. virtual PackedInt32Array font_get_texture_offsets(const RID &p_font_rid, const Vector2i &p_size, int64_t p_texture_index) const override;
  451. virtual PackedInt32Array font_get_glyph_list(const RID &p_font_rid, const Vector2i &p_size) const override;
  452. virtual void font_clear_glyphs(const RID &p_font_rid, const Vector2i &p_size) override;
  453. virtual void font_remove_glyph(const RID &p_font_rid, const Vector2i &p_size, int64_t p_glyph) override;
  454. virtual Vector2 font_get_glyph_advance(const RID &p_font_rid, int64_t p_size, int64_t p_glyph) const override;
  455. virtual void font_set_glyph_advance(const RID &p_font_rid, int64_t p_size, int64_t p_glyph, const Vector2 &p_advance) override;
  456. virtual Vector2 font_get_glyph_offset(const RID &p_font_rid, const Vector2i &p_size, int64_t p_glyph) const override;
  457. virtual void font_set_glyph_offset(const RID &p_font_rid, const Vector2i &p_size, int64_t p_glyph, const Vector2 &p_offset) override;
  458. virtual Vector2 font_get_glyph_size(const RID &p_font_rid, const Vector2i &p_size, int64_t p_glyph) const override;
  459. virtual void font_set_glyph_size(const RID &p_font_rid, const Vector2i &p_size, int64_t p_glyph, const Vector2 &p_gl_size) override;
  460. virtual Rect2 font_get_glyph_uv_rect(const RID &p_font_rid, const Vector2i &p_size, int64_t p_glyph) const override;
  461. virtual void font_set_glyph_uv_rect(const RID &p_font_rid, const Vector2i &p_size, int64_t p_glyph, const Rect2 &p_uv_rect) override;
  462. virtual int64_t font_get_glyph_texture_idx(const RID &p_font_rid, const Vector2i &p_size, int64_t p_glyph) const override;
  463. virtual void font_set_glyph_texture_idx(const RID &p_font_rid, const Vector2i &p_size, int64_t p_glyph, int64_t p_texture_idx) override;
  464. virtual RID font_get_glyph_texture_rid(const RID &p_font_rid, const Vector2i &p_size, int64_t p_glyph) const override;
  465. virtual Size2 font_get_glyph_texture_size(const RID &p_font_rid, const Vector2i &p_size, int64_t p_glyph) const override;
  466. virtual Dictionary font_get_glyph_contours(const RID &p_font, int64_t p_size, int64_t p_index) const override;
  467. virtual TypedArray<Vector2i> font_get_kerning_list(const RID &p_font_rid, int64_t p_size) const override;
  468. virtual void font_clear_kerning_map(const RID &p_font_rid, int64_t p_size) override;
  469. virtual void font_remove_kerning(const RID &p_font_rid, int64_t p_size, const Vector2i &p_glyph_pair) override;
  470. virtual void font_set_kerning(const RID &p_font_rid, int64_t p_size, const Vector2i &p_glyph_pair, const Vector2 &p_kerning) override;
  471. virtual Vector2 font_get_kerning(const RID &p_font_rid, int64_t p_size, const Vector2i &p_glyph_pair) const override;
  472. virtual int64_t font_get_glyph_index(const RID &p_font_rid, int64_t p_size, int64_t p_char, int64_t p_variation_selector = 0) const override;
  473. virtual bool font_has_char(const RID &p_font_rid, int64_t p_char) const override;
  474. virtual String font_get_supported_chars(const RID &p_font_rid) const override;
  475. virtual void font_render_range(const RID &p_font, const Vector2i &p_size, int64_t p_start, int64_t p_end) override;
  476. virtual void font_render_glyph(const RID &p_font_rid, const Vector2i &p_size, int64_t p_index) override;
  477. virtual void font_draw_glyph(const RID &p_font, const RID &p_canvas, int64_t p_size, const Vector2 &p_pos, int64_t p_index, const Color &p_color = Color(1, 1, 1)) const override;
  478. virtual void font_draw_glyph_outline(const RID &p_font, const RID &p_canvas, int64_t p_size, int64_t p_outline_size, const Vector2 &p_pos, int64_t p_index, const Color &p_color = Color(1, 1, 1)) const override;
  479. virtual bool font_is_language_supported(const RID &p_font_rid, const String &p_language) const override;
  480. virtual void font_set_language_support_override(const RID &p_font_rid, const String &p_language, bool p_supported) override;
  481. virtual bool font_get_language_support_override(const RID &p_font_rid, const String &p_language) override;
  482. virtual void font_remove_language_support_override(const RID &p_font_rid, const String &p_language) override;
  483. virtual PackedStringArray font_get_language_support_overrides(const RID &p_font_rid) override;
  484. virtual bool font_is_script_supported(const RID &p_font_rid, const String &p_script) const override;
  485. virtual void font_set_script_support_override(const RID &p_font_rid, const String &p_script, bool p_supported) override;
  486. virtual bool font_get_script_support_override(const RID &p_font_rid, const String &p_script) override;
  487. virtual void font_remove_script_support_override(const RID &p_font_rid, const String &p_script) override;
  488. virtual PackedStringArray font_get_script_support_overrides(const RID &p_font_rid) override;
  489. virtual void font_set_opentype_feature_overrides(const RID &p_font_rid, const Dictionary &p_overrides) override;
  490. virtual Dictionary font_get_opentype_feature_overrides(const RID &p_font_rid) const override;
  491. virtual Dictionary font_supported_feature_list(const RID &p_font_rid) const override;
  492. virtual Dictionary font_supported_variation_list(const RID &p_font_rid) const override;
  493. virtual double font_get_global_oversampling() const override;
  494. virtual void font_set_global_oversampling(double p_oversampling) override;
  495. /* Shaped text buffer interface */
  496. virtual RID create_shaped_text(Direction p_direction = DIRECTION_AUTO, Orientation p_orientation = ORIENTATION_HORIZONTAL) override;
  497. virtual void shaped_text_clear(const RID &p_shaped) override;
  498. virtual void shaped_text_set_direction(const RID &p_shaped, Direction p_direction = DIRECTION_AUTO) override;
  499. virtual Direction shaped_text_get_direction(const RID &p_shaped) const override;
  500. virtual Direction shaped_text_get_inferred_direction(const RID &p_shaped) const override;
  501. virtual void shaped_text_set_bidi_override(const RID &p_shaped, const Array &p_override) override;
  502. virtual void shaped_text_set_custom_punctuation(const RID &p_shaped, const String &p_punct) override;
  503. virtual String shaped_text_get_custom_punctuation(const RID &p_shaped) const override;
  504. virtual void shaped_text_set_orientation(const RID &p_shaped, Orientation p_orientation = ORIENTATION_HORIZONTAL) override;
  505. virtual Orientation shaped_text_get_orientation(const RID &p_shaped) const override;
  506. virtual void shaped_text_set_preserve_invalid(const RID &p_shaped, bool p_enabled) override;
  507. virtual bool shaped_text_get_preserve_invalid(const RID &p_shaped) const override;
  508. virtual void shaped_text_set_preserve_control(const RID &p_shaped, bool p_enabled) override;
  509. virtual bool shaped_text_get_preserve_control(const RID &p_shaped) const override;
  510. virtual void shaped_text_set_spacing(const RID &p_shaped, SpacingType p_spacing, int64_t p_value) override;
  511. virtual int64_t shaped_text_get_spacing(const RID &p_shaped, SpacingType p_spacing) const override;
  512. virtual bool shaped_text_add_string(const RID &p_shaped, const String &p_text, const Array &p_fonts, int64_t p_size, const Dictionary &p_opentype_features = Dictionary(), const String &p_language = "", const Variant &p_meta = Variant()) override;
  513. virtual bool shaped_text_add_object(const RID &p_shaped, const Variant &p_key, const Size2 &p_size, InlineAlignment p_inline_align = INLINE_ALIGNMENT_CENTER, int64_t p_length = 1) override;
  514. virtual bool shaped_text_resize_object(const RID &p_shaped, const Variant &p_key, const Size2 &p_size, InlineAlignment p_inline_align = INLINE_ALIGNMENT_CENTER) override;
  515. virtual int64_t shaped_get_span_count(const RID &p_shaped) const override;
  516. virtual Variant shaped_get_span_meta(const RID &p_shaped, int64_t p_index) const override;
  517. virtual void shaped_set_span_update_font(const RID &p_shaped, int64_t p_index, const Array &p_fonts, int64_t p_size, const Dictionary &p_opentype_features = Dictionary()) override;
  518. virtual RID shaped_text_substr(const RID &p_shaped, int64_t p_start, int64_t p_length) const override;
  519. virtual RID shaped_text_get_parent(const RID &p_shaped) const override;
  520. virtual double shaped_text_fit_to_width(const RID &p_shaped, double p_width, BitField<TextServer::JustificationFlag> p_jst_flags = JUSTIFICATION_WORD_BOUND | JUSTIFICATION_KASHIDA) override;
  521. virtual double shaped_text_tab_align(const RID &p_shaped, const PackedFloat32Array &p_tab_stops) override;
  522. virtual bool shaped_text_shape(const RID &p_shaped) override;
  523. virtual bool shaped_text_update_breaks(const RID &p_shaped) override;
  524. virtual bool shaped_text_update_justification_ops(const RID &p_shaped) override;
  525. virtual int64_t shaped_text_get_trim_pos(const RID &p_shaped) const override;
  526. virtual int64_t shaped_text_get_ellipsis_pos(const RID &p_shaped) const override;
  527. virtual const Glyph *shaped_text_get_ellipsis_glyphs(const RID &p_shaped) const override;
  528. virtual int64_t shaped_text_get_ellipsis_glyph_count(const RID &p_shaped) const override;
  529. virtual void shaped_text_overrun_trim_to_width(const RID &p_shaped, double p_width, BitField<TextServer::TextOverrunFlag> p_trim_flags) override;
  530. virtual bool shaped_text_is_ready(const RID &p_shaped) const override;
  531. virtual const Glyph *shaped_text_get_glyphs(const RID &p_shaped) const override;
  532. virtual const Glyph *shaped_text_sort_logical(const RID &p_shaped) override;
  533. virtual int64_t shaped_text_get_glyph_count(const RID &p_shaped) const override;
  534. virtual Vector2i shaped_text_get_range(const RID &p_shaped) const override;
  535. virtual Array shaped_text_get_objects(const RID &p_shaped) const override;
  536. virtual Rect2 shaped_text_get_object_rect(const RID &p_shaped, const Variant &p_key) const override;
  537. virtual Size2 shaped_text_get_size(const RID &p_shaped) const override;
  538. virtual double shaped_text_get_ascent(const RID &p_shaped) const override;
  539. virtual double shaped_text_get_descent(const RID &p_shaped) const override;
  540. virtual double shaped_text_get_width(const RID &p_shaped) const override;
  541. virtual double shaped_text_get_underline_position(const RID &p_shaped) const override;
  542. virtual double shaped_text_get_underline_thickness(const RID &p_shaped) const override;
  543. virtual String format_number(const String &p_string, const String &p_language = "") const override;
  544. virtual String parse_number(const String &p_string, const String &p_language = "") const override;
  545. virtual String percent_sign(const String &p_language = "") const override;
  546. virtual PackedInt32Array string_get_word_breaks(const String &p_string, const String &p_language = "") const override;
  547. virtual int is_confusable(const String &p_string, const PackedStringArray &p_dict) const override;
  548. virtual bool spoof_check(const String &p_string) const override;
  549. virtual String strip_diacritics(const String &p_string) const override;
  550. virtual bool is_valid_identifier(const String &p_string) const override;
  551. virtual String string_to_upper(const String &p_string, const String &p_language = "") const override;
  552. virtual String string_to_lower(const String &p_string, const String &p_language = "") const override;
  553. TextServerAdvanced();
  554. ~TextServerAdvanced();
  555. };
  556. #endif // TEXT_SERVER_ADV_H