Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
godotengine
GitHub Repository: godotengine/godot
Path: blob/master/modules/text_server_adv/text_server_adv.h
21207 views
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
31
#pragma once
32
33
/*************************************************************************/
34
/* ICU/HarfBuzz/Graphite backed Text Server implementation with BiDi, */
35
/* shaping and advanced font features support. */
36
/*************************************************************************/
37
38
#include "script_iterator.h"
39
40
#ifdef GDEXTENSION
41
// Headers for building as GDExtension plug-in.
42
43
#include <godot_cpp/godot.hpp>
44
45
#include <godot_cpp/core/class_db.hpp>
46
#include <godot_cpp/core/ext_wrappers.gen.inc>
47
#include <godot_cpp/core/mutex_lock.hpp>
48
49
#include <godot_cpp/variant/array.hpp>
50
#include <godot_cpp/variant/dictionary.hpp>
51
#include <godot_cpp/variant/packed_int32_array.hpp>
52
#include <godot_cpp/variant/packed_string_array.hpp>
53
#include <godot_cpp/variant/packed_vector2_array.hpp>
54
#include <godot_cpp/variant/rect2.hpp>
55
#include <godot_cpp/variant/rid.hpp>
56
#include <godot_cpp/variant/string.hpp>
57
#include <godot_cpp/variant/typed_array.hpp>
58
#include <godot_cpp/variant/vector2.hpp>
59
#include <godot_cpp/variant/vector2i.hpp>
60
61
#include <godot_cpp/classes/text_server.hpp>
62
#include <godot_cpp/classes/text_server_extension.hpp>
63
#include <godot_cpp/classes/text_server_manager.hpp>
64
65
#include <godot_cpp/classes/caret_info.hpp>
66
#include <godot_cpp/classes/global_constants_binds.hpp>
67
#include <godot_cpp/classes/glyph.hpp>
68
#include <godot_cpp/classes/image.hpp>
69
#include <godot_cpp/classes/image_texture.hpp>
70
#include <godot_cpp/classes/ref.hpp>
71
#include <godot_cpp/classes/worker_thread_pool.hpp>
72
73
#include <godot_cpp/templates/hash_map.hpp>
74
#include <godot_cpp/templates/hash_set.hpp>
75
#include <godot_cpp/templates/rid_owner.hpp>
76
#include <godot_cpp/templates/safe_refcount.hpp>
77
#include <godot_cpp/templates/vector.hpp>
78
79
using namespace godot;
80
81
#elif defined(GODOT_MODULE)
82
// Headers for building as built-in module.
83
84
#include "core/extension/ext_wrappers.gen.h"
85
#include "core/templates/hash_map.h"
86
#include "core/templates/rid_owner.h"
87
#include "core/templates/safe_refcount.h"
88
#include "scene/resources/image_texture.h"
89
#include "servers/text/text_server_extension.h"
90
91
#include "modules/modules_enabled.gen.h" // For freetype, msdfgen, svg.
92
93
#endif
94
95
// Thirdparty headers.
96
97
GODOT_GCC_WARNING_PUSH_AND_IGNORE("-Wshadow")
98
#if defined(__EMSCRIPTEN__) || (defined(__MINGW32__) && __clang_major__ >= 21)
99
GODOT_CLANG_WARNING_PUSH_AND_IGNORE("-Wunnecessary-virtual-specifier")
100
#endif
101
102
#include <unicode/ubidi.h>
103
#include <unicode/ubrk.h>
104
#include <unicode/uchar.h>
105
#include <unicode/uclean.h>
106
#include <unicode/udata.h>
107
#include <unicode/uiter.h>
108
#include <unicode/uloc.h>
109
#include <unicode/unorm2.h>
110
#include <unicode/uscript.h>
111
#include <unicode/uspoof.h>
112
#include <unicode/ustring.h>
113
#include <unicode/utypes.h>
114
115
GODOT_GCC_WARNING_POP
116
#if defined(__EMSCRIPTEN__) || (defined(__MINGW32__) && __clang_major__ >= 21)
117
GODOT_CLANG_WARNING_POP
118
#endif
119
120
#ifdef MODULE_FREETYPE_ENABLED
121
#include <ft2build.h>
122
#include FT_FREETYPE_H
123
#include FT_TRUETYPE_TABLES_H
124
#include FT_STROKER_H
125
#include FT_ADVANCES_H
126
#include FT_MULTIPLE_MASTERS_H
127
#include FT_BBOX_H
128
#include FT_SIZES_H
129
#include FT_MODULE_H
130
#include FT_CONFIG_OPTIONS_H
131
#if !defined(FT_CONFIG_OPTION_USE_BROTLI) && !defined(_MSC_VER)
132
#warning FreeType is configured without Brotli support, built-in fonts will not be available.
133
#endif
134
#include <hb-ft.h>
135
#include <hb-ot.h>
136
#endif
137
138
#include <hb-icu.h>
139
#include <hb.h>
140
141
/*************************************************************************/
142
143
class TextServerAdvanced : public TextServerExtension {
144
GDCLASS(TextServerAdvanced, TextServerExtension);
145
_THREAD_SAFE_CLASS_
146
147
struct FeatureInfo {
148
StringName name;
149
Variant::Type vtype = Variant::INT;
150
bool hidden = false;
151
};
152
153
HashMap<StringName, int32_t> feature_sets;
154
HashMap<int32_t, FeatureInfo> feature_sets_inv;
155
156
enum LineBreakStrictness {
157
LB_AUTO,
158
LB_LOOSE,
159
LB_NORMAL,
160
LB_STRICT,
161
};
162
163
SafeNumeric<TextServer::FontLCDSubpixelLayout> lcd_subpixel_layout{ TextServer::FontLCDSubpixelLayout::FONT_LCD_SUBPIXEL_LAYOUT_NONE };
164
LineBreakStrictness lb_strictness = LB_AUTO;
165
void _update_settings();
166
167
void _insert_feature_sets();
168
_FORCE_INLINE_ void _insert_feature(const StringName &p_name, int32_t p_tag, Variant::Type p_vtype = Variant::INT, bool p_hidden = false);
169
170
// ICU support data.
171
172
static bool icu_data_loaded;
173
static PackedByteArray icu_data;
174
mutable USet *allowed = nullptr;
175
mutable USpoofChecker *sc_spoof = nullptr;
176
mutable USpoofChecker *sc_conf = nullptr;
177
178
mutable HashMap<String, UBreakIterator *> line_break_iterators_per_language;
179
180
UBreakIterator *_create_line_break_iterator_for_locale(const String &p_language, UErrorCode *r_err) const;
181
182
// Font cache data.
183
184
#ifdef MODULE_FREETYPE_ENABLED
185
mutable FT_Library ft_library = nullptr;
186
#endif
187
188
const int rect_range = 1;
189
190
struct FontTexturePosition {
191
int32_t index = -1;
192
int32_t x = 0;
193
int32_t y = 0;
194
195
FontTexturePosition() {}
196
FontTexturePosition(int32_t p_id, int32_t p_x, int32_t p_y) :
197
index(p_id), x(p_x), y(p_y) {}
198
};
199
200
struct Shelf {
201
int32_t x = 0;
202
int32_t y = 0;
203
int32_t w = 0;
204
int32_t h = 0;
205
206
FontTexturePosition alloc_shelf(int32_t p_id, int32_t p_w, int32_t p_h) {
207
if (p_w > w || p_h > h) {
208
return FontTexturePosition(-1, 0, 0);
209
}
210
int32_t xx = x;
211
x += p_w;
212
w -= p_w;
213
return FontTexturePosition(p_id, xx, y);
214
}
215
216
Shelf() {}
217
Shelf(int32_t p_x, int32_t p_y, int32_t p_w, int32_t p_h) :
218
x(p_x), y(p_y), w(p_w), h(p_h) {}
219
};
220
221
struct ShelfPackTexture {
222
int32_t texture_w = 1024;
223
int32_t texture_h = 1024;
224
225
Ref<Image> image;
226
Ref<ImageTexture> texture;
227
bool dirty = true;
228
229
List<Shelf> shelves;
230
231
FontTexturePosition pack_rect(int32_t p_id, int32_t p_h, int32_t p_w) {
232
int32_t y = 0;
233
int32_t waste = 0;
234
Shelf *best_shelf = nullptr;
235
int32_t best_waste = std::numeric_limits<std::int32_t>::max();
236
237
for (Shelf &E : shelves) {
238
y += E.h;
239
if (p_w > E.w) {
240
continue;
241
}
242
if (p_h == E.h) {
243
return E.alloc_shelf(p_id, p_w, p_h);
244
}
245
if (p_h > E.h) {
246
continue;
247
}
248
if (p_h < E.h) {
249
waste = (E.h - p_h) * p_w;
250
if (waste < best_waste) {
251
best_waste = waste;
252
best_shelf = &E;
253
}
254
}
255
}
256
if (best_shelf) {
257
return best_shelf->alloc_shelf(p_id, p_w, p_h);
258
}
259
if (p_h <= (texture_h - y) && p_w <= texture_w) {
260
List<Shelf>::Element *E = shelves.push_back(Shelf(0, y, texture_w, p_h));
261
return E->get().alloc_shelf(p_id, p_w, p_h);
262
}
263
return FontTexturePosition(-1, 0, 0);
264
}
265
266
ShelfPackTexture() {}
267
ShelfPackTexture(int32_t p_w, int32_t p_h) :
268
texture_w(p_w), texture_h(p_h) {}
269
};
270
271
struct FontGlyph {
272
bool found = false;
273
int texture_idx = -1;
274
Rect2 rect;
275
Rect2 uv_rect;
276
Vector2 advance;
277
bool from_svg = false;
278
};
279
280
struct FontAdvanced;
281
struct FontForSizeAdvanced {
282
double ascent = 0.0;
283
double descent = 0.0;
284
double underline_position = 0.0;
285
double underline_thickness = 0.0;
286
double scale = 1.0;
287
288
FontAdvanced *owner = nullptr;
289
uint32_t viewport_oversampling = 0;
290
291
Vector2i size;
292
293
Vector<ShelfPackTexture> textures;
294
HashMap<int64_t, int64_t> inv_glyph_map;
295
HashMap<int32_t, FontGlyph> glyph_map;
296
HashMap<Vector2i, Vector2> kerning_map;
297
hb_font_t *hb_handle = nullptr;
298
299
#ifdef MODULE_FREETYPE_ENABLED
300
FT_Size fsize = nullptr;
301
#endif
302
303
~FontForSizeAdvanced() {
304
if (hb_handle != nullptr) {
305
hb_font_destroy(hb_handle);
306
}
307
#ifdef MODULE_FREETYPE_ENABLED
308
if (fsize != nullptr) {
309
FT_Done_Size(fsize);
310
}
311
#endif
312
}
313
};
314
315
struct OversamplingLevel {
316
HashSet<FontForSizeAdvanced *> fonts;
317
int32_t refcount = 1;
318
};
319
320
mutable HashMap<uint32_t, OversamplingLevel> oversampling_levels;
321
322
struct FontAdvancedLinkedVariation {
323
RID base_font;
324
int extra_spacing[4] = { 0, 0, 0, 0 };
325
double baseline_offset = 0.0;
326
};
327
328
struct FontAdvanced {
329
Mutex mutex;
330
331
TextServer::FontAntialiasing antialiasing = TextServer::FONT_ANTIALIASING_GRAY;
332
bool disable_embedded_bitmaps = true;
333
bool mipmaps = false;
334
bool msdf = false;
335
int msdf_range = 14;
336
FixedSizeScaleMode fixed_size_scale_mode = FIXED_SIZE_SCALE_DISABLE;
337
int msdf_source_size = 48;
338
int fixed_size = 0;
339
bool allow_system_fallback = true;
340
bool force_autohinter = false;
341
bool modulate_color_glyphs = false;
342
TextServer::Hinting hinting = TextServer::HINTING_LIGHT;
343
TextServer::SubpixelPositioning subpixel_positioning = TextServer::SUBPIXEL_POSITIONING_AUTO;
344
bool keep_rounding_remainders = true;
345
Dictionary variation_coordinates;
346
double oversampling_override = 0.0;
347
double embolden = 0.0;
348
Transform2D transform;
349
350
BitField<TextServer::FontStyle> style_flags = 0;
351
String font_name;
352
String style_name;
353
int weight = 400;
354
int stretch = 100;
355
int extra_spacing[4] = { 0, 0, 0, 0 };
356
double baseline_offset = 0.0;
357
358
HashMap<Vector2i, FontForSizeAdvanced *> cache;
359
360
bool face_init = false;
361
HashSet<uint32_t> supported_scripts;
362
Dictionary supported_features;
363
Dictionary supported_varaitions;
364
Dictionary feature_overrides;
365
366
// Language/script support override.
367
HashMap<String, bool> language_support_overrides;
368
HashMap<String, bool> script_support_overrides;
369
370
PackedByteArray data;
371
const uint8_t *data_ptr = nullptr;
372
size_t data_size;
373
int face_index = 0;
374
375
#ifdef MODULE_FREETYPE_ENABLED
376
FT_Face face = nullptr;
377
FT_StreamRec stream;
378
#endif
379
380
~FontAdvanced() {
381
for (const KeyValue<Vector2i, FontForSizeAdvanced *> &E : cache) {
382
memdelete(E.value);
383
}
384
cache.clear();
385
#ifdef MODULE_FREETYPE_ENABLED
386
if (face != nullptr) {
387
FT_Done_Face(face);
388
}
389
#endif
390
}
391
};
392
393
_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;
394
#ifdef MODULE_MSDFGEN_ENABLED
395
_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;
396
#endif
397
#ifdef MODULE_FREETYPE_ENABLED
398
_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;
399
#endif
400
bool _ensure_glyph(FontAdvanced *p_font_data, const Vector2i &p_size, int32_t p_glyph, FontGlyph &r_glyph, uint32_t p_oversampling = 0) const;
401
bool _ensure_cache_for_size(FontAdvanced *p_font_data, const Vector2i &p_size, FontForSizeAdvanced *&r_cache_for_size, bool p_silent = false, uint32_t p_oversampling = 0) const;
402
_FORCE_INLINE_ bool _font_validate(const RID &p_font_rid) const;
403
_FORCE_INLINE_ void _font_clear_cache(FontAdvanced *p_font_data);
404
static void _generateMTSDF_threaded(void *p_td, uint32_t p_y);
405
406
_FORCE_INLINE_ Vector2i _get_size(const FontAdvanced *p_font_data, int p_size) const {
407
if (p_font_data->msdf) {
408
return Vector2i(p_font_data->msdf_source_size * 64, 0);
409
} else if (p_font_data->fixed_size > 0) {
410
return Vector2i(p_font_data->fixed_size * 64, 0);
411
} else {
412
return Vector2i(p_size * 64, 0);
413
}
414
}
415
416
_FORCE_INLINE_ Vector2i _get_size_outline(const FontAdvanced *p_font_data, const Vector2i &p_size) const {
417
if (p_font_data->msdf) {
418
return Vector2i(p_font_data->msdf_source_size * 64, 0);
419
} else if (p_font_data->fixed_size > 0) {
420
return Vector2i(p_font_data->fixed_size * 64, MIN(p_size.y, 1));
421
} else {
422
return Vector2i(p_size.x * 64, p_size.y);
423
}
424
}
425
426
_FORCE_INLINE_ double _get_extra_advance(RID p_font_rid, int p_font_size) const;
427
_FORCE_INLINE_ Variant::Type _get_tag_type(int64_t p_tag) const;
428
_FORCE_INLINE_ bool _get_tag_hidden(int64_t p_tag) const;
429
_FORCE_INLINE_ int _font_get_weight_by_name(const String &p_sty_name) const {
430
String sty_name = p_sty_name.remove_chars(" -");
431
if (sty_name.contains("thin") || sty_name.contains("hairline")) {
432
return 100;
433
} else if (sty_name.contains("extralight") || sty_name.contains("ultralight")) {
434
return 200;
435
} else if (sty_name.contains("light")) {
436
return 300;
437
} else if (sty_name.contains("semilight")) {
438
return 350;
439
} else if (sty_name.contains("regular")) {
440
return 400;
441
} else if (sty_name.contains("medium")) {
442
return 500;
443
} else if (sty_name.contains("semibold") || sty_name.contains("demibold")) {
444
return 600;
445
} else if (sty_name.contains("bold")) {
446
return 700;
447
} else if (sty_name.contains("extrabold") || sty_name.contains("ultrabold")) {
448
return 800;
449
} else if (sty_name.contains("black") || sty_name.contains("heavy")) {
450
return 900;
451
} else if (sty_name.contains("extrablack") || sty_name.contains("ultrablack")) {
452
return 950;
453
}
454
return 400;
455
}
456
_FORCE_INLINE_ int _font_get_stretch_by_name(const String &p_sty_name) const {
457
String sty_name = p_sty_name.remove_chars(" -");
458
if (sty_name.contains("ultracondensed")) {
459
return 50;
460
} else if (sty_name.contains("extracondensed")) {
461
return 63;
462
} else if (sty_name.contains("condensed")) {
463
return 75;
464
} else if (sty_name.contains("semicondensed")) {
465
return 87;
466
} else if (sty_name.contains("semiexpanded")) {
467
return 113;
468
} else if (sty_name.contains("expanded")) {
469
return 125;
470
} else if (sty_name.contains("extraexpanded")) {
471
return 150;
472
} else if (sty_name.contains("ultraexpanded")) {
473
return 200;
474
}
475
return 100;
476
}
477
_FORCE_INLINE_ bool _is_ital_style(const String &p_sty_name) const {
478
return p_sty_name.contains("italic") || p_sty_name.contains("oblique");
479
}
480
481
// Shaped text cache data.
482
struct TrimData {
483
int trim_pos = -1;
484
int ellipsis_pos = -1;
485
Vector<Glyph> ellipsis_glyph_buf;
486
};
487
488
struct TextRun {
489
Vector2i range;
490
RID font_rid;
491
int font_size = 0;
492
bool rtl = false;
493
int64_t span_index = -1;
494
};
495
496
struct ShapedTextDataAdvanced {
497
Mutex mutex;
498
499
/* Source data */
500
RID parent; // Substring parent ShapedTextData.
501
502
int start = 0; // Substring start offset in the parent string.
503
int end = 0; // Substring end offset in the parent string.
504
505
String text;
506
String custom_punct;
507
TextServer::Direction direction = DIRECTION_LTR; // Desired text direction.
508
TextServer::Orientation orientation = ORIENTATION_HORIZONTAL;
509
510
struct Span {
511
int start = -1;
512
int end = -1;
513
514
Array fonts;
515
int font_size = 0;
516
517
Variant embedded_key;
518
519
String language;
520
Dictionary features;
521
Variant meta;
522
};
523
Vector<Span> spans;
524
int first_span = 0; // First span in the parent ShapedTextData.
525
int last_span = 0;
526
527
Vector<TextRun> runs;
528
bool runs_dirty = true;
529
530
struct EmbeddedObject {
531
int start = -1;
532
int end = -1;
533
InlineAlignment inline_align = INLINE_ALIGNMENT_CENTER;
534
Rect2 rect;
535
double baseline = 0;
536
};
537
HashMap<Variant, EmbeddedObject> objects;
538
539
/* Shaped data */
540
TextServer::Direction para_direction = DIRECTION_LTR; // Detected text direction.
541
int base_para_direction = UBIDI_DEFAULT_LTR;
542
SafeFlag valid{ false }; // String is shaped.
543
bool line_breaks_valid = false; // Line and word break flags are populated (and virtual zero width spaces inserted).
544
bool justification_ops_valid = false; // Virtual elongation glyphs are added to the string.
545
bool sort_valid = false;
546
bool text_trimmed = false;
547
548
bool preserve_invalid = true; // Draw hex code box instead of missing characters.
549
bool preserve_control = false; // Draw control characters.
550
551
double ascent = 0.0; // Ascent for horizontal layout, 1/2 of width for vertical.
552
double descent = 0.0; // Descent for horizontal layout, 1/2 of width for vertical.
553
double width = 0.0; // Width for horizontal layout, height for vertical.
554
double width_trimmed = 0.0;
555
int extra_spacing[4] = { 0, 0, 0, 0 };
556
557
double upos = 0.0;
558
double uthk = 0.0;
559
560
char32_t el_char = 0x2026;
561
TrimData overrun_trim_data;
562
bool fit_width_minimum_reached = false;
563
564
LocalVector<Glyph> glyphs;
565
LocalVector<Glyph> glyphs_logical;
566
567
/* Intermediate data */
568
Char16String utf16;
569
Vector<UBiDi *> bidi_iter;
570
Vector<Vector3i> bidi_override;
571
ScriptIterator *script_iter = nullptr;
572
hb_buffer_t *hb_buffer = nullptr;
573
574
HashMap<int, bool> jstops;
575
HashMap<int, bool> breaks;
576
PackedInt32Array chars;
577
int break_inserts = 0;
578
bool break_ops_valid = false;
579
bool js_ops_valid = false;
580
bool chars_valid = false;
581
582
~ShapedTextDataAdvanced() {
583
for (int i = 0; i < bidi_iter.size(); i++) {
584
if (bidi_iter[i]) {
585
ubidi_close(bidi_iter[i]);
586
}
587
}
588
if (script_iter) {
589
memdelete(script_iter);
590
}
591
if (hb_buffer) {
592
hb_buffer_destroy(hb_buffer);
593
}
594
}
595
};
596
597
// Common data.
598
599
mutable RID_PtrOwner<FontAdvancedLinkedVariation> font_var_owner;
600
mutable RID_PtrOwner<FontAdvanced> font_owner;
601
mutable RID_PtrOwner<ShapedTextDataAdvanced> shaped_owner;
602
603
_FORCE_INLINE_ FontAdvanced *_get_font_data(const RID &p_font_rid) const {
604
RID rid = p_font_rid;
605
FontAdvancedLinkedVariation *fdv = font_var_owner.get_or_null(rid);
606
if (unlikely(fdv)) {
607
rid = fdv->base_font;
608
}
609
return font_owner.get_or_null(rid);
610
}
611
612
struct SystemFontKey {
613
String font_name;
614
TextServer::FontAntialiasing antialiasing = TextServer::FONT_ANTIALIASING_GRAY;
615
bool disable_embedded_bitmaps = true;
616
bool italic = false;
617
bool mipmaps = false;
618
bool msdf = false;
619
bool force_autohinter = false;
620
int weight = 400;
621
int stretch = 100;
622
int msdf_range = 14;
623
int msdf_source_size = 48;
624
int fixed_size = 0;
625
TextServer::Hinting hinting = TextServer::HINTING_LIGHT;
626
TextServer::SubpixelPositioning subpixel_positioning = TextServer::SUBPIXEL_POSITIONING_AUTO;
627
bool keep_rounding_remainders = true;
628
Dictionary variation_coordinates;
629
double embolden = 0.0;
630
Transform2D transform;
631
int extra_spacing[4] = { 0, 0, 0, 0 };
632
double baseline_offset = 0.0;
633
634
bool operator==(const SystemFontKey &p_b) const {
635
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) && (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);
636
}
637
638
SystemFontKey(const String &p_font_name, bool p_italic, int p_weight, int p_stretch, RID p_font, const TextServerAdvanced *p_fb) {
639
font_name = p_font_name;
640
italic = p_italic;
641
weight = p_weight;
642
stretch = p_stretch;
643
antialiasing = p_fb->_font_get_antialiasing(p_font);
644
disable_embedded_bitmaps = p_fb->_font_get_disable_embedded_bitmaps(p_font);
645
mipmaps = p_fb->_font_get_generate_mipmaps(p_font);
646
msdf = p_fb->_font_is_multichannel_signed_distance_field(p_font);
647
msdf_range = p_fb->_font_get_msdf_pixel_range(p_font);
648
msdf_source_size = p_fb->_font_get_msdf_size(p_font);
649
fixed_size = p_fb->_font_get_fixed_size(p_font);
650
force_autohinter = p_fb->_font_is_force_autohinter(p_font);
651
hinting = p_fb->_font_get_hinting(p_font);
652
subpixel_positioning = p_fb->_font_get_subpixel_positioning(p_font);
653
keep_rounding_remainders = p_fb->_font_get_keep_rounding_remainders(p_font);
654
variation_coordinates = p_fb->_font_get_variation_coordinates(p_font);
655
embolden = p_fb->_font_get_embolden(p_font);
656
transform = p_fb->_font_get_transform(p_font);
657
extra_spacing[SPACING_TOP] = p_fb->_font_get_spacing(p_font, SPACING_TOP);
658
extra_spacing[SPACING_BOTTOM] = p_fb->_font_get_spacing(p_font, SPACING_BOTTOM);
659
extra_spacing[SPACING_SPACE] = p_fb->_font_get_spacing(p_font, SPACING_SPACE);
660
extra_spacing[SPACING_GLYPH] = p_fb->_font_get_spacing(p_font, SPACING_GLYPH);
661
baseline_offset = p_fb->_font_get_baseline_offset(p_font);
662
}
663
};
664
665
struct SystemFontCacheRec {
666
RID rid;
667
int index = 0;
668
};
669
670
struct SystemFontCache {
671
Vector<SystemFontCacheRec> var;
672
int max_var = 0;
673
};
674
675
struct SystemFontKeyHasher {
676
_FORCE_INLINE_ static uint32_t hash(const SystemFontKey &p_a) {
677
uint32_t hash = p_a.font_name.hash();
678
hash = hash_murmur3_one_32(p_a.variation_coordinates.hash(), hash);
679
hash = hash_murmur3_one_32(p_a.weight, hash);
680
hash = hash_murmur3_one_32(p_a.stretch, hash);
681
hash = hash_murmur3_one_32(p_a.msdf_range, hash);
682
hash = hash_murmur3_one_32(p_a.msdf_source_size, hash);
683
hash = hash_murmur3_one_32(p_a.fixed_size, hash);
684
hash = hash_murmur3_one_double(p_a.embolden, hash);
685
hash = hash_murmur3_one_real(p_a.transform[0].x, hash);
686
hash = hash_murmur3_one_real(p_a.transform[0].y, hash);
687
hash = hash_murmur3_one_real(p_a.transform[1].x, hash);
688
hash = hash_murmur3_one_real(p_a.transform[1].y, hash);
689
hash = hash_murmur3_one_32(p_a.extra_spacing[SPACING_TOP], hash);
690
hash = hash_murmur3_one_32(p_a.extra_spacing[SPACING_BOTTOM], hash);
691
hash = hash_murmur3_one_32(p_a.extra_spacing[SPACING_SPACE], hash);
692
hash = hash_murmur3_one_32(p_a.extra_spacing[SPACING_GLYPH], hash);
693
hash = hash_murmur3_one_double(p_a.baseline_offset, hash);
694
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));
695
}
696
};
697
mutable HashMap<SystemFontKey, SystemFontCache, SystemFontKeyHasher> system_fonts;
698
mutable HashMap<String, PackedByteArray> system_font_data;
699
700
void _update_chars(ShapedTextDataAdvanced *p_sd) const;
701
void _generate_runs(ShapedTextDataAdvanced *p_sd) const;
702
void _realign(ShapedTextDataAdvanced *p_sd) const;
703
int64_t _convert_pos(const String &p_utf32, const Char16String &p_utf16, int64_t p_pos) const;
704
int64_t _convert_pos(const ShapedTextDataAdvanced *p_sd, int64_t p_pos) const;
705
int64_t _convert_pos_inv(const ShapedTextDataAdvanced *p_sd, int64_t p_pos) const;
706
bool _shape_substr(ShapedTextDataAdvanced *p_new_sd, const ShapedTextDataAdvanced *p_sd, int64_t p_start, int64_t p_length) const;
707
708
struct FontPriorityList {
709
friend class TextServerAdvanced;
710
711
const int PRIORITY_SKIP = 100; // Font already used.
712
const int PRIORITY_MAX = 2;
713
int current_priority = 0;
714
uint32_t current_index = 0;
715
uint32_t font_count = 0;
716
String language;
717
String script_code;
718
bool color = false;
719
LocalVector<Pair<RID, int>> unprocessed_fonts;
720
LocalVector<RID> fonts;
721
const TextServerAdvanced *text_server;
722
723
FontPriorityList(const TextServerAdvanced *p_text_server, const Array &p_fonts, const String &p_language, const String &p_script_code, bool p_color) {
724
text_server = p_text_server;
725
language = p_language;
726
script_code = p_script_code;
727
font_count = p_fonts.size();
728
color = p_color;
729
730
unprocessed_fonts.reserve(font_count);
731
for (uint32_t i = 0; i < font_count; i++) {
732
unprocessed_fonts.push_back(Pair<RID, int>(p_fonts[i], -1));
733
}
734
735
fonts.reserve(font_count);
736
if (font_count > 0) {
737
fonts.push_back(p_fonts[0]);
738
unprocessed_fonts[0].second = PRIORITY_SKIP;
739
current_index++;
740
}
741
}
742
743
_FORCE_INLINE_ uint32_t size() const {
744
return font_count;
745
}
746
747
_FORCE_INLINE_ int _get_priority(const RID &p_font) {
748
if (color && text_server->_font_is_color(p_font)) {
749
return 0;
750
}
751
return text_server->_font_is_script_supported(p_font, script_code) ? (text_server->_font_is_language_supported(p_font, language) ? 0 : 1) : 2;
752
}
753
754
RID operator[](uint32_t p_index) {
755
if (p_index < fonts.size()) {
756
return fonts[p_index];
757
}
758
while (current_priority < PRIORITY_MAX || current_index < font_count) {
759
if (current_index >= font_count) {
760
current_priority++;
761
current_index = 0;
762
}
763
const RID &font = unprocessed_fonts[current_index].first;
764
int &priority = unprocessed_fonts[current_index].second;
765
if (priority < 0) {
766
priority = _get_priority(font);
767
}
768
if (priority == current_priority) {
769
unprocessed_fonts[current_index].second = PRIORITY_SKIP;
770
fonts.push_back(font);
771
if (p_index < fonts.size()) {
772
return fonts[p_index];
773
}
774
}
775
current_index++;
776
}
777
return RID();
778
}
779
};
780
void _shape_run(ShapedTextDataAdvanced *p_sd, int64_t p_start, int64_t p_end, const String &p_language, hb_script_t p_script, hb_direction_t p_direction, FontPriorityList &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);
781
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);
782
_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);
783
784
_FORCE_INLINE_ void _add_features(const Dictionary &p_source, Vector<hb_feature_t> &r_ftrs);
785
786
String os_locale;
787
788
Mutex ft_mutex;
789
790
// HarfBuzz bitmap font interface.
791
792
static hb_font_funcs_t *funcs;
793
794
struct bmp_font_t {
795
TextServerAdvanced::FontForSizeAdvanced *face = nullptr;
796
bool unref = false; /* Whether to destroy bm_face when done. */
797
};
798
799
static bmp_font_t *_bmp_font_create(TextServerAdvanced::FontForSizeAdvanced *p_face, bool p_unref);
800
static void _bmp_font_destroy(void *p_data);
801
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);
802
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);
803
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);
804
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);
805
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);
806
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);
807
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);
808
static void _bmp_create_font_funcs();
809
static void _bmp_free_font_funcs();
810
static void _bmp_font_set_funcs(hb_font_t *p_font, TextServerAdvanced::FontForSizeAdvanced *p_face, bool p_unref);
811
static hb_font_t *_bmp_font_create(TextServerAdvanced::FontForSizeAdvanced *p_face, hb_destroy_func_t p_destroy);
812
813
hb_font_t *_font_get_hb_handle(const RID &p_font, int64_t p_font_size, bool &r_is_color) const;
814
bool _font_is_color(const RID &p_font) const;
815
816
struct GlyphCompare { // For line breaking reordering.
817
_FORCE_INLINE_ bool operator()(const Glyph &l, const Glyph &r) const {
818
if (l.start == r.start) {
819
if (l.count == r.count) {
820
return (l.flags & TextServer::GRAPHEME_IS_VIRTUAL) < (r.flags & TextServer::GRAPHEME_IS_VIRTUAL);
821
}
822
return l.count > r.count; // Sort first glyph with count & flags, order of the rest are irrelevant.
823
} else {
824
return l.start < r.start;
825
}
826
}
827
};
828
829
protected:
830
static void _bind_methods() {}
831
832
void full_copy(ShapedTextDataAdvanced *p_shaped);
833
void invalidate(ShapedTextDataAdvanced *p_shaped, bool p_text = false);
834
835
public:
836
MODBIND1RC(bool, has_feature, Feature);
837
MODBIND0RC(String, get_name);
838
MODBIND0RC(int64_t, get_features);
839
840
MODBIND1(free_rid, const RID &);
841
MODBIND1R(bool, has, const RID &);
842
MODBIND1R(bool, load_support_data, const String &);
843
844
MODBIND0RC(String, get_support_data_filename);
845
MODBIND0RC(String, get_support_data_info);
846
MODBIND1RC(bool, save_support_data, const String &);
847
MODBIND0RC(PackedByteArray, get_support_data);
848
MODBIND1RC(bool, is_locale_using_support_data, const String &);
849
850
MODBIND1RC(bool, is_locale_right_to_left, const String &);
851
852
MODBIND1RC(int64_t, name_to_tag, const String &);
853
MODBIND1RC(String, tag_to_name, int64_t);
854
855
/* Font interface */
856
857
MODBIND0R(RID, create_font);
858
MODBIND1R(RID, create_font_linked_variation, const RID &);
859
860
MODBIND2(font_set_data, const RID &, const PackedByteArray &);
861
MODBIND3(font_set_data_ptr, const RID &, const uint8_t *, int64_t);
862
863
MODBIND2(font_set_face_index, const RID &, int64_t);
864
MODBIND1RC(int64_t, font_get_face_index, const RID &);
865
866
MODBIND1RC(int64_t, font_get_face_count, const RID &);
867
868
MODBIND2(font_set_style, const RID &, BitField<FontStyle>);
869
MODBIND1RC(BitField<FontStyle>, font_get_style, const RID &);
870
871
MODBIND2(font_set_style_name, const RID &, const String &);
872
MODBIND1RC(String, font_get_style_name, const RID &);
873
874
MODBIND2(font_set_weight, const RID &, int64_t);
875
MODBIND1RC(int64_t, font_get_weight, const RID &);
876
877
MODBIND2(font_set_stretch, const RID &, int64_t);
878
MODBIND1RC(int64_t, font_get_stretch, const RID &);
879
880
MODBIND2(font_set_name, const RID &, const String &);
881
MODBIND1RC(String, font_get_name, const RID &);
882
MODBIND1RC(Dictionary, font_get_ot_name_strings, const RID &);
883
884
MODBIND2(font_set_antialiasing, const RID &, TextServer::FontAntialiasing);
885
MODBIND1RC(TextServer::FontAntialiasing, font_get_antialiasing, const RID &);
886
887
MODBIND2(font_set_disable_embedded_bitmaps, const RID &, bool);
888
MODBIND1RC(bool, font_get_disable_embedded_bitmaps, const RID &);
889
890
MODBIND2(font_set_generate_mipmaps, const RID &, bool);
891
MODBIND1RC(bool, font_get_generate_mipmaps, const RID &);
892
893
MODBIND2(font_set_multichannel_signed_distance_field, const RID &, bool);
894
MODBIND1RC(bool, font_is_multichannel_signed_distance_field, const RID &);
895
896
MODBIND2(font_set_msdf_pixel_range, const RID &, int64_t);
897
MODBIND1RC(int64_t, font_get_msdf_pixel_range, const RID &);
898
899
MODBIND2(font_set_msdf_size, const RID &, int64_t);
900
MODBIND1RC(int64_t, font_get_msdf_size, const RID &);
901
902
MODBIND2(font_set_fixed_size, const RID &, int64_t);
903
MODBIND1RC(int64_t, font_get_fixed_size, const RID &);
904
905
MODBIND2(font_set_fixed_size_scale_mode, const RID &, FixedSizeScaleMode);
906
MODBIND1RC(FixedSizeScaleMode, font_get_fixed_size_scale_mode, const RID &);
907
908
MODBIND2(font_set_allow_system_fallback, const RID &, bool);
909
MODBIND1RC(bool, font_is_allow_system_fallback, const RID &);
910
MODBIND0(font_clear_system_fallback_cache);
911
912
MODBIND2(font_set_force_autohinter, const RID &, bool);
913
MODBIND1RC(bool, font_is_force_autohinter, const RID &);
914
915
MODBIND2(font_set_modulate_color_glyphs, const RID &, bool);
916
MODBIND1RC(bool, font_is_modulate_color_glyphs, const RID &);
917
918
MODBIND2(font_set_subpixel_positioning, const RID &, SubpixelPositioning);
919
MODBIND1RC(SubpixelPositioning, font_get_subpixel_positioning, const RID &);
920
921
MODBIND2(font_set_keep_rounding_remainders, const RID &, bool);
922
MODBIND1RC(bool, font_get_keep_rounding_remainders, const RID &);
923
924
MODBIND2(font_set_embolden, const RID &, double);
925
MODBIND1RC(double, font_get_embolden, const RID &);
926
927
MODBIND3(font_set_spacing, const RID &, SpacingType, int64_t);
928
MODBIND2RC(int64_t, font_get_spacing, const RID &, SpacingType);
929
930
MODBIND2(font_set_baseline_offset, const RID &, double);
931
MODBIND1RC(double, font_get_baseline_offset, const RID &);
932
933
MODBIND2(font_set_transform, const RID &, const Transform2D &);
934
MODBIND1RC(Transform2D, font_get_transform, const RID &);
935
936
MODBIND2(font_set_variation_coordinates, const RID &, const Dictionary &);
937
MODBIND1RC(Dictionary, font_get_variation_coordinates, const RID &);
938
939
MODBIND2(font_set_oversampling, const RID &, double);
940
MODBIND1RC(double, font_get_oversampling, const RID &);
941
942
MODBIND2(font_set_hinting, const RID &, TextServer::Hinting);
943
MODBIND1RC(TextServer::Hinting, font_get_hinting, const RID &);
944
945
MODBIND1RC(TypedArray<Vector2i>, font_get_size_cache_list, const RID &);
946
MODBIND1(font_clear_size_cache, const RID &);
947
MODBIND2(font_remove_size_cache, const RID &, const Vector2i &);
948
MODBIND1RC(TypedArray<Dictionary>, font_get_size_cache_info, const RID &);
949
950
MODBIND3(font_set_ascent, const RID &, int64_t, double);
951
MODBIND2RC(double, font_get_ascent, const RID &, int64_t);
952
953
MODBIND3(font_set_descent, const RID &, int64_t, double);
954
MODBIND2RC(double, font_get_descent, const RID &, int64_t);
955
956
MODBIND3(font_set_underline_position, const RID &, int64_t, double);
957
MODBIND2RC(double, font_get_underline_position, const RID &, int64_t);
958
959
MODBIND3(font_set_underline_thickness, const RID &, int64_t, double);
960
MODBIND2RC(double, font_get_underline_thickness, const RID &, int64_t);
961
962
MODBIND3(font_set_scale, const RID &, int64_t, double);
963
MODBIND2RC(double, font_get_scale, const RID &, int64_t);
964
965
MODBIND2RC(int64_t, font_get_texture_count, const RID &, const Vector2i &);
966
MODBIND2(font_clear_textures, const RID &, const Vector2i &);
967
MODBIND3(font_remove_texture, const RID &, const Vector2i &, int64_t);
968
969
MODBIND4(font_set_texture_image, const RID &, const Vector2i &, int64_t, const Ref<Image> &);
970
MODBIND3RC(Ref<Image>, font_get_texture_image, const RID &, const Vector2i &, int64_t);
971
972
MODBIND4(font_set_texture_offsets, const RID &, const Vector2i &, int64_t, const PackedInt32Array &);
973
MODBIND3RC(PackedInt32Array, font_get_texture_offsets, const RID &, const Vector2i &, int64_t);
974
975
MODBIND2RC(PackedInt32Array, font_get_glyph_list, const RID &, const Vector2i &);
976
MODBIND2(font_clear_glyphs, const RID &, const Vector2i &);
977
MODBIND3(font_remove_glyph, const RID &, const Vector2i &, int64_t);
978
979
MODBIND3RC(Vector2, font_get_glyph_advance, const RID &, int64_t, int64_t);
980
MODBIND4(font_set_glyph_advance, const RID &, int64_t, int64_t, const Vector2 &);
981
982
MODBIND3RC(Vector2, font_get_glyph_offset, const RID &, const Vector2i &, int64_t);
983
MODBIND4(font_set_glyph_offset, const RID &, const Vector2i &, int64_t, const Vector2 &);
984
985
MODBIND3RC(Vector2, font_get_glyph_size, const RID &, const Vector2i &, int64_t);
986
MODBIND4(font_set_glyph_size, const RID &, const Vector2i &, int64_t, const Vector2 &);
987
988
MODBIND3RC(Rect2, font_get_glyph_uv_rect, const RID &, const Vector2i &, int64_t);
989
MODBIND4(font_set_glyph_uv_rect, const RID &, const Vector2i &, int64_t, const Rect2 &);
990
991
MODBIND3RC(int64_t, font_get_glyph_texture_idx, const RID &, const Vector2i &, int64_t);
992
MODBIND4(font_set_glyph_texture_idx, const RID &, const Vector2i &, int64_t, int64_t);
993
994
MODBIND3RC(RID, font_get_glyph_texture_rid, const RID &, const Vector2i &, int64_t);
995
MODBIND3RC(Size2, font_get_glyph_texture_size, const RID &, const Vector2i &, int64_t);
996
997
MODBIND3RC(Dictionary, font_get_glyph_contours, const RID &, int64_t, int64_t);
998
999
MODBIND2RC(TypedArray<Vector2i>, font_get_kerning_list, const RID &, int64_t);
1000
MODBIND2(font_clear_kerning_map, const RID &, int64_t);
1001
MODBIND3(font_remove_kerning, const RID &, int64_t, const Vector2i &);
1002
1003
MODBIND4(font_set_kerning, const RID &, int64_t, const Vector2i &, const Vector2 &);
1004
MODBIND3RC(Vector2, font_get_kerning, const RID &, int64_t, const Vector2i &);
1005
1006
MODBIND4RC(int64_t, font_get_glyph_index, const RID &, int64_t, int64_t, int64_t);
1007
MODBIND3RC(int64_t, font_get_char_from_glyph_index, const RID &, int64_t, int64_t);
1008
1009
MODBIND2RC(bool, font_has_char, const RID &, int64_t);
1010
MODBIND1RC(String, font_get_supported_chars, const RID &);
1011
MODBIND1RC(PackedInt32Array, font_get_supported_glyphs, const RID &);
1012
1013
MODBIND4(font_render_range, const RID &, const Vector2i &, int64_t, int64_t);
1014
MODBIND3(font_render_glyph, const RID &, const Vector2i &, int64_t);
1015
1016
MODBIND7C(font_draw_glyph, const RID &, const RID &, int64_t, const Vector2 &, int64_t, const Color &, float);
1017
MODBIND8C(font_draw_glyph_outline, const RID &, const RID &, int64_t, int64_t, const Vector2 &, int64_t, const Color &, float);
1018
1019
MODBIND2RC(bool, font_is_language_supported, const RID &, const String &);
1020
MODBIND3(font_set_language_support_override, const RID &, const String &, bool);
1021
MODBIND2R(bool, font_get_language_support_override, const RID &, const String &);
1022
MODBIND2(font_remove_language_support_override, const RID &, const String &);
1023
MODBIND1R(PackedStringArray, font_get_language_support_overrides, const RID &);
1024
1025
MODBIND2RC(bool, font_is_script_supported, const RID &, const String &);
1026
MODBIND3(font_set_script_support_override, const RID &, const String &, bool);
1027
MODBIND2R(bool, font_get_script_support_override, const RID &, const String &);
1028
MODBIND2(font_remove_script_support_override, const RID &, const String &);
1029
MODBIND1R(PackedStringArray, font_get_script_support_overrides, const RID &);
1030
1031
MODBIND2(font_set_opentype_feature_overrides, const RID &, const Dictionary &);
1032
MODBIND1RC(Dictionary, font_get_opentype_feature_overrides, const RID &);
1033
1034
MODBIND1RC(Dictionary, font_supported_feature_list, const RID &);
1035
MODBIND1RC(Dictionary, font_supported_variation_list, const RID &);
1036
1037
MODBIND1(reference_oversampling_level, double);
1038
MODBIND1(unreference_oversampling_level, double);
1039
1040
/* Shaped text buffer interface */
1041
1042
MODBIND2R(RID, create_shaped_text, Direction, Orientation);
1043
1044
MODBIND1(shaped_text_clear, const RID &);
1045
MODBIND1R(RID, shaped_text_duplicate, const RID &);
1046
1047
MODBIND2(shaped_text_set_direction, const RID &, Direction);
1048
MODBIND1RC(Direction, shaped_text_get_direction, const RID &);
1049
MODBIND1RC(Direction, shaped_text_get_inferred_direction, const RID &);
1050
1051
MODBIND2(shaped_text_set_bidi_override, const RID &, const Array &);
1052
1053
MODBIND2(shaped_text_set_custom_punctuation, const RID &, const String &);
1054
MODBIND1RC(String, shaped_text_get_custom_punctuation, const RID &);
1055
1056
MODBIND2(shaped_text_set_custom_ellipsis, const RID &, int64_t);
1057
MODBIND1RC(int64_t, shaped_text_get_custom_ellipsis, const RID &);
1058
1059
MODBIND2(shaped_text_set_orientation, const RID &, Orientation);
1060
MODBIND1RC(Orientation, shaped_text_get_orientation, const RID &);
1061
1062
MODBIND2(shaped_text_set_preserve_invalid, const RID &, bool);
1063
MODBIND1RC(bool, shaped_text_get_preserve_invalid, const RID &);
1064
1065
MODBIND2(shaped_text_set_preserve_control, const RID &, bool);
1066
MODBIND1RC(bool, shaped_text_get_preserve_control, const RID &);
1067
1068
MODBIND3(shaped_text_set_spacing, const RID &, SpacingType, int64_t);
1069
MODBIND2RC(int64_t, shaped_text_get_spacing, const RID &, SpacingType);
1070
1071
MODBIND7R(bool, shaped_text_add_string, const RID &, const String &, const TypedArray<RID> &, int64_t, const Dictionary &, const String &, const Variant &);
1072
MODBIND6R(bool, shaped_text_add_object, const RID &, const Variant &, const Size2 &, InlineAlignment, int64_t, double);
1073
MODBIND5R(bool, shaped_text_resize_object, const RID &, const Variant &, const Size2 &, InlineAlignment, double);
1074
MODBIND2RC(bool, shaped_text_has_object, const RID &, const Variant &);
1075
MODBIND1RC(String, shaped_get_text, const RID &);
1076
1077
MODBIND1RC(int64_t, shaped_get_span_count, const RID &);
1078
MODBIND2RC(Variant, shaped_get_span_meta, const RID &, int64_t);
1079
MODBIND2RC(Variant, shaped_get_span_embedded_object, const RID &, int64_t);
1080
MODBIND2RC(String, shaped_get_span_text, const RID &, int64_t);
1081
MODBIND2RC(Variant, shaped_get_span_object, const RID &, int64_t);
1082
MODBIND5(shaped_set_span_update_font, const RID &, int64_t, const TypedArray<RID> &, int64_t, const Dictionary &);
1083
1084
MODBIND1RC(int64_t, shaped_get_run_count, const RID &);
1085
MODBIND2RC(String, shaped_get_run_text, const RID &, int64_t);
1086
MODBIND2RC(Vector2i, shaped_get_run_range, const RID &, int64_t);
1087
MODBIND2RC(RID, shaped_get_run_font_rid, const RID &, int64_t);
1088
MODBIND2RC(int, shaped_get_run_font_size, const RID &, int64_t);
1089
MODBIND2RC(String, shaped_get_run_language, const RID &, int64_t);
1090
MODBIND2RC(Direction, shaped_get_run_direction, const RID &, int64_t);
1091
MODBIND2RC(Variant, shaped_get_run_object, const RID &, int64_t);
1092
1093
MODBIND3RC(RID, shaped_text_substr, const RID &, int64_t, int64_t);
1094
MODBIND1RC(RID, shaped_text_get_parent, const RID &);
1095
1096
MODBIND3R(double, shaped_text_fit_to_width, const RID &, double, BitField<TextServer::JustificationFlag>);
1097
MODBIND2R(double, shaped_text_tab_align, const RID &, const PackedFloat32Array &);
1098
1099
MODBIND1R(bool, shaped_text_shape, const RID &);
1100
MODBIND1R(bool, shaped_text_update_breaks, const RID &);
1101
MODBIND1R(bool, shaped_text_update_justification_ops, const RID &);
1102
1103
MODBIND1RC(int64_t, shaped_text_get_trim_pos, const RID &);
1104
MODBIND1RC(int64_t, shaped_text_get_ellipsis_pos, const RID &);
1105
MODBIND1RC(const Glyph *, shaped_text_get_ellipsis_glyphs, const RID &);
1106
MODBIND1RC(int64_t, shaped_text_get_ellipsis_glyph_count, const RID &);
1107
1108
MODBIND3(shaped_text_overrun_trim_to_width, const RID &, double, BitField<TextServer::TextOverrunFlag>);
1109
1110
MODBIND1RC(bool, shaped_text_is_ready, const RID &);
1111
1112
MODBIND1RC(const Glyph *, shaped_text_get_glyphs, const RID &);
1113
MODBIND1R(const Glyph *, shaped_text_sort_logical, const RID &);
1114
MODBIND1RC(int64_t, shaped_text_get_glyph_count, const RID &);
1115
1116
MODBIND1RC(Vector2i, shaped_text_get_range, const RID &);
1117
1118
MODBIND1RC(Array, shaped_text_get_objects, const RID &);
1119
MODBIND2RC(Rect2, shaped_text_get_object_rect, const RID &, const Variant &);
1120
MODBIND2RC(Vector2i, shaped_text_get_object_range, const RID &, const Variant &);
1121
MODBIND2RC(int64_t, shaped_text_get_object_glyph, const RID &, const Variant &);
1122
1123
MODBIND1RC(Size2, shaped_text_get_size, const RID &);
1124
MODBIND1RC(double, shaped_text_get_ascent, const RID &);
1125
MODBIND1RC(double, shaped_text_get_descent, const RID &);
1126
MODBIND1RC(double, shaped_text_get_width, const RID &);
1127
MODBIND1RC(double, shaped_text_get_underline_position, const RID &);
1128
MODBIND1RC(double, shaped_text_get_underline_thickness, const RID &);
1129
1130
MODBIND1RC(PackedInt32Array, shaped_text_get_character_breaks, const RID &);
1131
1132
MODBIND3RC(PackedInt32Array, string_get_word_breaks, const String &, const String &, int64_t);
1133
MODBIND2RC(PackedInt32Array, string_get_character_breaks, const String &, const String &);
1134
1135
MODBIND2RC(int64_t, is_confusable, const String &, const PackedStringArray &);
1136
MODBIND1RC(bool, spoof_check, const String &);
1137
1138
MODBIND1RC(String, strip_diacritics, const String &);
1139
MODBIND1RC(bool, is_valid_identifier, const String &);
1140
MODBIND1RC(bool, is_valid_letter, uint64_t);
1141
1142
MODBIND2RC(String, string_to_upper, const String &, const String &);
1143
MODBIND2RC(String, string_to_lower, const String &, const String &);
1144
MODBIND2RC(String, string_to_title, const String &, const String &);
1145
1146
MODBIND0(cleanup);
1147
1148
TextServerAdvanced();
1149
~TextServerAdvanced();
1150
};
1151
1152