From 1e66c63774b14ce8a411ae6259e8d02bdc61c5da Mon Sep 17 00:00:00 2001 From: Glenn Maynard Date: Thu, 16 Jan 2003 23:22:21 +0000 Subject: [PATCH] simplifications and minor fixes --- stepmania/src/Font.cpp | 28 +++++++--------------------- stepmania/src/Font.h | 2 +- stepmania/src/FontManager.h | 3 --- stepmania/src/RageUtil.cpp | 2 +- stepmania/src/ThemeManager.cpp | 28 +++++++--------------------- 5 files changed, 16 insertions(+), 47 deletions(-) diff --git a/stepmania/src/Font.cpp b/stepmania/src/Font.cpp index 0292be6fe0..def36cdb81 100644 --- a/stepmania/src/Font.cpp +++ b/stepmania/src/Font.cpp @@ -345,30 +345,14 @@ void Font::SetDefaultGlyph(FontPage *fp) } -/* "Normal.png", "Normal [foo].png", "Normal 16x16.png", and "Normal [foo] 16x16.png" - * are all part of the FontName "Normal". "Normal2 16x16.png" is not. - * - * So, FileName must start with FontName, followed by either " [", " DIGIT" or - * a period. - * - * This is to make sure we don't pull in textures from similarly-named fonts. - */ -bool Font::MatchesFont(CString FontName, CString FileName) -{ - FontName.MakeLower(); - FileName.MakeLower(); - - if(FileName.substr(0, FontName.size()) != FontName) - return false; - FileName = FileName.substr(FontName.size()); - - return regex("^( \\[|\\.| [0-9]+x[0-9]+)", FileName); -} - -CString GetFontName(CString FileName) +CString Font::GetFontName(CString FileName) { CString orig = FileName; + CString sDir, sFName, sExt; + splitpath( FileName, sDir, sFName, sExt ); + FileName = sFName; + /* If it ends in an extension, remove it. */ if(regex("\\....", FileName)) FileName.erase(FileName.size()-4); @@ -387,9 +371,11 @@ CString GetFontName(CString FileName) if(FileName.empty()) RageException::Throw("Can't parse font filename \"%s\"", orig.GetString()); + FileName.MakeLower(); return FileName; } + /* Given a file in a font, find all of the files for the font. * * Possibilities: diff --git a/stepmania/src/Font.h b/stepmania/src/Font.h index 69729f8091..dbf5cc2eff 100644 --- a/stepmania/src/Font.h +++ b/stepmania/src/Font.h @@ -131,7 +131,7 @@ public: static const longchar DEFAULT_GLYPH; - static bool MatchesFont(CString FontName, CString FileName); + static CString GetFontName(CString FileName); private: /* List of pages and fonts that we use (and are responsible for freeing). */ diff --git a/stepmania/src/FontManager.h b/stepmania/src/FontManager.h index f1ab88630f..ef207d91a5 100644 --- a/stepmania/src/FontManager.h +++ b/stepmania/src/FontManager.h @@ -36,9 +36,6 @@ public: * adjustment of fonts in ScreenTestFonts at the moment. */ void ReloadFonts(); - /* Return true if FileName is a part of the font "FontName". */ - static bool MatchesFont(CString FontName, CString FileName); - static longchar MakeGameGlyph(longchar c, Game g); static bool ExtractGameGlyph(longchar ch, int &c, Game &g); diff --git a/stepmania/src/RageUtil.cpp b/stepmania/src/RageUtil.cpp index 2fe59c031d..5fc555bf03 100644 --- a/stepmania/src/RageUtil.cpp +++ b/stepmania/src/RageUtil.cpp @@ -201,7 +201,7 @@ void splitpath( CString Path, CString& Dir, CString& Filename, CString& Ext ) Dir = mat[0]; Path = mat[1]; - if(regex("^(.*)(\\....)$", Path, mat)) + if(regex("^(.*)(\\.[^\\.]+)$", Path, mat)) { Filename = mat[0]; Ext = mat[1]; diff --git a/stepmania/src/ThemeManager.cpp b/stepmania/src/ThemeManager.cpp index ccc958b909..6f513051f9 100644 --- a/stepmania/src/ThemeManager.cpp +++ b/stepmania/src/ThemeManager.cpp @@ -129,44 +129,30 @@ try_element_again: /////////////////////////////////////// // Search both the current theme and the default theme dirs for this element /////////////////////////////////////// - static const char *font_masks[] = { "*.png", ".redir", NULL }; - static const char *blank_mask[] = { "", NULL }; - const char **asset_masks = font_masks; - /* If the theme asset name has an extension, don't add - * a mask. This should only happen with redirs. */ - if(sFileName.find_last_of('.') != sFileName.npos) - asset_masks = blank_mask; - - int i; - CString path; - - for(i = 0; asset_masks[i]; ++i) - { - path = sCurrentThemeDir; - GetDirListing( path + "Fonts\\"+sFileName + asset_masks[i], - asPossibleElementFilePaths, false, true ); - } + CString path = sCurrentThemeDir; + GetDirListing( sCurrentThemeDir + "Fonts\\"+sFileName + "*", + asPossibleElementFilePaths, false, true ); /* Weed out false matches. (For example, this gets rid of "normal2" when * we're really looking for "normal".) */ + int i; for(i = 0; i < int(asPossibleElementFilePaths.size()); ) { - if(!Font::MatchesFont(path + "Fonts\\"+ sFileName, asPossibleElementFilePaths[i])) + if(Font::GetFontName(sFileName) != Font::GetFontName(asPossibleElementFilePaths[i])) asPossibleElementFilePaths.erase(asPossibleElementFilePaths.begin()+i); else i++; } if(asPossibleElementFilePaths.empty()) - for(i = 0; asset_masks[i]; ++i) { path = sDefaultThemeDir; - GetDirListing( path + "Fonts\\"+ sFileName + asset_masks[i], + GetDirListing( sDefaultThemeDir + "Fonts\\"+ sFileName + "*", asPossibleElementFilePaths, false, true ); } for(i = 0; i < int(asPossibleElementFilePaths.size()); ) { - if(!Font::MatchesFont(path + "Fonts\\"+ sFileName, asPossibleElementFilePaths[i])) + if(Font::GetFontName(sFileName) != Font::GetFontName(asPossibleElementFilePaths[i])) asPossibleElementFilePaths.erase(asPossibleElementFilePaths.begin()+i); else i++; }