Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
godotengine
GitHub Repository: godotengine/godot
Path: blob/master/servers/text/text_server.h
11322 views
1
/**************************************************************************/
2
/* text_server.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
#include "core/io/image.h"
34
#include "core/object/ref_counted.h"
35
#include "core/templates/rid.h"
36
#include "core/variant/native_ptr.h"
37
#include "core/variant/variant.h"
38
39
template <typename T>
40
class TypedArray;
41
42
struct Glyph;
43
struct CaretInfo;
44
45
#define OT_TAG(m_c1, m_c2, m_c3, m_c4) ((int32_t)((((uint32_t)(m_c1) & 0xff) << 24) | (((uint32_t)(m_c2) & 0xff) << 16) | (((uint32_t)(m_c3) & 0xff) << 8) | ((uint32_t)(m_c4) & 0xff)))
46
47
class TextServer : public RefCounted {
48
GDCLASS(TextServer, RefCounted);
49
50
public:
51
enum FontAntialiasing {
52
FONT_ANTIALIASING_NONE,
53
FONT_ANTIALIASING_GRAY,
54
FONT_ANTIALIASING_LCD,
55
};
56
57
enum FontLCDSubpixelLayout {
58
FONT_LCD_SUBPIXEL_LAYOUT_NONE,
59
FONT_LCD_SUBPIXEL_LAYOUT_HRGB,
60
FONT_LCD_SUBPIXEL_LAYOUT_HBGR,
61
FONT_LCD_SUBPIXEL_LAYOUT_VRGB,
62
FONT_LCD_SUBPIXEL_LAYOUT_VBGR,
63
FONT_LCD_SUBPIXEL_LAYOUT_MAX,
64
};
65
66
enum Direction {
67
DIRECTION_AUTO,
68
DIRECTION_LTR,
69
DIRECTION_RTL,
70
DIRECTION_INHERITED,
71
};
72
73
enum Orientation {
74
ORIENTATION_HORIZONTAL,
75
ORIENTATION_VERTICAL
76
};
77
78
enum JustificationFlag {
79
JUSTIFICATION_NONE = 0,
80
JUSTIFICATION_KASHIDA = 1 << 0,
81
JUSTIFICATION_WORD_BOUND = 1 << 1,
82
JUSTIFICATION_TRIM_EDGE_SPACES = 1 << 2,
83
JUSTIFICATION_AFTER_LAST_TAB = 1 << 3,
84
JUSTIFICATION_CONSTRAIN_ELLIPSIS = 1 << 4,
85
JUSTIFICATION_SKIP_LAST_LINE = 1 << 5,
86
JUSTIFICATION_SKIP_LAST_LINE_WITH_VISIBLE_CHARS = 1 << 6,
87
JUSTIFICATION_DO_NOT_SKIP_SINGLE_LINE = 1 << 7,
88
};
89
90
enum VisibleCharactersBehavior {
91
VC_CHARS_BEFORE_SHAPING,
92
VC_CHARS_AFTER_SHAPING,
93
VC_GLYPHS_AUTO,
94
VC_GLYPHS_LTR,
95
VC_GLYPHS_RTL,
96
};
97
98
enum AutowrapMode {
99
AUTOWRAP_OFF,
100
AUTOWRAP_ARBITRARY,
101
AUTOWRAP_WORD,
102
AUTOWRAP_WORD_SMART
103
};
104
105
enum LineBreakFlag {
106
BREAK_NONE = 0,
107
BREAK_MANDATORY = 1 << 0,
108
BREAK_WORD_BOUND = 1 << 1,
109
BREAK_GRAPHEME_BOUND = 1 << 2,
110
BREAK_ADAPTIVE = 1 << 3,
111
#ifndef DISABLE_DEPRECATED
112
BREAK_TRIM_EDGE_SPACES = 1 << 4,
113
#else
114
// RESERVED = 1 << 4,
115
#endif
116
BREAK_TRIM_INDENT = 1 << 5,
117
BREAK_TRIM_START_EDGE_SPACES = 1 << 6,
118
BREAK_TRIM_END_EDGE_SPACES = 1 << 7,
119
120
BREAK_TRIM_MASK = BREAK_TRIM_INDENT | BREAK_TRIM_START_EDGE_SPACES | BREAK_TRIM_END_EDGE_SPACES,
121
};
122
123
enum OverrunBehavior {
124
OVERRUN_NO_TRIMMING,
125
OVERRUN_TRIM_CHAR,
126
OVERRUN_TRIM_WORD,
127
OVERRUN_TRIM_ELLIPSIS,
128
OVERRUN_TRIM_WORD_ELLIPSIS,
129
OVERRUN_TRIM_ELLIPSIS_FORCE,
130
OVERRUN_TRIM_WORD_ELLIPSIS_FORCE,
131
};
132
133
enum TextOverrunFlag {
134
OVERRUN_NO_TRIM = 0,
135
OVERRUN_TRIM = 1 << 0,
136
OVERRUN_TRIM_WORD_ONLY = 1 << 1,
137
OVERRUN_ADD_ELLIPSIS = 1 << 2,
138
OVERRUN_ENFORCE_ELLIPSIS = 1 << 3,
139
OVERRUN_JUSTIFICATION_AWARE = 1 << 4,
140
};
141
142
enum GraphemeFlag {
143
GRAPHEME_IS_VALID = 1 << 0, // Grapheme is valid.
144
GRAPHEME_IS_RTL = 1 << 1, // Grapheme is right-to-left.
145
GRAPHEME_IS_VIRTUAL = 1 << 2, // Grapheme is not part of source string (added by fit_to_width function, do not affect caret movement).
146
GRAPHEME_IS_SPACE = 1 << 3, // Is whitespace (for justification and word breaks).
147
GRAPHEME_IS_BREAK_HARD = 1 << 4, // Is line break (mandatory break, e.g. "\n").
148
GRAPHEME_IS_BREAK_SOFT = 1 << 5, // Is line break (optional break, e.g. space).
149
GRAPHEME_IS_TAB = 1 << 6, // Is tab or vertical tab.
150
GRAPHEME_IS_ELONGATION = 1 << 7, // Elongation (e.g. kashida), grapheme can be duplicated or truncated to fit line to width.
151
GRAPHEME_IS_PUNCTUATION = 1 << 8, // Punctuation, except underscore (can be used as word break, but not line break or justifiction).
152
GRAPHEME_IS_UNDERSCORE = 1 << 9, // Underscore (can be used as word break).
153
GRAPHEME_IS_CONNECTED = 1 << 10, // Connected to previous grapheme.
154
GRAPHEME_IS_SAFE_TO_INSERT_TATWEEL = 1 << 11, // It is safe to insert a U+0640 before this grapheme for elongation.
155
GRAPHEME_IS_EMBEDDED_OBJECT = 1 << 12, // Grapheme is an object replacement character for the embedded object.
156
GRAPHEME_IS_SOFT_HYPHEN = 1 << 13, // Grapheme is a soft hyphen.
157
};
158
159
enum Hinting {
160
HINTING_NONE,
161
HINTING_LIGHT,
162
HINTING_NORMAL
163
};
164
165
enum SubpixelPositioning {
166
SUBPIXEL_POSITIONING_DISABLED = 0,
167
SUBPIXEL_POSITIONING_AUTO = 1,
168
SUBPIXEL_POSITIONING_ONE_HALF = 2,
169
SUBPIXEL_POSITIONING_ONE_QUARTER = 3,
170
171
SUBPIXEL_POSITIONING_ONE_HALF_MAX_SIZE = 20,
172
SUBPIXEL_POSITIONING_ONE_QUARTER_MAX_SIZE = 16,
173
};
174
175
enum Feature {
176
FEATURE_SIMPLE_LAYOUT = 1 << 0,
177
FEATURE_BIDI_LAYOUT = 1 << 1,
178
FEATURE_VERTICAL_LAYOUT = 1 << 2,
179
FEATURE_SHAPING = 1 << 3,
180
FEATURE_KASHIDA_JUSTIFICATION = 1 << 4,
181
FEATURE_BREAK_ITERATORS = 1 << 5,
182
FEATURE_FONT_BITMAP = 1 << 6,
183
FEATURE_FONT_DYNAMIC = 1 << 7,
184
FEATURE_FONT_MSDF = 1 << 8,
185
FEATURE_FONT_SYSTEM = 1 << 9,
186
FEATURE_FONT_VARIABLE = 1 << 10,
187
FEATURE_CONTEXT_SENSITIVE_CASE_CONVERSION = 1 << 11,
188
FEATURE_USE_SUPPORT_DATA = 1 << 12,
189
FEATURE_UNICODE_IDENTIFIERS = 1 << 13,
190
FEATURE_UNICODE_SECURITY = 1 << 14,
191
};
192
193
enum ContourPointTag {
194
CONTOUR_CURVE_TAG_ON = 0x01,
195
CONTOUR_CURVE_TAG_OFF_CONIC = 0x00,
196
CONTOUR_CURVE_TAG_OFF_CUBIC = 0x02
197
};
198
199
enum SpacingType {
200
SPACING_GLYPH,
201
SPACING_SPACE,
202
SPACING_TOP,
203
SPACING_BOTTOM,
204
SPACING_MAX,
205
};
206
207
enum FontStyle {
208
FONT_BOLD = 1 << 0,
209
FONT_ITALIC = 1 << 1,
210
FONT_FIXED_WIDTH = 1 << 2,
211
};
212
213
enum StructuredTextParser {
214
STRUCTURED_TEXT_DEFAULT,
215
STRUCTURED_TEXT_URI,
216
STRUCTURED_TEXT_FILE,
217
STRUCTURED_TEXT_EMAIL,
218
STRUCTURED_TEXT_LIST,
219
STRUCTURED_TEXT_GDSCRIPT,
220
STRUCTURED_TEXT_CUSTOM
221
};
222
223
enum FixedSizeScaleMode {
224
FIXED_SIZE_SCALE_DISABLE,
225
FIXED_SIZE_SCALE_INTEGER_ONLY,
226
FIXED_SIZE_SCALE_ENABLED,
227
};
228
229
void _draw_hex_code_box_number(const RID &p_canvas, int64_t p_size, const Vector2 &p_pos, uint8_t p_index, const Color &p_color) const;
230
231
protected:
232
double vp_oversampling = 0.0;
233
HashMap<char32_t, char32_t> diacritics_map;
234
void _diacritics_map_add(const String &p_from, char32_t p_to);
235
void _init_diacritics_map();
236
237
static void _bind_methods();
238
239
#ifndef DISABLE_DEPRECATED
240
void _font_draw_glyph_bind_compat_104872(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;
241
void _font_draw_glyph_outline_bind_compat_104872(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;
242
void _shaped_text_draw_bind_compat_104872(const RID &p_shaped, const RID &p_canvas, const Vector2 &p_pos, double p_clip_l = -1.0, double p_clip_r = -1.0, const Color &p_color = Color(1, 1, 1)) const;
243
void _shaped_text_draw_outline_bind_compat_104872(const RID &p_shaped, const RID &p_canvas, const Vector2 &p_pos, double p_clip_l = -1.0, double p_clip_r = -1.0, int64_t p_outline_size = 1, const Color &p_color = Color(1, 1, 1)) const;
244
PackedInt32Array _shaped_text_get_word_breaks_bind_compat_90732(const RID &p_shaped, BitField<TextServer::GraphemeFlag> p_grapheme_flags = GRAPHEME_IS_SPACE | GRAPHEME_IS_PUNCTUATION) const;
245
static void _bind_compatibility_methods();
246
#endif
247
248
public:
249
static BitField<TextOverrunFlag> get_overrun_flags_from_behavior(OverrunBehavior p_behavior);
250
251
virtual bool has_feature(Feature p_feature) const = 0;
252
virtual String get_name() const = 0;
253
virtual int64_t get_features() const = 0;
254
255
virtual void free_rid(const RID &p_rid) = 0;
256
virtual bool has(const RID &p_rid) = 0;
257
virtual bool load_support_data(const String &p_filename) = 0;
258
259
virtual String get_support_data_filename() const = 0;
260
virtual String get_support_data_info() const = 0;
261
virtual bool save_support_data(const String &p_filename) const = 0;
262
virtual PackedByteArray get_support_data() const = 0;
263
264
virtual bool is_locale_right_to_left(const String &p_locale) const = 0;
265
266
virtual int64_t name_to_tag(const String &p_name) const;
267
virtual String tag_to_name(int64_t p_tag) const;
268
269
/* Font interface */
270
271
virtual RID create_font() = 0;
272
virtual RID create_font_linked_variation(const RID &p_font_rid) = 0;
273
274
virtual void font_set_data(const RID &p_font_rid, const PackedByteArray &p_data) = 0;
275
virtual void font_set_data_ptr(const RID &p_font_rid, const uint8_t *p_data_ptr, int64_t p_data_size) = 0;
276
277
virtual void font_set_face_index(const RID &p_font_rid, int64_t p_index) = 0;
278
virtual int64_t font_get_face_index(const RID &p_font_rid) const = 0;
279
280
virtual int64_t font_get_face_count(const RID &p_font_rid) const = 0;
281
282
virtual void font_set_style(const RID &p_font_rid, BitField<FontStyle> p_style) = 0;
283
virtual BitField<FontStyle> font_get_style(const RID &p_font_rid) const = 0;
284
285
virtual void font_set_name(const RID &p_font_rid, const String &p_name) = 0;
286
virtual String font_get_name(const RID &p_font_rid) const = 0;
287
virtual Dictionary font_get_ot_name_strings(const RID &p_font_rid) const { return Dictionary(); }
288
289
virtual void font_set_style_name(const RID &p_font_rid, const String &p_name) = 0;
290
virtual String font_get_style_name(const RID &p_font_rid) const = 0;
291
292
virtual void font_set_weight(const RID &p_font_rid, int64_t p_weight) = 0;
293
virtual int64_t font_get_weight(const RID &p_font_rid) const = 0;
294
295
virtual void font_set_stretch(const RID &p_font_rid, int64_t p_stretch) = 0;
296
virtual int64_t font_get_stretch(const RID &p_font_rid) const = 0;
297
298
virtual void font_set_antialiasing(const RID &p_font_rid, FontAntialiasing p_antialiasing) = 0;
299
virtual FontAntialiasing font_get_antialiasing(const RID &p_font_rid) const = 0;
300
301
virtual void font_set_disable_embedded_bitmaps(const RID &p_font_rid, bool p_disable_embedded_bitmaps) = 0;
302
virtual bool font_get_disable_embedded_bitmaps(const RID &p_font_rid) const = 0;
303
304
virtual void font_set_generate_mipmaps(const RID &p_font_rid, bool p_generate_mipmaps) = 0;
305
virtual bool font_get_generate_mipmaps(const RID &p_font_rid) const = 0;
306
307
virtual void font_set_multichannel_signed_distance_field(const RID &p_font_rid, bool p_msdf) = 0;
308
virtual bool font_is_multichannel_signed_distance_field(const RID &p_font_rid) const = 0;
309
310
virtual void font_set_msdf_pixel_range(const RID &p_font_rid, int64_t p_msdf_pixel_range) = 0;
311
virtual int64_t font_get_msdf_pixel_range(const RID &p_font_rid) const = 0;
312
313
virtual void font_set_msdf_size(const RID &p_font_rid, int64_t p_msdf_size) = 0;
314
virtual int64_t font_get_msdf_size(const RID &p_font_rid) const = 0;
315
316
virtual void font_set_fixed_size(const RID &p_font_rid, int64_t p_fixed_size) = 0;
317
virtual int64_t font_get_fixed_size(const RID &p_font_rid) const = 0;
318
319
virtual void font_set_fixed_size_scale_mode(const RID &p_font_rid, FixedSizeScaleMode p_fixed_size_scale) = 0;
320
virtual FixedSizeScaleMode font_get_fixed_size_scale_mode(const RID &p_font_rid) const = 0;
321
322
virtual void font_set_allow_system_fallback(const RID &p_font_rid, bool p_allow_system_fallback) = 0;
323
virtual bool font_is_allow_system_fallback(const RID &p_font_rid) const = 0;
324
325
virtual void font_clear_system_fallback_cache() {}
326
327
virtual void font_set_force_autohinter(const RID &p_font_rid, bool p_force_autohinter) = 0;
328
virtual bool font_is_force_autohinter(const RID &p_font_rid) const = 0;
329
330
virtual void font_set_modulate_color_glyphs(const RID &p_font_rid, bool p_modulate) = 0;
331
virtual bool font_is_modulate_color_glyphs(const RID &p_font_rid) const = 0;
332
333
virtual void font_set_hinting(const RID &p_font_rid, Hinting p_hinting) = 0;
334
virtual Hinting font_get_hinting(const RID &p_font_rid) const = 0;
335
336
virtual void font_set_subpixel_positioning(const RID &p_font_rid, SubpixelPositioning p_subpixel) = 0;
337
virtual SubpixelPositioning font_get_subpixel_positioning(const RID &p_font_rid) const = 0;
338
339
virtual void font_set_keep_rounding_remainders(const RID &p_font_rid, bool p_keep_rounding_remainders) = 0;
340
virtual bool font_get_keep_rounding_remainders(const RID &p_font_rid) const = 0;
341
342
virtual void font_set_embolden(const RID &p_font_rid, double p_strength) = 0;
343
virtual double font_get_embolden(const RID &p_font_rid) const = 0;
344
345
virtual void font_set_spacing(const RID &p_font_rid, SpacingType p_spacing, int64_t p_value) = 0;
346
virtual int64_t font_get_spacing(const RID &p_font_rid, SpacingType p_spacing) const = 0;
347
348
virtual void font_set_baseline_offset(const RID &p_font_rid, double p_baseline_offset) = 0;
349
virtual double font_get_baseline_offset(const RID &p_font_rid) const = 0;
350
351
virtual void font_set_transform(const RID &p_font_rid, const Transform2D &p_transform) = 0;
352
virtual Transform2D font_get_transform(const RID &p_font_rid) const = 0;
353
354
virtual void font_set_variation_coordinates(const RID &p_font_rid, const Dictionary &p_variation_coordinates) = 0;
355
virtual Dictionary font_get_variation_coordinates(const RID &p_font_rid) const = 0;
356
357
virtual void font_set_oversampling(const RID &p_font_rid, double p_oversampling) = 0;
358
virtual double font_get_oversampling(const RID &p_font_rid) const = 0;
359
360
virtual TypedArray<Vector2i> font_get_size_cache_list(const RID &p_font_rid) const = 0;
361
virtual void font_clear_size_cache(const RID &p_font_rid) = 0;
362
virtual void font_remove_size_cache(const RID &p_font_rid, const Vector2i &p_size) = 0;
363
virtual TypedArray<Dictionary> font_get_size_cache_info(const RID &p_font_rid) const = 0;
364
365
virtual void font_set_ascent(const RID &p_font_rid, int64_t p_size, double p_ascent) = 0;
366
virtual double font_get_ascent(const RID &p_font_rid, int64_t p_size) const = 0;
367
368
virtual void font_set_descent(const RID &p_font_rid, int64_t p_size, double p_descent) = 0;
369
virtual double font_get_descent(const RID &p_font_rid, int64_t p_size) const = 0;
370
371
virtual void font_set_underline_position(const RID &p_font_rid, int64_t p_size, double p_underline_position) = 0;
372
virtual double font_get_underline_position(const RID &p_font_rid, int64_t p_size) const = 0;
373
374
virtual void font_set_underline_thickness(const RID &p_font_rid, int64_t p_size, double p_underline_thickness) = 0;
375
virtual double font_get_underline_thickness(const RID &p_font_rid, int64_t p_size) const = 0;
376
377
virtual void font_set_scale(const RID &p_font_rid, int64_t p_size, double p_scale) = 0;
378
virtual double font_get_scale(const RID &p_font_rid, int64_t p_size) const = 0;
379
380
virtual int64_t font_get_texture_count(const RID &p_font_rid, const Vector2i &p_size) const = 0;
381
virtual void font_clear_textures(const RID &p_font_rid, const Vector2i &p_size) = 0;
382
virtual void font_remove_texture(const RID &p_font_rid, const Vector2i &p_size, int64_t p_texture_index) = 0;
383
384
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) = 0;
385
virtual Ref<Image> font_get_texture_image(const RID &p_font_rid, const Vector2i &p_size, int64_t p_texture_index) const = 0;
386
387
virtual void font_set_texture_offsets(const RID &p_font_rid, const Vector2i &p_size, int64_t p_texture_index, const PackedInt32Array &p_offset) = 0;
388
virtual PackedInt32Array font_get_texture_offsets(const RID &p_font_rid, const Vector2i &p_size, int64_t p_texture_index) const = 0;
389
390
virtual PackedInt32Array font_get_glyph_list(const RID &p_font_rid, const Vector2i &p_size) const = 0;
391
virtual void font_clear_glyphs(const RID &p_font_rid, const Vector2i &p_size) = 0;
392
virtual void font_remove_glyph(const RID &p_font_rid, const Vector2i &p_size, int64_t p_glyph) = 0;
393
394
virtual Vector2 font_get_glyph_advance(const RID &p_font_rid, int64_t p_size, int64_t p_glyph) const = 0;
395
virtual void font_set_glyph_advance(const RID &p_font_rid, int64_t p_size, int64_t p_glyph, const Vector2 &p_advance) = 0;
396
397
virtual Vector2 font_get_glyph_offset(const RID &p_font_rid, const Vector2i &p_size, int64_t p_glyph) const = 0;
398
virtual void font_set_glyph_offset(const RID &p_font_rid, const Vector2i &p_size, int64_t p_glyph, const Vector2 &p_offset) = 0;
399
400
virtual Vector2 font_get_glyph_size(const RID &p_font_rid, const Vector2i &p_size, int64_t p_glyph) const = 0;
401
virtual void font_set_glyph_size(const RID &p_font_rid, const Vector2i &p_size, int64_t p_glyph, const Vector2 &p_gl_size) = 0;
402
403
virtual Rect2 font_get_glyph_uv_rect(const RID &p_font_rid, const Vector2i &p_size, int64_t p_glyph) const = 0;
404
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) = 0;
405
406
virtual int64_t font_get_glyph_texture_idx(const RID &p_font_rid, const Vector2i &p_size, int64_t p_glyph) const = 0;
407
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) = 0;
408
virtual RID font_get_glyph_texture_rid(const RID &p_font_rid, const Vector2i &p_size, int64_t p_glyph) const = 0;
409
virtual Size2 font_get_glyph_texture_size(const RID &p_font_rid, const Vector2i &p_size, int64_t p_glyph) const = 0;
410
411
virtual Dictionary font_get_glyph_contours(const RID &p_font, int64_t p_size, int64_t p_index) const = 0;
412
413
virtual TypedArray<Vector2i> font_get_kerning_list(const RID &p_font_rid, int64_t p_size) const = 0;
414
virtual void font_clear_kerning_map(const RID &p_font_rid, int64_t p_size) = 0;
415
virtual void font_remove_kerning(const RID &p_font_rid, int64_t p_size, const Vector2i &p_glyph_pair) = 0;
416
417
virtual void font_set_kerning(const RID &p_font_rid, int64_t p_size, const Vector2i &p_glyph_pair, const Vector2 &p_kerning) = 0;
418
virtual Vector2 font_get_kerning(const RID &p_font_rid, int64_t p_size, const Vector2i &p_glyph_pair) const = 0;
419
420
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) const = 0;
421
virtual int64_t font_get_char_from_glyph_index(const RID &p_font_rid, int64_t p_size, int64_t p_glyph_index) const = 0;
422
423
virtual bool font_has_char(const RID &p_font_rid, int64_t p_char) const = 0;
424
virtual String font_get_supported_chars(const RID &p_font_rid) const = 0;
425
virtual PackedInt32Array font_get_supported_glyphs(const RID &p_font_rid) const = 0;
426
427
virtual void font_render_range(const RID &p_font, const Vector2i &p_size, int64_t p_start, int64_t p_end) = 0;
428
virtual void font_render_glyph(const RID &p_font_rid, const Vector2i &p_size, int64_t p_index) = 0;
429
430
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), float p_oversampling = 0.0) const = 0;
431
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), float p_oversampling = 0.0) const = 0;
432
433
virtual bool font_is_language_supported(const RID &p_font_rid, const String &p_language) const = 0;
434
virtual void font_set_language_support_override(const RID &p_font_rid, const String &p_language, bool p_supported) = 0;
435
virtual bool font_get_language_support_override(const RID &p_font_rid, const String &p_language) = 0;
436
virtual void font_remove_language_support_override(const RID &p_font_rid, const String &p_language) = 0;
437
virtual PackedStringArray font_get_language_support_overrides(const RID &p_font_rid) = 0;
438
439
virtual bool font_is_script_supported(const RID &p_font_rid, const String &p_script) const = 0;
440
virtual void font_set_script_support_override(const RID &p_font_rid, const String &p_script, bool p_supported) = 0;
441
virtual bool font_get_script_support_override(const RID &p_font_rid, const String &p_script) = 0;
442
virtual void font_remove_script_support_override(const RID &p_font_rid, const String &p_script) = 0;
443
virtual PackedStringArray font_get_script_support_overrides(const RID &p_font_rid) = 0;
444
445
virtual void font_set_opentype_feature_overrides(const RID &p_font_rid, const Dictionary &p_overrides) = 0;
446
virtual Dictionary font_get_opentype_feature_overrides(const RID &p_font_rid) const = 0;
447
448
virtual Dictionary font_supported_feature_list(const RID &p_font_rid) const = 0;
449
virtual Dictionary font_supported_variation_list(const RID &p_font_rid) const = 0;
450
451
#ifndef DISABLE_DEPRECATED
452
virtual double font_get_global_oversampling() const { return 1.0; }
453
virtual void font_set_global_oversampling(double p_oversampling) {}
454
#endif
455
virtual void reference_oversampling_level(double p_oversampling) {}
456
virtual void unreference_oversampling_level(double p_oversampling) {}
457
458
virtual Vector2 get_hex_code_box_size(int64_t p_size, int64_t p_index) const;
459
virtual void draw_hex_code_box(const RID &p_canvas, int64_t p_size, const Vector2 &p_pos, int64_t p_index, const Color &p_color) const;
460
461
/* Shaped text buffer interface */
462
463
virtual RID create_shaped_text(Direction p_direction = DIRECTION_AUTO, Orientation p_orientation = ORIENTATION_HORIZONTAL) = 0;
464
465
virtual void shaped_text_clear(const RID &p_shaped) = 0;
466
467
virtual void shaped_text_set_direction(const RID &p_shaped, Direction p_direction = DIRECTION_AUTO) = 0;
468
virtual Direction shaped_text_get_direction(const RID &p_shaped) const = 0;
469
virtual Direction shaped_text_get_inferred_direction(const RID &p_shaped) const = 0;
470
471
virtual void shaped_text_set_bidi_override(const RID &p_shaped, const Array &p_override) = 0;
472
473
virtual void shaped_text_set_custom_punctuation(const RID &p_shaped, const String &p_punct) = 0;
474
virtual String shaped_text_get_custom_punctuation(const RID &p_shaped) const = 0;
475
476
virtual void shaped_text_set_custom_ellipsis(const RID &p_shaped, int64_t p_char) = 0;
477
virtual int64_t shaped_text_get_custom_ellipsis(const RID &p_shaped) const = 0;
478
479
virtual void shaped_text_set_orientation(const RID &p_shaped, Orientation p_orientation = ORIENTATION_HORIZONTAL) = 0;
480
virtual Orientation shaped_text_get_orientation(const RID &p_shaped) const = 0;
481
482
virtual void shaped_text_set_preserve_invalid(const RID &p_shaped, bool p_enabled) = 0;
483
virtual bool shaped_text_get_preserve_invalid(const RID &p_shaped) const = 0;
484
485
virtual void shaped_text_set_preserve_control(const RID &p_shaped, bool p_enabled) = 0;
486
virtual bool shaped_text_get_preserve_control(const RID &p_shaped) const = 0;
487
488
virtual void shaped_text_set_spacing(const RID &p_shaped, SpacingType p_spacing, int64_t p_value) = 0;
489
virtual int64_t shaped_text_get_spacing(const RID &p_shaped, SpacingType p_spacing) const = 0;
490
491
virtual bool shaped_text_add_string(const RID &p_shaped, const String &p_text, const TypedArray<RID> &p_fonts, int64_t p_size, const Dictionary &p_opentype_features = Dictionary(), const String &p_language = "", const Variant &p_meta = Variant()) = 0;
492
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, double p_baseline = 0.0) = 0;
493
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, double p_baseline = 0.0) = 0;
494
virtual String shaped_get_text(const RID &p_shaped) const = 0;
495
496
virtual int64_t shaped_get_span_count(const RID &p_shaped) const = 0;
497
virtual Variant shaped_get_span_meta(const RID &p_shaped, int64_t p_index) const = 0;
498
virtual Variant shaped_get_span_embedded_object(const RID &p_shaped, int64_t p_index) const = 0;
499
virtual String shaped_get_span_text(const RID &p_shaped, int64_t p_index) const = 0;
500
virtual Variant shaped_get_span_object(const RID &p_shaped, int64_t p_index) const = 0;
501
virtual void shaped_set_span_update_font(const RID &p_shaped, int64_t p_index, const TypedArray<RID> &p_fonts, int64_t p_size, const Dictionary &p_opentype_features = Dictionary()) = 0;
502
503
virtual int64_t shaped_get_run_count(const RID &p_shaped) const = 0;
504
virtual String shaped_get_run_text(const RID &p_shaped, int64_t p_index) const = 0;
505
virtual Vector2i shaped_get_run_range(const RID &p_shaped, int64_t p_index) const = 0;
506
virtual RID shaped_get_run_font_rid(const RID &p_shaped, int64_t p_index) const = 0;
507
virtual int shaped_get_run_font_size(const RID &p_shaped, int64_t p_index) const = 0;
508
virtual String shaped_get_run_language(const RID &p_shaped, int64_t p_index) const = 0;
509
virtual Direction shaped_get_run_direction(const RID &p_shaped, int64_t p_index) const = 0;
510
virtual Variant shaped_get_run_object(const RID &p_shaped, int64_t p_index) const = 0;
511
512
virtual RID shaped_text_substr(const RID &p_shaped, int64_t p_start, int64_t p_length) const = 0; // Copy shaped substring (e.g. line break) without reshaping, but correctly reordered, preservers range.
513
virtual RID shaped_text_get_parent(const RID &p_shaped) const = 0;
514
515
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) = 0;
516
virtual double shaped_text_tab_align(const RID &p_shaped, const PackedFloat32Array &p_tab_stops) = 0;
517
518
virtual bool shaped_text_shape(const RID &p_shaped) = 0;
519
virtual bool shaped_text_update_breaks(const RID &p_shaped) = 0;
520
virtual bool shaped_text_update_justification_ops(const RID &p_shaped) = 0;
521
522
virtual bool shaped_text_is_ready(const RID &p_shaped) const = 0;
523
bool shaped_text_has_visible_chars(const RID &p_shaped) const;
524
525
virtual const Glyph *shaped_text_get_glyphs(const RID &p_shaped) const = 0;
526
TypedArray<Dictionary> _shaped_text_get_glyphs_wrapper(const RID &p_shaped) const;
527
virtual const Glyph *shaped_text_sort_logical(const RID &p_shaped) = 0;
528
TypedArray<Dictionary> _shaped_text_sort_logical_wrapper(const RID &p_shaped);
529
virtual int64_t shaped_text_get_glyph_count(const RID &p_shaped) const = 0;
530
531
virtual Vector2i shaped_text_get_range(const RID &p_shaped) const = 0;
532
533
virtual PackedInt32Array shaped_text_get_line_breaks_adv(const RID &p_shaped, const PackedFloat32Array &p_width, int64_t p_start = 0, bool p_once = true, BitField<TextServer::LineBreakFlag> p_break_flags = BREAK_MANDATORY | BREAK_WORD_BOUND) const;
534
virtual PackedInt32Array shaped_text_get_line_breaks(const RID &p_shaped, double p_width, int64_t p_start = 0, BitField<TextServer::LineBreakFlag> p_break_flags = BREAK_MANDATORY | BREAK_WORD_BOUND) const;
535
virtual PackedInt32Array shaped_text_get_word_breaks(const RID &p_shaped, BitField<TextServer::GraphemeFlag> p_grapheme_flags = GRAPHEME_IS_SPACE | GRAPHEME_IS_PUNCTUATION, BitField<TextServer::GraphemeFlag> p_skip_grapheme_flags = GRAPHEME_IS_VIRTUAL) const;
536
537
virtual int64_t shaped_text_get_trim_pos(const RID &p_shaped) const = 0;
538
virtual int64_t shaped_text_get_ellipsis_pos(const RID &p_shaped) const = 0;
539
virtual const Glyph *shaped_text_get_ellipsis_glyphs(const RID &p_shaped) const = 0;
540
TypedArray<Dictionary> _shaped_text_get_ellipsis_glyphs_wrapper(const RID &p_shaped) const;
541
virtual int64_t shaped_text_get_ellipsis_glyph_count(const RID &p_shaped) const = 0;
542
543
virtual void shaped_text_overrun_trim_to_width(const RID &p_shaped, double p_width, BitField<TextServer::TextOverrunFlag> p_trim_flags) = 0;
544
545
virtual Array shaped_text_get_objects(const RID &p_shaped) const = 0;
546
virtual Rect2 shaped_text_get_object_rect(const RID &p_shaped, const Variant &p_key) const = 0;
547
virtual Vector2i shaped_text_get_object_range(const RID &p_shaped, const Variant &p_key) const = 0;
548
virtual int64_t shaped_text_get_object_glyph(const RID &p_shaped, const Variant &p_key) const = 0;
549
550
virtual Size2 shaped_text_get_size(const RID &p_shaped) const = 0;
551
virtual double shaped_text_get_ascent(const RID &p_shaped) const = 0;
552
virtual double shaped_text_get_descent(const RID &p_shaped) const = 0;
553
virtual double shaped_text_get_width(const RID &p_shaped) const = 0;
554
virtual double shaped_text_get_underline_position(const RID &p_shaped) const = 0;
555
virtual double shaped_text_get_underline_thickness(const RID &p_shaped) const = 0;
556
557
virtual Direction shaped_text_get_dominant_direction_in_range(const RID &p_shaped, int64_t p_start, int64_t p_end) const;
558
559
virtual CaretInfo shaped_text_get_carets(const RID &p_shaped, int64_t p_position) const;
560
Dictionary _shaped_text_get_carets_wrapper(const RID &p_shaped, int64_t p_position) const;
561
562
virtual Vector<Vector2> shaped_text_get_selection(const RID &p_shaped, int64_t p_start, int64_t p_end) const;
563
564
virtual int64_t shaped_text_hit_test_grapheme(const RID &p_shaped, double p_coords) const; // Return grapheme index.
565
virtual int64_t shaped_text_hit_test_position(const RID &p_shaped, double p_coords) const; // Return caret/selection position.
566
567
virtual Vector2 shaped_text_get_grapheme_bounds(const RID &p_shaped, int64_t p_pos) const;
568
virtual int64_t shaped_text_next_grapheme_pos(const RID &p_shaped, int64_t p_pos) const;
569
virtual int64_t shaped_text_prev_grapheme_pos(const RID &p_shaped, int64_t p_pos) const;
570
571
virtual PackedInt32Array shaped_text_get_character_breaks(const RID &p_shaped) const = 0;
572
virtual int64_t shaped_text_next_character_pos(const RID &p_shaped, int64_t p_pos) const;
573
virtual int64_t shaped_text_prev_character_pos(const RID &p_shaped, int64_t p_pos) const;
574
virtual int64_t shaped_text_closest_character_pos(const RID &p_shaped, int64_t p_pos) const;
575
576
// The pen position is always placed on the baseline and moving left to right.
577
virtual void shaped_text_draw(const RID &p_shaped, const RID &p_canvas, const Vector2 &p_pos, double p_clip_l = -1.0, double p_clip_r = -1.0, const Color &p_color = Color(1, 1, 1), float p_oversampling = 0.0) const;
578
virtual void shaped_text_draw_outline(const RID &p_shaped, const RID &p_canvas, const Vector2 &p_pos, double p_clip_l = -1.0, double p_clip_r = -1.0, int64_t p_outline_size = 1, const Color &p_color = Color(1, 1, 1), float p_oversampling = 0.0) const;
579
580
#ifdef DEBUG_ENABLED
581
void debug_print_glyph(int p_idx, const Glyph &p_glyph) const;
582
void shaped_text_debug_print(const RID &p_shaped) const;
583
#endif
584
585
// Number conversion.
586
virtual String format_number(const String &p_string, const String &p_language = "") const = 0;
587
virtual String parse_number(const String &p_string, const String &p_language = "") const = 0;
588
virtual String percent_sign(const String &p_language = "") const = 0;
589
590
// String functions.
591
virtual PackedInt32Array string_get_word_breaks(const String &p_string, const String &p_language = "", int64_t p_chars_per_line = 0) const = 0;
592
virtual PackedInt32Array string_get_character_breaks(const String &p_string, const String &p_language = "") const;
593
594
virtual int64_t is_confusable(const String &p_string, const PackedStringArray &p_dict) const { return -1; }
595
virtual bool spoof_check(const String &p_string) const { return false; }
596
597
virtual String strip_diacritics(const String &p_string) const;
598
virtual bool is_valid_identifier(const String &p_string) const;
599
virtual bool is_valid_letter(uint64_t p_unicode) const;
600
601
// Other string operations.
602
virtual String string_to_upper(const String &p_string, const String &p_language = "") const = 0;
603
virtual String string_to_lower(const String &p_string, const String &p_language = "") const = 0;
604
virtual String string_to_title(const String &p_string, const String &p_language = "") const = 0;
605
606
TypedArray<Vector3i> parse_structured_text(StructuredTextParser p_parser_type, const Array &p_args, const String &p_text) const;
607
608
virtual void set_current_drawn_item_oversampling(double p_vp_oversampling) { vp_oversampling = p_vp_oversampling; }
609
610
virtual void cleanup() {}
611
612
TextServer();
613
~TextServer();
614
};
615
616
/*************************************************************************/
617
618
struct Glyph {
619
int start = -1; // Start offset in the source string.
620
int end = -1; // End offset in the source string.
621
622
uint8_t count = 0; // Number of glyphs in the grapheme, set in the first glyph only.
623
uint8_t repeat = 1; // Draw multiple times in the row.
624
uint16_t flags = 0; // Grapheme flags (valid, rtl, virtual), set in the first glyph only.
625
626
float x_off = 0.f; // Offset from the origin of the glyph on baseline.
627
float y_off = 0.f;
628
float advance = 0.f; // Advance to the next glyph along baseline(x for horizontal layout, y for vertical).
629
630
RID font_rid; // Font resource.
631
int font_size = 0; // Font size.
632
int32_t index = 0; // Glyph index (font specific) or UTF-32 codepoint (for the invalid glyphs).
633
634
int span_index = -1;
635
636
bool operator==(const Glyph &p_a) const;
637
bool operator!=(const Glyph &p_a) const;
638
639
bool operator<(const Glyph &p_a) const;
640
bool operator>(const Glyph &p_a) const;
641
};
642
643
struct CaretInfo {
644
Rect2 l_caret;
645
Rect2 t_caret;
646
TextServer::Direction l_dir;
647
TextServer::Direction t_dir;
648
};
649
650
/*************************************************************************/
651
652
class TextServerManager : public Object {
653
GDCLASS(TextServerManager, Object);
654
655
protected:
656
static void _bind_methods();
657
658
private:
659
static TextServerManager *singleton;
660
661
Ref<TextServer> primary_interface;
662
Vector<Ref<TextServer>> interfaces;
663
664
public:
665
_FORCE_INLINE_ static TextServerManager *get_singleton() {
666
return singleton;
667
}
668
669
void add_interface(const Ref<TextServer> &p_interface);
670
void remove_interface(const Ref<TextServer> &p_interface);
671
int get_interface_count() const;
672
Ref<TextServer> get_interface(int p_index) const;
673
Ref<TextServer> find_interface(const String &p_name) const;
674
TypedArray<Dictionary> get_interfaces() const;
675
676
_FORCE_INLINE_ Ref<TextServer> get_primary_interface() const {
677
return primary_interface;
678
}
679
void set_primary_interface(const Ref<TextServer> &p_primary_interface);
680
681
TextServerManager();
682
~TextServerManager();
683
};
684
685
/*************************************************************************/
686
687
#define TS TextServerManager::get_singleton()->get_primary_interface()
688
689
VARIANT_ENUM_CAST(TextServer::VisibleCharactersBehavior);
690
VARIANT_ENUM_CAST(TextServer::AutowrapMode);
691
VARIANT_ENUM_CAST(TextServer::OverrunBehavior);
692
VARIANT_ENUM_CAST(TextServer::Direction);
693
VARIANT_ENUM_CAST(TextServer::Orientation);
694
VARIANT_BITFIELD_CAST(TextServer::JustificationFlag);
695
VARIANT_BITFIELD_CAST(TextServer::LineBreakFlag);
696
VARIANT_BITFIELD_CAST(TextServer::TextOverrunFlag);
697
VARIANT_BITFIELD_CAST(TextServer::GraphemeFlag);
698
VARIANT_ENUM_CAST(TextServer::Hinting);
699
VARIANT_ENUM_CAST(TextServer::SubpixelPositioning);
700
VARIANT_ENUM_CAST(TextServer::Feature);
701
VARIANT_ENUM_CAST(TextServer::ContourPointTag);
702
VARIANT_ENUM_CAST(TextServer::SpacingType);
703
VARIANT_BITFIELD_CAST(TextServer::FontStyle);
704
VARIANT_ENUM_CAST(TextServer::StructuredTextParser);
705
VARIANT_ENUM_CAST(TextServer::FontAntialiasing);
706
VARIANT_ENUM_CAST(TextServer::FontLCDSubpixelLayout);
707
VARIANT_ENUM_CAST(TextServer::FixedSizeScaleMode);
708
709
GDVIRTUAL_NATIVE_PTR(Glyph);
710
GDVIRTUAL_NATIVE_PTR(CaretInfo);
711
712