diff options
Diffstat (limited to 'modules/text_server_fb/text_server_fb.cpp')
-rw-r--r-- | modules/text_server_fb/text_server_fb.cpp | 671 |
1 files changed, 407 insertions, 264 deletions
diff --git a/modules/text_server_fb/text_server_fb.cpp b/modules/text_server_fb/text_server_fb.cpp index d346f54827..f12275d10c 100644 --- a/modules/text_server_fb/text_server_fb.cpp +++ b/modules/text_server_fb/text_server_fb.cpp @@ -123,6 +123,14 @@ void TextServerFallback::_free_rid(const RID &p_rid) { font_owner.free(p_rid); } memdelete(fd); + } else if (font_var_owner.owns(p_rid)) { + MutexLock ftlock(ft_mutex); + + FontFallbackLinkedVariation *fdv = font_var_owner.get_or_null(p_rid); + { + font_var_owner.free(p_rid); + } + memdelete(fdv); } else if (shaped_owner.owns(p_rid)) { ShapedTextDataFallback *sd = shaped_owner.get_or_null(p_rid); { @@ -935,9 +943,25 @@ RID TextServerFallback::_create_font() { return font_owner.make_rid(fd); } +RID TextServerFallback::_create_font_linked_variation(const RID &p_font_rid) { + _THREAD_SAFE_METHOD_ + + RID rid = p_font_rid; + FontFallbackLinkedVariation *fdv = font_var_owner.get_or_null(rid); + if (unlikely(fdv)) { + rid = fdv->base_font; + } + ERR_FAIL_COND_V(!font_owner.owns(rid), RID()); + + FontFallbackLinkedVariation *new_fdv = memnew(FontFallbackLinkedVariation); + new_fdv->base_font = rid; + + return font_var_owner.make_rid(new_fdv); +} + void TextServerFallback::_font_set_data(const RID &p_font_rid, const PackedByteArray &p_data) { - FontFallback *fd = font_owner.get_or_null(p_font_rid); - ERR_FAIL_COND(!fd); + FontFallback *fd = _get_font_data(p_font_rid); + ERR_FAIL_NULL(fd); MutexLock lock(fd->mutex); _font_clear_cache(fd); @@ -947,8 +971,8 @@ void TextServerFallback::_font_set_data(const RID &p_font_rid, const PackedByteA } void TextServerFallback::_font_set_data_ptr(const RID &p_font_rid, const uint8_t *p_data_ptr, int64_t p_data_size) { - FontFallback *fd = font_owner.get_or_null(p_font_rid); - ERR_FAIL_COND(!fd); + FontFallback *fd = _get_font_data(p_font_rid); + ERR_FAIL_NULL(fd); MutexLock lock(fd->mutex); _font_clear_cache(fd); @@ -958,8 +982,8 @@ void TextServerFallback::_font_set_data_ptr(const RID &p_font_rid, const uint8_t } void TextServerFallback::_font_set_style(const RID &p_font_rid, BitField<FontStyle> p_style) { - FontFallback *fd = font_owner.get_or_null(p_font_rid); - ERR_FAIL_COND(!fd); + FontFallback *fd = _get_font_data(p_font_rid); + ERR_FAIL_NULL(fd); MutexLock lock(fd->mutex); Vector2i size = _get_size(fd, 16); @@ -971,8 +995,8 @@ void TextServerFallback::_font_set_face_index(const RID &p_font_rid, int64_t p_f ERR_FAIL_COND(p_face_index < 0); ERR_FAIL_COND(p_face_index >= 0x7FFF); - FontFallback *fd = font_owner.get_or_null(p_font_rid); - ERR_FAIL_COND(!fd); + FontFallback *fd = _get_font_data(p_font_rid); + ERR_FAIL_NULL(fd); MutexLock lock(fd->mutex); if (fd->face_index != p_face_index) { @@ -982,16 +1006,16 @@ void TextServerFallback::_font_set_face_index(const RID &p_font_rid, int64_t p_f } int64_t TextServerFallback::_font_get_face_index(const RID &p_font_rid) const { - FontFallback *fd = font_owner.get_or_null(p_font_rid); - ERR_FAIL_COND_V(!fd, 0); + FontFallback *fd = _get_font_data(p_font_rid); + ERR_FAIL_NULL_V(fd, 0); MutexLock lock(fd->mutex); return fd->face_index; } int64_t TextServerFallback::_font_get_face_count(const RID &p_font_rid) const { - FontFallback *fd = font_owner.get_or_null(p_font_rid); - ERR_FAIL_COND_V(!fd, 0); + FontFallback *fd = _get_font_data(p_font_rid); + ERR_FAIL_NULL_V(fd, 0); MutexLock lock(fd->mutex); int face_count = 0; @@ -1036,8 +1060,8 @@ int64_t TextServerFallback::_font_get_face_count(const RID &p_font_rid) const { } BitField<TextServer::FontStyle> TextServerFallback::_font_get_style(const RID &p_font_rid) const { - FontFallback *fd = font_owner.get_or_null(p_font_rid); - ERR_FAIL_COND_V(!fd, 0); + FontFallback *fd = _get_font_data(p_font_rid); + ERR_FAIL_NULL_V(fd, 0); MutexLock lock(fd->mutex); Vector2i size = _get_size(fd, 16); @@ -1046,8 +1070,8 @@ BitField<TextServer::FontStyle> TextServerFallback::_font_get_style(const RID &p } void TextServerFallback::_font_set_style_name(const RID &p_font_rid, const String &p_name) { - FontFallback *fd = font_owner.get_or_null(p_font_rid); - ERR_FAIL_COND(!fd); + FontFallback *fd = _get_font_data(p_font_rid); + ERR_FAIL_NULL(fd); MutexLock lock(fd->mutex); Vector2i size = _get_size(fd, 16); @@ -1056,8 +1080,8 @@ void TextServerFallback::_font_set_style_name(const RID &p_font_rid, const Strin } String TextServerFallback::_font_get_style_name(const RID &p_font_rid) const { - FontFallback *fd = font_owner.get_or_null(p_font_rid); - ERR_FAIL_COND_V(!fd, String()); + FontFallback *fd = _get_font_data(p_font_rid); + ERR_FAIL_NULL_V(fd, String()); MutexLock lock(fd->mutex); Vector2i size = _get_size(fd, 16); @@ -1066,8 +1090,8 @@ String TextServerFallback::_font_get_style_name(const RID &p_font_rid) const { } void TextServerFallback::_font_set_weight(const RID &p_font_rid, int64_t p_weight) { - FontFallback *fd = font_owner.get_or_null(p_font_rid); - ERR_FAIL_COND(!fd); + FontFallback *fd = _get_font_data(p_font_rid); + ERR_FAIL_NULL(fd); MutexLock lock(fd->mutex); Vector2i size = _get_size(fd, 16); @@ -1076,8 +1100,8 @@ void TextServerFallback::_font_set_weight(const RID &p_font_rid, int64_t p_weigh } int64_t TextServerFallback::_font_get_weight(const RID &p_font_rid) const { - FontFallback *fd = font_owner.get_or_null(p_font_rid); - ERR_FAIL_COND_V(!fd, 400); + FontFallback *fd = _get_font_data(p_font_rid); + ERR_FAIL_NULL_V(fd, 400); MutexLock lock(fd->mutex); Vector2i size = _get_size(fd, 16); @@ -1086,8 +1110,8 @@ int64_t TextServerFallback::_font_get_weight(const RID &p_font_rid) const { } void TextServerFallback::_font_set_stretch(const RID &p_font_rid, int64_t p_stretch) { - FontFallback *fd = font_owner.get_or_null(p_font_rid); - ERR_FAIL_COND(!fd); + FontFallback *fd = _get_font_data(p_font_rid); + ERR_FAIL_NULL(fd); MutexLock lock(fd->mutex); Vector2i size = _get_size(fd, 16); @@ -1096,8 +1120,8 @@ void TextServerFallback::_font_set_stretch(const RID &p_font_rid, int64_t p_stre } int64_t TextServerFallback::_font_get_stretch(const RID &p_font_rid) const { - FontFallback *fd = font_owner.get_or_null(p_font_rid); - ERR_FAIL_COND_V(!fd, 100); + FontFallback *fd = _get_font_data(p_font_rid); + ERR_FAIL_NULL_V(fd, 100); MutexLock lock(fd->mutex); Vector2i size = _get_size(fd, 16); @@ -1106,8 +1130,8 @@ int64_t TextServerFallback::_font_get_stretch(const RID &p_font_rid) const { } void TextServerFallback::_font_set_name(const RID &p_font_rid, const String &p_name) { - FontFallback *fd = font_owner.get_or_null(p_font_rid); - ERR_FAIL_COND(!fd); + FontFallback *fd = _get_font_data(p_font_rid); + ERR_FAIL_NULL(fd); MutexLock lock(fd->mutex); Vector2i size = _get_size(fd, 16); @@ -1116,8 +1140,8 @@ void TextServerFallback::_font_set_name(const RID &p_font_rid, const String &p_n } String TextServerFallback::_font_get_name(const RID &p_font_rid) const { - FontFallback *fd = font_owner.get_or_null(p_font_rid); - ERR_FAIL_COND_V(!fd, String()); + FontFallback *fd = _get_font_data(p_font_rid); + ERR_FAIL_NULL_V(fd, String()); MutexLock lock(fd->mutex); Vector2i size = _get_size(fd, 16); @@ -1126,8 +1150,8 @@ String TextServerFallback::_font_get_name(const RID &p_font_rid) const { } void TextServerFallback::_font_set_antialiasing(const RID &p_font_rid, TextServer::FontAntialiasing p_antialiasing) { - FontFallback *fd = font_owner.get_or_null(p_font_rid); - ERR_FAIL_COND(!fd); + FontFallback *fd = _get_font_data(p_font_rid); + ERR_FAIL_NULL(fd); MutexLock lock(fd->mutex); if (fd->antialiasing != p_antialiasing) { @@ -1137,16 +1161,16 @@ void TextServerFallback::_font_set_antialiasing(const RID &p_font_rid, TextServe } TextServer::FontAntialiasing TextServerFallback::_font_get_antialiasing(const RID &p_font_rid) const { - FontFallback *fd = font_owner.get_or_null(p_font_rid); - ERR_FAIL_COND_V(!fd, TextServer::FONT_ANTIALIASING_NONE); + FontFallback *fd = _get_font_data(p_font_rid); + ERR_FAIL_NULL_V(fd, TextServer::FONT_ANTIALIASING_NONE); MutexLock lock(fd->mutex); return fd->antialiasing; } void TextServerFallback::_font_set_generate_mipmaps(const RID &p_font_rid, bool p_generate_mipmaps) { - FontFallback *fd = font_owner.get_or_null(p_font_rid); - ERR_FAIL_COND(!fd); + FontFallback *fd = _get_font_data(p_font_rid); + ERR_FAIL_NULL(fd); MutexLock lock(fd->mutex); if (fd->mipmaps != p_generate_mipmaps) { @@ -1161,16 +1185,16 @@ void TextServerFallback::_font_set_generate_mipmaps(const RID &p_font_rid, bool } bool TextServerFallback::_font_get_generate_mipmaps(const RID &p_font_rid) const { - FontFallback *fd = font_owner.get_or_null(p_font_rid); - ERR_FAIL_COND_V(!fd, false); + FontFallback *fd = _get_font_data(p_font_rid); + ERR_FAIL_NULL_V(fd, false); MutexLock lock(fd->mutex); return fd->mipmaps; } void TextServerFallback::_font_set_multichannel_signed_distance_field(const RID &p_font_rid, bool p_msdf) { - FontFallback *fd = font_owner.get_or_null(p_font_rid); - ERR_FAIL_COND(!fd); + FontFallback *fd = _get_font_data(p_font_rid); + ERR_FAIL_NULL(fd); MutexLock lock(fd->mutex); if (fd->msdf != p_msdf) { @@ -1180,16 +1204,16 @@ void TextServerFallback::_font_set_multichannel_signed_distance_field(const RID } bool TextServerFallback::_font_is_multichannel_signed_distance_field(const RID &p_font_rid) const { - FontFallback *fd = font_owner.get_or_null(p_font_rid); - ERR_FAIL_COND_V(!fd, false); + FontFallback *fd = _get_font_data(p_font_rid); + ERR_FAIL_NULL_V(fd, false); MutexLock lock(fd->mutex); return fd->msdf; } void TextServerFallback::_font_set_msdf_pixel_range(const RID &p_font_rid, int64_t p_msdf_pixel_range) { - FontFallback *fd = font_owner.get_or_null(p_font_rid); - ERR_FAIL_COND(!fd); + FontFallback *fd = _get_font_data(p_font_rid); + ERR_FAIL_NULL(fd); MutexLock lock(fd->mutex); if (fd->msdf_range != p_msdf_pixel_range) { @@ -1199,16 +1223,16 @@ void TextServerFallback::_font_set_msdf_pixel_range(const RID &p_font_rid, int64 } int64_t TextServerFallback::_font_get_msdf_pixel_range(const RID &p_font_rid) const { - FontFallback *fd = font_owner.get_or_null(p_font_rid); - ERR_FAIL_COND_V(!fd, false); + FontFallback *fd = _get_font_data(p_font_rid); + ERR_FAIL_NULL_V(fd, false); MutexLock lock(fd->mutex); return fd->msdf_range; } void TextServerFallback::_font_set_msdf_size(const RID &p_font_rid, int64_t p_msdf_size) { - FontFallback *fd = font_owner.get_or_null(p_font_rid); - ERR_FAIL_COND(!fd); + FontFallback *fd = _get_font_data(p_font_rid); + ERR_FAIL_NULL(fd); MutexLock lock(fd->mutex); if (fd->msdf_source_size != p_msdf_size) { @@ -1218,48 +1242,64 @@ void TextServerFallback::_font_set_msdf_size(const RID &p_font_rid, int64_t p_ms } int64_t TextServerFallback::_font_get_msdf_size(const RID &p_font_rid) const { - FontFallback *fd = font_owner.get_or_null(p_font_rid); - ERR_FAIL_COND_V(!fd, false); + FontFallback *fd = _get_font_data(p_font_rid); + ERR_FAIL_NULL_V(fd, 0); MutexLock lock(fd->mutex); return fd->msdf_source_size; } void TextServerFallback::_font_set_fixed_size(const RID &p_font_rid, int64_t p_fixed_size) { - FontFallback *fd = font_owner.get_or_null(p_font_rid); - ERR_FAIL_COND(!fd); + FontFallback *fd = _get_font_data(p_font_rid); + ERR_FAIL_NULL(fd); MutexLock lock(fd->mutex); fd->fixed_size = p_fixed_size; } int64_t TextServerFallback::_font_get_fixed_size(const RID &p_font_rid) const { - FontFallback *fd = font_owner.get_or_null(p_font_rid); - ERR_FAIL_COND_V(!fd, false); + FontFallback *fd = _get_font_data(p_font_rid); + ERR_FAIL_NULL_V(fd, 0); MutexLock lock(fd->mutex); return fd->fixed_size; } +void TextServerFallback::_font_set_fixed_size_scale_mode(const RID &p_font_rid, TextServer::FixedSizeScaleMode p_fixed_size_scale_mode) { + FontFallback *fd = _get_font_data(p_font_rid); + ERR_FAIL_NULL(fd); + + MutexLock lock(fd->mutex); + fd->fixed_size_scale_mode = p_fixed_size_scale_mode; +} + +TextServer::FixedSizeScaleMode TextServerFallback::_font_get_fixed_size_scale_mode(const RID &p_font_rid) const { + FontFallback *fd = _get_font_data(p_font_rid); + ERR_FAIL_NULL_V(fd, FIXED_SIZE_SCALE_DISABLE); + + MutexLock lock(fd->mutex); + return fd->fixed_size_scale_mode; +} + void TextServerFallback::_font_set_allow_system_fallback(const RID &p_font_rid, bool p_allow_system_fallback) { - FontFallback *fd = font_owner.get_or_null(p_font_rid); - ERR_FAIL_COND(!fd); + FontFallback *fd = _get_font_data(p_font_rid); + ERR_FAIL_NULL(fd); MutexLock lock(fd->mutex); fd->allow_system_fallback = p_allow_system_fallback; } bool TextServerFallback::_font_is_allow_system_fallback(const RID &p_font_rid) const { - FontFallback *fd = font_owner.get_or_null(p_font_rid); - ERR_FAIL_COND_V(!fd, false); + FontFallback *fd = _get_font_data(p_font_rid); + ERR_FAIL_NULL_V(fd, false); MutexLock lock(fd->mutex); return fd->allow_system_fallback; } void TextServerFallback::_font_set_force_autohinter(const RID &p_font_rid, bool p_force_autohinter) { - FontFallback *fd = font_owner.get_or_null(p_font_rid); - ERR_FAIL_COND(!fd); + FontFallback *fd = _get_font_data(p_font_rid); + ERR_FAIL_NULL(fd); MutexLock lock(fd->mutex); if (fd->force_autohinter != p_force_autohinter) { @@ -1269,16 +1309,16 @@ void TextServerFallback::_font_set_force_autohinter(const RID &p_font_rid, bool } bool TextServerFallback::_font_is_force_autohinter(const RID &p_font_rid) const { - FontFallback *fd = font_owner.get_or_null(p_font_rid); - ERR_FAIL_COND_V(!fd, false); + FontFallback *fd = _get_font_data(p_font_rid); + ERR_FAIL_NULL_V(fd, false); MutexLock lock(fd->mutex); return fd->force_autohinter; } void TextServerFallback::_font_set_hinting(const RID &p_font_rid, TextServer::Hinting p_hinting) { - FontFallback *fd = font_owner.get_or_null(p_font_rid); - ERR_FAIL_COND(!fd); + FontFallback *fd = _get_font_data(p_font_rid); + ERR_FAIL_NULL(fd); MutexLock lock(fd->mutex); if (fd->hinting != p_hinting) { @@ -1288,32 +1328,32 @@ void TextServerFallback::_font_set_hinting(const RID &p_font_rid, TextServer::Hi } TextServer::Hinting TextServerFallback::_font_get_hinting(const RID &p_font_rid) const { - FontFallback *fd = font_owner.get_or_null(p_font_rid); - ERR_FAIL_COND_V(!fd, HINTING_NONE); + FontFallback *fd = _get_font_data(p_font_rid); + ERR_FAIL_NULL_V(fd, HINTING_NONE); MutexLock lock(fd->mutex); return fd->hinting; } void TextServerFallback::_font_set_subpixel_positioning(const RID &p_font_rid, TextServer::SubpixelPositioning p_subpixel) { - FontFallback *fd = font_owner.get_or_null(p_font_rid); - ERR_FAIL_COND(!fd); + FontFallback *fd = _get_font_data(p_font_rid); + ERR_FAIL_NULL(fd); MutexLock lock(fd->mutex); fd->subpixel_positioning = p_subpixel; } TextServer::SubpixelPositioning TextServerFallback::_font_get_subpixel_positioning(const RID &p_font_rid) const { - FontFallback *fd = font_owner.get_or_null(p_font_rid); - ERR_FAIL_COND_V(!fd, SUBPIXEL_POSITIONING_DISABLED); + FontFallback *fd = _get_font_data(p_font_rid); + ERR_FAIL_NULL_V(fd, SUBPIXEL_POSITIONING_DISABLED); MutexLock lock(fd->mutex); return fd->subpixel_positioning; } void TextServerFallback::_font_set_embolden(const RID &p_font_rid, double p_strength) { - FontFallback *fd = font_owner.get_or_null(p_font_rid); - ERR_FAIL_COND(!fd); + FontFallback *fd = _get_font_data(p_font_rid); + ERR_FAIL_NULL(fd); MutexLock lock(fd->mutex); if (fd->embolden != p_strength) { @@ -1323,8 +1363,8 @@ void TextServerFallback::_font_set_embolden(const RID &p_font_rid, double p_stre } double TextServerFallback::_font_get_embolden(const RID &p_font_rid) const { - FontFallback *fd = font_owner.get_or_null(p_font_rid); - ERR_FAIL_COND_V(!fd, 0.0); + FontFallback *fd = _get_font_data(p_font_rid); + ERR_FAIL_NULL_V(fd, 0.0); MutexLock lock(fd->mutex); return fd->embolden; @@ -1332,29 +1372,40 @@ double TextServerFallback::_font_get_embolden(const RID &p_font_rid) const { void TextServerFallback::_font_set_spacing(const RID &p_font_rid, SpacingType p_spacing, int64_t p_value) { ERR_FAIL_INDEX((int)p_spacing, 4); - FontFallback *fd = font_owner.get_or_null(p_font_rid); - ERR_FAIL_COND(!fd); + FontFallbackLinkedVariation *fdv = font_var_owner.get_or_null(p_font_rid); + if (fdv) { + if (fdv->extra_spacing[p_spacing] != p_value) { + fdv->extra_spacing[p_spacing] = p_value; + } + } else { + FontFallback *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; + 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 TextServerFallback::_font_get_spacing(const RID &p_font_rid, SpacingType p_spacing) const { ERR_FAIL_INDEX_V((int)p_spacing, 4, 0); + FontFallbackLinkedVariation *fdv = font_var_owner.get_or_null(p_font_rid); + if (fdv) { + return fdv->extra_spacing[p_spacing]; + } else { + FontFallback *fd = font_owner.get_or_null(p_font_rid); + ERR_FAIL_NULL_V(fd, 0); - FontFallback *fd = font_owner.get_or_null(p_font_rid); - ERR_FAIL_COND_V(!fd, 0); - - MutexLock lock(fd->mutex); - return fd->extra_spacing[p_spacing]; + MutexLock lock(fd->mutex); + return fd->extra_spacing[p_spacing]; + } } void TextServerFallback::_font_set_transform(const RID &p_font_rid, const Transform2D &p_transform) { - FontFallback *fd = font_owner.get_or_null(p_font_rid); - ERR_FAIL_COND(!fd); + FontFallback *fd = _get_font_data(p_font_rid); + ERR_FAIL_NULL(fd); MutexLock lock(fd->mutex); if (fd->transform != p_transform) { @@ -1364,33 +1415,35 @@ void TextServerFallback::_font_set_transform(const RID &p_font_rid, const Transf } Transform2D TextServerFallback::_font_get_transform(const RID &p_font_rid) const { - FontFallback *fd = font_owner.get_or_null(p_font_rid); - ERR_FAIL_COND_V(!fd, Transform2D()); + FontFallback *fd = _get_font_data(p_font_rid); + ERR_FAIL_NULL_V(fd, Transform2D()); MutexLock lock(fd->mutex); return fd->transform; } void TextServerFallback::_font_set_variation_coordinates(const RID &p_font_rid, const Dictionary &p_variation_coordinates) { - FontFallback *fd = font_owner.get_or_null(p_font_rid); - ERR_FAIL_COND(!fd); + FontFallback *fd = _get_font_data(p_font_rid); + ERR_FAIL_NULL(fd); MutexLock lock(fd->mutex); - _font_clear_cache(fd); - 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.duplicate(); + } } Dictionary TextServerFallback::_font_get_variation_coordinates(const RID &p_font_rid) const { - FontFallback *fd = font_owner.get_or_null(p_font_rid); - ERR_FAIL_COND_V(!fd, Dictionary()); + FontFallback *fd = _get_font_data(p_font_rid); + ERR_FAIL_NULL_V(fd, Dictionary()); MutexLock lock(fd->mutex); return fd->variation_coordinates; } void TextServerFallback::_font_set_oversampling(const RID &p_font_rid, double p_oversampling) { - FontFallback *fd = font_owner.get_or_null(p_font_rid); - ERR_FAIL_COND(!fd); + FontFallback *fd = _get_font_data(p_font_rid); + ERR_FAIL_NULL(fd); MutexLock lock(fd->mutex); if (fd->oversampling != p_oversampling) { @@ -1400,16 +1453,16 @@ void TextServerFallback::_font_set_oversampling(const RID &p_font_rid, double p_ } double TextServerFallback::_font_get_oversampling(const RID &p_font_rid) const { - FontFallback *fd = font_owner.get_or_null(p_font_rid); - ERR_FAIL_COND_V(!fd, 0.0); + FontFallback *fd = _get_font_data(p_font_rid); + ERR_FAIL_NULL_V(fd, 0.0); MutexLock lock(fd->mutex); return fd->oversampling; } TypedArray<Vector2i> TextServerFallback::_font_get_size_cache_list(const RID &p_font_rid) const { - FontFallback *fd = font_owner.get_or_null(p_font_rid); - ERR_FAIL_COND_V(!fd, TypedArray<Vector2i>()); + FontFallback *fd = _get_font_data(p_font_rid); + ERR_FAIL_NULL_V(fd, TypedArray<Vector2i>()); MutexLock lock(fd->mutex); TypedArray<Vector2i> ret; @@ -1420,8 +1473,8 @@ TypedArray<Vector2i> TextServerFallback::_font_get_size_cache_list(const RID &p_ } void TextServerFallback::_font_clear_size_cache(const RID &p_font_rid) { - FontFallback *fd = font_owner.get_or_null(p_font_rid); - ERR_FAIL_COND(!fd); + FontFallback *fd = _get_font_data(p_font_rid); + ERR_FAIL_NULL(fd); MutexLock lock(fd->mutex); MutexLock ftlock(ft_mutex); @@ -1432,8 +1485,8 @@ void TextServerFallback::_font_clear_size_cache(const RID &p_font_rid) { } void TextServerFallback::_font_remove_size_cache(const RID &p_font_rid, const Vector2i &p_size) { - FontFallback *fd = font_owner.get_or_null(p_font_rid); - ERR_FAIL_COND(!fd); + FontFallback *fd = _get_font_data(p_font_rid); + ERR_FAIL_NULL(fd); MutexLock lock(fd->mutex); MutexLock ftlock(ft_mutex); @@ -1444,8 +1497,8 @@ void TextServerFallback::_font_remove_size_cache(const RID &p_font_rid, const Ve } void TextServerFallback::_font_set_ascent(const RID &p_font_rid, int64_t p_size, double p_ascent) { - FontFallback *fd = font_owner.get_or_null(p_font_rid); - ERR_FAIL_COND(!fd); + FontFallback *fd = _get_font_data(p_font_rid); + ERR_FAIL_NULL(fd); MutexLock lock(fd->mutex); Vector2i size = _get_size(fd, p_size); @@ -1455,8 +1508,8 @@ void TextServerFallback::_font_set_ascent(const RID &p_font_rid, int64_t p_size, } double TextServerFallback::_font_get_ascent(const RID &p_font_rid, int64_t p_size) const { - FontFallback *fd = font_owner.get_or_null(p_font_rid); - ERR_FAIL_COND_V(!fd, 0.0); + FontFallback *fd = _get_font_data(p_font_rid); + ERR_FAIL_NULL_V(fd, 0.0); MutexLock lock(fd->mutex); Vector2i size = _get_size(fd, p_size); @@ -1465,14 +1518,20 @@ double TextServerFallback::_font_get_ascent(const RID &p_font_rid, int64_t p_siz if (fd->msdf) { return fd->cache[size]->ascent * (double)p_size / (double)fd->msdf_source_size; + } else if (fd->fixed_size > 0 && fd->fixed_size_scale_mode != FIXED_SIZE_SCALE_DISABLE && size.x != p_size) { + if (fd->fixed_size_scale_mode == FIXED_SIZE_SCALE_ENABLED) { + return fd->cache[size]->ascent * (double)p_size / (double)fd->fixed_size; + } else { + return fd->cache[size]->ascent * Math::round((double)p_size / (double)fd->fixed_size); + } } else { return fd->cache[size]->ascent; } } void TextServerFallback::_font_set_descent(const RID &p_font_rid, int64_t p_size, double p_descent) { - FontFallback *fd = font_owner.get_or_null(p_font_rid); - ERR_FAIL_COND(!fd); + FontFallback *fd = _get_font_data(p_font_rid); + ERR_FAIL_NULL(fd); Vector2i size = _get_size(fd, p_size); @@ -1481,8 +1540,8 @@ void TextServerFallback::_font_set_descent(const RID &p_font_rid, int64_t p_size } double TextServerFallback::_font_get_descent(const RID &p_font_rid, int64_t p_size) const { - FontFallback *fd = font_owner.get_or_null(p_font_rid); - ERR_FAIL_COND_V(!fd, 0.0); + FontFallback *fd = _get_font_data(p_font_rid); + ERR_FAIL_NULL_V(fd, 0.0); MutexLock lock(fd->mutex); Vector2i size = _get_size(fd, p_size); @@ -1491,14 +1550,20 @@ double TextServerFallback::_font_get_descent(const RID &p_font_rid, int64_t p_si if (fd->msdf) { return fd->cache[size]->descent * (double)p_size / (double)fd->msdf_source_size; + } else if (fd->fixed_size > 0 && fd->fixed_size_scale_mode != FIXED_SIZE_SCALE_DISABLE && size.x != p_size) { + if (fd->fixed_size_scale_mode == FIXED_SIZE_SCALE_ENABLED) { + return fd->cache[size]->descent * (double)p_size / (double)fd->fixed_size; + } else { + return fd->cache[size]->descent * Math::round((double)p_size / (double)fd->fixed_size); + } } else { return fd->cache[size]->descent; } } void TextServerFallback::_font_set_underline_position(const RID &p_font_rid, int64_t p_size, double p_underline_position) { - FontFallback *fd = font_owner.get_or_null(p_font_rid); - ERR_FAIL_COND(!fd); + FontFallback *fd = _get_font_data(p_font_rid); + ERR_FAIL_NULL(fd); MutexLock lock(fd->mutex); Vector2i size = _get_size(fd, p_size); @@ -1508,8 +1573,8 @@ void TextServerFallback::_font_set_underline_position(const RID &p_font_rid, int } double TextServerFallback::_font_get_underline_position(const RID &p_font_rid, int64_t p_size) const { - FontFallback *fd = font_owner.get_or_null(p_font_rid); - ERR_FAIL_COND_V(!fd, 0.0); + FontFallback *fd = _get_font_data(p_font_rid); + ERR_FAIL_NULL_V(fd, 0.0); MutexLock lock(fd->mutex); Vector2i size = _get_size(fd, p_size); @@ -1518,14 +1583,20 @@ double TextServerFallback::_font_get_underline_position(const RID &p_font_rid, i if (fd->msdf) { return fd->cache[size]->underline_position * (double)p_size / (double)fd->msdf_source_size; + } else if (fd->fixed_size > 0 && fd->fixed_size_scale_mode != FIXED_SIZE_SCALE_DISABLE && size.x != p_size) { + if (fd->fixed_size_scale_mode == FIXED_SIZE_SCALE_ENABLED) { + return fd->cache[size]->underline_position * (double)p_size / (double)fd->fixed_size; + } else { + return fd->cache[size]->underline_position * Math::round((double)p_size / (double)fd->fixed_size); + } } else { return fd->cache[size]->underline_position; } } void TextServerFallback::_font_set_underline_thickness(const RID &p_font_rid, int64_t p_size, double p_underline_thickness) { - FontFallback *fd = font_owner.get_or_null(p_font_rid); - ERR_FAIL_COND(!fd); + FontFallback *fd = _get_font_data(p_font_rid); + ERR_FAIL_NULL(fd); MutexLock lock(fd->mutex); Vector2i size = _get_size(fd, p_size); @@ -1535,8 +1606,8 @@ void TextServerFallback::_font_set_underline_thickness(const RID &p_font_rid, in } double TextServerFallback::_font_get_underline_thickness(const RID &p_font_rid, int64_t p_size) const { - FontFallback *fd = font_owner.get_or_null(p_font_rid); - ERR_FAIL_COND_V(!fd, 0.0); + FontFallback *fd = _get_font_data(p_font_rid); + ERR_FAIL_NULL_V(fd, 0.0); MutexLock lock(fd->mutex); Vector2i size = _get_size(fd, p_size); @@ -1545,14 +1616,20 @@ double TextServerFallback::_font_get_underline_thickness(const RID &p_font_rid, if (fd->msdf) { return fd->cache[size]->underline_thickness * (double)p_size / (double)fd->msdf_source_size; + } else if (fd->fixed_size > 0 && fd->fixed_size_scale_mode != FIXED_SIZE_SCALE_DISABLE && size.x != p_size) { + if (fd->fixed_size_scale_mode == FIXED_SIZE_SCALE_ENABLED) { + return fd->cache[size]->underline_thickness * (double)p_size / (double)fd->fixed_size; + } else { + return fd->cache[size]->underline_thickness * Math::round((double)p_size / (double)fd->fixed_size); + } } else { return fd->cache[size]->underline_thickness; } } void TextServerFallback::_font_set_scale(const RID &p_font_rid, int64_t p_size, double p_scale) { - FontFallback *fd = font_owner.get_or_null(p_font_rid); - ERR_FAIL_COND(!fd); + FontFallback *fd = _get_font_data(p_font_rid); + ERR_FAIL_NULL(fd); MutexLock lock(fd->mutex); Vector2i size = _get_size(fd, p_size); @@ -1567,8 +1644,8 @@ void TextServerFallback::_font_set_scale(const RID &p_font_rid, int64_t p_size, } double TextServerFallback::_font_get_scale(const RID &p_font_rid, int64_t p_size) const { - FontFallback *fd = font_owner.get_or_null(p_font_rid); - ERR_FAIL_COND_V(!fd, 0.0); + FontFallback *fd = _get_font_data(p_font_rid); + ERR_FAIL_NULL_V(fd, 0.0); MutexLock lock(fd->mutex); Vector2i size = _get_size(fd, p_size); @@ -1577,14 +1654,20 @@ double TextServerFallback::_font_get_scale(const RID &p_font_rid, int64_t p_size if (fd->msdf) { return fd->cache[size]->scale * (double)p_size / (double)fd->msdf_source_size; + } else if (fd->fixed_size > 0 && fd->fixed_size_scale_mode != FIXED_SIZE_SCALE_DISABLE && size.x != p_size) { + if (fd->fixed_size_scale_mode == FIXED_SIZE_SCALE_ENABLED) { + return fd->cache[size]->scale * (double)p_size / (double)fd->fixed_size; + } else { + return fd->cache[size]->scale * Math::round((double)p_size / (double)fd->fixed_size); + } } else { return fd->cache[size]->scale / fd->cache[size]->oversampling; } } int64_t TextServerFallback::_font_get_texture_count(const RID &p_font_rid, const Vector2i &p_size) const { - FontFallback *fd = font_owner.get_or_null(p_font_rid); - ERR_FAIL_COND_V(!fd, 0); + FontFallback *fd = _get_font_data(p_font_rid); + ERR_FAIL_NULL_V(fd, 0); MutexLock lock(fd->mutex); Vector2i size = _get_size_outline(fd, p_size); @@ -1595,8 +1678,8 @@ int64_t TextServerFallback::_font_get_texture_count(const RID &p_font_rid, const } void TextServerFallback::_font_clear_textures(const RID &p_font_rid, const Vector2i &p_size) { - FontFallback *fd = font_owner.get_or_null(p_font_rid); - ERR_FAIL_COND(!fd); + FontFallback *fd = _get_font_data(p_font_rid); + ERR_FAIL_NULL(fd); MutexLock lock(fd->mutex); Vector2i size = _get_size_outline(fd, p_size); @@ -1605,8 +1688,8 @@ void TextServerFallback::_font_clear_textures(const RID &p_font_rid, const Vecto } void TextServerFallback::_font_remove_texture(const RID &p_font_rid, const Vector2i &p_size, int64_t p_texture_index) { - FontFallback *fd = font_owner.get_or_null(p_font_rid); - ERR_FAIL_COND(!fd); + FontFallback *fd = _get_font_data(p_font_rid); + ERR_FAIL_NULL(fd); MutexLock lock(fd->mutex); Vector2i size = _get_size_outline(fd, p_size); @@ -1617,8 +1700,8 @@ void TextServerFallback::_font_remove_texture(const RID &p_font_rid, const Vecto } void TextServerFallback::_font_set_texture_image(const RID &p_font_rid, const Vector2i &p_size, int64_t p_texture_index, const Ref<Image> &p_image) { - FontFallback *fd = font_owner.get_or_null(p_font_rid); - ERR_FAIL_COND(!fd); + FontFallback *fd = _get_font_data(p_font_rid); + ERR_FAIL_NULL(fd); ERR_FAIL_COND(p_image.is_null()); MutexLock lock(fd->mutex); @@ -1646,8 +1729,8 @@ void TextServerFallback::_font_set_texture_image(const RID &p_font_rid, const Ve } Ref<Image> TextServerFallback::_font_get_texture_image(const RID &p_font_rid, const Vector2i &p_size, int64_t p_texture_index) const { - FontFallback *fd = font_owner.get_or_null(p_font_rid); - ERR_FAIL_COND_V(!fd, Ref<Image>()); + FontFallback *fd = _get_font_data(p_font_rid); + ERR_FAIL_NULL_V(fd, Ref<Image>()); MutexLock lock(fd->mutex); Vector2i size = _get_size_outline(fd, p_size); @@ -1660,8 +1743,8 @@ Ref<Image> TextServerFallback::_font_get_texture_image(const RID &p_font_rid, co void TextServerFallback::_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); - FontFallback *fd = font_owner.get_or_null(p_font_rid); - ERR_FAIL_COND(!fd); + FontFallback *fd = _get_font_data(p_font_rid); + ERR_FAIL_NULL(fd); MutexLock lock(fd->mutex); Vector2i size = _get_size_outline(fd, p_size); @@ -1679,8 +1762,8 @@ void TextServerFallback::_font_set_texture_offsets(const RID &p_font_rid, const } PackedInt32Array TextServerFallback::_font_get_texture_offsets(const RID &p_font_rid, const Vector2i &p_size, int64_t p_texture_index) const { - FontFallback *fd = font_owner.get_or_null(p_font_rid); - ERR_FAIL_COND_V(!fd, PackedInt32Array()); + FontFallback *fd = _get_font_data(p_font_rid); + ERR_FAIL_NULL_V(fd, PackedInt32Array()); MutexLock lock(fd->mutex); Vector2i size = _get_size_outline(fd, p_size); @@ -1704,8 +1787,8 @@ PackedInt32Array TextServerFallback::_font_get_texture_offsets(const RID &p_font } PackedInt32Array TextServerFallback::_font_get_glyph_list(const RID &p_font_rid, const Vector2i &p_size) const { - FontFallback *fd = font_owner.get_or_null(p_font_rid); - ERR_FAIL_COND_V(!fd, PackedInt32Array()); + FontFallback *fd = _get_font_data(p_font_rid); + ERR_FAIL_NULL_V(fd, PackedInt32Array()); MutexLock lock(fd->mutex); Vector2i size = _get_size_outline(fd, p_size); @@ -1720,8 +1803,8 @@ PackedInt32Array TextServerFallback::_font_get_glyph_list(const RID &p_font_rid, } void TextServerFallback::_font_clear_glyphs(const RID &p_font_rid, const Vector2i &p_size) { - FontFallback *fd = font_owner.get_or_null(p_font_rid); - ERR_FAIL_COND(!fd); + FontFallback *fd = _get_font_data(p_font_rid); + ERR_FAIL_NULL(fd); MutexLock lock(fd->mutex); Vector2i size = _get_size_outline(fd, p_size); @@ -1731,8 +1814,8 @@ void TextServerFallback::_font_clear_glyphs(const RID &p_font_rid, const Vector2 } void TextServerFallback::_font_remove_glyph(const RID &p_font_rid, const Vector2i &p_size, int64_t p_glyph) { - FontFallback *fd = font_owner.get_or_null(p_font_rid); - ERR_FAIL_COND(!fd); + FontFallback *fd = _get_font_data(p_font_rid); + ERR_FAIL_NULL(fd); MutexLock lock(fd->mutex); Vector2i size = _get_size_outline(fd, p_size); @@ -1742,8 +1825,8 @@ void TextServerFallback::_font_remove_glyph(const RID &p_font_rid, const Vector2 } Vector2 TextServerFallback::_font_get_glyph_advance(const RID &p_font_rid, int64_t p_size, int64_t p_glyph) const { - FontFallback *fd = font_owner.get_or_null(p_font_rid); - ERR_FAIL_COND_V(!fd, Vector2()); + FontFallback *fd = _get_font_data(p_font_rid); + ERR_FAIL_NULL_V(fd, Vector2()); MutexLock lock(fd->mutex); Vector2i size = _get_size(fd, p_size); @@ -1772,6 +1855,12 @@ Vector2 TextServerFallback::_font_get_glyph_advance(const RID &p_font_rid, int64 double scale = _font_get_scale(p_font_rid, p_size); if (fd->msdf) { return (gl[p_glyph | mod].advance + ea) * (double)p_size / (double)fd->msdf_source_size; + } else if (fd->fixed_size > 0 && fd->fixed_size_scale_mode != FIXED_SIZE_SCALE_DISABLE && size.x != p_size) { + if (fd->fixed_size_scale_mode == FIXED_SIZE_SCALE_ENABLED) { + return (gl[p_glyph | mod].advance + ea) * (double)p_size / (double)fd->fixed_size; + } else { + return (gl[p_glyph | mod].advance + ea) * Math::round((double)p_size / (double)fd->fixed_size); + } } else if ((scale == 1.0) && ((fd->subpixel_positioning == SUBPIXEL_POSITIONING_DISABLED) || (fd->subpixel_positioning == SUBPIXEL_POSITIONING_AUTO && size.x > SUBPIXEL_POSITIONING_ONE_HALF_MAX_SIZE))) { return (gl[p_glyph | mod].advance + ea).round(); } else { @@ -1780,8 +1869,8 @@ Vector2 TextServerFallback::_font_get_glyph_advance(const RID &p_font_rid, int64 } void TextServerFallback::_font_set_glyph_advance(const RID &p_font_rid, int64_t p_size, int64_t p_glyph, const Vector2 &p_advance) { - FontFallback *fd = font_owner.get_or_null(p_font_rid); - ERR_FAIL_COND(!fd); + FontFallback *fd = _get_font_data(p_font_rid); + ERR_FAIL_NULL(fd); MutexLock lock(fd->mutex); Vector2i size = _get_size(fd, p_size); @@ -1795,8 +1884,8 @@ void TextServerFallback::_font_set_glyph_advance(const RID &p_font_rid, int64_t } Vector2 TextServerFallback::_font_get_glyph_offset(const RID &p_font_rid, const Vector2i &p_size, int64_t p_glyph) const { - FontFallback *fd = font_owner.get_or_null(p_font_rid); - ERR_FAIL_COND_V(!fd, Vector2()); + FontFallback *fd = _get_font_data(p_font_rid); + ERR_FAIL_NULL_V(fd, Vector2()); MutexLock lock(fd->mutex); Vector2i size = _get_size_outline(fd, p_size); @@ -1819,14 +1908,20 @@ Vector2 TextServerFallback::_font_get_glyph_offset(const RID &p_font_rid, const if (fd->msdf) { return gl[p_glyph | mod].rect.position * (double)p_size.x / (double)fd->msdf_source_size; + } else if (fd->fixed_size > 0 && fd->fixed_size_scale_mode != FIXED_SIZE_SCALE_DISABLE && size.x != p_size.x) { + if (fd->fixed_size_scale_mode == FIXED_SIZE_SCALE_ENABLED) { + return gl[p_glyph | mod].rect.position * (double)p_size.x / (double)fd->fixed_size; + } else { + return gl[p_glyph | mod].rect.position * Math::round((double)p_size.x / (double)fd->fixed_size); + } } else { return gl[p_glyph | mod].rect.position; } } void TextServerFallback::_font_set_glyph_offset(const RID &p_font_rid, const Vector2i &p_size, int64_t p_glyph, const Vector2 &p_offset) { - FontFallback *fd = font_owner.get_or_null(p_font_rid); - ERR_FAIL_COND(!fd); + FontFallback *fd = _get_font_data(p_font_rid); + ERR_FAIL_NULL(fd); MutexLock lock(fd->mutex); Vector2i size = _get_size_outline(fd, p_size); @@ -1840,8 +1935,8 @@ void TextServerFallback::_font_set_glyph_offset(const RID &p_font_rid, const Vec } Vector2 TextServerFallback::_font_get_glyph_size(const RID &p_font_rid, const Vector2i &p_size, int64_t p_glyph) const { - FontFallback *fd = font_owner.get_or_null(p_font_rid); - ERR_FAIL_COND_V(!fd, Vector2()); + FontFallback *fd = _get_font_data(p_font_rid); + ERR_FAIL_NULL_V(fd, Vector2()); MutexLock lock(fd->mutex); Vector2i size = _get_size_outline(fd, p_size); @@ -1864,14 +1959,20 @@ Vector2 TextServerFallback::_font_get_glyph_size(const RID &p_font_rid, const Ve if (fd->msdf) { return gl[p_glyph | mod].rect.size * (double)p_size.x / (double)fd->msdf_source_size; + } else if (fd->fixed_size > 0 && fd->fixed_size_scale_mode != FIXED_SIZE_SCALE_DISABLE && size.x != p_size.x) { + if (fd->fixed_size_scale_mode == FIXED_SIZE_SCALE_ENABLED) { + return gl[p_glyph | mod].rect.size * (double)p_size.x / (double)fd->fixed_size; + } else { + return gl[p_glyph | mod].rect.size * Math::round((double)p_size.x / (double)fd->fixed_size); + } } else { return gl[p_glyph | mod].rect.size; } } void TextServerFallback::_font_set_glyph_size(const RID &p_font_rid, const Vector2i &p_size, int64_t p_glyph, const Vector2 &p_gl_size) { - FontFallback *fd = font_owner.get_or_null(p_font_rid); - ERR_FAIL_COND(!fd); + FontFallback *fd = _get_font_data(p_font_rid); + ERR_FAIL_NULL(fd); MutexLock lock(fd->mutex); Vector2i size = _get_size_outline(fd, p_size); @@ -1885,8 +1986,8 @@ void TextServerFallback::_font_set_glyph_size(const RID &p_font_rid, const Vecto } Rect2 TextServerFallback::_font_get_glyph_uv_rect(const RID &p_font_rid, const Vector2i &p_size, int64_t p_glyph) const { - FontFallback *fd = font_owner.get_or_null(p_font_rid); - ERR_FAIL_COND_V(!fd, Rect2()); + FontFallback *fd = _get_font_data(p_font_rid); + ERR_FAIL_NULL_V(fd, Rect2()); MutexLock lock(fd->mutex); Vector2i size = _get_size_outline(fd, p_size); @@ -1910,8 +2011,8 @@ Rect2 TextServerFallback::_font_get_glyph_uv_rect(const RID &p_font_rid, const V } void TextServerFallback::_font_set_glyph_uv_rect(const RID &p_font_rid, const Vector2i &p_size, int64_t p_glyph, const Rect2 &p_uv_rect) { - FontFallback *fd = font_owner.get_or_null(p_font_rid); - ERR_FAIL_COND(!fd); + FontFallback *fd = _get_font_data(p_font_rid); + ERR_FAIL_NULL(fd); MutexLock lock(fd->mutex); Vector2i size = _get_size_outline(fd, p_size); @@ -1925,8 +2026,8 @@ void TextServerFallback::_font_set_glyph_uv_rect(const RID &p_font_rid, const Ve } int64_t TextServerFallback::_font_get_glyph_texture_idx(const RID &p_font_rid, const Vector2i &p_size, int64_t p_glyph) const { - FontFallback *fd = font_owner.get_or_null(p_font_rid); - ERR_FAIL_COND_V(!fd, -1); + FontFallback *fd = _get_font_data(p_font_rid); + ERR_FAIL_NULL_V(fd, -1); MutexLock lock(fd->mutex); Vector2i size = _get_size_outline(fd, p_size); @@ -1950,8 +2051,8 @@ int64_t TextServerFallback::_font_get_glyph_texture_idx(const RID &p_font_rid, c } void TextServerFallback::_font_set_glyph_texture_idx(const RID &p_font_rid, const Vector2i &p_size, int64_t p_glyph, int64_t p_texture_idx) { - FontFallback *fd = font_owner.get_or_null(p_font_rid); - ERR_FAIL_COND(!fd); + FontFallback *fd = _get_font_data(p_font_rid); + ERR_FAIL_NULL(fd); MutexLock lock(fd->mutex); Vector2i size = _get_size_outline(fd, p_size); @@ -1965,8 +2066,8 @@ void TextServerFallback::_font_set_glyph_texture_idx(const RID &p_font_rid, cons } RID TextServerFallback::_font_get_glyph_texture_rid(const RID &p_font_rid, const Vector2i &p_size, int64_t p_glyph) const { - FontFallback *fd = font_owner.get_or_null(p_font_rid); - ERR_FAIL_COND_V(!fd, RID()); + FontFallback *fd = _get_font_data(p_font_rid); + ERR_FAIL_NULL_V(fd, RID()); MutexLock lock(fd->mutex); Vector2i size = _get_size_outline(fd, p_size); @@ -2011,8 +2112,8 @@ RID TextServerFallback::_font_get_glyph_texture_rid(const RID &p_font_rid, const } Size2 TextServerFallback::_font_get_glyph_texture_size(const RID &p_font_rid, const Vector2i &p_size, int64_t p_glyph) const { - FontFallback *fd = font_owner.get_or_null(p_font_rid); - ERR_FAIL_COND_V(!fd, Size2()); + FontFallback *fd = _get_font_data(p_font_rid); + ERR_FAIL_NULL_V(fd, Size2()); MutexLock lock(fd->mutex); Vector2i size = _get_size_outline(fd, p_size); @@ -2057,8 +2158,8 @@ Size2 TextServerFallback::_font_get_glyph_texture_size(const RID &p_font_rid, co } Dictionary TextServerFallback::_font_get_glyph_contours(const RID &p_font_rid, int64_t p_size, int64_t p_index) const { - FontFallback *fd = font_owner.get_or_null(p_font_rid); - ERR_FAIL_COND_V(!fd, Dictionary()); + FontFallback *fd = _get_font_data(p_font_rid); + ERR_FAIL_NULL_V(fd, Dictionary()); MutexLock lock(fd->mutex); Vector2i size = _get_size(fd, p_size); @@ -2087,6 +2188,12 @@ Dictionary TextServerFallback::_font_get_glyph_contours(const RID &p_font_rid, i double scale = (1.0 / 64.0) / fd->cache[size]->oversampling * fd->cache[size]->scale; if (fd->msdf) { scale = scale * (double)p_size / (double)fd->msdf_source_size; + } else if (fd->fixed_size > 0 && fd->fixed_size_scale_mode != FIXED_SIZE_SCALE_DISABLE && size.x != p_size) { + if (fd->fixed_size_scale_mode == FIXED_SIZE_SCALE_ENABLED) { + scale = scale * (double)p_size / (double)fd->fixed_size; + } else { + scale = scale * Math::round((double)p_size / (double)fd->fixed_size); + } } for (short i = 0; i < fd->cache[size]->face->glyph->outline.n_points; i++) { points.push_back(Vector3(fd->cache[size]->face->glyph->outline.points[i].x * scale, -fd->cache[size]->face->glyph->outline.points[i].y * scale, FT_CURVE_TAG(fd->cache[size]->face->glyph->outline.tags[i]))); @@ -2107,8 +2214,8 @@ Dictionary TextServerFallback::_font_get_glyph_contours(const RID &p_font_rid, i } TypedArray<Vector2i> TextServerFallback::_font_get_kerning_list(const RID &p_font_rid, int64_t p_size) const { - FontFallback *fd = font_owner.get_or_null(p_font_rid); - ERR_FAIL_COND_V(!fd, TypedArray<Vector2i>()); + FontFallback *fd = _get_font_data(p_font_rid); + ERR_FAIL_NULL_V(fd, TypedArray<Vector2i>()); MutexLock lock(fd->mutex); Vector2i size = _get_size(fd, p_size); @@ -2123,8 +2230,8 @@ TypedArray<Vector2i> TextServerFallback::_font_get_kerning_list(const RID &p_fon } void TextServerFallback::_font_clear_kerning_map(const RID &p_font_rid, int64_t p_size) { - FontFallback *fd = font_owner.get_or_null(p_font_rid); - ERR_FAIL_COND(!fd); + FontFallback *fd = _get_font_data(p_font_rid); + ERR_FAIL_NULL(fd); MutexLock lock(fd->mutex); Vector2i size = _get_size(fd, p_size); @@ -2134,8 +2241,8 @@ void TextServerFallback::_font_clear_kerning_map(const RID &p_font_rid, int64_t } void TextServerFallback::_font_remove_kerning(const RID &p_font_rid, int64_t p_size, const Vector2i &p_glyph_pair) { - FontFallback *fd = font_owner.get_or_null(p_font_rid); - ERR_FAIL_COND(!fd); + FontFallback *fd = _get_font_data(p_font_rid); + ERR_FAIL_NULL(fd); MutexLock lock(fd->mutex); Vector2i size = _get_size(fd, p_size); @@ -2145,8 +2252,8 @@ void TextServerFallback::_font_remove_kerning(const RID &p_font_rid, int64_t p_s } void TextServerFallback::_font_set_kerning(const RID &p_font_rid, int64_t p_size, const Vector2i &p_glyph_pair, const Vector2 &p_kerning) { - FontFallback *fd = font_owner.get_or_null(p_font_rid); - ERR_FAIL_COND(!fd); + FontFallback *fd = _get_font_data(p_font_rid); + ERR_FAIL_NULL(fd); MutexLock lock(fd->mutex); Vector2i size = _get_size(fd, p_size); @@ -2156,8 +2263,8 @@ void TextServerFallback::_font_set_kerning(const RID &p_font_rid, int64_t p_size } Vector2 TextServerFallback::_font_get_kerning(const RID &p_font_rid, int64_t p_size, const Vector2i &p_glyph_pair) const { - FontFallback *fd = font_owner.get_or_null(p_font_rid); - ERR_FAIL_COND_V(!fd, Vector2()); + FontFallback *fd = _get_font_data(p_font_rid); + ERR_FAIL_NULL_V(fd, Vector2()); MutexLock lock(fd->mutex); Vector2i size = _get_size(fd, p_size); @@ -2169,6 +2276,12 @@ Vector2 TextServerFallback::_font_get_kerning(const RID &p_font_rid, int64_t p_s if (kern.has(p_glyph_pair)) { if (fd->msdf) { return kern[p_glyph_pair] * (double)p_size / (double)fd->msdf_source_size; + } else if (fd->fixed_size > 0 && fd->fixed_size_scale_mode != FIXED_SIZE_SCALE_DISABLE && size.x != p_size) { + if (fd->fixed_size_scale_mode == FIXED_SIZE_SCALE_ENABLED) { + return kern[p_glyph_pair] * (double)p_size / (double)fd->fixed_size; + } else { + return kern[p_glyph_pair] * Math::round((double)p_size / (double)fd->fixed_size); + } } else { return kern[p_glyph_pair]; } @@ -2181,6 +2294,12 @@ Vector2 TextServerFallback::_font_get_kerning(const RID &p_font_rid, int64_t p_s FT_Get_Kerning(fd->cache[size]->face, glyph_a, glyph_b, FT_KERNING_DEFAULT, &delta); if (fd->msdf) { return Vector2(delta.x, delta.y) * (double)p_size / (double)fd->msdf_source_size; + } else if (fd->fixed_size > 0 && fd->fixed_size_scale_mode != FIXED_SIZE_SCALE_DISABLE && size.x != p_size) { + if (fd->fixed_size_scale_mode == FIXED_SIZE_SCALE_ENABLED) { + return Vector2(delta.x, delta.y) * (double)p_size / (double)fd->fixed_size; + } else { + return Vector2(delta.x, delta.y) * Math::round((double)p_size / (double)fd->fixed_size); + } } else { return Vector2(delta.x, delta.y); } @@ -2200,7 +2319,7 @@ int64_t TextServerFallback::_font_get_char_from_glyph_index(const RID &p_font_ri } bool TextServerFallback::_font_has_char(const RID &p_font_rid, int64_t p_char) const { - FontFallback *fd = font_owner.get_or_null(p_font_rid); + FontFallback *fd = _get_font_data(p_font_rid); ERR_FAIL_COND_V_MSG((p_char >= 0xd800 && p_char <= 0xdfff) || (p_char > 0x10ffff), false, "Unicode parsing error: Invalid unicode codepoint " + String::num_int64(p_char, 16) + "."); if (!fd) { return false; @@ -2221,8 +2340,8 @@ bool TextServerFallback::_font_has_char(const RID &p_font_rid, int64_t p_char) c } String TextServerFallback::_font_get_supported_chars(const RID &p_font_rid) const { - FontFallback *fd = font_owner.get_or_null(p_font_rid); - ERR_FAIL_COND_V(!fd, String()); + FontFallback *fd = _get_font_data(p_font_rid); + ERR_FAIL_NULL_V(fd, String()); MutexLock lock(fd->mutex); if (fd->cache.is_empty()) { @@ -2254,8 +2373,8 @@ String TextServerFallback::_font_get_supported_chars(const RID &p_font_rid) cons } void TextServerFallback::_font_render_range(const RID &p_font_rid, const Vector2i &p_size, int64_t p_start, int64_t p_end) { - FontFallback *fd = font_owner.get_or_null(p_font_rid); - ERR_FAIL_COND(!fd); + FontFallback *fd = _get_font_data(p_font_rid); + 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) + "."); @@ -2289,8 +2408,8 @@ void TextServerFallback::_font_render_range(const RID &p_font_rid, const Vector2 } void TextServerFallback::_font_render_glyph(const RID &p_font_rid, const Vector2i &p_size, int64_t p_index) { - FontFallback *fd = font_owner.get_or_null(p_font_rid); - ERR_FAIL_COND(!fd); + FontFallback *fd = _get_font_data(p_font_rid); + ERR_FAIL_NULL(fd); MutexLock lock(fd->mutex); Vector2i size = _get_size_outline(fd, p_size); @@ -2320,8 +2439,8 @@ void TextServerFallback::_font_render_glyph(const RID &p_font_rid, const Vector2 } void TextServerFallback::_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 { - FontFallback *fd = font_owner.get_or_null(p_font_rid); - ERR_FAIL_COND(!fd); + FontFallback *fd = _get_font_data(p_font_rid); + ERR_FAIL_NULL(fd); MutexLock lock(fd->mutex); Vector2i size = _get_size(fd, p_size); @@ -2398,8 +2517,20 @@ void TextServerFallback::_font_draw_glyph(const RID &p_font_rid, const RID &p_ca cpos.y = Math::floor(cpos.y); cpos.x = Math::floor(cpos.x); } - cpos += gl.rect.position; + Vector2 gpos = gl.rect.position; Size2 csize = gl.rect.size; + if (fd->fixed_size > 0 && fd->fixed_size_scale_mode != FIXED_SIZE_SCALE_DISABLE && size.x != p_size) { + if (fd->fixed_size_scale_mode == FIXED_SIZE_SCALE_ENABLED) { + double gl_scale = (double)p_size / (double)fd->fixed_size; + gpos *= gl_scale; + csize *= gl_scale; + } else { + double gl_scale = Math::round((double)p_size / (double)fd->fixed_size); + gpos *= gl_scale; + csize *= gl_scale; + } + } + cpos += gpos; if (lcd_aa) { RenderingServer::get_singleton()->canvas_item_add_lcd_texture_rect_region(p_canvas, Rect2(cpos, csize), texture, gl.uv_rect, modulate); } else { @@ -2412,8 +2543,8 @@ void TextServerFallback::_font_draw_glyph(const RID &p_font_rid, const RID &p_ca } void TextServerFallback::_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 { - FontFallback *fd = font_owner.get_or_null(p_font_rid); - ERR_FAIL_COND(!fd); + FontFallback *fd = _get_font_data(p_font_rid); + ERR_FAIL_NULL(fd); MutexLock lock(fd->mutex); Vector2i size = _get_size_outline(fd, Vector2i(p_size, p_outline_size)); @@ -2490,8 +2621,20 @@ void TextServerFallback::_font_draw_glyph_outline(const RID &p_font_rid, const R cpos.y = Math::floor(cpos.y); cpos.x = Math::floor(cpos.x); } - cpos += gl.rect.position; + Vector2 gpos = gl.rect.position; Size2 csize = gl.rect.size; + if (fd->fixed_size > 0 && fd->fixed_size_scale_mode != FIXED_SIZE_SCALE_DISABLE && size.x != p_size) { + if (fd->fixed_size_scale_mode == FIXED_SIZE_SCALE_ENABLED) { + double gl_scale = (double)p_size / (double)fd->fixed_size; + gpos *= gl_scale; + csize *= gl_scale; + } else { + double gl_scale = Math::round((double)p_size / (double)fd->fixed_size); + gpos *= gl_scale; + csize *= gl_scale; + } + } + cpos += gpos; if (lcd_aa) { RenderingServer::get_singleton()->canvas_item_add_lcd_texture_rect_region(p_canvas, Rect2(cpos, csize), texture, gl.uv_rect, modulate); } else { @@ -2504,8 +2647,8 @@ void TextServerFallback::_font_draw_glyph_outline(const RID &p_font_rid, const R } bool TextServerFallback::_font_is_language_supported(const RID &p_font_rid, const String &p_language) const { - FontFallback *fd = font_owner.get_or_null(p_font_rid); - ERR_FAIL_COND_V(!fd, false); + FontFallback *fd = _get_font_data(p_font_rid); + ERR_FAIL_NULL_V(fd, false); MutexLock lock(fd->mutex); if (fd->language_support_overrides.has(p_language)) { @@ -2516,32 +2659,32 @@ bool TextServerFallback::_font_is_language_supported(const RID &p_font_rid, cons } void TextServerFallback::_font_set_language_support_override(const RID &p_font_rid, const String &p_language, bool p_supported) { - FontFallback *fd = font_owner.get_or_null(p_font_rid); - ERR_FAIL_COND(!fd); + FontFallback *fd = _get_font_data(p_font_rid); + ERR_FAIL_NULL(fd); MutexLock lock(fd->mutex); fd->language_support_overrides[p_language] = p_supported; } bool TextServerFallback::_font_get_language_support_override(const RID &p_font_rid, const String &p_language) { - FontFallback *fd = font_owner.get_or_null(p_font_rid); - ERR_FAIL_COND_V(!fd, false); + FontFallback *fd = _get_font_data(p_font_rid); + ERR_FAIL_NULL_V(fd, false); MutexLock lock(fd->mutex); return fd->language_support_overrides[p_language]; } void TextServerFallback::_font_remove_language_support_override(const RID &p_font_rid, const String &p_language) { - FontFallback *fd = font_owner.get_or_null(p_font_rid); - ERR_FAIL_COND(!fd); + FontFallback *fd = _get_font_data(p_font_rid); + ERR_FAIL_NULL(fd); MutexLock lock(fd->mutex); fd->language_support_overrides.erase(p_language); } PackedStringArray TextServerFallback::_font_get_language_support_overrides(const RID &p_font_rid) { - FontFallback *fd = font_owner.get_or_null(p_font_rid); - ERR_FAIL_COND_V(!fd, PackedStringArray()); + FontFallback *fd = _get_font_data(p_font_rid); + ERR_FAIL_NULL_V(fd, PackedStringArray()); MutexLock lock(fd->mutex); PackedStringArray out; @@ -2552,8 +2695,8 @@ PackedStringArray TextServerFallback::_font_get_language_support_overrides(const } bool TextServerFallback::_font_is_script_supported(const RID &p_font_rid, const String &p_script) const { - FontFallback *fd = font_owner.get_or_null(p_font_rid); - ERR_FAIL_COND_V(!fd, false); + FontFallback *fd = _get_font_data(p_font_rid); + ERR_FAIL_NULL_V(fd, false); MutexLock lock(fd->mutex); if (fd->script_support_overrides.has(p_script)) { @@ -2564,24 +2707,24 @@ bool TextServerFallback::_font_is_script_supported(const RID &p_font_rid, const } void TextServerFallback::_font_set_script_support_override(const RID &p_font_rid, const String &p_script, bool p_supported) { - FontFallback *fd = font_owner.get_or_null(p_font_rid); - ERR_FAIL_COND(!fd); + FontFallback *fd = _get_font_data(p_font_rid); + ERR_FAIL_NULL(fd); MutexLock lock(fd->mutex); fd->script_support_overrides[p_script] = p_supported; } bool TextServerFallback::_font_get_script_support_override(const RID &p_font_rid, const String &p_script) { - FontFallback *fd = font_owner.get_or_null(p_font_rid); - ERR_FAIL_COND_V(!fd, false); + FontFallback *fd = _get_font_data(p_font_rid); + ERR_FAIL_NULL_V(fd, false); MutexLock lock(fd->mutex); return fd->script_support_overrides[p_script]; } void TextServerFallback::_font_remove_script_support_override(const RID &p_font_rid, const String &p_script) { - FontFallback *fd = font_owner.get_or_null(p_font_rid); - ERR_FAIL_COND(!fd); + FontFallback *fd = _get_font_data(p_font_rid); + ERR_FAIL_NULL(fd); MutexLock lock(fd->mutex); Vector2i size = _get_size(fd, 16); @@ -2590,8 +2733,8 @@ void TextServerFallback::_font_remove_script_support_override(const RID &p_font_ } PackedStringArray TextServerFallback::_font_get_script_support_overrides(const RID &p_font_rid) { - FontFallback *fd = font_owner.get_or_null(p_font_rid); - ERR_FAIL_COND_V(!fd, PackedStringArray()); + FontFallback *fd = _get_font_data(p_font_rid); + ERR_FAIL_NULL_V(fd, PackedStringArray()); MutexLock lock(fd->mutex); PackedStringArray out; @@ -2602,8 +2745,8 @@ PackedStringArray TextServerFallback::_font_get_script_support_overrides(const R } void TextServerFallback::_font_set_opentype_feature_overrides(const RID &p_font_rid, const Dictionary &p_overrides) { - FontFallback *fd = font_owner.get_or_null(p_font_rid); - ERR_FAIL_COND(!fd); + FontFallback *fd = _get_font_data(p_font_rid); + ERR_FAIL_NULL(fd); MutexLock lock(fd->mutex); Vector2i size = _get_size(fd, 16); @@ -2612,8 +2755,8 @@ void TextServerFallback::_font_set_opentype_feature_overrides(const RID &p_font_ } Dictionary TextServerFallback::_font_get_opentype_feature_overrides(const RID &p_font_rid) const { - FontFallback *fd = font_owner.get_or_null(p_font_rid); - ERR_FAIL_COND_V(!fd, Dictionary()); + FontFallback *fd = _get_font_data(p_font_rid); + ERR_FAIL_NULL_V(fd, Dictionary()); MutexLock lock(fd->mutex); return fd->feature_overrides; @@ -2624,8 +2767,8 @@ Dictionary TextServerFallback::_font_supported_feature_list(const RID &p_font_ri } Dictionary TextServerFallback::_font_supported_variation_list(const RID &p_font_rid) const { - FontFallback *fd = font_owner.get_or_null(p_font_rid); - ERR_FAIL_COND_V(!fd, Dictionary()); + FontFallback *fd = _get_font_data(p_font_rid); + ERR_FAIL_NULL_V(fd, Dictionary()); MutexLock lock(fd->mutex); Vector2i size = _get_size(fd, 16); @@ -2714,7 +2857,7 @@ RID TextServerFallback::_create_shaped_text(TextServer::Direction p_direction, T void TextServerFallback::_shaped_text_clear(const RID &p_shaped) { ShapedTextDataFallback *sd = shaped_owner.get_or_null(p_shaped); - ERR_FAIL_COND(!sd); + ERR_FAIL_NULL(sd); MutexLock lock(sd->mutex); sd->parent = RID(); @@ -2744,7 +2887,7 @@ TextServer::Direction TextServerFallback::_shaped_text_get_inferred_direction(co void TextServerFallback::_shaped_text_set_custom_punctuation(const RID &p_shaped, const String &p_punct) { _THREAD_SAFE_METHOD_ ShapedTextDataFallback *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()) { @@ -2758,13 +2901,13 @@ void TextServerFallback::_shaped_text_set_custom_punctuation(const RID &p_shaped String TextServerFallback::_shaped_text_get_custom_punctuation(const RID &p_shaped) const { _THREAD_SAFE_METHOD_ const ShapedTextDataFallback *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 TextServerFallback::_shaped_text_set_orientation(const RID &p_shaped, TextServer::Orientation p_orientation) { ShapedTextDataFallback *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) { @@ -2782,7 +2925,7 @@ void TextServerFallback::_shaped_text_set_bidi_override(const RID &p_shaped, con TextServer::Orientation TextServerFallback::_shaped_text_get_orientation(const RID &p_shaped) const { const ShapedTextDataFallback *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; @@ -2792,7 +2935,7 @@ void TextServerFallback::_shaped_text_set_preserve_invalid(const RID &p_shaped, ShapedTextDataFallback *sd = shaped_owner.get_or_null(p_shaped); MutexLock lock(sd->mutex); - ERR_FAIL_COND(!sd); + ERR_FAIL_NULL(sd); if (sd->preserve_invalid != p_enabled) { if (sd->parent != RID()) { full_copy(sd); @@ -2804,7 +2947,7 @@ void TextServerFallback::_shaped_text_set_preserve_invalid(const RID &p_shaped, bool TextServerFallback::_shaped_text_get_preserve_invalid(const RID &p_shaped) const { const ShapedTextDataFallback *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; @@ -2812,7 +2955,7 @@ bool TextServerFallback::_shaped_text_get_preserve_invalid(const RID &p_shaped) void TextServerFallback::_shaped_text_set_preserve_control(const RID &p_shaped, bool p_enabled) { ShapedTextDataFallback *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) { @@ -2826,7 +2969,7 @@ void TextServerFallback::_shaped_text_set_preserve_control(const RID &p_shaped, bool TextServerFallback::_shaped_text_get_preserve_control(const RID &p_shaped) const { const ShapedTextDataFallback *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; @@ -2835,7 +2978,7 @@ bool TextServerFallback::_shaped_text_get_preserve_control(const RID &p_shaped) void TextServerFallback::_shaped_text_set_spacing(const RID &p_shaped, SpacingType p_spacing, int64_t p_value) { ERR_FAIL_INDEX((int)p_spacing, 4); ShapedTextDataFallback *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) { @@ -2851,7 +2994,7 @@ int64_t TextServerFallback::_shaped_text_get_spacing(const RID &p_shaped, Spacin ERR_FAIL_INDEX_V((int)p_spacing, 4, 0); const ShapedTextDataFallback *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]; @@ -2859,20 +3002,20 @@ int64_t TextServerFallback::_shaped_text_get_spacing(const RID &p_shaped, Spacin int64_t TextServerFallback::_shaped_get_span_count(const RID &p_shaped) const { ShapedTextDataFallback *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 TextServerFallback::_shaped_get_span_meta(const RID &p_shaped, int64_t p_index) const { ShapedTextDataFallback *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 TextServerFallback::_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) { ShapedTextDataFallback *sd = shaped_owner.get_or_null(p_shaped); - ERR_FAIL_COND(!sd); + ERR_FAIL_NULL(sd); ERR_FAIL_INDEX(p_index, sd->spans.size()); ShapedTextDataFallback::Span &span = sd->spans.ptrw()[p_index]; @@ -2896,13 +3039,13 @@ void TextServerFallback::_shaped_set_span_update_font(const RID &p_shaped, int64 bool TextServerFallback::_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) { ShapedTextDataFallback *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(p_size <= 0, false); for (int i = 0; i < p_fonts.size(); i++) { - ERR_FAIL_COND_V(!font_owner.get_or_null(p_fonts[i]), false); + ERR_FAIL_NULL_V(_get_font_data(p_fonts[i]), false); } if (p_text.is_empty()) { @@ -2947,7 +3090,7 @@ bool TextServerFallback::_shaped_text_add_string(const RID &p_shaped, const Stri bool TextServerFallback::_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) { ShapedTextDataFallback *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(p_key == Variant(), false); @@ -2979,7 +3122,7 @@ bool TextServerFallback::_shaped_text_add_object(const RID &p_shaped, const Vari bool TextServerFallback::_shaped_text_resize_object(const RID &p_shaped, const Variant &p_key, const Size2 &p_size, InlineAlignment p_inline_align, double p_baseline) { ShapedTextDataFallback *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); @@ -3123,7 +3266,7 @@ RID TextServerFallback::_shaped_text_substr(const RID &p_shaped, int64_t p_start _THREAD_SAFE_METHOD_ const ShapedTextDataFallback *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()) { @@ -3215,7 +3358,7 @@ RID TextServerFallback::_shaped_text_substr(const RID &p_shaped, int64_t p_start RID TextServerFallback::_shaped_text_get_parent(const RID &p_shaped) const { ShapedTextDataFallback *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; @@ -3223,7 +3366,7 @@ RID TextServerFallback::_shaped_text_get_parent(const RID &p_shaped) const { double TextServerFallback::_shaped_text_fit_to_width(const RID &p_shaped, double p_width, BitField<JustificationFlag> p_jst_flags) { ShapedTextDataFallback *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) { @@ -3332,7 +3475,7 @@ double TextServerFallback::_shaped_text_fit_to_width(const RID &p_shaped, double double TextServerFallback::_shaped_text_tab_align(const RID &p_shaped, const PackedFloat32Array &p_tab_stops) { ShapedTextDataFallback *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) { @@ -3388,7 +3531,7 @@ double TextServerFallback::_shaped_text_tab_align(const RID &p_shaped, const Pac bool TextServerFallback::_shaped_text_update_breaks(const RID &p_shaped) { ShapedTextDataFallback *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) { @@ -3444,7 +3587,7 @@ bool TextServerFallback::_shaped_text_update_breaks(const RID &p_shaped) { bool TextServerFallback::_shaped_text_update_justification_ops(const RID &p_shaped) { ShapedTextDataFallback *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) { @@ -3460,7 +3603,7 @@ bool TextServerFallback::_shaped_text_update_justification_ops(const RID &p_shap void TextServerFallback::_shaped_text_overrun_trim_to_width(const RID &p_shaped_line, double p_width, BitField<TextServer::TextOverrunFlag> p_trim_flags) { ShapedTextDataFallback *sd = shaped_owner.get_or_null(p_shaped_line); - ERR_FAIL_COND_MSG(!sd, "ShapedTextDataFallback invalid."); + ERR_FAIL_NULL_MSG(sd, "ShapedTextDataFallback invalid."); MutexLock lock(sd->mutex); if (!sd->valid) { @@ -3617,7 +3760,7 @@ void TextServerFallback::_shaped_text_overrun_trim_to_width(const RID &p_shaped_ int64_t TextServerFallback::_shaped_text_get_trim_pos(const RID &p_shaped) const { ShapedTextDataFallback *sd = shaped_owner.get_or_null(p_shaped); - ERR_FAIL_COND_V_MSG(!sd, -1, "ShapedTextDataFallback invalid."); + ERR_FAIL_NULL_V_MSG(sd, -1, "ShapedTextDataFallback invalid."); MutexLock lock(sd->mutex); return sd->overrun_trim_data.trim_pos; @@ -3625,7 +3768,7 @@ int64_t TextServerFallback::_shaped_text_get_trim_pos(const RID &p_shaped) const int64_t TextServerFallback::_shaped_text_get_ellipsis_pos(const RID &p_shaped) const { ShapedTextDataFallback *sd = shaped_owner.get_or_null(p_shaped); - ERR_FAIL_COND_V_MSG(!sd, -1, "ShapedTextDataFallback invalid."); + ERR_FAIL_NULL_V_MSG(sd, -1, "ShapedTextDataFallback invalid."); MutexLock lock(sd->mutex); return sd->overrun_trim_data.ellipsis_pos; @@ -3633,7 +3776,7 @@ int64_t TextServerFallback::_shaped_text_get_ellipsis_pos(const RID &p_shaped) c const Glyph *TextServerFallback::_shaped_text_get_ellipsis_glyphs(const RID &p_shaped) const { ShapedTextDataFallback *sd = shaped_owner.get_or_null(p_shaped); - ERR_FAIL_COND_V_MSG(!sd, nullptr, "ShapedTextDataFallback invalid."); + ERR_FAIL_NULL_V_MSG(sd, nullptr, "ShapedTextDataFallback invalid."); MutexLock lock(sd->mutex); return sd->overrun_trim_data.ellipsis_glyph_buf.ptr(); @@ -3641,7 +3784,7 @@ const Glyph *TextServerFallback::_shaped_text_get_ellipsis_glyphs(const RID &p_s int64_t TextServerFallback::_shaped_text_get_ellipsis_glyph_count(const RID &p_shaped) const { ShapedTextDataFallback *sd = shaped_owner.get_or_null(p_shaped); - ERR_FAIL_COND_V_MSG(!sd, 0, "ShapedTextDataFallback invalid."); + ERR_FAIL_NULL_V_MSG(sd, 0, "ShapedTextDataFallback invalid."); MutexLock lock(sd->mutex); return sd->overrun_trim_data.ellipsis_glyph_buf.size(); @@ -3649,7 +3792,7 @@ int64_t TextServerFallback::_shaped_text_get_ellipsis_glyph_count(const RID &p_s bool TextServerFallback::_shaped_text_shape(const RID &p_shaped) { ShapedTextDataFallback *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) { @@ -3958,7 +4101,7 @@ bool TextServerFallback::_shaped_text_shape(const RID &p_shaped) { bool TextServerFallback::_shaped_text_is_ready(const RID &p_shaped) const { const ShapedTextDataFallback *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; @@ -3966,7 +4109,7 @@ bool TextServerFallback::_shaped_text_is_ready(const RID &p_shaped) const { const Glyph *TextServerFallback::_shaped_text_get_glyphs(const RID &p_shaped) const { const ShapedTextDataFallback *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) { @@ -3977,7 +4120,7 @@ const Glyph *TextServerFallback::_shaped_text_get_glyphs(const RID &p_shaped) co int64_t TextServerFallback::_shaped_text_get_glyph_count(const RID &p_shaped) const { const ShapedTextDataFallback *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) { @@ -3988,7 +4131,7 @@ int64_t TextServerFallback::_shaped_text_get_glyph_count(const RID &p_shaped) co const Glyph *TextServerFallback::_shaped_text_sort_logical(const RID &p_shaped) { const ShapedTextDataFallback *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) { @@ -4000,7 +4143,7 @@ const Glyph *TextServerFallback::_shaped_text_sort_logical(const RID &p_shaped) Vector2i TextServerFallback::_shaped_text_get_range(const RID &p_shaped) const { const ShapedTextDataFallback *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); @@ -4009,7 +4152,7 @@ Vector2i TextServerFallback::_shaped_text_get_range(const RID &p_shaped) const { Array TextServerFallback::_shaped_text_get_objects(const RID &p_shaped) const { Array ret; const ShapedTextDataFallback *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, ShapedTextDataFallback::EmbeddedObject> &E : sd->objects) { @@ -4021,7 +4164,7 @@ Array TextServerFallback::_shaped_text_get_objects(const RID &p_shaped) const { Rect2 TextServerFallback::_shaped_text_get_object_rect(const RID &p_shaped, const Variant &p_key) const { const ShapedTextDataFallback *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()); @@ -4033,7 +4176,7 @@ Rect2 TextServerFallback::_shaped_text_get_object_rect(const RID &p_shaped, cons Size2 TextServerFallback::_shaped_text_get_size(const RID &p_shaped) const { const ShapedTextDataFallback *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) { @@ -4048,7 +4191,7 @@ Size2 TextServerFallback::_shaped_text_get_size(const RID &p_shaped) const { double TextServerFallback::_shaped_text_get_ascent(const RID &p_shaped) const { const ShapedTextDataFallback *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) { @@ -4059,7 +4202,7 @@ double TextServerFallback::_shaped_text_get_ascent(const RID &p_shaped) const { double TextServerFallback::_shaped_text_get_descent(const RID &p_shaped) const { const ShapedTextDataFallback *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) { @@ -4070,7 +4213,7 @@ double TextServerFallback::_shaped_text_get_descent(const RID &p_shaped) const { double TextServerFallback::_shaped_text_get_width(const RID &p_shaped) const { const ShapedTextDataFallback *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) { @@ -4081,7 +4224,7 @@ double TextServerFallback::_shaped_text_get_width(const RID &p_shaped) const { double TextServerFallback::_shaped_text_get_underline_position(const RID &p_shaped) const { const ShapedTextDataFallback *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) { @@ -4093,7 +4236,7 @@ double TextServerFallback::_shaped_text_get_underline_position(const RID &p_shap double TextServerFallback::_shaped_text_get_underline_thickness(const RID &p_shaped) const { const ShapedTextDataFallback *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) { @@ -4105,7 +4248,7 @@ double TextServerFallback::_shaped_text_get_underline_thickness(const RID &p_sha PackedInt32Array TextServerFallback::_shaped_text_get_character_breaks(const RID &p_shaped) const { const ShapedTextDataFallback *sd = shaped_owner.get_or_null(p_shaped); - ERR_FAIL_COND_V(!sd, PackedInt32Array()); + ERR_FAIL_NULL_V(sd, PackedInt32Array()); MutexLock lock(sd->mutex); if (!sd->valid) { |