2003-02-16 04:01:45 +00:00
|
|
|
#include "global.h"
|
2002-03-30 20:00:13 +00:00
|
|
|
#include "FontManager.h"
|
|
|
|
|
#include "Font.h"
|
|
|
|
|
#include "RageUtil.h"
|
2002-05-01 19:14:55 +00:00
|
|
|
#include "RageLog.h"
|
2002-07-27 19:29:51 +00:00
|
|
|
#include "RageException.h"
|
2003-11-02 04:05:13 +00:00
|
|
|
#include <map>
|
2004-07-25 04:27:20 +00:00
|
|
|
#include "GameManager.h"
|
2002-06-14 22:25:22 +00:00
|
|
|
|
2004-02-15 05:45:18 +00:00
|
|
|
FontManager* FONT = NULL; // global and accessable from anywhere in our program
|
2002-03-30 20:00:13 +00:00
|
|
|
|
2003-11-02 04:05:13 +00:00
|
|
|
// map from file name to a texture holder
|
|
|
|
|
typedef pair<CString,CString> FontName;
|
|
|
|
|
static map<FontName, Font*> g_mapPathToFont;
|
|
|
|
|
|
2002-03-30 20:00:13 +00:00
|
|
|
FontManager::FontManager()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
FontManager::~FontManager()
|
|
|
|
|
{
|
2003-11-02 04:05:13 +00:00
|
|
|
for( std::map<FontName, Font*>::iterator i = g_mapPathToFont.begin();
|
|
|
|
|
i != g_mapPathToFont.end(); ++i)
|
2002-03-30 20:00:13 +00:00
|
|
|
{
|
2003-11-02 04:05:13 +00:00
|
|
|
const FontName &fn = i->first;
|
2002-09-07 08:20:10 +00:00
|
|
|
Font* pFont = i->second;
|
2003-11-02 04:05:13 +00:00
|
|
|
LOG->Trace( "FONT LEAK: '%s', RefCount = %d.", fn.first.c_str(), pFont->m_iRefCount );
|
2003-01-10 00:31:46 +00:00
|
|
|
delete pFont;
|
2002-03-30 20:00:13 +00:00
|
|
|
}
|
2003-01-06 02:50:25 +00:00
|
|
|
}
|
2002-03-30 20:00:13 +00:00
|
|
|
|
2003-01-10 00:31:46 +00:00
|
|
|
void FontManager::ReloadFonts()
|
|
|
|
|
{
|
2003-11-02 04:05:13 +00:00
|
|
|
for(map<FontName, Font*>::iterator i = g_mapPathToFont.begin();
|
|
|
|
|
i != g_mapPathToFont.end(); ++i)
|
2003-01-10 00:31:46 +00:00
|
|
|
{
|
2003-01-10 02:02:51 +00:00
|
|
|
i->second->Reload();
|
2003-01-05 03:32:41 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Font* FontManager::LoadFont( const CString &sFontOrTextureFilePath, CString sChars )
|
|
|
|
|
{
|
|
|
|
|
// Convert the path to lowercase so that we don't load duplicates.
|
2003-01-10 00:31:46 +00:00
|
|
|
// Really, this does not solve the duplicate problem. We could have two copies
|
2003-01-05 03:32:41 +00:00
|
|
|
// of the same bitmap if there are equivalent but different paths
|
|
|
|
|
// (e.g. "graphics\blah.png" and "..\stepmania\graphics\blah.png" ).
|
|
|
|
|
|
2003-11-02 04:05:13 +00:00
|
|
|
CHECKPOINT_M( ssprintf("FontManager::LoadFont(%s).", sFontOrTextureFilePath.c_str()) );
|
|
|
|
|
const FontName NewName( sFontOrTextureFilePath, sChars );
|
|
|
|
|
map<FontName, Font*>::iterator p = g_mapPathToFont.find( NewName );
|
|
|
|
|
if( p != g_mapPathToFont.end() )
|
|
|
|
|
{
|
2003-01-05 03:32:41 +00:00
|
|
|
Font *pFont=p->second;
|
|
|
|
|
pFont->m_iRefCount++;
|
|
|
|
|
return pFont;
|
|
|
|
|
}
|
|
|
|
|
|
2003-01-10 02:02:51 +00:00
|
|
|
Font *f = new Font;
|
|
|
|
|
f->Load(sFontOrTextureFilePath, sChars);
|
2003-11-02 04:05:13 +00:00
|
|
|
g_mapPathToFont[NewName] = f;
|
2003-01-05 03:32:41 +00:00
|
|
|
return f;
|
|
|
|
|
}
|
|
|
|
|
|
2002-03-30 20:00:13 +00:00
|
|
|
|
2003-01-04 05:20:40 +00:00
|
|
|
void FontManager::UnloadFont( Font *fp )
|
2002-03-30 20:00:13 +00:00
|
|
|
{
|
2003-10-22 06:37:31 +00:00
|
|
|
CHECKPOINT_M( ssprintf("FontManager::UnloadFont(%s).", fp->path.c_str()) );
|
2002-03-30 20:00:13 +00:00
|
|
|
|
2003-11-02 04:05:13 +00:00
|
|
|
for( std::map<FontName, Font*>::iterator i = g_mapPathToFont.begin();
|
|
|
|
|
i != g_mapPathToFont.end(); ++i)
|
2002-03-30 20:00:13 +00:00
|
|
|
{
|
2003-11-02 04:05:13 +00:00
|
|
|
if(i->second != fp)
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
i->second->m_iRefCount--;
|
|
|
|
|
|
|
|
|
|
if( fp->m_iRefCount == 0 )
|
2003-01-04 05:20:40 +00:00
|
|
|
{
|
2003-11-02 04:05:13 +00:00
|
|
|
delete i->second; // free the texture
|
|
|
|
|
g_mapPathToFont.erase( i ); // and remove the key in the map
|
2003-01-04 05:20:40 +00:00
|
|
|
}
|
2003-11-02 04:05:13 +00:00
|
|
|
return;
|
2002-03-30 20:00:13 +00:00
|
|
|
}
|
|
|
|
|
|
2003-01-04 05:20:40 +00:00
|
|
|
RageException::Throw( "Unloaded an unknown font (%p)", fp );
|
2002-03-30 20:00:13 +00:00
|
|
|
}
|
2004-06-08 01:24:17 +00:00
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* (c) 2001-2003 Chris Danford, Glenn Maynard
|
|
|
|
|
* All rights reserved.
|
|
|
|
|
*
|
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a
|
|
|
|
|
* copy of this software and associated documentation files (the
|
|
|
|
|
* "Software"), to deal in the Software without restriction, including
|
|
|
|
|
* without limitation the rights to use, copy, modify, merge, publish,
|
|
|
|
|
* distribute, and/or sell copies of the Software, and to permit persons to
|
|
|
|
|
* whom the Software is furnished to do so, provided that the above
|
|
|
|
|
* copyright notice(s) and this permission notice appear in all copies of
|
|
|
|
|
* the Software and that both the above copyright notice(s) and this
|
|
|
|
|
* permission notice appear in supporting documentation.
|
|
|
|
|
*
|
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
|
|
|
|
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
|
|
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF
|
|
|
|
|
* THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR HOLDERS
|
|
|
|
|
* INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL INDIRECT
|
|
|
|
|
* OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
|
|
|
|
|
* OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
|
|
|
* OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
|
|
|
* PERFORMANCE OF THIS SOFTWARE.
|
|
|
|
|
*/
|