fix glyphs have wrong frame in Numbers fonts

This commit is contained in:
Chris Danford
2003-06-06 20:30:57 +00:00
parent 2cb374103f
commit b032ac4737
2 changed files with 39 additions and 71 deletions
+4 -29
View File
@@ -24,8 +24,6 @@
#include "GameManager.h" #include "GameManager.h"
#include "FontCharmaps.h" #include "FontCharmaps.h"
#include "FontCharAliases.h" #include "FontCharAliases.h"
#include "SDL_video.h"
#include "SDL_image.h"
/* Last private-use Unicode character: */ /* Last private-use Unicode character: */
const wchar_t Font::DEFAULT_GLYPH = 0xF8FF; const wchar_t Font::DEFAULT_GLYPH = 0xF8FF;
@@ -33,7 +31,6 @@ const wchar_t Font::DEFAULT_GLYPH = 0xF8FF;
FontPage::FontPage() FontPage::FontPage()
{ {
m_pTexture = NULL; m_pTexture = NULL;
m_pSurface = NULL;
} }
void FontPage::Load( FontPageSettings cfg ) void FontPage::Load( FontPageSettings cfg )
@@ -45,10 +42,7 @@ void FontPage::Load( FontPageSettings cfg )
ID.bStretch = true; ID.bStretch = true;
m_pTexture = TEXTUREMAN->LoadTexture( ID ); m_pTexture = TEXTUREMAN->LoadTexture( ID );
ASSERT( m_pTexture ); ASSERT( m_pTexture != NULL );
m_pSurface = IMG_Load( ID.filename );
ASSERT( m_pSurface );
// load character widths // load character widths
vector<int> FrameWidths; vector<int> FrameWidths;
@@ -116,25 +110,15 @@ void FontPage::Load( FontPageSettings cfg )
void FontPage::SetTextureCoords(const vector<int> &widths) void FontPage::SetTextureCoords(const vector<int> &widths)
{ {
for(int y = 0; y < m_pTexture->GetFramesHigh(); ++y) for(int i = 0; i < m_pTexture->GetNumFrames(); ++i)
{ {
for(int x = 0; x < m_pTexture->GetFramesWide(); ++x)
{
int i = y*m_pTexture->GetFramesHigh() + x;
glyph g; glyph g;
g.fp = this; g.fp = this;
/* Make a copy of each texture rect, reducing each to the actual dimensions /* Make a copy of each texture rect, reducing each to the actual dimensions
* of the character (most characters don't take a full block). */ * of the character (most characters don't take a full block). */
g.rect = *m_pTexture->GetTextureCoordRect(i); g.rect = *m_pTexture->GetTextureCoordRect(i);;
g.blitSrc = RectI(
m_pTexture->GetSourceFrameWidth()*x,
m_pTexture->GetSourceFrameHeight()*y,
m_pTexture->GetSourceFrameWidth()*(x+1),
m_pTexture->GetSourceFrameHeight()*(y+1) );
/* Set the width and height to the width and line spacing, respectively. */ /* Set the width and height to the width and line spacing, respectively. */
g.width = float(widths[i]); g.width = float(widths[i]);
@@ -160,9 +144,6 @@ void FontPage::SetTextureCoords(const vector<int> &widths)
iPixelsToChopOff--; iPixelsToChopOff--;
g.width++; g.width++;
} }
g.blitSrc.left += iPixelsToChopOff/2;
g.blitSrc.right -= iPixelsToChopOff/2;
float fTexCoordsToChopOff = float(iPixelsToChopOff) / m_pTexture->GetSourceWidth(); float fTexCoordsToChopOff = float(iPixelsToChopOff) / m_pTexture->GetSourceWidth();
g.rect.left += fTexCoordsToChopOff/2; g.rect.left += fTexCoordsToChopOff/2;
@@ -170,11 +151,9 @@ void FontPage::SetTextureCoords(const vector<int> &widths)
} }
g.Texture = m_pTexture; g.Texture = m_pTexture;
g.Surface = m_pSurface;
glyphs.push_back(g); glyphs.push_back(g);
} }
}
} }
void FontPage::SetExtraPixels(int DrawExtraPixelsLeft, int DrawExtraPixelsRight) void FontPage::SetExtraPixels(int DrawExtraPixelsLeft, int DrawExtraPixelsRight)
@@ -200,8 +179,6 @@ void FontPage::SetExtraPixels(int DrawExtraPixelsLeft, int DrawExtraPixelsRight)
float ExtraRight = min( float(DrawExtraPixelsRight), (iFrameWidth-iCharWidth)/2.0f ); float ExtraRight = min( float(DrawExtraPixelsRight), (iFrameWidth-iCharWidth)/2.0f );
/* Move left and expand right. */ /* Move left and expand right. */
glyphs[i].blitSrc.left -= ExtraLeft;
glyphs[i].blitSrc.right += ExtraRight;
glyphs[i].rect.left -= ExtraLeft / m_pTexture->GetSourceWidth(); glyphs[i].rect.left -= ExtraLeft / m_pTexture->GetSourceWidth();
glyphs[i].rect.right += ExtraRight / m_pTexture->GetSourceWidth(); glyphs[i].rect.right += ExtraRight / m_pTexture->GetSourceWidth();
glyphs[i].hshift -= ExtraLeft; glyphs[i].hshift -= ExtraLeft;
@@ -211,10 +188,8 @@ void FontPage::SetExtraPixels(int DrawExtraPixelsLeft, int DrawExtraPixelsRight)
FontPage::~FontPage() FontPage::~FontPage()
{ {
if( m_pTexture ) if( m_pTexture != NULL )
TEXTUREMAN->UnloadTexture( m_pTexture ); TEXTUREMAN->UnloadTexture( m_pTexture );
if( m_pSurface )
SDL_FreeSurface( m_pSurface );
} }
int Font::GetLineWidthInSourcePixels( const wstring &szLine ) const int Font::GetLineWidthInSourcePixels( const wstring &szLine ) const
-7
View File
@@ -16,14 +16,11 @@
#include "IniFile.h" #include "IniFile.h"
class FontPage; class FontPage;
struct SDL_Surface;
struct glyph { struct glyph {
FontPage *fp; FontPage *fp;
RageTexture *Texture; RageTexture *Texture;
RageTexture *GetTexture() const { return const_cast<RageTexture *>(Texture); } RageTexture *GetTexture() const { return const_cast<RageTexture *>(Texture); }
SDL_Surface *Surface;
SDL_Surface *GetSurface() const { return Surface; }
/* Number of pixels to advance horizontally after drawing this character. */ /* Number of pixels to advance horizontally after drawing this character. */
int hadvance; int hadvance;
@@ -36,9 +33,6 @@ struct glyph {
/* Texture coordinate rect. */ /* Texture coordinate rect. */
RectF rect; RectF rect;
/* rect in pixels */
RectI blitSrc;
}; };
struct FontPageSettings struct FontPageSettings
@@ -77,7 +71,6 @@ class FontPage
{ {
public: public:
RageTexture* m_pTexture; RageTexture* m_pTexture;
SDL_Surface* m_pSurface;
CString m_sTexturePath; CString m_sTexturePath;