summaryrefslogtreecommitdiffstats
path: root/modules/text_server_adv/text_server_adv.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'modules/text_server_adv/text_server_adv.cpp')
-rw-r--r--modules/text_server_adv/text_server_adv.cpp486
1 files changed, 309 insertions, 177 deletions
diff --git a/modules/text_server_adv/text_server_adv.cpp b/modules/text_server_adv/text_server_adv.cpp
index 13d8a2c17a..9adb10236e 100644
--- a/modules/text_server_adv/text_server_adv.cpp
+++ b/modules/text_server_adv/text_server_adv.cpp
@@ -1810,7 +1810,7 @@ _FORCE_INLINE_ void TextServerAdvanced::_font_clear_cache(FontAdvanced *p_font_d
hb_font_t *TextServerAdvanced::_font_get_hb_handle(const RID &p_font_rid, int64_t p_size) const {
FontAdvanced *fd = font_owner.get_or_null(p_font_rid);
- ERR_FAIL_COND_V(!fd, nullptr);
+ ERR_FAIL_NULL_V(fd, nullptr);
MutexLock lock(fd->mutex);
Vector2i size = _get_size(fd, p_size);
@@ -1830,7 +1830,7 @@ RID TextServerAdvanced::_create_font() {
void TextServerAdvanced::_font_set_data(const RID &p_font_rid, const PackedByteArray &p_data) {
FontAdvanced *fd = font_owner.get_or_null(p_font_rid);
- ERR_FAIL_COND(!fd);
+ ERR_FAIL_NULL(fd);
MutexLock lock(fd->mutex);
_font_clear_cache(fd);
@@ -1841,7 +1841,7 @@ void TextServerAdvanced::_font_set_data(const RID &p_font_rid, const PackedByteA
void TextServerAdvanced::_font_set_data_ptr(const RID &p_font_rid, const uint8_t *p_data_ptr, int64_t p_data_size) {
FontAdvanced *fd = font_owner.get_or_null(p_font_rid);
- ERR_FAIL_COND(!fd);
+ ERR_FAIL_NULL(fd);
MutexLock lock(fd->mutex);
_font_clear_cache(fd);
@@ -1855,7 +1855,7 @@ void TextServerAdvanced::_font_set_face_index(const RID &p_font_rid, int64_t p_f
ERR_FAIL_COND(p_face_index >= 0x7FFF);
FontAdvanced *fd = font_owner.get_or_null(p_font_rid);
- ERR_FAIL_COND(!fd);
+ ERR_FAIL_NULL(fd);
MutexLock lock(fd->mutex);
if (fd->face_index != p_face_index) {
@@ -1866,7 +1866,7 @@ void TextServerAdvanced::_font_set_face_index(const RID &p_font_rid, int64_t p_f
int64_t TextServerAdvanced::_font_get_face_index(const RID &p_font_rid) const {
FontAdvanced *fd = font_owner.get_or_null(p_font_rid);
- ERR_FAIL_COND_V(!fd, 0);
+ ERR_FAIL_NULL_V(fd, 0);
MutexLock lock(fd->mutex);
return fd->face_index;
@@ -1874,7 +1874,7 @@ int64_t TextServerAdvanced::_font_get_face_index(const RID &p_font_rid) const {
int64_t TextServerAdvanced::_font_get_face_count(const RID &p_font_rid) const {
FontAdvanced *fd = font_owner.get_or_null(p_font_rid);
- ERR_FAIL_COND_V(!fd, 0);
+ ERR_FAIL_NULL_V(fd, 0);
MutexLock lock(fd->mutex);
int face_count = 0;
@@ -1920,7 +1920,7 @@ int64_t TextServerAdvanced::_font_get_face_count(const RID &p_font_rid) const {
void TextServerAdvanced::_font_set_style(const RID &p_font_rid, BitField<FontStyle> p_style) {
FontAdvanced *fd = font_owner.get_or_null(p_font_rid);
- ERR_FAIL_COND(!fd);
+ ERR_FAIL_NULL(fd);
MutexLock lock(fd->mutex);
Vector2i size = _get_size(fd, 16);
@@ -1930,7 +1930,7 @@ void TextServerAdvanced::_font_set_style(const RID &p_font_rid, BitField<FontSty
BitField<TextServer::FontStyle> TextServerAdvanced::_font_get_style(const RID &p_font_rid) const {
FontAdvanced *fd = font_owner.get_or_null(p_font_rid);
- ERR_FAIL_COND_V(!fd, 0);
+ ERR_FAIL_NULL_V(fd, 0);
MutexLock lock(fd->mutex);
Vector2i size = _get_size(fd, 16);
@@ -1940,7 +1940,7 @@ BitField<TextServer::FontStyle> TextServerAdvanced::_font_get_style(const RID &p
void TextServerAdvanced::_font_set_style_name(const RID &p_font_rid, const String &p_name) {
FontAdvanced *fd = font_owner.get_or_null(p_font_rid);
- ERR_FAIL_COND(!fd);
+ ERR_FAIL_NULL(fd);
MutexLock lock(fd->mutex);
Vector2i size = _get_size(fd, 16);
@@ -1950,7 +1950,7 @@ void TextServerAdvanced::_font_set_style_name(const RID &p_font_rid, const Strin
String TextServerAdvanced::_font_get_style_name(const RID &p_font_rid) const {
FontAdvanced *fd = font_owner.get_or_null(p_font_rid);
- ERR_FAIL_COND_V(!fd, String());
+ ERR_FAIL_NULL_V(fd, String());
MutexLock lock(fd->mutex);
Vector2i size = _get_size(fd, 16);
@@ -1960,7 +1960,7 @@ String TextServerAdvanced::_font_get_style_name(const RID &p_font_rid) const {
void TextServerAdvanced::_font_set_weight(const RID &p_font_rid, int64_t p_weight) {
FontAdvanced *fd = font_owner.get_or_null(p_font_rid);
- ERR_FAIL_COND(!fd);
+ ERR_FAIL_NULL(fd);
MutexLock lock(fd->mutex);
Vector2i size = _get_size(fd, 16);
@@ -1970,7 +1970,7 @@ void TextServerAdvanced::_font_set_weight(const RID &p_font_rid, int64_t p_weigh
int64_t TextServerAdvanced::_font_get_weight(const RID &p_font_rid) const {
FontAdvanced *fd = font_owner.get_or_null(p_font_rid);
- ERR_FAIL_COND_V(!fd, 400);
+ ERR_FAIL_NULL_V(fd, 400);
MutexLock lock(fd->mutex);
Vector2i size = _get_size(fd, 16);
@@ -1980,7 +1980,7 @@ int64_t TextServerAdvanced::_font_get_weight(const RID &p_font_rid) const {
void TextServerAdvanced::_font_set_stretch(const RID &p_font_rid, int64_t p_stretch) {
FontAdvanced *fd = font_owner.get_or_null(p_font_rid);
- ERR_FAIL_COND(!fd);
+ ERR_FAIL_NULL(fd);
MutexLock lock(fd->mutex);
Vector2i size = _get_size(fd, 16);
@@ -1990,7 +1990,7 @@ void TextServerAdvanced::_font_set_stretch(const RID &p_font_rid, int64_t p_stre
int64_t TextServerAdvanced::_font_get_stretch(const RID &p_font_rid) const {
FontAdvanced *fd = font_owner.get_or_null(p_font_rid);
- ERR_FAIL_COND_V(!fd, 100);
+ ERR_FAIL_NULL_V(fd, 100);
MutexLock lock(fd->mutex);
Vector2i size = _get_size(fd, 16);
@@ -2000,7 +2000,7 @@ int64_t TextServerAdvanced::_font_get_stretch(const RID &p_font_rid) const {
void TextServerAdvanced::_font_set_name(const RID &p_font_rid, const String &p_name) {
FontAdvanced *fd = font_owner.get_or_null(p_font_rid);
- ERR_FAIL_COND(!fd);
+ ERR_FAIL_NULL(fd);
MutexLock lock(fd->mutex);
Vector2i size = _get_size(fd, 16);
@@ -2010,7 +2010,7 @@ void TextServerAdvanced::_font_set_name(const RID &p_font_rid, const String &p_n
String TextServerAdvanced::_font_get_name(const RID &p_font_rid) const {
FontAdvanced *fd = font_owner.get_or_null(p_font_rid);
- ERR_FAIL_COND_V(!fd, String());
+ ERR_FAIL_NULL_V(fd, String());
MutexLock lock(fd->mutex);
Vector2i size = _get_size(fd, 16);
@@ -2020,7 +2020,7 @@ String TextServerAdvanced::_font_get_name(const RID &p_font_rid) const {
Dictionary TextServerAdvanced::_font_get_ot_name_strings(const RID &p_font_rid) const {
FontAdvanced *fd = font_owner.get_or_null(p_font_rid);
- ERR_FAIL_COND_V(!fd, Dictionary());
+ ERR_FAIL_NULL_V(fd, Dictionary());
MutexLock lock(fd->mutex);
Vector2i size = _get_size(fd, 16);
@@ -2113,12 +2113,10 @@ Dictionary TextServerAdvanced::_font_get_ot_name_strings(const RID &p_font_rid)
name = vformat("unknown_%d", names[i].name_id);
} break;
}
+ String text;
unsigned int text_size = hb_ot_name_get_utf32(hb_face, names[i].name_id, names[i].language, nullptr, nullptr) + 1;
- // @todo After godot-cpp#1141 is fixed, use text.resize() and write directly to text.wptr() instead of using a temporary buffer.
- char32_t *buffer = memnew_arr(char32_t, text_size);
- hb_ot_name_get_utf32(hb_face, names[i].name_id, names[i].language, &text_size, (uint32_t *)buffer);
- String text(buffer);
- memdelete_arr(buffer);
+ text.resize(text_size);
+ hb_ot_name_get_utf32(hb_face, names[i].name_id, names[i].language, &text_size, (uint32_t *)text.ptrw());
if (!text.is_empty()) {
Dictionary &id_string = names_for_lang[String(hb_language_to_string(names[i].language))];
id_string[name] = text;
@@ -2135,7 +2133,7 @@ Dictionary TextServerAdvanced::_font_get_ot_name_strings(const RID &p_font_rid)
void TextServerAdvanced::_font_set_antialiasing(const RID &p_font_rid, TextServer::FontAntialiasing p_antialiasing) {
FontAdvanced *fd = font_owner.get_or_null(p_font_rid);
- ERR_FAIL_COND(!fd);
+ ERR_FAIL_NULL(fd);
MutexLock lock(fd->mutex);
if (fd->antialiasing != p_antialiasing) {
@@ -2146,7 +2144,7 @@ void TextServerAdvanced::_font_set_antialiasing(const RID &p_font_rid, TextServe
TextServer::FontAntialiasing TextServerAdvanced::_font_get_antialiasing(const RID &p_font_rid) const {
FontAdvanced *fd = font_owner.get_or_null(p_font_rid);
- ERR_FAIL_COND_V(!fd, TextServer::FONT_ANTIALIASING_NONE);
+ ERR_FAIL_NULL_V(fd, TextServer::FONT_ANTIALIASING_NONE);
MutexLock lock(fd->mutex);
return fd->antialiasing;
@@ -2154,7 +2152,7 @@ TextServer::FontAntialiasing TextServerAdvanced::_font_get_antialiasing(const RI
void TextServerAdvanced::_font_set_generate_mipmaps(const RID &p_font_rid, bool p_generate_mipmaps) {
FontAdvanced *fd = font_owner.get_or_null(p_font_rid);
- ERR_FAIL_COND(!fd);
+ ERR_FAIL_NULL(fd);
MutexLock lock(fd->mutex);
if (fd->mipmaps != p_generate_mipmaps) {
@@ -2170,7 +2168,7 @@ void TextServerAdvanced::_font_set_generate_mipmaps(const RID &p_font_rid, bool
bool TextServerAdvanced::_font_get_generate_mipmaps(const RID &p_font_rid) const {
FontAdvanced *fd = font_owner.get_or_null(p_font_rid);
- ERR_FAIL_COND_V(!fd, false);
+ ERR_FAIL_NULL_V(fd, false);
MutexLock lock(fd->mutex);
return fd->mipmaps;
@@ -2178,7 +2176,7 @@ bool TextServerAdvanced::_font_get_generate_mipmaps(const RID &p_font_rid) const
void TextServerAdvanced::_font_set_multichannel_signed_distance_field(const RID &p_font_rid, bool p_msdf) {
FontAdvanced *fd = font_owner.get_or_null(p_font_rid);
- ERR_FAIL_COND(!fd);
+ ERR_FAIL_NULL(fd);
MutexLock lock(fd->mutex);
if (fd->msdf != p_msdf) {
@@ -2189,7 +2187,7 @@ void TextServerAdvanced::_font_set_multichannel_signed_distance_field(const RID
bool TextServerAdvanced::_font_is_multichannel_signed_distance_field(const RID &p_font_rid) const {
FontAdvanced *fd = font_owner.get_or_null(p_font_rid);
- ERR_FAIL_COND_V(!fd, false);
+ ERR_FAIL_NULL_V(fd, false);
MutexLock lock(fd->mutex);
return fd->msdf;
@@ -2197,7 +2195,7 @@ bool TextServerAdvanced::_font_is_multichannel_signed_distance_field(const RID &
void TextServerAdvanced::_font_set_msdf_pixel_range(const RID &p_font_rid, int64_t p_msdf_pixel_range) {
FontAdvanced *fd = font_owner.get_or_null(p_font_rid);
- ERR_FAIL_COND(!fd);
+ ERR_FAIL_NULL(fd);
MutexLock lock(fd->mutex);
if (fd->msdf_range != p_msdf_pixel_range) {
@@ -2208,7 +2206,7 @@ void TextServerAdvanced::_font_set_msdf_pixel_range(const RID &p_font_rid, int64
int64_t TextServerAdvanced::_font_get_msdf_pixel_range(const RID &p_font_rid) const {
FontAdvanced *fd = font_owner.get_or_null(p_font_rid);
- ERR_FAIL_COND_V(!fd, false);
+ ERR_FAIL_NULL_V(fd, false);
MutexLock lock(fd->mutex);
return fd->msdf_range;
@@ -2216,7 +2214,7 @@ int64_t TextServerAdvanced::_font_get_msdf_pixel_range(const RID &p_font_rid) co
void TextServerAdvanced::_font_set_msdf_size(const RID &p_font_rid, int64_t p_msdf_size) {
FontAdvanced *fd = font_owner.get_or_null(p_font_rid);
- ERR_FAIL_COND(!fd);
+ ERR_FAIL_NULL(fd);
MutexLock lock(fd->mutex);
if (fd->msdf_source_size != p_msdf_size) {
@@ -2227,7 +2225,7 @@ void TextServerAdvanced::_font_set_msdf_size(const RID &p_font_rid, int64_t p_ms
int64_t TextServerAdvanced::_font_get_msdf_size(const RID &p_font_rid) const {
FontAdvanced *fd = font_owner.get_or_null(p_font_rid);
- ERR_FAIL_COND_V(!fd, false);
+ ERR_FAIL_NULL_V(fd, false);
MutexLock lock(fd->mutex);
return fd->msdf_source_size;
@@ -2235,7 +2233,7 @@ int64_t TextServerAdvanced::_font_get_msdf_size(const RID &p_font_rid) const {
void TextServerAdvanced::_font_set_fixed_size(const RID &p_font_rid, int64_t p_fixed_size) {
FontAdvanced *fd = font_owner.get_or_null(p_font_rid);
- ERR_FAIL_COND(!fd);
+ ERR_FAIL_NULL(fd);
MutexLock lock(fd->mutex);
fd->fixed_size = p_fixed_size;
@@ -2243,7 +2241,7 @@ void TextServerAdvanced::_font_set_fixed_size(const RID &p_font_rid, int64_t p_f
int64_t TextServerAdvanced::_font_get_fixed_size(const RID &p_font_rid) const {
FontAdvanced *fd = font_owner.get_or_null(p_font_rid);
- ERR_FAIL_COND_V(!fd, false);
+ ERR_FAIL_NULL_V(fd, false);
MutexLock lock(fd->mutex);
return fd->fixed_size;
@@ -2251,7 +2249,7 @@ int64_t TextServerAdvanced::_font_get_fixed_size(const RID &p_font_rid) const {
void TextServerAdvanced::_font_set_allow_system_fallback(const RID &p_font_rid, bool p_allow_system_fallback) {
FontAdvanced *fd = font_owner.get_or_null(p_font_rid);
- ERR_FAIL_COND(!fd);
+ ERR_FAIL_NULL(fd);
MutexLock lock(fd->mutex);
fd->allow_system_fallback = p_allow_system_fallback;
@@ -2259,7 +2257,7 @@ void TextServerAdvanced::_font_set_allow_system_fallback(const RID &p_font_rid,
bool TextServerAdvanced::_font_is_allow_system_fallback(const RID &p_font_rid) const {
FontAdvanced *fd = font_owner.get_or_null(p_font_rid);
- ERR_FAIL_COND_V(!fd, false);
+ ERR_FAIL_NULL_V(fd, false);
MutexLock lock(fd->mutex);
return fd->allow_system_fallback;
@@ -2267,7 +2265,7 @@ bool TextServerAdvanced::_font_is_allow_system_fallback(const RID &p_font_rid) c
void TextServerAdvanced::_font_set_force_autohinter(const RID &p_font_rid, bool p_force_autohinter) {
FontAdvanced *fd = font_owner.get_or_null(p_font_rid);
- ERR_FAIL_COND(!fd);
+ ERR_FAIL_NULL(fd);
MutexLock lock(fd->mutex);
if (fd->force_autohinter != p_force_autohinter) {
@@ -2278,7 +2276,7 @@ void TextServerAdvanced::_font_set_force_autohinter(const RID &p_font_rid, bool
bool TextServerAdvanced::_font_is_force_autohinter(const RID &p_font_rid) const {
FontAdvanced *fd = font_owner.get_or_null(p_font_rid);
- ERR_FAIL_COND_V(!fd, false);
+ ERR_FAIL_NULL_V(fd, false);
MutexLock lock(fd->mutex);
return fd->force_autohinter;
@@ -2286,7 +2284,7 @@ bool TextServerAdvanced::_font_is_force_autohinter(const RID &p_font_rid) const
void TextServerAdvanced::_font_set_hinting(const RID &p_font_rid, TextServer::Hinting p_hinting) {
FontAdvanced *fd = font_owner.get_or_null(p_font_rid);
- ERR_FAIL_COND(!fd);
+ ERR_FAIL_NULL(fd);
MutexLock lock(fd->mutex);
if (fd->hinting != p_hinting) {
@@ -2297,7 +2295,7 @@ void TextServerAdvanced::_font_set_hinting(const RID &p_font_rid, TextServer::Hi
TextServer::Hinting TextServerAdvanced::_font_get_hinting(const RID &p_font_rid) const {
FontAdvanced *fd = font_owner.get_or_null(p_font_rid);
- ERR_FAIL_COND_V(!fd, HINTING_NONE);
+ ERR_FAIL_NULL_V(fd, HINTING_NONE);
MutexLock lock(fd->mutex);
return fd->hinting;
@@ -2305,7 +2303,7 @@ TextServer::Hinting TextServerAdvanced::_font_get_hinting(const RID &p_font_rid)
void TextServerAdvanced::_font_set_subpixel_positioning(const RID &p_font_rid, TextServer::SubpixelPositioning p_subpixel) {
FontAdvanced *fd = font_owner.get_or_null(p_font_rid);
- ERR_FAIL_COND(!fd);
+ ERR_FAIL_NULL(fd);
MutexLock lock(fd->mutex);
fd->subpixel_positioning = p_subpixel;
@@ -2313,7 +2311,7 @@ void TextServerAdvanced::_font_set_subpixel_positioning(const RID &p_font_rid, T
TextServer::SubpixelPositioning TextServerAdvanced::_font_get_subpixel_positioning(const RID &p_font_rid) const {
FontAdvanced *fd = font_owner.get_or_null(p_font_rid);
- ERR_FAIL_COND_V(!fd, SUBPIXEL_POSITIONING_DISABLED);
+ ERR_FAIL_NULL_V(fd, SUBPIXEL_POSITIONING_DISABLED);
MutexLock lock(fd->mutex);
return fd->subpixel_positioning;
@@ -2321,7 +2319,7 @@ TextServer::SubpixelPositioning TextServerAdvanced::_font_get_subpixel_positioni
void TextServerAdvanced::_font_set_embolden(const RID &p_font_rid, double p_strength) {
FontAdvanced *fd = font_owner.get_or_null(p_font_rid);
- ERR_FAIL_COND(!fd);
+ ERR_FAIL_NULL(fd);
MutexLock lock(fd->mutex);
if (fd->embolden != p_strength) {
@@ -2332,15 +2330,38 @@ void TextServerAdvanced::_font_set_embolden(const RID &p_font_rid, double p_stre
double TextServerAdvanced::_font_get_embolden(const RID &p_font_rid) const {
FontAdvanced *fd = font_owner.get_or_null(p_font_rid);
- ERR_FAIL_COND_V(!fd, 0.0);
+ ERR_FAIL_NULL_V(fd, 0.0);
MutexLock lock(fd->mutex);
return fd->embolden;
}
+void TextServerAdvanced::_font_set_spacing(const RID &p_font_rid, SpacingType p_spacing, int64_t p_value) {
+ ERR_FAIL_INDEX((int)p_spacing, 4);
+ FontAdvanced *fd = font_owner.get_or_null(p_font_rid);
+ ERR_FAIL_NULL(fd);
+
+ MutexLock lock(fd->mutex);
+ if (fd->extra_spacing[p_spacing] != p_value) {
+ _font_clear_cache(fd);
+ fd->extra_spacing[p_spacing] = p_value;
+ }
+}
+
+int64_t TextServerAdvanced::_font_get_spacing(const RID &p_font_rid, SpacingType p_spacing) const {
+ ERR_FAIL_INDEX_V((int)p_spacing, 4, 0);
+
+ FontAdvanced *fd = font_owner.get_or_null(p_font_rid);
+ ERR_FAIL_NULL_V(fd, 0);
+
+ MutexLock lock(fd->mutex);
+
+ return fd->extra_spacing[p_spacing];
+}
+
void TextServerAdvanced::_font_set_transform(const RID &p_font_rid, const Transform2D &p_transform) {
FontAdvanced *fd = font_owner.get_or_null(p_font_rid);
- ERR_FAIL_COND(!fd);
+ ERR_FAIL_NULL(fd);
MutexLock lock(fd->mutex);
if (fd->transform != p_transform) {
@@ -2351,7 +2372,7 @@ void TextServerAdvanced::_font_set_transform(const RID &p_font_rid, const Transf
Transform2D TextServerAdvanced::_font_get_transform(const RID &p_font_rid) const {
FontAdvanced *fd = font_owner.get_or_null(p_font_rid);
- ERR_FAIL_COND_V(!fd, Transform2D());
+ ERR_FAIL_NULL_V(fd, Transform2D());
MutexLock lock(fd->mutex);
return fd->transform;
@@ -2359,18 +2380,18 @@ Transform2D TextServerAdvanced::_font_get_transform(const RID &p_font_rid) const
void TextServerAdvanced::_font_set_variation_coordinates(const RID &p_font_rid, const Dictionary &p_variation_coordinates) {
FontAdvanced *fd = font_owner.get_or_null(p_font_rid);
- ERR_FAIL_COND(!fd);
+ ERR_FAIL_NULL(fd);
MutexLock lock(fd->mutex);
- if (fd->variation_coordinates != p_variation_coordinates) {
+ if (!fd->variation_coordinates.recursive_equal(p_variation_coordinates, 1)) {
_font_clear_cache(fd);
- fd->variation_coordinates = p_variation_coordinates;
+ fd->variation_coordinates = p_variation_coordinates.duplicate();
}
}
Dictionary TextServerAdvanced::_font_get_variation_coordinates(const RID &p_font_rid) const {
FontAdvanced *fd = font_owner.get_or_null(p_font_rid);
- ERR_FAIL_COND_V(!fd, Dictionary());
+ ERR_FAIL_NULL_V(fd, Dictionary());
MutexLock lock(fd->mutex);
return fd->variation_coordinates;
@@ -2378,7 +2399,7 @@ Dictionary TextServerAdvanced::_font_get_variation_coordinates(const RID &p_font
void TextServerAdvanced::_font_set_oversampling(const RID &p_font_rid, double p_oversampling) {
FontAdvanced *fd = font_owner.get_or_null(p_font_rid);
- ERR_FAIL_COND(!fd);
+ ERR_FAIL_NULL(fd);
MutexLock lock(fd->mutex);
if (fd->oversampling != p_oversampling) {
@@ -2389,7 +2410,7 @@ void TextServerAdvanced::_font_set_oversampling(const RID &p_font_rid, double p_
double TextServerAdvanced::_font_get_oversampling(const RID &p_font_rid) const {
FontAdvanced *fd = font_owner.get_or_null(p_font_rid);
- ERR_FAIL_COND_V(!fd, 0.0);
+ ERR_FAIL_NULL_V(fd, 0.0);
MutexLock lock(fd->mutex);
return fd->oversampling;
@@ -2397,7 +2418,7 @@ double TextServerAdvanced::_font_get_oversampling(const RID &p_font_rid) const {
TypedArray<Vector2i> TextServerAdvanced::_font_get_size_cache_list(const RID &p_font_rid) const {
FontAdvanced *fd = font_owner.get_or_null(p_font_rid);
- ERR_FAIL_COND_V(!fd, TypedArray<Vector2i>());
+ ERR_FAIL_NULL_V(fd, TypedArray<Vector2i>());
MutexLock lock(fd->mutex);
TypedArray<Vector2i> ret;
@@ -2409,7 +2430,7 @@ TypedArray<Vector2i> TextServerAdvanced::_font_get_size_cache_list(const RID &p_
void TextServerAdvanced::_font_clear_size_cache(const RID &p_font_rid) {
FontAdvanced *fd = font_owner.get_or_null(p_font_rid);
- ERR_FAIL_COND(!fd);
+ ERR_FAIL_NULL(fd);
MutexLock lock(fd->mutex);
MutexLock ftlock(ft_mutex);
@@ -2421,7 +2442,7 @@ void TextServerAdvanced::_font_clear_size_cache(const RID &p_font_rid) {
void TextServerAdvanced::_font_remove_size_cache(const RID &p_font_rid, const Vector2i &p_size) {
FontAdvanced *fd = font_owner.get_or_null(p_font_rid);
- ERR_FAIL_COND(!fd);
+ ERR_FAIL_NULL(fd);
MutexLock lock(fd->mutex);
MutexLock ftlock(ft_mutex);
@@ -2433,7 +2454,7 @@ void TextServerAdvanced::_font_remove_size_cache(const RID &p_font_rid, const Ve
void TextServerAdvanced::_font_set_ascent(const RID &p_font_rid, int64_t p_size, double p_ascent) {
FontAdvanced *fd = font_owner.get_or_null(p_font_rid);
- ERR_FAIL_COND(!fd);
+ ERR_FAIL_NULL(fd);
MutexLock lock(fd->mutex);
Vector2i size = _get_size(fd, p_size);
@@ -2444,7 +2465,7 @@ void TextServerAdvanced::_font_set_ascent(const RID &p_font_rid, int64_t p_size,
double TextServerAdvanced::_font_get_ascent(const RID &p_font_rid, int64_t p_size) const {
FontAdvanced *fd = font_owner.get_or_null(p_font_rid);
- ERR_FAIL_COND_V(!fd, 0.0);
+ ERR_FAIL_NULL_V(fd, 0.0);
MutexLock lock(fd->mutex);
Vector2i size = _get_size(fd, p_size);
@@ -2460,7 +2481,7 @@ double TextServerAdvanced::_font_get_ascent(const RID &p_font_rid, int64_t p_siz
void TextServerAdvanced::_font_set_descent(const RID &p_font_rid, int64_t p_size, double p_descent) {
FontAdvanced *fd = font_owner.get_or_null(p_font_rid);
- ERR_FAIL_COND(!fd);
+ ERR_FAIL_NULL(fd);
Vector2i size = _get_size(fd, p_size);
@@ -2470,7 +2491,7 @@ void TextServerAdvanced::_font_set_descent(const RID &p_font_rid, int64_t p_size
double TextServerAdvanced::_font_get_descent(const RID &p_font_rid, int64_t p_size) const {
FontAdvanced *fd = font_owner.get_or_null(p_font_rid);
- ERR_FAIL_COND_V(!fd, 0.0);
+ ERR_FAIL_NULL_V(fd, 0.0);
MutexLock lock(fd->mutex);
Vector2i size = _get_size(fd, p_size);
@@ -2486,7 +2507,7 @@ double TextServerAdvanced::_font_get_descent(const RID &p_font_rid, int64_t p_si
void TextServerAdvanced::_font_set_underline_position(const RID &p_font_rid, int64_t p_size, double p_underline_position) {
FontAdvanced *fd = font_owner.get_or_null(p_font_rid);
- ERR_FAIL_COND(!fd);
+ ERR_FAIL_NULL(fd);
MutexLock lock(fd->mutex);
Vector2i size = _get_size(fd, p_size);
@@ -2497,7 +2518,7 @@ void TextServerAdvanced::_font_set_underline_position(const RID &p_font_rid, int
double TextServerAdvanced::_font_get_underline_position(const RID &p_font_rid, int64_t p_size) const {
FontAdvanced *fd = font_owner.get_or_null(p_font_rid);
- ERR_FAIL_COND_V(!fd, 0.0);
+ ERR_FAIL_NULL_V(fd, 0.0);
MutexLock lock(fd->mutex);
Vector2i size = _get_size(fd, p_size);
@@ -2513,7 +2534,7 @@ double TextServerAdvanced::_font_get_underline_position(const RID &p_font_rid, i
void TextServerAdvanced::_font_set_underline_thickness(const RID &p_font_rid, int64_t p_size, double p_underline_thickness) {
FontAdvanced *fd = font_owner.get_or_null(p_font_rid);
- ERR_FAIL_COND(!fd);
+ ERR_FAIL_NULL(fd);
MutexLock lock(fd->mutex);
Vector2i size = _get_size(fd, p_size);
@@ -2524,7 +2545,7 @@ void TextServerAdvanced::_font_set_underline_thickness(const RID &p_font_rid, in
double TextServerAdvanced::_font_get_underline_thickness(const RID &p_font_rid, int64_t p_size) const {
FontAdvanced *fd = font_owner.get_or_null(p_font_rid);
- ERR_FAIL_COND_V(!fd, 0.0);
+ ERR_FAIL_NULL_V(fd, 0.0);
MutexLock lock(fd->mutex);
Vector2i size = _get_size(fd, p_size);
@@ -2540,7 +2561,7 @@ double TextServerAdvanced::_font_get_underline_thickness(const RID &p_font_rid,
void TextServerAdvanced::_font_set_scale(const RID &p_font_rid, int64_t p_size, double p_scale) {
FontAdvanced *fd = font_owner.get_or_null(p_font_rid);
- ERR_FAIL_COND(!fd);
+ ERR_FAIL_NULL(fd);
MutexLock lock(fd->mutex);
Vector2i size = _get_size(fd, p_size);
@@ -2556,7 +2577,7 @@ void TextServerAdvanced::_font_set_scale(const RID &p_font_rid, int64_t p_size,
double TextServerAdvanced::_font_get_scale(const RID &p_font_rid, int64_t p_size) const {
FontAdvanced *fd = font_owner.get_or_null(p_font_rid);
- ERR_FAIL_COND_V(!fd, 0.0);
+ ERR_FAIL_NULL_V(fd, 0.0);
MutexLock lock(fd->mutex);
Vector2i size = _get_size(fd, p_size);
@@ -2572,7 +2593,7 @@ double TextServerAdvanced::_font_get_scale(const RID &p_font_rid, int64_t p_size
int64_t TextServerAdvanced::_font_get_texture_count(const RID &p_font_rid, const Vector2i &p_size) const {
FontAdvanced *fd = font_owner.get_or_null(p_font_rid);
- ERR_FAIL_COND_V(!fd, 0);
+ ERR_FAIL_NULL_V(fd, 0);
MutexLock lock(fd->mutex);
Vector2i size = _get_size_outline(fd, p_size);
@@ -2584,7 +2605,7 @@ int64_t TextServerAdvanced::_font_get_texture_count(const RID &p_font_rid, const
void TextServerAdvanced::_font_clear_textures(const RID &p_font_rid, const Vector2i &p_size) {
FontAdvanced *fd = font_owner.get_or_null(p_font_rid);
- ERR_FAIL_COND(!fd);
+ ERR_FAIL_NULL(fd);
MutexLock lock(fd->mutex);
Vector2i size = _get_size_outline(fd, p_size);
@@ -2594,7 +2615,7 @@ void TextServerAdvanced::_font_clear_textures(const RID &p_font_rid, const Vecto
void TextServerAdvanced::_font_remove_texture(const RID &p_font_rid, const Vector2i &p_size, int64_t p_texture_index) {
FontAdvanced *fd = font_owner.get_or_null(p_font_rid);
- ERR_FAIL_COND(!fd);
+ ERR_FAIL_NULL(fd);
MutexLock lock(fd->mutex);
Vector2i size = _get_size_outline(fd, p_size);
@@ -2606,7 +2627,7 @@ void TextServerAdvanced::_font_remove_texture(const RID &p_font_rid, const Vecto
void TextServerAdvanced::_font_set_texture_image(const RID &p_font_rid, const Vector2i &p_size, int64_t p_texture_index, const Ref<Image> &p_image) {
FontAdvanced *fd = font_owner.get_or_null(p_font_rid);
- ERR_FAIL_COND(!fd);
+ ERR_FAIL_NULL(fd);
ERR_FAIL_COND(p_image.is_null());
MutexLock lock(fd->mutex);
@@ -2635,7 +2656,7 @@ void TextServerAdvanced::_font_set_texture_image(const RID &p_font_rid, const Ve
Ref<Image> TextServerAdvanced::_font_get_texture_image(const RID &p_font_rid, const Vector2i &p_size, int64_t p_texture_index) const {
FontAdvanced *fd = font_owner.get_or_null(p_font_rid);
- ERR_FAIL_COND_V(!fd, Ref<Image>());
+ ERR_FAIL_NULL_V(fd, Ref<Image>());
MutexLock lock(fd->mutex);
Vector2i size = _get_size_outline(fd, p_size);
@@ -2649,7 +2670,7 @@ Ref<Image> TextServerAdvanced::_font_get_texture_image(const RID &p_font_rid, co
void TextServerAdvanced::_font_set_texture_offsets(const RID &p_font_rid, const Vector2i &p_size, int64_t p_texture_index, const PackedInt32Array &p_offsets) {
ERR_FAIL_COND(p_offsets.size() % 4 != 0);
FontAdvanced *fd = font_owner.get_or_null(p_font_rid);
- ERR_FAIL_COND(!fd);
+ ERR_FAIL_NULL(fd);
MutexLock lock(fd->mutex);
Vector2i size = _get_size_outline(fd, p_size);
@@ -2668,7 +2689,7 @@ void TextServerAdvanced::_font_set_texture_offsets(const RID &p_font_rid, const
PackedInt32Array TextServerAdvanced::_font_get_texture_offsets(const RID &p_font_rid, const Vector2i &p_size, int64_t p_texture_index) const {
FontAdvanced *fd = font_owner.get_or_null(p_font_rid);
- ERR_FAIL_COND_V(!fd, PackedInt32Array());
+ ERR_FAIL_NULL_V(fd, PackedInt32Array());
MutexLock lock(fd->mutex);
Vector2i size = _get_size_outline(fd, p_size);
@@ -2693,7 +2714,7 @@ PackedInt32Array TextServerAdvanced::_font_get_texture_offsets(const RID &p_font
PackedInt32Array TextServerAdvanced::_font_get_glyph_list(const RID &p_font_rid, const Vector2i &p_size) const {
FontAdvanced *fd = font_owner.get_or_null(p_font_rid);
- ERR_FAIL_COND_V(!fd, PackedInt32Array());
+ ERR_FAIL_NULL_V(fd, PackedInt32Array());
MutexLock lock(fd->mutex);
Vector2i size = _get_size_outline(fd, p_size);
@@ -2709,7 +2730,7 @@ PackedInt32Array TextServerAdvanced::_font_get_glyph_list(const RID &p_font_rid,
void TextServerAdvanced::_font_clear_glyphs(const RID &p_font_rid, const Vector2i &p_size) {
FontAdvanced *fd = font_owner.get_or_null(p_font_rid);
- ERR_FAIL_COND(!fd);
+ ERR_FAIL_NULL(fd);
MutexLock lock(fd->mutex);
Vector2i size = _get_size_outline(fd, p_size);
@@ -2720,7 +2741,7 @@ void TextServerAdvanced::_font_clear_glyphs(const RID &p_font_rid, const Vector2
void TextServerAdvanced::_font_remove_glyph(const RID &p_font_rid, const Vector2i &p_size, int64_t p_glyph) {
FontAdvanced *fd = font_owner.get_or_null(p_font_rid);
- ERR_FAIL_COND(!fd);
+ ERR_FAIL_NULL(fd);
MutexLock lock(fd->mutex);
Vector2i size = _get_size_outline(fd, p_size);
@@ -2731,7 +2752,7 @@ void TextServerAdvanced::_font_remove_glyph(const RID &p_font_rid, const Vector2
double TextServerAdvanced::_get_extra_advance(RID p_font_rid, int p_font_size) const {
const FontAdvanced *fd = font_owner.get_or_null(p_font_rid);
- ERR_FAIL_COND_V(!fd, 0.0);
+ ERR_FAIL_NULL_V(fd, 0.0);
MutexLock lock(fd->mutex);
Vector2i size = _get_size(fd, p_font_size);
@@ -2745,7 +2766,7 @@ double TextServerAdvanced::_get_extra_advance(RID p_font_rid, int p_font_size) c
Vector2 TextServerAdvanced::_font_get_glyph_advance(const RID &p_font_rid, int64_t p_size, int64_t p_glyph) const {
FontAdvanced *fd = font_owner.get_or_null(p_font_rid);
- ERR_FAIL_COND_V(!fd, Vector2());
+ ERR_FAIL_NULL_V(fd, Vector2());
MutexLock lock(fd->mutex);
Vector2i size = _get_size(fd, p_size);
@@ -2783,7 +2804,7 @@ Vector2 TextServerAdvanced::_font_get_glyph_advance(const RID &p_font_rid, int64
void TextServerAdvanced::_font_set_glyph_advance(const RID &p_font_rid, int64_t p_size, int64_t p_glyph, const Vector2 &p_advance) {
FontAdvanced *fd = font_owner.get_or_null(p_font_rid);
- ERR_FAIL_COND(!fd);
+ ERR_FAIL_NULL(fd);
MutexLock lock(fd->mutex);
Vector2i size = _get_size(fd, p_size);
@@ -2798,7 +2819,7 @@ void TextServerAdvanced::_font_set_glyph_advance(const RID &p_font_rid, int64_t
Vector2 TextServerAdvanced::_font_get_glyph_offset(const RID &p_font_rid, const Vector2i &p_size, int64_t p_glyph) const {
FontAdvanced *fd = font_owner.get_or_null(p_font_rid);
- ERR_FAIL_COND_V(!fd, Vector2());
+ ERR_FAIL_NULL_V(fd, Vector2());
MutexLock lock(fd->mutex);
Vector2i size = _get_size_outline(fd, p_size);
@@ -2828,7 +2849,7 @@ Vector2 TextServerAdvanced::_font_get_glyph_offset(const RID &p_font_rid, const
void TextServerAdvanced::_font_set_glyph_offset(const RID &p_font_rid, const Vector2i &p_size, int64_t p_glyph, const Vector2 &p_offset) {
FontAdvanced *fd = font_owner.get_or_null(p_font_rid);
- ERR_FAIL_COND(!fd);
+ ERR_FAIL_NULL(fd);
MutexLock lock(fd->mutex);
Vector2i size = _get_size_outline(fd, p_size);
@@ -2843,7 +2864,7 @@ void TextServerAdvanced::_font_set_glyph_offset(const RID &p_font_rid, const Vec
Vector2 TextServerAdvanced::_font_get_glyph_size(const RID &p_font_rid, const Vector2i &p_size, int64_t p_glyph) const {
FontAdvanced *fd = font_owner.get_or_null(p_font_rid);
- ERR_FAIL_COND_V(!fd, Vector2());
+ ERR_FAIL_NULL_V(fd, Vector2());
MutexLock lock(fd->mutex);
Vector2i size = _get_size_outline(fd, p_size);
@@ -2873,7 +2894,7 @@ Vector2 TextServerAdvanced::_font_get_glyph_size(const RID &p_font_rid, const Ve
void TextServerAdvanced::_font_set_glyph_size(const RID &p_font_rid, const Vector2i &p_size, int64_t p_glyph, const Vector2 &p_gl_size) {
FontAdvanced *fd = font_owner.get_or_null(p_font_rid);
- ERR_FAIL_COND(!fd);
+ ERR_FAIL_NULL(fd);
MutexLock lock(fd->mutex);
Vector2i size = _get_size_outline(fd, p_size);
@@ -2888,7 +2909,7 @@ void TextServerAdvanced::_font_set_glyph_size(const RID &p_font_rid, const Vecto
Rect2 TextServerAdvanced::_font_get_glyph_uv_rect(const RID &p_font_rid, const Vector2i &p_size, int64_t p_glyph) const {
FontAdvanced *fd = font_owner.get_or_null(p_font_rid);
- ERR_FAIL_COND_V(!fd, Rect2());
+ ERR_FAIL_NULL_V(fd, Rect2());
MutexLock lock(fd->mutex);
Vector2i size = _get_size_outline(fd, p_size);
@@ -2913,7 +2934,7 @@ Rect2 TextServerAdvanced::_font_get_glyph_uv_rect(const RID &p_font_rid, const V
void TextServerAdvanced::_font_set_glyph_uv_rect(const RID &p_font_rid, const Vector2i &p_size, int64_t p_glyph, const Rect2 &p_uv_rect) {
FontAdvanced *fd = font_owner.get_or_null(p_font_rid);
- ERR_FAIL_COND(!fd);
+ ERR_FAIL_NULL(fd);
MutexLock lock(fd->mutex);
Vector2i size = _get_size_outline(fd, p_size);
@@ -2928,7 +2949,7 @@ void TextServerAdvanced::_font_set_glyph_uv_rect(const RID &p_font_rid, const Ve
int64_t TextServerAdvanced::_font_get_glyph_texture_idx(const RID &p_font_rid, const Vector2i &p_size, int64_t p_glyph) const {
FontAdvanced *fd = font_owner.get_or_null(p_font_rid);
- ERR_FAIL_COND_V(!fd, -1);
+ ERR_FAIL_NULL_V(fd, -1);
MutexLock lock(fd->mutex);
Vector2i size = _get_size_outline(fd, p_size);
@@ -2953,7 +2974,7 @@ int64_t TextServerAdvanced::_font_get_glyph_texture_idx(const RID &p_font_rid, c
void TextServerAdvanced::_font_set_glyph_texture_idx(const RID &p_font_rid, const Vector2i &p_size, int64_t p_glyph, int64_t p_texture_idx) {
FontAdvanced *fd = font_owner.get_or_null(p_font_rid);
- ERR_FAIL_COND(!fd);
+ ERR_FAIL_NULL(fd);
MutexLock lock(fd->mutex);
Vector2i size = _get_size_outline(fd, p_size);
@@ -2968,7 +2989,7 @@ void TextServerAdvanced::_font_set_glyph_texture_idx(const RID &p_font_rid, cons
RID TextServerAdvanced::_font_get_glyph_texture_rid(const RID &p_font_rid, const Vector2i &p_size, int64_t p_glyph) const {
FontAdvanced *fd = font_owner.get_or_null(p_font_rid);
- ERR_FAIL_COND_V(!fd, RID());
+ ERR_FAIL_NULL_V(fd, RID());
MutexLock lock(fd->mutex);
Vector2i size = _get_size_outline(fd, p_size);
@@ -3014,7 +3035,7 @@ RID TextServerAdvanced::_font_get_glyph_texture_rid(const RID &p_font_rid, const
Size2 TextServerAdvanced::_font_get_glyph_texture_size(const RID &p_font_rid, const Vector2i &p_size, int64_t p_glyph) const {
FontAdvanced *fd = font_owner.get_or_null(p_font_rid);
- ERR_FAIL_COND_V(!fd, Size2());
+ ERR_FAIL_NULL_V(fd, Size2());
MutexLock lock(fd->mutex);
Vector2i size = _get_size_outline(fd, p_size);
@@ -3060,7 +3081,7 @@ Size2 TextServerAdvanced::_font_get_glyph_texture_size(const RID &p_font_rid, co
Dictionary TextServerAdvanced::_font_get_glyph_contours(const RID &p_font_rid, int64_t p_size, int64_t p_index) const {
FontAdvanced *fd = font_owner.get_or_null(p_font_rid);
- ERR_FAIL_COND_V(!fd, Dictionary());
+ ERR_FAIL_NULL_V(fd, Dictionary());
MutexLock lock(fd->mutex);
Vector2i size = _get_size(fd, p_size);
@@ -3110,7 +3131,7 @@ Dictionary TextServerAdvanced::_font_get_glyph_contours(const RID &p_font_rid, i
TypedArray<Vector2i> TextServerAdvanced::_font_get_kerning_list(const RID &p_font_rid, int64_t p_size) const {
FontAdvanced *fd = font_owner.get_or_null(p_font_rid);
- ERR_FAIL_COND_V(!fd, TypedArray<Vector2i>());
+ ERR_FAIL_NULL_V(fd, TypedArray<Vector2i>());
MutexLock lock(fd->mutex);
Vector2i size = _get_size(fd, p_size);
@@ -3126,7 +3147,7 @@ TypedArray<Vector2i> TextServerAdvanced::_font_get_kerning_list(const RID &p_fon
void TextServerAdvanced::_font_clear_kerning_map(const RID &p_font_rid, int64_t p_size) {
FontAdvanced *fd = font_owner.get_or_null(p_font_rid);
- ERR_FAIL_COND(!fd);
+ ERR_FAIL_NULL(fd);
MutexLock lock(fd->mutex);
Vector2i size = _get_size(fd, p_size);
@@ -3137,7 +3158,7 @@ void TextServerAdvanced::_font_clear_kerning_map(const RID &p_font_rid, int64_t
void TextServerAdvanced::_font_remove_kerning(const RID &p_font_rid, int64_t p_size, const Vector2i &p_glyph_pair) {
FontAdvanced *fd = font_owner.get_or_null(p_font_rid);
- ERR_FAIL_COND(!fd);
+ ERR_FAIL_NULL(fd);
MutexLock lock(fd->mutex);
Vector2i size = _get_size(fd, p_size);
@@ -3148,7 +3169,7 @@ void TextServerAdvanced::_font_remove_kerning(const RID &p_font_rid, int64_t p_s
void TextServerAdvanced::_font_set_kerning(const RID &p_font_rid, int64_t p_size, const Vector2i &p_glyph_pair, const Vector2 &p_kerning) {
FontAdvanced *fd = font_owner.get_or_null(p_font_rid);
- ERR_FAIL_COND(!fd);
+ ERR_FAIL_NULL(fd);
MutexLock lock(fd->mutex);
Vector2i size = _get_size(fd, p_size);
@@ -3159,7 +3180,7 @@ void TextServerAdvanced::_font_set_kerning(const RID &p_font_rid, int64_t p_size
Vector2 TextServerAdvanced::_font_get_kerning(const RID &p_font_rid, int64_t p_size, const Vector2i &p_glyph_pair) const {
FontAdvanced *fd = font_owner.get_or_null(p_font_rid);
- ERR_FAIL_COND_V(!fd, Vector2());
+ ERR_FAIL_NULL_V(fd, Vector2());
MutexLock lock(fd->mutex);
Vector2i size = _get_size(fd, p_size);
@@ -3192,7 +3213,7 @@ Vector2 TextServerAdvanced::_font_get_kerning(const RID &p_font_rid, int64_t p_s
int64_t TextServerAdvanced::_font_get_glyph_index(const RID &p_font_rid, int64_t p_size, int64_t p_char, int64_t p_variation_selector) const {
FontAdvanced *fd = font_owner.get_or_null(p_font_rid);
- ERR_FAIL_COND_V(!fd, 0);
+ ERR_FAIL_NULL_V(fd, 0);
ERR_FAIL_COND_V_MSG((p_char >= 0xd800 && p_char <= 0xdfff) || (p_char > 0x10ffff), 0, "Unicode parsing error: Invalid unicode codepoint " + String::num_int64(p_char, 16) + ".");
ERR_FAIL_COND_V_MSG((p_variation_selector >= 0xd800 && p_variation_selector <= 0xdfff) || (p_variation_selector > 0x10ffff), 0, "Unicode parsing error: Invalid unicode codepoint " + String::num_int64(p_variation_selector, 16) + ".");
@@ -3217,7 +3238,7 @@ int64_t TextServerAdvanced::_font_get_glyph_index(const RID &p_font_rid, int64_t
int64_t TextServerAdvanced::_font_get_char_from_glyph_index(const RID &p_font_rid, int64_t p_size, int64_t p_glyph_index) const {
FontAdvanced *fd = font_owner.get_or_null(p_font_rid);
- ERR_FAIL_COND_V(!fd, 0);
+ ERR_FAIL_NULL_V(fd, 0);
MutexLock lock(fd->mutex);
Vector2i size = _get_size(fd, p_size);
@@ -3269,7 +3290,7 @@ bool TextServerAdvanced::_font_has_char(const RID &p_font_rid, int64_t p_char) c
String TextServerAdvanced::_font_get_supported_chars(const RID &p_font_rid) const {
FontAdvanced *fd = font_owner.get_or_null(p_font_rid);
- ERR_FAIL_COND_V(!fd, String());
+ ERR_FAIL_NULL_V(fd, String());
MutexLock lock(fd->mutex);
if (fd->cache.is_empty()) {
@@ -3302,7 +3323,7 @@ String TextServerAdvanced::_font_get_supported_chars(const RID &p_font_rid) cons
void TextServerAdvanced::_font_render_range(const RID &p_font_rid, const Vector2i &p_size, int64_t p_start, int64_t p_end) {
FontAdvanced *fd = font_owner.get_or_null(p_font_rid);
- ERR_FAIL_COND(!fd);
+ ERR_FAIL_NULL(fd);
ERR_FAIL_COND_MSG((p_start >= 0xd800 && p_start <= 0xdfff) || (p_start > 0x10ffff), "Unicode parsing error: Invalid unicode codepoint " + String::num_int64(p_start, 16) + ".");
ERR_FAIL_COND_MSG((p_end >= 0xd800 && p_end <= 0xdfff) || (p_end > 0x10ffff), "Unicode parsing error: Invalid unicode codepoint " + String::num_int64(p_end, 16) + ".");
@@ -3337,7 +3358,7 @@ void TextServerAdvanced::_font_render_range(const RID &p_font_rid, const Vector2
void TextServerAdvanced::_font_render_glyph(const RID &p_font_rid, const Vector2i &p_size, int64_t p_index) {
FontAdvanced *fd = font_owner.get_or_null(p_font_rid);
- ERR_FAIL_COND(!fd);
+ ERR_FAIL_NULL(fd);
MutexLock lock(fd->mutex);
Vector2i size = _get_size_outline(fd, p_size);
@@ -3368,7 +3389,7 @@ void TextServerAdvanced::_font_render_glyph(const RID &p_font_rid, const Vector2
void TextServerAdvanced::_font_draw_glyph(const RID &p_font_rid, const RID &p_canvas, int64_t p_size, const Vector2 &p_pos, int64_t p_index, const Color &p_color) const {
FontAdvanced *fd = font_owner.get_or_null(p_font_rid);
- ERR_FAIL_COND(!fd);
+ ERR_FAIL_NULL(fd);
MutexLock lock(fd->mutex);
Vector2i size = _get_size(fd, p_size);
@@ -3460,7 +3481,7 @@ void TextServerAdvanced::_font_draw_glyph(const RID &p_font_rid, const RID &p_ca
void TextServerAdvanced::_font_draw_glyph_outline(const RID &p_font_rid, const RID &p_canvas, int64_t p_size, int64_t p_outline_size, const Vector2 &p_pos, int64_t p_index, const Color &p_color) const {
FontAdvanced *fd = font_owner.get_or_null(p_font_rid);
- ERR_FAIL_COND(!fd);
+ ERR_FAIL_NULL(fd);
MutexLock lock(fd->mutex);
Vector2i size = _get_size_outline(fd, Vector2i(p_size, p_outline_size));
@@ -3552,7 +3573,7 @@ void TextServerAdvanced::_font_draw_glyph_outline(const RID &p_font_rid, const R
bool TextServerAdvanced::_font_is_language_supported(const RID &p_font_rid, const String &p_language) const {
FontAdvanced *fd = font_owner.get_or_null(p_font_rid);
- ERR_FAIL_COND_V(!fd, false);
+ ERR_FAIL_NULL_V(fd, false);
MutexLock lock(fd->mutex);
if (fd->language_support_overrides.has(p_language)) {
@@ -3564,7 +3585,7 @@ bool TextServerAdvanced::_font_is_language_supported(const RID &p_font_rid, cons
void TextServerAdvanced::_font_set_language_support_override(const RID &p_font_rid, const String &p_language, bool p_supported) {
FontAdvanced *fd = font_owner.get_or_null(p_font_rid);
- ERR_FAIL_COND(!fd);
+ ERR_FAIL_NULL(fd);
MutexLock lock(fd->mutex);
fd->language_support_overrides[p_language] = p_supported;
@@ -3572,7 +3593,7 @@ void TextServerAdvanced::_font_set_language_support_override(const RID &p_font_r
bool TextServerAdvanced::_font_get_language_support_override(const RID &p_font_rid, const String &p_language) {
FontAdvanced *fd = font_owner.get_or_null(p_font_rid);
- ERR_FAIL_COND_V(!fd, false);
+ ERR_FAIL_NULL_V(fd, false);
MutexLock lock(fd->mutex);
return fd->language_support_overrides[p_language];
@@ -3580,7 +3601,7 @@ bool TextServerAdvanced::_font_get_language_support_override(const RID &p_font_r
void TextServerAdvanced::_font_remove_language_support_override(const RID &p_font_rid, const String &p_language) {
FontAdvanced *fd = font_owner.get_or_null(p_font_rid);
- ERR_FAIL_COND(!fd);
+ ERR_FAIL_NULL(fd);
MutexLock lock(fd->mutex);
fd->language_support_overrides.erase(p_language);
@@ -3588,7 +3609,7 @@ void TextServerAdvanced::_font_remove_language_support_override(const RID &p_fon
PackedStringArray TextServerAdvanced::_font_get_language_support_overrides(const RID &p_font_rid) {
FontAdvanced *fd = font_owner.get_or_null(p_font_rid);
- ERR_FAIL_COND_V(!fd, PackedStringArray());
+ ERR_FAIL_NULL_V(fd, PackedStringArray());
MutexLock lock(fd->mutex);
PackedStringArray out;
@@ -3600,7 +3621,7 @@ PackedStringArray TextServerAdvanced::_font_get_language_support_overrides(const
bool TextServerAdvanced::_font_is_script_supported(const RID &p_font_rid, const String &p_script) const {
FontAdvanced *fd = font_owner.get_or_null(p_font_rid);
- ERR_FAIL_COND_V(!fd, false);
+ ERR_FAIL_NULL_V(fd, false);
MutexLock lock(fd->mutex);
if (fd->script_support_overrides.has(p_script)) {
@@ -3614,7 +3635,7 @@ bool TextServerAdvanced::_font_is_script_supported(const RID &p_font_rid, const
void TextServerAdvanced::_font_set_script_support_override(const RID &p_font_rid, const String &p_script, bool p_supported) {
FontAdvanced *fd = font_owner.get_or_null(p_font_rid);
- ERR_FAIL_COND(!fd);
+ ERR_FAIL_NULL(fd);
MutexLock lock(fd->mutex);
fd->script_support_overrides[p_script] = p_supported;
@@ -3622,7 +3643,7 @@ void TextServerAdvanced::_font_set_script_support_override(const RID &p_font_rid
bool TextServerAdvanced::_font_get_script_support_override(const RID &p_font_rid, const String &p_script) {
FontAdvanced *fd = font_owner.get_or_null(p_font_rid);
- ERR_FAIL_COND_V(!fd, false);
+ ERR_FAIL_NULL_V(fd, false);
MutexLock lock(fd->mutex);
return fd->script_support_overrides[p_script];
@@ -3630,7 +3651,7 @@ bool TextServerAdvanced::_font_get_script_support_override(const RID &p_font_rid
void TextServerAdvanced::_font_remove_script_support_override(const RID &p_font_rid, const String &p_script) {
FontAdvanced *fd = font_owner.get_or_null(p_font_rid);
- ERR_FAIL_COND(!fd);
+ ERR_FAIL_NULL(fd);
MutexLock lock(fd->mutex);
fd->script_support_overrides.erase(p_script);
@@ -3638,7 +3659,7 @@ void TextServerAdvanced::_font_remove_script_support_override(const RID &p_font_
PackedStringArray TextServerAdvanced::_font_get_script_support_overrides(const RID &p_font_rid) {
FontAdvanced *fd = font_owner.get_or_null(p_font_rid);
- ERR_FAIL_COND_V(!fd, PackedStringArray());
+ ERR_FAIL_NULL_V(fd, PackedStringArray());
MutexLock lock(fd->mutex);
PackedStringArray out;
@@ -3650,7 +3671,7 @@ PackedStringArray TextServerAdvanced::_font_get_script_support_overrides(const R
void TextServerAdvanced::_font_set_opentype_feature_overrides(const RID &p_font_rid, const Dictionary &p_overrides) {
FontAdvanced *fd = font_owner.get_or_null(p_font_rid);
- ERR_FAIL_COND(!fd);
+ ERR_FAIL_NULL(fd);
MutexLock lock(fd->mutex);
Vector2i size = _get_size(fd, 16);
@@ -3660,7 +3681,7 @@ void TextServerAdvanced::_font_set_opentype_feature_overrides(const RID &p_font_
Dictionary TextServerAdvanced::_font_get_opentype_feature_overrides(const RID &p_font_rid) const {
FontAdvanced *fd = font_owner.get_or_null(p_font_rid);
- ERR_FAIL_COND_V(!fd, Dictionary());
+ ERR_FAIL_NULL_V(fd, Dictionary());
MutexLock lock(fd->mutex);
return fd->feature_overrides;
@@ -3668,7 +3689,7 @@ Dictionary TextServerAdvanced::_font_get_opentype_feature_overrides(const RID &p
Dictionary TextServerAdvanced::_font_supported_feature_list(const RID &p_font_rid) const {
FontAdvanced *fd = font_owner.get_or_null(p_font_rid);
- ERR_FAIL_COND_V(!fd, Dictionary());
+ ERR_FAIL_NULL_V(fd, Dictionary());
MutexLock lock(fd->mutex);
Vector2i size = _get_size(fd, 16);
@@ -3678,7 +3699,7 @@ Dictionary TextServerAdvanced::_font_supported_feature_list(const RID &p_font_ri
Dictionary TextServerAdvanced::_font_supported_variation_list(const RID &p_font_rid) const {
FontAdvanced *fd = font_owner.get_or_null(p_font_rid);
- ERR_FAIL_COND_V(!fd, Dictionary());
+ ERR_FAIL_NULL_V(fd, Dictionary());
MutexLock lock(fd->mutex);
Vector2i size = _get_size(fd, 16);
@@ -3782,6 +3803,7 @@ void TextServerAdvanced::invalidate(TextServerAdvanced::ShapedTextDataAdvanced *
p_shaped->script_iter = nullptr;
}
p_shaped->break_ops_valid = false;
+ p_shaped->chars_valid = false;
p_shaped->js_ops_valid = false;
}
}
@@ -3821,7 +3843,7 @@ RID TextServerAdvanced::_create_shaped_text(TextServer::Direction p_direction, T
void TextServerAdvanced::_shaped_text_clear(const RID &p_shaped) {
ShapedTextDataAdvanced *sd = shaped_owner.get_or_null(p_shaped);
- ERR_FAIL_COND(!sd);
+ ERR_FAIL_NULL(sd);
MutexLock lock(sd->mutex);
sd->parent = RID();
@@ -3837,7 +3859,7 @@ void TextServerAdvanced::_shaped_text_clear(const RID &p_shaped) {
void TextServerAdvanced::_shaped_text_set_direction(const RID &p_shaped, TextServer::Direction p_direction) {
ShapedTextDataAdvanced *sd = shaped_owner.get_or_null(p_shaped);
ERR_FAIL_COND_MSG(p_direction == DIRECTION_INHERITED, "Invalid text direction.");
- ERR_FAIL_COND(!sd);
+ ERR_FAIL_NULL(sd);
MutexLock lock(sd->mutex);
if (sd->direction != p_direction) {
@@ -3851,7 +3873,7 @@ void TextServerAdvanced::_shaped_text_set_direction(const RID &p_shaped, TextSer
TextServer::Direction TextServerAdvanced::_shaped_text_get_direction(const RID &p_shaped) const {
const ShapedTextDataAdvanced *sd = shaped_owner.get_or_null(p_shaped);
- ERR_FAIL_COND_V(!sd, TextServer::DIRECTION_LTR);
+ ERR_FAIL_NULL_V(sd, TextServer::DIRECTION_LTR);
MutexLock lock(sd->mutex);
return sd->direction;
@@ -3859,7 +3881,7 @@ TextServer::Direction TextServerAdvanced::_shaped_text_get_direction(const RID &
TextServer::Direction TextServerAdvanced::_shaped_text_get_inferred_direction(const RID &p_shaped) const {
const ShapedTextDataAdvanced *sd = shaped_owner.get_or_null(p_shaped);
- ERR_FAIL_COND_V(!sd, TextServer::DIRECTION_LTR);
+ ERR_FAIL_NULL_V(sd, TextServer::DIRECTION_LTR);
MutexLock lock(sd->mutex);
return sd->para_direction;
@@ -3868,7 +3890,7 @@ TextServer::Direction TextServerAdvanced::_shaped_text_get_inferred_direction(co
void TextServerAdvanced::_shaped_text_set_custom_punctuation(const RID &p_shaped, const String &p_punct) {
_THREAD_SAFE_METHOD_
ShapedTextDataAdvanced *sd = shaped_owner.get_or_null(p_shaped);
- ERR_FAIL_COND(!sd);
+ ERR_FAIL_NULL(sd);
if (sd->custom_punct != p_punct) {
if (sd->parent != RID()) {
@@ -3882,13 +3904,13 @@ void TextServerAdvanced::_shaped_text_set_custom_punctuation(const RID &p_shaped
String TextServerAdvanced::_shaped_text_get_custom_punctuation(const RID &p_shaped) const {
_THREAD_SAFE_METHOD_
const ShapedTextDataAdvanced *sd = shaped_owner.get_or_null(p_shaped);
- ERR_FAIL_COND_V(!sd, String());
+ ERR_FAIL_NULL_V(sd, String());
return sd->custom_punct;
}
void TextServerAdvanced::_shaped_text_set_bidi_override(const RID &p_shaped, const Array &p_override) {
ShapedTextDataAdvanced *sd = shaped_owner.get_or_null(p_shaped);
- ERR_FAIL_COND(!sd);
+ ERR_FAIL_NULL(sd);
MutexLock lock(sd->mutex);
if (sd->parent != RID()) {
@@ -3909,7 +3931,7 @@ void TextServerAdvanced::_shaped_text_set_bidi_override(const RID &p_shaped, con
void TextServerAdvanced::_shaped_text_set_orientation(const RID &p_shaped, TextServer::Orientation p_orientation) {
ShapedTextDataAdvanced *sd = shaped_owner.get_or_null(p_shaped);
- ERR_FAIL_COND(!sd);
+ ERR_FAIL_NULL(sd);
MutexLock lock(sd->mutex);
if (sd->orientation != p_orientation) {
@@ -3923,7 +3945,7 @@ void TextServerAdvanced::_shaped_text_set_orientation(const RID &p_shaped, TextS
void TextServerAdvanced::_shaped_text_set_preserve_invalid(const RID &p_shaped, bool p_enabled) {
ShapedTextDataAdvanced *sd = shaped_owner.get_or_null(p_shaped);
- ERR_FAIL_COND(!sd);
+ ERR_FAIL_NULL(sd);
MutexLock lock(sd->mutex);
ERR_FAIL_COND(sd->parent != RID());
@@ -3935,7 +3957,7 @@ void TextServerAdvanced::_shaped_text_set_preserve_invalid(const RID &p_shaped,
bool TextServerAdvanced::_shaped_text_get_preserve_invalid(const RID &p_shaped) const {
const ShapedTextDataAdvanced *sd = shaped_owner.get_or_null(p_shaped);
- ERR_FAIL_COND_V(!sd, false);
+ ERR_FAIL_NULL_V(sd, false);
MutexLock lock(sd->mutex);
return sd->preserve_invalid;
@@ -3943,7 +3965,7 @@ bool TextServerAdvanced::_shaped_text_get_preserve_invalid(const RID &p_shaped)
void TextServerAdvanced::_shaped_text_set_preserve_control(const RID &p_shaped, bool p_enabled) {
ShapedTextDataAdvanced *sd = shaped_owner.get_or_null(p_shaped);
- ERR_FAIL_COND(!sd);
+ ERR_FAIL_NULL(sd);
MutexLock lock(sd->mutex);
if (sd->preserve_control != p_enabled) {
@@ -3957,7 +3979,7 @@ void TextServerAdvanced::_shaped_text_set_preserve_control(const RID &p_shaped,
bool TextServerAdvanced::_shaped_text_get_preserve_control(const RID &p_shaped) const {
const ShapedTextDataAdvanced *sd = shaped_owner.get_or_null(p_shaped);
- ERR_FAIL_COND_V(!sd, false);
+ ERR_FAIL_NULL_V(sd, false);
MutexLock lock(sd->mutex);
return sd->preserve_control;
@@ -3966,7 +3988,7 @@ bool TextServerAdvanced::_shaped_text_get_preserve_control(const RID &p_shaped)
void TextServerAdvanced::_shaped_text_set_spacing(const RID &p_shaped, SpacingType p_spacing, int64_t p_value) {
ERR_FAIL_INDEX((int)p_spacing, 4);
ShapedTextDataAdvanced *sd = shaped_owner.get_or_null(p_shaped);
- ERR_FAIL_COND(!sd);
+ ERR_FAIL_NULL(sd);
MutexLock lock(sd->mutex);
if (sd->extra_spacing[p_spacing] != p_value) {
@@ -3982,7 +4004,7 @@ int64_t TextServerAdvanced::_shaped_text_get_spacing(const RID &p_shaped, Spacin
ERR_FAIL_INDEX_V((int)p_spacing, 4, 0);
const ShapedTextDataAdvanced *sd = shaped_owner.get_or_null(p_shaped);
- ERR_FAIL_COND_V(!sd, 0);
+ ERR_FAIL_NULL_V(sd, 0);
MutexLock lock(sd->mutex);
return sd->extra_spacing[p_spacing];
@@ -3990,7 +4012,7 @@ int64_t TextServerAdvanced::_shaped_text_get_spacing(const RID &p_shaped, Spacin
TextServer::Orientation TextServerAdvanced::_shaped_text_get_orientation(const RID &p_shaped) const {
const ShapedTextDataAdvanced *sd = shaped_owner.get_or_null(p_shaped);
- ERR_FAIL_COND_V(!sd, TextServer::ORIENTATION_HORIZONTAL);
+ ERR_FAIL_NULL_V(sd, TextServer::ORIENTATION_HORIZONTAL);
MutexLock lock(sd->mutex);
return sd->orientation;
@@ -3998,20 +4020,20 @@ TextServer::Orientation TextServerAdvanced::_shaped_text_get_orientation(const R
int64_t TextServerAdvanced::_shaped_get_span_count(const RID &p_shaped) const {
ShapedTextDataAdvanced *sd = shaped_owner.get_or_null(p_shaped);
- ERR_FAIL_COND_V(!sd, 0);
+ ERR_FAIL_NULL_V(sd, 0);
return sd->spans.size();
}
Variant TextServerAdvanced::_shaped_get_span_meta(const RID &p_shaped, int64_t p_index) const {
ShapedTextDataAdvanced *sd = shaped_owner.get_or_null(p_shaped);
- ERR_FAIL_COND_V(!sd, Variant());
+ ERR_FAIL_NULL_V(sd, Variant());
ERR_FAIL_INDEX_V(p_index, sd->spans.size(), Variant());
return sd->spans[p_index].meta;
}
void TextServerAdvanced::_shaped_set_span_update_font(const RID &p_shaped, int64_t p_index, const TypedArray<RID> &p_fonts, int64_t p_size, const Dictionary &p_opentype_features) {
ShapedTextDataAdvanced *sd = shaped_owner.get_or_null(p_shaped);
- ERR_FAIL_COND(!sd);
+ ERR_FAIL_NULL(sd);
ERR_FAIL_INDEX(p_index, sd->spans.size());
ShapedTextDataAdvanced::Span &span = sd->spans.ptrw()[p_index];
@@ -4024,7 +4046,7 @@ void TextServerAdvanced::_shaped_set_span_update_font(const RID &p_shaped, int64
bool TextServerAdvanced::_shaped_text_add_string(const RID &p_shaped, const String &p_text, const TypedArray<RID> &p_fonts, int64_t p_size, const Dictionary &p_opentype_features, const String &p_language, const Variant &p_meta) {
ShapedTextDataAdvanced *sd = shaped_owner.get_or_null(p_shaped);
- ERR_FAIL_COND_V(!sd, false);
+ ERR_FAIL_NULL_V(sd, false);
ERR_FAIL_COND_V(p_size <= 0, false);
MutexLock lock(sd->mutex);
@@ -4060,7 +4082,7 @@ bool TextServerAdvanced::_shaped_text_add_string(const RID &p_shaped, const Stri
bool TextServerAdvanced::_shaped_text_add_object(const RID &p_shaped, const Variant &p_key, const Size2 &p_size, InlineAlignment p_inline_align, int64_t p_length, double p_baseline) {
_THREAD_SAFE_METHOD_
ShapedTextDataAdvanced *sd = shaped_owner.get_or_null(p_shaped);
- ERR_FAIL_COND_V(!sd, false);
+ ERR_FAIL_NULL_V(sd, false);
ERR_FAIL_COND_V(p_key == Variant(), false);
ERR_FAIL_COND_V(sd->objects.has(p_key), false);
@@ -4090,7 +4112,7 @@ bool TextServerAdvanced::_shaped_text_add_object(const RID &p_shaped, const Vari
bool TextServerAdvanced::_shaped_text_resize_object(const RID &p_shaped, const Variant &p_key, const Size2 &p_size, InlineAlignment p_inline_align, double p_baseline) {
ShapedTextDataAdvanced *sd = shaped_owner.get_or_null(p_shaped);
- ERR_FAIL_COND_V(!sd, false);
+ ERR_FAIL_NULL_V(sd, false);
MutexLock lock(sd->mutex);
ERR_FAIL_COND_V(!sd->objects.has(p_key), false);
@@ -4130,8 +4152,8 @@ bool TextServerAdvanced::_shaped_text_resize_object(const RID &p_shaped, const V
} else {
if (gl.font_rid.is_valid()) {
if (sd->orientation == ORIENTATION_HORIZONTAL) {
- sd->ascent = MAX(sd->ascent, MAX(_font_get_ascent(gl.font_rid, gl.font_size), -gl.y_off));
- sd->descent = MAX(sd->descent, MAX(_font_get_descent(gl.font_rid, gl.font_size), gl.y_off));
+ sd->ascent = MAX(sd->ascent, MAX(_font_get_ascent(gl.font_rid, gl.font_size) + _font_get_spacing(gl.font_rid, SPACING_TOP), -gl.y_off));
+ sd->descent = MAX(sd->descent, MAX(_font_get_descent(gl.font_rid, gl.font_size) + _font_get_spacing(gl.font_rid, SPACING_BOTTOM), gl.y_off));
} else {
sd->ascent = MAX(sd->ascent, Math::round(_font_get_glyph_advance(gl.font_rid, gl.font_size, gl.index).x * 0.5));
sd->descent = MAX(sd->descent, Math::round(_font_get_glyph_advance(gl.font_rid, gl.font_size, gl.index).x * 0.5));
@@ -4233,7 +4255,7 @@ void TextServerAdvanced::_realign(ShapedTextDataAdvanced *p_sd) const {
RID TextServerAdvanced::_shaped_text_substr(const RID &p_shaped, int64_t p_start, int64_t p_length) const {
_THREAD_SAFE_METHOD_
const ShapedTextDataAdvanced *sd = shaped_owner.get_or_null(p_shaped);
- ERR_FAIL_COND_V(!sd, RID());
+ ERR_FAIL_NULL_V(sd, RID());
MutexLock lock(sd->mutex);
if (sd->parent != RID()) {
@@ -4385,8 +4407,8 @@ bool TextServerAdvanced::_shape_substr(ShapedTextDataAdvanced *p_new_sd, const S
} else {
if (gl.font_rid.is_valid()) {
if (p_new_sd->orientation == ORIENTATION_HORIZONTAL) {
- p_new_sd->ascent = MAX(p_new_sd->ascent, MAX(_font_get_ascent(gl.font_rid, gl.font_size), -gl.y_off));
- p_new_sd->descent = MAX(p_new_sd->descent, MAX(_font_get_descent(gl.font_rid, gl.font_size), gl.y_off));
+ p_new_sd->ascent = MAX(p_new_sd->ascent, MAX(_font_get_ascent(gl.font_rid, gl.font_size) + _font_get_spacing(gl.font_rid, SPACING_TOP), -gl.y_off));
+ p_new_sd->descent = MAX(p_new_sd->descent, MAX(_font_get_descent(gl.font_rid, gl.font_size) + _font_get_spacing(gl.font_rid, SPACING_BOTTOM), gl.y_off));
} else {
p_new_sd->ascent = MAX(p_new_sd->ascent, Math::round(_font_get_glyph_advance(gl.font_rid, gl.font_size, gl.index).x * 0.5));
p_new_sd->descent = MAX(p_new_sd->descent, Math::round(_font_get_glyph_advance(gl.font_rid, gl.font_size, gl.index).x * 0.5));
@@ -4417,7 +4439,7 @@ bool TextServerAdvanced::_shape_substr(ShapedTextDataAdvanced *p_new_sd, const S
RID TextServerAdvanced::_shaped_text_get_parent(const RID &p_shaped) const {
ShapedTextDataAdvanced *sd = shaped_owner.get_or_null(p_shaped);
- ERR_FAIL_COND_V(!sd, RID());
+ ERR_FAIL_NULL_V(sd, RID());
MutexLock lock(sd->mutex);
return sd->parent;
@@ -4425,7 +4447,7 @@ RID TextServerAdvanced::_shaped_text_get_parent(const RID &p_shaped) const {
double TextServerAdvanced::_shaped_text_fit_to_width(const RID &p_shaped, double p_width, BitField<TextServer::JustificationFlag> p_jst_flags) {
ShapedTextDataAdvanced *sd = shaped_owner.get_or_null(p_shaped);
- ERR_FAIL_COND_V(!sd, 0.0);
+ ERR_FAIL_NULL_V(sd, 0.0);
MutexLock lock(sd->mutex);
if (!sd->valid) {
@@ -4582,7 +4604,7 @@ double TextServerAdvanced::_shaped_text_fit_to_width(const RID &p_shaped, double
double TextServerAdvanced::_shaped_text_tab_align(const RID &p_shaped, const PackedFloat32Array &p_tab_stops) {
ShapedTextDataAdvanced *sd = shaped_owner.get_or_null(p_shaped);
- ERR_FAIL_COND_V(!sd, 0.0);
+ ERR_FAIL_NULL_V(sd, 0.0);
MutexLock lock(sd->mutex);
if (!sd->valid) {
@@ -4638,7 +4660,7 @@ double TextServerAdvanced::_shaped_text_tab_align(const RID &p_shaped, const Pac
void TextServerAdvanced::_shaped_text_overrun_trim_to_width(const RID &p_shaped_line, double p_width, BitField<TextServer::TextOverrunFlag> p_trim_flags) {
ShapedTextDataAdvanced *sd = shaped_owner.get_or_null(p_shaped_line);
- ERR_FAIL_COND_MSG(!sd, "ShapedTextDataAdvanced invalid.");
+ ERR_FAIL_NULL_MSG(sd, "ShapedTextDataAdvanced invalid.");
MutexLock lock(sd->mutex);
if (!sd->valid) {
@@ -4708,7 +4730,7 @@ void TextServerAdvanced::_shaped_text_overrun_trim_to_width(const RID &p_shaped_
int ellipsis_width = 0;
if (add_ellipsis && whitespace_gl_font_rid.is_valid()) {
- ellipsis_width = 3 * dot_adv.x + sd->extra_spacing[SPACING_GLYPH] + (cut_per_word ? whitespace_adv.x : 0);
+ ellipsis_width = 3 * dot_adv.x + sd->extra_spacing[SPACING_GLYPH] + _font_get_spacing(dot_gl_font_rid, SPACING_GLYPH) + (cut_per_word ? whitespace_adv.x : 0);
}
int ell_min_characters = 6;
@@ -4771,7 +4793,7 @@ void TextServerAdvanced::_shaped_text_overrun_trim_to_width(const RID &p_shaped_
if ((trim_pos >= 0 && sd->width > p_width) || enforce_ellipsis) {
if (add_ellipsis && (ellipsis_pos > 0 || enforce_ellipsis)) {
- // Insert an additional space when cutting word bound for aesthetics.
+ // Insert an additional space when cutting word bound for esthetics.
if (cut_per_word && (ellipsis_pos > 0)) {
Glyph gl;
gl.count = 1;
@@ -4805,7 +4827,7 @@ void TextServerAdvanced::_shaped_text_overrun_trim_to_width(const RID &p_shaped_
int64_t TextServerAdvanced::_shaped_text_get_trim_pos(const RID &p_shaped) const {
ShapedTextDataAdvanced *sd = shaped_owner.get_or_null(p_shaped);
- ERR_FAIL_COND_V_MSG(!sd, -1, "ShapedTextDataAdvanced invalid.");
+ ERR_FAIL_NULL_V_MSG(sd, -1, "ShapedTextDataAdvanced invalid.");
MutexLock lock(sd->mutex);
return sd->overrun_trim_data.trim_pos;
@@ -4813,7 +4835,7 @@ int64_t TextServerAdvanced::_shaped_text_get_trim_pos(const RID &p_shaped) const
int64_t TextServerAdvanced::_shaped_text_get_ellipsis_pos(const RID &p_shaped) const {
ShapedTextDataAdvanced *sd = shaped_owner.get_or_null(p_shaped);
- ERR_FAIL_COND_V_MSG(!sd, -1, "ShapedTextDataAdvanced invalid.");
+ ERR_FAIL_NULL_V_MSG(sd, -1, "ShapedTextDataAdvanced invalid.");
MutexLock lock(sd->mutex);
return sd->overrun_trim_data.ellipsis_pos;
@@ -4821,7 +4843,7 @@ int64_t TextServerAdvanced::_shaped_text_get_ellipsis_pos(const RID &p_shaped) c
const Glyph *TextServerAdvanced::_shaped_text_get_ellipsis_glyphs(const RID &p_shaped) const {
ShapedTextDataAdvanced *sd = shaped_owner.get_or_null(p_shaped);
- ERR_FAIL_COND_V_MSG(!sd, nullptr, "ShapedTextDataAdvanced invalid.");
+ ERR_FAIL_NULL_V_MSG(sd, nullptr, "ShapedTextDataAdvanced invalid.");
MutexLock lock(sd->mutex);
return sd->overrun_trim_data.ellipsis_glyph_buf.ptr();
@@ -4829,15 +4851,84 @@ const Glyph *TextServerAdvanced::_shaped_text_get_ellipsis_glyphs(const RID &p_s
int64_t TextServerAdvanced::_shaped_text_get_ellipsis_glyph_count(const RID &p_shaped) const {
ShapedTextDataAdvanced *sd = shaped_owner.get_or_null(p_shaped);
- ERR_FAIL_COND_V_MSG(!sd, 0, "ShapedTextDataAdvanced invalid.");
+ ERR_FAIL_NULL_V_MSG(sd, 0, "ShapedTextDataAdvanced invalid.");
MutexLock lock(sd->mutex);
return sd->overrun_trim_data.ellipsis_glyph_buf.size();
}
+void TextServerAdvanced::_update_chars(ShapedTextDataAdvanced *p_sd) const {
+ if (!p_sd->chars_valid) {
+ p_sd->chars.clear();
+
+ const UChar *data = p_sd->utf16.get_data();
+ UErrorCode err = U_ZERO_ERROR;
+ int prev = -1;
+ int i = 0;
+
+ Vector<ShapedTextDataAdvanced::Span> &spans = p_sd->spans;
+ if (p_sd->parent != RID()) {
+ ShapedTextDataAdvanced *parent_sd = shaped_owner.get_or_null(p_sd->parent);
+ ERR_FAIL_COND(!parent_sd->valid);
+ spans = parent_sd->spans;
+ }
+
+ while (i < spans.size()) {
+ if (spans[i].start > p_sd->end) {
+ break;
+ }
+ if (spans[i].end < p_sd->start) {
+ i++;
+ continue;
+ }
+
+ int r_start = MAX(0, spans[i].start - p_sd->start);
+ String language = spans[i].language;
+ while (i + 1 < spans.size() && language == spans[i + 1].language) {
+ i++;
+ }
+ int r_end = MIN(spans[i].end - p_sd->start, p_sd->text.length());
+ UBreakIterator *bi = ubrk_open(UBRK_CHARACTER, (language.is_empty()) ? TranslationServer::get_singleton()->get_tool_locale().ascii().get_data() : language.ascii().get_data(), data + _convert_pos_inv(p_sd, r_start), _convert_pos_inv(p_sd, r_end - r_start), &err);
+ if (U_SUCCESS(err)) {
+ while (ubrk_next(bi) != UBRK_DONE) {
+ int pos = _convert_pos(p_sd, ubrk_current(bi)) + r_start + p_sd->start;
+ if (prev != pos) {
+ p_sd->chars.push_back(pos);
+ }
+ prev = pos;
+ }
+ ubrk_close(bi);
+ } else {
+ for (int j = r_start; j < r_end; j++) {
+ if (prev != j) {
+ p_sd->chars.push_back(j + 1 + p_sd->start);
+ }
+ prev = j;
+ }
+ }
+ i++;
+ }
+ p_sd->chars_valid = true;
+ }
+}
+
+PackedInt32Array TextServerAdvanced::_shaped_text_get_character_breaks(const RID &p_shaped) const {
+ ShapedTextDataAdvanced *sd = shaped_owner.get_or_null(p_shaped);
+ ERR_FAIL_NULL_V(sd, PackedInt32Array());
+
+ MutexLock lock(sd->mutex);
+ if (!sd->valid) {
+ const_cast<TextServerAdvanced *>(this)->_shaped_text_shape(p_shaped);
+ }
+
+ _update_chars(sd);
+
+ return sd->chars;
+}
+
bool TextServerAdvanced::_shaped_text_update_breaks(const RID &p_shaped) {
ShapedTextDataAdvanced *sd = shaped_owner.get_or_null(p_shaped);
- ERR_FAIL_COND_V(!sd, false);
+ ERR_FAIL_NULL_V(sd, false);
MutexLock lock(sd->mutex);
if (!sd->valid) {
@@ -5102,7 +5193,7 @@ _FORCE_INLINE_ int64_t _generate_kashida_justification_opportunies(const String
bool TextServerAdvanced::_shaped_text_update_justification_ops(const RID &p_shaped) {
ShapedTextDataAdvanced *sd = shaped_owner.get_or_null(p_shaped);
- ERR_FAIL_COND_V(!sd, false);
+ ERR_FAIL_NULL_V(sd, false);
MutexLock lock(sd->mutex);
if (!sd->valid) {
@@ -5256,7 +5347,7 @@ Glyph TextServerAdvanced::_shape_single_glyph(ShapedTextDataAdvanced *p_sd, char
hb_font_t *hb_font = _font_get_hb_handle(p_font, p_font_size);
double scale = _font_get_scale(p_font, p_font_size);
bool subpos = (scale != 1.0) || (_font_get_subpixel_positioning(p_font) == SUBPIXEL_POSITIONING_ONE_HALF) || (_font_get_subpixel_positioning(p_font) == SUBPIXEL_POSITIONING_ONE_QUARTER) || (_font_get_subpixel_positioning(p_font) == SUBPIXEL_POSITIONING_AUTO && p_font_size <= SUBPIXEL_POSITIONING_ONE_HALF_MAX_SIZE);
- ERR_FAIL_COND_V(hb_font == nullptr, Glyph());
+ ERR_FAIL_NULL_V(hb_font, Glyph());
hb_buffer_clear_contents(p_sd->hb_buffer);
hb_buffer_set_direction(p_sd->hb_buffer, p_direction);
@@ -5338,7 +5429,17 @@ void TextServerAdvanced::_shape_run(ShapedTextDataAdvanced *p_sd, int64_t p_star
// Try system fallback.
RID fdef = p_fonts[0];
if (_font_is_allow_system_fallback(fdef)) {
- String text = p_sd->text.substr(p_start, 1);
+ _update_chars(p_sd);
+
+ int64_t next = p_end;
+ for (const int32_t &E : p_sd->chars) {
+ if (E > p_start) {
+ next = E;
+ break;
+ }
+ }
+ String text = p_sd->text.substr(p_start, next - p_start);
+
String font_name = _font_get_name(fdef);
BitField<FontStyle> font_style = _font_get_style(fdef);
int font_weight = _font_get_weight(fdef);
@@ -5481,6 +5582,10 @@ void TextServerAdvanced::_shape_run(ShapedTextDataAdvanced *p_sd, int64_t p_star
_font_set_oversampling(sysf.rid, key.oversampling);
_font_set_embolden(sysf.rid, key.embolden);
_font_set_transform(sysf.rid, key.transform);
+ _font_set_spacing(sysf.rid, SPACING_TOP, key.extra_spacing[SPACING_TOP]);
+ _font_set_spacing(sysf.rid, SPACING_BOTTOM, key.extra_spacing[SPACING_BOTTOM]);
+ _font_set_spacing(sysf.rid, SPACING_SPACE, key.extra_spacing[SPACING_SPACE]);
+ _font_set_spacing(sysf.rid, SPACING_GLYPH, key.extra_spacing[SPACING_GLYPH]);
if (system_fonts.has(key)) {
system_fonts[key].var.push_back(sysf);
@@ -5529,18 +5634,18 @@ void TextServerAdvanced::_shape_run(ShapedTextDataAdvanced *p_sd, int64_t p_star
}
FontAdvanced *fd = font_owner.get_or_null(f);
- ERR_FAIL_COND(!fd);
+ ERR_FAIL_NULL(fd);
MutexLock lock(fd->mutex);
Vector2i fss = _get_size(fd, fs);
hb_font_t *hb_font = _font_get_hb_handle(f, fs);
double scale = _font_get_scale(f, fs);
- double sp_sp = p_sd->extra_spacing[SPACING_SPACE];
- double sp_gl = p_sd->extra_spacing[SPACING_GLYPH];
+ double sp_sp = p_sd->extra_spacing[SPACING_SPACE] + _font_get_spacing(f, SPACING_SPACE);
+ double sp_gl = p_sd->extra_spacing[SPACING_GLYPH] + _font_get_spacing(f, SPACING_GLYPH);
bool last_run = (p_sd->end == p_end);
double ea = _get_extra_advance(f, fs);
bool subpos = (scale != 1.0) || (_font_get_subpixel_positioning(f) == SUBPIXEL_POSITIONING_ONE_HALF) || (_font_get_subpixel_positioning(f) == SUBPIXEL_POSITIONING_ONE_QUARTER) || (_font_get_subpixel_positioning(f) == SUBPIXEL_POSITIONING_AUTO && fs <= SUBPIXEL_POSITIONING_ONE_HALF_MAX_SIZE);
- ERR_FAIL_COND(hb_font == nullptr);
+ ERR_FAIL_NULL(hb_font);
hb_buffer_clear_contents(p_sd->hb_buffer);
hb_buffer_set_direction(p_sd->hb_buffer, p_direction);
@@ -5721,8 +5826,8 @@ void TextServerAdvanced::_shape_run(ShapedTextDataAdvanced *p_sd, int64_t p_star
if (failed_subrun_start != p_end + 1) {
_shape_run(p_sd, failed_subrun_start, failed_subrun_end, p_script, p_direction, p_fonts, p_span, p_fb_index + 1, p_start, p_end);
}
- p_sd->ascent = MAX(p_sd->ascent, _font_get_ascent(f, fs));
- p_sd->descent = MAX(p_sd->descent, _font_get_descent(f, fs));
+ p_sd->ascent = MAX(p_sd->ascent, _font_get_ascent(f, fs) + _font_get_spacing(f, SPACING_TOP));
+ p_sd->descent = MAX(p_sd->descent, _font_get_descent(f, fs) + _font_get_spacing(f, SPACING_BOTTOM));
p_sd->upos = MAX(p_sd->upos, _font_get_underline_position(f, fs));
p_sd->uthk = MAX(p_sd->uthk, _font_get_underline_thickness(f, fs));
}
@@ -5731,7 +5836,7 @@ void TextServerAdvanced::_shape_run(ShapedTextDataAdvanced *p_sd, int64_t p_star
bool TextServerAdvanced::_shaped_text_shape(const RID &p_shaped) {
_THREAD_SAFE_METHOD_
ShapedTextDataAdvanced *sd = shaped_owner.get_or_null(p_shaped);
- ERR_FAIL_COND_V(!sd, false);
+ ERR_FAIL_NULL_V(sd, false);
MutexLock lock(sd->mutex);
if (sd->valid) {
@@ -5777,8 +5882,11 @@ bool TextServerAdvanced::_shaped_text_shape(const RID &p_shaped) {
sd->para_direction = (direction == UBIDI_RTL) ? DIRECTION_RTL : DIRECTION_LTR;
sd->base_para_direction = direction;
} else {
- sd->para_direction = DIRECTION_LTR;
- sd->base_para_direction = UBIDI_DEFAULT_LTR;
+ const String &lang = (sd->spans.is_empty() || sd->spans[0].language.is_empty()) ? TranslationServer::get_singleton()->get_tool_locale() : sd->spans[0].language;
+ bool lang_rtl = _is_locale_right_to_left(lang);
+
+ sd->para_direction = lang_rtl ? DIRECTION_RTL : DIRECTION_LTR;
+ sd->base_para_direction = lang_rtl ? UBIDI_DEFAULT_RTL : UBIDI_DEFAULT_LTR;
}
} break;
}
@@ -5944,7 +6052,7 @@ bool TextServerAdvanced::_shaped_text_shape(const RID &p_shaped) {
bool TextServerAdvanced::_shaped_text_is_ready(const RID &p_shaped) const {
const ShapedTextDataAdvanced *sd = shaped_owner.get_or_null(p_shaped);
- ERR_FAIL_COND_V(!sd, false);
+ ERR_FAIL_NULL_V(sd, false);
MutexLock lock(sd->mutex);
return sd->valid;
@@ -5952,7 +6060,7 @@ bool TextServerAdvanced::_shaped_text_is_ready(const RID &p_shaped) const {
const Glyph *TextServerAdvanced::_shaped_text_get_glyphs(const RID &p_shaped) const {
const ShapedTextDataAdvanced *sd = shaped_owner.get_or_null(p_shaped);
- ERR_FAIL_COND_V(!sd, nullptr);
+ ERR_FAIL_NULL_V(sd, nullptr);
MutexLock lock(sd->mutex);
if (!sd->valid) {
@@ -5963,7 +6071,7 @@ const Glyph *TextServerAdvanced::_shaped_text_get_glyphs(const RID &p_shaped) co
int64_t TextServerAdvanced::_shaped_text_get_glyph_count(const RID &p_shaped) const {
const ShapedTextDataAdvanced *sd = shaped_owner.get_or_null(p_shaped);
- ERR_FAIL_COND_V(!sd, 0);
+ ERR_FAIL_NULL_V(sd, 0);
MutexLock lock(sd->mutex);
if (!sd->valid) {
@@ -5974,7 +6082,7 @@ int64_t TextServerAdvanced::_shaped_text_get_glyph_count(const RID &p_shaped) co
const Glyph *TextServerAdvanced::_shaped_text_sort_logical(const RID &p_shaped) {
ShapedTextDataAdvanced *sd = shaped_owner.get_or_null(p_shaped);
- ERR_FAIL_COND_V(!sd, nullptr);
+ ERR_FAIL_NULL_V(sd, nullptr);
MutexLock lock(sd->mutex);
if (!sd->valid) {
@@ -5992,7 +6100,7 @@ const Glyph *TextServerAdvanced::_shaped_text_sort_logical(const RID &p_shaped)
Vector2i TextServerAdvanced::_shaped_text_get_range(const RID &p_shaped) const {
const ShapedTextDataAdvanced *sd = shaped_owner.get_or_null(p_shaped);
- ERR_FAIL_COND_V(!sd, Vector2i());
+ ERR_FAIL_NULL_V(sd, Vector2i());
MutexLock lock(sd->mutex);
return Vector2(sd->start, sd->end);
@@ -6001,7 +6109,7 @@ Vector2i TextServerAdvanced::_shaped_text_get_range(const RID &p_shaped) const {
Array TextServerAdvanced::_shaped_text_get_objects(const RID &p_shaped) const {
Array ret;
const ShapedTextDataAdvanced *sd = shaped_owner.get_or_null(p_shaped);
- ERR_FAIL_COND_V(!sd, ret);
+ ERR_FAIL_NULL_V(sd, ret);
MutexLock lock(sd->mutex);
for (const KeyValue<Variant, ShapedTextDataAdvanced::EmbeddedObject> &E : sd->objects) {
@@ -6013,7 +6121,7 @@ Array TextServerAdvanced::_shaped_text_get_objects(const RID &p_shaped) const {
Rect2 TextServerAdvanced::_shaped_text_get_object_rect(const RID &p_shaped, const Variant &p_key) const {
const ShapedTextDataAdvanced *sd = shaped_owner.get_or_null(p_shaped);
- ERR_FAIL_COND_V(!sd, Rect2());
+ ERR_FAIL_NULL_V(sd, Rect2());
MutexLock lock(sd->mutex);
ERR_FAIL_COND_V(!sd->objects.has(p_key), Rect2());
@@ -6025,7 +6133,7 @@ Rect2 TextServerAdvanced::_shaped_text_get_object_rect(const RID &p_shaped, cons
Size2 TextServerAdvanced::_shaped_text_get_size(const RID &p_shaped) const {
const ShapedTextDataAdvanced *sd = shaped_owner.get_or_null(p_shaped);
- ERR_FAIL_COND_V(!sd, Size2());
+ ERR_FAIL_NULL_V(sd, Size2());
MutexLock lock(sd->mutex);
if (!sd->valid) {
@@ -6040,7 +6148,7 @@ Size2 TextServerAdvanced::_shaped_text_get_size(const RID &p_shaped) const {
double TextServerAdvanced::_shaped_text_get_ascent(const RID &p_shaped) const {
const ShapedTextDataAdvanced *sd = shaped_owner.get_or_null(p_shaped);
- ERR_FAIL_COND_V(!sd, 0.0);
+ ERR_FAIL_NULL_V(sd, 0.0);
MutexLock lock(sd->mutex);
if (!sd->valid) {
@@ -6051,7 +6159,7 @@ double TextServerAdvanced::_shaped_text_get_ascent(const RID &p_shaped) const {
double TextServerAdvanced::_shaped_text_get_descent(const RID &p_shaped) const {
const ShapedTextDataAdvanced *sd = shaped_owner.get_or_null(p_shaped);
- ERR_FAIL_COND_V(!sd, 0.0);
+ ERR_FAIL_NULL_V(sd, 0.0);
MutexLock lock(sd->mutex);
if (!sd->valid) {
@@ -6062,7 +6170,7 @@ double TextServerAdvanced::_shaped_text_get_descent(const RID &p_shaped) const {
double TextServerAdvanced::_shaped_text_get_width(const RID &p_shaped) const {
const ShapedTextDataAdvanced *sd = shaped_owner.get_or_null(p_shaped);
- ERR_FAIL_COND_V(!sd, 0.0);
+ ERR_FAIL_NULL_V(sd, 0.0);
MutexLock lock(sd->mutex);
if (!sd->valid) {
@@ -6073,7 +6181,7 @@ double TextServerAdvanced::_shaped_text_get_width(const RID &p_shaped) const {
double TextServerAdvanced::_shaped_text_get_underline_position(const RID &p_shaped) const {
const ShapedTextDataAdvanced *sd = shaped_owner.get_or_null(p_shaped);
- ERR_FAIL_COND_V(!sd, 0.0);
+ ERR_FAIL_NULL_V(sd, 0.0);
MutexLock lock(sd->mutex);
if (!sd->valid) {
@@ -6085,7 +6193,7 @@ double TextServerAdvanced::_shaped_text_get_underline_position(const RID &p_shap
double TextServerAdvanced::_shaped_text_get_underline_thickness(const RID &p_shaped) const {
const ShapedTextDataAdvanced *sd = shaped_owner.get_or_null(p_shaped);
- ERR_FAIL_COND_V(!sd, 0.0);
+ ERR_FAIL_NULL_V(sd, 0.0);
MutexLock lock(sd->mutex);
if (!sd->valid) {
@@ -6602,6 +6710,30 @@ PackedInt32Array TextServerAdvanced::_string_get_word_breaks(const String &p_str
return ret;
}
+PackedInt32Array TextServerAdvanced::_string_get_character_breaks(const String &p_string, const String &p_language) const {
+ const String lang = (p_language.is_empty()) ? TranslationServer::get_singleton()->get_tool_locale() : p_language;
+ // Convert to UTF-16.
+ Char16String utf16 = p_string.utf16();
+
+ PackedInt32Array ret;
+
+ UErrorCode err = U_ZERO_ERROR;
+ UBreakIterator *bi = ubrk_open(UBRK_CHARACTER, lang.ascii().get_data(), (const UChar *)utf16.get_data(), utf16.length(), &err);
+ if (U_SUCCESS(err)) {
+ while (ubrk_next(bi) != UBRK_DONE) {
+ int pos = _convert_pos(p_string, utf16, ubrk_current(bi));
+ ret.push_back(pos);
+ }
+ ubrk_close(bi);
+ } else {
+ for (int i = 0; i <= p_string.size(); i++) {
+ ret.push_back(i);
+ }
+ }
+
+ return ret;
+}
+
bool TextServerAdvanced::_is_valid_identifier(const String &p_string) const {
#ifndef ICU_STATIC_DATA
if (!icu_data_loaded) {