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:
+23
-15
@@ -27,25 +27,33 @@ Font::Font()
|
|||||||
, flags(FONT_NORMAL)
|
, flags(FONT_NORMAL)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
bool Font::PreloadResourceFonts(String fontsDirectoryPath, bool recursive) {
|
bool Font::PreloadResourceFonts(bool recursive) {
|
||||||
#if wxUSE_PRIVATE_FONTS
|
#if wxUSE_PRIVATE_FONTS
|
||||||
String pathSeparator(wxFileName::GetPathSeparator());
|
String pathSeparator(wxFileName::GetPathSeparator());
|
||||||
String appPath( wxFileName(wxStandardPaths::Get().GetExecutablePath()).GetPath() );
|
String appPath(wxFileName(wxStandardPaths::Get().GetExecutablePath()).GetPath());
|
||||||
fontsDirectoryPath = appPath + pathSeparator + fontsDirectoryPath + (fontsDirectoryPath.EndsWith(pathSeparator) ? wxString() : pathSeparator);
|
wxDir appDir(appPath);
|
||||||
|
if (!appDir.IsOpened()) return true;
|
||||||
if (!wxDirExists(fontsDirectoryPath)) return false;
|
|
||||||
|
|
||||||
// tally fonts
|
|
||||||
vector<String> fontFilePaths;
|
|
||||||
TallyResourceFonts(fontsDirectoryPath, fontFilePaths, recursive);
|
|
||||||
if (fontFilePaths.size() == 0) return false;
|
|
||||||
|
|
||||||
// load fonts
|
|
||||||
bool preloadHadErrors = false;
|
bool preloadHadErrors = false;
|
||||||
for (String fontFilePath : fontFilePaths) {
|
wxString folder;
|
||||||
if (!wxFont::AddPrivateFont(fontFilePath)) {
|
bool cont = appDir.GetFirst(&folder, wxEmptyString, wxDIR_DIRS);
|
||||||
preloadHadErrors = true;
|
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;
|
return preloadHadErrors;
|
||||||
|
|||||||
+3
-2
@@ -49,8 +49,9 @@ public:
|
|||||||
|
|
||||||
Font();
|
Font();
|
||||||
|
|
||||||
/// Load fonts (.ttf or .otf) from the given directory and its subdirectories, returns true if there were errors
|
/// Load fonts (.ttf or .otf) from all directories in the app directory that contain "fonts" in their names,
|
||||||
static bool PreloadResourceFonts(String fontsDirectoryPath, bool recursive);
|
/// 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
|
/// Adds font file paths from the given directory into fontFilePaths
|
||||||
static void TallyResourceFonts(String fontsDirectoryPath, vector<String>& fontFilePaths, bool recursive);
|
static void TallyResourceFonts(String fontsDirectoryPath, vector<String>& fontFilePaths, bool recursive);
|
||||||
/// Update the scritables, returns true if there is a change
|
/// Update the scritables, returns true if there is a change
|
||||||
|
|||||||
+1
-1
@@ -87,7 +87,7 @@ int MSE::OnRun() {
|
|||||||
// Platform friendly appname
|
// Platform friendly appname
|
||||||
SetAppName(_("magicseteditor"));
|
SetAppName(_("magicseteditor"));
|
||||||
#endif
|
#endif
|
||||||
Font::PreloadResourceFonts(_("Magic - Fonts"), true);
|
Font::PreloadResourceFonts(true);
|
||||||
wxInitAllImageHandlers();
|
wxInitAllImageHandlers();
|
||||||
wxFileSystem::AddHandler(new wxInternetFSHandler); // needed for update checker
|
wxFileSystem::AddHandler(new wxInternetFSHandler); // needed for update checker
|
||||||
wxSocketBase::Initialize();
|
wxSocketBase::Initialize();
|
||||||
|
|||||||
Reference in New Issue
Block a user