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() void BitmapText::UpdateBaseZoom()
{ {
const float fBaseZoom = m_pFont->GetFontBaseZoom();
if( m_fMaxWidth == 0 ) if( m_fMaxWidth == 0 )
{ {
this->SetBaseZoomX( 1 ); this->SetBaseZoomX( fBaseZoom );
} }
else else
{ {
const float fWidth = GetUnzoomedWidth(); const float fWidth = GetUnzoomedWidth();
if( fWidth != 0 ) // don't divide by 0 const float fZoom = min( 1, m_fMaxWidth/fWidth ); /* Never increase the zoom. */
{ this->SetBaseZoomX( fBaseZoom * fZoom );
/* Never decrease the zoom. */
const float fZoom = min( 1, m_fMaxWidth/fWidth );
this->SetBaseZoomX( fZoom );
}
} }
if( m_fMaxHeight == 0 ) if( m_fMaxHeight == 0 )
{ {
this->SetBaseZoomY( 1 ); this->SetBaseZoomY( fBaseZoom );
} }
else else
{ {
const float fHeight = GetUnzoomedHeight(); const float fHeight = GetUnzoomedHeight();
if( fHeight != 0 ) // don't divide by 0 const float fZoom = min( 1, m_fMaxHeight/fHeight ); /* Never increase the zoom. */
{ this->SetBaseZoomY( fBaseZoom * fZoom );
/* Never decrease the zoom. */
const float fZoom = min( 1, m_fMaxHeight/fHeight );
this->SetBaseZoomY( fZoom );
}
} }
} }
+10 -8
View File
@@ -29,15 +29,10 @@ void FontPage::Load( const FontPageSettings &cfg )
ASSERT( m_FontPageTextures.m_pTextureMain != NULL ); ASSERT( m_FontPageTextures.m_pTextureMain != NULL );
RageTextureID ID2 = ID1; 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" */ ID2.filename.Replace( "]", "-stroke]" );
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) ) if( IsAFile(ID2.filename) )
{ {
m_FontPageTextures.m_pTextureStroke = TEXTUREMAN->LoadTexture( ID2 ); m_FontPageTextures.m_pTextureStroke = TEXTUREMAN->LoadTexture( ID2 );
@@ -45,6 +40,7 @@ void FontPage::Load( const FontPageSettings &cfg )
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->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()) ); 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 // load character widths
vector<int> aiFrameWidths; vector<int> aiFrameWidths;
@@ -232,6 +228,7 @@ Font::Font()
m_iRefCount = 1; m_iRefCount = 1;
m_pDefault = NULL; m_pDefault = NULL;
m_bRightToLeft = false; m_bRightToLeft = false;
m_fFontBaseZoom = 1;
} }
Font::~Font() Font::~Font()
@@ -693,6 +690,7 @@ void Font::Load( const RString &sIniPath, RString sChars )
ini.RenameKey("Char Widths", "main"); ini.RenameKey("Char Widths", "main");
ini.GetValue( "main", "CapitalsOnly", bCapitalsOnly ); ini.GetValue( "main", "CapitalsOnly", bCapitalsOnly );
ini.GetValue( "main", "RightToLeft", m_bRightToLeft ); ini.GetValue( "main", "RightToLeft", m_bRightToLeft );
ini.GetValue( "main", "FontBaseZoom", m_fFontBaseZoom );
} }
{ {
@@ -743,6 +741,10 @@ void Font::Load( const RString &sIniPath, RString sChars )
/* Grab the page name, eg "foo" from "Normal [foo].png". */ /* Grab the page name, eg "foo" from "Normal [foo].png". */
RString sPagename = GetPageNameFromFileName( sTexturePath ); RString sPagename = GetPageNameFromFileName( sTexturePath );
// Ignore stroke textures
if( sTexturePath.find("-stroke") != string::npos )
continue;
/* Load settings for this page from the INI. */ /* Load settings for this page from the INI. */
FontPageSettings cfg; FontPageSettings cfg;
LoadFontPageSettings( cfg, ini, sTexturePath, "common", sChars ); LoadFontPageSettings( cfg, ini, sTexturePath, "common", sChars );
+3
View File
@@ -147,6 +147,7 @@ public:
void SetDefaultGlyph( FontPage *pPage ); void SetDefaultGlyph( FontPage *pPage );
bool IsRightToLeft() const { return m_bRightToLeft; }; bool IsRightToLeft() const { return m_bRightToLeft; };
float GetFontBaseZoom() const { return m_fFontBaseZoom; };
private: private:
/* List of pages and fonts that we use (and are responsible for freeing). */ /* 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. // There may be a better way to handle this.
bool m_bRightToLeft; bool m_bRightToLeft;
float m_fFontBaseZoom;
/* We keep this around only for reloading. */ /* We keep this around only for reloading. */
RString m_sChars; RString m_sChars;