Move stroke designation into font page name area (better than having 2 png files with identical names except for texture hints). Add FontBaseZoom to allow for double resolution fonts without setting the zoom to 0.5 for every BitmapText.

This commit is contained in:
Chris Danford
2008-03-27 22:23:21 +00:00
parent 5c1fdcbf92
commit d38f040487
3 changed files with 27 additions and 28 deletions
+8 -14
View File
@@ -445,34 +445,28 @@ void BitmapText::SetMaxHeight( float fMaxHeight )
void BitmapText::UpdateBaseZoom()
{
const float fBaseZoom = m_pFont->GetFontBaseZoom();
if( m_fMaxWidth == 0 )
{
this->SetBaseZoomX( 1 );
this->SetBaseZoomX( fBaseZoom );
}
else
{
const float fWidth = GetUnzoomedWidth();
if( fWidth != 0 ) // don't divide by 0
{
/* Never decrease the zoom. */
const float fZoom = min( 1, m_fMaxWidth/fWidth );
this->SetBaseZoomX( fZoom );
}
const float fZoom = min( 1, m_fMaxWidth/fWidth ); /* Never increase the zoom. */
this->SetBaseZoomX( fBaseZoom * fZoom );
}
if( m_fMaxHeight == 0 )
{
this->SetBaseZoomY( 1 );
this->SetBaseZoomY( fBaseZoom );
}
else
{
const float fHeight = GetUnzoomedHeight();
if( fHeight != 0 ) // don't divide by 0
{
/* Never decrease the zoom. */
const float fZoom = min( 1, m_fMaxHeight/fHeight );
this->SetBaseZoomY( fZoom );
}
const float fZoom = min( 1, m_fMaxHeight/fHeight ); /* Never increase the zoom. */
this->SetBaseZoomY( fBaseZoom * fZoom );
}
}
+16 -14
View File
@@ -29,21 +29,17 @@ void FontPage::Load( const FontPageSettings &cfg )
ASSERT( m_FontPageTextures.m_pTextureMain != NULL );
RageTextureID ID2 = ID1;
/* "arial 20 16x16 [main].png" => "arial 20 16x16 [main-stroke].png" */
if( ID2.filename.find("]") != string::npos )
{
/* "arial 20 16x16.png" => "arial 20 16x16 (stroke).png" */
size_t pos = ID2.filename.find_last_of( '.' );
if( pos == RString::npos )
ID2.filename += " (stroke)";
else
ID2.filename.insert( pos, " (stroke)" );
}
if( IsAFile(ID2.filename) )
{
m_FontPageTextures.m_pTextureStroke = TEXTUREMAN->LoadTexture( ID2 );
ASSERT( m_FontPageTextures.m_pTextureStroke != NULL );
ASSERT_M( m_FontPageTextures.m_pTextureMain->GetSourceFrameWidth() == m_FontPageTextures.m_pTextureStroke->GetSourceFrameWidth(), ssprintf("'%s' and '%s' must have the same frame widths", ID1.filename.c_str(), ID2.filename.c_str()) );
ASSERT_M( m_FontPageTextures.m_pTextureMain->GetNumFrames() == m_FontPageTextures.m_pTextureStroke->GetNumFrames(), ssprintf("'%s' and '%s' must have the same frame dimensions", ID1.filename.c_str(), ID2.filename.c_str()) );
ID2.filename.Replace( "]", "-stroke]" );
if( IsAFile(ID2.filename) )
{
m_FontPageTextures.m_pTextureStroke = TEXTUREMAN->LoadTexture( ID2 );
ASSERT( m_FontPageTextures.m_pTextureStroke != NULL );
ASSERT_M( m_FontPageTextures.m_pTextureMain->GetSourceFrameWidth() == m_FontPageTextures.m_pTextureStroke->GetSourceFrameWidth(), ssprintf("'%s' and '%s' must have the same frame widths", ID1.filename.c_str(), ID2.filename.c_str()) );
ASSERT_M( m_FontPageTextures.m_pTextureMain->GetNumFrames() == m_FontPageTextures.m_pTextureStroke->GetNumFrames(), ssprintf("'%s' and '%s' must have the same frame dimensions", ID1.filename.c_str(), ID2.filename.c_str()) );
}
}
// load character widths
@@ -232,6 +228,7 @@ Font::Font()
m_iRefCount = 1;
m_pDefault = NULL;
m_bRightToLeft = false;
m_fFontBaseZoom = 1;
}
Font::~Font()
@@ -693,6 +690,7 @@ void Font::Load( const RString &sIniPath, RString sChars )
ini.RenameKey("Char Widths", "main");
ini.GetValue( "main", "CapitalsOnly", bCapitalsOnly );
ini.GetValue( "main", "RightToLeft", m_bRightToLeft );
ini.GetValue( "main", "FontBaseZoom", m_fFontBaseZoom );
}
{
@@ -742,6 +740,10 @@ void Font::Load( const RString &sIniPath, RString sChars )
/* Grab the page name, eg "foo" from "Normal [foo].png". */
RString sPagename = GetPageNameFromFileName( sTexturePath );
// Ignore stroke textures
if( sTexturePath.find("-stroke") != string::npos )
continue;
/* Load settings for this page from the INI. */
FontPageSettings cfg;
+3
View File
@@ -147,6 +147,7 @@ public:
void SetDefaultGlyph( FontPage *pPage );
bool IsRightToLeft() const { return m_bRightToLeft; };
float GetFontBaseZoom() const { return m_fFontBaseZoom; };
private:
/* List of pages and fonts that we use (and are responsible for freeing). */
@@ -165,6 +166,8 @@ private:
// There may be a better way to handle this.
bool m_bRightToLeft;
float m_fFontBaseZoom;
/* We keep this around only for reloading. */
RString m_sChars;