Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
godotengine
GitHub Repository: godotengine/godot
Path: blob/master/scene/resources/font.h
9896 views
1
/**************************************************************************/
2
/* font.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/resource.h"
34
#include "core/templates/lru.h"
35
#include "scene/resources/texture.h"
36
#include "servers/text_server.h"
37
38
class TextLine;
39
class TextParagraph;
40
41
/*************************************************************************/
42
/* Font */
43
/*************************************************************************/
44
45
class Font : public Resource {
46
GDCLASS(Font, Resource);
47
48
struct ShapedTextKey {
49
String text;
50
int font_size = 14;
51
float width = 0.f;
52
BitField<TextServer::JustificationFlag> jst_flags = TextServer::JUSTIFICATION_NONE;
53
BitField<TextServer::LineBreakFlag> brk_flags = TextServer::BREAK_MANDATORY;
54
TextServer::Direction direction = TextServer::DIRECTION_AUTO;
55
TextServer::Orientation orientation = TextServer::ORIENTATION_HORIZONTAL;
56
57
bool operator==(const ShapedTextKey &p_b) const {
58
return (font_size == p_b.font_size) && (width == p_b.width) && (jst_flags == p_b.jst_flags) && (brk_flags == p_b.brk_flags) && (direction == p_b.direction) && (orientation == p_b.orientation) && (text == p_b.text);
59
}
60
61
ShapedTextKey() {}
62
ShapedTextKey(const String &p_text, int p_font_size, float p_width, BitField<TextServer::JustificationFlag> p_jst_flags, BitField<TextServer::LineBreakFlag> p_brk_flags, TextServer::Direction p_direction, TextServer::Orientation p_orientation) {
63
text = p_text;
64
font_size = p_font_size;
65
width = p_width;
66
jst_flags = p_jst_flags;
67
brk_flags = p_brk_flags;
68
direction = p_direction;
69
orientation = p_orientation;
70
}
71
};
72
73
struct ShapedTextKeyHasher {
74
_FORCE_INLINE_ static uint32_t hash(const ShapedTextKey &p_a) {
75
uint32_t hash = p_a.text.hash();
76
hash = hash_murmur3_one_32(p_a.font_size, hash);
77
hash = hash_murmur3_one_float(p_a.width, hash);
78
hash = hash_murmur3_one_32(p_a.brk_flags | (p_a.jst_flags << 6) | (p_a.direction << 12) | (p_a.orientation << 15), hash);
79
return hash_fmix32(hash);
80
}
81
};
82
83
// Shaped string cache.
84
mutable LRUCache<ShapedTextKey, Ref<TextLine>, ShapedTextKeyHasher> cache;
85
mutable LRUCache<ShapedTextKey, Ref<TextParagraph>, ShapedTextKeyHasher> cache_wrap;
86
87
protected:
88
// Output.
89
mutable TypedArray<RID> rids;
90
mutable bool dirty_rids = true;
91
92
// Fallbacks.
93
static constexpr int MAX_FALLBACK_DEPTH = 64;
94
TypedArray<Font> fallbacks;
95
96
static void _bind_methods();
97
98
virtual void _update_rids_fb(const Font *p_f, int p_depth) const;
99
virtual void _update_rids() const;
100
virtual void reset_state() override;
101
102
#ifndef DISABLE_DEPRECATED
103
void _draw_string_bind_compat_104872(RID p_canvas_item, const Point2 &p_pos, const String &p_text, HorizontalAlignment p_alignment = HORIZONTAL_ALIGNMENT_LEFT, float p_width = -1, int p_font_size = DEFAULT_FONT_SIZE, const Color &p_modulate = Color(1.0, 1.0, 1.0), BitField<TextServer::JustificationFlag> p_jst_flags = TextServer::JUSTIFICATION_KASHIDA | TextServer::JUSTIFICATION_WORD_BOUND, TextServer::Direction p_direction = TextServer::DIRECTION_AUTO, TextServer::Orientation p_orientation = TextServer::ORIENTATION_HORIZONTAL) const;
104
void _draw_multiline_string_bind_compat_104872(RID p_canvas_item, const Point2 &p_pos, const String &p_text, HorizontalAlignment p_alignment = HORIZONTAL_ALIGNMENT_LEFT, float p_width = -1, int p_font_size = DEFAULT_FONT_SIZE, int p_max_lines = -1, const Color &p_modulate = Color(1.0, 1.0, 1.0), BitField<TextServer::LineBreakFlag> p_brk_flags = TextServer::BREAK_MANDATORY | TextServer::BREAK_WORD_BOUND, BitField<TextServer::JustificationFlag> p_jst_flags = TextServer::JUSTIFICATION_KASHIDA | TextServer::JUSTIFICATION_WORD_BOUND, TextServer::Direction p_direction = TextServer::DIRECTION_AUTO, TextServer::Orientation p_orientation = TextServer::ORIENTATION_HORIZONTAL) const;
105
void _draw_string_outline_bind_compat_104872(RID p_canvas_item, const Point2 &p_pos, const String &p_text, HorizontalAlignment p_alignment = HORIZONTAL_ALIGNMENT_LEFT, float p_width = -1, int p_font_size = DEFAULT_FONT_SIZE, int p_size = 1, const Color &p_modulate = Color(1.0, 1.0, 1.0), BitField<TextServer::JustificationFlag> p_jst_flags = TextServer::JUSTIFICATION_KASHIDA | TextServer::JUSTIFICATION_WORD_BOUND, TextServer::Direction p_direction = TextServer::DIRECTION_AUTO, TextServer::Orientation p_orientation = TextServer::ORIENTATION_HORIZONTAL) const;
106
void _draw_multiline_string_outline_bind_compat_104872(RID p_canvas_item, const Point2 &p_pos, const String &p_text, HorizontalAlignment p_alignment = HORIZONTAL_ALIGNMENT_LEFT, float p_width = -1, int p_font_size = DEFAULT_FONT_SIZE, int p_max_lines = -1, int p_size = 1, const Color &p_modulate = Color(1.0, 1.0, 1.0), BitField<TextServer::LineBreakFlag> p_brk_flags = TextServer::BREAK_MANDATORY | TextServer::BREAK_WORD_BOUND, BitField<TextServer::JustificationFlag> p_jst_flags = TextServer::JUSTIFICATION_KASHIDA | TextServer::JUSTIFICATION_WORD_BOUND, TextServer::Direction p_direction = TextServer::DIRECTION_AUTO, TextServer::Orientation p_orientation = TextServer::ORIENTATION_HORIZONTAL) const;
107
real_t _draw_char_bind_compat_104872(RID p_canvas_item, const Point2 &p_pos, char32_t p_char, int p_font_size = DEFAULT_FONT_SIZE, const Color &p_modulate = Color(1.0, 1.0, 1.0)) const;
108
real_t _draw_char_outline_bind_compat_104872(RID p_canvas_item, const Point2 &p_pos, char32_t p_char, int p_font_size = DEFAULT_FONT_SIZE, int p_size = 1, const Color &p_modulate = Color(1.0, 1.0, 1.0)) const;
109
RID _find_variation_bind_compat_80954(const Dictionary &p_variation_coordinates, int p_face_index = 0, float p_strength = 0.0, Transform2D p_transform = Transform2D()) const;
110
RID _find_variation_bind_compat_87668(const Dictionary &p_variation_coordinates, int p_face_index = 0, float p_strength = 0.0, Transform2D p_transform = Transform2D(), int p_spacing_top = 0, int p_spacing_bottom = 0, int p_spacing_space = 0, int p_spacing_glyph = 0) const;
111
static void _bind_compatibility_methods();
112
#endif
113
114
public:
115
virtual bool _is_cyclic(const Ref<Font> &p_f, int p_depth) const;
116
virtual bool _is_base_cyclic(const Ref<Font> &p_f, int p_depth) const;
117
virtual void _invalidate_rids();
118
119
static constexpr int DEFAULT_FONT_SIZE = 16;
120
121
// Fallbacks.
122
virtual void set_fallbacks(const TypedArray<Font> &p_fallbacks);
123
virtual TypedArray<Font> get_fallbacks() const;
124
125
// Output.
126
virtual RID find_variation(const Dictionary &p_variation_coordinates, int p_face_index = 0, float p_strength = 0.0, Transform2D p_transform = Transform2D(), int p_spacing_top = 0, int p_spacing_bottom = 0, int p_spacing_space = 0, int p_spacing_glyph = 0, float p_baseline_offset = 0.0) const { return RID(); }
127
virtual RID _get_rid() const { return RID(); }
128
virtual TypedArray<RID> get_rids() const;
129
130
// Font metrics.
131
virtual real_t get_height(int p_font_size) const;
132
virtual real_t get_ascent(int p_font_size) const;
133
virtual real_t get_descent(int p_font_size) const;
134
virtual real_t get_underline_position(int p_font_size) const;
135
virtual real_t get_underline_thickness(int p_font_size) const;
136
137
virtual String get_font_name() const;
138
virtual String get_font_style_name() const;
139
virtual Dictionary get_ot_name_strings() const;
140
virtual BitField<TextServer::FontStyle> get_font_style() const;
141
virtual int get_font_weight() const;
142
virtual int get_font_stretch() const;
143
144
virtual int get_spacing(TextServer::SpacingType p_spacing) const { return 0; }
145
virtual Dictionary get_opentype_features() const;
146
147
// Drawing string.
148
virtual void set_cache_capacity(int p_single_line, int p_multi_line);
149
150
virtual Size2 get_string_size(const String &p_text, HorizontalAlignment p_alignment = HORIZONTAL_ALIGNMENT_LEFT, float p_width = -1, int p_font_size = DEFAULT_FONT_SIZE, BitField<TextServer::JustificationFlag> p_jst_flags = TextServer::JUSTIFICATION_KASHIDA | TextServer::JUSTIFICATION_WORD_BOUND, TextServer::Direction p_direction = TextServer::DIRECTION_AUTO, TextServer::Orientation p_orientation = TextServer::ORIENTATION_HORIZONTAL) const;
151
virtual Size2 get_multiline_string_size(const String &p_text, HorizontalAlignment p_alignment = HORIZONTAL_ALIGNMENT_LEFT, float p_width = -1, int p_font_size = DEFAULT_FONT_SIZE, int p_max_lines = -1, BitField<TextServer::LineBreakFlag> p_brk_flags = TextServer::BREAK_MANDATORY | TextServer::BREAK_WORD_BOUND, BitField<TextServer::JustificationFlag> p_jst_flags = TextServer::JUSTIFICATION_KASHIDA | TextServer::JUSTIFICATION_WORD_BOUND, TextServer::Direction p_direction = TextServer::DIRECTION_AUTO, TextServer::Orientation p_orientation = TextServer::ORIENTATION_HORIZONTAL) const;
152
153
virtual void draw_string(RID p_canvas_item, const Point2 &p_pos, const String &p_text, HorizontalAlignment p_alignment = HORIZONTAL_ALIGNMENT_LEFT, float p_width = -1, int p_font_size = DEFAULT_FONT_SIZE, const Color &p_modulate = Color(1.0, 1.0, 1.0), BitField<TextServer::JustificationFlag> p_jst_flags = TextServer::JUSTIFICATION_KASHIDA | TextServer::JUSTIFICATION_WORD_BOUND, TextServer::Direction p_direction = TextServer::DIRECTION_AUTO, TextServer::Orientation p_orientation = TextServer::ORIENTATION_HORIZONTAL, float p_oversampling = 0.0) const;
154
virtual void draw_multiline_string(RID p_canvas_item, const Point2 &p_pos, const String &p_text, HorizontalAlignment p_alignment = HORIZONTAL_ALIGNMENT_LEFT, float p_width = -1, int p_font_size = DEFAULT_FONT_SIZE, int p_max_lines = -1, const Color &p_modulate = Color(1.0, 1.0, 1.0), BitField<TextServer::LineBreakFlag> p_brk_flags = TextServer::BREAK_MANDATORY | TextServer::BREAK_WORD_BOUND, BitField<TextServer::JustificationFlag> p_jst_flags = TextServer::JUSTIFICATION_KASHIDA | TextServer::JUSTIFICATION_WORD_BOUND, TextServer::Direction p_direction = TextServer::DIRECTION_AUTO, TextServer::Orientation p_orientation = TextServer::ORIENTATION_HORIZONTAL, float p_oversampling = 0.0) const;
155
156
virtual void draw_string_outline(RID p_canvas_item, const Point2 &p_pos, const String &p_text, HorizontalAlignment p_alignment = HORIZONTAL_ALIGNMENT_LEFT, float p_width = -1, int p_font_size = DEFAULT_FONT_SIZE, int p_size = 1, const Color &p_modulate = Color(1.0, 1.0, 1.0), BitField<TextServer::JustificationFlag> p_jst_flags = TextServer::JUSTIFICATION_KASHIDA | TextServer::JUSTIFICATION_WORD_BOUND, TextServer::Direction p_direction = TextServer::DIRECTION_AUTO, TextServer::Orientation p_orientation = TextServer::ORIENTATION_HORIZONTAL, float p_oversampling = 0.0) const;
157
virtual void draw_multiline_string_outline(RID p_canvas_item, const Point2 &p_pos, const String &p_text, HorizontalAlignment p_alignment = HORIZONTAL_ALIGNMENT_LEFT, float p_width = -1, int p_font_size = DEFAULT_FONT_SIZE, int p_max_lines = -1, int p_size = 1, const Color &p_modulate = Color(1.0, 1.0, 1.0), BitField<TextServer::LineBreakFlag> p_brk_flags = TextServer::BREAK_MANDATORY | TextServer::BREAK_WORD_BOUND, BitField<TextServer::JustificationFlag> p_jst_flags = TextServer::JUSTIFICATION_KASHIDA | TextServer::JUSTIFICATION_WORD_BOUND, TextServer::Direction p_direction = TextServer::DIRECTION_AUTO, TextServer::Orientation p_orientation = TextServer::ORIENTATION_HORIZONTAL, float p_oversampling = 0.0) const;
158
159
// Drawing char.
160
virtual Size2 get_char_size(char32_t p_char, int p_font_size = DEFAULT_FONT_SIZE) const;
161
virtual real_t draw_char(RID p_canvas_item, const Point2 &p_pos, char32_t p_char, int p_font_size = DEFAULT_FONT_SIZE, const Color &p_modulate = Color(1.0, 1.0, 1.0), float p_oversampling = 0.0) const;
162
virtual real_t draw_char_outline(RID p_canvas_item, const Point2 &p_pos, char32_t p_char, int p_font_size = DEFAULT_FONT_SIZE, int p_size = 1, const Color &p_modulate = Color(1.0, 1.0, 1.0), float p_oversampling = 0.0) const;
163
164
// Helper functions.
165
virtual bool has_char(char32_t p_char) const;
166
virtual String get_supported_chars() const;
167
168
virtual bool is_language_supported(const String &p_language) const;
169
virtual bool is_script_supported(const String &p_script) const;
170
171
virtual Dictionary get_supported_feature_list() const;
172
virtual Dictionary get_supported_variation_list() const;
173
virtual int64_t get_face_count() const;
174
175
Font();
176
~Font();
177
};
178
179
/*************************************************************************/
180
/* FontFile */
181
/*************************************************************************/
182
183
class FontFile : public Font {
184
GDCLASS(FontFile, Font);
185
RES_BASE_EXTENSION("fontdata");
186
187
// Font source data.
188
const uint8_t *data_ptr = nullptr;
189
size_t data_size = 0;
190
mutable PackedByteArray data;
191
192
TextServer::FontAntialiasing antialiasing = TextServer::FONT_ANTIALIASING_GRAY;
193
bool mipmaps = false;
194
bool disable_embedded_bitmaps = true;
195
bool msdf = false;
196
int msdf_pixel_range = 16;
197
int msdf_size = 48;
198
int fixed_size = 0;
199
TextServer::FixedSizeScaleMode fixed_size_scale_mode = TextServer::FIXED_SIZE_SCALE_DISABLE;
200
bool force_autohinter = false;
201
bool modulate_color_glyphs = false;
202
bool allow_system_fallback = true;
203
TextServer::Hinting hinting = TextServer::HINTING_LIGHT;
204
TextServer::SubpixelPositioning subpixel_positioning = TextServer::SUBPIXEL_POSITIONING_AUTO;
205
bool keep_rounding_remainders = true;
206
double oversampling_override = 0.0;
207
208
#ifndef DISABLE_DEPRECATED
209
real_t bmp_height = 0.0;
210
real_t bmp_ascent = 0.0;
211
#endif
212
213
// Cache.
214
mutable Vector<RID> cache;
215
216
_FORCE_INLINE_ void _clear_cache();
217
_FORCE_INLINE_ void _ensure_rid(int p_cache_index, int p_make_linked_from = -1) const;
218
219
void _convert_packed_8bit(Ref<Image> &p_source, int p_page, int p_sz);
220
void _convert_packed_4bit(Ref<Image> &p_source, int p_page, int p_sz);
221
void _convert_rgba_4bit(Ref<Image> &p_source, int p_page, int p_sz);
222
void _convert_mono_8bit(Ref<Image> &p_source, int p_page, int p_ch, int p_sz, int p_ol);
223
void _convert_mono_4bit(Ref<Image> &p_source, int p_page, int p_ch, int p_sz, int p_ol);
224
225
protected:
226
static void _bind_methods();
227
void _validate_property(PropertyInfo &p_property) const;
228
229
bool _set(const StringName &p_name, const Variant &p_value);
230
bool _get(const StringName &p_name, Variant &r_ret) const;
231
void _get_property_list(List<PropertyInfo> *p_list) const;
232
233
virtual void reset_state() override;
234
235
public:
236
Error _load_bitmap_font(const String &p_path, List<String> *r_image_files);
237
238
Error load_bitmap_font(const String &p_path);
239
Error load_dynamic_font(const String &p_path);
240
241
// Font source data.
242
virtual void set_data_ptr(const uint8_t *p_data, size_t p_size);
243
virtual void set_data(const PackedByteArray &p_data);
244
virtual PackedByteArray get_data() const;
245
246
// Common properties.
247
virtual void set_font_name(const String &p_name);
248
virtual void set_font_style_name(const String &p_name);
249
virtual void set_font_style(BitField<TextServer::FontStyle> p_style);
250
virtual void set_font_weight(int p_weight);
251
virtual void set_font_stretch(int p_stretch);
252
253
virtual void set_antialiasing(TextServer::FontAntialiasing p_antialiasing);
254
virtual TextServer::FontAntialiasing get_antialiasing() const;
255
256
virtual void set_disable_embedded_bitmaps(bool p_disable_embedded_bitmaps);
257
virtual bool get_disable_embedded_bitmaps() const;
258
259
virtual void set_generate_mipmaps(bool p_generate_mipmaps);
260
virtual bool get_generate_mipmaps() const;
261
262
virtual void set_multichannel_signed_distance_field(bool p_msdf);
263
virtual bool is_multichannel_signed_distance_field() const;
264
265
virtual void set_msdf_pixel_range(int p_msdf_pixel_range);
266
virtual int get_msdf_pixel_range() const;
267
268
virtual void set_msdf_size(int p_msdf_size);
269
virtual int get_msdf_size() const;
270
271
virtual void set_fixed_size(int p_fixed_size);
272
virtual int get_fixed_size() const;
273
274
virtual void set_fixed_size_scale_mode(TextServer::FixedSizeScaleMode p_fixed_size_scale_mode);
275
virtual TextServer::FixedSizeScaleMode get_fixed_size_scale_mode() const;
276
277
virtual void set_allow_system_fallback(bool p_allow_system_fallback);
278
virtual bool is_allow_system_fallback() const;
279
280
virtual void set_force_autohinter(bool p_force_autohinter);
281
virtual bool is_force_autohinter() const;
282
283
virtual void set_modulate_color_glyphs(bool p_modulate);
284
virtual bool is_modulate_color_glyphs() const;
285
286
virtual void set_hinting(TextServer::Hinting p_hinting);
287
virtual TextServer::Hinting get_hinting() const;
288
289
virtual void set_subpixel_positioning(TextServer::SubpixelPositioning p_subpixel);
290
virtual TextServer::SubpixelPositioning get_subpixel_positioning() const;
291
292
virtual void set_keep_rounding_remainders(bool p_keep_rounding_remainders);
293
virtual bool get_keep_rounding_remainders() const;
294
295
virtual void set_oversampling(real_t p_oversampling);
296
virtual real_t get_oversampling() const;
297
298
// Cache.
299
virtual RID find_variation(const Dictionary &p_variation_coordinates, int p_face_index = 0, float p_strength = 0.0, Transform2D p_transform = Transform2D(), int p_spacing_top = 0, int p_spacing_bottom = 0, int p_spacing_space = 0, int p_spacing_glyph = 0, float p_baseline_offset = 0.0) const override;
300
virtual RID _get_rid() const override;
301
302
virtual int get_cache_count() const;
303
virtual void clear_cache();
304
virtual void remove_cache(int p_cache_index);
305
306
virtual TypedArray<Vector2i> get_size_cache_list(int p_cache_index) const;
307
virtual void clear_size_cache(int p_cache_index);
308
virtual void remove_size_cache(int p_cache_index, const Vector2i &p_size);
309
310
virtual void set_variation_coordinates(int p_cache_index, const Dictionary &p_variation_coordinates);
311
virtual Dictionary get_variation_coordinates(int p_cache_index) const;
312
313
virtual void set_embolden(int p_cache_index, float p_strength);
314
virtual float get_embolden(int p_cache_index) const;
315
316
virtual void set_transform(int p_cache_index, Transform2D p_transform);
317
virtual Transform2D get_transform(int p_cache_index) const;
318
319
virtual void set_extra_spacing(int p_cache_index, TextServer::SpacingType p_spacing, int64_t p_value);
320
virtual int64_t get_extra_spacing(int p_cache_index, TextServer::SpacingType p_spacing) const;
321
322
virtual float get_extra_baseline_offset(int p_cache_index) const;
323
virtual void set_extra_baseline_offset(int p_cache_index, float p_baseline_offset);
324
325
virtual void set_face_index(int p_cache_index, int64_t p_index);
326
virtual int64_t get_face_index(int p_cache_index) const;
327
328
virtual void set_cache_ascent(int p_cache_index, int p_size, real_t p_ascent);
329
virtual real_t get_cache_ascent(int p_cache_index, int p_size) const;
330
331
virtual void set_cache_descent(int p_cache_index, int p_size, real_t p_descent);
332
virtual real_t get_cache_descent(int p_cache_index, int p_size) const;
333
334
virtual void set_cache_underline_position(int p_cache_index, int p_size, real_t p_underline_position);
335
virtual real_t get_cache_underline_position(int p_cache_index, int p_size) const;
336
337
virtual void set_cache_underline_thickness(int p_cache_index, int p_size, real_t p_underline_thickness);
338
virtual real_t get_cache_underline_thickness(int p_cache_index, int p_size) const;
339
340
virtual void set_cache_scale(int p_cache_index, int p_size, real_t p_scale); // Rendering scale for bitmap fonts (e.g. emoji fonts).
341
virtual real_t get_cache_scale(int p_cache_index, int p_size) const;
342
343
virtual int get_texture_count(int p_cache_index, const Vector2i &p_size) const;
344
virtual void clear_textures(int p_cache_index, const Vector2i &p_size);
345
virtual void remove_texture(int p_cache_index, const Vector2i &p_size, int p_texture_index);
346
347
virtual void set_texture_image(int p_cache_index, const Vector2i &p_size, int p_texture_index, const Ref<Image> &p_image);
348
virtual Ref<Image> get_texture_image(int p_cache_index, const Vector2i &p_size, int p_texture_index) const;
349
350
virtual void set_texture_offsets(int p_cache_index, const Vector2i &p_size, int p_texture_index, const PackedInt32Array &p_offset);
351
virtual PackedInt32Array get_texture_offsets(int p_cache_index, const Vector2i &p_size, int p_texture_index) const;
352
353
virtual PackedInt32Array get_glyph_list(int p_cache_index, const Vector2i &p_size) const;
354
virtual void clear_glyphs(int p_cache_index, const Vector2i &p_size);
355
virtual void remove_glyph(int p_cache_index, const Vector2i &p_size, int32_t p_glyph);
356
357
virtual void set_glyph_advance(int p_cache_index, int p_size, int32_t p_glyph, const Vector2 &p_advance);
358
virtual Vector2 get_glyph_advance(int p_cache_index, int p_size, int32_t p_glyph) const;
359
360
virtual void set_glyph_offset(int p_cache_index, const Vector2i &p_size, int32_t p_glyph, const Vector2 &p_offset);
361
virtual Vector2 get_glyph_offset(int p_cache_index, const Vector2i &p_size, int32_t p_glyph) const;
362
363
virtual void set_glyph_size(int p_cache_index, const Vector2i &p_size, int32_t p_glyph, const Vector2 &p_gl_size);
364
virtual Vector2 get_glyph_size(int p_cache_index, const Vector2i &p_size, int32_t p_glyph) const;
365
366
virtual void set_glyph_uv_rect(int p_cache_index, const Vector2i &p_size, int32_t p_glyph, const Rect2 &p_uv_rect);
367
virtual Rect2 get_glyph_uv_rect(int p_cache_index, const Vector2i &p_size, int32_t p_glyph) const;
368
369
virtual void set_glyph_texture_idx(int p_cache_index, const Vector2i &p_size, int32_t p_glyph, int p_texture_idx);
370
virtual int get_glyph_texture_idx(int p_cache_index, const Vector2i &p_size, int32_t p_glyph) const;
371
372
virtual TypedArray<Vector2i> get_kerning_list(int p_cache_index, int p_size) const;
373
virtual void clear_kerning_map(int p_cache_index, int p_size);
374
virtual void remove_kerning(int p_cache_index, int p_size, const Vector2i &p_glyph_pair);
375
376
virtual void set_kerning(int p_cache_index, int p_size, const Vector2i &p_glyph_pair, const Vector2 &p_kerning);
377
virtual Vector2 get_kerning(int p_cache_index, int p_size, const Vector2i &p_glyph_pair) const;
378
379
virtual void render_range(int p_cache_index, const Vector2i &p_size, char32_t p_start, char32_t p_end);
380
virtual void render_glyph(int p_cache_index, const Vector2i &p_size, int32_t p_index);
381
382
// Language/script support override.
383
virtual void set_language_support_override(const String &p_language, bool p_supported);
384
virtual bool get_language_support_override(const String &p_language) const;
385
virtual void remove_language_support_override(const String &p_language);
386
virtual Vector<String> get_language_support_overrides() const;
387
388
virtual void set_script_support_override(const String &p_script, bool p_supported);
389
virtual bool get_script_support_override(const String &p_script) const;
390
virtual void remove_script_support_override(const String &p_script);
391
virtual Vector<String> get_script_support_overrides() const;
392
393
virtual void set_opentype_feature_overrides(const Dictionary &p_overrides);
394
virtual Dictionary get_opentype_feature_overrides() const;
395
396
// Base font properties.
397
virtual int32_t get_glyph_index(int p_size, char32_t p_char, char32_t p_variation_selector = 0x0000) const;
398
virtual char32_t get_char_from_glyph_index(int p_size, int32_t p_glyph_index) const;
399
400
FontFile();
401
~FontFile();
402
};
403
404
/*************************************************************************/
405
/* FontVariation */
406
/*************************************************************************/
407
408
class FontVariation : public Font {
409
GDCLASS(FontVariation, Font);
410
411
struct Variation {
412
Dictionary opentype;
413
real_t embolden = 0.f;
414
int face_index = 0;
415
Transform2D transform;
416
};
417
418
mutable Ref<Font> theme_font;
419
420
Ref<Font> base_font;
421
422
Variation variation;
423
Dictionary opentype_features;
424
int extra_spacing[TextServer::SPACING_MAX];
425
float baseline_offset = 0.0;
426
427
protected:
428
static void _bind_methods();
429
430
virtual void _update_rids() const override;
431
432
virtual void reset_state() override;
433
434
public:
435
virtual void set_base_font(const Ref<Font> &p_font);
436
virtual Ref<Font> get_base_font() const;
437
virtual Ref<Font> _get_base_font_or_default() const;
438
439
virtual void set_variation_opentype(const Dictionary &p_coords);
440
virtual Dictionary get_variation_opentype() const;
441
442
virtual void set_variation_embolden(float p_strength);
443
virtual float get_variation_embolden() const;
444
445
virtual void set_variation_transform(Transform2D p_transform);
446
virtual Transform2D get_variation_transform() const;
447
448
virtual void set_variation_face_index(int p_face_index);
449
virtual int get_variation_face_index() const;
450
451
virtual void set_opentype_features(const Dictionary &p_features);
452
virtual Dictionary get_opentype_features() const override;
453
454
virtual void set_spacing(TextServer::SpacingType p_spacing, int p_value);
455
virtual int get_spacing(TextServer::SpacingType p_spacing) const override;
456
457
virtual float get_baseline_offset() const;
458
virtual void set_baseline_offset(float p_baseline_offset);
459
460
// Output.
461
virtual RID find_variation(const Dictionary &p_variation_coordinates, int p_face_index = 0, float p_strength = 0.0, Transform2D p_transform = Transform2D(), int p_spacing_top = 0, int p_spacing_bottom = 0, int p_spacing_space = 0, int p_spacing_glyph = 0, float p_baseline_offset = 0.0) const override;
462
virtual RID _get_rid() const override;
463
464
FontVariation();
465
~FontVariation();
466
};
467
468
/*************************************************************************/
469
/* SystemFont */
470
/*************************************************************************/
471
472
class SystemFont : public Font {
473
GDCLASS(SystemFont, Font);
474
475
PackedStringArray names;
476
bool italic = false;
477
int weight = 400;
478
int stretch = 100;
479
480
mutable Ref<Font> theme_font;
481
482
Ref<FontFile> base_font;
483
Vector<int> face_indices;
484
int ftr_weight = 0;
485
int ftr_stretch = 0;
486
int ftr_italic = 0;
487
488
TextServer::FontAntialiasing antialiasing = TextServer::FONT_ANTIALIASING_GRAY;
489
bool mipmaps = false;
490
bool disable_embedded_bitmaps = true;
491
bool force_autohinter = false;
492
bool modulate_color_glyphs = false;
493
bool allow_system_fallback = true;
494
TextServer::Hinting hinting = TextServer::HINTING_LIGHT;
495
TextServer::SubpixelPositioning subpixel_positioning = TextServer::SUBPIXEL_POSITIONING_AUTO;
496
bool keep_rounding_remainders = true;
497
double oversampling_override = 0.0;
498
bool msdf = false;
499
int msdf_pixel_range = 16;
500
int msdf_size = 48;
501
502
protected:
503
static void _bind_methods();
504
505
virtual void _update_base_font();
506
virtual void _update_rids() const override;
507
508
virtual void reset_state() override;
509
510
public:
511
virtual Ref<Font> get_base_font() const { return base_font; }
512
virtual Ref<Font> _get_base_font_or_default() const;
513
514
virtual void set_antialiasing(TextServer::FontAntialiasing p_antialiasing);
515
virtual TextServer::FontAntialiasing get_antialiasing() const;
516
517
virtual void set_disable_embedded_bitmaps(bool p_disable_embedded_bitmaps);
518
virtual bool get_disable_embedded_bitmaps() const;
519
520
virtual void set_generate_mipmaps(bool p_generate_mipmaps);
521
virtual bool get_generate_mipmaps() const;
522
523
virtual void set_allow_system_fallback(bool p_allow_system_fallback);
524
virtual bool is_allow_system_fallback() const;
525
526
virtual void set_force_autohinter(bool p_force_autohinter);
527
virtual bool is_force_autohinter() const;
528
529
virtual void set_modulate_color_glyphs(bool p_modulate);
530
virtual bool is_modulate_color_glyphs() const;
531
532
virtual void set_hinting(TextServer::Hinting p_hinting);
533
virtual TextServer::Hinting get_hinting() const;
534
535
virtual void set_subpixel_positioning(TextServer::SubpixelPositioning p_subpixel);
536
virtual TextServer::SubpixelPositioning get_subpixel_positioning() const;
537
538
virtual void set_keep_rounding_remainders(bool p_keep_rounding_remainders);
539
virtual bool get_keep_rounding_remainders() const;
540
541
virtual void set_oversampling(real_t p_oversampling);
542
virtual real_t get_oversampling() const;
543
544
virtual void set_multichannel_signed_distance_field(bool p_msdf);
545
virtual bool is_multichannel_signed_distance_field() const;
546
547
virtual void set_msdf_pixel_range(int p_msdf_pixel_range);
548
virtual int get_msdf_pixel_range() const;
549
550
virtual void set_msdf_size(int p_msdf_size);
551
virtual int get_msdf_size() const;
552
553
virtual void set_font_names(const PackedStringArray &p_names);
554
virtual PackedStringArray get_font_names() const;
555
556
virtual void set_font_italic(bool p_italic);
557
virtual bool get_font_italic() const;
558
559
virtual void set_font_weight(int p_weight);
560
virtual int get_font_weight() const override;
561
562
virtual void set_font_stretch(int p_stretch);
563
virtual int get_font_stretch() const override;
564
565
virtual int get_spacing(TextServer::SpacingType p_spacing) const override;
566
567
virtual RID find_variation(const Dictionary &p_variation_coordinates, int p_face_index = 0, float p_strength = 0.0, Transform2D p_transform = Transform2D(), int p_spacing_top = 0, int p_spacing_bottom = 0, int p_spacing_space = 0, int p_spacing_glyph = 0, float p_baseline_offset = 0.0) const override;
568
virtual RID _get_rid() const override;
569
570
int64_t get_face_count() const override;
571
572
SystemFont();
573
~SystemFont();
574
};
575
576