simplifications and minor fixes

This commit is contained in:
Glenn Maynard
2003-01-16 23:22:21 +00:00
parent ffc6ae2c37
commit 1e66c63774
5 changed files with 16 additions and 47 deletions
+7 -21
View File
@@ -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:
+1 -1
View File
@@ -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). */
-3
View File
@@ -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);
+1 -1
View File
@@ -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];
+7 -21
View File
@@ -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++;
}