simplify code

This commit is contained in:
GenevensiS
2025-04-08 01:47:45 +02:00
parent dca935a966
commit 28b2862bd8
2 changed files with 7 additions and 9 deletions
+5 -7
View File
@@ -37,7 +37,8 @@ bool Font::PreloadResourceFonts(String fontsDirectoryPath, bool recursive) {
// tally fonts // tally fonts
vector<String> fontFilePaths; vector<String> fontFilePaths;
if (!TallyResourceFonts(fontsDirectoryPath, fontFilePaths, recursive)) return false; TallyResourceFonts(fontsDirectoryPath, fontFilePaths, recursive);
if (fontFilePaths.size() == 0) return false;
// load fonts // load fonts
bool preloadHadErrors = false; bool preloadHadErrors = false;
@@ -53,25 +54,22 @@ bool Font::PreloadResourceFonts(String fontsDirectoryPath, bool recursive) {
return false; return false;
} }
bool Font::TallyResourceFonts(String fontsDirectoryPath, vector<String>& fontFilePaths, bool recursive) { void Font::TallyResourceFonts(String fontsDirectoryPath, vector<String>& fontFilePaths, bool recursive) {
wxDir fontsDirectory(fontsDirectoryPath); wxDir fontsDirectory(fontsDirectoryPath);
String fontFileName = ""; String fontFileName = wxEmptyString;
bool foundFonts = false;
bool hasNext = fontsDirectory.GetFirst(&fontFileName); bool hasNext = fontsDirectory.GetFirst(&fontFileName);
while (hasNext) { while (hasNext) {
String fontFilePath = fontsDirectoryPath + fontFileName; String fontFilePath = fontsDirectoryPath + fontFileName;
if (wxDirExists(fontFilePath)) { if (wxDirExists(fontFilePath)) {
if (recursive) { if (recursive) {
foundFonts = foundFonts || TallyResourceFonts(fontFilePath + wxFileName::GetPathSeparator(), fontFilePaths, true); TallyResourceFonts(fontFilePath + wxFileName::GetPathSeparator(), fontFilePaths, true);
} }
} }
else if (fontFilePath.EndsWith(_(".ttf")) || fontFilePath.EndsWith(_(".otf"))) { else if (fontFilePath.EndsWith(_(".ttf")) || fontFilePath.EndsWith(_(".otf"))) {
foundFonts = true;
fontFilePaths.push_back(fontFilePath); fontFilePaths.push_back(fontFilePath);
} }
hasNext = fontsDirectory.GetNext(&fontFileName); hasNext = fontsDirectory.GetNext(&fontFileName);
} }
return foundFonts;
} }
bool Font::update(Context& ctx) { bool Font::update(Context& ctx) {
+2 -2
View File
@@ -51,8 +51,8 @@ public:
/// Load fonts (.ttf or .otf) from the given directory and its subdirectories, returns true if there were errors /// 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); static bool PreloadResourceFonts(String fontsDirectoryPath, bool recursive);
/// Adds font file paths from the given directory into fontFilePaths, returns true if fonts were found /// Adds font file paths from the given directory into fontFilePaths
static bool 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
bool update(Context& ctx); bool update(Context& ctx);
/// Add the given dependency to the dependent_scripts list for the variables this font depends on /// Add the given dependency to the dependent_scripts list for the variables this font depends on