| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 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/text_server.h" |
| 37 |
|
| 38 |
class TextLine; |
| 39 |
class TextParagraph; |
| 40 |
|
| 41 |
|
| 42 |
|
| 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 |
|
| 84 |
mutable LRUCache<ShapedTextKey, Ref<TextLine>, ShapedTextKeyHasher> cache; |
| 85 |
mutable LRUCache<ShapedTextKey, Ref<TextParagraph>, ShapedTextKeyHasher> cache_wrap; |
| 86 |
|
| 87 |
protected: |
| 88 |
|
| 89 |
mutable TypedArray<RID> rids; |
| 90 |
mutable bool dirty_rids = true; |
| 91 |
|
| 92 |
|
| 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 |
|
| 122 |
virtual void set_fallbacks(const TypedArray<Font> &p_fallbacks); |
| 123 |
virtual TypedArray<Font> get_fallbacks() const; |
| 124 |
|
| 125 |
|
| 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 |
|
| 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 |
|
| 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 |
|
| 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 |
|
| 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 |
|
| 181 |
|
| 182 |
|
| 183 |
class FontFile : public Font { |
| 184 |
GDCLASS(FontFile, Font); |
| 185 |
RES_BASE_EXTENSION("fontdata"); |
| 186 |
|
| 187 |
|
| 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 |
HashMap<String, bool> language_support_overrides; |
| 209 |
HashMap<String, bool> script_support_overrides; |
| 210 |
Dictionary feature_overrides; |
| 211 |
|
| 212 |
#ifndef DISABLE_DEPRECATED |
| 213 |
real_t bmp_height = 0.0; |
| 214 |
real_t bmp_ascent = 0.0; |
| 215 |
#endif |
| 216 |
|
| 217 |
|
| 218 |
mutable Vector<RID> cache; |
| 219 |
|
| 220 |
_FORCE_INLINE_ void _clear_cache(); |
| 221 |
_FORCE_INLINE_ void _ensure_rid(int p_cache_index, int p_make_linked_from = -1) const; |
| 222 |
|
| 223 |
void _convert_packed_8bit(Ref<Image> &p_source, int p_page, int p_sz); |
| 224 |
void _convert_packed_4bit(Ref<Image> &p_source, int p_page, int p_sz); |
| 225 |
void _convert_rgba_4bit(Ref<Image> &p_source, int p_page, int p_sz); |
| 226 |
void _convert_mono_8bit(Ref<Image> &p_source, int p_page, int p_ch, int p_sz, int p_ol); |
| 227 |
void _convert_mono_4bit(Ref<Image> &p_source, int p_page, int p_ch, int p_sz, int p_ol); |
| 228 |
|
| 229 |
protected: |
| 230 |
static void _bind_methods(); |
| 231 |
void _validate_property(PropertyInfo &p_property) const; |
| 232 |
|
| 233 |
bool _set(const StringName &p_name, const Variant &p_value); |
| 234 |
bool _get(const StringName &p_name, Variant &r_ret) const; |
| 235 |
void _get_property_list(List<PropertyInfo> *p_list) const; |
| 236 |
|
| 237 |
virtual void reset_state() override; |
| 238 |
|
| 239 |
public: |
| 240 |
Error _load_bitmap_font(const String &p_path, List<String> *r_image_files); |
| 241 |
|
| 242 |
Error load_bitmap_font(const String &p_path); |
| 243 |
Error load_dynamic_font(const String &p_path); |
| 244 |
|
| 245 |
|
| 246 |
virtual void set_data_ptr(const uint8_t *p_data, size_t p_size); |
| 247 |
virtual void set_data(const PackedByteArray &p_data); |
| 248 |
virtual PackedByteArray get_data() const; |
| 249 |
|
| 250 |
|
| 251 |
virtual void set_font_name(const String &p_name); |
| 252 |
virtual void set_font_style_name(const String &p_name); |
| 253 |
virtual void set_font_style(BitField<TextServer::FontStyle> p_style); |
| 254 |
virtual void set_font_weight(int p_weight); |
| 255 |
virtual void set_font_stretch(int p_stretch); |
| 256 |
|
| 257 |
virtual void set_antialiasing(TextServer::FontAntialiasing p_antialiasing); |
| 258 |
virtual TextServer::FontAntialiasing get_antialiasing() const; |
| 259 |
|
| 260 |
virtual void set_disable_embedded_bitmaps(bool p_disable_embedded_bitmaps); |
| 261 |
virtual bool get_disable_embedded_bitmaps() const; |
| 262 |
|
| 263 |
virtual void set_generate_mipmaps(bool p_generate_mipmaps); |
| 264 |
virtual bool get_generate_mipmaps() const; |
| 265 |
|
| 266 |
virtual void set_multichannel_signed_distance_field(bool p_msdf); |
| 267 |
virtual bool is_multichannel_signed_distance_field() const; |
| 268 |
|
| 269 |
virtual void set_msdf_pixel_range(int p_msdf_pixel_range); |
| 270 |
virtual int get_msdf_pixel_range() const; |
| 271 |
|
| 272 |
virtual void set_msdf_size(int p_msdf_size); |
| 273 |
virtual int get_msdf_size() const; |
| 274 |
|
| 275 |
virtual void set_fixed_size(int p_fixed_size); |
| 276 |
virtual int get_fixed_size() const; |
| 277 |
|
| 278 |
virtual void set_fixed_size_scale_mode(TextServer::FixedSizeScaleMode p_fixed_size_scale_mode); |
| 279 |
virtual TextServer::FixedSizeScaleMode get_fixed_size_scale_mode() const; |
| 280 |
|
| 281 |
virtual void set_allow_system_fallback(bool p_allow_system_fallback); |
| 282 |
virtual bool is_allow_system_fallback() const; |
| 283 |
|
| 284 |
virtual void set_force_autohinter(bool p_force_autohinter); |
| 285 |
virtual bool is_force_autohinter() const; |
| 286 |
|
| 287 |
virtual void set_modulate_color_glyphs(bool p_modulate); |
| 288 |
virtual bool is_modulate_color_glyphs() const; |
| 289 |
|
| 290 |
virtual void set_hinting(TextServer::Hinting p_hinting); |
| 291 |
virtual TextServer::Hinting get_hinting() const; |
| 292 |
|
| 293 |
virtual void set_subpixel_positioning(TextServer::SubpixelPositioning p_subpixel); |
| 294 |
virtual TextServer::SubpixelPositioning get_subpixel_positioning() const; |
| 295 |
|
| 296 |
virtual void set_keep_rounding_remainders(bool p_keep_rounding_remainders); |
| 297 |
virtual bool get_keep_rounding_remainders() const; |
| 298 |
|
| 299 |
virtual void set_oversampling(real_t p_oversampling); |
| 300 |
virtual real_t get_oversampling() const; |
| 301 |
|
| 302 |
|
| 303 |
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; |
| 304 |
virtual RID _get_rid() const override; |
| 305 |
|
| 306 |
virtual int get_cache_count() const; |
| 307 |
virtual void clear_cache(); |
| 308 |
virtual void remove_cache(int p_cache_index); |
| 309 |
|
| 310 |
virtual TypedArray<Vector2i> get_size_cache_list(int p_cache_index) const; |
| 311 |
virtual void clear_size_cache(int p_cache_index); |
| 312 |
virtual void remove_size_cache(int p_cache_index, const Vector2i &p_size); |
| 313 |
|
| 314 |
virtual void set_variation_coordinates(int p_cache_index, const Dictionary &p_variation_coordinates); |
| 315 |
virtual Dictionary get_variation_coordinates(int p_cache_index) const; |
| 316 |
|
| 317 |
virtual void set_embolden(int p_cache_index, float p_strength); |
| 318 |
virtual float get_embolden(int p_cache_index) const; |
| 319 |
|
| 320 |
virtual void set_transform(int p_cache_index, Transform2D p_transform); |
| 321 |
virtual Transform2D get_transform(int p_cache_index) const; |
| 322 |
|
| 323 |
virtual void set_extra_spacing(int p_cache_index, TextServer::SpacingType p_spacing, int64_t p_value); |
| 324 |
virtual int64_t get_extra_spacing(int p_cache_index, TextServer::SpacingType p_spacing) const; |
| 325 |
|
| 326 |
virtual float get_extra_baseline_offset(int p_cache_index) const; |
| 327 |
virtual void set_extra_baseline_offset(int p_cache_index, float p_baseline_offset); |
| 328 |
|
| 329 |
virtual void set_face_index(int p_cache_index, int64_t p_index); |
| 330 |
virtual int64_t get_face_index(int p_cache_index) const; |
| 331 |
|
| 332 |
virtual void set_cache_ascent(int p_cache_index, int p_size, real_t p_ascent); |
| 333 |
virtual real_t get_cache_ascent(int p_cache_index, int p_size) const; |
| 334 |
|
| 335 |
virtual void set_cache_descent(int p_cache_index, int p_size, real_t p_descent); |
| 336 |
virtual real_t get_cache_descent(int p_cache_index, int p_size) const; |
| 337 |
|
| 338 |
virtual void set_cache_underline_position(int p_cache_index, int p_size, real_t p_underline_position); |
| 339 |
virtual real_t get_cache_underline_position(int p_cache_index, int p_size) const; |
| 340 |
|
| 341 |
virtual void set_cache_underline_thickness(int p_cache_index, int p_size, real_t p_underline_thickness); |
| 342 |
virtual real_t get_cache_underline_thickness(int p_cache_index, int p_size) const; |
| 343 |
|
| 344 |
virtual void set_cache_scale(int p_cache_index, int p_size, real_t p_scale); |
| 345 |
virtual real_t get_cache_scale(int p_cache_index, int p_size) const; |
| 346 |
|
| 347 |
virtual int get_texture_count(int p_cache_index, const Vector2i &p_size) const; |
| 348 |
virtual void clear_textures(int p_cache_index, const Vector2i &p_size); |
| 349 |
virtual void remove_texture(int p_cache_index, const Vector2i &p_size, int p_texture_index); |
| 350 |
|
| 351 |
virtual void set_texture_image(int p_cache_index, const Vector2i &p_size, int p_texture_index, const Ref<Image> &p_image); |
| 352 |
virtual Ref<Image> get_texture_image(int p_cache_index, const Vector2i &p_size, int p_texture_index) const; |
| 353 |
|
| 354 |
virtual void set_texture_offsets(int p_cache_index, const Vector2i &p_size, int p_texture_index, const PackedInt32Array &p_offset); |
| 355 |
virtual PackedInt32Array get_texture_offsets(int p_cache_index, const Vector2i &p_size, int p_texture_index) const; |
| 356 |
|
| 357 |
virtual PackedInt32Array get_glyph_list(int p_cache_index, const Vector2i &p_size) const; |
| 358 |
virtual void clear_glyphs(int p_cache_index, const Vector2i &p_size); |
| 359 |
virtual void remove_glyph(int p_cache_index, const Vector2i &p_size, int32_t p_glyph); |
| 360 |
|
| 361 |
virtual void set_glyph_advance(int p_cache_index, int p_size, int32_t p_glyph, const Vector2 &p_advance); |
| 362 |
virtual Vector2 get_glyph_advance(int p_cache_index, int p_size, int32_t p_glyph) const; |
| 363 |
|
| 364 |
virtual void set_glyph_offset(int p_cache_index, const Vector2i &p_size, int32_t p_glyph, const Vector2 &p_offset); |
| 365 |
virtual Vector2 get_glyph_offset(int p_cache_index, const Vector2i &p_size, int32_t p_glyph) const; |
| 366 |
|
| 367 |
virtual void set_glyph_size(int p_cache_index, const Vector2i &p_size, int32_t p_glyph, const Vector2 &p_gl_size); |
| 368 |
virtual Vector2 get_glyph_size(int p_cache_index, const Vector2i &p_size, int32_t p_glyph) const; |
| 369 |
|
| 370 |
virtual void set_glyph_uv_rect(int p_cache_index, const Vector2i &p_size, int32_t p_glyph, const Rect2 &p_uv_rect); |
| 371 |
virtual Rect2 get_glyph_uv_rect(int p_cache_index, const Vector2i &p_size, int32_t p_glyph) const; |
| 372 |
|
| 373 |
virtual void set_glyph_texture_idx(int p_cache_index, const Vector2i &p_size, int32_t p_glyph, int p_texture_idx); |
| 374 |
virtual int get_glyph_texture_idx(int p_cache_index, const Vector2i &p_size, int32_t p_glyph) const; |
| 375 |
|
| 376 |
virtual TypedArray<Vector2i> get_kerning_list(int p_cache_index, int p_size) const; |
| 377 |
virtual void clear_kerning_map(int p_cache_index, int p_size); |
| 378 |
virtual void remove_kerning(int p_cache_index, int p_size, const Vector2i &p_glyph_pair); |
| 379 |
|
| 380 |
virtual void set_kerning(int p_cache_index, int p_size, const Vector2i &p_glyph_pair, const Vector2 &p_kerning); |
| 381 |
virtual Vector2 get_kerning(int p_cache_index, int p_size, const Vector2i &p_glyph_pair) const; |
| 382 |
|
| 383 |
virtual void render_range(int p_cache_index, const Vector2i &p_size, char32_t p_start, char32_t p_end); |
| 384 |
virtual void render_glyph(int p_cache_index, const Vector2i &p_size, int32_t p_index); |
| 385 |
|
| 386 |
|
| 387 |
virtual void set_language_support_override(const String &p_language, bool p_supported); |
| 388 |
virtual bool get_language_support_override(const String &p_language) const; |
| 389 |
virtual void remove_language_support_override(const String &p_language); |
| 390 |
virtual Vector<String> get_language_support_overrides() const; |
| 391 |
|
| 392 |
virtual void set_script_support_override(const String &p_script, bool p_supported); |
| 393 |
virtual bool get_script_support_override(const String &p_script) const; |
| 394 |
virtual void remove_script_support_override(const String &p_script); |
| 395 |
virtual Vector<String> get_script_support_overrides() const; |
| 396 |
|
| 397 |
virtual void set_opentype_feature_overrides(const Dictionary &p_overrides); |
| 398 |
virtual Dictionary get_opentype_feature_overrides() const; |
| 399 |
|
| 400 |
|
| 401 |
virtual int32_t get_glyph_index(int p_size, char32_t p_char, char32_t p_variation_selector = 0x0000) const; |
| 402 |
virtual char32_t get_char_from_glyph_index(int p_size, int32_t p_glyph_index) const; |
| 403 |
|
| 404 |
FontFile(); |
| 405 |
~FontFile(); |
| 406 |
}; |
| 407 |
|
| 408 |
|
| 409 |
|
| 410 |
|
| 411 |
|
| 412 |
class FontVariation : public Font { |
| 413 |
GDCLASS(FontVariation, Font); |
| 414 |
|
| 415 |
struct Variation { |
| 416 |
Dictionary opentype; |
| 417 |
real_t embolden = 0.f; |
| 418 |
int face_index = 0; |
| 419 |
Transform2D transform; |
| 420 |
}; |
| 421 |
|
| 422 |
mutable Ref<Font> theme_font; |
| 423 |
|
| 424 |
Ref<Font> base_font; |
| 425 |
|
| 426 |
Variation variation; |
| 427 |
Dictionary opentype_features; |
| 428 |
int extra_spacing[TextServer::SPACING_MAX]; |
| 429 |
float baseline_offset = 0.0; |
| 430 |
|
| 431 |
protected: |
| 432 |
static void _bind_methods(); |
| 433 |
|
| 434 |
virtual void _update_rids() const override; |
| 435 |
|
| 436 |
virtual void reset_state() override; |
| 437 |
|
| 438 |
public: |
| 439 |
virtual void set_base_font(const Ref<Font> &p_font); |
| 440 |
virtual Ref<Font> get_base_font() const; |
| 441 |
virtual Ref<Font> _get_base_font_or_default() const; |
| 442 |
|
| 443 |
virtual void set_variation_opentype(const Dictionary &p_coords); |
| 444 |
virtual Dictionary get_variation_opentype() const; |
| 445 |
|
| 446 |
virtual void set_variation_embolden(float p_strength); |
| 447 |
virtual float get_variation_embolden() const; |
| 448 |
|
| 449 |
virtual void set_variation_transform(Transform2D p_transform); |
| 450 |
virtual Transform2D get_variation_transform() const; |
| 451 |
|
| 452 |
virtual void set_variation_face_index(int p_face_index); |
| 453 |
virtual int get_variation_face_index() const; |
| 454 |
|
| 455 |
virtual void set_opentype_features(const Dictionary &p_features); |
| 456 |
virtual Dictionary get_opentype_features() const override; |
| 457 |
|
| 458 |
virtual void set_spacing(TextServer::SpacingType p_spacing, int p_value); |
| 459 |
virtual int get_spacing(TextServer::SpacingType p_spacing) const override; |
| 460 |
|
| 461 |
virtual float get_baseline_offset() const; |
| 462 |
virtual void set_baseline_offset(float p_baseline_offset); |
| 463 |
|
| 464 |
|
| 465 |
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; |
| 466 |
virtual RID _get_rid() const override; |
| 467 |
|
| 468 |
FontVariation(); |
| 469 |
~FontVariation(); |
| 470 |
}; |
| 471 |
|
| 472 |
|
| 473 |
|
| 474 |
|
| 475 |
|
| 476 |
class SystemFont : public Font { |
| 477 |
GDCLASS(SystemFont, Font); |
| 478 |
|
| 479 |
PackedStringArray names; |
| 480 |
bool italic = false; |
| 481 |
int weight = 400; |
| 482 |
int stretch = 100; |
| 483 |
|
| 484 |
mutable Ref<Font> theme_font; |
| 485 |
|
| 486 |
Ref<FontFile> base_font; |
| 487 |
Vector<int> face_indices; |
| 488 |
int ftr_weight = 0; |
| 489 |
int ftr_stretch = 0; |
| 490 |
int ftr_italic = 0; |
| 491 |
|
| 492 |
TextServer::FontAntialiasing antialiasing = TextServer::FONT_ANTIALIASING_GRAY; |
| 493 |
bool mipmaps = false; |
| 494 |
bool disable_embedded_bitmaps = true; |
| 495 |
bool force_autohinter = false; |
| 496 |
bool modulate_color_glyphs = false; |
| 497 |
bool allow_system_fallback = true; |
| 498 |
TextServer::Hinting hinting = TextServer::HINTING_LIGHT; |
| 499 |
TextServer::SubpixelPositioning subpixel_positioning = TextServer::SUBPIXEL_POSITIONING_AUTO; |
| 500 |
bool keep_rounding_remainders = true; |
| 501 |
double oversampling_override = 0.0; |
| 502 |
bool msdf = false; |
| 503 |
int msdf_pixel_range = 16; |
| 504 |
int msdf_size = 48; |
| 505 |
|
| 506 |
protected: |
| 507 |
static void _bind_methods(); |
| 508 |
|
| 509 |
virtual void _update_base_font(); |
| 510 |
virtual void _update_rids() const override; |
| 511 |
|
| 512 |
virtual void reset_state() override; |
| 513 |
|
| 514 |
public: |
| 515 |
virtual Ref<Font> get_base_font() const { return base_font; } |
| 516 |
virtual Ref<Font> _get_base_font_or_default() const; |
| 517 |
|
| 518 |
virtual void set_antialiasing(TextServer::FontAntialiasing p_antialiasing); |
| 519 |
virtual TextServer::FontAntialiasing get_antialiasing() const; |
| 520 |
|
| 521 |
virtual void set_disable_embedded_bitmaps(bool p_disable_embedded_bitmaps); |
| 522 |
virtual bool get_disable_embedded_bitmaps() const; |
| 523 |
|
| 524 |
virtual void set_generate_mipmaps(bool p_generate_mipmaps); |
| 525 |
virtual bool get_generate_mipmaps() const; |
| 526 |
|
| 527 |
virtual void set_allow_system_fallback(bool p_allow_system_fallback); |
| 528 |
virtual bool is_allow_system_fallback() const; |
| 529 |
|
| 530 |
virtual void set_force_autohinter(bool p_force_autohinter); |
| 531 |
virtual bool is_force_autohinter() const; |
| 532 |
|
| 533 |
virtual void set_modulate_color_glyphs(bool p_modulate); |
| 534 |
virtual bool is_modulate_color_glyphs() const; |
| 535 |
|
| 536 |
virtual void set_hinting(TextServer::Hinting p_hinting); |
| 537 |
virtual TextServer::Hinting get_hinting() const; |
| 538 |
|
| 539 |
virtual void set_subpixel_positioning(TextServer::SubpixelPositioning p_subpixel); |
| 540 |
virtual TextServer::SubpixelPositioning get_subpixel_positioning() const; |
| 541 |
|
| 542 |
virtual void set_keep_rounding_remainders(bool p_keep_rounding_remainders); |
| 543 |
virtual bool get_keep_rounding_remainders() const; |
| 544 |
|
| 545 |
virtual void set_oversampling(real_t p_oversampling); |
| 546 |
virtual real_t get_oversampling() const; |
| 547 |
|
| 548 |
virtual void set_multichannel_signed_distance_field(bool p_msdf); |
| 549 |
virtual bool is_multichannel_signed_distance_field() const; |
| 550 |
|
| 551 |
virtual void set_msdf_pixel_range(int p_msdf_pixel_range); |
| 552 |
virtual int get_msdf_pixel_range() const; |
| 553 |
|
| 554 |
virtual void set_msdf_size(int p_msdf_size); |
| 555 |
virtual int get_msdf_size() const; |
| 556 |
|
| 557 |
virtual void set_font_names(const PackedStringArray &p_names); |
| 558 |
virtual PackedStringArray get_font_names() const; |
| 559 |
|
| 560 |
virtual void set_font_italic(bool p_italic); |
| 561 |
virtual bool get_font_italic() const; |
| 562 |
|
| 563 |
virtual void set_font_weight(int p_weight); |
| 564 |
virtual int get_font_weight() const override; |
| 565 |
|
| 566 |
virtual void set_font_stretch(int p_stretch); |
| 567 |
virtual int get_font_stretch() const override; |
| 568 |
|
| 569 |
virtual int get_spacing(TextServer::SpacingType p_spacing) const override; |
| 570 |
|
| 571 |
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; |
| 572 |
virtual RID _get_rid() const override; |
| 573 |
|
| 574 |
int64_t get_face_count() const override; |
| 575 |
|
| 576 |
SystemFont(); |
| 577 |
~SystemFont(); |
| 578 |
}; |