|
@@ -1359,7 +1359,7 @@ _FORCE_INLINE_ bool TextServerAdvanced::_ensure_glyph(FontAdvanced *p_font_data,
|
|
|
return false;
|
|
return false;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-_FORCE_INLINE_ bool TextServerAdvanced::_ensure_cache_for_size(FontAdvanced *p_font_data, const Vector2i &p_size, FontForSizeAdvanced *&r_cache_for_size) const {
|
|
|
|
|
|
|
+_FORCE_INLINE_ bool TextServerAdvanced::_ensure_cache_for_size(FontAdvanced *p_font_data, const Vector2i &p_size, FontForSizeAdvanced *&r_cache_for_size, bool p_silent) const {
|
|
|
ERR_FAIL_COND_V(p_size.x <= 0, false);
|
|
ERR_FAIL_COND_V(p_size.x <= 0, false);
|
|
|
|
|
|
|
|
HashMap<Vector2i, FontForSizeAdvanced *>::Iterator E = p_font_data->cache.find(p_size);
|
|
HashMap<Vector2i, FontForSizeAdvanced *>::Iterator E = p_font_data->cache.find(p_size);
|
|
@@ -1380,7 +1380,11 @@ _FORCE_INLINE_ bool TextServerAdvanced::_ensure_cache_for_size(FontAdvanced *p_f
|
|
|
error = FT_Init_FreeType(&ft_library);
|
|
error = FT_Init_FreeType(&ft_library);
|
|
|
if (error != 0) {
|
|
if (error != 0) {
|
|
|
memdelete(fd);
|
|
memdelete(fd);
|
|
|
- ERR_FAIL_V_MSG(false, "FreeType: Error initializing library: '" + String(FT_Error_String(error)) + "'.");
|
|
|
|
|
|
|
+ if (p_silent) {
|
|
|
|
|
+ return false;
|
|
|
|
|
+ } else {
|
|
|
|
|
+ ERR_FAIL_V_MSG(false, "FreeType: Error initializing library: '" + String(FT_Error_String(error)) + "'.");
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
#ifdef MODULE_SVG_ENABLED
|
|
#ifdef MODULE_SVG_ENABLED
|
|
|
FT_Property_Set(ft_library, "ot-svg", "svg-hooks", get_tvg_svg_in_ot_hooks());
|
|
FT_Property_Set(ft_library, "ot-svg", "svg-hooks", get_tvg_svg_in_ot_hooks());
|
|
@@ -1414,7 +1418,11 @@ _FORCE_INLINE_ bool TextServerAdvanced::_ensure_cache_for_size(FontAdvanced *p_f
|
|
|
FT_Done_Face(fd->face);
|
|
FT_Done_Face(fd->face);
|
|
|
fd->face = nullptr;
|
|
fd->face = nullptr;
|
|
|
memdelete(fd);
|
|
memdelete(fd);
|
|
|
- ERR_FAIL_V_MSG(false, "FreeType: Error loading font: '" + String(FT_Error_String(error)) + "'.");
|
|
|
|
|
|
|
+ if (p_silent) {
|
|
|
|
|
+ return false;
|
|
|
|
|
+ } else {
|
|
|
|
|
+ ERR_FAIL_V_MSG(false, "FreeType: Error loading font: '" + String(FT_Error_String(error)) + "'.");
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -1849,7 +1857,11 @@ _FORCE_INLINE_ bool TextServerAdvanced::_ensure_cache_for_size(FontAdvanced *p_f
|
|
|
}
|
|
}
|
|
|
#else
|
|
#else
|
|
|
memdelete(fd);
|
|
memdelete(fd);
|
|
|
- ERR_FAIL_V_MSG(false, "FreeType: Can't load dynamic font, engine is compiled without FreeType support!");
|
|
|
|
|
|
|
+ if (p_silent) {
|
|
|
|
|
+ return false;
|
|
|
|
|
+ } else {
|
|
|
|
|
+ ERR_FAIL_V_MSG(false, "FreeType: Can't load dynamic font, engine is compiled without FreeType support!");
|
|
|
|
|
+ }
|
|
|
#endif
|
|
#endif
|
|
|
} else {
|
|
} else {
|
|
|
// Init bitmap font.
|
|
// Init bitmap font.
|
|
@@ -1860,6 +1872,16 @@ _FORCE_INLINE_ bool TextServerAdvanced::_ensure_cache_for_size(FontAdvanced *p_f
|
|
|
return true;
|
|
return true;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+_FORCE_INLINE_ bool TextServerAdvanced::_font_validate(const RID &p_font_rid) const {
|
|
|
|
|
+ FontAdvanced *fd = _get_font_data(p_font_rid);
|
|
|
|
|
+ ERR_FAIL_NULL_V(fd, false);
|
|
|
|
|
+
|
|
|
|
|
+ MutexLock lock(fd->mutex);
|
|
|
|
|
+ Vector2i size = _get_size(fd, 16);
|
|
|
|
|
+ FontForSizeAdvanced *ffsd = nullptr;
|
|
|
|
|
+ return _ensure_cache_for_size(fd, size, ffsd, true);
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
_FORCE_INLINE_ void TextServerAdvanced::_font_clear_cache(FontAdvanced *p_font_data) {
|
|
_FORCE_INLINE_ void TextServerAdvanced::_font_clear_cache(FontAdvanced *p_font_data) {
|
|
|
MutexLock ftlock(ft_mutex);
|
|
MutexLock ftlock(ft_mutex);
|
|
|
|
|
|
|
@@ -5108,6 +5130,10 @@ RID TextServerAdvanced::_find_sys_font_for_text(const RID &p_fdef, const String
|
|
|
SystemFontCacheRec sysf;
|
|
SystemFontCacheRec sysf;
|
|
|
sysf.rid = _create_font();
|
|
sysf.rid = _create_font();
|
|
|
_font_set_data_ptr(sysf.rid, font_data.ptr(), font_data.size());
|
|
_font_set_data_ptr(sysf.rid, font_data.ptr(), font_data.size());
|
|
|
|
|
+ if (!_font_validate(sysf.rid)) {
|
|
|
|
|
+ _free_rid(sysf.rid);
|
|
|
|
|
+ continue;
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
Dictionary var = dvar;
|
|
Dictionary var = dvar;
|
|
|
// Select matching style from collection.
|
|
// Select matching style from collection.
|