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