diff options
Diffstat (limited to 'servers/text_server.h')
-rw-r--r-- | servers/text_server.h | 221 |
1 files changed, 140 insertions, 81 deletions
diff --git a/servers/text_server.h b/servers/text_server.h index 26993838a3..62e02e3c97 100644 --- a/servers/text_server.h +++ b/servers/text_server.h @@ -116,6 +116,13 @@ public: CONTOUR_CURVE_TAG_OFF_CUBIC = 0x02 }; + enum SpacingType { + SPACING_GLYPH, + SPACING_SPACE, + SPACING_TOP, + SPACING_BOTTOM, + }; + struct Glyph { int start = -1; // Start offset in the source string. int end = -1; // End offset in the source string. @@ -124,13 +131,13 @@ public: uint8_t repeat = 1; // Draw multiple times in the row. uint16_t flags = 0; // Grapheme flags (valid, rtl, virtual), set in the first glyph only. - float x_off = 0.f; // Offset from the origin of the glyph on baseline. - float y_off = 0.f; - float advance = 0.f; // Advance to the next glyph along baseline(x for horizontal layout, y for vertical). + real_t x_off = 0.f; // Offset from the origin of the glyph on baseline. + real_t y_off = 0.f; + real_t advance = 0.f; // Advance to the next glyph along baseline(x for horizontal layout, y for vertical). RID font_rid; // Font resource. int font_size = 0; // Font size; - uint32_t index = 0; // Glyph index (font specific) or UTF-32 codepoint (for the invalid glyphs). + int32_t index = 0; // Glyph index (font specific) or UTF-32 codepoint (for the invalid glyphs). bool operator==(const Glyph &p_a) const; bool operator!=(const Glyph &p_a) const; @@ -163,6 +170,8 @@ public: }; struct ShapedTextData { + Mutex mutex; + /* Source data */ RID parent; // Substring parent ShapedTextData. @@ -205,13 +214,13 @@ public: bool preserve_invalid = true; // Draw hex code box instead of missing characters. bool preserve_control = false; // Draw control characters. - float ascent = 0.f; // Ascent for horizontal layout, 1/2 of width for vertical. - float descent = 0.f; // Descent for horizontal layout, 1/2 of width for vertical. - float width = 0.f; // Width for horizontal layout, height for vertical. - float width_trimmed = 0.f; + real_t ascent = 0.f; // Ascent for horizontal layout, 1/2 of width for vertical. + real_t descent = 0.f; // Descent for horizontal layout, 1/2 of width for vertical. + real_t width = 0.f; // Width for horizontal layout, height for vertical. + real_t width_trimmed = 0.f; - float upos = 0.f; - float uthk = 0.f; + real_t upos = 0.f; + real_t uthk = 0.f; TrimData overrun_trim_data; bool fit_width_minimum_reached = false; @@ -245,85 +254,134 @@ public: virtual bool is_locale_right_to_left(const String &p_locale) = 0; - virtual int32_t name_to_tag(const String &p_name) { return 0; }; - virtual String tag_to_name(int32_t p_tag) { return ""; }; + virtual int32_t name_to_tag(const String &p_name) const { return 0; }; + virtual String tag_to_name(int32_t p_tag) const { return ""; }; /* Font interface */ - virtual RID create_font_system(const String &p_name, int p_base_size = 16) = 0; - virtual RID create_font_resource(const String &p_filename, int p_base_size = 16) = 0; - virtual RID create_font_memory(const uint8_t *p_data, size_t p_size, const String &p_type, int p_base_size = 16) = 0; - virtual RID create_font_bitmap(float p_height, float p_ascent, int p_base_size = 16) = 0; + virtual RID create_font() = 0; + + virtual void font_set_data(RID p_font_rid, const PackedByteArray &p_data) = 0; + virtual void font_set_data_ptr(RID p_font_rid, const uint8_t *p_data_ptr, size_t p_data_size) = 0; + + virtual void font_set_antialiased(RID p_font_rid, bool p_antialiased) = 0; + virtual bool font_is_antialiased(RID p_font_rid) const = 0; + + virtual void font_set_multichannel_signed_distance_field(RID p_font_rid, bool p_msdf) = 0; + virtual bool font_is_multichannel_signed_distance_field(RID p_font_rid) const = 0; + + virtual void font_set_msdf_pixel_range(RID p_font_rid, int p_msdf_pixel_range) = 0; + virtual int font_get_msdf_pixel_range(RID p_font_rid) const = 0; + + virtual void font_set_msdf_size(RID p_font_rid, int p_msdf_size) = 0; + virtual int font_get_msdf_size(RID p_font_rid) const = 0; + + virtual void font_set_fixed_size(RID p_font_rid, int p_fixed_size) = 0; + virtual int font_get_fixed_size(RID p_font_rid) const = 0; + + virtual void font_set_force_autohinter(RID p_font_rid, bool p_force_autohinter) = 0; + virtual bool font_is_force_autohinter(RID p_font_rid) const = 0; + + virtual void font_set_hinting(RID p_font_rid, TextServer::Hinting p_hinting) = 0; + virtual TextServer::Hinting font_get_hinting(RID p_font_rid) const = 0; - virtual void font_bitmap_add_texture(RID p_font, const Ref<Texture> &p_texture) = 0; - virtual void font_bitmap_add_char(RID p_font, char32_t p_char, int p_texture_idx, const Rect2 &p_rect, const Size2 &p_align, float p_advance) = 0; - virtual void font_bitmap_add_kerning_pair(RID p_font, char32_t p_A, char32_t p_B, int p_kerning) = 0; + virtual void font_set_variation_coordinates(RID p_font_rid, const Dictionary &p_variation_coordinates) = 0; + virtual Dictionary font_get_variation_coordinates(RID p_font_rid) const = 0; - virtual float font_get_height(RID p_font, int p_size) const = 0; - virtual float font_get_ascent(RID p_font, int p_size) const = 0; - virtual float font_get_descent(RID p_font, int p_size) const = 0; + virtual void font_set_oversampling(RID p_font_rid, real_t p_oversampling) = 0; + virtual real_t font_get_oversampling(RID p_font_rid) const = 0; - virtual int font_get_spacing_space(RID p_font) const = 0; - virtual void font_set_spacing_space(RID p_font, int p_value) = 0; + virtual Array font_get_size_cache_list(RID p_font_rid) const = 0; + virtual void font_clear_size_cache(RID p_font_rid) = 0; + virtual void font_remove_size_cache(RID p_font_rid, const Vector2i &p_size) = 0; - virtual int font_get_spacing_glyph(RID p_font) const = 0; - virtual void font_set_spacing_glyph(RID p_font, int p_value) = 0; + virtual void font_set_ascent(RID p_font_rid, int p_size, real_t p_ascent) = 0; + virtual real_t font_get_ascent(RID p_font_rid, int p_size) const = 0; - virtual float font_get_underline_position(RID p_font, int p_size) const = 0; - virtual float font_get_underline_thickness(RID p_font, int p_size) const = 0; + virtual void font_set_descent(RID p_font_rid, int p_size, real_t p_descent) = 0; + virtual real_t font_get_descent(RID p_font_rid, int p_size) const = 0; - virtual void font_set_antialiased(RID p_font, bool p_antialiased) = 0; - virtual bool font_get_antialiased(RID p_font) const = 0; + virtual void font_set_underline_position(RID p_font_rid, int p_size, real_t p_underline_position) = 0; + virtual real_t font_get_underline_position(RID p_font_rid, int p_size) const = 0; - virtual Dictionary font_get_feature_list(RID p_font) const { return Dictionary(); }; - virtual Dictionary font_get_variation_list(RID p_font) const { return Dictionary(); }; + virtual void font_set_underline_thickness(RID p_font_rid, int p_size, real_t p_underline_thickness) = 0; + virtual real_t font_get_underline_thickness(RID p_font_rid, int p_size) const = 0; - virtual void font_set_variation(RID p_font, const String &p_name, double p_value){}; - virtual double font_get_variation(RID p_font, const String &p_name) const { return 0; }; + virtual void font_set_scale(RID p_font_rid, int p_size, real_t p_scale) = 0; + virtual real_t font_get_scale(RID p_font_rid, int p_size) const = 0; - virtual void font_set_distance_field_hint(RID p_font, bool p_distance_field) = 0; - virtual bool font_get_distance_field_hint(RID p_font) const = 0; + virtual void font_set_spacing(RID p_font_rid, int p_size, SpacingType p_spacing, int p_value) = 0; + virtual int font_get_spacing(RID p_font_rid, int p_size, SpacingType p_spacing) const = 0; - virtual void font_set_hinting(RID p_font, Hinting p_hinting) = 0; - virtual Hinting font_get_hinting(RID p_font) const = 0; + virtual int font_get_texture_count(RID p_font_rid, const Vector2i &p_size) const = 0; + virtual void font_clear_textures(RID p_font_rid, const Vector2i &p_size) = 0; + virtual void font_remove_texture(RID p_font_rid, const Vector2i &p_size, int p_texture_index) = 0; - virtual void font_set_force_autohinter(RID p_font, bool p_enabeld) = 0; - virtual bool font_get_force_autohinter(RID p_font) const = 0; + virtual void font_set_texture_image(RID p_font_rid, const Vector2i &p_size, int p_texture_index, const Ref<Image> &p_image) = 0; + virtual Ref<Image> font_get_texture_image(RID p_font_rid, const Vector2i &p_size, int p_texture_index) const = 0; - virtual bool font_has_char(RID p_font, char32_t p_char) const = 0; - virtual String font_get_supported_chars(RID p_font) const = 0; + virtual void font_set_texture_offsets(RID p_font_rid, const Vector2i &p_size, int p_texture_index, const PackedInt32Array &p_offset) = 0; + virtual PackedInt32Array font_get_texture_offsets(RID p_font_rid, const Vector2i &p_size, int p_texture_index) const = 0; - virtual bool font_has_outline(RID p_font) const = 0; - virtual float font_get_base_size(RID p_font) const = 0; + virtual Array font_get_glyph_list(RID p_font_rid, const Vector2i &p_size) const = 0; + virtual void font_clear_glyphs(RID p_font_rid, const Vector2i &p_size) = 0; + virtual void font_remove_glyph(RID p_font_rid, const Vector2i &p_size, int32_t p_glyph) = 0; - virtual bool font_is_language_supported(RID p_font, const String &p_language) const = 0; - virtual void font_set_language_support_override(RID p_font, const String &p_language, bool p_supported) = 0; - virtual bool font_get_language_support_override(RID p_font, const String &p_language) = 0; - virtual void font_remove_language_support_override(RID p_font, const String &p_language) = 0; - virtual Vector<String> font_get_language_support_overrides(RID p_font) = 0; + virtual Vector2 font_get_glyph_advance(RID p_font_rid, int p_size, int32_t p_glyph) const = 0; + virtual void font_set_glyph_advance(RID p_font_rid, int p_size, int32_t p_glyph, const Vector2 &p_advance) = 0; - virtual bool font_is_script_supported(RID p_font, const String &p_script) const = 0; - virtual void font_set_script_support_override(RID p_font, const String &p_script, bool p_supported) = 0; - virtual bool font_get_script_support_override(RID p_font, const String &p_script) = 0; - virtual void font_remove_script_support_override(RID p_font, const String &p_script) = 0; - virtual Vector<String> font_get_script_support_overrides(RID p_font) = 0; + virtual Vector2 font_get_glyph_offset(RID p_font_rid, const Vector2i &p_size, int32_t p_glyph) const = 0; + virtual void font_set_glyph_offset(RID p_font_rid, const Vector2i &p_size, int32_t p_glyph, const Vector2 &p_offset) = 0; - virtual uint32_t font_get_glyph_index(RID p_font, char32_t p_char, char32_t p_variation_selector = 0x0000) const = 0; - virtual Vector2 font_get_glyph_advance(RID p_font, uint32_t p_index, int p_size) const = 0; - virtual Vector2 font_get_glyph_kerning(RID p_font, uint32_t p_index_a, uint32_t p_index_b, int p_size) const = 0; + virtual Vector2 font_get_glyph_size(RID p_font_rid, const Vector2i &p_size, int32_t p_glyph) const = 0; + virtual void font_set_glyph_size(RID p_font_rid, const Vector2i &p_size, int32_t p_glyph, const Vector2 &p_gl_size) = 0; - virtual Vector2 font_draw_glyph(RID p_font, RID p_canvas, int p_size, const Vector2 &p_pos, uint32_t p_index, const Color &p_color = Color(1, 1, 1)) const = 0; - virtual Vector2 font_draw_glyph_outline(RID p_font, RID p_canvas, int p_size, int p_outline_size, const Vector2 &p_pos, uint32_t p_index, const Color &p_color = Color(1, 1, 1)) const = 0; + virtual Rect2 font_get_glyph_uv_rect(RID p_font_rid, const Vector2i &p_size, int32_t p_glyph) const = 0; + virtual void font_set_glyph_uv_rect(RID p_font_rid, const Vector2i &p_size, int32_t p_glyph, const Rect2 &p_uv_rect) = 0; - virtual bool font_get_glyph_contours(RID p_font, int p_size, uint32_t p_index, Vector<Vector3> &r_points, Vector<int32_t> &r_contours, bool &r_orientation) const = 0; + virtual int font_get_glyph_texture_idx(RID p_font_rid, const Vector2i &p_size, int32_t p_glyph) const = 0; + virtual void font_set_glyph_texture_idx(RID p_font_rid, const Vector2i &p_size, int32_t p_glyph, int p_texture_idx) = 0; - virtual float font_get_oversampling() const = 0; - virtual void font_set_oversampling(float p_oversampling) = 0; + virtual bool font_get_glyph_contours(RID p_font, int p_size, int32_t p_index, Vector<Vector3> &r_points, Vector<int32_t> &r_contours, bool &r_orientation) const = 0; + + virtual Array font_get_kerning_list(RID p_font_rid, int p_size) const = 0; + virtual void font_clear_kerning_map(RID p_font_rid, int p_size) = 0; + virtual void font_remove_kerning(RID p_font_rid, int p_size, const Vector2i &p_glyph_pair) = 0; + + virtual void font_set_kerning(RID p_font_rid, int p_size, const Vector2i &p_glyph_pair, const Vector2 &p_kerning) = 0; + virtual Vector2 font_get_kerning(RID p_font_rid, int p_size, const Vector2i &p_glyph_pair) const = 0; + + virtual int32_t font_get_glyph_index(RID p_font_rid, int p_size, char32_t p_char, char32_t p_variation_selector) const = 0; + + virtual bool font_has_char(RID p_font_rid, char32_t p_char) const = 0; + virtual String font_get_supported_chars(RID p_font_rid) const = 0; + + virtual void font_render_range(RID p_font, const Vector2i &p_size, char32_t p_start, char32_t p_end) = 0; + virtual void font_render_glyph(RID p_font_rid, const Vector2i &p_size, int32_t p_index) = 0; + + virtual void font_draw_glyph(RID p_font, RID p_canvas, int p_size, const Vector2 &p_pos, int32_t p_index, const Color &p_color = Color(1, 1, 1)) const = 0; + virtual void font_draw_glyph_outline(RID p_font, RID p_canvas, int p_size, int p_outline_size, const Vector2 &p_pos, int32_t p_index, const Color &p_color = Color(1, 1, 1)) const = 0; + + virtual bool font_is_language_supported(RID p_font_rid, const String &p_language) const = 0; + virtual void font_set_language_support_override(RID p_font_rid, const String &p_language, bool p_supported) = 0; + virtual bool font_get_language_support_override(RID p_font_rid, const String &p_language) = 0; + virtual void font_remove_language_support_override(RID p_font_rid, const String &p_language) = 0; + virtual Vector<String> font_get_language_support_overrides(RID p_font_rid) = 0; + + virtual bool font_is_script_supported(RID p_font_rid, const String &p_script) const = 0; + virtual void font_set_script_support_override(RID p_font_rid, const String &p_script, bool p_supported) = 0; + virtual bool font_get_script_support_override(RID p_font_rid, const String &p_script) = 0; + virtual void font_remove_script_support_override(RID p_font_rid, const String &p_script) = 0; + virtual Vector<String> font_get_script_support_overrides(RID p_font_rid) = 0; + + virtual Dictionary font_supported_feature_list(RID p_font_rid) const = 0; + virtual Dictionary font_supported_variation_list(RID p_font_rid) const = 0; + + virtual real_t font_get_global_oversampling() const = 0; + virtual void font_set_global_oversampling(real_t p_oversampling) = 0; Vector2 get_hex_code_box_size(int p_size, char32_t p_index) const; void draw_hex_code_box(RID p_canvas, int p_size, const Vector2 &p_pos, char32_t p_index, const Color &p_color) const; - virtual Vector<String> get_system_fonts() const = 0; - /* Shaped text buffer interface */ virtual RID create_shaped_text(Direction p_direction = DIRECTION_AUTO, Orientation p_orientation = ORIENTATION_HORIZONTAL) = 0; @@ -351,8 +409,8 @@ public: virtual RID shaped_text_substr(RID p_shaped, int p_start, int p_length) const = 0; // Copy shaped substring (e.g. line break) without reshaping, but correctly reordered, preservers range. virtual RID shaped_text_get_parent(RID p_shaped) const = 0; - virtual float shaped_text_fit_to_width(RID p_shaped, float p_width, uint8_t /*JustificationFlag*/ p_jst_flags = JUSTIFICATION_WORD_BOUND | JUSTIFICATION_KASHIDA) = 0; - virtual float shaped_text_tab_align(RID p_shaped, const Vector<float> &p_tab_stops) = 0; + virtual real_t shaped_text_fit_to_width(RID p_shaped, real_t p_width, uint8_t /*JustificationFlag*/ p_jst_flags = JUSTIFICATION_WORD_BOUND | JUSTIFICATION_KASHIDA) = 0; + virtual real_t shaped_text_tab_align(RID p_shaped, const Vector<real_t> &p_tab_stops) = 0; virtual bool shaped_text_shape(RID p_shaped) = 0; virtual bool shaped_text_update_breaks(RID p_shaped) = 0; @@ -366,36 +424,36 @@ public: virtual Vector<Glyph> shaped_text_sort_logical(RID p_shaped) = 0; - virtual Vector<Vector2i> shaped_text_get_line_breaks_adv(RID p_shaped, const Vector<float> &p_width, int p_start = 0, bool p_once = true, uint8_t /*TextBreakFlag*/ p_break_flags = BREAK_MANDATORY | BREAK_WORD_BOUND) const; - virtual Vector<Vector2i> shaped_text_get_line_breaks(RID p_shaped, float p_width, int p_start = 0, uint8_t /*TextBreakFlag*/ p_break_flags = BREAK_MANDATORY | BREAK_WORD_BOUND) const; + virtual Vector<Vector2i> shaped_text_get_line_breaks_adv(RID p_shaped, const Vector<real_t> &p_width, int p_start = 0, bool p_once = true, uint8_t /*TextBreakFlag*/ p_break_flags = BREAK_MANDATORY | BREAK_WORD_BOUND) const; + virtual Vector<Vector2i> shaped_text_get_line_breaks(RID p_shaped, real_t p_width, int p_start = 0, uint8_t /*TextBreakFlag*/ p_break_flags = BREAK_MANDATORY | BREAK_WORD_BOUND) const; virtual Vector<Vector2i> shaped_text_get_word_breaks(RID p_shaped, int p_grapheme_flags = GRAPHEME_IS_SPACE | GRAPHEME_IS_PUNCTUATION) const; virtual TrimData shaped_text_get_trim_data(RID p_shaped) const; - virtual void shaped_text_overrun_trim_to_width(RID p_shaped, float p_width, uint8_t p_trim_flags) = 0; + virtual void shaped_text_overrun_trim_to_width(RID p_shaped, real_t p_width, uint8_t p_trim_flags) = 0; virtual Array shaped_text_get_objects(RID p_shaped) const = 0; virtual Rect2 shaped_text_get_object_rect(RID p_shaped, Variant p_key) const = 0; virtual Size2 shaped_text_get_size(RID p_shaped) const = 0; - virtual float shaped_text_get_ascent(RID p_shaped) const = 0; - virtual float shaped_text_get_descent(RID p_shaped) const = 0; - virtual float shaped_text_get_width(RID p_shaped) const = 0; - virtual float shaped_text_get_underline_position(RID p_shaped) const = 0; - virtual float shaped_text_get_underline_thickness(RID p_shaped) const = 0; + virtual real_t shaped_text_get_ascent(RID p_shaped) const = 0; + virtual real_t shaped_text_get_descent(RID p_shaped) const = 0; + virtual real_t shaped_text_get_width(RID p_shaped) const = 0; + virtual real_t shaped_text_get_underline_position(RID p_shaped) const = 0; + virtual real_t shaped_text_get_underline_thickness(RID p_shaped) const = 0; virtual Direction shaped_text_get_dominant_direciton_in_range(RID p_shaped, int p_start, int p_end) const; virtual void shaped_text_get_carets(RID p_shaped, int p_position, Rect2 &p_leading_caret, Direction &p_leading_dir, Rect2 &p_trailing_caret, Direction &p_trailing_dir) const; virtual Vector<Vector2> shaped_text_get_selection(RID p_shaped, int p_start, int p_end) const; - virtual int shaped_text_hit_test_grapheme(RID p_shaped, float p_coords) const; // Return grapheme index. - virtual int shaped_text_hit_test_position(RID p_shaped, float p_coords) const; // Return caret/selection position. + virtual int shaped_text_hit_test_grapheme(RID p_shaped, real_t p_coords) const; // Return grapheme index. + virtual int shaped_text_hit_test_position(RID p_shaped, real_t p_coords) const; // Return caret/selection position. virtual int shaped_text_next_grapheme_pos(RID p_shaped, int p_pos); virtual int shaped_text_prev_grapheme_pos(RID p_shaped, int p_pos); // The pen position is always placed on the baseline and moveing left to right. - virtual void shaped_text_draw(RID p_shaped, RID p_canvas, const Vector2 &p_pos, float p_clip_l = -1.f, float p_clip_r = -1.f, const Color &p_color = Color(1, 1, 1)) const; - virtual void shaped_text_draw_outline(RID p_shaped, RID p_canvas, const Vector2 &p_pos, float p_clip_l = -1.f, float p_clip_r = -1.f, int p_outline_size = 1, const Color &p_color = Color(1, 1, 1)) const; + virtual void shaped_text_draw(RID p_shaped, RID p_canvas, const Vector2 &p_pos, real_t p_clip_l = -1.f, real_t p_clip_r = -1.f, const Color &p_color = Color(1, 1, 1)) const; + virtual void shaped_text_draw_outline(RID p_shaped, RID p_canvas, const Vector2 &p_pos, real_t p_clip_l = -1.f, real_t p_clip_r = -1.f, int p_outline_size = 1, const Color &p_color = Color(1, 1, 1)) const; // Number conversion. virtual String format_number(const String &p_string, const String &p_language = "") const { return p_string; }; @@ -403,9 +461,9 @@ public: virtual String percent_sign(const String &p_language = "") const { return "%"; }; /* GDScript wrappers */ - RID _create_font_memory(const PackedByteArray &p_data, const String &p_type, int p_base_size = 16); + RID _create_font_memory(const PackedByteArray &p_data, int p_base_size = 16); - Dictionary _font_get_glyph_contours(RID p_font, int p_size, uint32_t p_index) const; + Dictionary _font_get_glyph_contours(RID p_font, int p_size, int32_t p_index) const; Array _shaped_text_get_glyphs(RID p_shaped) const; Dictionary _shaped_text_get_carets(RID p_shaped, int p_position) const; @@ -413,7 +471,7 @@ public: void _shaped_text_set_bidi_override(RID p_shaped, const Array &p_override); Array _shaped_text_get_line_breaks_adv(RID p_shaped, const PackedFloat32Array &p_width, int p_start, bool p_once, uint8_t p_break_flags) const; - Array _shaped_text_get_line_breaks(RID p_shaped, float p_width, int p_start, uint8_t p_break_flags) const; + Array _shaped_text_get_line_breaks(RID p_shaped, real_t p_width, int p_start, uint8_t p_break_flags) const; Array _shaped_text_get_word_breaks(RID p_shaped) const; Array _shaped_text_get_selection(RID p_shaped, int p_start, int p_end) const; @@ -491,5 +549,6 @@ VARIANT_ENUM_CAST(TextServer::GraphemeFlag); VARIANT_ENUM_CAST(TextServer::Hinting); VARIANT_ENUM_CAST(TextServer::Feature); VARIANT_ENUM_CAST(TextServer::ContourPointTag); +VARIANT_ENUM_CAST(TextServer::SpacingType); #endif // TEXT_SERVER_H |