diff options
Diffstat (limited to 'modules')
20 files changed, 456 insertions, 2518 deletions
diff --git a/modules/gdnative/SCsub b/modules/gdnative/SCsub index 94bda04d12..f7f21a433e 100644 --- a/modules/gdnative/SCsub +++ b/modules/gdnative/SCsub @@ -18,7 +18,6 @@ Export("env_gdnative") SConscript("pluginscript/SCsub") SConscript("videodecoder/SCsub") -SConscript("text/SCsub") import gdnative_builders diff --git a/modules/gdnative/gdnative_api.json b/modules/gdnative/gdnative_api.json index 627883886c..cf1c7dc01f 100644 --- a/modules/gdnative/gdnative_api.json +++ b/modules/gdnative/gdnative_api.json @@ -5103,489 +5103,6 @@ ] } ] - }, - { - "name": "text", - "type": "TEXT", - "version": { - "major": 1, - "minor": 0 - }, - "next": null, - "api": [ - { - "name": "godot_text_register_interface", - "return_type": "void", - "arguments": [ - [ - "const godot_text_interface_gdnative *", - "p_interface" - ], - [ - "const godot_string *", - "p_name" - ], - [ - "uint32_t", - "p_features" - ] - ] - }, - { - "name": "godot_glyph_new", - "return_type": "void", - "arguments": [ - [ - "godot_glyph *", - "r_dest" - ] - ] - }, - { - "name": "godot_glyph_get_range", - "return_type": "godot_vector2i", - "arguments": [ - [ - "const godot_glyph *", - "p_self" - ] - ] - }, - { - "name": "godot_glyph_set_range", - "return_type": "void", - "arguments": [ - [ - "godot_glyph *", - "p_self" - ], - [ - "const godot_vector2i *", - "p_range" - ] - ] - }, - { - "name": "godot_glyph_get_count", - "return_type": "godot_int", - "arguments": [ - [ - "const godot_glyph *", - "p_self" - ] - ] - }, - { - "name": "godot_glyph_set_count", - "return_type": "void", - "arguments": [ - [ - "godot_glyph *", - "p_self" - ], - [ - "godot_int", - "p_count" - ] - ] - }, - { - "name": "godot_glyph_get_repeat", - "return_type": "godot_int", - "arguments": [ - [ - "const godot_glyph *", - "p_self" - ] - ] - }, - { - "name": "godot_glyph_set_repeat", - "return_type": "void", - "arguments": [ - [ - "godot_glyph *", - "p_self" - ], - [ - "godot_int", - "p_repeat" - ] - ] - }, - { - "name": "godot_glyph_get_flags", - "return_type": "godot_int", - "arguments": [ - [ - "const godot_glyph *", - "p_self" - ] - ] - }, - { - "name": "godot_glyph_set_flags", - "return_type": "void", - "arguments": [ - [ - "godot_glyph *", - "p_self" - ], - [ - "godot_int", - "p_flags" - ] - ] - }, - { - "name": "godot_glyph_get_offset", - "return_type": "godot_vector2", - "arguments": [ - [ - "const godot_glyph *", - "p_self" - ] - ] - }, - { - "name": "godot_glyph_set_offset", - "return_type": "void", - "arguments": [ - [ - "godot_glyph *", - "p_self" - ], - [ - "const godot_vector2 *", - "p_offset" - ] - ] - }, - { - "name": "godot_glyph_get_advance", - "return_type": "godot_real_t", - "arguments": [ - [ - "const godot_glyph *", - "p_self" - ] - ] - }, - { - "name": "godot_glyph_set_advance", - "return_type": "void", - "arguments": [ - [ - "godot_glyph *", - "p_self" - ], - [ - "godot_real_t", - "p_advance" - ] - ] - }, - { - "name": "godot_glyph_get_font", - "return_type": "godot_rid", - "arguments": [ - [ - "const godot_glyph *", - "p_self" - ] - ] - }, - { - "name": "godot_glyph_set_font", - "return_type": "void", - "arguments": [ - [ - "godot_glyph *", - "p_self" - ], - [ - "godot_rid *", - "p_font" - ] - ] - }, - { - "name": "godot_glyph_get_font_size", - "return_type": "godot_int", - "arguments": [ - [ - "const godot_glyph *", - "p_self" - ] - ] - }, - { - "name": "godot_glyph_set_font_size", - "return_type": "void", - "arguments": [ - [ - "godot_glyph *", - "p_self" - ], - [ - "godot_int", - "p_size" - ] - ] - }, - { - "name": "godot_glyph_get_index", - "return_type": "godot_int", - "arguments": [ - [ - "const godot_glyph *", - "p_self" - ] - ] - }, - { - "name": "godot_glyph_set_index", - "return_type": "void", - "arguments": [ - [ - "godot_glyph *", - "p_self" - ], - [ - "godot_int", - "p_index" - ] - ] - }, - { - "name": "godot_packed_glyph_array_new", - "return_type": "void", - "arguments": [ - [ - "godot_packed_glyph_array *", - "r_dest" - ] - ] - }, - { - "name": "godot_packed_glyph_array_new_copy", - "return_type": "void", - "arguments": [ - [ - "godot_packed_glyph_array *", - "r_dest" - ], - [ - "const godot_packed_glyph_array *", - "p_src" - ] - ] - }, - { - "name": "godot_packed_glyph_array_is_empty", - "return_type": "godot_bool", - "arguments": [ - [ - "const godot_packed_glyph_array *", - "p_self" - ] - ] - }, - { - "name": "godot_packed_glyph_array_append", - "return_type": "void", - "arguments": [ - [ - "godot_packed_glyph_array *", - "p_self" - ], - [ - "const godot_glyph *", - "p_data" - ] - ] - }, - { - "name": "godot_packed_glyph_array_append_array", - "return_type": "void", - "arguments": [ - [ - "godot_packed_glyph_array *", - "p_self" - ], - [ - "const godot_packed_glyph_array *", - "p_array" - ] - ] - }, - { - "name": "godot_packed_glyph_array_insert", - "return_type": "godot_error", - "arguments": [ - [ - "godot_packed_glyph_array *", - "p_self" - ], - [ - "const godot_int", - "p_idx" - ], - [ - "const godot_glyph *", - "p_data" - ] - ] - }, - { - "name": "godot_packed_glyph_array_has", - "return_type": "godot_bool", - "arguments": [ - [ - "godot_packed_glyph_array *", - "p_self" - ], - [ - "const godot_glyph *", - "p_value" - ] - ] - }, - { - "name": "godot_packed_glyph_array_sort", - "return_type": "void", - "arguments": [ - [ - "godot_packed_glyph_array *", - "p_self" - ] - ] - }, - { - "name": "godot_packed_glyph_array_reverse", - "return_type": "void", - "arguments": [ - [ - "godot_packed_glyph_array *", - "p_self" - ] - ] - }, - { - "name": "godot_packed_glyph_array_push_back", - "return_type": "void", - "arguments": [ - [ - "godot_packed_glyph_array *", - "p_self" - ], - [ - "const godot_glyph *", - "p_data" - ] - ] - }, - { - "name": "godot_packed_glyph_array_remove", - "return_type": "void", - "arguments": [ - [ - "godot_packed_glyph_array *", - "p_self" - ], - [ - "const godot_int", - "p_idx" - ] - ] - }, - { - "name": "godot_packed_glyph_array_resize", - "return_type": "void", - "arguments": [ - [ - "godot_packed_glyph_array *", - "p_self" - ], - [ - "const godot_int", - "p_size" - ] - ] - }, - { - "name": "godot_packed_glyph_array_ptr", - "return_type": "const godot_glyph *", - "arguments": [ - [ - "const godot_packed_glyph_array *", - "p_self" - ] - ] - }, - { - "name": "godot_packed_glyph_array_ptrw", - "return_type": "godot_glyph *", - "arguments": [ - [ - "godot_packed_glyph_array *", - "p_self" - ] - ] - }, - { - "name": "godot_packed_glyph_array_set", - "return_type": "void", - "arguments": [ - [ - "godot_packed_glyph_array *", - "p_self" - ], - [ - "const godot_int", - "p_idx" - ], - [ - "const godot_glyph *", - "p_data" - ] - ] - }, - { - "name": "godot_packed_glyph_array_get", - "return_type": "godot_glyph", - "arguments": [ - [ - "const godot_packed_glyph_array *", - "p_self" - ], - [ - "const godot_int", - "p_idx" - ] - ] - }, - { - "name": "godot_packed_glyph_array_size", - "return_type": "godot_int", - "arguments": [ - [ - "const godot_packed_glyph_array *", - "p_self" - ] - ] - }, - { - "name": "godot_packed_glyph_array_destroy", - "return_type": "void", - "arguments": [ - [ - "godot_packed_glyph_array *", - "p_self" - ] - ] - } - ] } ] } diff --git a/modules/gdnative/gdnative_builders.py b/modules/gdnative/gdnative_builders.py index 4986b173cf..6c96e23426 100644 --- a/modules/gdnative/gdnative_builders.py +++ b/modules/gdnative/gdnative_builders.py @@ -22,7 +22,6 @@ def _build_gdnative_api_struct_header(api): "#include <nativescript/godot_nativescript.h>", "#include <pluginscript/godot_pluginscript.h>", "#include <videodecoder/godot_videodecoder.h>", - "#include <text/godot_text.h>", "", "#ifdef __cplusplus", 'extern "C" {', diff --git a/modules/gdnative/include/text/godot_text.h b/modules/gdnative/include/text/godot_text.h deleted file mode 100644 index 940cfd11f8..0000000000 --- a/modules/gdnative/include/text/godot_text.h +++ /dev/null @@ -1,283 +0,0 @@ -/*************************************************************************/ -/* godot_text.h */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* https://godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */ -/* */ -/* Permission is hereby granted, free of charge, to any person obtaining */ -/* a copy of this software and associated documentation files (the */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/*************************************************************************/ - -#ifndef GODOT_NATIVETEXT_H -#define GODOT_NATIVETEXT_H - -#include <gdnative/gdnative.h> - -#ifdef __cplusplus -extern "C" { -#endif - -#define GODOT_TEXT_API_MAJOR 1 -#define GODOT_TEXT_API_MINOR 0 - -#define GODOT_GLYPH_SIZE 40 - -#ifndef GODOT_TEXT_API_GODOT_GLYPH_TYPE_DEFINED -#define GODOT_TEXT_API_GODOT_GLYPH_TYPE_DEFINED -typedef struct { - uint8_t _dont_touch_that[GODOT_GLYPH_SIZE]; -} godot_glyph; -#endif - -#define GODOT_PACKED_GLYPH_ARRAY_SIZE (2 * sizeof(void *)) - -#ifndef GODOT_TEXT_API_GODOT_PACKED_GLYPH_ARRAY_TYPE_DEFINED -#define GODOT_TEXT_API_GODOT_PACKED_GLYPH_ARRAY_TYPE_DEFINED -typedef struct { - uint8_t _dont_touch_that[GODOT_PACKED_GLYPH_ARRAY_SIZE]; -} godot_packed_glyph_array; -#endif - -typedef struct { - godot_gdnative_api_version version; - - void *(*constructor)(godot_object *); - void (*destructor)(void *); - - godot_string (*get_name)(const void *); - godot_bool (*has_feature)(const void *, godot_int); - - void (*free)(void *, godot_rid *); - bool (*has)(void *, godot_rid *); - - bool (*load_support_data)(void *, const godot_string *); - godot_string (*get_support_data_filename)(const void *); - godot_string (*get_support_data_info)(const void *); - bool (*save_support_data)(void *, const godot_string *); - - bool (*is_locale_right_to_left)(void *, const godot_string *); - int32_t (*name_to_tag)(const void *, const godot_string *); - godot_string (*tag_to_name)(const void *, int32_t); - - godot_rid (*create_font)(void *); - void (*font_set_data)(void *, godot_rid *, const godot_packed_byte_array *); - void (*font_set_data_ptr)(void *, godot_rid *, const uint8_t *, size_t); - void (*font_set_antialiased)(void *, godot_rid *, bool); - bool (*font_is_antialiased)(const void *, godot_rid *); - void (*font_set_multichannel_signed_distance_field)(void *, godot_rid *, bool); - bool (*font_is_multichannel_signed_distance_field)(const void *, godot_rid *); - void (*font_set_msdf_pixel_range)(void *, godot_rid *, godot_int); - godot_int (*font_get_msdf_pixel_range)(const void *, godot_rid *); - void (*font_set_msdf_size)(void *, godot_rid *, godot_int); - godot_int (*font_get_msdf_size)(const void *, godot_rid *); - void (*font_set_fixed_size)(void *, godot_rid *, godot_int); - godot_int (*font_get_fixed_size)(const void *, godot_rid *); - void (*font_set_force_autohinter)(void *, godot_rid *, bool); - bool (*font_is_force_autohinter)(const void *, godot_rid *); - void (*font_set_hinting)(void *, godot_rid *, godot_int); - godot_int (*font_get_hinting)(const void *, godot_rid *); - void (*font_set_variation_coordinates)(void *, godot_rid *, const godot_dictionary *); - godot_dictionary (*font_get_variation_coordinates)(const void *, godot_rid *); - void (*font_set_oversampling)(void *, godot_rid *, godot_real_t); - godot_real_t (*font_get_oversampling)(const void *, godot_rid *); - godot_array (*font_get_size_cache_list)(const void *, godot_rid *); - void (*font_clear_size_cache)(void *, godot_rid *); - void (*font_remove_size_cache)(void *, godot_rid *, const godot_vector2i *); - void (*font_set_ascent)(void *, godot_rid *, godot_int, godot_real_t); - godot_real_t (*font_get_ascent)(const void *, godot_rid *, godot_int); - void (*font_set_descent)(void *, godot_rid *, godot_int, godot_real_t); - godot_real_t (*font_get_descent)(const void *, godot_rid *, godot_int); - void (*font_set_underline_position)(void *, godot_rid *, godot_int, godot_real_t); - godot_real_t (*font_get_underline_position)(const void *, godot_rid *, godot_int); - void (*font_set_underline_thickness)(void *, godot_rid *, godot_int, godot_real_t); - godot_real_t (*font_get_underline_thickness)(const void *, godot_rid *, godot_int); - void (*font_set_scale)(void *, godot_rid *, godot_int, godot_real_t); - godot_real_t (*font_get_scale)(const void *, godot_rid *, godot_int); - void (*font_set_spacing)(void *, godot_rid *, godot_int, godot_int, godot_int); - godot_int (*font_get_spacing)(const void *, godot_rid *, godot_int, godot_int); - godot_int (*font_get_texture_count)(const void *, godot_rid *, const godot_vector2i *); - void (*font_clear_textures)(void *, godot_rid *, const godot_vector2i *); - void (*font_remove_texture)(void *, godot_rid *, const godot_vector2i *, godot_int); - void (*font_set_texture_image)(void *, godot_rid *, const godot_vector2i *, godot_int, const godot_object *); - godot_object *(*font_get_texture_image)(const void *, godot_rid *, const godot_vector2i *, godot_int); - void (*font_set_texture_offsets)(void *, godot_rid *, const godot_vector2i *, godot_int, const godot_packed_int32_array *); - godot_packed_int32_array (*font_get_texture_offsets)(const void *, godot_rid *, const godot_vector2i *, godot_int); - godot_array (*font_get_glyph_list)(const void *, godot_rid *, const godot_vector2i *); - void (*font_clear_glyphs)(void *, godot_rid *, const godot_vector2i *); - void (*font_remove_glyph)(void *, godot_rid *, const godot_vector2i *, int32_t); - godot_vector2 (*font_get_glyph_advance)(const void *, godot_rid *, godot_int, int32_t); - void (*font_set_glyph_advance)(void *, godot_rid *, godot_int, int32_t, const godot_vector2 *); - godot_vector2 (*font_get_glyph_offset)(const void *, godot_rid *, const godot_vector2i *, int32_t); - void (*font_set_glyph_offset)(void *, godot_rid *, const godot_vector2i *, int32_t, const godot_vector2 *); - godot_vector2 (*font_get_glyph_size)(const void *, godot_rid *, const godot_vector2i *, int32_t); - void (*font_set_glyph_size)(void *, godot_rid *, const godot_vector2i *, int32_t, const godot_vector2 *); - godot_rect2 (*font_get_glyph_uv_rect)(const void *, godot_rid *, const godot_vector2i *, int32_t); - void (*font_set_glyph_uv_rect)(void *, godot_rid *, const godot_vector2i *, int32_t, const godot_rect2 *); - godot_int (*font_get_glyph_texture_idx)(const void *, godot_rid *, const godot_vector2i *, int32_t); - void (*font_set_glyph_texture_idx)(void *, godot_rid *, const godot_vector2i *, int32_t, godot_int); - bool (*font_get_glyph_contours)(const void *, godot_rid *, godot_int, int32_t, godot_packed_vector3_array *, godot_packed_int32_array *, bool *); - godot_array (*font_get_kerning_list)(const void *, godot_rid *, godot_int); - void (*font_clear_kerning_map)(void *, godot_rid *, godot_int); - void (*font_remove_kerning)(void *, godot_rid *, godot_int, const godot_vector2i *); - void (*font_set_kerning)(void *, godot_rid *, godot_int, const godot_vector2i *, const godot_vector2 *); - godot_vector2 (*font_get_kerning)(const void *, godot_rid *, godot_int, const godot_vector2i *); - int32_t (*font_get_glyph_index)(const void *, godot_rid *, godot_int, char32_t, char32_t); - bool (*font_has_char)(const void *, godot_rid *, char32_t); - godot_string (*font_get_supported_chars)(const void *, godot_rid *); - void (*font_render_range)(void *, godot_rid *, const godot_vector2i *, char32_t, char32_t); - void (*font_render_glyph)(void *, godot_rid *, const godot_vector2i *, int32_t); - void (*font_draw_glyph)(const void *, godot_rid *, godot_rid *, godot_int, const godot_vector2 *, int32_t, const godot_color *); - void (*font_draw_glyph_outline)(const void *, godot_rid *, godot_rid *, godot_int, godot_int, const godot_vector2 *, int32_t, const godot_color *); - bool (*font_is_language_supported)(const void *, godot_rid *, const godot_string *); - void (*font_set_language_support_override)(void *, godot_rid *, const godot_string *, bool); - bool (*font_get_language_support_override)(const void *, godot_rid *, const godot_string *); - void (*font_remove_language_support_override)(void *, godot_rid *, const godot_string *); - godot_packed_string_array (*font_get_language_support_overrides)(const void *, godot_rid *); - bool (*font_is_script_supported)(const void *, godot_rid *, const godot_string *); - void (*font_set_script_support_override)(void *, godot_rid *, const godot_string *, bool); - bool (*font_get_script_support_override)(const void *, godot_rid *, const godot_string *); - void (*font_remove_script_support_override)(void *, godot_rid *, const godot_string *); - godot_packed_string_array (*font_get_script_support_overrides)(const void *, godot_rid *); - godot_dictionary (*font_supported_feature_list)(const void *, godot_rid *); - godot_dictionary (*font_supported_variation_list)(const void *, godot_rid *); - godot_real_t (*font_get_global_oversampling)(const void *); - void (*font_set_global_oversampling)(void *, godot_real_t); - - godot_rid (*create_shaped_text)(void *, godot_int, godot_int); - void (*shaped_text_clear)(void *, godot_rid *); - void (*shaped_text_set_direction)(void *, godot_rid *, godot_int); - godot_int (*shaped_text_get_direction)(void *, godot_rid *); - void (*shaped_text_set_bidi_override)(void *, godot_rid *, const godot_packed_vector2i_array *); - void (*shaped_text_set_orientation)(void *, godot_rid *, godot_int); - godot_int (*shaped_text_get_orientation)(void *, godot_rid *); - void (*shaped_text_set_preserve_invalid)(void *, godot_rid *, bool); - bool (*shaped_text_get_preserve_invalid)(void *, godot_rid *); - void (*shaped_text_set_preserve_control)(void *, godot_rid *, bool); - bool (*shaped_text_get_preserve_control)(void *, godot_rid *); - bool (*shaped_text_add_string)(void *, godot_rid *, const godot_string *, const godot_rid **, int, const godot_dictionary *, const godot_string *); - bool (*shaped_text_add_object)(void *, godot_rid *, const godot_variant *, const godot_vector2 *, godot_int, godot_int); - bool (*shaped_text_resize_object)(void *, godot_rid *, const godot_variant *, const godot_vector2 *, godot_int); - godot_rid (*shaped_text_substr)(void *, godot_rid *, godot_int, godot_int); - godot_rid (*shaped_text_get_parent)(void *, godot_rid *); - godot_real_t (*shaped_text_fit_to_width)(void *, godot_rid *, godot_real_t, uint8_t); - godot_real_t (*shaped_text_tab_align)(void *, godot_rid *, godot_packed_float32_array *); - bool (*shaped_text_shape)(void *, godot_rid *); - bool (*shaped_text_update_breaks)(void *, godot_rid *); - bool (*shaped_text_update_justification_ops)(void *, godot_rid *); - void (*shaped_text_overrun_trim_to_width)(void *, godot_rid *, godot_real_t, uint8_t); - bool (*shaped_text_is_ready)(void *, godot_rid *); - godot_packed_glyph_array (*shaped_text_get_glyphs)(void *, godot_rid *); - godot_vector2i (*shaped_text_get_range)(void *, godot_rid *); - godot_packed_glyph_array (*shaped_text_sort_logical)(void *, godot_rid *); - godot_packed_vector2i_array (*shaped_text_get_line_breaks_adv)(void *, godot_rid *, godot_packed_float32_array *, int, bool, uint8_t); - godot_packed_vector2i_array (*shaped_text_get_line_breaks)(void *, godot_rid *, godot_real_t, int, uint8_t); - godot_packed_vector2i_array (*shaped_text_get_word_breaks)(void *, godot_rid *, int); - godot_array (*shaped_text_get_objects)(void *, godot_rid *); - godot_rect2 (*shaped_text_get_object_rect)(void *, godot_rid *, const godot_variant *); - godot_vector2 (*shaped_text_get_size)(void *, godot_rid *); - godot_real_t (*shaped_text_get_ascent)(void *, godot_rid *); - godot_real_t (*shaped_text_get_descent)(void *, godot_rid *); - godot_real_t (*shaped_text_get_width)(void *, godot_rid *); - godot_real_t (*shaped_text_get_underline_position)(void *, godot_rid *); - godot_real_t (*shaped_text_get_underline_thickness)(void *, godot_rid *); - - godot_string (*format_number)(void *, const godot_string *, const godot_string *); - godot_string (*parse_number)(void *, const godot_string *, const godot_string *); - godot_string (*percent_sign)(void *, const godot_string *); -} godot_text_interface_gdnative; - -void GDAPI godot_text_register_interface(const godot_text_interface_gdnative *p_interface, const godot_string *p_name, uint32_t p_features); - -// Glyph - -void GDAPI godot_glyph_new(godot_glyph *r_dest); - -godot_vector2i GDAPI godot_glyph_get_range(const godot_glyph *p_self); -void GDAPI godot_glyph_set_range(godot_glyph *p_self, const godot_vector2i *p_range); - -godot_int GDAPI godot_glyph_get_count(const godot_glyph *p_self); -void GDAPI godot_glyph_set_count(godot_glyph *p_self, godot_int p_count); - -godot_int GDAPI godot_glyph_get_repeat(const godot_glyph *p_self); -void GDAPI godot_glyph_set_repeat(godot_glyph *p_self, godot_int p_repeat); - -godot_int GDAPI godot_glyph_get_flags(const godot_glyph *p_self); -void GDAPI godot_glyph_set_flags(godot_glyph *p_self, godot_int p_flags); - -godot_vector2 GDAPI godot_glyph_get_offset(const godot_glyph *p_self); -void GDAPI godot_glyph_set_offset(godot_glyph *p_self, const godot_vector2 *p_offset); - -godot_real_t GDAPI godot_glyph_get_advance(const godot_glyph *p_self); -void GDAPI godot_glyph_set_advance(godot_glyph *p_self, godot_real_t p_advance); - -godot_rid GDAPI godot_glyph_get_font(const godot_glyph *p_self); -void GDAPI godot_glyph_set_font(godot_glyph *p_self, godot_rid *p_font); - -godot_int GDAPI godot_glyph_get_font_size(const godot_glyph *p_self); -void GDAPI godot_glyph_set_font_size(godot_glyph *p_self, godot_int p_size); - -godot_int GDAPI godot_glyph_get_index(const godot_glyph *p_self); -void GDAPI godot_glyph_set_index(godot_glyph *p_self, godot_int p_index); - -// GlyphArray - -void GDAPI godot_packed_glyph_array_new(godot_packed_glyph_array *r_dest); -void GDAPI godot_packed_glyph_array_new_copy(godot_packed_glyph_array *r_dest, const godot_packed_glyph_array *p_src); - -const godot_glyph GDAPI *godot_packed_glyph_array_ptr(const godot_packed_glyph_array *p_self); -godot_glyph GDAPI *godot_packed_glyph_array_ptrw(godot_packed_glyph_array *p_self); - -void GDAPI godot_packed_glyph_array_append(godot_packed_glyph_array *p_self, const godot_glyph *p_data); - -void GDAPI godot_packed_glyph_array_append_array(godot_packed_glyph_array *p_self, const godot_packed_glyph_array *p_array); - -godot_error GDAPI godot_packed_glyph_array_insert(godot_packed_glyph_array *p_self, const godot_int p_idx, const godot_glyph *p_data); - -godot_bool GDAPI godot_packed_glyph_array_has(godot_packed_glyph_array *p_self, const godot_glyph *p_value); - -void GDAPI godot_packed_glyph_array_sort(godot_packed_glyph_array *p_self); - -void GDAPI godot_packed_glyph_array_reverse(godot_packed_glyph_array *p_self); - -void GDAPI godot_packed_glyph_array_push_back(godot_packed_glyph_array *p_self, const godot_glyph *p_data); - -void GDAPI godot_packed_glyph_array_remove(godot_packed_glyph_array *p_self, godot_int p_idx); - -void GDAPI godot_packed_glyph_array_resize(godot_packed_glyph_array *p_self, godot_int p_size); - -void GDAPI godot_packed_glyph_array_set(godot_packed_glyph_array *p_self, godot_int p_idx, const godot_glyph *p_data); -godot_glyph GDAPI godot_packed_glyph_array_get(const godot_packed_glyph_array *p_self, godot_int p_idx); - -godot_int GDAPI godot_packed_glyph_array_size(const godot_packed_glyph_array *p_self); - -godot_bool GDAPI godot_packed_glyph_array_is_empty(const godot_packed_glyph_array *p_self); - -void GDAPI godot_packed_glyph_array_destroy(godot_packed_glyph_array *p_self); - -// Grapheme - -#ifdef __cplusplus -} -#endif - -#endif /* !GODOT_NATIVETEXT_H */ diff --git a/modules/gdnative/text/SCsub b/modules/gdnative/text/SCsub deleted file mode 100644 index 0b2db3b504..0000000000 --- a/modules/gdnative/text/SCsub +++ /dev/null @@ -1,6 +0,0 @@ -#!/usr/bin/env python - -Import("env") -Import("env_gdnative") - -env_gdnative.add_source_files(env.modules_sources, "*.cpp") diff --git a/modules/gdnative/text/config.py b/modules/gdnative/text/config.py deleted file mode 100644 index d22f9454ed..0000000000 --- a/modules/gdnative/text/config.py +++ /dev/null @@ -1,6 +0,0 @@ -def can_build(env, platform): - return True - - -def configure(env): - pass diff --git a/modules/gdnative/text/register_types.cpp b/modules/gdnative/text/register_types.cpp deleted file mode 100644 index 67385d2fbf..0000000000 --- a/modules/gdnative/text/register_types.cpp +++ /dev/null @@ -1,36 +0,0 @@ -/*************************************************************************/ -/* register_types.cpp */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* https://godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */ -/* */ -/* Permission is hereby granted, free of charge, to any person obtaining */ -/* a copy of this software and associated documentation files (the */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/*************************************************************************/ - -#include "register_types.h" -#include "text_server_gdnative.h" - -void register_text_server_gdn_types() {} - -void unregister_text_server_gdn_types() {} diff --git a/modules/gdnative/text/register_types.h b/modules/gdnative/text/register_types.h deleted file mode 100644 index cd4f2a3089..0000000000 --- a/modules/gdnative/text/register_types.h +++ /dev/null @@ -1,37 +0,0 @@ -/*************************************************************************/ -/* register_types.h */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* https://godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */ -/* */ -/* Permission is hereby granted, free of charge, to any person obtaining */ -/* a copy of this software and associated documentation files (the */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/*************************************************************************/ - -#ifndef TEXT_REGISTER_TYPES_H -#define TEXT_REGISTER_TYPES_H - -void register_text_server_gdn_types(); -void unregister_text_server_gdn_types(); - -#endif // TEXT_REGISTER_TYPES_H diff --git a/modules/gdnative/text/text_server_gdnative.cpp b/modules/gdnative/text/text_server_gdnative.cpp deleted file mode 100644 index 39db8ae636..0000000000 --- a/modules/gdnative/text/text_server_gdnative.cpp +++ /dev/null @@ -1,1086 +0,0 @@ -/*************************************************************************/ -/* text_server_gdnative.cpp */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* https://godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */ -/* */ -/* Permission is hereby granted, free of charge, to any person obtaining */ -/* a copy of this software and associated documentation files (the */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/*************************************************************************/ - -#include "text_server_gdnative.h" - -bool TextServerGDNative::has_feature(Feature p_feature) { - ERR_FAIL_COND_V(interface == nullptr, false); - return interface->has_feature(data, (godot_int)p_feature); -} - -String TextServerGDNative::get_name() const { - ERR_FAIL_COND_V(interface == nullptr, String()); - godot_string result = interface->get_name(data); - String name = *(String *)&result; - godot_string_destroy(&result); - return name; -} - -void TextServerGDNative::free(RID p_rid) { - ERR_FAIL_COND(interface == nullptr); - interface->free(data, (godot_rid *)&p_rid); -} - -bool TextServerGDNative::has(RID p_rid) { - ERR_FAIL_COND_V(interface == nullptr, false); - return interface->has(data, (godot_rid *)&p_rid); -} - -bool TextServerGDNative::load_support_data(const String &p_filename) { - ERR_FAIL_COND_V(interface == nullptr, false); - return interface->load_support_data(data, (godot_string *)&p_filename); -} - -#ifdef TOOLS_ENABLED - -String TextServerGDNative::get_support_data_filename() { - ERR_FAIL_COND_V(interface == nullptr, String()); - godot_string result = interface->get_support_data_filename(data); - String name = *(String *)&result; - godot_string_destroy(&result); - return name; -} - -String TextServerGDNative::get_support_data_info() { - ERR_FAIL_COND_V(interface == nullptr, String()); - godot_string result = interface->get_support_data_info(data); - String info = *(String *)&result; - godot_string_destroy(&result); - return info; -} - -bool TextServerGDNative::save_support_data(const String &p_filename) { - ERR_FAIL_COND_V(interface == nullptr, false); - return interface->save_support_data(data, (godot_string *)&p_filename); -} - -#endif - -bool TextServerGDNative::is_locale_right_to_left(const String &p_locale) { - ERR_FAIL_COND_V(interface == nullptr, false); - return interface->is_locale_right_to_left(data, (godot_string *)&p_locale); -} - -int32_t TextServerGDNative::name_to_tag(const String &p_name) const { - ERR_FAIL_COND_V(interface == nullptr, 0); - return interface->name_to_tag(data, (godot_string *)&p_name); -} - -String TextServerGDNative::tag_to_name(int32_t p_tag) const { - ERR_FAIL_COND_V(interface == nullptr, String()); - godot_string result = interface->tag_to_name(data, p_tag); - String name = *(String *)&result; - godot_string_destroy(&result); - return name; -} - -/*************************************************************************/ -/* Font */ -/*************************************************************************/ - -RID TextServerGDNative::create_font() { - ERR_FAIL_COND_V(interface == nullptr, RID()); - godot_rid result = interface->create_font(data); - RID rid = *(RID *)&result; - return rid; -} - -void TextServerGDNative::font_set_data(RID p_font_rid, const PackedByteArray &p_data) { - ERR_FAIL_COND(interface == nullptr); - interface->font_set_data(data, (godot_rid *)&p_font_rid, (const godot_packed_byte_array *)&p_data); -} - -void TextServerGDNative::font_set_data_ptr(RID p_font_rid, const uint8_t *p_data_ptr, size_t p_data_size) { - ERR_FAIL_COND(interface == nullptr); - interface->font_set_data_ptr(data, (godot_rid *)&p_font_rid, p_data_ptr, p_data_size); -} - -void TextServerGDNative::font_set_antialiased(RID p_font_rid, bool p_antialiased) { - ERR_FAIL_COND(interface == nullptr); - interface->font_set_antialiased(data, (godot_rid *)&p_font_rid, p_antialiased); -} - -bool TextServerGDNative::font_is_antialiased(RID p_font_rid) const { - ERR_FAIL_COND_V(interface == nullptr, false); - return interface->font_is_antialiased(data, (godot_rid *)&p_font_rid); -} - -void TextServerGDNative::font_set_multichannel_signed_distance_field(RID p_font_rid, bool p_msdf) { - ERR_FAIL_COND(interface == nullptr); - interface->font_set_multichannel_signed_distance_field(data, (godot_rid *)&p_font_rid, p_msdf); -} - -bool TextServerGDNative::font_is_multichannel_signed_distance_field(RID p_font_rid) const { - ERR_FAIL_COND_V(interface == nullptr, false); - return interface->font_is_multichannel_signed_distance_field(data, (godot_rid *)&p_font_rid); -} - -void TextServerGDNative::font_set_msdf_pixel_range(RID p_font_rid, int p_msdf_pixel_range) { - ERR_FAIL_COND(interface == nullptr); - interface->font_set_msdf_pixel_range(data, (godot_rid *)&p_font_rid, p_msdf_pixel_range); -} - -int TextServerGDNative::font_get_msdf_pixel_range(RID p_font_rid) const { - ERR_FAIL_COND_V(interface == nullptr, 0); - return interface->font_get_msdf_pixel_range(data, (godot_rid *)&p_font_rid); -} - -void TextServerGDNative::font_set_msdf_size(RID p_font_rid, int p_msdf_size) { - ERR_FAIL_COND(interface == nullptr); - interface->font_set_msdf_size(data, (godot_rid *)&p_font_rid, p_msdf_size); -} - -int TextServerGDNative::font_get_msdf_size(RID p_font_rid) const { - ERR_FAIL_COND_V(interface == nullptr, 0); - return interface->font_get_msdf_size(data, (godot_rid *)&p_font_rid); -} - -void TextServerGDNative::font_set_fixed_size(RID p_font_rid, int p_fixed_size) { - ERR_FAIL_COND(interface == nullptr); - interface->font_set_fixed_size(data, (godot_rid *)&p_font_rid, p_fixed_size); -} - -int TextServerGDNative::font_get_fixed_size(RID p_font_rid) const { - ERR_FAIL_COND_V(interface == nullptr, 0); - return interface->font_get_fixed_size(data, (godot_rid *)&p_font_rid); -} - -void TextServerGDNative::font_set_force_autohinter(RID p_font_rid, bool p_force_autohinter) { - ERR_FAIL_COND(interface == nullptr); - interface->font_set_force_autohinter(data, (godot_rid *)&p_font_rid, p_force_autohinter); -} - -bool TextServerGDNative::font_is_force_autohinter(RID p_font_rid) const { - ERR_FAIL_COND_V(interface == nullptr, false); - return interface->font_is_force_autohinter(data, (godot_rid *)&p_font_rid); -} - -void TextServerGDNative::font_set_hinting(RID p_font_rid, TextServer::Hinting p_hinting) { - ERR_FAIL_COND(interface == nullptr); - interface->font_set_hinting(data, (godot_rid *)&p_font_rid, (godot_int)p_hinting); -} - -TextServer::Hinting TextServerGDNative::font_get_hinting(RID p_font_rid) const { - ERR_FAIL_COND_V(interface == nullptr, TextServer::HINTING_NONE); - return (TextServer::Hinting)interface->font_get_hinting(data, (godot_rid *)&p_font_rid); -} - -void TextServerGDNative::font_set_variation_coordinates(RID p_font_rid, const Dictionary &p_variation_coordinates) { - ERR_FAIL_COND(interface == nullptr); - interface->font_set_variation_coordinates(data, (godot_rid *)&p_font_rid, (const godot_dictionary *)&p_variation_coordinates); -} - -Dictionary TextServerGDNative::font_get_variation_coordinates(RID p_font_rid) const { - ERR_FAIL_COND_V(interface == nullptr, Dictionary()); - godot_dictionary result = interface->font_get_variation_coordinates(data, (godot_rid *)&p_font_rid); - Dictionary dict = *(Dictionary *)&result; - godot_dictionary_destroy(&result); - return dict; -} - -void TextServerGDNative::font_set_oversampling(RID p_font_rid, real_t p_oversampling) { - ERR_FAIL_COND(interface == nullptr); - interface->font_set_oversampling(data, (godot_rid *)&p_font_rid, p_oversampling); -} - -real_t TextServerGDNative::font_get_oversampling(RID p_font_rid) const { - ERR_FAIL_COND_V(interface == nullptr, 0.0f); - return interface->font_get_oversampling(data, (godot_rid *)&p_font_rid); -} - -Array TextServerGDNative::font_get_size_cache_list(RID p_font_rid) const { - ERR_FAIL_COND_V(interface == nullptr, Array()); - godot_array result = interface->font_get_size_cache_list(data, (godot_rid *)&p_font_rid); - Array list = *(Array *)&result; - godot_array_destroy(&result); - return list; -} - -void TextServerGDNative::font_clear_size_cache(RID p_font_rid) { - ERR_FAIL_COND(interface == nullptr); - interface->font_clear_size_cache(data, (godot_rid *)&p_font_rid); -} - -void TextServerGDNative::font_remove_size_cache(RID p_font_rid, const Vector2i &p_size) { - ERR_FAIL_COND(interface == nullptr); - interface->font_remove_size_cache(data, (godot_rid *)&p_font_rid, (const godot_vector2i *)&p_size); -} - -void TextServerGDNative::font_set_ascent(RID p_font_rid, int p_size, real_t p_ascent) { - ERR_FAIL_COND(interface == nullptr); - interface->font_set_ascent(data, (godot_rid *)&p_font_rid, p_size, p_ascent); -} - -real_t TextServerGDNative::font_get_ascent(RID p_font_rid, int p_size) const { - ERR_FAIL_COND_V(interface == nullptr, 0.0f); - return interface->font_get_ascent(data, (godot_rid *)&p_font_rid, p_size); -} - -void TextServerGDNative::font_set_descent(RID p_font_rid, int p_size, real_t p_descent) { - ERR_FAIL_COND(interface == nullptr); - interface->font_set_descent(data, (godot_rid *)&p_font_rid, p_size, p_descent); -} - -real_t TextServerGDNative::font_get_descent(RID p_font_rid, int p_size) const { - ERR_FAIL_COND_V(interface == nullptr, 0.0f); - return interface->font_get_descent(data, (godot_rid *)&p_font_rid, p_size); -} - -void TextServerGDNative::font_set_underline_position(RID p_font_rid, int p_size, real_t p_underline_position) { - ERR_FAIL_COND(interface == nullptr); - interface->font_set_underline_position(data, (godot_rid *)&p_font_rid, p_size, p_underline_position); -} - -real_t TextServerGDNative::font_get_underline_position(RID p_font_rid, int p_size) const { - ERR_FAIL_COND_V(interface == nullptr, 0.0f); - return interface->font_get_underline_position(data, (godot_rid *)&p_font_rid, p_size); -} - -void TextServerGDNative::font_set_underline_thickness(RID p_font_rid, int p_size, real_t p_underline_thickness) { - ERR_FAIL_COND(interface == nullptr); - interface->font_set_underline_thickness(data, (godot_rid *)&p_font_rid, p_size, p_underline_thickness); -} - -real_t TextServerGDNative::font_get_underline_thickness(RID p_font_rid, int p_size) const { - ERR_FAIL_COND_V(interface == nullptr, 0.0f); - return interface->font_get_underline_thickness(data, (godot_rid *)&p_font_rid, p_size); -} - -void TextServerGDNative::font_set_scale(RID p_font_rid, int p_size, real_t p_scale) { - ERR_FAIL_COND(interface == nullptr); - interface->font_set_scale(data, (godot_rid *)&p_font_rid, p_size, p_scale); -} - -real_t TextServerGDNative::font_get_scale(RID p_font_rid, int p_size) const { - ERR_FAIL_COND_V(interface == nullptr, 0.0f); - return interface->font_get_scale(data, (godot_rid *)&p_font_rid, p_size); -} - -void TextServerGDNative::font_set_spacing(RID p_font_rid, int p_size, TextServer::SpacingType p_spacing, int p_value) { - ERR_FAIL_COND(interface == nullptr); - interface->font_set_spacing(data, (godot_rid *)&p_font_rid, p_size, (godot_int)p_spacing, p_value); -} - -int TextServerGDNative::font_get_spacing(RID p_font_rid, int p_size, TextServer::SpacingType p_spacing) const { - ERR_FAIL_COND_V(interface == nullptr, 0); - return interface->font_get_spacing(data, (godot_rid *)&p_font_rid, p_size, (godot_int)p_spacing); -} - -int TextServerGDNative::font_get_texture_count(RID p_font_rid, const Vector2i &p_size) const { - ERR_FAIL_COND_V(interface == nullptr, -1); - return interface->font_get_texture_count(data, (godot_rid *)&p_font_rid, (const godot_vector2i *)&p_size); -} - -void TextServerGDNative::font_clear_textures(RID p_font_rid, const Vector2i &p_size) { - ERR_FAIL_COND(interface == nullptr); - interface->font_clear_textures(data, (godot_rid *)&p_font_rid, (const godot_vector2i *)&p_size); -} - -void TextServerGDNative::font_remove_texture(RID p_font_rid, const Vector2i &p_size, int p_texture_index) { - ERR_FAIL_COND(interface == nullptr); - interface->font_remove_texture(data, (godot_rid *)&p_font_rid, (const godot_vector2i *)&p_size, p_texture_index); -} - -void TextServerGDNative::font_set_texture_image(RID p_font_rid, const Vector2i &p_size, int p_texture_index, const Ref<Image> &p_image) { - ERR_FAIL_COND(interface == nullptr); - interface->font_set_texture_image(data, (godot_rid *)&p_font_rid, (const godot_vector2i *)&p_size, p_texture_index, (const godot_object *)p_image.ptr()); -} - -Ref<Image> TextServerGDNative::font_get_texture_image(RID p_font_rid, const Vector2i &p_size, int p_texture_index) const { - ERR_FAIL_COND_V(interface == nullptr, Ref<Image>()); - godot_object *result = interface->font_get_texture_image(data, (godot_rid *)&p_font_rid, (const godot_vector2i *)&p_size, p_texture_index); - return Ref<Image>((Image *)result); -} - -void TextServerGDNative::font_set_texture_offsets(RID p_font_rid, const Vector2i &p_size, int p_texture_index, const PackedInt32Array &p_offset) { - ERR_FAIL_COND(interface == nullptr); - interface->font_set_texture_offsets(data, (godot_rid *)&p_font_rid, (const godot_vector2i *)&p_size, p_texture_index, (const godot_packed_int32_array *)&p_offset); -} - -PackedInt32Array TextServerGDNative::font_get_texture_offsets(RID p_font_rid, const Vector2i &p_size, int p_texture_index) const { - ERR_FAIL_COND_V(interface == nullptr, PackedInt32Array()); - godot_packed_int32_array result = interface->font_get_texture_offsets(data, (godot_rid *)&p_font_rid, (const godot_vector2i *)&p_size, p_texture_index); - PackedInt32Array offset = *(PackedInt32Array *)&result; - godot_packed_int32_array_destroy(&result); - return offset; -} - -Array TextServerGDNative::font_get_glyph_list(RID p_font_rid, const Vector2i &p_size) const { - ERR_FAIL_COND_V(interface == nullptr, Array()); - godot_array result = interface->font_get_glyph_list(data, (godot_rid *)&p_font_rid, (const godot_vector2i *)&p_size); - Array list = *(Array *)&result; - godot_array_destroy(&result); - return list; -} - -void TextServerGDNative::font_clear_glyphs(RID p_font_rid, const Vector2i &p_size) { - ERR_FAIL_COND(interface == nullptr); - interface->font_clear_glyphs(data, (godot_rid *)&p_font_rid, (const godot_vector2i *)&p_size); -} - -void TextServerGDNative::font_remove_glyph(RID p_font_rid, const Vector2i &p_size, int32_t p_glyph) { - ERR_FAIL_COND(interface == nullptr); - interface->font_remove_glyph(data, (godot_rid *)&p_font_rid, (const godot_vector2i *)&p_size, p_glyph); -} - -Vector2 TextServerGDNative::font_get_glyph_advance(RID p_font_rid, int p_size, int32_t p_glyph) const { - ERR_FAIL_COND_V(interface == nullptr, Vector2()); - godot_vector2 result = interface->font_get_glyph_advance(data, (godot_rid *)&p_font_rid, p_size, p_glyph); - Vector2 adv = *(Vector2 *)&result; - return adv; -} - -void TextServerGDNative::font_set_glyph_advance(RID p_font_rid, int p_size, int32_t p_glyph, const Vector2 &p_advance) { - ERR_FAIL_COND(interface == nullptr); - interface->font_set_glyph_advance(data, (godot_rid *)&p_font_rid, p_size, p_glyph, (const godot_vector2 *)&p_advance); -} - -Vector2 TextServerGDNative::font_get_glyph_offset(RID p_font_rid, const Vector2i &p_size, int32_t p_glyph) const { - ERR_FAIL_COND_V(interface == nullptr, Vector2()); - godot_vector2 result = interface->font_get_glyph_offset(data, (godot_rid *)&p_font_rid, (const godot_vector2i *)&p_size, p_glyph); - Vector2 off = *(Vector2 *)&result; - return off; -} - -void TextServerGDNative::font_set_glyph_offset(RID p_font_rid, const Vector2i &p_size, int32_t p_glyph, const Vector2 &p_offset) { - ERR_FAIL_COND(interface == nullptr); - interface->font_set_glyph_offset(data, (godot_rid *)&p_font_rid, (const godot_vector2i *)&p_size, p_glyph, (const godot_vector2 *)&p_offset); -} - -Vector2 TextServerGDNative::font_get_glyph_size(RID p_font_rid, const Vector2i &p_size, int32_t p_glyph) const { - ERR_FAIL_COND_V(interface == nullptr, Vector2()); - godot_vector2 result = interface->font_get_glyph_size(data, (godot_rid *)&p_font_rid, (const godot_vector2i *)&p_size, p_glyph); - Vector2 sz = *(Vector2 *)&result; - return sz; -} - -void TextServerGDNative::font_set_glyph_size(RID p_font_rid, const Vector2i &p_size, int32_t p_glyph, const Vector2 &p_gl_size) { - ERR_FAIL_COND(interface == nullptr); - interface->font_set_glyph_size(data, (godot_rid *)&p_font_rid, (const godot_vector2i *)&p_size, p_glyph, (const godot_vector2 *)&p_gl_size); -} - -Rect2 TextServerGDNative::font_get_glyph_uv_rect(RID p_font_rid, const Vector2i &p_size, int32_t p_glyph) const { - ERR_FAIL_COND_V(interface == nullptr, Rect2()); - godot_rect2 result = interface->font_get_glyph_uv_rect(data, (godot_rid *)&p_font_rid, (const godot_vector2i *)&p_size, p_glyph); - Rect2 uv = *(Rect2 *)&result; - return uv; -} - -void TextServerGDNative::font_set_glyph_uv_rect(RID p_font_rid, const Vector2i &p_size, int32_t p_glyph, const Rect2 &p_uv_rect) { - ERR_FAIL_COND(interface == nullptr); - interface->font_set_glyph_uv_rect(data, (godot_rid *)&p_font_rid, (const godot_vector2i *)&p_size, p_glyph, (const godot_rect2 *)&p_uv_rect); -} - -int TextServerGDNative::font_get_glyph_texture_idx(RID p_font_rid, const Vector2i &p_size, int32_t p_glyph) const { - ERR_FAIL_COND_V(interface == nullptr, -1); - return interface->font_get_glyph_texture_idx(data, (godot_rid *)&p_font_rid, (const godot_vector2i *)&p_size, p_glyph); -} - -void TextServerGDNative::font_set_glyph_texture_idx(RID p_font_rid, const Vector2i &p_size, int32_t p_glyph, int p_texture_idx) { - ERR_FAIL_COND(interface == nullptr); - interface->font_set_glyph_texture_idx(data, (godot_rid *)&p_font_rid, (const godot_vector2i *)&p_size, p_glyph, p_texture_idx); -} - -bool TextServerGDNative::font_get_glyph_contours(RID p_font_rid, int p_size, int32_t p_index, Vector<Vector3> &r_points, Vector<int32_t> &r_contours, bool &r_orientation) const { - ERR_FAIL_COND_V(interface == nullptr, false); - return interface->font_get_glyph_contours(data, (godot_rid *)&p_font_rid, p_size, p_index, (godot_packed_vector3_array *)&r_points, (godot_packed_int32_array *)&r_contours, &r_orientation); -} - -Array TextServerGDNative::font_get_kerning_list(RID p_font_rid, int p_size) const { - ERR_FAIL_COND_V(interface == nullptr, Array()); - godot_array result = interface->font_get_kerning_list(data, (godot_rid *)&p_font_rid, p_size); - Array list = *(Array *)&result; - godot_array_destroy(&result); - return list; -} - -void TextServerGDNative::font_clear_kerning_map(RID p_font_rid, int p_size) { - ERR_FAIL_COND(interface == nullptr); - interface->font_clear_kerning_map(data, (godot_rid *)&p_font_rid, p_size); -} - -void TextServerGDNative::font_remove_kerning(RID p_font_rid, int p_size, const Vector2i &p_glyph_pair) { - ERR_FAIL_COND(interface == nullptr); - interface->font_remove_kerning(data, (godot_rid *)&p_font_rid, p_size, (const godot_vector2i *)&p_glyph_pair); -} - -void TextServerGDNative::font_set_kerning(RID p_font_rid, int p_size, const Vector2i &p_glyph_pair, const Vector2 &p_kerning) { - ERR_FAIL_COND(interface == nullptr); - interface->font_set_kerning(data, (godot_rid *)&p_font_rid, p_size, (const godot_vector2i *)&p_glyph_pair, (const godot_vector2 *)&p_kerning); -} - -Vector2 TextServerGDNative::font_get_kerning(RID p_font_rid, int p_size, const Vector2i &p_glyph_pair) const { - ERR_FAIL_COND_V(interface == nullptr, Vector2()); - godot_vector2 result = interface->font_get_kerning(data, (godot_rid *)&p_font_rid, p_size, (const godot_vector2i *)&p_glyph_pair); - Vector2 kern = *(Vector2 *)&result; - return kern; -} - -int32_t TextServerGDNative::font_get_glyph_index(RID p_font_rid, int p_size, char32_t p_char, char32_t p_variation_selector) const { - ERR_FAIL_COND_V(interface == nullptr, 0); - return interface->font_get_glyph_index(data, (godot_rid *)&p_font_rid, p_size, p_char, p_variation_selector); -} - -bool TextServerGDNative::font_has_char(RID p_font_rid, char32_t p_char) const { - ERR_FAIL_COND_V(interface == nullptr, false); - return interface->font_has_char(data, (godot_rid *)&p_font_rid, p_char); -} - -String TextServerGDNative::font_get_supported_chars(RID p_font_rid) const { - ERR_FAIL_COND_V(interface == nullptr, String()); - godot_string result = interface->font_get_supported_chars(data, (godot_rid *)&p_font_rid); - String chars = *(String *)&result; - godot_string_destroy(&result); - return chars; -} - -void TextServerGDNative::font_render_range(RID p_font_rid, const Vector2i &p_size, char32_t p_start, char32_t p_end) { - ERR_FAIL_COND(interface == nullptr); - interface->font_render_range(data, (godot_rid *)&p_font_rid, (const godot_vector2i *)&p_size, p_start, p_end); -} - -void TextServerGDNative::font_render_glyph(RID p_font_rid, const Vector2i &p_size, int32_t p_index) { - ERR_FAIL_COND(interface == nullptr); - interface->font_render_glyph(data, (godot_rid *)&p_font_rid, (const godot_vector2i *)&p_size, p_index); -} - -void TextServerGDNative::font_draw_glyph(RID p_font_rid, RID p_canvas, int p_size, const Vector2 &p_pos, int32_t p_index, const Color &p_color) const { - ERR_FAIL_COND(interface == nullptr); - interface->font_draw_glyph(data, (godot_rid *)&p_font_rid, (godot_rid *)&p_canvas, p_size, (const godot_vector2 *)&p_pos, p_index, (const godot_color *)&p_color); -} - -void TextServerGDNative::font_draw_glyph_outline(RID p_font_rid, RID p_canvas, int p_size, int p_outline_size, const Vector2 &p_pos, int32_t p_index, const Color &p_color) const { - ERR_FAIL_COND(interface == nullptr); - interface->font_draw_glyph_outline(data, (godot_rid *)&p_font_rid, (godot_rid *)&p_canvas, p_size, p_outline_size, (const godot_vector2 *)&p_pos, p_index, (const godot_color *)&p_color); -} - -bool TextServerGDNative::font_is_language_supported(RID p_font_rid, const String &p_language) const { - ERR_FAIL_COND_V(interface == nullptr, false); - return interface->font_is_language_supported(data, (godot_rid *)&p_font_rid, (const godot_string *)&p_language); -} - -void TextServerGDNative::font_set_language_support_override(RID p_font_rid, const String &p_language, bool p_supported) { - ERR_FAIL_COND(interface == nullptr); - interface->font_set_language_support_override(data, (godot_rid *)&p_font_rid, (const godot_string *)&p_language, p_supported); -} - -bool TextServerGDNative::font_get_language_support_override(RID p_font_rid, const String &p_language) { - ERR_FAIL_COND_V(interface == nullptr, false); - return interface->font_get_language_support_override(data, (godot_rid *)&p_font_rid, (const godot_string *)&p_language); -} - -void TextServerGDNative::font_remove_language_support_override(RID p_font_rid, const String &p_language) { - ERR_FAIL_COND(interface == nullptr); - interface->font_remove_language_support_override(data, (godot_rid *)&p_font_rid, (const godot_string *)&p_language); -} - -Vector<String> TextServerGDNative::font_get_language_support_overrides(RID p_font_rid) { - ERR_FAIL_COND_V(interface == nullptr, PackedStringArray()); - godot_packed_string_array result = interface->font_get_language_support_overrides(data, (godot_rid *)&p_font_rid); - PackedStringArray list = *(PackedStringArray *)&result; - godot_packed_string_array_destroy(&result); - return list; -} - -bool TextServerGDNative::font_is_script_supported(RID p_font_rid, const String &p_script) const { - ERR_FAIL_COND_V(interface == nullptr, false); - return interface->font_is_script_supported(data, (godot_rid *)&p_font_rid, (const godot_string *)&p_script); -} - -void TextServerGDNative::font_set_script_support_override(RID p_font_rid, const String &p_script, bool p_supported) { - ERR_FAIL_COND(interface == nullptr); - interface->font_set_script_support_override(data, (godot_rid *)&p_font_rid, (const godot_string *)&p_script, p_supported); -} - -bool TextServerGDNative::font_get_script_support_override(RID p_font_rid, const String &p_script) { - ERR_FAIL_COND_V(interface == nullptr, false); - return interface->font_get_script_support_override(data, (godot_rid *)&p_font_rid, (const godot_string *)&p_script); -} - -void TextServerGDNative::font_remove_script_support_override(RID p_font_rid, const String &p_script) { - ERR_FAIL_COND(interface == nullptr); - interface->font_remove_script_support_override(data, (godot_rid *)&p_font_rid, (const godot_string *)&p_script); -} - -Vector<String> TextServerGDNative::font_get_script_support_overrides(RID p_font_rid) { - ERR_FAIL_COND_V(interface == nullptr, PackedStringArray()); - godot_packed_string_array result = interface->font_get_script_support_overrides(data, (godot_rid *)&p_font_rid); - PackedStringArray list = *(PackedStringArray *)&result; - godot_packed_string_array_destroy(&result); - return list; -} - -Dictionary TextServerGDNative::font_supported_feature_list(RID p_font_rid) const { - ERR_FAIL_COND_V(interface == nullptr, Dictionary()); - godot_dictionary result = interface->font_supported_feature_list(data, (godot_rid *)&p_font_rid); - Dictionary dict = *(Dictionary *)&result; - godot_dictionary_destroy(&result); - return dict; -} - -Dictionary TextServerGDNative::font_supported_variation_list(RID p_font_rid) const { - ERR_FAIL_COND_V(interface == nullptr, Dictionary()); - godot_dictionary result = interface->font_supported_variation_list(data, (godot_rid *)&p_font_rid); - Dictionary dict = *(Dictionary *)&result; - godot_dictionary_destroy(&result); - return dict; -} - -real_t TextServerGDNative::font_get_global_oversampling() const { - ERR_FAIL_COND_V(interface == nullptr, 0.0f); - return interface->font_get_global_oversampling(data); -} - -void TextServerGDNative::font_set_global_oversampling(real_t p_oversampling) { - ERR_FAIL_COND(interface == nullptr); - interface->font_set_global_oversampling(data, p_oversampling); -} - -/*************************************************************************/ -/* Shaped text buffer interface */ -/*************************************************************************/ - -RID TextServerGDNative::create_shaped_text(TextServer::Direction p_direction, TextServer::Orientation p_orientation) { - ERR_FAIL_COND_V(interface == nullptr, RID()); - godot_rid result = interface->create_shaped_text(data, (godot_int)p_direction, (godot_int)p_orientation); - RID rid = *(RID *)&result; - return rid; -} - -void TextServerGDNative::shaped_text_clear(RID p_shaped) { - ERR_FAIL_COND(interface == nullptr); - interface->shaped_text_clear(data, (godot_rid *)&p_shaped); -} - -void TextServerGDNative::shaped_text_set_direction(RID p_shaped, TextServer::Direction p_direction) { - ERR_FAIL_COND(interface == nullptr); - interface->shaped_text_set_direction(data, (godot_rid *)&p_shaped, (godot_int)p_direction); -} - -TextServer::Direction TextServerGDNative::shaped_text_get_direction(RID p_shaped) const { - ERR_FAIL_COND_V(interface == nullptr, TextServer::DIRECTION_LTR); - return (TextServer::Direction)interface->shaped_text_get_direction(data, (godot_rid *)&p_shaped); -} - -void TextServerGDNative::shaped_text_set_orientation(RID p_shaped, TextServer::Orientation p_orientation) { - ERR_FAIL_COND(interface == nullptr); - interface->shaped_text_set_orientation(data, (godot_rid *)&p_shaped, (godot_int)p_orientation); -} - -TextServer::Orientation TextServerGDNative::shaped_text_get_orientation(RID p_shaped) const { - ERR_FAIL_COND_V(interface == nullptr, TextServer::ORIENTATION_HORIZONTAL); - return (TextServer::Orientation)interface->shaped_text_get_orientation(data, (godot_rid *)&p_shaped); -} - -void TextServerGDNative::shaped_text_set_bidi_override(RID p_shaped, const Vector<Vector2i> &p_override) { - ERR_FAIL_COND(interface == nullptr); - interface->shaped_text_set_bidi_override(data, (godot_rid *)&p_shaped, (const godot_packed_vector2i_array *)&p_override); -} - -void TextServerGDNative::shaped_text_set_preserve_invalid(RID p_shaped, bool p_enabled) { - ERR_FAIL_COND(interface == nullptr); - interface->shaped_text_set_preserve_invalid(data, (godot_rid *)&p_shaped, p_enabled); -} - -bool TextServerGDNative::shaped_text_get_preserve_invalid(RID p_shaped) const { - ERR_FAIL_COND_V(interface == nullptr, false); - return (TextServer::Orientation)interface->shaped_text_get_preserve_invalid(data, (godot_rid *)&p_shaped); -} - -void TextServerGDNative::shaped_text_set_preserve_control(RID p_shaped, bool p_enabled) { - ERR_FAIL_COND(interface == nullptr); - interface->shaped_text_set_preserve_control(data, (godot_rid *)&p_shaped, p_enabled); -} - -bool TextServerGDNative::shaped_text_get_preserve_control(RID p_shaped) const { - ERR_FAIL_COND_V(interface == nullptr, false); - return (TextServer::Orientation)interface->shaped_text_get_preserve_control(data, (godot_rid *)&p_shaped); -} - -bool TextServerGDNative::shaped_text_add_string(RID p_shaped, const String &p_text, const Vector<RID> &p_fonts, int p_size, const Dictionary &p_opentype_features, const String &p_language) { - ERR_FAIL_COND_V(interface == nullptr, false); - return interface->shaped_text_add_string(data, (godot_rid *)&p_shaped, (const godot_string *)&p_text, (const godot_rid **)p_fonts.ptr(), p_size, (const godot_dictionary *)&p_opentype_features, (const godot_string *)&p_language); -} - -bool TextServerGDNative::shaped_text_add_object(RID p_shaped, Variant p_key, const Size2 &p_size, InlineAlign p_inline_align, int p_length) { - ERR_FAIL_COND_V(interface == nullptr, false); - return interface->shaped_text_add_object(data, (godot_rid *)&p_shaped, (const godot_variant *)&p_key, (const godot_vector2 *)&p_size, (godot_int)p_inline_align, p_length); -} - -bool TextServerGDNative::shaped_text_resize_object(RID p_shaped, Variant p_key, const Size2 &p_size, InlineAlign p_inline_align) { - ERR_FAIL_COND_V(interface == nullptr, false); - return interface->shaped_text_resize_object(data, (godot_rid *)&p_shaped, (const godot_variant *)&p_key, (const godot_vector2 *)&p_size, (godot_int)p_inline_align); -} - -RID TextServerGDNative::shaped_text_substr(RID p_shaped, int p_start, int p_length) const { - ERR_FAIL_COND_V(interface == nullptr, RID()); - godot_rid result = interface->shaped_text_substr(data, (godot_rid *)&p_shaped, (godot_int)p_start, (godot_int)p_length); - RID rid = *(RID *)&result; - return rid; -} - -RID TextServerGDNative::shaped_text_get_parent(RID p_shaped) const { - ERR_FAIL_COND_V(interface == nullptr, RID()); - godot_rid result = interface->shaped_text_get_parent(data, (godot_rid *)&p_shaped); - RID rid = *(RID *)&result; - return rid; -} - -real_t TextServerGDNative::shaped_text_fit_to_width(RID p_shaped, real_t p_width, uint8_t p_jst_flags) { - ERR_FAIL_COND_V(interface == nullptr, 0.f); - return interface->shaped_text_fit_to_width(data, (godot_rid *)&p_shaped, p_width, p_jst_flags); -} - -real_t TextServerGDNative::shaped_text_tab_align(RID p_shaped, const Vector<real_t> &p_tab_stops) { - ERR_FAIL_COND_V(interface == nullptr, 0.f); - return interface->shaped_text_tab_align(data, (godot_rid *)&p_shaped, (godot_packed_float32_array *)&p_tab_stops); -} - -bool TextServerGDNative::shaped_text_shape(RID p_shaped) { - ERR_FAIL_COND_V(interface == nullptr, false); - return interface->shaped_text_shape(data, (godot_rid *)&p_shaped); -} - -bool TextServerGDNative::shaped_text_update_breaks(RID p_shaped) { - ERR_FAIL_COND_V(interface == nullptr, false); - return interface->shaped_text_update_breaks(data, (godot_rid *)&p_shaped); -} - -bool TextServerGDNative::shaped_text_update_justification_ops(RID p_shaped) { - ERR_FAIL_COND_V(interface == nullptr, false); - return interface->shaped_text_update_justification_ops(data, (godot_rid *)&p_shaped); -} - -void TextServerGDNative::shaped_text_overrun_trim_to_width(RID p_shaped_line, real_t p_width, uint8_t p_trim_flags) { - ERR_FAIL_COND(interface == nullptr); - interface->shaped_text_overrun_trim_to_width(data, (godot_rid *)&p_shaped_line, p_width, p_trim_flags); -}; - -bool TextServerGDNative::shaped_text_is_ready(RID p_shaped) const { - ERR_FAIL_COND_V(interface == nullptr, false); - return interface->shaped_text_is_ready(data, (godot_rid *)&p_shaped); -} - -Vector<TextServer::Glyph> TextServerGDNative::shaped_text_get_glyphs(RID p_shaped) const { - ERR_FAIL_COND_V(interface == nullptr, Vector<TextServer::Glyph>()); - godot_packed_glyph_array result = interface->shaped_text_get_glyphs(data, (godot_rid *)&p_shaped); - Vector<TextServer::Glyph> glyphs = *(Vector<TextServer::Glyph> *)&result; - godot_packed_glyph_array_destroy(&result); - return glyphs; -} - -Vector2i TextServerGDNative::shaped_text_get_range(RID p_shaped) const { - ERR_FAIL_COND_V(interface == nullptr, Vector2i()); - godot_vector2i result = interface->shaped_text_get_range(data, (godot_rid *)&p_shaped); - Vector2i range = *(Vector2i *)&result; - return range; -} - -Vector<TextServer::Glyph> TextServerGDNative::shaped_text_sort_logical(RID p_shaped) { - ERR_FAIL_COND_V(interface == nullptr, Vector<TextServer::Glyph>()); - godot_packed_glyph_array result = interface->shaped_text_sort_logical(data, (godot_rid *)&p_shaped); - Vector<TextServer::Glyph> glyphs = *(Vector<TextServer::Glyph> *)&result; - godot_packed_glyph_array_destroy(&result); - return glyphs; -} - -Vector<Vector2i> TextServerGDNative::shaped_text_get_line_breaks_adv(RID p_shaped, const Vector<real_t> &p_width, int p_start, bool p_once, uint8_t p_break_flags) const { - ERR_FAIL_COND_V(interface == nullptr, Vector<Vector2i>()); - if (interface->shaped_text_get_line_breaks_adv != nullptr) { - godot_packed_vector2i_array result = interface->shaped_text_get_line_breaks_adv(data, (godot_rid *)&p_shaped, (godot_packed_float32_array *)&p_width, p_start, p_once, p_break_flags); - Vector<Vector2i> breaks = *(Vector<Vector2i> *)&result; - godot_packed_vector2i_array_destroy(&result); - return breaks; - } else { - return TextServer::shaped_text_get_line_breaks_adv(p_shaped, p_width, p_break_flags); - } -} - -Vector<Vector2i> TextServerGDNative::shaped_text_get_line_breaks(RID p_shaped, real_t p_width, int p_start, uint8_t p_break_flags) const { - ERR_FAIL_COND_V(interface == nullptr, Vector<Vector2i>()); - if (interface->shaped_text_get_line_breaks != nullptr) { - godot_packed_vector2i_array result = interface->shaped_text_get_line_breaks(data, (godot_rid *)&p_shaped, p_width, p_start, p_break_flags); - Vector<Vector2i> breaks = *(Vector<Vector2i> *)&result; - godot_packed_vector2i_array_destroy(&result); - return breaks; - } else { - return TextServer::shaped_text_get_line_breaks(p_shaped, p_width, p_break_flags); - } -} - -Vector<Vector2i> TextServerGDNative::shaped_text_get_word_breaks(RID p_shaped, int p_grapheme_flags) const { - ERR_FAIL_COND_V(interface == nullptr, Vector<Vector2i>()); - if (interface->shaped_text_get_word_breaks != nullptr) { - godot_packed_vector2i_array result = interface->shaped_text_get_word_breaks(data, (godot_rid *)&p_shaped, p_grapheme_flags); - Vector<Vector2i> breaks = *(Vector<Vector2i> *)&result; - godot_packed_vector2i_array_destroy(&result); - return breaks; - } else { - return TextServer::shaped_text_get_word_breaks(p_shaped, p_grapheme_flags); - } -} - -Array TextServerGDNative::shaped_text_get_objects(RID p_shaped) const { - ERR_FAIL_COND_V(interface == nullptr, Array()); - godot_array result = interface->shaped_text_get_objects(data, (godot_rid *)&p_shaped); - Array rect = *(Array *)&result; - return rect; -} - -Rect2 TextServerGDNative::shaped_text_get_object_rect(RID p_shaped, Variant p_key) const { - ERR_FAIL_COND_V(interface == nullptr, Rect2()); - godot_rect2 result = interface->shaped_text_get_object_rect(data, (godot_rid *)&p_shaped, (const godot_variant *)&p_key); - Rect2 rect = *(Rect2 *)&result; - return rect; -} - -Size2 TextServerGDNative::shaped_text_get_size(RID p_shaped) const { - ERR_FAIL_COND_V(interface == nullptr, Size2()); - godot_vector2 result = interface->shaped_text_get_size(data, (godot_rid *)&p_shaped); - Size2 size = *(Size2 *)&result; - return size; -} - -real_t TextServerGDNative::shaped_text_get_ascent(RID p_shaped) const { - ERR_FAIL_COND_V(interface == nullptr, 0.f); - return interface->shaped_text_get_ascent(data, (godot_rid *)&p_shaped); -} - -real_t TextServerGDNative::shaped_text_get_descent(RID p_shaped) const { - ERR_FAIL_COND_V(interface == nullptr, 0.f); - return interface->shaped_text_get_descent(data, (godot_rid *)&p_shaped); -} - -real_t TextServerGDNative::shaped_text_get_width(RID p_shaped) const { - ERR_FAIL_COND_V(interface == nullptr, 0.f); - return interface->shaped_text_get_width(data, (godot_rid *)&p_shaped); -} - -real_t TextServerGDNative::shaped_text_get_underline_position(RID p_shaped) const { - ERR_FAIL_COND_V(interface == nullptr, 0.f); - return interface->shaped_text_get_underline_position(data, (godot_rid *)&p_shaped); -} - -real_t TextServerGDNative::shaped_text_get_underline_thickness(RID p_shaped) const { - ERR_FAIL_COND_V(interface == nullptr, 0.f); - return interface->shaped_text_get_underline_thickness(data, (godot_rid *)&p_shaped); -} - -String TextServerGDNative::format_number(const String &p_string, const String &p_language) const { - ERR_FAIL_COND_V(interface == nullptr, String()); - godot_string result = interface->format_number(data, (const godot_string *)&p_string, (const godot_string *)&p_language); - if (interface->format_number == nullptr) { - return p_string; - } - String ret = *(String *)&result; - godot_string_destroy(&result); - return ret; -} - -String TextServerGDNative::parse_number(const String &p_string, const String &p_language) const { - ERR_FAIL_COND_V(interface == nullptr, String()); - if (interface->parse_number == nullptr) { - return p_string; - } - godot_string result = interface->parse_number(data, (const godot_string *)&p_string, (const godot_string *)&p_language); - String ret = *(String *)&result; - godot_string_destroy(&result); - return ret; -} - -String TextServerGDNative::percent_sign(const String &p_language) const { - ERR_FAIL_COND_V(interface == nullptr, String()); - if (interface->percent_sign == nullptr) { - return "%"; - } - godot_string result = interface->percent_sign(data, (const godot_string *)&p_language); - String ret = *(String *)&result; - godot_string_destroy(&result); - return ret; -} - -TextServer *TextServerGDNative::create_func(Error &r_error, void *p_user_data) { - const godot_text_interface_gdnative *interface = (const godot_text_interface_gdnative *)p_user_data; - r_error = OK; - - TextServerGDNative *server = memnew(TextServerGDNative()); - server->interface = interface; - server->data = interface->constructor((godot_object *)server); - - return server; -} - -TextServerGDNative::TextServerGDNative() { - data = nullptr; - interface = nullptr; -} - -TextServerGDNative::~TextServerGDNative() { - if (interface != nullptr) { - interface->destructor(data); - data = nullptr; - interface = nullptr; - } -} - -/*************************************************************************/ -/* GDNative functions */ -/*************************************************************************/ - -#ifdef __cplusplus -extern "C" { -#endif - -static_assert(sizeof(godot_glyph) == sizeof(TextServer::Glyph), "Glyph size mismatch"); -static_assert(sizeof(godot_packed_glyph_array) == sizeof(Vector<TextServer::Glyph>), "Vector<Glyph> size mismatch"); - -void GDAPI godot_text_register_interface(const godot_text_interface_gdnative *p_interface, const godot_string *p_name, uint32_t p_features) { - ERR_FAIL_COND(p_interface->version.major != 1); - String name = *(String *)p_name; - TextServerManager::register_create_function(name + "(GDNative)", p_features, TextServerGDNative::create_func, (void *)p_interface); -} - -// Glyph - -void GDAPI godot_glyph_new(godot_glyph *r_dest) { - TextServer::Glyph *dest = (TextServer::Glyph *)r_dest; - *dest = TextServer::Glyph(); -} - -godot_vector2i GDAPI godot_glyph_get_range(const godot_glyph *p_self) { - godot_vector2i dest; - Vector2i *d = (Vector2i *)&dest; - const TextServer::Glyph *self = (const TextServer::Glyph *)p_self; - d->x = self->start; - d->y = self->end; - return dest; -} - -void GDAPI godot_glyph_set_range(godot_glyph *p_self, const godot_vector2i *p_range) { - TextServer::Glyph *self = (TextServer::Glyph *)p_self; - const Vector2i *range = (const Vector2i *)p_range; - self->start = range->x; - self->end = range->y; -} - -godot_int GDAPI godot_glyph_get_count(const godot_glyph *p_self) { - const TextServer::Glyph *self = (const TextServer::Glyph *)p_self; - return self->count; -} - -void GDAPI godot_glyph_set_count(godot_glyph *p_self, godot_int p_count) { - TextServer::Glyph *self = (TextServer::Glyph *)p_self; - self->count = p_count; -} - -godot_int GDAPI godot_glyph_get_repeat(const godot_glyph *p_self) { - const TextServer::Glyph *self = (const TextServer::Glyph *)p_self; - return self->repeat; -} - -void GDAPI godot_glyph_set_repeat(godot_glyph *p_self, godot_int p_repeat) { - TextServer::Glyph *self = (TextServer::Glyph *)p_self; - self->repeat = p_repeat; -} - -godot_int GDAPI godot_glyph_get_flags(const godot_glyph *p_self) { - const TextServer::Glyph *self = (const TextServer::Glyph *)p_self; - return self->flags; -} - -void GDAPI godot_glyph_set_flags(godot_glyph *p_self, godot_int p_flags) { - TextServer::Glyph *self = (TextServer::Glyph *)p_self; - self->flags = p_flags; -} - -godot_vector2 GDAPI godot_glyph_get_offset(const godot_glyph *p_self) { - godot_vector2 dest; - Vector2 *d = (Vector2 *)&dest; - const TextServer::Glyph *self = (const TextServer::Glyph *)p_self; - d->x = self->x_off; - d->y = self->y_off; - return dest; -} - -void GDAPI godot_glyph_set_offset(godot_glyph *p_self, const godot_vector2 *p_offset) { - TextServer::Glyph *self = (TextServer::Glyph *)p_self; - const Vector2 *offset = (const Vector2 *)p_offset; - self->x_off = offset->x; - self->y_off = offset->y; -} - -godot_real_t GDAPI godot_glyph_get_advance(const godot_glyph *p_self) { - const TextServer::Glyph *self = (const TextServer::Glyph *)p_self; - return self->advance; -} - -void GDAPI godot_glyph_set_advance(godot_glyph *p_self, godot_real_t p_advance) { - TextServer::Glyph *self = (TextServer::Glyph *)p_self; - self->advance = p_advance; -} - -godot_rid GDAPI godot_glyph_get_font(const godot_glyph *p_self) { - godot_rid dest; - RID *d = (RID *)&dest; - const TextServer::Glyph *self = (const TextServer::Glyph *)p_self; - *d = self->font_rid; - return dest; -} - -void GDAPI godot_glyph_set_font(godot_glyph *p_self, godot_rid *p_font) { - TextServer::Glyph *self = (TextServer::Glyph *)p_self; - const RID *font = (const RID *)p_font; - self->font_rid = *font; -} - -godot_int GDAPI godot_glyph_get_font_size(const godot_glyph *p_self) { - const TextServer::Glyph *self = (const TextServer::Glyph *)p_self; - return self->font_size; -} - -void GDAPI godot_glyph_set_font_size(godot_glyph *p_self, godot_int p_size) { - TextServer::Glyph *self = (TextServer::Glyph *)p_self; - self->font_size = p_size; -} - -godot_int GDAPI godot_glyph_get_index(const godot_glyph *p_self) { - const TextServer::Glyph *self = (const TextServer::Glyph *)p_self; - return self->index; -} - -void GDAPI godot_glyph_set_index(godot_glyph *p_self, godot_int p_index) { - TextServer::Glyph *self = (TextServer::Glyph *)p_self; - self->index = p_index; -} - -// GlyphArray - -void GDAPI godot_packed_glyph_array_new(godot_packed_glyph_array *r_dest) { - Vector<TextServer::Glyph> *dest = (Vector<TextServer::Glyph> *)r_dest; - memnew_placement(dest, Vector<TextServer::Glyph>); -} - -void GDAPI godot_packed_glyph_array_new_copy(godot_packed_glyph_array *r_dest, const godot_packed_glyph_array *p_src) { - Vector<TextServer::Glyph> *dest = (Vector<TextServer::Glyph> *)r_dest; - const Vector<TextServer::Glyph> *src = (const Vector<TextServer::Glyph> *)p_src; - memnew_placement(dest, Vector<TextServer::Glyph>(*src)); -} - -const godot_glyph GDAPI *godot_packed_glyph_array_ptr(const godot_packed_glyph_array *p_self) { - const Vector<TextServer::Glyph> *self = (const Vector<TextServer::Glyph> *)p_self; - return (const godot_glyph *)self->ptr(); -} - -godot_glyph GDAPI *godot_packed_glyph_array_ptrw(godot_packed_glyph_array *p_self) { - Vector<TextServer::Glyph> *self = (Vector<TextServer::Glyph> *)p_self; - return (godot_glyph *)self->ptrw(); -} - -void GDAPI godot_packed_glyph_array_append(godot_packed_glyph_array *p_self, const godot_glyph *p_data) { - Vector<TextServer::Glyph> *self = (Vector<TextServer::Glyph> *)p_self; - TextServer::Glyph &s = *(TextServer::Glyph *)p_data; - self->push_back(s); -} - -void GDAPI godot_packed_glyph_array_append_array(godot_packed_glyph_array *p_self, const godot_packed_glyph_array *p_array) { - Vector<TextServer::Glyph> *self = (Vector<TextServer::Glyph> *)p_self; - Vector<TextServer::Glyph> *array = (Vector<TextServer::Glyph> *)p_array; - self->append_array(*array); -} - -godot_error GDAPI godot_packed_glyph_array_insert(godot_packed_glyph_array *p_self, const godot_int p_idx, const godot_glyph *p_data) { - Vector<TextServer::Glyph> *self = (Vector<TextServer::Glyph> *)p_self; - TextServer::Glyph &s = *(TextServer::Glyph *)p_data; - return (godot_error)self->insert(p_idx, s); -} - -godot_bool GDAPI godot_packed_glyph_array_has(godot_packed_glyph_array *p_self, const godot_glyph *p_value) { - Vector<TextServer::Glyph> *self = (Vector<TextServer::Glyph> *)p_self; - TextServer::Glyph &v = *(TextServer::Glyph *)p_value; - return (godot_bool)self->has(v); -} - -void GDAPI godot_packed_glyph_array_sort(godot_packed_glyph_array *p_self) { - Vector<TextServer::Glyph> *self = (Vector<TextServer::Glyph> *)p_self; - self->sort(); -} - -void GDAPI godot_packed_glyph_array_reverse(godot_packed_glyph_array *p_self) { - Vector<TextServer::Glyph> *self = (Vector<TextServer::Glyph> *)p_self; - self->reverse(); -} - -void GDAPI godot_packed_glyph_array_push_back(godot_packed_glyph_array *p_self, const godot_glyph *p_data) { - Vector<TextServer::Glyph> *self = (Vector<TextServer::Glyph> *)p_self; - TextServer::Glyph &s = *(TextServer::Glyph *)p_data; - self->push_back(s); -} - -void GDAPI godot_packed_glyph_array_remove(godot_packed_glyph_array *p_self, const godot_int p_idx) { - Vector<TextServer::Glyph> *self = (Vector<TextServer::Glyph> *)p_self; - self->remove(p_idx); -} - -void GDAPI godot_packed_glyph_array_resize(godot_packed_glyph_array *p_self, const godot_int p_size) { - Vector<TextServer::Glyph> *self = (Vector<TextServer::Glyph> *)p_self; - self->resize(p_size); -} - -void GDAPI godot_packed_glyph_array_set(godot_packed_glyph_array *p_self, const godot_int p_idx, const godot_glyph *p_data) { - Vector<TextServer::Glyph> *self = (Vector<TextServer::Glyph> *)p_self; - TextServer::Glyph &s = *(TextServer::Glyph *)p_data; - self->set(p_idx, s); -} - -godot_glyph GDAPI godot_packed_glyph_array_get(const godot_packed_glyph_array *p_self, const godot_int p_idx) { - const Vector<TextServer::Glyph> *self = (const Vector<TextServer::Glyph> *)p_self; - godot_glyph v; - TextServer::Glyph *s = (TextServer::Glyph *)&v; - *s = self->get(p_idx); - return v; -} - -godot_int GDAPI godot_packed_glyph_array_size(const godot_packed_glyph_array *p_self) { - const Vector<TextServer::Glyph> *self = (const Vector<TextServer::Glyph> *)p_self; - return self->size(); -} - -godot_bool GDAPI godot_packed_glyph_array_is_empty(const godot_packed_glyph_array *p_self) { - const Vector<TextServer::Glyph> *self = (const Vector<TextServer::Glyph> *)p_self; - return self->is_empty(); -} - -void GDAPI godot_packed_glyph_array_destroy(godot_packed_glyph_array *p_self) { - ((Vector<TextServer::Glyph> *)p_self)->~Vector(); -} - -#ifdef __cplusplus -} -#endif diff --git a/modules/gdnative/text/text_server_gdnative.h b/modules/gdnative/text/text_server_gdnative.h deleted file mode 100644 index f081637e23..0000000000 --- a/modules/gdnative/text/text_server_gdnative.h +++ /dev/null @@ -1,254 +0,0 @@ -/*************************************************************************/ -/* text_server_gdnative.h */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* https://godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */ -/* */ -/* Permission is hereby granted, free of charge, to any person obtaining */ -/* a copy of this software and associated documentation files (the */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/*************************************************************************/ - -#ifndef TEXT_SERVER_GDNATIVE_H -#define TEXT_SERVER_GDNATIVE_H - -#include "modules/gdnative/gdnative.h" - -#include "servers/text_server.h" - -class TextServerGDNative : public TextServer { - GDCLASS(TextServerGDNative, TextServer); - - const godot_text_interface_gdnative *interface = nullptr; - void *data = nullptr; - -protected: - static void _bind_methods(){}; - -public: - virtual bool has_feature(Feature p_feature) override; - virtual String get_name() const override; - - virtual void free(RID p_rid) override; - virtual bool has(RID p_rid) override; - virtual bool load_support_data(const String &p_filename) override; - -#ifdef TOOLS_ENABLED - virtual String get_support_data_filename() override; - virtual String get_support_data_info() override; - virtual bool save_support_data(const String &p_filename) override; -#endif - - virtual bool is_locale_right_to_left(const String &p_locale) override; - - virtual int32_t name_to_tag(const String &p_name) const override; - virtual String tag_to_name(int32_t p_tag) const override; - - /* Font interface */ - virtual RID create_font() override; - - virtual void font_set_data(RID p_font_rid, const PackedByteArray &p_data) override; - virtual void font_set_data_ptr(RID p_font_rid, const uint8_t *p_data_ptr, size_t p_data_size) override; - - virtual void font_set_antialiased(RID p_font_rid, bool p_antialiased) override; - virtual bool font_is_antialiased(RID p_font_rid) const override; - - virtual void font_set_multichannel_signed_distance_field(RID p_font_rid, bool p_msdf) override; - virtual bool font_is_multichannel_signed_distance_field(RID p_font_rid) const override; - - virtual void font_set_msdf_pixel_range(RID p_font_rid, int p_msdf_pixel_range) override; - virtual int font_get_msdf_pixel_range(RID p_font_rid) const override; - - virtual void font_set_msdf_size(RID p_font_rid, int p_msdf_size) override; - virtual int font_get_msdf_size(RID p_font_rid) const override; - - virtual void font_set_fixed_size(RID p_font_rid, int p_fixed_size) override; - virtual int font_get_fixed_size(RID p_font_rid) const override; - - virtual void font_set_force_autohinter(RID p_font_rid, bool p_force_autohinter) override; - virtual bool font_is_force_autohinter(RID p_font_rid) const override; - - virtual void font_set_hinting(RID p_font_rid, TextServer::Hinting p_hinting) override; - virtual TextServer::Hinting font_get_hinting(RID p_font_rid) const override; - - virtual void font_set_variation_coordinates(RID p_font_rid, const Dictionary &p_variation_coordinates) override; - virtual Dictionary font_get_variation_coordinates(RID p_font_rid) const override; - - virtual void font_set_oversampling(RID p_font_rid, real_t p_oversampling) override; - virtual real_t font_get_oversampling(RID p_font_rid) const override; - - virtual Array font_get_size_cache_list(RID p_font_rid) const override; - virtual void font_clear_size_cache(RID p_font_rid) override; - virtual void font_remove_size_cache(RID p_font_rid, const Vector2i &p_size) override; - - virtual void font_set_ascent(RID p_font_rid, int p_size, real_t p_ascent) override; - virtual real_t font_get_ascent(RID p_font_rid, int p_size) const override; - - virtual void font_set_descent(RID p_font_rid, int p_size, real_t p_descent) override; - virtual real_t font_get_descent(RID p_font_rid, int p_size) const override; - - virtual void font_set_underline_position(RID p_font_rid, int p_size, real_t p_underline_position) override; - virtual real_t font_get_underline_position(RID p_font_rid, int p_size) const override; - - virtual void font_set_underline_thickness(RID p_font_rid, int p_size, real_t p_underline_thickness) override; - virtual real_t font_get_underline_thickness(RID p_font_rid, int p_size) const override; - - virtual void font_set_scale(RID p_font_rid, int p_size, real_t p_scale) override; - virtual real_t font_get_scale(RID p_font_rid, int p_size) const override; - - virtual void font_set_spacing(RID p_font_rid, int p_size, SpacingType p_spacing, int p_value) override; - virtual int font_get_spacing(RID p_font_rid, int p_size, SpacingType p_spacing) const override; - - virtual int font_get_texture_count(RID p_font_rid, const Vector2i &p_size) const override; - virtual void font_clear_textures(RID p_font_rid, const Vector2i &p_size) override; - virtual void font_remove_texture(RID p_font_rid, const Vector2i &p_size, int p_texture_index) override; - - virtual void font_set_texture_image(RID p_font_rid, const Vector2i &p_size, int p_texture_index, const Ref<Image> &p_image) override; - virtual Ref<Image> font_get_texture_image(RID p_font_rid, const Vector2i &p_size, int p_texture_index) const override; - - virtual void font_set_texture_offsets(RID p_font_rid, const Vector2i &p_size, int p_texture_index, const PackedInt32Array &p_offset) override; - virtual PackedInt32Array font_get_texture_offsets(RID p_font_rid, const Vector2i &p_size, int p_texture_index) const override; - - virtual Array font_get_glyph_list(RID p_font_rid, const Vector2i &p_size) const override; - virtual void font_clear_glyphs(RID p_font_rid, const Vector2i &p_size) override; - virtual void font_remove_glyph(RID p_font_rid, const Vector2i &p_size, int32_t p_glyph) override; - - virtual Vector2 font_get_glyph_advance(RID p_font_rid, int p_size, int32_t p_glyph) const override; - virtual void font_set_glyph_advance(RID p_font_rid, int p_size, int32_t p_glyph, const Vector2 &p_advance) override; - - virtual Vector2 font_get_glyph_offset(RID p_font_rid, const Vector2i &p_size, int32_t p_glyph) const override; - virtual void font_set_glyph_offset(RID p_font_rid, const Vector2i &p_size, int32_t p_glyph, const Vector2 &p_offset) override; - - virtual Vector2 font_get_glyph_size(RID p_font_rid, const Vector2i &p_size, int32_t p_glyph) const override; - virtual void font_set_glyph_size(RID p_font_rid, const Vector2i &p_size, int32_t p_glyph, const Vector2 &p_gl_size) override; - - virtual Rect2 font_get_glyph_uv_rect(RID p_font_rid, const Vector2i &p_size, int32_t p_glyph) const override; - virtual void font_set_glyph_uv_rect(RID p_font_rid, const Vector2i &p_size, int32_t p_glyph, const Rect2 &p_uv_rect) override; - - virtual int font_get_glyph_texture_idx(RID p_font_rid, const Vector2i &p_size, int32_t p_glyph) const override; - virtual void font_set_glyph_texture_idx(RID p_font_rid, const Vector2i &p_size, int32_t p_glyph, int p_texture_idx) override; - - 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 override; - - virtual Array font_get_kerning_list(RID p_font_rid, int p_size) const override; - virtual void font_clear_kerning_map(RID p_font_rid, int p_size) override; - virtual void font_remove_kerning(RID p_font_rid, int p_size, const Vector2i &p_glyph_pair) override; - - virtual void font_set_kerning(RID p_font_rid, int p_size, const Vector2i &p_glyph_pair, const Vector2 &p_kerning) override; - virtual Vector2 font_get_kerning(RID p_font_rid, int p_size, const Vector2i &p_glyph_pair) const override; - - virtual int32_t font_get_glyph_index(RID p_font_rid, int p_size, char32_t p_char, char32_t p_variation_selector = 0) const override; - - virtual bool font_has_char(RID p_font_rid, char32_t p_char) const override; - virtual String font_get_supported_chars(RID p_font_rid) const override; - - virtual void font_render_range(RID p_font, const Vector2i &p_size, char32_t p_start, char32_t p_end) override; - virtual void font_render_glyph(RID p_font_rid, const Vector2i &p_size, int32_t p_index) override; - - 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 override; - 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 override; - - virtual bool font_is_language_supported(RID p_font_rid, const String &p_language) const override; - virtual void font_set_language_support_override(RID p_font_rid, const String &p_language, bool p_supported) override; - virtual bool font_get_language_support_override(RID p_font_rid, const String &p_language) override; - virtual void font_remove_language_support_override(RID p_font_rid, const String &p_language) override; - virtual Vector<String> font_get_language_support_overrides(RID p_font_rid) override; - - virtual bool font_is_script_supported(RID p_font_rid, const String &p_script) const override; - virtual void font_set_script_support_override(RID p_font_rid, const String &p_script, bool p_supported) override; - virtual bool font_get_script_support_override(RID p_font_rid, const String &p_script) override; - virtual void font_remove_script_support_override(RID p_font_rid, const String &p_script) override; - virtual Vector<String> font_get_script_support_overrides(RID p_font_rid) override; - - virtual Dictionary font_supported_feature_list(RID p_font_rid) const override; - virtual Dictionary font_supported_variation_list(RID p_font_rid) const override; - - virtual real_t font_get_global_oversampling() const override; - virtual void font_set_global_oversampling(real_t p_oversampling) override; - - /* Shaped text buffer interface */ - - virtual RID create_shaped_text(Direction p_direction = DIRECTION_AUTO, Orientation p_orientation = ORIENTATION_HORIZONTAL) override; - - virtual void shaped_text_clear(RID p_shaped) override; - - virtual void shaped_text_set_direction(RID p_shaped, Direction p_direction = DIRECTION_AUTO) override; - virtual Direction shaped_text_get_direction(RID p_shaped) const override; - - virtual void shaped_text_set_bidi_override(RID p_shaped, const Vector<Vector2i> &p_override) override; - - virtual void shaped_text_set_orientation(RID p_shaped, Orientation p_orientation = ORIENTATION_HORIZONTAL) override; - virtual Orientation shaped_text_get_orientation(RID p_shaped) const override; - - virtual void shaped_text_set_preserve_invalid(RID p_shaped, bool p_enabled) override; - virtual bool shaped_text_get_preserve_invalid(RID p_shaped) const override; - - virtual void shaped_text_set_preserve_control(RID p_shaped, bool p_enabled) override; - virtual bool shaped_text_get_preserve_control(RID p_shaped) const override; - - virtual bool shaped_text_add_string(RID p_shaped, const String &p_text, const Vector<RID> &p_fonts, int p_size, const Dictionary &p_opentype_features = Dictionary(), const String &p_language = "") override; - virtual bool shaped_text_add_object(RID p_shaped, Variant p_key, const Size2 &p_size, InlineAlign p_inline_align = INLINE_ALIGN_CENTER, int p_length = 1) override; - virtual bool shaped_text_resize_object(RID p_shaped, Variant p_key, const Size2 &p_size, InlineAlign p_inline_align = INLINE_ALIGN_CENTER) override; - - virtual RID shaped_text_substr(RID p_shaped, int p_start, int p_length) const override; - virtual RID shaped_text_get_parent(RID p_shaped) const override; - - 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) override; - virtual real_t shaped_text_tab_align(RID p_shaped, const Vector<real_t> &p_tab_stops) override; - - virtual bool shaped_text_shape(RID p_shaped) override; - virtual bool shaped_text_update_breaks(RID p_shaped) override; - virtual bool shaped_text_update_justification_ops(RID p_shaped) override; - - virtual void shaped_text_overrun_trim_to_width(RID p_shaped, real_t p_width, uint8_t p_trim_flags) override; - - virtual bool shaped_text_is_ready(RID p_shaped) const override; - - virtual Vector<Glyph> shaped_text_get_glyphs(RID p_shaped) const override; - - virtual Vector2i shaped_text_get_range(RID p_shaped) const override; - - virtual Vector<Glyph> shaped_text_sort_logical(RID p_shaped) override; - 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 override; - virtual Vector<Vector2i> shaped_text_get_line_breaks(RID p_shaped, real_t p_width, int p_start = 0, uint8_t p_break_flags = BREAK_MANDATORY | BREAK_WORD_BOUND) const override; - virtual Vector<Vector2i> shaped_text_get_word_breaks(RID p_shaped, int p_grapheme_flags = GRAPHEME_IS_SPACE | GRAPHEME_IS_PUNCTUATION) const override; - virtual Array shaped_text_get_objects(RID p_shaped) const override; - virtual Rect2 shaped_text_get_object_rect(RID p_shaped, Variant p_key) const override; - - virtual Size2 shaped_text_get_size(RID p_shaped) const override; - virtual real_t shaped_text_get_ascent(RID p_shaped) const override; - virtual real_t shaped_text_get_descent(RID p_shaped) const override; - virtual real_t shaped_text_get_width(RID p_shaped) const override; - virtual real_t shaped_text_get_underline_position(RID p_shaped) const override; - virtual real_t shaped_text_get_underline_thickness(RID p_shaped) const override; - - virtual String format_number(const String &p_string, const String &p_language = "") const override; - virtual String parse_number(const String &p_string, const String &p_language = "") const override; - virtual String percent_sign(const String &p_language = "") const override; - - static TextServer *create_func(Error &r_error, void *p_user_data); - - TextServerGDNative(); - ~TextServerGDNative(); -}; - -#endif // TEXT_SERVER_GDNATIVE_H diff --git a/modules/text_server_adv/config.py b/modules/text_server_adv/config.py index d22f9454ed..8c8df9b05e 100644 --- a/modules/text_server_adv/config.py +++ b/modules/text_server_adv/config.py @@ -4,3 +4,13 @@ def can_build(env, platform): def configure(env): pass + + +def get_doc_classes(): + return [ + "TextServerAdvanced", + ] + + +def get_doc_path(): + return "doc_classes" diff --git a/modules/text_server_adv/doc_classes/TextServerAdvanced.xml b/modules/text_server_adv/doc_classes/TextServerAdvanced.xml new file mode 100644 index 0000000000..eff4aa5fae --- /dev/null +++ b/modules/text_server_adv/doc_classes/TextServerAdvanced.xml @@ -0,0 +1,10 @@ +<?xml version="1.0" encoding="UTF-8" ?> +<class name="TextServerAdvanced" inherits="TextServer" version="4.0"> + <brief_description> + Text Server using HarfBuzz, ICU and SIL Graphite to support BiDi, complex text layouts and contextual OpenType features. + </brief_description> + <description> + </description> + <tutorials> + </tutorials> +</class> diff --git a/modules/text_server_adv/register_types.cpp b/modules/text_server_adv/register_types.cpp index abefa83b9b..b711d1561f 100644 --- a/modules/text_server_adv/register_types.cpp +++ b/modules/text_server_adv/register_types.cpp @@ -33,7 +33,12 @@ #include "text_server_adv.h" void preregister_text_server_adv_types() { - TextServerAdvanced::register_server(); + GDREGISTER_CLASS(TextServerAdvanced); + if (TextServerManager::get_singleton()) { + Ref<TextServerAdvanced> ts; + ts.instantiate(); + TextServerManager::get_singleton()->add_interface(ts); + } } void register_text_server_adv_types() { diff --git a/modules/text_server_adv/text_server_adv.cpp b/modules/text_server_adv/text_server_adv.cpp index b5b7342e87..f5d159040f 100644 --- a/modules/text_server_adv/text_server_adv.cpp +++ b/modules/text_server_adv/text_server_adv.cpp @@ -322,7 +322,7 @@ _FORCE_INLINE_ bool is_underscore(char32_t p_char) { String TextServerAdvanced::interface_name = "ICU / HarfBuzz / Graphite"; uint32_t TextServerAdvanced::interface_features = FEATURE_BIDI_LAYOUT | FEATURE_VERTICAL_LAYOUT | FEATURE_SHAPING | FEATURE_KASHIDA_JUSTIFICATION | FEATURE_BREAK_ITERATORS | FEATURE_USE_SUPPORT_DATA | FEATURE_FONT_VARIABLE; -bool TextServerAdvanced::has_feature(Feature p_feature) { +bool TextServerAdvanced::has_feature(Feature p_feature) const { return (interface_features & p_feature) == p_feature; } @@ -330,6 +330,10 @@ String TextServerAdvanced::get_name() const { return interface_name; } +uint32_t TextServerAdvanced::get_features() const { + return interface_features; +} + void TextServerAdvanced::free(RID p_rid) { _THREAD_SAFE_METHOD_ if (font_owner.owns(p_rid)) { @@ -394,9 +398,23 @@ bool TextServerAdvanced::load_support_data(const String &p_filename) { return true; } -#ifdef TOOLS_ENABLED +String TextServerAdvanced::get_support_data_filename() const { +#ifdef ICU_STATIC_DATA + return _MKSTR(ICU_DATA_NAME); +#else + return String(); +#endif +} + +String TextServerAdvanced::get_support_data_info() const { +#ifdef ICU_STATIC_DATA + return String("ICU break iteration data (") + _MKSTR(ICU_DATA_NAME) + String(")."); +#else + return String(); +#endif +} -bool TextServerAdvanced::save_support_data(const String &p_filename) { +bool TextServerAdvanced::save_support_data(const String &p_filename) const { _THREAD_SAFE_METHOD_ #ifdef ICU_STATIC_DATA @@ -415,9 +433,7 @@ bool TextServerAdvanced::save_support_data(const String &p_filename) { #endif } -#endif - -bool TextServerAdvanced::is_locale_right_to_left(const String &p_locale) { +bool TextServerAdvanced::is_locale_right_to_left(const String &p_locale) const { String l = p_locale.get_slicec('_', 0); if ((l == "ar") || (l == "dv") || (l == "he") || (l == "fa") || (l == "ff") || (l == "ku") || (l == "ur")) { return true; @@ -1142,7 +1158,7 @@ _FORCE_INLINE_ bool TextServerAdvanced::_ensure_glyph(FontDataAdvanced *p_font_d int error = FT_Load_Glyph(fd->face, p_glyph, flags); if (error) { fd->glyph_map[p_glyph] = FontGlyph(); - ERR_FAIL_V_MSG(false, "FreeType: Failed to load glyph."); + return false; } if (!outline) { @@ -1236,7 +1252,7 @@ _FORCE_INLINE_ bool TextServerAdvanced::_ensure_cache_for_size(FontDataAdvanced fd->oversampling = 1.0f; fd->size.x = p_font_data->msdf_source_size; } else if (p_font_data->oversampling <= 0.0f) { - fd->oversampling = TS->font_get_global_oversampling(); + fd->oversampling = font_get_global_oversampling(); } else { fd->oversampling = p_font_data->oversampling; } @@ -1244,13 +1260,13 @@ _FORCE_INLINE_ bool TextServerAdvanced::_ensure_cache_for_size(FontDataAdvanced if (FT_HAS_COLOR(fd->face) && fd->face->num_fixed_sizes > 0) { int best_match = 0; int diff = ABS(fd->size.x - ((int64_t)fd->face->available_sizes[0].width)); - fd->scale = real_t(fd->size.x * fd->oversampling) / fd->face->available_sizes[0].width; + fd->scale = float(fd->size.x * fd->oversampling) / fd->face->available_sizes[0].width; for (int i = 1; i < fd->face->num_fixed_sizes; i++) { int ndiff = ABS(fd->size.x - ((int64_t)fd->face->available_sizes[i].width)); if (ndiff < diff) { best_match = i; diff = ndiff; - fd->scale = real_t(fd->size.x * fd->oversampling) / fd->face->available_sizes[i].width; + fd->scale = float(fd->size.x * fd->oversampling) / fd->face->available_sizes[i].width; } } FT_Select_Size(fd->face, best_match); @@ -1786,7 +1802,7 @@ Dictionary TextServerAdvanced::font_get_variation_coordinates(RID p_font_rid) co return fd->variation_coordinates; } -void TextServerAdvanced::font_set_oversampling(RID p_font_rid, real_t p_oversampling) { +void TextServerAdvanced::font_set_oversampling(RID p_font_rid, float p_oversampling) { FontDataAdvanced *fd = font_owner.get_or_null(p_font_rid); ERR_FAIL_COND(!fd); @@ -1797,7 +1813,7 @@ void TextServerAdvanced::font_set_oversampling(RID p_font_rid, real_t p_oversamp } } -real_t TextServerAdvanced::font_get_oversampling(RID p_font_rid) const { +float TextServerAdvanced::font_get_oversampling(RID p_font_rid) const { FontDataAdvanced *fd = font_owner.get_or_null(p_font_rid); ERR_FAIL_COND_V(!fd, 0.f); @@ -1839,7 +1855,7 @@ void TextServerAdvanced::font_remove_size_cache(RID p_font_rid, const Vector2i & } } -void TextServerAdvanced::font_set_ascent(RID p_font_rid, int p_size, real_t p_ascent) { +void TextServerAdvanced::font_set_ascent(RID p_font_rid, int p_size, float p_ascent) { FontDataAdvanced *fd = font_owner.get_or_null(p_font_rid); ERR_FAIL_COND(!fd); @@ -1850,7 +1866,7 @@ void TextServerAdvanced::font_set_ascent(RID p_font_rid, int p_size, real_t p_as fd->cache[size]->ascent = p_ascent; } -real_t TextServerAdvanced::font_get_ascent(RID p_font_rid, int p_size) const { +float TextServerAdvanced::font_get_ascent(RID p_font_rid, int p_size) const { FontDataAdvanced *fd = font_owner.get_or_null(p_font_rid); ERR_FAIL_COND_V(!fd, 0.f); @@ -1860,13 +1876,13 @@ real_t TextServerAdvanced::font_get_ascent(RID p_font_rid, int p_size) const { ERR_FAIL_COND_V(!_ensure_cache_for_size(fd, size), 0.f); if (fd->msdf) { - return fd->cache[size]->ascent * (real_t)p_size / (real_t)fd->msdf_source_size; + return fd->cache[size]->ascent * (float)p_size / (float)fd->msdf_source_size; } else { return fd->cache[size]->ascent; } } -void TextServerAdvanced::font_set_descent(RID p_font_rid, int p_size, real_t p_descent) { +void TextServerAdvanced::font_set_descent(RID p_font_rid, int p_size, float p_descent) { FontDataAdvanced *fd = font_owner.get_or_null(p_font_rid); ERR_FAIL_COND(!fd); @@ -1876,7 +1892,7 @@ void TextServerAdvanced::font_set_descent(RID p_font_rid, int p_size, real_t p_d fd->cache[size]->descent = p_descent; } -real_t TextServerAdvanced::font_get_descent(RID p_font_rid, int p_size) const { +float TextServerAdvanced::font_get_descent(RID p_font_rid, int p_size) const { FontDataAdvanced *fd = font_owner.get_or_null(p_font_rid); ERR_FAIL_COND_V(!fd, 0.f); @@ -1886,13 +1902,13 @@ real_t TextServerAdvanced::font_get_descent(RID p_font_rid, int p_size) const { ERR_FAIL_COND_V(!_ensure_cache_for_size(fd, size), 0.f); if (fd->msdf) { - return fd->cache[size]->descent * (real_t)p_size / (real_t)fd->msdf_source_size; + return fd->cache[size]->descent * (float)p_size / (float)fd->msdf_source_size; } else { return fd->cache[size]->descent; } } -void TextServerAdvanced::font_set_underline_position(RID p_font_rid, int p_size, real_t p_underline_position) { +void TextServerAdvanced::font_set_underline_position(RID p_font_rid, int p_size, float p_underline_position) { FontDataAdvanced *fd = font_owner.get_or_null(p_font_rid); ERR_FAIL_COND(!fd); @@ -1903,7 +1919,7 @@ void TextServerAdvanced::font_set_underline_position(RID p_font_rid, int p_size, fd->cache[size]->underline_position = p_underline_position; } -real_t TextServerAdvanced::font_get_underline_position(RID p_font_rid, int p_size) const { +float TextServerAdvanced::font_get_underline_position(RID p_font_rid, int p_size) const { FontDataAdvanced *fd = font_owner.get_or_null(p_font_rid); ERR_FAIL_COND_V(!fd, 0.f); @@ -1913,13 +1929,13 @@ real_t TextServerAdvanced::font_get_underline_position(RID p_font_rid, int p_siz ERR_FAIL_COND_V(!_ensure_cache_for_size(fd, size), 0.f); if (fd->msdf) { - return fd->cache[size]->underline_position * (real_t)p_size / (real_t)fd->msdf_source_size; + return fd->cache[size]->underline_position * (float)p_size / (float)fd->msdf_source_size; } else { return fd->cache[size]->underline_position; } } -void TextServerAdvanced::font_set_underline_thickness(RID p_font_rid, int p_size, real_t p_underline_thickness) { +void TextServerAdvanced::font_set_underline_thickness(RID p_font_rid, int p_size, float p_underline_thickness) { FontDataAdvanced *fd = font_owner.get_or_null(p_font_rid); ERR_FAIL_COND(!fd); @@ -1930,7 +1946,7 @@ void TextServerAdvanced::font_set_underline_thickness(RID p_font_rid, int p_size fd->cache[size]->underline_thickness = p_underline_thickness; } -real_t TextServerAdvanced::font_get_underline_thickness(RID p_font_rid, int p_size) const { +float TextServerAdvanced::font_get_underline_thickness(RID p_font_rid, int p_size) const { FontDataAdvanced *fd = font_owner.get_or_null(p_font_rid); ERR_FAIL_COND_V(!fd, 0.f); @@ -1940,13 +1956,13 @@ real_t TextServerAdvanced::font_get_underline_thickness(RID p_font_rid, int p_si ERR_FAIL_COND_V(!_ensure_cache_for_size(fd, size), 0.f); if (fd->msdf) { - return fd->cache[size]->underline_thickness * (real_t)p_size / (real_t)fd->msdf_source_size; + return fd->cache[size]->underline_thickness * (float)p_size / (float)fd->msdf_source_size; } else { return fd->cache[size]->underline_thickness; } } -void TextServerAdvanced::font_set_scale(RID p_font_rid, int p_size, real_t p_scale) { +void TextServerAdvanced::font_set_scale(RID p_font_rid, int p_size, float p_scale) { FontDataAdvanced *fd = font_owner.get_or_null(p_font_rid); ERR_FAIL_COND(!fd); @@ -1957,7 +1973,7 @@ void TextServerAdvanced::font_set_scale(RID p_font_rid, int p_size, real_t p_sca fd->cache[size]->scale = p_scale; } -real_t TextServerAdvanced::font_get_scale(RID p_font_rid, int p_size) const { +float TextServerAdvanced::font_get_scale(RID p_font_rid, int p_size) const { FontDataAdvanced *fd = font_owner.get_or_null(p_font_rid); ERR_FAIL_COND_V(!fd, 0.f); @@ -1967,7 +1983,7 @@ real_t TextServerAdvanced::font_get_scale(RID p_font_rid, int p_size) const { ERR_FAIL_COND_V(!_ensure_cache_for_size(fd, size), 0.f); if (fd->msdf) { - return fd->cache[size]->scale * (real_t)p_size / (real_t)fd->msdf_source_size; + return fd->cache[size]->scale * (float)p_size / (float)fd->msdf_source_size; } else { return fd->cache[size]->scale / fd->cache[size]->oversampling; } @@ -2006,14 +2022,14 @@ int TextServerAdvanced::font_get_spacing(RID p_font_rid, int p_size, TextServer: switch (p_spacing) { case TextServer::SPACING_GLYPH: { if (fd->msdf) { - return fd->cache[size]->spacing_glyph * (real_t)p_size / (real_t)fd->msdf_source_size; + return fd->cache[size]->spacing_glyph * (float)p_size / (float)fd->msdf_source_size; } else { return fd->cache[size]->spacing_glyph; } } break; case TextServer::SPACING_SPACE: { if (fd->msdf) { - return fd->cache[size]->spacing_space * (real_t)p_size / (real_t)fd->msdf_source_size; + return fd->cache[size]->spacing_space * (float)p_size / (float)fd->msdf_source_size; } else { return fd->cache[size]->spacing_space; } @@ -2182,7 +2198,7 @@ Vector2 TextServerAdvanced::font_get_glyph_advance(RID p_font_rid, int p_size, i const HashMap<int32_t, FontGlyph> &gl = fd->cache[size]->glyph_map; if (fd->msdf) { - return gl[p_glyph].advance * (real_t)p_size / (real_t)fd->msdf_source_size; + return gl[p_glyph].advance * (float)p_size / (float)fd->msdf_source_size; } else { return gl[p_glyph].advance; } @@ -2218,7 +2234,7 @@ Vector2 TextServerAdvanced::font_get_glyph_offset(RID p_font_rid, const Vector2i const HashMap<int32_t, FontGlyph> &gl = fd->cache[size]->glyph_map; if (fd->msdf) { - return gl[p_glyph].rect.position * (real_t)p_size.x / (real_t)fd->msdf_source_size; + return gl[p_glyph].rect.position * (float)p_size.x / (float)fd->msdf_source_size; } else { return gl[p_glyph].rect.position; } @@ -2254,7 +2270,7 @@ Vector2 TextServerAdvanced::font_get_glyph_size(RID p_font_rid, const Vector2i & const HashMap<int32_t, FontGlyph> &gl = fd->cache[size]->glyph_map; if (fd->msdf) { - return gl[p_glyph].rect.size * (real_t)p_size.x / (real_t)fd->msdf_source_size; + return gl[p_glyph].rect.size * (float)p_size.x / (float)fd->msdf_source_size; } else { return gl[p_glyph].rect.size; } @@ -2337,38 +2353,46 @@ void TextServerAdvanced::font_set_glyph_texture_idx(RID p_font_rid, const Vector gl[p_glyph].found = true; } -bool TextServerAdvanced::font_get_glyph_contours(RID p_font_rid, int p_size, int32_t p_index, Vector<Vector3> &r_points, Vector<int32_t> &r_contours, bool &r_orientation) const { +Dictionary TextServerAdvanced::font_get_glyph_contours(RID p_font_rid, int p_size, int32_t p_index) const { FontDataAdvanced *fd = font_owner.get_or_null(p_font_rid); - ERR_FAIL_COND_V(!fd, false); + ERR_FAIL_COND_V(!fd, Dictionary()); MutexLock lock(fd->mutex); Vector2i size = _get_size(fd, p_size); - ERR_FAIL_COND_V(!_ensure_cache_for_size(fd, size), false); + ERR_FAIL_COND_V(!_ensure_cache_for_size(fd, size), Dictionary()); + Vector<Vector3> points; + Vector<int32_t> contours; + bool orientation; #ifdef MODULE_FREETYPE_ENABLED int error = FT_Load_Glyph(fd->cache[size]->face, p_index, FT_LOAD_NO_BITMAP | (fd->force_autohinter ? FT_LOAD_FORCE_AUTOHINT : 0)); - ERR_FAIL_COND_V(error, false); + ERR_FAIL_COND_V(error, Dictionary()); - r_points.clear(); - r_contours.clear(); + points.clear(); + contours.clear(); - real_t h = fd->cache[size]->ascent; - real_t scale = (1.0 / 64.0) / fd->cache[size]->oversampling * fd->cache[size]->scale; + float h = fd->cache[size]->ascent; + float scale = (1.0 / 64.0) / fd->cache[size]->oversampling * fd->cache[size]->scale; if (fd->msdf) { - scale = scale * (real_t)p_size / (real_t)fd->msdf_source_size; + scale = scale * (float)p_size / (float)fd->msdf_source_size; } for (short i = 0; i < fd->cache[size]->face->glyph->outline.n_points; i++) { - r_points.push_back(Vector3(fd->cache[size]->face->glyph->outline.points[i].x * scale, h - fd->cache[size]->face->glyph->outline.points[i].y * scale, FT_CURVE_TAG(fd->cache[size]->face->glyph->outline.tags[i]))); + points.push_back(Vector3(fd->cache[size]->face->glyph->outline.points[i].x * scale, h - fd->cache[size]->face->glyph->outline.points[i].y * scale, FT_CURVE_TAG(fd->cache[size]->face->glyph->outline.tags[i]))); } for (short i = 0; i < fd->cache[size]->face->glyph->outline.n_contours; i++) { - r_contours.push_back(fd->cache[size]->face->glyph->outline.contours[i]); + contours.push_back(fd->cache[size]->face->glyph->outline.contours[i]); } - r_orientation = (FT_Outline_Get_Orientation(&fd->cache[size]->face->glyph->outline) == FT_ORIENTATION_FILL_RIGHT); + orientation = (FT_Outline_Get_Orientation(&fd->cache[size]->face->glyph->outline) == FT_ORIENTATION_FILL_RIGHT); #else - return false; + return Dictionary(); #endif - return true; + + Dictionary out; + out["points"] = points; + out["contours"] = contours; + out["orientation"] = orientation; + return out; } Array TextServerAdvanced::font_get_kerning_list(RID p_font_rid, int p_size) const { @@ -2433,7 +2457,7 @@ Vector2 TextServerAdvanced::font_get_kerning(RID p_font_rid, int p_size, const V if (kern.has(p_glyph_pair)) { if (fd->msdf) { - return kern[p_glyph_pair] * (real_t)p_size / (real_t)fd->msdf_source_size; + return kern[p_glyph_pair] * (float)p_size / (float)fd->msdf_source_size; } else { return kern[p_glyph_pair]; } @@ -2443,7 +2467,7 @@ Vector2 TextServerAdvanced::font_get_kerning(RID p_font_rid, int p_size, const V FT_Vector delta; FT_Get_Kerning(fd->cache[size]->face, p_glyph_pair.x, p_glyph_pair.y, FT_KERNING_DEFAULT, &delta); if (fd->msdf) { - return Vector2(delta.x, delta.y) * (real_t)p_size / (real_t)fd->msdf_source_size; + return Vector2(delta.x, delta.y) * (float)p_size / (float)fd->msdf_source_size; } else { return Vector2(delta.x, delta.y); } @@ -2582,8 +2606,8 @@ void TextServerAdvanced::font_draw_glyph(RID p_font_rid, RID p_canvas, int p_siz RID texture = fd->cache[size]->textures[gl.texture_idx].texture->get_rid(); if (fd->msdf) { Point2 cpos = p_pos; - cpos += gl.rect.position * (real_t)p_size / (real_t)fd->msdf_source_size; - Size2 csize = gl.rect.size * (real_t)p_size / (real_t)fd->msdf_source_size; + cpos += gl.rect.position * (float)p_size / (float)fd->msdf_source_size; + Size2 csize = gl.rect.size * (float)p_size / (float)fd->msdf_source_size; RenderingServer::get_singleton()->canvas_item_add_msdf_texture_rect_region(p_canvas, Rect2(cpos, csize), texture, gl.uv_rect, modulate, 0, fd->msdf_range); } else { Point2i cpos = p_pos; @@ -2622,8 +2646,8 @@ void TextServerAdvanced::font_draw_glyph_outline(RID p_font_rid, RID p_canvas, i RID texture = fd->cache[size]->textures[gl.texture_idx].texture->get_rid(); if (fd->msdf) { Point2 cpos = p_pos; - cpos += gl.rect.position * (real_t)p_size / (real_t)fd->msdf_source_size; - Size2 csize = gl.rect.size * (real_t)p_size / (real_t)fd->msdf_source_size; + cpos += gl.rect.position * (float)p_size / (float)fd->msdf_source_size; + Size2 csize = gl.rect.size * (float)p_size / (float)fd->msdf_source_size; RenderingServer::get_singleton()->canvas_item_add_msdf_texture_rect_region(p_canvas, Rect2(cpos, csize), texture, gl.uv_rect, modulate, p_outline_size * 2, fd->msdf_range); } else { Point2i cpos = p_pos; @@ -2694,7 +2718,7 @@ bool TextServerAdvanced::font_is_script_supported(RID p_font_rid, const String & } else { Vector2i size = _get_size(fd, 16); ERR_FAIL_COND_V(!_ensure_cache_for_size(fd, size), false); - return fd->supported_scripts.has(TS->name_to_tag(p_script)); + return fd->supported_scripts.has(hb_tag_from_string(p_script.ascii().get_data(), -1)); } } @@ -2754,11 +2778,11 @@ Dictionary TextServerAdvanced::font_supported_variation_list(RID p_font_rid) con return fd->supported_varaitions; } -real_t TextServerAdvanced::font_get_global_oversampling() const { +float TextServerAdvanced::font_get_global_oversampling() const { return oversampling; } -void TextServerAdvanced::font_set_global_oversampling(real_t p_oversampling) { +void TextServerAdvanced::font_set_global_oversampling(float p_oversampling) { _THREAD_SAFE_METHOD_ if (oversampling != p_oversampling) { oversampling = p_oversampling; @@ -2904,7 +2928,7 @@ TextServer::Direction TextServerAdvanced::shaped_text_get_direction(RID p_shaped return sd->direction; } -void TextServerAdvanced::shaped_text_set_bidi_override(RID p_shaped, const Vector<Vector2i> &p_override) { +void TextServerAdvanced::shaped_text_set_bidi_override(RID p_shaped, const Array &p_override) { ShapedTextDataAdvanced *sd = shaped_owner.get_or_null(p_shaped); ERR_FAIL_COND(!sd); @@ -2912,7 +2936,10 @@ void TextServerAdvanced::shaped_text_set_bidi_override(RID p_shaped, const Vecto if (sd->parent != RID()) { full_copy(sd); } - sd->bidi_override = p_override; + sd->bidi_override.clear(); + for (int i = 0; i < p_override.size(); i++) { + sd->bidi_override.push_back(p_override[i]); + } invalidate(sd); } @@ -3096,8 +3123,7 @@ bool TextServerAdvanced::shaped_text_resize_object(RID p_shaped, Variant p_key, } else if (sd->preserve_invalid || (sd->preserve_control && is_control(gl.index))) { // Glyph not found, replace with hex code box. if (sd->orientation == ORIENTATION_HORIZONTAL) { - sd->ascent = MAX(sd->ascent, Math::round(get_hex_code_box_size(gl.font_size, gl.index).y * 0.75f)); - sd->descent = MAX(sd->descent, Math::round(get_hex_code_box_size(gl.font_size, gl.index).y * 0.25f)); + sd->ascent = MAX(sd->ascent, get_hex_code_box_size(gl.font_size, gl.index).y); } else { sd->ascent = MAX(sd->ascent, Math::round(get_hex_code_box_size(gl.font_size, gl.index).x * 0.5f)); sd->descent = MAX(sd->descent, Math::round(get_hex_code_box_size(gl.font_size, gl.index).x * 0.5f)); @@ -3108,8 +3134,8 @@ bool TextServerAdvanced::shaped_text_resize_object(RID p_shaped, Variant p_key, } // Align embedded objects to baseline. - real_t full_ascent = sd->ascent; - real_t full_descent = sd->descent; + float full_ascent = sd->ascent; + float full_descent = sd->descent; for (KeyValue<Variant, ShapedTextData::EmbeddedObject> &E : sd->objects) { if ((E.value.pos >= sd->start) && (E.value.pos < sd->end)) { if (sd->orientation == ORIENTATION_HORIZONTAL) { @@ -3283,8 +3309,7 @@ RID TextServerAdvanced::shaped_text_substr(RID p_shaped, int p_start, int p_leng } else if (new_sd->preserve_invalid || (new_sd->preserve_control && is_control(gl.index))) { // Glyph not found, replace with hex code box. if (new_sd->orientation == ORIENTATION_HORIZONTAL) { - new_sd->ascent = MAX(new_sd->ascent, Math::round(get_hex_code_box_size(gl.font_size, gl.index).y * 0.75f)); - new_sd->descent = MAX(new_sd->descent, Math::round(get_hex_code_box_size(gl.font_size, gl.index).y * 0.25f)); + new_sd->ascent = MAX(new_sd->ascent, get_hex_code_box_size(gl.font_size, gl.index).y); } else { new_sd->ascent = MAX(new_sd->ascent, Math::round(get_hex_code_box_size(gl.font_size, gl.index).x * 0.5f)); new_sd->descent = MAX(new_sd->descent, Math::round(get_hex_code_box_size(gl.font_size, gl.index).x * 0.5f)); @@ -3299,8 +3324,8 @@ RID TextServerAdvanced::shaped_text_substr(RID p_shaped, int p_start, int p_leng } // Align embedded objects to baseline. - real_t full_ascent = new_sd->ascent; - real_t full_descent = new_sd->descent; + float full_ascent = new_sd->ascent; + float full_descent = new_sd->descent; for (KeyValue<Variant, ShapedTextData::EmbeddedObject> &E : new_sd->objects) { if ((E.value.pos >= new_sd->start) && (E.value.pos < new_sd->end)) { if (sd->orientation == ORIENTATION_HORIZONTAL) { @@ -3378,7 +3403,7 @@ RID TextServerAdvanced::shaped_text_get_parent(RID p_shaped) const { return sd->parent; } -real_t TextServerAdvanced::shaped_text_fit_to_width(RID p_shaped, real_t p_width, uint8_t /*JustificationFlag*/ p_jst_flags) { +float TextServerAdvanced::shaped_text_fit_to_width(RID p_shaped, float p_width, uint16_t /*JustificationFlag*/ p_jst_flags) { ShapedTextDataAdvanced *sd = shaped_owner.get_or_null(p_shaped); ERR_FAIL_COND_V(!sd, 0.f); @@ -3419,7 +3444,7 @@ real_t TextServerAdvanced::shaped_text_fit_to_width(RID p_shaped, real_t p_width } } - real_t justification_width; + float justification_width; if ((p_jst_flags & JUSTIFICATION_CONSTRAIN_ELLIPSIS) == JUSTIFICATION_CONSTRAIN_ELLIPSIS) { if (sd->overrun_trim_data.trim_pos >= 0) { start_pos = sd->overrun_trim_data.trim_pos; @@ -3459,7 +3484,7 @@ real_t TextServerAdvanced::shaped_text_fit_to_width(RID p_shaped, real_t p_width } if ((elongation_count > 0) && ((p_jst_flags & JUSTIFICATION_KASHIDA) == JUSTIFICATION_KASHIDA)) { - real_t delta_width_per_kashida = (p_width - justification_width) / elongation_count; + float delta_width_per_kashida = (p_width - justification_width) / elongation_count; for (int i = start_pos; i <= end_pos; i++) { Glyph &gl = sd->glyphs.write[i]; if (gl.count > 0) { @@ -3474,15 +3499,15 @@ real_t TextServerAdvanced::shaped_text_fit_to_width(RID p_shaped, real_t p_width } } } - real_t adv_remain = 0; + float adv_remain = 0; if ((space_count > 0) && ((p_jst_flags & JUSTIFICATION_WORD_BOUND) == JUSTIFICATION_WORD_BOUND)) { - real_t delta_width_per_space = (p_width - justification_width) / space_count; + float delta_width_per_space = (p_width - justification_width) / space_count; for (int i = start_pos; i <= end_pos; i++) { Glyph &gl = sd->glyphs.write[i]; if (gl.count > 0) { if ((gl.flags & GRAPHEME_IS_SPACE) == GRAPHEME_IS_SPACE) { - real_t old_adv = gl.advance; - real_t new_advance; + float old_adv = gl.advance; + float new_advance; if ((gl.flags & GRAPHEME_IS_VIRTUAL) == GRAPHEME_IS_VIRTUAL) { new_advance = MAX(gl.advance + delta_width_per_space, 0.f); } else { @@ -3514,7 +3539,7 @@ real_t TextServerAdvanced::shaped_text_fit_to_width(RID p_shaped, real_t p_width return sd->width; } -real_t TextServerAdvanced::shaped_text_tab_align(RID p_shaped, const Vector<real_t> &p_tab_stops) { +float TextServerAdvanced::shaped_text_tab_align(RID p_shaped, const PackedFloat32Array &p_tab_stops) { ShapedTextDataAdvanced *sd = shaped_owner.get_or_null(p_shaped); ERR_FAIL_COND_V(!sd, 0.f); @@ -3527,7 +3552,7 @@ real_t TextServerAdvanced::shaped_text_tab_align(RID p_shaped, const Vector<real } int tab_index = 0; - real_t off = 0.f; + float off = 0.f; int start, end, delta; if (sd->para_direction == DIRECTION_LTR) { @@ -3544,7 +3569,7 @@ real_t TextServerAdvanced::shaped_text_tab_align(RID p_shaped, const Vector<real for (int i = start; i != end; i += delta) { if ((gl[i].flags & GRAPHEME_IS_TAB) == GRAPHEME_IS_TAB) { - real_t tab_off = 0.f; + float tab_off = 0.f; while (tab_off <= off) { tab_off += p_tab_stops[tab_index]; tab_index++; @@ -3552,7 +3577,7 @@ real_t TextServerAdvanced::shaped_text_tab_align(RID p_shaped, const Vector<real tab_index = 0; } } - real_t old_adv = gl[i].advance; + float old_adv = gl[i].advance; gl[i].advance = tab_off - off; sd->width += gl[i].advance - old_adv; off = 0; @@ -3564,7 +3589,7 @@ real_t TextServerAdvanced::shaped_text_tab_align(RID p_shaped, const Vector<real return 0.f; } -void TextServerAdvanced::shaped_text_overrun_trim_to_width(RID p_shaped_line, real_t p_width, uint8_t p_trim_flags) { +void TextServerAdvanced::shaped_text_overrun_trim_to_width(RID p_shaped_line, float p_width, uint16_t p_trim_flags) { ShapedTextDataAdvanced *sd = shaped_owner.get_or_null(p_shaped_line); ERR_FAIL_COND_MSG(!sd, "ShapedTextDataAdvanced invalid."); @@ -3607,7 +3632,7 @@ void TextServerAdvanced::shaped_text_overrun_trim_to_width(RID p_shaped_line, re } int ell_min_characters = 6; - real_t width = sd->width; + float width = sd->width; bool is_rtl = sd->direction == DIRECTION_RTL || (sd->direction == DIRECTION_AUTO && sd->para_direction == DIRECTION_RTL); @@ -3663,7 +3688,7 @@ void TextServerAdvanced::shaped_text_overrun_trim_to_width(RID p_shaped_line, re if (add_ellipsis && (ellipsis_pos > 0 || enforce_ellipsis)) { // Insert an additional space when cutting word bound for aesthetics. if (cut_per_word && (ellipsis_pos > 0)) { - TextServer::Glyph gl; + Glyph gl; gl.count = 1; gl.advance = whitespace_adv.x; gl.index = whitespace_gl_idx; @@ -3674,7 +3699,7 @@ void TextServerAdvanced::shaped_text_overrun_trim_to_width(RID p_shaped_line, re sd->overrun_trim_data.ellipsis_glyph_buf.append(gl); } // Add ellipsis dots. - TextServer::Glyph gl; + Glyph gl; gl.count = 1; gl.repeat = 3; gl.advance = dot_adv.x; @@ -3691,12 +3716,36 @@ void TextServerAdvanced::shaped_text_overrun_trim_to_width(RID p_shaped_line, re } } -TextServer::TrimData TextServerAdvanced::shaped_text_get_trim_data(RID p_shaped) const { +int TextServerAdvanced::shaped_text_get_trim_pos(RID p_shaped) const { + ShapedTextDataAdvanced *sd = shaped_owner.get_or_null(p_shaped); + ERR_FAIL_COND_V_MSG(!sd, -1, "ShapedTextDataAdvanced invalid."); + + MutexLock lock(sd->mutex); + return sd->overrun_trim_data.trim_pos; +} + +int TextServerAdvanced::shaped_text_get_ellipsis_pos(RID p_shaped) const { ShapedTextDataAdvanced *sd = shaped_owner.get_or_null(p_shaped); - ERR_FAIL_COND_V_MSG(!sd, TrimData(), "ShapedTextDataAdvanced invalid."); + ERR_FAIL_COND_V_MSG(!sd, -1, "ShapedTextDataAdvanced invalid."); MutexLock lock(sd->mutex); - return sd->overrun_trim_data; + return sd->overrun_trim_data.ellipsis_pos; +} + +const Glyph *TextServerAdvanced::shaped_text_get_ellipsis_glyphs(RID p_shaped) const { + ShapedTextDataAdvanced *sd = shaped_owner.get_or_null(p_shaped); + ERR_FAIL_COND_V_MSG(!sd, nullptr, "ShapedTextDataAdvanced invalid."); + + MutexLock lock(sd->mutex); + return sd->overrun_trim_data.ellipsis_glyph_buf.ptr(); +} + +int TextServerAdvanced::shaped_text_get_ellipsis_glyph_count(RID p_shaped) const { + ShapedTextDataAdvanced *sd = shaped_owner.get_or_null(p_shaped); + ERR_FAIL_COND_V_MSG(!sd, 0, "ShapedTextDataAdvanced invalid."); + + MutexLock lock(sd->mutex); + return sd->overrun_trim_data.ellipsis_glyph_buf.size(); } bool TextServerAdvanced::shaped_text_update_breaks(RID p_shaped) { @@ -3783,7 +3832,7 @@ bool TextServerAdvanced::shaped_text_update_breaks(RID p_shaped) { if (is_whitespace(c)) { sd_glyphs[i].flags |= GRAPHEME_IS_BREAK_SOFT; } else { - TextServer::Glyph gl; + Glyph gl; gl.start = sd_glyphs[i].start; gl.end = sd_glyphs[i].end; gl.count = 1; @@ -3964,7 +4013,7 @@ bool TextServerAdvanced::shaped_text_update_justification_ops(RID p_shaped) { sd->glyphs.write[i].flags |= GRAPHEME_IS_ELONGATION; } else { if (sd->glyphs[i].font_rid != RID()) { - TextServer::Glyph gl = _shape_single_glyph(sd, 0x0640, HB_SCRIPT_ARABIC, HB_DIRECTION_RTL, sd->glyphs[i].font_rid, sd->glyphs[i].font_size); + Glyph gl = _shape_single_glyph(sd, 0x0640, HB_SCRIPT_ARABIC, HB_DIRECTION_RTL, sd->glyphs[i].font_rid, sd->glyphs[i].font_size); if ((gl.flags & GRAPHEME_IS_VALID) == GRAPHEME_IS_VALID) { gl.start = sd->glyphs[i].start; gl.end = sd->glyphs[i].end; @@ -3982,7 +4031,7 @@ bool TextServerAdvanced::shaped_text_update_justification_ops(RID p_shaped) { } } } else if (!is_whitespace(c)) { - TextServer::Glyph gl; + Glyph gl; gl.start = sd->glyphs[i].start; gl.end = sd->glyphs[i].end; gl.count = 1; @@ -4007,9 +4056,9 @@ bool TextServerAdvanced::shaped_text_update_justification_ops(RID p_shaped) { return sd->justification_ops_valid; } -TextServer::Glyph TextServerAdvanced::_shape_single_glyph(ShapedTextDataAdvanced *p_sd, char32_t p_char, hb_script_t p_script, hb_direction_t p_direction, RID p_font, int p_font_size) { +Glyph TextServerAdvanced::_shape_single_glyph(ShapedTextDataAdvanced *p_sd, char32_t p_char, hb_script_t p_script, hb_direction_t p_direction, RID p_font, int p_font_size) { hb_font_t *hb_font = _font_get_hb_handle(p_font, p_font_size); - ERR_FAIL_COND_V(hb_font == nullptr, TextServer::Glyph()); + ERR_FAIL_COND_V(hb_font == nullptr, Glyph()); hb_buffer_clear_contents(p_sd->hb_buffer); hb_buffer_set_direction(p_sd->hb_buffer, p_direction); @@ -4024,7 +4073,7 @@ TextServer::Glyph TextServerAdvanced::_shape_single_glyph(ShapedTextDataAdvanced hb_glyph_position_t *glyph_pos = hb_buffer_get_glyph_positions(p_sd->hb_buffer, &glyph_count); // Process glyphs. - TextServer::Glyph gl; + Glyph gl; if (p_direction == HB_DIRECTION_RTL || p_direction == HB_DIRECTION_BTT) { gl.flags |= TextServer::GRAPHEME_IS_RTL; @@ -4034,7 +4083,7 @@ TextServer::Glyph TextServerAdvanced::_shape_single_glyph(ShapedTextDataAdvanced gl.font_size = p_font_size; if (glyph_count > 0) { - real_t scale = font_get_scale(p_font, p_font_size); + float scale = font_get_scale(p_font, p_font_size); if (p_sd->orientation == ORIENTATION_HORIZONTAL) { gl.advance = Math::round(glyph_pos[0].x_advance / (64.0 / scale)); } else { @@ -4059,7 +4108,7 @@ void TextServerAdvanced::_shape_run(ShapedTextDataAdvanced *p_sd, int32_t p_star // Add fallback glyphs. for (int i = p_start; i < p_end; i++) { if (p_sd->preserve_invalid || (p_sd->preserve_control && is_control(p_sd->text[i]))) { - TextServer::Glyph gl; + Glyph gl; gl.start = i; gl.end = i + 1; gl.count = 1; @@ -4071,8 +4120,7 @@ void TextServerAdvanced::_shape_run(ShapedTextDataAdvanced *p_sd, int32_t p_star } if (p_sd->orientation == ORIENTATION_HORIZONTAL) { gl.advance = get_hex_code_box_size(fs, gl.index).x; - p_sd->ascent = MAX(p_sd->ascent, Math::round(get_hex_code_box_size(fs, gl.index).y * 0.75f)); - p_sd->descent = MAX(p_sd->descent, Math::round(get_hex_code_box_size(fs, gl.index).y * 0.25f)); + p_sd->ascent = MAX(p_sd->ascent, get_hex_code_box_size(fs, gl.index).y); } else { gl.advance = get_hex_code_box_size(fs, gl.index).y; p_sd->ascent = MAX(p_sd->ascent, Math::round(get_hex_code_box_size(fs, gl.index).x * 0.5f)); @@ -4126,7 +4174,7 @@ void TextServerAdvanced::_shape_run(ShapedTextDataAdvanced *p_sd, int32_t p_star // Process glyphs. if (glyph_count > 0) { - TextServer::Glyph *w = (TextServer::Glyph *)memalloc(glyph_count * sizeof(TextServer::Glyph)); + Glyph *w = (Glyph *)memalloc(glyph_count * sizeof(Glyph)); int end = (p_direction == HB_DIRECTION_RTL || p_direction == HB_DIRECTION_BTT) ? p_end : 0; uint32_t last_cluster_id = UINT32_MAX; @@ -4155,8 +4203,8 @@ void TextServerAdvanced::_shape_run(ShapedTextDataAdvanced *p_sd, int32_t p_star last_cluster_id = glyph_info[i].cluster; - TextServer::Glyph &gl = w[i]; - gl = TextServer::Glyph(); + Glyph &gl = w[i]; + gl = Glyph(); gl.start = glyph_info[i].cluster; gl.end = end; @@ -4171,7 +4219,7 @@ void TextServerAdvanced::_shape_run(ShapedTextDataAdvanced *p_sd, int32_t p_star gl.index = glyph_info[i].codepoint; if (gl.index != 0) { - real_t scale = font_get_scale(f, fs); + float scale = font_get_scale(f, fs); if (p_sd->orientation == ORIENTATION_HORIZONTAL) { gl.advance = Math::round(glyph_pos[i].x_advance / (64.0 / scale)); } else { @@ -4411,8 +4459,8 @@ bool TextServerAdvanced::shaped_text_shape(RID p_shaped) { } // Align embedded objects to baseline. - real_t full_ascent = sd->ascent; - real_t full_descent = sd->descent; + float full_ascent = sd->ascent; + float full_descent = sd->descent; for (KeyValue<Variant, ShapedTextData::EmbeddedObject> &E : sd->objects) { if (sd->orientation == ORIENTATION_HORIZONTAL) { switch (E.value.inline_align & INLINE_ALIGN_TEXT_MASK) { @@ -4486,28 +4534,31 @@ bool TextServerAdvanced::shaped_text_is_ready(RID p_shaped) const { return sd->valid; } -Vector<TextServer::Glyph> TextServerAdvanced::shaped_text_get_glyphs(RID p_shaped) const { +const Glyph *TextServerAdvanced::shaped_text_get_glyphs(RID p_shaped) const { const ShapedTextDataAdvanced *sd = shaped_owner.get_or_null(p_shaped); - ERR_FAIL_COND_V(!sd, Vector<TextServer::Glyph>()); + ERR_FAIL_COND_V(!sd, nullptr); MutexLock lock(sd->mutex); if (!sd->valid) { const_cast<TextServerAdvanced *>(this)->shaped_text_shape(p_shaped); } - return sd->glyphs; + return sd->glyphs.ptr(); } -Vector2i TextServerAdvanced::shaped_text_get_range(RID p_shaped) const { +int TextServerAdvanced::shaped_text_get_glyph_count(RID p_shaped) const { const ShapedTextDataAdvanced *sd = shaped_owner.get_or_null(p_shaped); - ERR_FAIL_COND_V(!sd, Vector2i()); + ERR_FAIL_COND_V(!sd, 0); MutexLock lock(sd->mutex); - return Vector2(sd->start, sd->end); + if (!sd->valid) { + const_cast<TextServerAdvanced *>(this)->shaped_text_shape(p_shaped); + } + return sd->glyphs.size(); } -Vector<TextServer::Glyph> TextServerAdvanced::shaped_text_sort_logical(RID p_shaped) { +const Glyph *TextServerAdvanced::shaped_text_sort_logical(RID p_shaped) { ShapedTextDataAdvanced *sd = shaped_owner.get_or_null(p_shaped); - ERR_FAIL_COND_V(!sd, Vector<TextServer::Glyph>()); + ERR_FAIL_COND_V(!sd, nullptr); MutexLock lock(sd->mutex); if (!sd->valid) { @@ -4516,11 +4567,19 @@ Vector<TextServer::Glyph> TextServerAdvanced::shaped_text_sort_logical(RID p_sha if (!sd->sort_valid) { sd->glyphs_logical = sd->glyphs; - sd->glyphs_logical.sort_custom<TextServer::GlyphCompare>(); + sd->glyphs_logical.sort_custom<GlyphCompare>(); sd->sort_valid = true; } - return sd->glyphs_logical; + return sd->glyphs_logical.ptr(); +} + +Vector2i TextServerAdvanced::shaped_text_get_range(RID p_shaped) const { + const ShapedTextDataAdvanced *sd = shaped_owner.get_or_null(p_shaped); + ERR_FAIL_COND_V(!sd, Vector2i()); + + MutexLock lock(sd->mutex); + return Vector2(sd->start, sd->end); } Array TextServerAdvanced::shaped_text_get_objects(RID p_shaped) const { @@ -4563,7 +4622,7 @@ Size2 TextServerAdvanced::shaped_text_get_size(RID p_shaped) const { } } -real_t TextServerAdvanced::shaped_text_get_ascent(RID p_shaped) const { +float TextServerAdvanced::shaped_text_get_ascent(RID p_shaped) const { const ShapedTextDataAdvanced *sd = shaped_owner.get_or_null(p_shaped); ERR_FAIL_COND_V(!sd, 0.f); @@ -4574,7 +4633,7 @@ real_t TextServerAdvanced::shaped_text_get_ascent(RID p_shaped) const { return sd->ascent; } -real_t TextServerAdvanced::shaped_text_get_descent(RID p_shaped) const { +float TextServerAdvanced::shaped_text_get_descent(RID p_shaped) const { const ShapedTextDataAdvanced *sd = shaped_owner.get_or_null(p_shaped); ERR_FAIL_COND_V(!sd, 0.f); @@ -4585,7 +4644,7 @@ real_t TextServerAdvanced::shaped_text_get_descent(RID p_shaped) const { return sd->descent; } -real_t TextServerAdvanced::shaped_text_get_width(RID p_shaped) const { +float TextServerAdvanced::shaped_text_get_width(RID p_shaped) const { const ShapedTextDataAdvanced *sd = shaped_owner.get_or_null(p_shaped); ERR_FAIL_COND_V(!sd, 0.f); @@ -4596,7 +4655,7 @@ real_t TextServerAdvanced::shaped_text_get_width(RID p_shaped) const { return (sd->text_trimmed ? sd->width_trimmed : sd->width); } -real_t TextServerAdvanced::shaped_text_get_underline_position(RID p_shaped) const { +float TextServerAdvanced::shaped_text_get_underline_position(RID p_shaped) const { const ShapedTextDataAdvanced *sd = shaped_owner.get_or_null(p_shaped); ERR_FAIL_COND_V(!sd, 0.f); @@ -4608,7 +4667,7 @@ real_t TextServerAdvanced::shaped_text_get_underline_position(RID p_shaped) cons return sd->upos; } -real_t TextServerAdvanced::shaped_text_get_underline_thickness(RID p_shaped) const { +float TextServerAdvanced::shaped_text_get_underline_thickness(RID p_shaped) const { const ShapedTextDataAdvanced *sd = shaped_owner.get_or_null(p_shaped); ERR_FAIL_COND_V(!sd, 0.f); @@ -4752,15 +4811,6 @@ String TextServerAdvanced::percent_sign(const String &p_language) const { return "%"; } -TextServer *TextServerAdvanced::create_func(Error &r_error, void *p_user_data) { - r_error = OK; - return memnew(TextServerAdvanced()); -} - -void TextServerAdvanced::register_server() { - TextServerManager::register_create_function(interface_name, interface_features, create_func, nullptr); -} - TextServerAdvanced::TextServerAdvanced() { _insert_num_systems_lang(); _insert_feature_sets(); diff --git a/modules/text_server_adv/text_server_adv.h b/modules/text_server_adv/text_server_adv.h index fc0e7a09a7..1feeada76d 100644 --- a/modules/text_server_adv/text_server_adv.h +++ b/modules/text_server_adv/text_server_adv.h @@ -115,12 +115,12 @@ class TextServerAdvanced : public TextServer { }; struct FontDataForSizeAdvanced { - real_t ascent = 0.f; - real_t descent = 0.f; - real_t underline_position = 0.f; - real_t underline_thickness = 0.f; - real_t scale = 1.f; - real_t oversampling = 1.f; + float ascent = 0.f; + float descent = 0.f; + float underline_position = 0.f; + float underline_thickness = 0.f; + float scale = 1.f; + float oversampling = 1.f; int spacing_glyph = 0; int spacing_space = 0; @@ -161,7 +161,7 @@ class TextServerAdvanced : public TextServer { bool force_autohinter = false; TextServer::Hinting hinting = TextServer::HINTING_LIGHT; Dictionary variation_coordinates; - real_t oversampling = 0.f; + float oversampling = 0.f; Map<Vector2i, FontDataForSizeAdvanced *> cache; @@ -245,14 +245,14 @@ class TextServerAdvanced : public TextServer { // Common data. - real_t oversampling = 1.f; + float oversampling = 1.f; mutable RID_PtrOwner<FontDataAdvanced> font_owner; mutable RID_PtrOwner<ShapedTextDataAdvanced> shaped_owner; int _convert_pos(const ShapedTextDataAdvanced *p_sd, int p_pos) const; int _convert_pos_inv(const ShapedTextDataAdvanced *p_sd, int p_pos) const; void _shape_run(ShapedTextDataAdvanced *p_sd, int32_t p_start, int32_t p_end, hb_script_t p_script, hb_direction_t p_direction, Vector<RID> p_fonts, int p_span, int p_fb_index); - TextServer::Glyph _shape_single_glyph(ShapedTextDataAdvanced *p_sd, char32_t p_char, hb_script_t p_script, hb_direction_t p_direction, RID p_font, int p_font_size); + Glyph _shape_single_glyph(ShapedTextDataAdvanced *p_sd, char32_t p_char, hb_script_t p_script, hb_direction_t p_direction, RID p_font, int p_font_size); // HarfBuzz bitmap font interface. @@ -284,20 +284,19 @@ protected: void invalidate(ShapedTextDataAdvanced *p_shaped); public: - virtual bool has_feature(Feature p_feature) override; + virtual bool has_feature(Feature p_feature) const override; virtual String get_name() const override; + virtual uint32_t get_features() const override; virtual void free(RID p_rid) override; virtual bool has(RID p_rid) override; virtual bool load_support_data(const String &p_filename) override; -#ifdef TOOLS_ENABLED - virtual String get_support_data_filename() override { return _MKSTR(ICU_DATA_NAME); }; - virtual String get_support_data_info() override { return String("ICU break iteration data (") + _MKSTR(ICU_DATA_NAME) + String(")."); }; - virtual bool save_support_data(const String &p_filename) override; -#endif + virtual String get_support_data_filename() const override; + virtual String get_support_data_info() const override; + virtual bool save_support_data(const String &p_filename) const override; - virtual bool is_locale_right_to_left(const String &p_locale) override; + virtual bool is_locale_right_to_left(const String &p_locale) const override; virtual int32_t name_to_tag(const String &p_name) const override; virtual String tag_to_name(int32_t p_tag) const override; @@ -332,8 +331,8 @@ public: virtual void font_set_variation_coordinates(RID p_font_rid, const Dictionary &p_variation_coordinates) override; virtual Dictionary font_get_variation_coordinates(RID p_font_rid) const override; - virtual void font_set_oversampling(RID p_font_rid, real_t p_oversampling) override; - virtual real_t font_get_oversampling(RID p_font_rid) const override; + virtual void font_set_oversampling(RID p_font_rid, float p_oversampling) override; + virtual float font_get_oversampling(RID p_font_rid) const override; virtual Array font_get_size_cache_list(RID p_font_rid) const override; virtual void font_clear_size_cache(RID p_font_rid) override; @@ -341,20 +340,20 @@ public: hb_font_t *_font_get_hb_handle(RID p_font, int p_font_size) const; - virtual void font_set_ascent(RID p_font_rid, int p_size, real_t p_ascent) override; - virtual real_t font_get_ascent(RID p_font_rid, int p_size) const override; + virtual void font_set_ascent(RID p_font_rid, int p_size, float p_ascent) override; + virtual float font_get_ascent(RID p_font_rid, int p_size) const override; - virtual void font_set_descent(RID p_font_rid, int p_size, real_t p_descent) override; - virtual real_t font_get_descent(RID p_font_rid, int p_size) const override; + virtual void font_set_descent(RID p_font_rid, int p_size, float p_descent) override; + virtual float font_get_descent(RID p_font_rid, int p_size) const override; - virtual void font_set_underline_position(RID p_font_rid, int p_size, real_t p_underline_position) override; - virtual real_t font_get_underline_position(RID p_font_rid, int p_size) const override; + virtual void font_set_underline_position(RID p_font_rid, int p_size, float p_underline_position) override; + virtual float font_get_underline_position(RID p_font_rid, int p_size) const override; - virtual void font_set_underline_thickness(RID p_font_rid, int p_size, real_t p_underline_thickness) override; - virtual real_t font_get_underline_thickness(RID p_font_rid, int p_size) const override; + virtual void font_set_underline_thickness(RID p_font_rid, int p_size, float p_underline_thickness) override; + virtual float font_get_underline_thickness(RID p_font_rid, int p_size) const override; - virtual void font_set_scale(RID p_font_rid, int p_size, real_t p_scale) override; - virtual real_t font_get_scale(RID p_font_rid, int p_size) const override; + virtual void font_set_scale(RID p_font_rid, int p_size, float p_scale) override; + virtual float font_get_scale(RID p_font_rid, int p_size) const override; virtual void font_set_spacing(RID p_font_rid, int p_size, SpacingType p_spacing, int p_value) override; virtual int font_get_spacing(RID p_font_rid, int p_size, SpacingType p_spacing) const override; @@ -388,7 +387,7 @@ public: virtual int font_get_glyph_texture_idx(RID p_font_rid, const Vector2i &p_size, int32_t p_glyph) const override; virtual void font_set_glyph_texture_idx(RID p_font_rid, const Vector2i &p_size, int32_t p_glyph, int p_texture_idx) override; - 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 override; + virtual Dictionary font_get_glyph_contours(RID p_font, int p_size, int32_t p_index) const override; virtual Array font_get_kerning_list(RID p_font_rid, int p_size) const override; virtual void font_clear_kerning_map(RID p_font_rid, int p_size) override; @@ -423,8 +422,8 @@ public: virtual Dictionary font_supported_feature_list(RID p_font_rid) const override; virtual Dictionary font_supported_variation_list(RID p_font_rid) const override; - virtual real_t font_get_global_oversampling() const override; - virtual void font_set_global_oversampling(real_t p_oversampling) override; + virtual float font_get_global_oversampling() const override; + virtual void font_set_global_oversampling(float p_oversampling) override; /* Shaped text buffer interface */ @@ -435,7 +434,7 @@ public: virtual void shaped_text_set_direction(RID p_shaped, Direction p_direction = DIRECTION_AUTO) override; virtual Direction shaped_text_get_direction(RID p_shaped) const override; - virtual void shaped_text_set_bidi_override(RID p_shaped, const Vector<Vector2i> &p_override) override; + virtual void shaped_text_set_bidi_override(RID p_shaped, const Array &p_override) override; virtual void shaped_text_set_orientation(RID p_shaped, Orientation p_orientation = ORIENTATION_HORIZONTAL) override; virtual Orientation shaped_text_get_orientation(RID p_shaped) const override; @@ -453,41 +452,42 @@ public: virtual RID shaped_text_substr(RID p_shaped, int p_start, int p_length) const override; virtual RID shaped_text_get_parent(RID p_shaped) const override; - 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) override; - virtual real_t shaped_text_tab_align(RID p_shaped, const Vector<real_t> &p_tab_stops) override; + virtual float shaped_text_fit_to_width(RID p_shaped, float p_width, uint16_t /*JustificationFlag*/ p_jst_flags = JUSTIFICATION_WORD_BOUND | JUSTIFICATION_KASHIDA) override; + virtual float shaped_text_tab_align(RID p_shaped, const PackedFloat32Array &p_tab_stops) override; virtual bool shaped_text_shape(RID p_shaped) override; virtual bool shaped_text_update_breaks(RID p_shaped) override; virtual bool shaped_text_update_justification_ops(RID p_shaped) override; - virtual void shaped_text_overrun_trim_to_width(RID p_shaped, real_t p_width, uint8_t p_trim_flags) override; - virtual TrimData shaped_text_get_trim_data(RID p_shaped) const override; + virtual int shaped_text_get_trim_pos(RID p_shaped) const override; + virtual int shaped_text_get_ellipsis_pos(RID p_shaped) const override; + virtual const Glyph *shaped_text_get_ellipsis_glyphs(RID p_shaped) const override; + virtual int shaped_text_get_ellipsis_glyph_count(RID p_shaped) const override; + + virtual void shaped_text_overrun_trim_to_width(RID p_shaped, float p_width, uint16_t p_trim_flags) override; virtual bool shaped_text_is_ready(RID p_shaped) const override; - virtual Vector<Glyph> shaped_text_get_glyphs(RID p_shaped) const override; + virtual const Glyph *shaped_text_get_glyphs(RID p_shaped) const override; + virtual const Glyph *shaped_text_sort_logical(RID p_shaped) override; + virtual int shaped_text_get_glyph_count(RID p_shaped) const override; virtual Vector2i shaped_text_get_range(RID p_shaped) const override; - virtual Vector<Glyph> shaped_text_sort_logical(RID p_shaped) override; - virtual Array shaped_text_get_objects(RID p_shaped) const override; virtual Rect2 shaped_text_get_object_rect(RID p_shaped, Variant p_key) const override; virtual Size2 shaped_text_get_size(RID p_shaped) const override; - virtual real_t shaped_text_get_ascent(RID p_shaped) const override; - virtual real_t shaped_text_get_descent(RID p_shaped) const override; - virtual real_t shaped_text_get_width(RID p_shaped) const override; - virtual real_t shaped_text_get_underline_position(RID p_shaped) const override; - virtual real_t shaped_text_get_underline_thickness(RID p_shaped) const override; + virtual float shaped_text_get_ascent(RID p_shaped) const override; + virtual float shaped_text_get_descent(RID p_shaped) const override; + virtual float shaped_text_get_width(RID p_shaped) const override; + virtual float shaped_text_get_underline_position(RID p_shaped) const override; + virtual float shaped_text_get_underline_thickness(RID p_shaped) const override; virtual String format_number(const String &p_string, const String &p_language = "") const override; virtual String parse_number(const String &p_string, const String &p_language = "") const override; virtual String percent_sign(const String &p_language = "") const override; - static TextServer *create_func(Error &r_error, void *p_user_data); - static void register_server(); - TextServerAdvanced(); ~TextServerAdvanced(); }; diff --git a/modules/text_server_fb/config.py b/modules/text_server_fb/config.py index 7a73080ae9..275c2b4d53 100644 --- a/modules/text_server_fb/config.py +++ b/modules/text_server_fb/config.py @@ -9,3 +9,13 @@ def configure(env): def is_enabled(): # The module is disabled by default. Use module_text_server_fb_enabled=yes to enable it. return False + + +def get_doc_classes(): + return [ + "TextServerFallback", + ] + + +def get_doc_path(): + return "doc_classes" diff --git a/modules/text_server_fb/doc_classes/TextServerFallback.xml b/modules/text_server_fb/doc_classes/TextServerFallback.xml new file mode 100644 index 0000000000..8aadf2b882 --- /dev/null +++ b/modules/text_server_fb/doc_classes/TextServerFallback.xml @@ -0,0 +1,10 @@ +<?xml version="1.0" encoding="UTF-8" ?> +<class name="TextServerFallback" inherits="TextServer" version="4.0"> + <brief_description> + Fallback implementation of the Text Server, without BiDi and complex text layout support. + </brief_description> + <description> + </description> + <tutorials> + </tutorials> +</class> diff --git a/modules/text_server_fb/register_types.cpp b/modules/text_server_fb/register_types.cpp index 87cbd2ac2c..0b59040ce8 100644 --- a/modules/text_server_fb/register_types.cpp +++ b/modules/text_server_fb/register_types.cpp @@ -33,7 +33,12 @@ #include "text_server_fb.h" void preregister_text_server_fb_types() { - TextServerFallback::register_server(); + GDREGISTER_CLASS(TextServerFallback); + if (TextServerManager::get_singleton()) { + Ref<TextServerFallback> ts; + ts.instantiate(); + TextServerManager::get_singleton()->add_interface(ts); + } } void register_text_server_fb_types() { diff --git a/modules/text_server_fb/text_server_fb.cpp b/modules/text_server_fb/text_server_fb.cpp index 62adf458aa..3d868d7be3 100644 --- a/modules/text_server_fb/text_server_fb.cpp +++ b/modules/text_server_fb/text_server_fb.cpp @@ -69,7 +69,7 @@ _FORCE_INLINE_ bool is_underscore(char32_t p_char) { String TextServerFallback::interface_name = "Fallback"; uint32_t TextServerFallback::interface_features = 0; // Nothing is supported. -bool TextServerFallback::has_feature(Feature p_feature) { +bool TextServerFallback::has_feature(Feature p_feature) const { return (interface_features & p_feature) == p_feature; } @@ -77,6 +77,10 @@ String TextServerFallback::get_name() const { return interface_name; } +uint32_t TextServerFallback::get_features() const { + return interface_features; +} + void TextServerFallback::free(RID p_rid) { _THREAD_SAFE_METHOD_ if (font_owner.owns(p_rid)) { @@ -99,15 +103,11 @@ bool TextServerFallback::load_support_data(const String &p_filename) { return false; // No extra data used. } -#ifdef TOOLS_ENABLED - -bool TextServerFallback::save_support_data(const String &p_filename) { +bool TextServerFallback::save_support_data(const String &p_filename) const { return false; // No extra data used. } -#endif - -bool TextServerFallback::is_locale_right_to_left(const String &p_locale) { +bool TextServerFallback::is_locale_right_to_left(const String &p_locale) const { return false; // No RTL support. } @@ -420,7 +420,7 @@ _FORCE_INLINE_ TextServerFallback::FontGlyph TextServerFallback::rasterize_msdf( FontTexture &tex = p_data->textures.write[tex_pos.index]; edgeColoringSimple(shape, 3.0); // Max. angle. - msdfgen::Bitmap<real_t, 4> image(w, h); // Texture size. + msdfgen::Bitmap<float, 4> image(w, h); // Texture size. //msdfgen::generateMTSDF(image, shape, p_pixel_range, 1.0, msdfgen::Vector2(-bounds.l, -bounds.b)); // Range, scale, translation. DistancePixelConversion distancePixelConversion(p_pixel_range); @@ -620,7 +620,7 @@ _FORCE_INLINE_ bool TextServerFallback::_ensure_glyph(FontDataFallback *p_font_d int error = FT_Load_Glyph(fd->face, glyph_index, flags); if (error) { fd->glyph_map[p_glyph] = FontGlyph(); - ERR_FAIL_V_MSG(false, "FreeType: Failed to load glyph."); + return false; } if (!outline) { @@ -714,7 +714,7 @@ _FORCE_INLINE_ bool TextServerFallback::_ensure_cache_for_size(FontDataFallback fd->oversampling = 1.0f; fd->size.x = p_font_data->msdf_source_size; } else if (p_font_data->oversampling <= 0.0f) { - fd->oversampling = TS->font_get_global_oversampling(); + fd->oversampling = font_get_global_oversampling(); } else { fd->oversampling = p_font_data->oversampling; } @@ -722,13 +722,13 @@ _FORCE_INLINE_ bool TextServerFallback::_ensure_cache_for_size(FontDataFallback if (FT_HAS_COLOR(fd->face) && fd->face->num_fixed_sizes > 0) { int best_match = 0; int diff = ABS(fd->size.x - ((int64_t)fd->face->available_sizes[0].width)); - fd->scale = real_t(fd->size.x * fd->oversampling) / fd->face->available_sizes[0].width; + fd->scale = float(fd->size.x * fd->oversampling) / fd->face->available_sizes[0].width; for (int i = 1; i < fd->face->num_fixed_sizes; i++) { int ndiff = ABS(fd->size.x - ((int64_t)fd->face->available_sizes[i].width)); if (ndiff < diff) { best_match = i; diff = ndiff; - fd->scale = real_t(fd->size.x * fd->oversampling) / fd->face->available_sizes[i].width; + fd->scale = float(fd->size.x * fd->oversampling) / fd->face->available_sizes[i].width; } } FT_Select_Size(fd->face, best_match); @@ -769,7 +769,7 @@ _FORCE_INLINE_ bool TextServerFallback::_ensure_cache_for_size(FontDataFallback for (FT_UInt i = 0; i < amaster->num_axis; i++) { // Reset to default. int32_t var_tag = amaster->axis[i].tag; - real_t var_value = (double)amaster->axis[i].def / 65536.f; + float var_value = (double)amaster->axis[i].def / 65536.f; coords.write[i] = amaster->axis[i].def; if (p_font_data->variation_coordinates.has(var_tag)) { @@ -983,7 +983,7 @@ Dictionary TextServerFallback::font_get_variation_coordinates(RID p_font_rid) co return fd->variation_coordinates; } -void TextServerFallback::font_set_oversampling(RID p_font_rid, real_t p_oversampling) { +void TextServerFallback::font_set_oversampling(RID p_font_rid, float p_oversampling) { FontDataFallback *fd = font_owner.get_or_null(p_font_rid); ERR_FAIL_COND(!fd); @@ -994,7 +994,7 @@ void TextServerFallback::font_set_oversampling(RID p_font_rid, real_t p_oversamp } } -real_t TextServerFallback::font_get_oversampling(RID p_font_rid) const { +float TextServerFallback::font_get_oversampling(RID p_font_rid) const { FontDataFallback *fd = font_owner.get_or_null(p_font_rid); ERR_FAIL_COND_V(!fd, 0.f); @@ -1036,7 +1036,7 @@ void TextServerFallback::font_remove_size_cache(RID p_font_rid, const Vector2i & } } -void TextServerFallback::font_set_ascent(RID p_font_rid, int p_size, real_t p_ascent) { +void TextServerFallback::font_set_ascent(RID p_font_rid, int p_size, float p_ascent) { FontDataFallback *fd = font_owner.get_or_null(p_font_rid); ERR_FAIL_COND(!fd); @@ -1047,7 +1047,7 @@ void TextServerFallback::font_set_ascent(RID p_font_rid, int p_size, real_t p_as fd->cache[size]->ascent = p_ascent; } -real_t TextServerFallback::font_get_ascent(RID p_font_rid, int p_size) const { +float TextServerFallback::font_get_ascent(RID p_font_rid, int p_size) const { FontDataFallback *fd = font_owner.get_or_null(p_font_rid); ERR_FAIL_COND_V(!fd, 0.f); @@ -1057,13 +1057,13 @@ real_t TextServerFallback::font_get_ascent(RID p_font_rid, int p_size) const { ERR_FAIL_COND_V(!_ensure_cache_for_size(fd, size), 0.f); if (fd->msdf) { - return fd->cache[size]->ascent * (real_t)p_size / (real_t)fd->msdf_source_size; + return fd->cache[size]->ascent * (float)p_size / (float)fd->msdf_source_size; } else { return fd->cache[size]->ascent; } } -void TextServerFallback::font_set_descent(RID p_font_rid, int p_size, real_t p_descent) { +void TextServerFallback::font_set_descent(RID p_font_rid, int p_size, float p_descent) { FontDataFallback *fd = font_owner.get_or_null(p_font_rid); ERR_FAIL_COND(!fd); @@ -1073,7 +1073,7 @@ void TextServerFallback::font_set_descent(RID p_font_rid, int p_size, real_t p_d fd->cache[size]->descent = p_descent; } -real_t TextServerFallback::font_get_descent(RID p_font_rid, int p_size) const { +float TextServerFallback::font_get_descent(RID p_font_rid, int p_size) const { FontDataFallback *fd = font_owner.get_or_null(p_font_rid); ERR_FAIL_COND_V(!fd, 0.f); @@ -1083,13 +1083,13 @@ real_t TextServerFallback::font_get_descent(RID p_font_rid, int p_size) const { ERR_FAIL_COND_V(!_ensure_cache_for_size(fd, size), 0.f); if (fd->msdf) { - return fd->cache[size]->descent * (real_t)p_size / (real_t)fd->msdf_source_size; + return fd->cache[size]->descent * (float)p_size / (float)fd->msdf_source_size; } else { return fd->cache[size]->descent; } } -void TextServerFallback::font_set_underline_position(RID p_font_rid, int p_size, real_t p_underline_position) { +void TextServerFallback::font_set_underline_position(RID p_font_rid, int p_size, float p_underline_position) { FontDataFallback *fd = font_owner.get_or_null(p_font_rid); ERR_FAIL_COND(!fd); @@ -1100,7 +1100,7 @@ void TextServerFallback::font_set_underline_position(RID p_font_rid, int p_size, fd->cache[size]->underline_position = p_underline_position; } -real_t TextServerFallback::font_get_underline_position(RID p_font_rid, int p_size) const { +float TextServerFallback::font_get_underline_position(RID p_font_rid, int p_size) const { FontDataFallback *fd = font_owner.get_or_null(p_font_rid); ERR_FAIL_COND_V(!fd, 0.f); @@ -1110,13 +1110,13 @@ real_t TextServerFallback::font_get_underline_position(RID p_font_rid, int p_siz ERR_FAIL_COND_V(!_ensure_cache_for_size(fd, size), 0.f); if (fd->msdf) { - return fd->cache[size]->underline_position * (real_t)p_size / (real_t)fd->msdf_source_size; + return fd->cache[size]->underline_position * (float)p_size / (float)fd->msdf_source_size; } else { return fd->cache[size]->underline_position; } } -void TextServerFallback::font_set_underline_thickness(RID p_font_rid, int p_size, real_t p_underline_thickness) { +void TextServerFallback::font_set_underline_thickness(RID p_font_rid, int p_size, float p_underline_thickness) { FontDataFallback *fd = font_owner.get_or_null(p_font_rid); ERR_FAIL_COND(!fd); @@ -1127,7 +1127,7 @@ void TextServerFallback::font_set_underline_thickness(RID p_font_rid, int p_size fd->cache[size]->underline_thickness = p_underline_thickness; } -real_t TextServerFallback::font_get_underline_thickness(RID p_font_rid, int p_size) const { +float TextServerFallback::font_get_underline_thickness(RID p_font_rid, int p_size) const { FontDataFallback *fd = font_owner.get_or_null(p_font_rid); ERR_FAIL_COND_V(!fd, 0.f); @@ -1137,13 +1137,13 @@ real_t TextServerFallback::font_get_underline_thickness(RID p_font_rid, int p_si ERR_FAIL_COND_V(!_ensure_cache_for_size(fd, size), 0.f); if (fd->msdf) { - return fd->cache[size]->underline_thickness * (real_t)p_size / (real_t)fd->msdf_source_size; + return fd->cache[size]->underline_thickness * (float)p_size / (float)fd->msdf_source_size; } else { return fd->cache[size]->underline_thickness; } } -void TextServerFallback::font_set_scale(RID p_font_rid, int p_size, real_t p_scale) { +void TextServerFallback::font_set_scale(RID p_font_rid, int p_size, float p_scale) { FontDataFallback *fd = font_owner.get_or_null(p_font_rid); ERR_FAIL_COND(!fd); @@ -1154,7 +1154,7 @@ void TextServerFallback::font_set_scale(RID p_font_rid, int p_size, real_t p_sca fd->cache[size]->scale = p_scale; } -real_t TextServerFallback::font_get_scale(RID p_font_rid, int p_size) const { +float TextServerFallback::font_get_scale(RID p_font_rid, int p_size) const { FontDataFallback *fd = font_owner.get_or_null(p_font_rid); ERR_FAIL_COND_V(!fd, 0.f); @@ -1164,7 +1164,7 @@ real_t TextServerFallback::font_get_scale(RID p_font_rid, int p_size) const { ERR_FAIL_COND_V(!_ensure_cache_for_size(fd, size), 0.f); if (fd->msdf) { - return fd->cache[size]->scale * (real_t)p_size / (real_t)fd->msdf_source_size; + return fd->cache[size]->scale * (float)p_size / (float)fd->msdf_source_size; } else { return fd->cache[size]->scale / fd->cache[size]->oversampling; } @@ -1203,14 +1203,14 @@ int TextServerFallback::font_get_spacing(RID p_font_rid, int p_size, TextServer: switch (p_spacing) { case TextServer::SPACING_GLYPH: { if (fd->msdf) { - return fd->cache[size]->spacing_glyph * (real_t)p_size / (real_t)fd->msdf_source_size; + return fd->cache[size]->spacing_glyph * (float)p_size / (float)fd->msdf_source_size; } else { return fd->cache[size]->spacing_glyph; } } break; case TextServer::SPACING_SPACE: { if (fd->msdf) { - return fd->cache[size]->spacing_space * (real_t)p_size / (real_t)fd->msdf_source_size; + return fd->cache[size]->spacing_space * (float)p_size / (float)fd->msdf_source_size; } else { return fd->cache[size]->spacing_space; } @@ -1379,7 +1379,7 @@ Vector2 TextServerFallback::font_get_glyph_advance(RID p_font_rid, int p_size, i const HashMap<int32_t, FontGlyph> &gl = fd->cache[size]->glyph_map; if (fd->msdf) { - return gl[p_glyph].advance * (real_t)p_size / (real_t)fd->msdf_source_size; + return gl[p_glyph].advance * (float)p_size / (float)fd->msdf_source_size; } else { return gl[p_glyph].advance; } @@ -1415,7 +1415,7 @@ Vector2 TextServerFallback::font_get_glyph_offset(RID p_font_rid, const Vector2i const HashMap<int32_t, FontGlyph> &gl = fd->cache[size]->glyph_map; if (fd->msdf) { - return gl[p_glyph].rect.position * (real_t)p_size.x / (real_t)fd->msdf_source_size; + return gl[p_glyph].rect.position * (float)p_size.x / (float)fd->msdf_source_size; } else { return gl[p_glyph].rect.position; } @@ -1451,7 +1451,7 @@ Vector2 TextServerFallback::font_get_glyph_size(RID p_font_rid, const Vector2i & const HashMap<int32_t, FontGlyph> &gl = fd->cache[size]->glyph_map; if (fd->msdf) { - return gl[p_glyph].rect.size * (real_t)p_size.x / (real_t)fd->msdf_source_size; + return gl[p_glyph].rect.size * (float)p_size.x / (float)fd->msdf_source_size; } else { return gl[p_glyph].rect.size; } @@ -1534,38 +1534,46 @@ void TextServerFallback::font_set_glyph_texture_idx(RID p_font_rid, const Vector gl[p_glyph].found = true; } -bool TextServerFallback::font_get_glyph_contours(RID p_font_rid, int p_size, int32_t p_index, Vector<Vector3> &r_points, Vector<int32_t> &r_contours, bool &r_orientation) const { +Dictionary TextServerFallback::font_get_glyph_contours(RID p_font_rid, int p_size, int32_t p_index) const { FontDataFallback *fd = font_owner.get_or_null(p_font_rid); - ERR_FAIL_COND_V(!fd, false); + ERR_FAIL_COND_V(!fd, Dictionary()); MutexLock lock(fd->mutex); Vector2i size = _get_size(fd, p_size); - ERR_FAIL_COND_V(!_ensure_cache_for_size(fd, size), false); + ERR_FAIL_COND_V(!_ensure_cache_for_size(fd, size), Dictionary()); + Vector<Vector3> points; + Vector<int32_t> contours; + bool orientation; #ifdef MODULE_FREETYPE_ENABLED int error = FT_Load_Glyph(fd->cache[size]->face, FT_Get_Char_Index(fd->cache[size]->face, p_index), FT_LOAD_NO_BITMAP | (fd->force_autohinter ? FT_LOAD_FORCE_AUTOHINT : 0)); - ERR_FAIL_COND_V(error, false); + ERR_FAIL_COND_V(error, Dictionary()); - r_points.clear(); - r_contours.clear(); + points.clear(); + contours.clear(); - real_t h = fd->cache[size]->ascent; - real_t scale = (1.0 / 64.0) / fd->cache[size]->oversampling * fd->cache[size]->scale; + float h = fd->cache[size]->ascent; + float scale = (1.0 / 64.0) / fd->cache[size]->oversampling * fd->cache[size]->scale; if (fd->msdf) { - scale = scale * (real_t)p_size / (real_t)fd->msdf_source_size; + scale = scale * (float)p_size / (float)fd->msdf_source_size; } for (short i = 0; i < fd->cache[size]->face->glyph->outline.n_points; i++) { - r_points.push_back(Vector3(fd->cache[size]->face->glyph->outline.points[i].x * scale, h - fd->cache[size]->face->glyph->outline.points[i].y * scale, FT_CURVE_TAG(fd->cache[size]->face->glyph->outline.tags[i]))); + points.push_back(Vector3(fd->cache[size]->face->glyph->outline.points[i].x * scale, h - fd->cache[size]->face->glyph->outline.points[i].y * scale, FT_CURVE_TAG(fd->cache[size]->face->glyph->outline.tags[i]))); } for (short i = 0; i < fd->cache[size]->face->glyph->outline.n_contours; i++) { - r_contours.push_back(fd->cache[size]->face->glyph->outline.contours[i]); + contours.push_back(fd->cache[size]->face->glyph->outline.contours[i]); } - r_orientation = (FT_Outline_Get_Orientation(&fd->cache[size]->face->glyph->outline) == FT_ORIENTATION_FILL_RIGHT); + orientation = (FT_Outline_Get_Orientation(&fd->cache[size]->face->glyph->outline) == FT_ORIENTATION_FILL_RIGHT); #else - return false; + return Dictionary(); #endif - return true; + + Dictionary out; + out["points"] = points; + out["contours"] = contours; + out["orientation"] = orientation; + return out; } Array TextServerFallback::font_get_kerning_list(RID p_font_rid, int p_size) const { @@ -1630,7 +1638,7 @@ Vector2 TextServerFallback::font_get_kerning(RID p_font_rid, int p_size, const V if (kern.has(p_glyph_pair)) { if (fd->msdf) { - return kern[p_glyph_pair] * (real_t)p_size / (real_t)fd->msdf_source_size; + return kern[p_glyph_pair] * (float)p_size / (float)fd->msdf_source_size; } else { return kern[p_glyph_pair]; } @@ -1642,7 +1650,7 @@ Vector2 TextServerFallback::font_get_kerning(RID p_font_rid, int p_size, const V int32_t glyph_b = FT_Get_Char_Index(fd->cache[size]->face, p_glyph_pair.y); FT_Get_Kerning(fd->cache[size]->face, glyph_a, glyph_b, FT_KERNING_DEFAULT, &delta); if (fd->msdf) { - return Vector2(delta.x, delta.y) * (real_t)p_size / (real_t)fd->msdf_source_size; + return Vector2(delta.x, delta.y) * (float)p_size / (float)fd->msdf_source_size; } else { return Vector2(delta.x, delta.y); } @@ -1756,8 +1764,8 @@ void TextServerFallback::font_draw_glyph(RID p_font_rid, RID p_canvas, int p_siz RID texture = fd->cache[size]->textures[gl.texture_idx].texture->get_rid(); if (fd->msdf) { Point2 cpos = p_pos; - cpos += gl.rect.position * (real_t)p_size / (real_t)fd->msdf_source_size; - Size2 csize = gl.rect.size * (real_t)p_size / (real_t)fd->msdf_source_size; + cpos += gl.rect.position * (float)p_size / (float)fd->msdf_source_size; + Size2 csize = gl.rect.size * (float)p_size / (float)fd->msdf_source_size; RenderingServer::get_singleton()->canvas_item_add_msdf_texture_rect_region(p_canvas, Rect2(cpos, csize), texture, gl.uv_rect, modulate, 0, fd->msdf_range); } else { Point2i cpos = p_pos; @@ -1796,8 +1804,8 @@ void TextServerFallback::font_draw_glyph_outline(RID p_font_rid, RID p_canvas, i RID texture = fd->cache[size]->textures[gl.texture_idx].texture->get_rid(); if (fd->msdf) { Point2 cpos = p_pos; - cpos += gl.rect.position * (real_t)p_size / (real_t)fd->msdf_source_size; - Size2 csize = gl.rect.size * (real_t)p_size / (real_t)fd->msdf_source_size; + cpos += gl.rect.position * (float)p_size / (float)fd->msdf_source_size; + Size2 csize = gl.rect.size * (float)p_size / (float)fd->msdf_source_size; RenderingServer::get_singleton()->canvas_item_add_msdf_texture_rect_region(p_canvas, Rect2(cpos, csize), texture, gl.uv_rect, modulate, p_outline_size * 2, fd->msdf_range); } else { Point2i cpos = p_pos; @@ -1922,11 +1930,11 @@ Dictionary TextServerFallback::font_supported_variation_list(RID p_font_rid) con return fd->supported_varaitions; } -real_t TextServerFallback::font_get_global_oversampling() const { +float TextServerFallback::font_get_global_oversampling() const { return oversampling; } -void TextServerFallback::font_set_global_oversampling(real_t p_oversampling) { +void TextServerFallback::font_set_global_oversampling(float p_oversampling) { _THREAD_SAFE_METHOD_ if (oversampling != p_oversampling) { oversampling = p_oversampling; @@ -2037,7 +2045,7 @@ void TextServerFallback::shaped_text_set_orientation(RID p_shaped, TextServer::O } } -void TextServerFallback::shaped_text_set_bidi_override(RID p_shaped, const Vector<Vector2i> &p_override) { +void TextServerFallback::shaped_text_set_bidi_override(RID p_shaped, const Array &p_override) { // No BiDi support, ignore. } @@ -2223,8 +2231,7 @@ bool TextServerFallback::shaped_text_resize_object(RID p_shaped, Variant p_key, } else if (sd->preserve_invalid || (sd->preserve_control && is_control(gl.index))) { // Glyph not found, replace with hex code box. if (sd->orientation == ORIENTATION_HORIZONTAL) { - sd->ascent = MAX(sd->ascent, Math::round(get_hex_code_box_size(gl.font_size, gl.index).y * 0.75f)); - sd->descent = MAX(sd->descent, Math::round(get_hex_code_box_size(gl.font_size, gl.index).y * 0.25f)); + sd->ascent = MAX(sd->ascent, get_hex_code_box_size(gl.font_size, gl.index).y); } else { sd->ascent = MAX(sd->ascent, Math::round(get_hex_code_box_size(gl.font_size, gl.index).x * 0.5f)); sd->descent = MAX(sd->descent, Math::round(get_hex_code_box_size(gl.font_size, gl.index).x * 0.5f)); @@ -2235,8 +2242,8 @@ bool TextServerFallback::shaped_text_resize_object(RID p_shaped, Variant p_key, } // Align embedded objects to baseline. - real_t full_ascent = sd->ascent; - real_t full_descent = sd->descent; + float full_ascent = sd->ascent; + float full_descent = sd->descent; for (KeyValue<Variant, ShapedTextData::EmbeddedObject> &E : sd->objects) { if ((E.value.pos >= sd->start) && (E.value.pos < sd->end)) { if (sd->orientation == ORIENTATION_HORIZONTAL) { @@ -2373,8 +2380,7 @@ RID TextServerFallback::shaped_text_substr(RID p_shaped, int p_start, int p_leng } else if (new_sd->preserve_invalid || (new_sd->preserve_control && is_control(gl.index))) { // Glyph not found, replace with hex code box. if (new_sd->orientation == ORIENTATION_HORIZONTAL) { - new_sd->ascent = MAX(new_sd->ascent, Math::round(get_hex_code_box_size(gl.font_size, gl.index).y * 0.75f)); - new_sd->descent = MAX(new_sd->descent, Math::round(get_hex_code_box_size(gl.font_size, gl.index).y * 0.25f)); + new_sd->ascent = MAX(new_sd->ascent, get_hex_code_box_size(gl.font_size, gl.index).y); } else { new_sd->ascent = MAX(new_sd->ascent, Math::round(get_hex_code_box_size(gl.font_size, gl.index).x * 0.5f)); new_sd->descent = MAX(new_sd->descent, Math::round(get_hex_code_box_size(gl.font_size, gl.index).x * 0.5f)); @@ -2387,8 +2393,8 @@ RID TextServerFallback::shaped_text_substr(RID p_shaped, int p_start, int p_leng } // Align embedded objects to baseline. - real_t full_ascent = new_sd->ascent; - real_t full_descent = new_sd->descent; + float full_ascent = new_sd->ascent; + float full_descent = new_sd->descent; for (KeyValue<Variant, ShapedTextData::EmbeddedObject> &E : new_sd->objects) { if ((E.value.pos >= new_sd->start) && (E.value.pos < new_sd->end)) { if (sd->orientation == ORIENTATION_HORIZONTAL) { @@ -2466,7 +2472,7 @@ RID TextServerFallback::shaped_text_get_parent(RID p_shaped) const { return sd->parent; } -real_t TextServerFallback::shaped_text_fit_to_width(RID p_shaped, real_t p_width, uint8_t /*JustificationFlag*/ p_jst_flags) { +float TextServerFallback::shaped_text_fit_to_width(RID p_shaped, float p_width, uint16_t /*JustificationFlag*/ p_jst_flags) { ShapedTextData *sd = shaped_owner.get_or_null(p_shaped); ERR_FAIL_COND_V(!sd, 0.f); @@ -2530,12 +2536,12 @@ real_t TextServerFallback::shaped_text_fit_to_width(RID p_shaped, real_t p_width } if ((space_count > 0) && ((p_jst_flags & JUSTIFICATION_WORD_BOUND) == JUSTIFICATION_WORD_BOUND)) { - real_t delta_width_per_space = (p_width - sd->width) / space_count; + float delta_width_per_space = (p_width - sd->width) / space_count; for (int i = start_pos; i <= end_pos; i++) { Glyph &gl = sd->glyphs.write[i]; if (gl.count > 0) { if ((gl.flags & GRAPHEME_IS_SPACE) == GRAPHEME_IS_SPACE) { - real_t old_adv = gl.advance; + float old_adv = gl.advance; gl.advance = MAX(gl.advance + delta_width_per_space, Math::round(0.1 * gl.font_size)); sd->width += (gl.advance - old_adv); } @@ -2546,7 +2552,7 @@ real_t TextServerFallback::shaped_text_fit_to_width(RID p_shaped, real_t p_width return sd->width; } -real_t TextServerFallback::shaped_text_tab_align(RID p_shaped, const Vector<real_t> &p_tab_stops) { +float TextServerFallback::shaped_text_tab_align(RID p_shaped, const PackedFloat32Array &p_tab_stops) { ShapedTextData *sd = shaped_owner.get_or_null(p_shaped); ERR_FAIL_COND_V(!sd, 0.f); @@ -2559,7 +2565,7 @@ real_t TextServerFallback::shaped_text_tab_align(RID p_shaped, const Vector<real } int tab_index = 0; - real_t off = 0.f; + float off = 0.f; int start, end, delta; if (sd->para_direction == DIRECTION_LTR) { @@ -2576,7 +2582,7 @@ real_t TextServerFallback::shaped_text_tab_align(RID p_shaped, const Vector<real for (int i = start; i != end; i += delta) { if ((gl[i].flags & GRAPHEME_IS_TAB) == GRAPHEME_IS_TAB) { - real_t tab_off = 0.f; + float tab_off = 0.f; while (tab_off <= off) { tab_off += p_tab_stops[tab_index]; tab_index++; @@ -2584,7 +2590,7 @@ real_t TextServerFallback::shaped_text_tab_align(RID p_shaped, const Vector<real tab_index = 0; } } - real_t old_adv = gl[i].advance; + float old_adv = gl[i].advance; gl[i].advance = tab_off - off; sd->width += gl[i].advance - old_adv; off = 0; @@ -2653,7 +2659,7 @@ bool TextServerFallback::shaped_text_update_justification_ops(RID p_shaped) { return true; } -void TextServerFallback::shaped_text_overrun_trim_to_width(RID p_shaped_line, real_t p_width, uint8_t p_trim_flags) { +void TextServerFallback::shaped_text_overrun_trim_to_width(RID p_shaped_line, float p_width, uint16_t p_trim_flags) { ShapedTextData *sd = shaped_owner.get_or_null(p_shaped_line); ERR_FAIL_COND_MSG(!sd, "ShapedTextDataFallback invalid."); @@ -2696,7 +2702,7 @@ void TextServerFallback::shaped_text_overrun_trim_to_width(RID p_shaped_line, re } int ell_min_characters = 6; - real_t width = sd->width; + float width = sd->width; int trim_pos = 0; int ellipsis_pos = (enforce_ellipsis) ? 0 : -1; @@ -2742,7 +2748,7 @@ void TextServerFallback::shaped_text_overrun_trim_to_width(RID p_shaped_line, re if (add_ellipsis && (ellipsis_pos > 0 || enforce_ellipsis)) { // Insert an additional space when cutting word bound for aesthetics. if (cut_per_word && (ellipsis_pos > 0)) { - TextServer::Glyph gl; + Glyph gl; gl.count = 1; gl.advance = whitespace_adv.x; gl.index = whitespace_gl_idx; @@ -2753,7 +2759,7 @@ void TextServerFallback::shaped_text_overrun_trim_to_width(RID p_shaped_line, re sd->overrun_trim_data.ellipsis_glyph_buf.append(gl); } // Add ellipsis dots. - TextServer::Glyph gl; + Glyph gl; gl.count = 1; gl.repeat = 3; gl.advance = dot_adv.x; @@ -2770,12 +2776,36 @@ void TextServerFallback::shaped_text_overrun_trim_to_width(RID p_shaped_line, re } } -TextServer::TrimData TextServerFallback::shaped_text_get_trim_data(RID p_shaped) const { +int TextServerFallback::shaped_text_get_trim_pos(RID p_shaped) const { + ShapedTextData *sd = shaped_owner.get_or_null(p_shaped); + ERR_FAIL_COND_V_MSG(!sd, -1, "ShapedTextData invalid."); + + MutexLock lock(sd->mutex); + return sd->overrun_trim_data.trim_pos; +} + +int TextServerFallback::shaped_text_get_ellipsis_pos(RID p_shaped) const { + ShapedTextData *sd = shaped_owner.get_or_null(p_shaped); + ERR_FAIL_COND_V_MSG(!sd, -1, "ShapedTextData invalid."); + + MutexLock lock(sd->mutex); + return sd->overrun_trim_data.ellipsis_pos; +} + +const Glyph *TextServerFallback::shaped_text_get_ellipsis_glyphs(RID p_shaped) const { + ShapedTextData *sd = shaped_owner.get_or_null(p_shaped); + ERR_FAIL_COND_V_MSG(!sd, nullptr, "ShapedTextData invalid."); + + MutexLock lock(sd->mutex); + return sd->overrun_trim_data.ellipsis_glyph_buf.ptr(); +} + +int TextServerFallback::shaped_text_get_ellipsis_glyph_count(RID p_shaped) const { ShapedTextData *sd = shaped_owner.get_or_null(p_shaped); - ERR_FAIL_COND_V_MSG(!sd, TrimData(), "ShapedTextDataFallback invalid."); + ERR_FAIL_COND_V_MSG(!sd, 0, "ShapedTextData invalid."); MutexLock lock(sd->mutex); - return sd->overrun_trim_data; + return sd->overrun_trim_data.ellipsis_glyph_buf.size(); } bool TextServerFallback::shaped_text_shape(RID p_shaped) { @@ -2890,8 +2920,7 @@ bool TextServerFallback::shaped_text_shape(RID p_shaped) { // Glyph not found, replace with hex code box. if (sd->orientation == ORIENTATION_HORIZONTAL) { gl.advance = get_hex_code_box_size(gl.font_size, gl.index).x; - sd->ascent = MAX(sd->ascent, Math::round(get_hex_code_box_size(gl.font_size, gl.index).y * 0.75f)); - sd->descent = MAX(sd->descent, Math::round(get_hex_code_box_size(gl.font_size, gl.index).y * 0.25f)); + sd->ascent = MAX(sd->ascent, get_hex_code_box_size(gl.font_size, gl.index).y); } else { gl.advance = get_hex_code_box_size(gl.font_size, gl.index).y; sd->ascent = MAX(sd->ascent, Math::round(get_hex_code_box_size(gl.font_size, gl.index).x * 0.5f)); @@ -2905,8 +2934,8 @@ bool TextServerFallback::shaped_text_shape(RID p_shaped) { } // Align embedded objects to baseline. - real_t full_ascent = sd->ascent; - real_t full_descent = sd->descent; + float full_ascent = sd->ascent; + float full_descent = sd->descent; for (KeyValue<Variant, ShapedTextData::EmbeddedObject> &E : sd->objects) { if (sd->orientation == ORIENTATION_HORIZONTAL) { switch (E.value.inline_align & INLINE_ALIGN_TEXT_MASK) { @@ -2980,35 +3009,46 @@ bool TextServerFallback::shaped_text_is_ready(RID p_shaped) const { return sd->valid; } -Vector<TextServer::Glyph> TextServerFallback::shaped_text_get_glyphs(RID p_shaped) const { +const Glyph *TextServerFallback::shaped_text_get_glyphs(RID p_shaped) const { const ShapedTextData *sd = shaped_owner.get_or_null(p_shaped); - ERR_FAIL_COND_V(!sd, Vector<TextServer::Glyph>()); + ERR_FAIL_COND_V(!sd, nullptr); MutexLock lock(sd->mutex); if (!sd->valid) { const_cast<TextServerFallback *>(this)->shaped_text_shape(p_shaped); } - return sd->glyphs; + return sd->glyphs.ptr(); } -Vector2i TextServerFallback::shaped_text_get_range(RID p_shaped) const { +int TextServerFallback::shaped_text_get_glyph_count(RID p_shaped) const { const ShapedTextData *sd = shaped_owner.get_or_null(p_shaped); - ERR_FAIL_COND_V(!sd, Vector2i()); + ERR_FAIL_COND_V(!sd, 0); MutexLock lock(sd->mutex); - return Vector2(sd->start, sd->end); + if (!sd->valid) { + const_cast<TextServerFallback *>(this)->shaped_text_shape(p_shaped); + } + return sd->glyphs.size(); } -Vector<TextServer::Glyph> TextServerFallback::shaped_text_sort_logical(RID p_shaped) { +const Glyph *TextServerFallback::shaped_text_sort_logical(RID p_shaped) { const ShapedTextData *sd = shaped_owner.get_or_null(p_shaped); - ERR_FAIL_COND_V(!sd, Vector<TextServer::Glyph>()); + ERR_FAIL_COND_V(!sd, nullptr); MutexLock lock(sd->mutex); if (!sd->valid) { const_cast<TextServerFallback *>(this)->shaped_text_shape(p_shaped); } - return sd->glyphs; // Already in the logical order, return as is. + return sd->glyphs.ptr(); // Already in the logical order, return as is. +} + +Vector2i TextServerFallback::shaped_text_get_range(RID p_shaped) const { + const ShapedTextData *sd = shaped_owner.get_or_null(p_shaped); + ERR_FAIL_COND_V(!sd, Vector2i()); + + MutexLock lock(sd->mutex); + return Vector2(sd->start, sd->end); } Array TextServerFallback::shaped_text_get_objects(RID p_shaped) const { @@ -3051,7 +3091,7 @@ Size2 TextServerFallback::shaped_text_get_size(RID p_shaped) const { } } -real_t TextServerFallback::shaped_text_get_ascent(RID p_shaped) const { +float TextServerFallback::shaped_text_get_ascent(RID p_shaped) const { const ShapedTextData *sd = shaped_owner.get_or_null(p_shaped); ERR_FAIL_COND_V(!sd, 0.f); @@ -3062,7 +3102,7 @@ real_t TextServerFallback::shaped_text_get_ascent(RID p_shaped) const { return sd->ascent; } -real_t TextServerFallback::shaped_text_get_descent(RID p_shaped) const { +float TextServerFallback::shaped_text_get_descent(RID p_shaped) const { const ShapedTextData *sd = shaped_owner.get_or_null(p_shaped); ERR_FAIL_COND_V(!sd, 0.f); @@ -3073,7 +3113,7 @@ real_t TextServerFallback::shaped_text_get_descent(RID p_shaped) const { return sd->descent; } -real_t TextServerFallback::shaped_text_get_width(RID p_shaped) const { +float TextServerFallback::shaped_text_get_width(RID p_shaped) const { const ShapedTextData *sd = shaped_owner.get_or_null(p_shaped); ERR_FAIL_COND_V(!sd, 0.f); @@ -3084,7 +3124,7 @@ real_t TextServerFallback::shaped_text_get_width(RID p_shaped) const { return sd->width; } -real_t TextServerFallback::shaped_text_get_underline_position(RID p_shaped) const { +float TextServerFallback::shaped_text_get_underline_position(RID p_shaped) const { const ShapedTextData *sd = shaped_owner.get_or_null(p_shaped); ERR_FAIL_COND_V(!sd, 0.f); @@ -3096,7 +3136,7 @@ real_t TextServerFallback::shaped_text_get_underline_position(RID p_shaped) cons return sd->upos; } -real_t TextServerFallback::shaped_text_get_underline_thickness(RID p_shaped) const { +float TextServerFallback::shaped_text_get_underline_thickness(RID p_shaped) const { const ShapedTextData *sd = shaped_owner.get_or_null(p_shaped); ERR_FAIL_COND_V(!sd, 0.f); @@ -3108,15 +3148,6 @@ real_t TextServerFallback::shaped_text_get_underline_thickness(RID p_shaped) con return sd->uthk; } -TextServer *TextServerFallback::create_func(Error &r_error, void *p_user_data) { - r_error = OK; - return memnew(TextServerFallback()); -} - -void TextServerFallback::register_server() { - TextServerManager::register_create_function(interface_name, interface_features, create_func, nullptr); -} - TextServerFallback::TextServerFallback(){}; TextServerFallback::~TextServerFallback() { diff --git a/modules/text_server_fb/text_server_fb.h b/modules/text_server_fb/text_server_fb.h index fde75e7135..992ce5018f 100644 --- a/modules/text_server_fb/text_server_fb.h +++ b/modules/text_server_fb/text_server_fb.h @@ -93,12 +93,12 @@ class TextServerFallback : public TextServer { }; struct FontDataForSizeFallback { - real_t ascent = 0.f; - real_t descent = 0.f; - real_t underline_position = 0.f; - real_t underline_thickness = 0.f; - real_t scale = 1.f; - real_t oversampling = 1.f; + float ascent = 0.f; + float descent = 0.f; + float underline_position = 0.f; + float underline_thickness = 0.f; + float scale = 1.f; + float oversampling = 1.f; int spacing_glyph = 0; int spacing_space = 0; @@ -134,7 +134,7 @@ class TextServerFallback : public TextServer { bool force_autohinter = false; TextServer::Hinting hinting = TextServer::HINTING_LIGHT; Dictionary variation_coordinates; - real_t oversampling = 0.f; + float oversampling = 0.f; Map<Vector2i, FontDataForSizeFallback *> cache; @@ -194,7 +194,7 @@ class TextServerFallback : public TextServer { // Common data. - real_t oversampling = 1.f; + float oversampling = 1.f; mutable RID_PtrOwner<FontDataFallback> font_owner; mutable RID_PtrOwner<ShapedTextData> shaped_owner; @@ -205,20 +205,19 @@ protected: void invalidate(ShapedTextData *p_shaped); public: - virtual bool has_feature(Feature p_feature) override; + virtual bool has_feature(Feature p_feature) const override; virtual String get_name() const override; + virtual uint32_t get_features() const override; virtual void free(RID p_rid) override; virtual bool has(RID p_rid) override; virtual bool load_support_data(const String &p_filename) override; -#ifdef TOOLS_ENABLED - virtual String get_support_data_filename() override { return ""; }; - virtual String get_support_data_info() override { return "Not supported"; }; - virtual bool save_support_data(const String &p_filename) override; -#endif + virtual String get_support_data_filename() const override { return ""; }; + virtual String get_support_data_info() const override { return "Not supported"; }; + virtual bool save_support_data(const String &p_filename) const override; - virtual bool is_locale_right_to_left(const String &p_locale) override; + virtual bool is_locale_right_to_left(const String &p_locale) const override; virtual int32_t name_to_tag(const String &p_name) const override; virtual String tag_to_name(int32_t p_tag) const override; @@ -253,27 +252,27 @@ public: virtual void font_set_variation_coordinates(RID p_font_rid, const Dictionary &p_variation_coordinates) override; virtual Dictionary font_get_variation_coordinates(RID p_font_rid) const override; - virtual void font_set_oversampling(RID p_font_rid, real_t p_oversampling) override; - virtual real_t font_get_oversampling(RID p_font_rid) const override; + virtual void font_set_oversampling(RID p_font_rid, float p_oversampling) override; + virtual float font_get_oversampling(RID p_font_rid) const override; virtual Array font_get_size_cache_list(RID p_font_rid) const override; virtual void font_clear_size_cache(RID p_font_rid) override; virtual void font_remove_size_cache(RID p_font_rid, const Vector2i &p_size) override; - virtual void font_set_ascent(RID p_font_rid, int p_size, real_t p_ascent) override; - virtual real_t font_get_ascent(RID p_font_rid, int p_size) const override; + virtual void font_set_ascent(RID p_font_rid, int p_size, float p_ascent) override; + virtual float font_get_ascent(RID p_font_rid, int p_size) const override; - virtual void font_set_descent(RID p_font_rid, int p_size, real_t p_descent) override; - virtual real_t font_get_descent(RID p_font_rid, int p_size) const override; + virtual void font_set_descent(RID p_font_rid, int p_size, float p_descent) override; + virtual float font_get_descent(RID p_font_rid, int p_size) const override; - virtual void font_set_underline_position(RID p_font_rid, int p_size, real_t p_underline_position) override; - virtual real_t font_get_underline_position(RID p_font_rid, int p_size) const override; + virtual void font_set_underline_position(RID p_font_rid, int p_size, float p_underline_position) override; + virtual float font_get_underline_position(RID p_font_rid, int p_size) const override; - virtual void font_set_underline_thickness(RID p_font_rid, int p_size, real_t p_underline_thickness) override; - virtual real_t font_get_underline_thickness(RID p_font_rid, int p_size) const override; + virtual void font_set_underline_thickness(RID p_font_rid, int p_size, float p_underline_thickness) override; + virtual float font_get_underline_thickness(RID p_font_rid, int p_size) const override; - virtual void font_set_scale(RID p_font_rid, int p_size, real_t p_scale) override; - virtual real_t font_get_scale(RID p_font_rid, int p_size) const override; + virtual void font_set_scale(RID p_font_rid, int p_size, float p_scale) override; + virtual float font_get_scale(RID p_font_rid, int p_size) const override; virtual void font_set_spacing(RID p_font_rid, int p_size, SpacingType p_spacing, int p_value) override; virtual int font_get_spacing(RID p_font_rid, int p_size, SpacingType p_spacing) const override; @@ -307,7 +306,7 @@ public: virtual int font_get_glyph_texture_idx(RID p_font_rid, const Vector2i &p_size, int32_t p_glyph) const override; virtual void font_set_glyph_texture_idx(RID p_font_rid, const Vector2i &p_size, int32_t p_glyph, int p_texture_idx) override; - 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 override; + virtual Dictionary font_get_glyph_contours(RID p_font, int p_size, int32_t p_index) const override; virtual Array font_get_kerning_list(RID p_font_rid, int p_size) const override; virtual void font_clear_kerning_map(RID p_font_rid, int p_size) override; @@ -342,8 +341,8 @@ public: virtual Dictionary font_supported_feature_list(RID p_font_rid) const override; virtual Dictionary font_supported_variation_list(RID p_font_rid) const override; - virtual real_t font_get_global_oversampling() const override; - virtual void font_set_global_oversampling(real_t p_oversampling) override; + virtual float font_get_global_oversampling() const override; + virtual void font_set_global_oversampling(float p_oversampling) override; /* Shaped text buffer interface */ @@ -354,7 +353,7 @@ public: virtual void shaped_text_set_direction(RID p_shaped, Direction p_direction = DIRECTION_AUTO) override; virtual Direction shaped_text_get_direction(RID p_shaped) const override; - virtual void shaped_text_set_bidi_override(RID p_shaped, const Vector<Vector2i> &p_override) override; + virtual void shaped_text_set_bidi_override(RID p_shaped, const Array &p_override) override; virtual void shaped_text_set_orientation(RID p_shaped, Orientation p_orientation = ORIENTATION_HORIZONTAL) override; virtual Orientation shaped_text_get_orientation(RID p_shaped) const override; @@ -372,36 +371,37 @@ public: virtual RID shaped_text_substr(RID p_shaped, int p_start, int p_length) const override; virtual RID shaped_text_get_parent(RID p_shaped) const override; - 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) override; - virtual real_t shaped_text_tab_align(RID p_shaped, const Vector<real_t> &p_tab_stops) override; + virtual float shaped_text_fit_to_width(RID p_shaped, float p_width, uint16_t /*JustificationFlag*/ p_jst_flags = JUSTIFICATION_WORD_BOUND | JUSTIFICATION_KASHIDA) override; + virtual float shaped_text_tab_align(RID p_shaped, const PackedFloat32Array &p_tab_stops) override; virtual bool shaped_text_shape(RID p_shaped) override; virtual bool shaped_text_update_breaks(RID p_shaped) override; virtual bool shaped_text_update_justification_ops(RID p_shaped) override; - virtual void shaped_text_overrun_trim_to_width(RID p_shaped, real_t p_width, uint8_t p_trim_flags) override; - virtual TrimData shaped_text_get_trim_data(RID p_shaped) const override; + virtual int shaped_text_get_trim_pos(RID p_shaped) const override; + virtual int shaped_text_get_ellipsis_pos(RID p_shaped) const override; + virtual const Glyph *shaped_text_get_ellipsis_glyphs(RID p_shaped) const override; + virtual int shaped_text_get_ellipsis_glyph_count(RID p_shaped) const override; + + virtual void shaped_text_overrun_trim_to_width(RID p_shaped, float p_width, uint16_t p_trim_flags) override; virtual bool shaped_text_is_ready(RID p_shaped) const override; - virtual Vector<Glyph> shaped_text_get_glyphs(RID p_shaped) const override; + virtual const Glyph *shaped_text_get_glyphs(RID p_shaped) const override; + virtual const Glyph *shaped_text_sort_logical(RID p_shaped) override; + virtual int shaped_text_get_glyph_count(RID p_shaped) const override; virtual Vector2i shaped_text_get_range(RID p_shaped) const override; - virtual Vector<Glyph> shaped_text_sort_logical(RID p_shaped) override; - virtual Array shaped_text_get_objects(RID p_shaped) const override; virtual Rect2 shaped_text_get_object_rect(RID p_shaped, Variant p_key) const override; virtual Size2 shaped_text_get_size(RID p_shaped) const override; - virtual real_t shaped_text_get_ascent(RID p_shaped) const override; - virtual real_t shaped_text_get_descent(RID p_shaped) const override; - virtual real_t shaped_text_get_width(RID p_shaped) const override; - virtual real_t shaped_text_get_underline_position(RID p_shaped) const override; - virtual real_t shaped_text_get_underline_thickness(RID p_shaped) const override; - - static TextServer *create_func(Error &r_error, void *p_user_data); - static void register_server(); + virtual float shaped_text_get_ascent(RID p_shaped) const override; + virtual float shaped_text_get_descent(RID p_shaped) const override; + virtual float shaped_text_get_width(RID p_shaped) const override; + virtual float shaped_text_get_underline_position(RID p_shaped) const override; + virtual float shaped_text_get_underline_thickness(RID p_shaped) const override; TextServerFallback(); ~TextServerFallback(); |