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.cpp720
1 files changed, 402 insertions, 318 deletions
diff --git a/modules/text_server_adv/text_server_adv.cpp b/modules/text_server_adv/text_server_adv.cpp
index d0c22e9e4d..4bf09d3c84 100644
--- a/modules/text_server_adv/text_server_adv.cpp
+++ b/modules/text_server_adv/text_server_adv.cpp
@@ -136,11 +136,12 @@ hb_position_t TextServerAdvanced::_bmp_get_glyph_h_advance(hb_font_t *p_font, vo
return 0;
}
- if (!bm_font->face->glyph_map.has(p_glyph)) {
+ HashMap<int32_t, FontGlyph>::Iterator E = bm_font->face->glyph_map.find(p_glyph);
+ if (!E) {
return 0;
}
- return bm_font->face->glyph_map[p_glyph].advance.x * 64;
+ return E->value.advance.x * 64;
}
hb_position_t TextServerAdvanced::_bmp_get_glyph_v_advance(hb_font_t *p_font, void *p_font_data, hb_codepoint_t p_glyph, void *p_user_data) {
@@ -150,11 +151,12 @@ hb_position_t TextServerAdvanced::_bmp_get_glyph_v_advance(hb_font_t *p_font, vo
return 0;
}
- if (!bm_font->face->glyph_map.has(p_glyph)) {
+ HashMap<int32_t, FontGlyph>::Iterator E = bm_font->face->glyph_map.find(p_glyph);
+ if (!E) {
return 0;
}
- return -bm_font->face->glyph_map[p_glyph].advance.y * 64;
+ return -E->value.advance.y * 64;
}
hb_position_t TextServerAdvanced::_bmp_get_glyph_h_kerning(hb_font_t *p_font, void *p_font_data, hb_codepoint_t p_left_glyph, hb_codepoint_t p_right_glyph, void *p_user_data) {
@@ -178,11 +180,12 @@ hb_bool_t TextServerAdvanced::_bmp_get_glyph_v_origin(hb_font_t *p_font, void *p
return false;
}
- if (!bm_font->face->glyph_map.has(p_glyph)) {
+ HashMap<int32_t, FontGlyph>::Iterator E = bm_font->face->glyph_map.find(p_glyph);
+ if (!E) {
return false;
}
- *r_x = bm_font->face->glyph_map[p_glyph].advance.x * 32;
+ *r_x = E->value.advance.x * 32;
*r_y = -bm_font->face->ascent * 64;
return true;
@@ -195,14 +198,15 @@ hb_bool_t TextServerAdvanced::_bmp_get_glyph_extents(hb_font_t *p_font, void *p_
return false;
}
- if (!bm_font->face->glyph_map.has(p_glyph)) {
+ HashMap<int32_t, FontGlyph>::Iterator E = bm_font->face->glyph_map.find(p_glyph);
+ if (!E) {
return false;
}
r_extents->x_bearing = 0;
r_extents->y_bearing = 0;
- r_extents->width = bm_font->face->glyph_map[p_glyph].rect.size.x * 64;
- r_extents->height = bm_font->face->glyph_map[p_glyph].rect.size.y * 64;
+ r_extents->width = E->value.rect.size.x * 64;
+ r_extents->height = E->value.rect.size.y * 64;
return true;
}
@@ -1188,18 +1192,21 @@ _FORCE_INLINE_ TextServerAdvanced::FontGlyph TextServerAdvanced::rasterize_bitma
/* Font Cache */
/*************************************************************************/
-_FORCE_INLINE_ bool TextServerAdvanced::_ensure_glyph(FontAdvanced *p_font_data, const Vector2i &p_size, int32_t p_glyph) const {
- ERR_FAIL_COND_V(!_ensure_cache_for_size(p_font_data, p_size), false);
+_FORCE_INLINE_ bool TextServerAdvanced::_ensure_glyph(FontAdvanced *p_font_data, const Vector2i &p_size, int32_t p_glyph, FontGlyph &r_glyph) const {
+ FontForSizeAdvanced *fd = nullptr;
+ ERR_FAIL_COND_V(!_ensure_cache_for_size(p_font_data, p_size, fd), false);
int32_t glyph_index = p_glyph & 0xffffff; // Remove subpixel shifts.
- FontForSizeAdvanced *fd = p_font_data->cache[p_size];
- if (fd->glyph_map.has(p_glyph)) {
- return fd->glyph_map[p_glyph].found;
+ HashMap<int32_t, FontGlyph>::Iterator E = fd->glyph_map.find(p_glyph);
+ if (E) {
+ r_glyph = E->value;
+ return E->value.found;
}
if (glyph_index == 0) { // Non graphical or invalid glyph, do not render.
- fd->glyph_map[p_glyph] = FontGlyph();
+ E = fd->glyph_map.insert(p_glyph, FontGlyph());
+ r_glyph = E->value;
return true;
}
@@ -1235,7 +1242,8 @@ _FORCE_INLINE_ bool TextServerAdvanced::_ensure_glyph(FontAdvanced *p_font_data,
int error = FT_Load_Glyph(fd->face, glyph_index, flags);
if (error) {
- fd->glyph_map[p_glyph] = FontGlyph();
+ E = fd->glyph_map.insert(p_glyph, FontGlyph());
+ r_glyph = E->value;
return false;
}
@@ -1339,17 +1347,22 @@ _FORCE_INLINE_ bool TextServerAdvanced::_ensure_glyph(FontAdvanced *p_font_data,
cleanup_stroker:
FT_Stroker_Done(stroker);
}
- fd->glyph_map[p_glyph] = gl;
+ E = fd->glyph_map.insert(p_glyph, gl);
+ r_glyph = E->value;
return gl.found;
}
#endif
- fd->glyph_map[p_glyph] = FontGlyph();
+ E = fd->glyph_map.insert(p_glyph, FontGlyph());
+ r_glyph = E->value;
return false;
}
-_FORCE_INLINE_ bool TextServerAdvanced::_ensure_cache_for_size(FontAdvanced *p_font_data, const Vector2i &p_size) const {
+_FORCE_INLINE_ bool TextServerAdvanced::_ensure_cache_for_size(FontAdvanced *p_font_data, const Vector2i &p_size, FontForSizeAdvanced *&r_cache_for_size) const {
ERR_FAIL_COND_V(p_size.x <= 0, false);
- if (p_font_data->cache.has(p_size)) {
+
+ HashMap<Vector2i, FontForSizeAdvanced *>::Iterator E = p_font_data->cache.find(p_size);
+ if (E) {
+ r_cache_for_size = E->value;
return true;
}
@@ -1840,7 +1853,8 @@ _FORCE_INLINE_ bool TextServerAdvanced::_ensure_cache_for_size(FontAdvanced *p_f
// Init bitmap font.
fd->hb_handle = _bmp_font_create(fd, nullptr);
}
- p_font_data->cache[p_size] = fd;
+ p_font_data->cache.insert(p_size, fd);
+ r_cache_for_size = fd;
return true;
}
@@ -1864,9 +1878,10 @@ hb_font_t *TextServerAdvanced::_font_get_hb_handle(const RID &p_font_rid, int64_
MutexLock lock(fd->mutex);
Vector2i size = _get_size(fd, p_size);
- ERR_FAIL_COND_V(!_ensure_cache_for_size(fd, size), nullptr);
+ FontForSizeAdvanced *ffsd = nullptr;
+ ERR_FAIL_COND_V(!_ensure_cache_for_size(fd, size, ffsd), nullptr);
- return fd->cache[size]->hb_handle;
+ return ffsd->hb_handle;
}
RID TextServerAdvanced::_create_font() {
@@ -1989,7 +2004,8 @@ void TextServerAdvanced::_font_set_style(const RID &p_font_rid, BitField<FontSty
MutexLock lock(fd->mutex);
Vector2i size = _get_size(fd, 16);
- ERR_FAIL_COND(!_ensure_cache_for_size(fd, size));
+ FontForSizeAdvanced *ffsd = nullptr;
+ ERR_FAIL_COND(!_ensure_cache_for_size(fd, size, ffsd));
fd->style_flags = p_style;
}
@@ -1999,7 +2015,8 @@ BitField<TextServer::FontStyle> TextServerAdvanced::_font_get_style(const RID &p
MutexLock lock(fd->mutex);
Vector2i size = _get_size(fd, 16);
- ERR_FAIL_COND_V(!_ensure_cache_for_size(fd, size), 0);
+ FontForSizeAdvanced *ffsd = nullptr;
+ ERR_FAIL_COND_V(!_ensure_cache_for_size(fd, size, ffsd), 0);
return fd->style_flags;
}
@@ -2009,7 +2026,8 @@ void TextServerAdvanced::_font_set_style_name(const RID &p_font_rid, const Strin
MutexLock lock(fd->mutex);
Vector2i size = _get_size(fd, 16);
- ERR_FAIL_COND(!_ensure_cache_for_size(fd, size));
+ FontForSizeAdvanced *ffsd = nullptr;
+ ERR_FAIL_COND(!_ensure_cache_for_size(fd, size, ffsd));
fd->style_name = p_name;
}
@@ -2019,7 +2037,8 @@ String TextServerAdvanced::_font_get_style_name(const RID &p_font_rid) const {
MutexLock lock(fd->mutex);
Vector2i size = _get_size(fd, 16);
- ERR_FAIL_COND_V(!_ensure_cache_for_size(fd, size), String());
+ FontForSizeAdvanced *ffsd = nullptr;
+ ERR_FAIL_COND_V(!_ensure_cache_for_size(fd, size, ffsd), String());
return fd->style_name;
}
@@ -2029,7 +2048,8 @@ void TextServerAdvanced::_font_set_weight(const RID &p_font_rid, int64_t p_weigh
MutexLock lock(fd->mutex);
Vector2i size = _get_size(fd, 16);
- ERR_FAIL_COND(!_ensure_cache_for_size(fd, size));
+ FontForSizeAdvanced *ffsd = nullptr;
+ ERR_FAIL_COND(!_ensure_cache_for_size(fd, size, ffsd));
fd->weight = CLAMP(p_weight, 100, 999);
}
@@ -2039,7 +2059,8 @@ int64_t TextServerAdvanced::_font_get_weight(const RID &p_font_rid) const {
MutexLock lock(fd->mutex);
Vector2i size = _get_size(fd, 16);
- ERR_FAIL_COND_V(!_ensure_cache_for_size(fd, size), 400);
+ FontForSizeAdvanced *ffsd = nullptr;
+ ERR_FAIL_COND_V(!_ensure_cache_for_size(fd, size, ffsd), 400);
return fd->weight;
}
@@ -2049,7 +2070,8 @@ void TextServerAdvanced::_font_set_stretch(const RID &p_font_rid, int64_t p_stre
MutexLock lock(fd->mutex);
Vector2i size = _get_size(fd, 16);
- ERR_FAIL_COND(!_ensure_cache_for_size(fd, size));
+ FontForSizeAdvanced *ffsd = nullptr;
+ ERR_FAIL_COND(!_ensure_cache_for_size(fd, size, ffsd));
fd->stretch = CLAMP(p_stretch, 50, 200);
}
@@ -2059,7 +2081,8 @@ int64_t TextServerAdvanced::_font_get_stretch(const RID &p_font_rid) const {
MutexLock lock(fd->mutex);
Vector2i size = _get_size(fd, 16);
- ERR_FAIL_COND_V(!_ensure_cache_for_size(fd, size), 100);
+ FontForSizeAdvanced *ffsd = nullptr;
+ ERR_FAIL_COND_V(!_ensure_cache_for_size(fd, size, ffsd), 100);
return fd->stretch;
}
@@ -2069,7 +2092,8 @@ void TextServerAdvanced::_font_set_name(const RID &p_font_rid, const String &p_n
MutexLock lock(fd->mutex);
Vector2i size = _get_size(fd, 16);
- ERR_FAIL_COND(!_ensure_cache_for_size(fd, size));
+ FontForSizeAdvanced *ffsd = nullptr;
+ ERR_FAIL_COND(!_ensure_cache_for_size(fd, size, ffsd));
fd->font_name = p_name;
}
@@ -2079,7 +2103,8 @@ String TextServerAdvanced::_font_get_name(const RID &p_font_rid) const {
MutexLock lock(fd->mutex);
Vector2i size = _get_size(fd, 16);
- ERR_FAIL_COND_V(!_ensure_cache_for_size(fd, size), String());
+ FontForSizeAdvanced *ffsd = nullptr;
+ ERR_FAIL_COND_V(!_ensure_cache_for_size(fd, size, ffsd), String());
return fd->font_name;
}
@@ -2089,9 +2114,10 @@ Dictionary TextServerAdvanced::_font_get_ot_name_strings(const RID &p_font_rid)
MutexLock lock(fd->mutex);
Vector2i size = _get_size(fd, 16);
- ERR_FAIL_COND_V(!_ensure_cache_for_size(fd, size), Dictionary());
+ FontForSizeAdvanced *ffsd = nullptr;
+ ERR_FAIL_COND_V(!_ensure_cache_for_size(fd, size, ffsd), Dictionary());
- hb_face_t *hb_face = hb_font_get_face(fd->cache[size]->hb_handle);
+ hb_face_t *hb_face = hb_font_get_face(ffsd->hb_handle);
unsigned int num_entries = 0;
const hb_ot_name_entry_t *names = hb_ot_name_list_names(hb_face, &num_entries);
@@ -2599,8 +2625,9 @@ void TextServerAdvanced::_font_set_ascent(const RID &p_font_rid, int64_t p_size,
MutexLock lock(fd->mutex);
Vector2i size = _get_size(fd, p_size);
- ERR_FAIL_COND(!_ensure_cache_for_size(fd, size));
- fd->cache[size]->ascent = p_ascent;
+ FontForSizeAdvanced *ffsd = nullptr;
+ ERR_FAIL_COND(!_ensure_cache_for_size(fd, size, ffsd));
+ ffsd->ascent = p_ascent;
}
double TextServerAdvanced::_font_get_ascent(const RID &p_font_rid, int64_t p_size) const {
@@ -2610,18 +2637,19 @@ double TextServerAdvanced::_font_get_ascent(const RID &p_font_rid, int64_t p_siz
MutexLock lock(fd->mutex);
Vector2i size = _get_size(fd, p_size);
- ERR_FAIL_COND_V(!_ensure_cache_for_size(fd, size), 0.0);
+ FontForSizeAdvanced *ffsd = nullptr;
+ ERR_FAIL_COND_V(!_ensure_cache_for_size(fd, size, ffsd), 0.0);
if (fd->msdf) {
- return fd->cache[size]->ascent * (double)p_size / (double)fd->msdf_source_size;
+ return ffsd->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;
+ return ffsd->ascent * (double)p_size / (double)fd->fixed_size;
} else {
- return fd->cache[size]->ascent * Math::round((double)p_size / (double)fd->fixed_size);
+ return ffsd->ascent * Math::round((double)p_size / (double)fd->fixed_size);
}
} else {
- return fd->cache[size]->ascent;
+ return ffsd->ascent;
}
}
@@ -2631,8 +2659,9 @@ void TextServerAdvanced::_font_set_descent(const RID &p_font_rid, int64_t p_size
Vector2i size = _get_size(fd, p_size);
- ERR_FAIL_COND(!_ensure_cache_for_size(fd, size));
- fd->cache[size]->descent = p_descent;
+ FontForSizeAdvanced *ffsd = nullptr;
+ ERR_FAIL_COND(!_ensure_cache_for_size(fd, size, ffsd));
+ ffsd->descent = p_descent;
}
double TextServerAdvanced::_font_get_descent(const RID &p_font_rid, int64_t p_size) const {
@@ -2642,18 +2671,19 @@ double TextServerAdvanced::_font_get_descent(const RID &p_font_rid, int64_t p_si
MutexLock lock(fd->mutex);
Vector2i size = _get_size(fd, p_size);
- ERR_FAIL_COND_V(!_ensure_cache_for_size(fd, size), 0.0);
+ FontForSizeAdvanced *ffsd = nullptr;
+ ERR_FAIL_COND_V(!_ensure_cache_for_size(fd, size, ffsd), 0.0);
if (fd->msdf) {
- return fd->cache[size]->descent * (double)p_size / (double)fd->msdf_source_size;
+ return ffsd->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;
+ return ffsd->descent * (double)p_size / (double)fd->fixed_size;
} else {
- return fd->cache[size]->descent * Math::round((double)p_size / (double)fd->fixed_size);
+ return ffsd->descent * Math::round((double)p_size / (double)fd->fixed_size);
}
} else {
- return fd->cache[size]->descent;
+ return ffsd->descent;
}
}
@@ -2664,8 +2694,9 @@ void TextServerAdvanced::_font_set_underline_position(const RID &p_font_rid, int
MutexLock lock(fd->mutex);
Vector2i size = _get_size(fd, p_size);
- ERR_FAIL_COND(!_ensure_cache_for_size(fd, size));
- fd->cache[size]->underline_position = p_underline_position;
+ FontForSizeAdvanced *ffsd = nullptr;
+ ERR_FAIL_COND(!_ensure_cache_for_size(fd, size, ffsd));
+ ffsd->underline_position = p_underline_position;
}
double TextServerAdvanced::_font_get_underline_position(const RID &p_font_rid, int64_t p_size) const {
@@ -2675,18 +2706,19 @@ double TextServerAdvanced::_font_get_underline_position(const RID &p_font_rid, i
MutexLock lock(fd->mutex);
Vector2i size = _get_size(fd, p_size);
- ERR_FAIL_COND_V(!_ensure_cache_for_size(fd, size), 0.0);
+ FontForSizeAdvanced *ffsd = nullptr;
+ ERR_FAIL_COND_V(!_ensure_cache_for_size(fd, size, ffsd), 0.0);
if (fd->msdf) {
- return fd->cache[size]->underline_position * (double)p_size / (double)fd->msdf_source_size;
+ return ffsd->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;
+ return ffsd->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);
+ return ffsd->underline_position * Math::round((double)p_size / (double)fd->fixed_size);
}
} else {
- return fd->cache[size]->underline_position;
+ return ffsd->underline_position;
}
}
@@ -2697,8 +2729,9 @@ void TextServerAdvanced::_font_set_underline_thickness(const RID &p_font_rid, in
MutexLock lock(fd->mutex);
Vector2i size = _get_size(fd, p_size);
- ERR_FAIL_COND(!_ensure_cache_for_size(fd, size));
- fd->cache[size]->underline_thickness = p_underline_thickness;
+ FontForSizeAdvanced *ffsd = nullptr;
+ ERR_FAIL_COND(!_ensure_cache_for_size(fd, size, ffsd));
+ ffsd->underline_thickness = p_underline_thickness;
}
double TextServerAdvanced::_font_get_underline_thickness(const RID &p_font_rid, int64_t p_size) const {
@@ -2708,18 +2741,19 @@ double TextServerAdvanced::_font_get_underline_thickness(const RID &p_font_rid,
MutexLock lock(fd->mutex);
Vector2i size = _get_size(fd, p_size);
- ERR_FAIL_COND_V(!_ensure_cache_for_size(fd, size), 0.0);
+ FontForSizeAdvanced *ffsd = nullptr;
+ ERR_FAIL_COND_V(!_ensure_cache_for_size(fd, size, ffsd), 0.0);
if (fd->msdf) {
- return fd->cache[size]->underline_thickness * (double)p_size / (double)fd->msdf_source_size;
+ return ffsd->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;
+ return ffsd->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);
+ return ffsd->underline_thickness * Math::round((double)p_size / (double)fd->fixed_size);
}
} else {
- return fd->cache[size]->underline_thickness;
+ return ffsd->underline_thickness;
}
}
@@ -2730,13 +2764,15 @@ void TextServerAdvanced::_font_set_scale(const RID &p_font_rid, int64_t p_size,
MutexLock lock(fd->mutex);
Vector2i size = _get_size(fd, p_size);
- ERR_FAIL_COND(!_ensure_cache_for_size(fd, size));
+ FontForSizeAdvanced *ffsd = nullptr;
+ ERR_FAIL_COND(!_ensure_cache_for_size(fd, size, ffsd));
+
#ifdef MODULE_FREETYPE_ENABLED
- if (fd->cache[size]->face) {
+ if (ffsd->face) {
return; // Do not override scale for dynamic fonts, it's calculated automatically.
}
#endif
- fd->cache[size]->scale = p_scale;
+ ffsd->scale = p_scale;
}
double TextServerAdvanced::_font_get_scale(const RID &p_font_rid, int64_t p_size) const {
@@ -2746,18 +2782,19 @@ double TextServerAdvanced::_font_get_scale(const RID &p_font_rid, int64_t p_size
MutexLock lock(fd->mutex);
Vector2i size = _get_size(fd, p_size);
- ERR_FAIL_COND_V(!_ensure_cache_for_size(fd, size), 0.0);
+ FontForSizeAdvanced *ffsd = nullptr;
+ ERR_FAIL_COND_V(!_ensure_cache_for_size(fd, size, ffsd), 0.0);
if (fd->msdf) {
- return fd->cache[size]->scale * (double)p_size / (double)fd->msdf_source_size;
+ return ffsd->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;
+ return ffsd->scale * (double)p_size / (double)fd->fixed_size;
} else {
- return fd->cache[size]->scale * Math::round((double)p_size / (double)fd->fixed_size);
+ return ffsd->scale * Math::round((double)p_size / (double)fd->fixed_size);
}
} else {
- return fd->cache[size]->scale / fd->cache[size]->oversampling;
+ return ffsd->scale / ffsd->oversampling;
}
}
@@ -2768,9 +2805,10 @@ int64_t TextServerAdvanced::_font_get_texture_count(const RID &p_font_rid, const
MutexLock lock(fd->mutex);
Vector2i size = _get_size_outline(fd, p_size);
- ERR_FAIL_COND_V(!_ensure_cache_for_size(fd, size), 0);
+ FontForSizeAdvanced *ffsd = nullptr;
+ ERR_FAIL_COND_V(!_ensure_cache_for_size(fd, size, ffsd), 0);
- return fd->cache[size]->textures.size();
+ return ffsd->textures.size();
}
void TextServerAdvanced::_font_clear_textures(const RID &p_font_rid, const Vector2i &p_size) {
@@ -2779,8 +2817,9 @@ void TextServerAdvanced::_font_clear_textures(const RID &p_font_rid, const Vecto
MutexLock lock(fd->mutex);
Vector2i size = _get_size_outline(fd, p_size);
- ERR_FAIL_COND(!_ensure_cache_for_size(fd, size));
- fd->cache[size]->textures.clear();
+ FontForSizeAdvanced *ffsd = nullptr;
+ ERR_FAIL_COND(!_ensure_cache_for_size(fd, size, ffsd));
+ ffsd->textures.clear();
}
void TextServerAdvanced::_font_remove_texture(const RID &p_font_rid, const Vector2i &p_size, int64_t p_texture_index) {
@@ -2789,10 +2828,11 @@ void TextServerAdvanced::_font_remove_texture(const RID &p_font_rid, const Vecto
MutexLock lock(fd->mutex);
Vector2i size = _get_size_outline(fd, p_size);
- ERR_FAIL_COND(!_ensure_cache_for_size(fd, size));
- ERR_FAIL_INDEX(p_texture_index, fd->cache[size]->textures.size());
+ FontForSizeAdvanced *ffsd = nullptr;
+ ERR_FAIL_COND(!_ensure_cache_for_size(fd, size, ffsd));
+ ERR_FAIL_INDEX(p_texture_index, ffsd->textures.size());
- fd->cache[size]->textures.remove_at(p_texture_index);
+ ffsd->textures.remove_at(p_texture_index);
}
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) {
@@ -2802,13 +2842,14 @@ void TextServerAdvanced::_font_set_texture_image(const RID &p_font_rid, const Ve
MutexLock lock(fd->mutex);
Vector2i size = _get_size_outline(fd, p_size);
- ERR_FAIL_COND(!_ensure_cache_for_size(fd, size));
+ FontForSizeAdvanced *ffsd = nullptr;
+ ERR_FAIL_COND(!_ensure_cache_for_size(fd, size, ffsd));
ERR_FAIL_COND(p_texture_index < 0);
- if (p_texture_index >= fd->cache[size]->textures.size()) {
- fd->cache[size]->textures.resize(p_texture_index + 1);
+ if (p_texture_index >= ffsd->textures.size()) {
+ ffsd->textures.resize(p_texture_index + 1);
}
- ShelfPackTexture &tex = fd->cache[size]->textures.write[p_texture_index];
+ ShelfPackTexture &tex = ffsd->textures.write[p_texture_index];
tex.image = p_image;
tex.texture_w = p_image->get_width();
@@ -2829,10 +2870,11 @@ Ref<Image> TextServerAdvanced::_font_get_texture_image(const RID &p_font_rid, co
MutexLock lock(fd->mutex);
Vector2i size = _get_size_outline(fd, p_size);
- ERR_FAIL_COND_V(!_ensure_cache_for_size(fd, size), Ref<Image>());
- ERR_FAIL_INDEX_V(p_texture_index, fd->cache[size]->textures.size(), Ref<Image>());
+ FontForSizeAdvanced *ffsd = nullptr;
+ ERR_FAIL_COND_V(!_ensure_cache_for_size(fd, size, ffsd), Ref<Image>());
+ ERR_FAIL_INDEX_V(p_texture_index, ffsd->textures.size(), Ref<Image>());
- const ShelfPackTexture &tex = fd->cache[size]->textures[p_texture_index];
+ const ShelfPackTexture &tex = ffsd->textures[p_texture_index];
return tex.image;
}
@@ -2843,13 +2885,14 @@ void TextServerAdvanced::_font_set_texture_offsets(const RID &p_font_rid, const
MutexLock lock(fd->mutex);
Vector2i size = _get_size_outline(fd, p_size);
- ERR_FAIL_COND(!_ensure_cache_for_size(fd, size));
+ FontForSizeAdvanced *ffsd = nullptr;
+ ERR_FAIL_COND(!_ensure_cache_for_size(fd, size, ffsd));
ERR_FAIL_COND(p_texture_index < 0);
- if (p_texture_index >= fd->cache[size]->textures.size()) {
- fd->cache[size]->textures.resize(p_texture_index + 1);
+ if (p_texture_index >= ffsd->textures.size()) {
+ ffsd->textures.resize(p_texture_index + 1);
}
- ShelfPackTexture &tex = fd->cache[size]->textures.write[p_texture_index];
+ ShelfPackTexture &tex = ffsd->textures.write[p_texture_index];
tex.shelves.clear();
for (int32_t i = 0; i < p_offsets.size(); i += 4) {
tex.shelves.push_back(Shelf(p_offsets[i], p_offsets[i + 1], p_offsets[i + 2], p_offsets[i + 3]));
@@ -2862,10 +2905,11 @@ PackedInt32Array TextServerAdvanced::_font_get_texture_offsets(const RID &p_font
MutexLock lock(fd->mutex);
Vector2i size = _get_size_outline(fd, p_size);
- ERR_FAIL_COND_V(!_ensure_cache_for_size(fd, size), PackedInt32Array());
- ERR_FAIL_INDEX_V(p_texture_index, fd->cache[size]->textures.size(), PackedInt32Array());
+ FontForSizeAdvanced *ffsd = nullptr;
+ ERR_FAIL_COND_V(!_ensure_cache_for_size(fd, size, ffsd), PackedInt32Array());
+ ERR_FAIL_INDEX_V(p_texture_index, ffsd->textures.size(), PackedInt32Array());
- const ShelfPackTexture &tex = fd->cache[size]->textures[p_texture_index];
+ const ShelfPackTexture &tex = ffsd->textures[p_texture_index];
PackedInt32Array ret;
ret.resize(tex.shelves.size() * 4);
@@ -2887,10 +2931,11 @@ PackedInt32Array TextServerAdvanced::_font_get_glyph_list(const RID &p_font_rid,
MutexLock lock(fd->mutex);
Vector2i size = _get_size_outline(fd, p_size);
- ERR_FAIL_COND_V(!_ensure_cache_for_size(fd, size), PackedInt32Array());
+ FontForSizeAdvanced *ffsd = nullptr;
+ ERR_FAIL_COND_V(!_ensure_cache_for_size(fd, size, ffsd), PackedInt32Array());
PackedInt32Array ret;
- const HashMap<int32_t, FontGlyph> &gl = fd->cache[size]->glyph_map;
+ const HashMap<int32_t, FontGlyph> &gl = ffsd->glyph_map;
for (const KeyValue<int32_t, FontGlyph> &E : gl) {
ret.push_back(E.key);
}
@@ -2903,9 +2948,10 @@ void TextServerAdvanced::_font_clear_glyphs(const RID &p_font_rid, const Vector2
MutexLock lock(fd->mutex);
Vector2i size = _get_size_outline(fd, p_size);
- ERR_FAIL_COND(!_ensure_cache_for_size(fd, size));
+ FontForSizeAdvanced *ffsd = nullptr;
+ ERR_FAIL_COND(!_ensure_cache_for_size(fd, size, ffsd));
- fd->cache[size]->glyph_map.clear();
+ ffsd->glyph_map.clear();
}
void TextServerAdvanced::_font_remove_glyph(const RID &p_font_rid, const Vector2i &p_size, int64_t p_glyph) {
@@ -2914,9 +2960,10 @@ void TextServerAdvanced::_font_remove_glyph(const RID &p_font_rid, const Vector2
MutexLock lock(fd->mutex);
Vector2i size = _get_size_outline(fd, p_size);
- ERR_FAIL_COND(!_ensure_cache_for_size(fd, size));
+ FontForSizeAdvanced *ffsd = nullptr;
+ ERR_FAIL_COND(!_ensure_cache_for_size(fd, size, ffsd));
- fd->cache[size]->glyph_map.erase(p_glyph);
+ ffsd->glyph_map.erase(p_glyph);
}
double TextServerAdvanced::_get_extra_advance(RID p_font_rid, int p_font_size) const {
@@ -2940,22 +2987,22 @@ Vector2 TextServerAdvanced::_font_get_glyph_advance(const RID &p_font_rid, int64
MutexLock lock(fd->mutex);
Vector2i size = _get_size(fd, p_size);
- ERR_FAIL_COND_V(!_ensure_cache_for_size(fd, size), Vector2());
+ FontForSizeAdvanced *ffsd = nullptr;
+ ERR_FAIL_COND_V(!_ensure_cache_for_size(fd, size, ffsd), Vector2());
int mod = 0;
if (fd->antialiasing == FONT_ANTIALIASING_LCD) {
- TextServer::FontLCDSubpixelLayout layout = (TextServer::FontLCDSubpixelLayout)(int)GLOBAL_GET("gui/theme/lcd_subpixel_layout");
+ TextServer::FontLCDSubpixelLayout layout = lcd_subpixel_layout.get();
if (layout != FONT_LCD_SUBPIXEL_LAYOUT_NONE) {
mod = (layout << 24);
}
}
- if (!_ensure_glyph(fd, size, p_glyph | mod)) {
+ FontGlyph fgl;
+ if (!_ensure_glyph(fd, size, p_glyph | mod, fgl)) {
return Vector2(); // Invalid or non graphicl glyph, do not display errors.
}
- const HashMap<int32_t, FontGlyph> &gl = fd->cache[size]->glyph_map;
-
Vector2 ea;
if (fd->embolden != 0.0) {
ea.x = fd->embolden * double(size.x) / 64.0;
@@ -2963,17 +3010,17 @@ Vector2 TextServerAdvanced::_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;
+ return (fgl.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;
+ return (fgl.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);
+ return (fgl.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();
+ return (fgl.advance + ea).round();
} else {
- return gl[p_glyph | mod].advance + ea;
+ return fgl.advance + ea;
}
}
@@ -2984,12 +3031,13 @@ void TextServerAdvanced::_font_set_glyph_advance(const RID &p_font_rid, int64_t
MutexLock lock(fd->mutex);
Vector2i size = _get_size(fd, p_size);
- ERR_FAIL_COND(!_ensure_cache_for_size(fd, size));
+ FontForSizeAdvanced *ffsd = nullptr;
+ ERR_FAIL_COND(!_ensure_cache_for_size(fd, size, ffsd));
- HashMap<int32_t, FontGlyph> &gl = fd->cache[size]->glyph_map;
+ FontGlyph &fgl = ffsd->glyph_map[p_glyph];
- gl[p_glyph].advance = p_advance;
- gl[p_glyph].found = true;
+ fgl.advance = p_advance;
+ fgl.found = true;
}
Vector2 TextServerAdvanced::_font_get_glyph_offset(const RID &p_font_rid, const Vector2i &p_size, int64_t p_glyph) const {
@@ -2999,32 +3047,32 @@ Vector2 TextServerAdvanced::_font_get_glyph_offset(const RID &p_font_rid, const
MutexLock lock(fd->mutex);
Vector2i size = _get_size_outline(fd, p_size);
- ERR_FAIL_COND_V(!_ensure_cache_for_size(fd, size), Vector2());
+ FontForSizeAdvanced *ffsd = nullptr;
+ ERR_FAIL_COND_V(!_ensure_cache_for_size(fd, size, ffsd), Vector2());
int mod = 0;
if (fd->antialiasing == FONT_ANTIALIASING_LCD) {
- TextServer::FontLCDSubpixelLayout layout = (TextServer::FontLCDSubpixelLayout)(int)GLOBAL_GET("gui/theme/lcd_subpixel_layout");
+ TextServer::FontLCDSubpixelLayout layout = lcd_subpixel_layout.get();
if (layout != FONT_LCD_SUBPIXEL_LAYOUT_NONE) {
mod = (layout << 24);
}
}
- if (!_ensure_glyph(fd, size, p_glyph | mod)) {
+ FontGlyph fgl;
+ if (!_ensure_glyph(fd, size, p_glyph | mod, fgl)) {
return Vector2(); // Invalid or non graphicl glyph, do not display errors.
}
- const HashMap<int32_t, FontGlyph> &gl = fd->cache[size]->glyph_map;
-
if (fd->msdf) {
- return gl[p_glyph | mod].rect.position * (double)p_size.x / (double)fd->msdf_source_size;
+ return fgl.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;
+ return fgl.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);
+ return fgl.rect.position * Math::round((double)p_size.x / (double)fd->fixed_size);
}
} else {
- return gl[p_glyph | mod].rect.position;
+ return fgl.rect.position;
}
}
@@ -3035,12 +3083,13 @@ void TextServerAdvanced::_font_set_glyph_offset(const RID &p_font_rid, const Vec
MutexLock lock(fd->mutex);
Vector2i size = _get_size_outline(fd, p_size);
- ERR_FAIL_COND(!_ensure_cache_for_size(fd, size));
+ FontForSizeAdvanced *ffsd = nullptr;
+ ERR_FAIL_COND(!_ensure_cache_for_size(fd, size, ffsd));
- HashMap<int32_t, FontGlyph> &gl = fd->cache[size]->glyph_map;
+ FontGlyph &fgl = ffsd->glyph_map[p_glyph];
- gl[p_glyph].rect.position = p_offset;
- gl[p_glyph].found = true;
+ fgl.rect.position = p_offset;
+ fgl.found = true;
}
Vector2 TextServerAdvanced::_font_get_glyph_size(const RID &p_font_rid, const Vector2i &p_size, int64_t p_glyph) const {
@@ -3050,32 +3099,32 @@ Vector2 TextServerAdvanced::_font_get_glyph_size(const RID &p_font_rid, const Ve
MutexLock lock(fd->mutex);
Vector2i size = _get_size_outline(fd, p_size);
- ERR_FAIL_COND_V(!_ensure_cache_for_size(fd, size), Vector2());
+ FontForSizeAdvanced *ffsd = nullptr;
+ ERR_FAIL_COND_V(!_ensure_cache_for_size(fd, size, ffsd), Vector2());
int mod = 0;
if (fd->antialiasing == FONT_ANTIALIASING_LCD) {
- TextServer::FontLCDSubpixelLayout layout = (TextServer::FontLCDSubpixelLayout)(int)GLOBAL_GET("gui/theme/lcd_subpixel_layout");
+ TextServer::FontLCDSubpixelLayout layout = lcd_subpixel_layout.get();
if (layout != FONT_LCD_SUBPIXEL_LAYOUT_NONE) {
mod = (layout << 24);
}
}
- if (!_ensure_glyph(fd, size, p_glyph | mod)) {
+ FontGlyph fgl;
+ if (!_ensure_glyph(fd, size, p_glyph | mod, fgl)) {
return Vector2(); // Invalid or non graphicl glyph, do not display errors.
}
- const HashMap<int32_t, FontGlyph> &gl = fd->cache[size]->glyph_map;
-
if (fd->msdf) {
- return gl[p_glyph | mod].rect.size * (double)p_size.x / (double)fd->msdf_source_size;
+ return fgl.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;
+ return fgl.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);
+ return fgl.rect.size * Math::round((double)p_size.x / (double)fd->fixed_size);
}
} else {
- return gl[p_glyph | mod].rect.size;
+ return fgl.rect.size;
}
}
@@ -3086,12 +3135,13 @@ void TextServerAdvanced::_font_set_glyph_size(const RID &p_font_rid, const Vecto
MutexLock lock(fd->mutex);
Vector2i size = _get_size_outline(fd, p_size);
- ERR_FAIL_COND(!_ensure_cache_for_size(fd, size));
+ FontForSizeAdvanced *ffsd = nullptr;
+ ERR_FAIL_COND(!_ensure_cache_for_size(fd, size, ffsd));
- HashMap<int32_t, FontGlyph> &gl = fd->cache[size]->glyph_map;
+ FontGlyph &fgl = ffsd->glyph_map[p_glyph];
- gl[p_glyph].rect.size = p_gl_size;
- gl[p_glyph].found = true;
+ fgl.rect.size = p_gl_size;
+ fgl.found = true;
}
Rect2 TextServerAdvanced::_font_get_glyph_uv_rect(const RID &p_font_rid, const Vector2i &p_size, int64_t p_glyph) const {
@@ -3101,22 +3151,23 @@ Rect2 TextServerAdvanced::_font_get_glyph_uv_rect(const RID &p_font_rid, const V
MutexLock lock(fd->mutex);
Vector2i size = _get_size_outline(fd, p_size);
- ERR_FAIL_COND_V(!_ensure_cache_for_size(fd, size), Rect2());
+ FontForSizeAdvanced *ffsd = nullptr;
+ ERR_FAIL_COND_V(!_ensure_cache_for_size(fd, size, ffsd), Rect2());
int mod = 0;
if (fd->antialiasing == FONT_ANTIALIASING_LCD) {
- TextServer::FontLCDSubpixelLayout layout = (TextServer::FontLCDSubpixelLayout)(int)GLOBAL_GET("gui/theme/lcd_subpixel_layout");
+ TextServer::FontLCDSubpixelLayout layout = lcd_subpixel_layout.get();
if (layout != FONT_LCD_SUBPIXEL_LAYOUT_NONE) {
mod = (layout << 24);
}
}
- if (!_ensure_glyph(fd, size, p_glyph | mod)) {
+ FontGlyph fgl;
+ if (!_ensure_glyph(fd, size, p_glyph | mod, fgl)) {
return Rect2(); // Invalid or non graphicl glyph, do not display errors.
}
- const HashMap<int32_t, FontGlyph> &gl = fd->cache[size]->glyph_map;
- return gl[p_glyph | mod].uv_rect;
+ return fgl.uv_rect;
}
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) {
@@ -3126,12 +3177,13 @@ void TextServerAdvanced::_font_set_glyph_uv_rect(const RID &p_font_rid, const Ve
MutexLock lock(fd->mutex);
Vector2i size = _get_size_outline(fd, p_size);
- ERR_FAIL_COND(!_ensure_cache_for_size(fd, size));
+ FontForSizeAdvanced *ffsd = nullptr;
+ ERR_FAIL_COND(!_ensure_cache_for_size(fd, size, ffsd));
- HashMap<int32_t, FontGlyph> &gl = fd->cache[size]->glyph_map;
+ FontGlyph &fgl = ffsd->glyph_map[p_glyph];
- gl[p_glyph].uv_rect = p_uv_rect;
- gl[p_glyph].found = true;
+ fgl.uv_rect = p_uv_rect;
+ fgl.found = true;
}
int64_t TextServerAdvanced::_font_get_glyph_texture_idx(const RID &p_font_rid, const Vector2i &p_size, int64_t p_glyph) const {
@@ -3141,22 +3193,23 @@ int64_t TextServerAdvanced::_font_get_glyph_texture_idx(const RID &p_font_rid, c
MutexLock lock(fd->mutex);
Vector2i size = _get_size_outline(fd, p_size);
- ERR_FAIL_COND_V(!_ensure_cache_for_size(fd, size), -1);
+ FontForSizeAdvanced *ffsd = nullptr;
+ ERR_FAIL_COND_V(!_ensure_cache_for_size(fd, size, ffsd), -1);
int mod = 0;
if (fd->antialiasing == FONT_ANTIALIASING_LCD) {
- TextServer::FontLCDSubpixelLayout layout = (TextServer::FontLCDSubpixelLayout)(int)GLOBAL_GET("gui/theme/lcd_subpixel_layout");
+ TextServer::FontLCDSubpixelLayout layout = lcd_subpixel_layout.get();
if (layout != FONT_LCD_SUBPIXEL_LAYOUT_NONE) {
mod = (layout << 24);
}
}
- if (!_ensure_glyph(fd, size, p_glyph | mod)) {
+ FontGlyph fgl;
+ if (!_ensure_glyph(fd, size, p_glyph | mod, fgl)) {
return -1; // Invalid or non graphicl glyph, do not display errors.
}
- const HashMap<int32_t, FontGlyph> &gl = fd->cache[size]->glyph_map;
- return gl[p_glyph | mod].texture_idx;
+ return fgl.texture_idx;
}
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) {
@@ -3166,12 +3219,13 @@ void TextServerAdvanced::_font_set_glyph_texture_idx(const RID &p_font_rid, cons
MutexLock lock(fd->mutex);
Vector2i size = _get_size_outline(fd, p_size);
- ERR_FAIL_COND(!_ensure_cache_for_size(fd, size));
+ FontForSizeAdvanced *ffsd = nullptr;
+ ERR_FAIL_COND(!_ensure_cache_for_size(fd, size, ffsd));
- HashMap<int32_t, FontGlyph> &gl = fd->cache[size]->glyph_map;
+ FontGlyph &fgl = ffsd->glyph_map[p_glyph];
- gl[p_glyph].texture_idx = p_texture_idx;
- gl[p_glyph].found = true;
+ fgl.texture_idx = p_texture_idx;
+ fgl.found = true;
}
RID TextServerAdvanced::_font_get_glyph_texture_rid(const RID &p_font_rid, const Vector2i &p_size, int64_t p_glyph) const {
@@ -3181,27 +3235,28 @@ RID TextServerAdvanced::_font_get_glyph_texture_rid(const RID &p_font_rid, const
MutexLock lock(fd->mutex);
Vector2i size = _get_size_outline(fd, p_size);
- ERR_FAIL_COND_V(!_ensure_cache_for_size(fd, size), RID());
+ FontForSizeAdvanced *ffsd = nullptr;
+ ERR_FAIL_COND_V(!_ensure_cache_for_size(fd, size, ffsd), RID());
int mod = 0;
if (fd->antialiasing == FONT_ANTIALIASING_LCD) {
- TextServer::FontLCDSubpixelLayout layout = (TextServer::FontLCDSubpixelLayout)(int)GLOBAL_GET("gui/theme/lcd_subpixel_layout");
+ TextServer::FontLCDSubpixelLayout layout = lcd_subpixel_layout.get();
if (layout != FONT_LCD_SUBPIXEL_LAYOUT_NONE) {
mod = (layout << 24);
}
}
- if (!_ensure_glyph(fd, size, p_glyph | mod)) {
+ FontGlyph fgl;
+ if (!_ensure_glyph(fd, size, p_glyph | mod, fgl)) {
return RID(); // Invalid or non graphicl glyph, do not display errors.
}
- const HashMap<int32_t, FontGlyph> &gl = fd->cache[size]->glyph_map;
- ERR_FAIL_COND_V(gl[p_glyph | mod].texture_idx < -1 || gl[p_glyph | mod].texture_idx >= fd->cache[size]->textures.size(), RID());
+ ERR_FAIL_COND_V(fgl.texture_idx < -1 || fgl.texture_idx >= ffsd->textures.size(), RID());
if (RenderingServer::get_singleton() != nullptr) {
- if (gl[p_glyph | mod].texture_idx != -1) {
- if (fd->cache[size]->textures[gl[p_glyph | mod].texture_idx].dirty) {
- ShelfPackTexture &tex = fd->cache[size]->textures.write[gl[p_glyph | mod].texture_idx];
+ if (fgl.texture_idx != -1) {
+ if (ffsd->textures[fgl.texture_idx].dirty) {
+ ShelfPackTexture &tex = ffsd->textures.write[fgl.texture_idx];
Ref<Image> img = tex.image;
if (fd->mipmaps && !img->has_mipmaps()) {
img = tex.image->duplicate();
@@ -3214,7 +3269,7 @@ RID TextServerAdvanced::_font_get_glyph_texture_rid(const RID &p_font_rid, const
}
tex.dirty = false;
}
- return fd->cache[size]->textures[gl[p_glyph | mod].texture_idx].texture->get_rid();
+ return ffsd->textures[fgl.texture_idx].texture->get_rid();
}
}
@@ -3228,27 +3283,28 @@ Size2 TextServerAdvanced::_font_get_glyph_texture_size(const RID &p_font_rid, co
MutexLock lock(fd->mutex);
Vector2i size = _get_size_outline(fd, p_size);
- ERR_FAIL_COND_V(!_ensure_cache_for_size(fd, size), Size2());
+ FontForSizeAdvanced *ffsd = nullptr;
+ ERR_FAIL_COND_V(!_ensure_cache_for_size(fd, size, ffsd), Size2());
int mod = 0;
if (fd->antialiasing == FONT_ANTIALIASING_LCD) {
- TextServer::FontLCDSubpixelLayout layout = (TextServer::FontLCDSubpixelLayout)(int)GLOBAL_GET("gui/theme/lcd_subpixel_layout");
+ TextServer::FontLCDSubpixelLayout layout = lcd_subpixel_layout.get();
if (layout != FONT_LCD_SUBPIXEL_LAYOUT_NONE) {
mod = (layout << 24);
}
}
- if (!_ensure_glyph(fd, size, p_glyph | mod)) {
+ FontGlyph fgl;
+ if (!_ensure_glyph(fd, size, p_glyph | mod, fgl)) {
return Size2(); // Invalid or non graphicl glyph, do not display errors.
}
- const HashMap<int32_t, FontGlyph> &gl = fd->cache[size]->glyph_map;
- ERR_FAIL_COND_V(gl[p_glyph | mod].texture_idx < -1 || gl[p_glyph | mod].texture_idx >= fd->cache[size]->textures.size(), Size2());
+ ERR_FAIL_COND_V(fgl.texture_idx < -1 || fgl.texture_idx >= ffsd->textures.size(), Size2());
if (RenderingServer::get_singleton() != nullptr) {
- if (gl[p_glyph | mod].texture_idx != -1) {
- if (fd->cache[size]->textures[gl[p_glyph | mod].texture_idx].dirty) {
- ShelfPackTexture &tex = fd->cache[size]->textures.write[gl[p_glyph | mod].texture_idx];
+ if (fgl.texture_idx != -1) {
+ if (ffsd->textures[fgl.texture_idx].dirty) {
+ ShelfPackTexture &tex = ffsd->textures.write[fgl.texture_idx];
Ref<Image> img = tex.image;
if (fd->mipmaps && !img->has_mipmaps()) {
img = tex.image->duplicate();
@@ -3261,7 +3317,7 @@ Size2 TextServerAdvanced::_font_get_glyph_texture_size(const RID &p_font_rid, co
}
tex.dirty = false;
}
- return fd->cache[size]->textures[gl[p_glyph | mod].texture_idx].texture->get_size();
+ return ffsd->textures[fgl.texture_idx].texture->get_size();
}
}
@@ -3275,7 +3331,8 @@ Dictionary TextServerAdvanced::_font_get_glyph_contours(const RID &p_font_rid, i
MutexLock lock(fd->mutex);
Vector2i size = _get_size(fd, p_size);
- ERR_FAIL_COND_V(!_ensure_cache_for_size(fd, size), Dictionary());
+ FontForSizeAdvanced *ffsd = nullptr;
+ ERR_FAIL_COND_V(!_ensure_cache_for_size(fd, size, ffsd), Dictionary());
#ifdef MODULE_FREETYPE_ENABLED
PackedVector3Array points;
@@ -3283,20 +3340,20 @@ Dictionary TextServerAdvanced::_font_get_glyph_contours(const RID &p_font_rid, i
int32_t index = p_index & 0xffffff; // Remove subpixel shifts.
- int error = FT_Load_Glyph(fd->cache[size]->face, index, FT_LOAD_NO_BITMAP | (fd->force_autohinter ? FT_LOAD_FORCE_AUTOHINT : 0));
+ int error = FT_Load_Glyph(ffsd->face, index, FT_LOAD_NO_BITMAP | (fd->force_autohinter ? FT_LOAD_FORCE_AUTOHINT : 0));
ERR_FAIL_COND_V(error, Dictionary());
if (fd->embolden != 0.f) {
FT_Pos strength = fd->embolden * p_size * 4; // 26.6 fractional units (1 / 64).
- FT_Outline_Embolden(&fd->cache[size]->face->glyph->outline, strength);
+ FT_Outline_Embolden(&ffsd->face->glyph->outline, strength);
}
if (fd->transform != Transform2D()) {
FT_Matrix mat = { FT_Fixed(fd->transform[0][0] * 65536), FT_Fixed(fd->transform[0][1] * 65536), FT_Fixed(fd->transform[1][0] * 65536), FT_Fixed(fd->transform[1][1] * 65536) }; // 16.16 fractional units (1 / 65536).
- FT_Outline_Transform(&fd->cache[size]->face->glyph->outline, &mat);
+ FT_Outline_Transform(&ffsd->face->glyph->outline, &mat);
}
- double scale = (1.0 / 64.0) / fd->cache[size]->oversampling * fd->cache[size]->scale;
+ double scale = (1.0 / 64.0) / ffsd->oversampling * ffsd->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) {
@@ -3306,13 +3363,13 @@ Dictionary TextServerAdvanced::_font_get_glyph_contours(const RID &p_font_rid, i
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])));
+ for (short i = 0; i < ffsd->face->glyph->outline.n_points; i++) {
+ points.push_back(Vector3(ffsd->face->glyph->outline.points[i].x * scale, -ffsd->face->glyph->outline.points[i].y * scale, FT_CURVE_TAG(ffsd->face->glyph->outline.tags[i])));
}
- for (short i = 0; i < fd->cache[size]->face->glyph->outline.n_contours; i++) {
- contours.push_back(fd->cache[size]->face->glyph->outline.contours[i]);
+ for (short i = 0; i < ffsd->face->glyph->outline.n_contours; i++) {
+ contours.push_back(ffsd->face->glyph->outline.contours[i]);
}
- bool orientation = (FT_Outline_Get_Orientation(&fd->cache[size]->face->glyph->outline) == FT_ORIENTATION_FILL_RIGHT);
+ bool orientation = (FT_Outline_Get_Orientation(&ffsd->face->glyph->outline) == FT_ORIENTATION_FILL_RIGHT);
Dictionary out;
out["points"] = points;
@@ -3331,7 +3388,8 @@ TypedArray<Vector2i> TextServerAdvanced::_font_get_kerning_list(const RID &p_fon
MutexLock lock(fd->mutex);
Vector2i size = _get_size(fd, p_size);
- ERR_FAIL_COND_V(!_ensure_cache_for_size(fd, size), TypedArray<Vector2i>());
+ FontForSizeAdvanced *ffsd = nullptr;
+ ERR_FAIL_COND_V(!_ensure_cache_for_size(fd, size, ffsd), TypedArray<Vector2i>());
TypedArray<Vector2i> ret;
for (const KeyValue<Vector2i, Vector2> &E : fd->cache[size]->kerning_map) {
@@ -3347,8 +3405,9 @@ void TextServerAdvanced::_font_clear_kerning_map(const RID &p_font_rid, int64_t
MutexLock lock(fd->mutex);
Vector2i size = _get_size(fd, p_size);
- ERR_FAIL_COND(!_ensure_cache_for_size(fd, size));
- fd->cache[size]->kerning_map.clear();
+ FontForSizeAdvanced *ffsd = nullptr;
+ ERR_FAIL_COND(!_ensure_cache_for_size(fd, size, ffsd));
+ ffsd->kerning_map.clear();
}
void TextServerAdvanced::_font_remove_kerning(const RID &p_font_rid, int64_t p_size, const Vector2i &p_glyph_pair) {
@@ -3358,8 +3417,9 @@ void TextServerAdvanced::_font_remove_kerning(const RID &p_font_rid, int64_t p_s
MutexLock lock(fd->mutex);
Vector2i size = _get_size(fd, p_size);
- ERR_FAIL_COND(!_ensure_cache_for_size(fd, size));
- fd->cache[size]->kerning_map.erase(p_glyph_pair);
+ FontForSizeAdvanced *ffsd = nullptr;
+ ERR_FAIL_COND(!_ensure_cache_for_size(fd, size, ffsd));
+ ffsd->kerning_map.erase(p_glyph_pair);
}
void TextServerAdvanced::_font_set_kerning(const RID &p_font_rid, int64_t p_size, const Vector2i &p_glyph_pair, const Vector2 &p_kerning) {
@@ -3369,8 +3429,9 @@ void TextServerAdvanced::_font_set_kerning(const RID &p_font_rid, int64_t p_size
MutexLock lock(fd->mutex);
Vector2i size = _get_size(fd, p_size);
- ERR_FAIL_COND(!_ensure_cache_for_size(fd, size));
- fd->cache[size]->kerning_map[p_glyph_pair] = p_kerning;
+ FontForSizeAdvanced *ffsd = nullptr;
+ ERR_FAIL_COND(!_ensure_cache_for_size(fd, size, ffsd));
+ ffsd->kerning_map[p_glyph_pair] = p_kerning;
}
Vector2 TextServerAdvanced::_font_get_kerning(const RID &p_font_rid, int64_t p_size, const Vector2i &p_glyph_pair) const {
@@ -3380,9 +3441,10 @@ Vector2 TextServerAdvanced::_font_get_kerning(const RID &p_font_rid, int64_t p_s
MutexLock lock(fd->mutex);
Vector2i size = _get_size(fd, p_size);
- ERR_FAIL_COND_V(!_ensure_cache_for_size(fd, size), Vector2());
+ FontForSizeAdvanced *ffsd = nullptr;
+ ERR_FAIL_COND_V(!_ensure_cache_for_size(fd, size, ffsd), Vector2());
- const HashMap<Vector2i, Vector2> &kern = fd->cache[size]->kerning_map;
+ const HashMap<Vector2i, Vector2> &kern = ffsd->kerning_map;
if (kern.has(p_glyph_pair)) {
if (fd->msdf) {
@@ -3398,9 +3460,9 @@ Vector2 TextServerAdvanced::_font_get_kerning(const RID &p_font_rid, int64_t p_s
}
} else {
#ifdef MODULE_FREETYPE_ENABLED
- if (fd->cache[size]->face) {
+ if (ffsd->face) {
FT_Vector delta;
- FT_Get_Kerning(fd->cache[size]->face, p_glyph_pair.x, p_glyph_pair.y, FT_KERNING_DEFAULT, &delta);
+ FT_Get_Kerning(ffsd->face, p_glyph_pair.x, p_glyph_pair.y, 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) {
@@ -3426,14 +3488,15 @@ int64_t TextServerAdvanced::_font_get_glyph_index(const RID &p_font_rid, int64_t
MutexLock lock(fd->mutex);
Vector2i size = _get_size(fd, p_size);
- ERR_FAIL_COND_V(!_ensure_cache_for_size(fd, size), 0);
+ FontForSizeAdvanced *ffsd = nullptr;
+ ERR_FAIL_COND_V(!_ensure_cache_for_size(fd, size, ffsd), 0);
#ifdef MODULE_FREETYPE_ENABLED
- if (fd->cache[size]->face) {
+ if (ffsd->face) {
if (p_variation_selector) {
- return FT_Face_GetCharVariantIndex(fd->cache[size]->face, p_char, p_variation_selector);
+ return FT_Face_GetCharVariantIndex(ffsd->face, p_char, p_variation_selector);
} else {
- return FT_Get_Char_Index(fd->cache[size]->face, p_char);
+ return FT_Get_Char_Index(ffsd->face, p_char);
}
} else {
return (int64_t)p_char;
@@ -3449,23 +3512,24 @@ int64_t TextServerAdvanced::_font_get_char_from_glyph_index(const RID &p_font_ri
MutexLock lock(fd->mutex);
Vector2i size = _get_size(fd, p_size);
- ERR_FAIL_COND_V(!_ensure_cache_for_size(fd, size), 0);
+ FontForSizeAdvanced *ffsd = nullptr;
+ ERR_FAIL_COND_V(!_ensure_cache_for_size(fd, size, ffsd), 0);
#ifdef MODULE_FREETYPE_ENABLED
- if (fd->cache[size]->inv_glyph_map.is_empty()) {
- FT_Face face = fd->cache[size]->face;
+ if (ffsd->inv_glyph_map.is_empty()) {
+ FT_Face face = ffsd->face;
FT_UInt gindex;
FT_ULong charcode = FT_Get_First_Char(face, &gindex);
while (gindex != 0) {
if (charcode != 0) {
- fd->cache[size]->inv_glyph_map[gindex] = charcode;
+ ffsd->inv_glyph_map[gindex] = charcode;
}
charcode = FT_Get_Next_Char(face, charcode, &gindex);
}
}
- if (fd->cache[size]->inv_glyph_map.has(p_glyph_index)) {
- return fd->cache[size]->inv_glyph_map[p_glyph_index];
+ if (ffsd->inv_glyph_map.has(p_glyph_index)) {
+ return ffsd->inv_glyph_map[p_glyph_index];
} else {
return 0;
}
@@ -3482,17 +3546,19 @@ bool TextServerAdvanced::_font_has_char(const RID &p_font_rid, int64_t p_char) c
}
MutexLock lock(fd->mutex);
+ FontForSizeAdvanced *ffsd = nullptr;
if (fd->cache.is_empty()) {
- ERR_FAIL_COND_V(!_ensure_cache_for_size(fd, fd->msdf ? Vector2i(fd->msdf_source_size, 0) : Vector2i(16, 0)), false);
+ ERR_FAIL_COND_V(!_ensure_cache_for_size(fd, fd->msdf ? Vector2i(fd->msdf_source_size, 0) : Vector2i(16, 0), ffsd), false);
+ } else {
+ ffsd = fd->cache.begin()->value;
}
- FontForSizeAdvanced *at_size = fd->cache.begin()->value;
#ifdef MODULE_FREETYPE_ENABLED
- if (at_size && at_size->face) {
- return FT_Get_Char_Index(at_size->face, p_char) != 0;
+ if (ffsd->face) {
+ return FT_Get_Char_Index(ffsd->face, p_char) != 0;
}
#endif
- return (at_size) ? at_size->glyph_map.has((int32_t)p_char) : false;
+ return ffsd->glyph_map.has((int32_t)p_char);
}
String TextServerAdvanced::_font_get_supported_chars(const RID &p_font_rid) const {
@@ -3500,30 +3566,30 @@ String TextServerAdvanced::_font_get_supported_chars(const RID &p_font_rid) cons
ERR_FAIL_NULL_V(fd, String());
MutexLock lock(fd->mutex);
+ FontForSizeAdvanced *ffsd = nullptr;
if (fd->cache.is_empty()) {
- ERR_FAIL_COND_V(!_ensure_cache_for_size(fd, fd->msdf ? Vector2i(fd->msdf_source_size, 0) : Vector2i(16, 0)), String());
+ ERR_FAIL_COND_V(!_ensure_cache_for_size(fd, fd->msdf ? Vector2i(fd->msdf_source_size, 0) : Vector2i(16, 0), ffsd), String());
+ } else {
+ ffsd = fd->cache.begin()->value;
}
- FontForSizeAdvanced *at_size = fd->cache.begin()->value;
String chars;
#ifdef MODULE_FREETYPE_ENABLED
- if (at_size && at_size->face) {
+ if (ffsd->face) {
FT_UInt gindex;
- FT_ULong charcode = FT_Get_First_Char(at_size->face, &gindex);
+ FT_ULong charcode = FT_Get_First_Char(ffsd->face, &gindex);
while (gindex != 0) {
if (charcode != 0) {
chars = chars + String::chr(charcode);
}
- charcode = FT_Get_Next_Char(at_size->face, charcode, &gindex);
+ charcode = FT_Get_Next_Char(ffsd->face, charcode, &gindex);
}
return chars;
}
#endif
- if (at_size) {
- const HashMap<int32_t, FontGlyph> &gl = at_size->glyph_map;
- for (const KeyValue<int32_t, FontGlyph> &E : gl) {
- chars = chars + String::chr(E.key);
- }
+ const HashMap<int32_t, FontGlyph> &gl = ffsd->glyph_map;
+ for (const KeyValue<int32_t, FontGlyph> &E : gl) {
+ chars = chars + String::chr(E.key);
}
return chars;
}
@@ -3533,10 +3599,12 @@ PackedInt32Array TextServerAdvanced::_font_get_supported_glyphs(const RID &p_fon
ERR_FAIL_NULL_V(fd, PackedInt32Array());
MutexLock lock(fd->mutex);
+ FontForSizeAdvanced *at_size = nullptr;
if (fd->cache.is_empty()) {
- ERR_FAIL_COND_V(!_ensure_cache_for_size(fd, fd->msdf ? Vector2i(fd->msdf_source_size, 0) : Vector2i(16, 0)), PackedInt32Array());
+ ERR_FAIL_COND_V(!_ensure_cache_for_size(fd, fd->msdf ? Vector2i(fd->msdf_source_size, 0) : Vector2i(16, 0), at_size), PackedInt32Array());
+ } else {
+ at_size = fd->cache.begin()->value;
}
- FontForSizeAdvanced *at_size = fd->cache.begin()->value;
PackedInt32Array glyphs;
#ifdef MODULE_FREETYPE_ENABLED
@@ -3567,25 +3635,27 @@ void TextServerAdvanced::_font_render_range(const RID &p_font_rid, const Vector2
MutexLock lock(fd->mutex);
Vector2i size = _get_size_outline(fd, p_size);
- ERR_FAIL_COND(!_ensure_cache_for_size(fd, size));
+ FontForSizeAdvanced *ffsd = nullptr;
+ ERR_FAIL_COND(!_ensure_cache_for_size(fd, size, ffsd));
for (int64_t i = p_start; i <= p_end; i++) {
#ifdef MODULE_FREETYPE_ENABLED
- int32_t idx = FT_Get_Char_Index(fd->cache[size]->face, i);
- if (fd->cache[size]->face) {
+ int32_t idx = FT_Get_Char_Index(ffsd->face, i);
+ if (ffsd->face) {
+ FontGlyph fgl;
if (fd->msdf) {
- _ensure_glyph(fd, size, (int32_t)idx);
+ _ensure_glyph(fd, size, (int32_t)idx, fgl);
} else {
for (int aa = 0; aa < ((fd->antialiasing == FONT_ANTIALIASING_LCD) ? FONT_LCD_SUBPIXEL_LAYOUT_MAX : 1); aa++) {
if ((fd->subpixel_positioning == SUBPIXEL_POSITIONING_ONE_QUARTER) || (fd->subpixel_positioning == SUBPIXEL_POSITIONING_AUTO && size.x <= SUBPIXEL_POSITIONING_ONE_QUARTER_MAX_SIZE)) {
- _ensure_glyph(fd, size, (int32_t)idx | (0 << 27) | (aa << 24));
- _ensure_glyph(fd, size, (int32_t)idx | (1 << 27) | (aa << 24));
- _ensure_glyph(fd, size, (int32_t)idx | (2 << 27) | (aa << 24));
- _ensure_glyph(fd, size, (int32_t)idx | (3 << 27) | (aa << 24));
+ _ensure_glyph(fd, size, (int32_t)idx | (0 << 27) | (aa << 24), fgl);
+ _ensure_glyph(fd, size, (int32_t)idx | (1 << 27) | (aa << 24), fgl);
+ _ensure_glyph(fd, size, (int32_t)idx | (2 << 27) | (aa << 24), fgl);
+ _ensure_glyph(fd, size, (int32_t)idx | (3 << 27) | (aa << 24), fgl);
} else if ((fd->subpixel_positioning == SUBPIXEL_POSITIONING_ONE_HALF) || (fd->subpixel_positioning == SUBPIXEL_POSITIONING_AUTO && size.x <= SUBPIXEL_POSITIONING_ONE_HALF_MAX_SIZE)) {
- _ensure_glyph(fd, size, (int32_t)idx | (1 << 27) | (aa << 24));
- _ensure_glyph(fd, size, (int32_t)idx | (0 << 27) | (aa << 24));
+ _ensure_glyph(fd, size, (int32_t)idx | (1 << 27) | (aa << 24), fgl);
+ _ensure_glyph(fd, size, (int32_t)idx | (0 << 27) | (aa << 24), fgl);
} else {
- _ensure_glyph(fd, size, (int32_t)idx | (aa << 24));
+ _ensure_glyph(fd, size, (int32_t)idx | (aa << 24), fgl);
}
}
}
@@ -3600,24 +3670,26 @@ void TextServerAdvanced::_font_render_glyph(const RID &p_font_rid, const Vector2
MutexLock lock(fd->mutex);
Vector2i size = _get_size_outline(fd, p_size);
- ERR_FAIL_COND(!_ensure_cache_for_size(fd, size));
+ FontForSizeAdvanced *ffsd = nullptr;
+ ERR_FAIL_COND(!_ensure_cache_for_size(fd, size, ffsd));
#ifdef MODULE_FREETYPE_ENABLED
int32_t idx = p_index & 0xffffff; // Remove subpixel shifts.
- if (fd->cache[size]->face) {
+ if (ffsd->face) {
+ FontGlyph fgl;
if (fd->msdf) {
- _ensure_glyph(fd, size, (int32_t)idx);
+ _ensure_glyph(fd, size, (int32_t)idx, fgl);
} else {
for (int aa = 0; aa < ((fd->antialiasing == FONT_ANTIALIASING_LCD) ? FONT_LCD_SUBPIXEL_LAYOUT_MAX : 1); aa++) {
if ((fd->subpixel_positioning == SUBPIXEL_POSITIONING_ONE_QUARTER) || (fd->subpixel_positioning == SUBPIXEL_POSITIONING_AUTO && size.x <= SUBPIXEL_POSITIONING_ONE_QUARTER_MAX_SIZE)) {
- _ensure_glyph(fd, size, (int32_t)idx | (0 << 27) | (aa << 24));
- _ensure_glyph(fd, size, (int32_t)idx | (1 << 27) | (aa << 24));
- _ensure_glyph(fd, size, (int32_t)idx | (2 << 27) | (aa << 24));
- _ensure_glyph(fd, size, (int32_t)idx | (3 << 27) | (aa << 24));
+ _ensure_glyph(fd, size, (int32_t)idx | (0 << 27) | (aa << 24), fgl);
+ _ensure_glyph(fd, size, (int32_t)idx | (1 << 27) | (aa << 24), fgl);
+ _ensure_glyph(fd, size, (int32_t)idx | (2 << 27) | (aa << 24), fgl);
+ _ensure_glyph(fd, size, (int32_t)idx | (3 << 27) | (aa << 24), fgl);
} else if ((fd->subpixel_positioning == SUBPIXEL_POSITIONING_ONE_HALF) || (fd->subpixel_positioning == SUBPIXEL_POSITIONING_AUTO && size.x <= SUBPIXEL_POSITIONING_ONE_HALF_MAX_SIZE)) {
- _ensure_glyph(fd, size, (int32_t)idx | (1 << 27) | (aa << 24));
- _ensure_glyph(fd, size, (int32_t)idx | (0 << 27) | (aa << 24));
+ _ensure_glyph(fd, size, (int32_t)idx | (1 << 27) | (aa << 24), fgl);
+ _ensure_glyph(fd, size, (int32_t)idx | (0 << 27) | (aa << 24), fgl);
} else {
- _ensure_glyph(fd, size, (int32_t)idx | (aa << 24));
+ _ensure_glyph(fd, size, (int32_t)idx | (aa << 24), fgl);
}
}
}
@@ -3634,16 +3706,17 @@ void TextServerAdvanced::_font_draw_glyph(const RID &p_font_rid, const RID &p_ca
MutexLock lock(fd->mutex);
Vector2i size = _get_size(fd, p_size);
- ERR_FAIL_COND(!_ensure_cache_for_size(fd, size));
+ FontForSizeAdvanced *ffsd = nullptr;
+ ERR_FAIL_COND(!_ensure_cache_for_size(fd, size, ffsd));
int32_t index = p_index & 0xffffff; // Remove subpixel shifts.
bool lcd_aa = false;
#ifdef MODULE_FREETYPE_ENABLED
- if (!fd->msdf && fd->cache[size]->face) {
+ if (!fd->msdf && ffsd->face) {
// LCD layout, bits 24, 25, 26
if (fd->antialiasing == FONT_ANTIALIASING_LCD) {
- TextServer::FontLCDSubpixelLayout layout = (TextServer::FontLCDSubpixelLayout)(int)GLOBAL_GET("gui/theme/lcd_subpixel_layout");
+ TextServer::FontLCDSubpixelLayout layout = lcd_subpixel_layout.get();
if (layout != FONT_LCD_SUBPIXEL_LAYOUT_NONE) {
lcd_aa = true;
index = index | (layout << 24);
@@ -3660,24 +3733,24 @@ void TextServerAdvanced::_font_draw_glyph(const RID &p_font_rid, const RID &p_ca
}
#endif
- if (!_ensure_glyph(fd, size, index)) {
+ FontGlyph fgl;
+ if (!_ensure_glyph(fd, size, index, fgl)) {
return; // Invalid or non-graphical glyph, do not display errors, nothing to draw.
}
- const FontGlyph &gl = fd->cache[size]->glyph_map[index];
- if (gl.found) {
- ERR_FAIL_COND(gl.texture_idx < -1 || gl.texture_idx >= fd->cache[size]->textures.size());
+ if (fgl.found) {
+ ERR_FAIL_COND(fgl.texture_idx < -1 || fgl.texture_idx >= ffsd->textures.size());
- if (gl.texture_idx != -1) {
+ if (fgl.texture_idx != -1) {
Color modulate = p_color;
#ifdef MODULE_FREETYPE_ENABLED
- if (fd->cache[size]->face && fd->cache[size]->textures[gl.texture_idx].image.is_valid() && (fd->cache[size]->textures[gl.texture_idx].image->get_format() == Image::FORMAT_RGBA8) && !lcd_aa && !fd->msdf) {
+ if (ffsd->face && ffsd->textures[fgl.texture_idx].image.is_valid() && (ffsd->textures[fgl.texture_idx].image->get_format() == Image::FORMAT_RGBA8) && !lcd_aa && !fd->msdf) {
modulate.r = modulate.g = modulate.b = 1.0;
}
#endif
if (RenderingServer::get_singleton() != nullptr) {
- if (fd->cache[size]->textures[gl.texture_idx].dirty) {
- ShelfPackTexture &tex = fd->cache[size]->textures.write[gl.texture_idx];
+ if (ffsd->textures[fgl.texture_idx].dirty) {
+ ShelfPackTexture &tex = ffsd->textures.write[fgl.texture_idx];
Ref<Image> img = tex.image;
if (fd->mipmaps && !img->has_mipmaps()) {
img = tex.image->duplicate();
@@ -3690,12 +3763,12 @@ void TextServerAdvanced::_font_draw_glyph(const RID &p_font_rid, const RID &p_ca
}
tex.dirty = false;
}
- RID texture = fd->cache[size]->textures[gl.texture_idx].texture->get_rid();
+ RID texture = ffsd->textures[fgl.texture_idx].texture->get_rid();
if (fd->msdf) {
Point2 cpos = p_pos;
- cpos += gl.rect.position * (double)p_size / (double)fd->msdf_source_size;
- Size2 csize = gl.rect.size * (double)p_size / (double)fd->msdf_source_size;
- RenderingServer::get_singleton()->canvas_item_add_msdf_texture_rect_region(p_canvas, Rect2(cpos, csize), texture, gl.uv_rect, modulate, 0, fd->msdf_range, (double)p_size / (double)fd->msdf_source_size);
+ cpos += fgl.rect.position * (double)p_size / (double)fd->msdf_source_size;
+ Size2 csize = fgl.rect.size * (double)p_size / (double)fd->msdf_source_size;
+ RenderingServer::get_singleton()->canvas_item_add_msdf_texture_rect_region(p_canvas, Rect2(cpos, csize), texture, fgl.uv_rect, modulate, 0, fd->msdf_range, (double)p_size / (double)fd->msdf_source_size);
} else {
double scale = _font_get_scale(p_font_rid, p_size);
Point2 cpos = p_pos;
@@ -3708,8 +3781,8 @@ void TextServerAdvanced::_font_draw_glyph(const RID &p_font_rid, const RID &p_ca
cpos.y = Math::floor(cpos.y);
cpos.x = Math::floor(cpos.x);
}
- Vector2 gpos = gl.rect.position;
- Size2 csize = gl.rect.size;
+ Vector2 gpos = fgl.rect.position;
+ Size2 csize = fgl.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;
@@ -3723,9 +3796,9 @@ void TextServerAdvanced::_font_draw_glyph(const RID &p_font_rid, const RID &p_ca
}
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);
+ RenderingServer::get_singleton()->canvas_item_add_lcd_texture_rect_region(p_canvas, Rect2(cpos, csize), texture, fgl.uv_rect, modulate);
} else {
- RenderingServer::get_singleton()->canvas_item_add_texture_rect_region(p_canvas, Rect2(cpos, csize), texture, gl.uv_rect, modulate, false, false);
+ RenderingServer::get_singleton()->canvas_item_add_texture_rect_region(p_canvas, Rect2(cpos, csize), texture, fgl.uv_rect, modulate, false, false);
}
}
}
@@ -3742,16 +3815,17 @@ void TextServerAdvanced::_font_draw_glyph_outline(const RID &p_font_rid, const R
MutexLock lock(fd->mutex);
Vector2i size = _get_size_outline(fd, Vector2i(p_size, p_outline_size));
- ERR_FAIL_COND(!_ensure_cache_for_size(fd, size));
+ FontForSizeAdvanced *ffsd = nullptr;
+ ERR_FAIL_COND(!_ensure_cache_for_size(fd, size, ffsd));
int32_t index = p_index & 0xffffff; // Remove subpixel shifts.
bool lcd_aa = false;
#ifdef MODULE_FREETYPE_ENABLED
- if (!fd->msdf && fd->cache[size]->face) {
+ if (!fd->msdf && ffsd->face) {
// LCD layout, bits 24, 25, 26
if (fd->antialiasing == FONT_ANTIALIASING_LCD) {
- TextServer::FontLCDSubpixelLayout layout = (TextServer::FontLCDSubpixelLayout)(int)GLOBAL_GET("gui/theme/lcd_subpixel_layout");
+ TextServer::FontLCDSubpixelLayout layout = lcd_subpixel_layout.get();
if (layout != FONT_LCD_SUBPIXEL_LAYOUT_NONE) {
lcd_aa = true;
index = index | (layout << 24);
@@ -3768,24 +3842,24 @@ void TextServerAdvanced::_font_draw_glyph_outline(const RID &p_font_rid, const R
}
#endif
- if (!_ensure_glyph(fd, size, index)) {
+ FontGlyph fgl;
+ if (!_ensure_glyph(fd, size, index, fgl)) {
return; // Invalid or non-graphical glyph, do not display errors, nothing to draw.
}
- const FontGlyph &gl = fd->cache[size]->glyph_map[index];
- if (gl.found) {
- ERR_FAIL_COND(gl.texture_idx < -1 || gl.texture_idx >= fd->cache[size]->textures.size());
+ if (fgl.found) {
+ ERR_FAIL_COND(fgl.texture_idx < -1 || fgl.texture_idx >= ffsd->textures.size());
- if (gl.texture_idx != -1) {
+ if (fgl.texture_idx != -1) {
Color modulate = p_color;
#ifdef MODULE_FREETYPE_ENABLED
- if (fd->cache[size]->face && fd->cache[size]->textures[gl.texture_idx].image.is_valid() && (fd->cache[size]->textures[gl.texture_idx].image->get_format() == Image::FORMAT_RGBA8) && !lcd_aa && !fd->msdf) {
+ if (ffsd->face && fd->cache[size]->textures[fgl.texture_idx].image.is_valid() && (ffsd->textures[fgl.texture_idx].image->get_format() == Image::FORMAT_RGBA8) && !lcd_aa && !fd->msdf) {
modulate.r = modulate.g = modulate.b = 1.0;
}
#endif
if (RenderingServer::get_singleton() != nullptr) {
- if (fd->cache[size]->textures[gl.texture_idx].dirty) {
- ShelfPackTexture &tex = fd->cache[size]->textures.write[gl.texture_idx];
+ if (ffsd->textures[fgl.texture_idx].dirty) {
+ ShelfPackTexture &tex = ffsd->textures.write[fgl.texture_idx];
Ref<Image> img = tex.image;
if (fd->mipmaps && !img->has_mipmaps()) {
img = tex.image->duplicate();
@@ -3798,12 +3872,12 @@ void TextServerAdvanced::_font_draw_glyph_outline(const RID &p_font_rid, const R
}
tex.dirty = false;
}
- RID texture = fd->cache[size]->textures[gl.texture_idx].texture->get_rid();
+ RID texture = ffsd->textures[fgl.texture_idx].texture->get_rid();
if (fd->msdf) {
Point2 cpos = p_pos;
- cpos += gl.rect.position * (double)p_size / (double)fd->msdf_source_size;
- Size2 csize = gl.rect.size * (double)p_size / (double)fd->msdf_source_size;
- RenderingServer::get_singleton()->canvas_item_add_msdf_texture_rect_region(p_canvas, Rect2(cpos, csize), texture, gl.uv_rect, modulate, p_outline_size, fd->msdf_range, (double)p_size / (double)fd->msdf_source_size);
+ cpos += fgl.rect.position * (double)p_size / (double)fd->msdf_source_size;
+ Size2 csize = fgl.rect.size * (double)p_size / (double)fd->msdf_source_size;
+ RenderingServer::get_singleton()->canvas_item_add_msdf_texture_rect_region(p_canvas, Rect2(cpos, csize), texture, fgl.uv_rect, modulate, p_outline_size, fd->msdf_range, (double)p_size / (double)fd->msdf_source_size);
} else {
Point2 cpos = p_pos;
double scale = _font_get_scale(p_font_rid, p_size);
@@ -3816,8 +3890,8 @@ void TextServerAdvanced::_font_draw_glyph_outline(const RID &p_font_rid, const R
cpos.y = Math::floor(cpos.y);
cpos.x = Math::floor(cpos.x);
}
- Vector2 gpos = gl.rect.position;
- Size2 csize = gl.rect.size;
+ Vector2 gpos = fgl.rect.position;
+ Size2 csize = fgl.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;
@@ -3831,9 +3905,9 @@ void TextServerAdvanced::_font_draw_glyph_outline(const RID &p_font_rid, const R
}
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);
+ RenderingServer::get_singleton()->canvas_item_add_lcd_texture_rect_region(p_canvas, Rect2(cpos, csize), texture, fgl.uv_rect, modulate);
} else {
- RenderingServer::get_singleton()->canvas_item_add_texture_rect_region(p_canvas, Rect2(cpos, csize), texture, gl.uv_rect, modulate, false, false);
+ RenderingServer::get_singleton()->canvas_item_add_texture_rect_region(p_canvas, Rect2(cpos, csize), texture, fgl.uv_rect, modulate, false, false);
}
}
}
@@ -3898,7 +3972,8 @@ bool TextServerAdvanced::_font_is_script_supported(const RID &p_font_rid, const
return fd->script_support_overrides[p_script];
} else {
Vector2i size = _get_size(fd, 16);
- ERR_FAIL_COND_V(!_ensure_cache_for_size(fd, size), false);
+ FontForSizeAdvanced *ffsd = nullptr;
+ ERR_FAIL_COND_V(!_ensure_cache_for_size(fd, size, ffsd), false);
return fd->supported_scripts.has(hb_tag_from_string(p_script.ascii().get_data(), -1));
}
}
@@ -3945,7 +4020,8 @@ void TextServerAdvanced::_font_set_opentype_feature_overrides(const RID &p_font_
MutexLock lock(fd->mutex);
Vector2i size = _get_size(fd, 16);
- ERR_FAIL_COND(!_ensure_cache_for_size(fd, size));
+ FontForSizeAdvanced *ffsd = nullptr;
+ ERR_FAIL_COND(!_ensure_cache_for_size(fd, size, ffsd));
fd->feature_overrides = p_overrides;
}
@@ -3963,7 +4039,8 @@ Dictionary TextServerAdvanced::_font_supported_feature_list(const RID &p_font_ri
MutexLock lock(fd->mutex);
Vector2i size = _get_size(fd, 16);
- ERR_FAIL_COND_V(!_ensure_cache_for_size(fd, size), Dictionary());
+ FontForSizeAdvanced *ffsd = nullptr;
+ ERR_FAIL_COND_V(!_ensure_cache_for_size(fd, size, ffsd), Dictionary());
return fd->supported_features;
}
@@ -3973,7 +4050,8 @@ Dictionary TextServerAdvanced::_font_supported_variation_list(const RID &p_font_
MutexLock lock(fd->mutex);
Vector2i size = _get_size(fd, 16);
- ERR_FAIL_COND_V(!_ensure_cache_for_size(fd, size), Dictionary());
+ FontForSizeAdvanced *ffsd = nullptr;
+ ERR_FAIL_COND_V(!_ensure_cache_for_size(fd, size, ffsd), Dictionary());
return fd->supported_varaitions;
}
@@ -4048,7 +4126,7 @@ int64_t TextServerAdvanced::_convert_pos_inv(const ShapedTextDataAdvanced *p_sd,
}
void TextServerAdvanced::invalidate(TextServerAdvanced::ShapedTextDataAdvanced *p_shaped, bool p_text) {
- p_shaped->valid = false;
+ p_shaped->valid.clear();
p_shaped->sort_valid = false;
p_shaped->line_breaks_valid = false;
p_shaped->justification_ops_valid = false;
@@ -4404,7 +4482,7 @@ bool TextServerAdvanced::_shaped_text_resize_object(const RID &p_shaped, const V
sd->objects[p_key].rect.size = p_size;
sd->objects[p_key].inline_align = p_inline_align;
sd->objects[p_key].baseline = p_baseline;
- if (sd->valid) {
+ if (sd->valid.is_set()) {
// Recalc string metrics.
sd->ascent = 0;
sd->descent = 0;
@@ -4548,7 +4626,7 @@ RID TextServerAdvanced::_shaped_text_substr(const RID &p_shaped, int64_t p_start
if (sd->parent != RID()) {
return _shaped_text_substr(sd->parent, p_start, p_length);
}
- if (!sd->valid) {
+ if (!sd->valid.is_set()) {
const_cast<TextServerAdvanced *>(this)->_shaped_text_shape(p_shaped);
}
ERR_FAIL_COND_V(p_start < 0 || p_length < 0, RID());
@@ -4576,7 +4654,7 @@ RID TextServerAdvanced::_shaped_text_substr(const RID &p_shaped, int64_t p_start
}
bool TextServerAdvanced::_shape_substr(ShapedTextDataAdvanced *p_new_sd, const ShapedTextDataAdvanced *p_sd, int64_t p_start, int64_t p_length) const {
- if (p_new_sd->valid) {
+ if (p_new_sd->valid.is_set()) {
return true;
}
@@ -4725,7 +4803,7 @@ bool TextServerAdvanced::_shape_substr(ShapedTextDataAdvanced *p_new_sd, const S
_realign(p_new_sd);
}
- p_new_sd->valid = true;
+ p_new_sd->valid.set();
return true;
}
@@ -4743,7 +4821,7 @@ double TextServerAdvanced::_shaped_text_fit_to_width(const RID &p_shaped, double
ERR_FAIL_NULL_V(sd, 0.0);
MutexLock lock(sd->mutex);
- if (!sd->valid) {
+ if (!sd->valid.is_set()) {
const_cast<TextServerAdvanced *>(this)->_shaped_text_shape(p_shaped);
}
if (!sd->justification_ops_valid) {
@@ -4900,7 +4978,7 @@ double TextServerAdvanced::_shaped_text_tab_align(const RID &p_shaped, const Pac
ERR_FAIL_NULL_V(sd, 0.0);
MutexLock lock(sd->mutex);
- if (!sd->valid) {
+ if (!sd->valid.is_set()) {
const_cast<TextServerAdvanced *>(this)->_shaped_text_shape(p_shaped);
}
if (!sd->line_breaks_valid) {
@@ -5117,7 +5195,7 @@ void TextServerAdvanced::_shaped_text_overrun_trim_to_width(const RID &p_shaped_
ERR_FAIL_NULL_MSG(sd, "ShapedTextDataAdvanced invalid.");
MutexLock lock(sd->mutex);
- if (!sd->valid) {
+ if (!sd->valid.is_set()) {
_shaped_text_shape(p_shaped_line);
}
@@ -5144,7 +5222,7 @@ void TextServerAdvanced::_shaped_text_overrun_trim_to_width(const RID &p_shaped_
Vector<ShapedTextDataAdvanced::Span> &spans = sd->spans;
if (sd->parent != RID()) {
ShapedTextDataAdvanced *parent_sd = shaped_owner.get_or_null(sd->parent);
- ERR_FAIL_COND(!parent_sd->valid);
+ ERR_FAIL_COND(!parent_sd->valid.is_set());
spans = parent_sd->spans;
}
@@ -5355,7 +5433,7 @@ void TextServerAdvanced::_update_chars(ShapedTextDataAdvanced *p_sd) const {
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);
+ ERR_FAIL_COND(!parent_sd->valid.is_set());
spans = parent_sd->spans;
}
@@ -5403,7 +5481,7 @@ PackedInt32Array TextServerAdvanced::_shaped_text_get_character_breaks(const RID
ERR_FAIL_NULL_V(sd, PackedInt32Array());
MutexLock lock(sd->mutex);
- if (!sd->valid) {
+ if (!sd->valid.is_set()) {
const_cast<TextServerAdvanced *>(this)->_shaped_text_shape(p_shaped);
}
@@ -5417,7 +5495,7 @@ bool TextServerAdvanced::_shaped_text_update_breaks(const RID &p_shaped) {
ERR_FAIL_NULL_V(sd, false);
MutexLock lock(sd->mutex);
- if (!sd->valid) {
+ if (!sd->valid.is_set()) {
_shaped_text_shape(p_shaped);
}
@@ -5688,7 +5766,7 @@ bool TextServerAdvanced::_shaped_text_update_justification_ops(const RID &p_shap
ERR_FAIL_NULL_V(sd, false);
MutexLock lock(sd->mutex);
- if (!sd->valid) {
+ if (!sd->valid.is_set()) {
_shaped_text_shape(p_shaped);
}
if (!sd->line_breaks_valid) {
@@ -6068,7 +6146,7 @@ void TextServerAdvanced::_shape_run(ShapedTextDataAdvanced *p_sd, int64_t p_star
int mod = 0;
if (fd->antialiasing == FONT_ANTIALIASING_LCD) {
- TextServer::FontLCDSubpixelLayout layout = (TextServer::FontLCDSubpixelLayout)(int)GLOBAL_GET("gui/theme/lcd_subpixel_layout");
+ TextServer::FontLCDSubpixelLayout layout = lcd_subpixel_layout.get();
if (layout != FONT_LCD_SUBPIXEL_LAYOUT_NONE) {
mod = (layout << 24);
}
@@ -6128,7 +6206,8 @@ void TextServerAdvanced::_shape_run(ShapedTextDataAdvanced *p_sd, int64_t p_star
gl.index = glyph_info[i].codepoint;
if (gl.index != 0) {
- _ensure_glyph(fd, fss, gl.index | mod);
+ FontGlyph fgl;
+ _ensure_glyph(fd, fss, gl.index | mod, fgl);
if (subpos) {
gl.x_off = (double)glyph_pos[i].x_offset / (64.0 / scale);
} else if (p_sd->orientation == ORIENTATION_HORIZONTAL) {
@@ -6240,7 +6319,7 @@ bool TextServerAdvanced::_shaped_text_shape(const RID &p_shaped) {
ERR_FAIL_NULL_V(sd, false);
MutexLock lock(sd->mutex);
- if (sd->valid) {
+ if (sd->valid.is_set()) {
return true;
}
@@ -6248,13 +6327,13 @@ bool TextServerAdvanced::_shaped_text_shape(const RID &p_shaped) {
if (sd->parent != RID()) {
_shaped_text_shape(sd->parent);
ShapedTextDataAdvanced *parent_sd = shaped_owner.get_or_null(sd->parent);
- ERR_FAIL_COND_V(!parent_sd->valid, false);
+ ERR_FAIL_COND_V(!parent_sd->valid.is_set(), false);
ERR_FAIL_COND_V(!_shape_substr(sd, parent_sd, sd->start, sd->end - sd->start), false);
return true;
}
if (sd->text.length() == 0) {
- sd->valid = true;
+ sd->valid.set();
return true;
}
@@ -6447,16 +6526,16 @@ bool TextServerAdvanced::_shaped_text_shape(const RID &p_shaped) {
}
_realign(sd);
- sd->valid = true;
- return sd->valid;
+ sd->valid.set();
+ return sd->valid.is_set();
}
bool TextServerAdvanced::_shaped_text_is_ready(const RID &p_shaped) const {
const ShapedTextDataAdvanced *sd = shaped_owner.get_or_null(p_shaped);
ERR_FAIL_NULL_V(sd, false);
- MutexLock lock(sd->mutex);
- return sd->valid;
+ // Atomic read is safe and faster.
+ return sd->valid.is_set();
}
const Glyph *TextServerAdvanced::_shaped_text_get_glyphs(const RID &p_shaped) const {
@@ -6464,7 +6543,7 @@ const Glyph *TextServerAdvanced::_shaped_text_get_glyphs(const RID &p_shaped) co
ERR_FAIL_NULL_V(sd, nullptr);
MutexLock lock(sd->mutex);
- if (!sd->valid) {
+ if (!sd->valid.is_set()) {
const_cast<TextServerAdvanced *>(this)->_shaped_text_shape(p_shaped);
}
return sd->glyphs.ptr();
@@ -6475,7 +6554,7 @@ int64_t TextServerAdvanced::_shaped_text_get_glyph_count(const RID &p_shaped) co
ERR_FAIL_NULL_V(sd, 0);
MutexLock lock(sd->mutex);
- if (!sd->valid) {
+ if (!sd->valid.is_set()) {
const_cast<TextServerAdvanced *>(this)->_shaped_text_shape(p_shaped);
}
return sd->glyphs.size();
@@ -6486,7 +6565,7 @@ const Glyph *TextServerAdvanced::_shaped_text_sort_logical(const RID &p_shaped)
ERR_FAIL_NULL_V(sd, nullptr);
MutexLock lock(sd->mutex);
- if (!sd->valid) {
+ if (!sd->valid.is_set()) {
const_cast<TextServerAdvanced *>(this)->_shaped_text_shape(p_shaped);
}
@@ -6526,7 +6605,7 @@ Rect2 TextServerAdvanced::_shaped_text_get_object_rect(const RID &p_shaped, cons
MutexLock lock(sd->mutex);
ERR_FAIL_COND_V(!sd->objects.has(p_key), Rect2());
- if (!sd->valid) {
+ if (!sd->valid.is_set()) {
const_cast<TextServerAdvanced *>(this)->_shaped_text_shape(p_shaped);
}
return sd->objects[p_key].rect;
@@ -6547,7 +6626,7 @@ int64_t TextServerAdvanced::_shaped_text_get_object_glyph(const RID &p_shaped, c
MutexLock lock(sd->mutex);
ERR_FAIL_COND_V(!sd->objects.has(p_key), -1);
- if (!sd->valid) {
+ if (!sd->valid.is_set()) {
const_cast<TextServerAdvanced *>(this)->_shaped_text_shape(p_shaped);
}
const ShapedTextDataAdvanced::EmbeddedObject &obj = sd->objects[p_key];
@@ -6566,7 +6645,7 @@ Size2 TextServerAdvanced::_shaped_text_get_size(const RID &p_shaped) const {
ERR_FAIL_NULL_V(sd, Size2());
MutexLock lock(sd->mutex);
- if (!sd->valid) {
+ if (!sd->valid.is_set()) {
const_cast<TextServerAdvanced *>(this)->_shaped_text_shape(p_shaped);
}
if (sd->orientation == TextServer::ORIENTATION_HORIZONTAL) {
@@ -6581,7 +6660,7 @@ double TextServerAdvanced::_shaped_text_get_ascent(const RID &p_shaped) const {
ERR_FAIL_NULL_V(sd, 0.0);
MutexLock lock(sd->mutex);
- if (!sd->valid) {
+ if (!sd->valid.is_set()) {
const_cast<TextServerAdvanced *>(this)->_shaped_text_shape(p_shaped);
}
return sd->ascent + sd->extra_spacing[SPACING_TOP];
@@ -6592,7 +6671,7 @@ double TextServerAdvanced::_shaped_text_get_descent(const RID &p_shaped) const {
ERR_FAIL_NULL_V(sd, 0.0);
MutexLock lock(sd->mutex);
- if (!sd->valid) {
+ if (!sd->valid.is_set()) {
const_cast<TextServerAdvanced *>(this)->_shaped_text_shape(p_shaped);
}
return sd->descent + sd->extra_spacing[SPACING_BOTTOM];
@@ -6603,7 +6682,7 @@ double TextServerAdvanced::_shaped_text_get_width(const RID &p_shaped) const {
ERR_FAIL_NULL_V(sd, 0.0);
MutexLock lock(sd->mutex);
- if (!sd->valid) {
+ if (!sd->valid.is_set()) {
const_cast<TextServerAdvanced *>(this)->_shaped_text_shape(p_shaped);
}
return Math::ceil(sd->text_trimmed ? sd->width_trimmed : sd->width);
@@ -6614,7 +6693,7 @@ double TextServerAdvanced::_shaped_text_get_underline_position(const RID &p_shap
ERR_FAIL_NULL_V(sd, 0.0);
MutexLock lock(sd->mutex);
- if (!sd->valid) {
+ if (!sd->valid.is_set()) {
const_cast<TextServerAdvanced *>(this)->_shaped_text_shape(p_shaped);
}
@@ -6626,7 +6705,7 @@ double TextServerAdvanced::_shaped_text_get_underline_thickness(const RID &p_sha
ERR_FAIL_NULL_V(sd, 0.0);
MutexLock lock(sd->mutex);
- if (!sd->valid) {
+ if (!sd->valid.is_set()) {
const_cast<TextServerAdvanced *>(this)->_shaped_text_shape(p_shaped);
}
@@ -7424,10 +7503,15 @@ bool TextServerAdvanced::_is_valid_letter(uint64_t p_unicode) const {
return u_isalpha(p_unicode);
}
+void TextServerAdvanced::_update_settings() {
+ lcd_subpixel_layout.set((TextServer::FontLCDSubpixelLayout)(int)GLOBAL_GET("gui/theme/lcd_subpixel_layout"));
+}
+
TextServerAdvanced::TextServerAdvanced() {
_insert_num_systems_lang();
_insert_feature_sets();
_bmp_create_font_funcs();
+ ProjectSettings::get_singleton()->connect("settings_changed", callable_mp(this, &TextServerAdvanced::_update_settings));
}
void TextServerAdvanced::_cleanup() {