diff options
author | Alexander-Alekseev <alexander.n.alekseev@gmail.com> | 2018-07-03 13:37:07 +0000 |
---|---|---|
committer | Alexander-Alekseev <alexander.n.alekseev@gmail.com> | 2018-07-10 14:47:26 +0000 |
commit | 38887d1a52e65844bb890dae4f2917817631f0e1 (patch) | |
tree | 0ea8bd60f2a44f8287f4ededc93a36efc7fe7b44 /editor/editor_fonts.cpp | |
parent | 04d9f8dbd6b1ec517c2d66db19efa93517933232 (diff) |
Fallback to default font if main/code font path doesn't exist
Diffstat (limited to 'editor/editor_fonts.cpp')
-rw-r--r-- | editor/editor_fonts.cpp | 17 |
1 files changed, 14 insertions, 3 deletions
diff --git a/editor/editor_fonts.cpp b/editor/editor_fonts.cpp index 26f16e282e..8e0d92267c 100644 --- a/editor/editor_fonts.cpp +++ b/editor/editor_fonts.cpp @@ -31,6 +31,7 @@ #include "editor_fonts.h" #include "builtin_fonts.gen.h" +#include "core/os/dir_access.h" #include "editor_scale.h" #include "editor_settings.h" #include "scene/resources/default_theme/default_theme.h" @@ -114,28 +115,34 @@ static Ref<BitmapFont> make_font(int p_height, int p_ascent, int p_valign, int p MAKE_FALLBACKS(m_name); void editor_register_fonts(Ref<Theme> p_theme) { + DirAccess *dir = DirAccess::create(DirAccess::ACCESS_FILESYSTEM); + /* Custom font */ DynamicFontData::Hinting font_hinting = (DynamicFontData::Hinting)(int)EditorSettings::get_singleton()->get("interface/editor/main_font_hinting"); String custom_font_path = EditorSettings::get_singleton()->get("interface/editor/main_font"); Ref<DynamicFontData> CustomFont; - if (custom_font_path.length() > 0) { + if (custom_font_path.length() > 0 && dir->file_exists(custom_font_path)) { CustomFont.instance(); CustomFont->set_hinting(font_hinting); CustomFont->set_font_path(custom_font_path); CustomFont->set_force_autohinter(true); //just looks better..i think? + } else { + EditorSettings::get_singleton()->set_manually("interface/editor/main_font", ""); } /* Custom Bold font */ String custom_font_path_bold = EditorSettings::get_singleton()->get("interface/editor/main_font_bold"); Ref<DynamicFontData> CustomFontBold; - if (custom_font_path_bold.length() > 0) { + if (custom_font_path_bold.length() > 0 && dir->file_exists(custom_font_path_bold)) { CustomFontBold.instance(); CustomFontBold->set_hinting(font_hinting); CustomFontBold->set_font_path(custom_font_path_bold); CustomFontBold->set_force_autohinter(true); //just looks better..i think? + } else { + EditorSettings::get_singleton()->set_manually("interface/editor/main_font_bold", ""); } /* Custom source code font */ @@ -143,12 +150,16 @@ void editor_register_fonts(Ref<Theme> p_theme) { String custom_font_path_source = EditorSettings::get_singleton()->get("interface/editor/code_font"); DynamicFontData::Hinting font_source_hinting = (DynamicFontData::Hinting)(int)EditorSettings::get_singleton()->get("interface/editor/code_font_hinting"); Ref<DynamicFontData> CustomFontSource; - if (custom_font_path_source.length() > 0) { + if (custom_font_path_source.length() > 0 && dir->file_exists(custom_font_path_source)) { CustomFontSource.instance(); CustomFontSource->set_hinting(font_source_hinting); CustomFontSource->set_font_path(custom_font_path_source); + } else { + EditorSettings::get_singleton()->set_manually("interface/editor/code_font", ""); } + memdelete(dir); + /* Droid Sans */ Ref<DynamicFontData> DefaultFont; |