mirror of
https://github.com/amyinspace/MagicSetEditor2.git
synced 2026-06-10 04:57:00 -04:00
Load all fonts folders
This commit is contained in:
+16
-8
@@ -27,26 +27,34 @@ 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);
|
||||
String appPath(wxFileName(wxStandardPaths::Get().GetExecutablePath()).GetPath());
|
||||
wxDir appDir(appPath);
|
||||
if (!appDir.IsOpened()) return true;
|
||||
|
||||
if (!wxDirExists(fontsDirectoryPath)) return false;
|
||||
bool preloadHadErrors = false;
|
||||
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(fontsDirectoryPath, fontFilePaths, recursive);
|
||||
if (fontFilePaths.size() == 0) return false;
|
||||
TallyResourceFonts(folderPath, fontFilePaths, recursive);
|
||||
|
||||
// load fonts
|
||||
bool preloadHadErrors = false;
|
||||
for (String fontFilePath : fontFilePaths) {
|
||||
for (const String& fontFilePath : fontFilePaths) {
|
||||
if (!wxFont::AddPrivateFont(fontFilePath)) {
|
||||
preloadHadErrors = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
cont = appDir.GetNext(&folder);
|
||||
}
|
||||
|
||||
return preloadHadErrors;
|
||||
|
||||
|
||||
+3
-2
@@ -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
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user