From dafd1a4f194ed37cb0303eebb28693930d7b0c89 Mon Sep 17 00:00:00 2001 From: GenevensiS <66968533+G-e-n-e-v-e-n-s-i-S@users.noreply.github.com> Date: Thu, 10 Jul 2025 17:17:10 +0200 Subject: [PATCH] Load all fonts folders --- src/data/font.cpp | 38 +++++++++++++++++++++++--------------- src/data/font.hpp | 5 +++-- src/main.cpp | 2 +- 3 files changed, 27 insertions(+), 18 deletions(-) diff --git a/src/data/font.cpp b/src/data/font.cpp index 98298ba8..89482ea7 100644 --- a/src/data/font.cpp +++ b/src/data/font.cpp @@ -27,25 +27,33 @@ Font::Font() , flags(FONT_NORMAL) {} -bool Font::PreloadResourceFonts(String fontsDirectoryPath, bool recursive) { +bool Font::PreloadResourceFonts(bool recursive) { #if wxUSE_PRIVATE_FONTS String pathSeparator(wxFileName::GetPathSeparator()); - String appPath( wxFileName(wxStandardPaths::Get().GetExecutablePath()).GetPath() ); - fontsDirectoryPath = appPath + pathSeparator + fontsDirectoryPath + (fontsDirectoryPath.EndsWith(pathSeparator) ? wxString() : pathSeparator); - - if (!wxDirExists(fontsDirectoryPath)) return false; - - // tally fonts - vector fontFilePaths; - TallyResourceFonts(fontsDirectoryPath, fontFilePaths, recursive); - if (fontFilePaths.size() == 0) return false; - - // load fonts + String appPath(wxFileName(wxStandardPaths::Get().GetExecutablePath()).GetPath()); + wxDir appDir(appPath); + if (!appDir.IsOpened()) return true; + bool preloadHadErrors = false; - for (String fontFilePath : fontFilePaths) { - if (!wxFont::AddPrivateFont(fontFilePath)) { - preloadHadErrors = true; + wxString folder; + bool cont = appDir.GetFirst(&folder, wxEmptyString, wxDIR_DIRS); + while (cont) + { + if (folder.Lower().Contains("fonts")) { + String folderPath = appPath + pathSeparator + folder + pathSeparator; + + // tally fonts + vector fontFilePaths; + TallyResourceFonts(folderPath, fontFilePaths, recursive); + + // load fonts + for (const String& fontFilePath : fontFilePaths) { + if (!wxFont::AddPrivateFont(fontFilePath)) { + preloadHadErrors = true; + } + } } + cont = appDir.GetNext(&folder); } return preloadHadErrors; diff --git a/src/data/font.hpp b/src/data/font.hpp index 9a3368b1..49283d54 100644 --- a/src/data/font.hpp +++ b/src/data/font.hpp @@ -49,8 +49,9 @@ public: Font(); - /// Load fonts (.ttf or .otf) from the given directory and its subdirectories, returns true if there were errors - static bool PreloadResourceFonts(String fontsDirectoryPath, bool recursive); + /// Load fonts (.ttf or .otf) from all directories in the app directory that contain "fonts" in their names, + /// and optionaly their subdirectories, returns true if there were errors + static bool PreloadResourceFonts(bool recursive); /// Adds font file paths from the given directory into fontFilePaths static void TallyResourceFonts(String fontsDirectoryPath, vector& fontFilePaths, bool recursive); /// Update the scritables, returns true if there is a change diff --git a/src/main.cpp b/src/main.cpp index 948bd114..e3b708e7 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -87,7 +87,7 @@ int MSE::OnRun() { // Platform friendly appname SetAppName(_("magicseteditor")); #endif - Font::PreloadResourceFonts(_("Magic - Fonts"), true); + Font::PreloadResourceFonts(true); wxInitAllImageHandlers(); wxFileSystem::AddHandler(new wxInternetFSHandler); // needed for update checker wxSocketBase::Initialize();