Load all fonts folders

This commit is contained in:
GenevensiS
2025-07-10 17:17:10 +02:00
committed by GitHub
parent 026400a1e0
commit dafd1a4f19
3 changed files with 27 additions and 18 deletions
+23 -15
View File
@@ -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<String> 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<String> fontFilePaths;
TallyResourceFonts(folderPath, fontFilePaths, recursive);
// load fonts
for (const String& fontFilePath : fontFilePaths) {
if (!wxFont::AddPrivateFont(fontFilePath)) {
preloadHadErrors = true;
}
}
}
cont = appDir.GetNext(&folder);
}
return preloadHadErrors;
+3 -2
View File
@@ -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<String>& fontFilePaths, bool recursive);
/// Update the scritables, returns true if there is a change
+1 -1
View File
@@ -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();