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 "FontCharmaps.h"
#include "FontCharAliases.h"
#include "SDL_video.h"
#include "SDL_image.h"
/* Last private-use Unicode character: */
const wchar_t Font::DEFAULT_GLYPH = 0xF8FF;
@@ -33,7 +31,6 @@ const wchar_t Font::DEFAULT_GLYPH = 0xF8FF;
FontPage::FontPage()
{
m_pTexture = NULL;
m_pSurface = NULL;
}
void FontPage::Load( FontPageSettings cfg )
@@ -45,10 +42,7 @@ void FontPage::Load( FontPageSettings cfg )
ID.bStretch = true;
m_pTexture = TEXTUREMAN->LoadTexture( ID );
ASSERT( m_pTexture );
m_pSurface = IMG_Load( ID.filename );
ASSERT( m_pSurface );
ASSERT( m_pTexture != NULL );
// load character widths
vector<int> FrameWidths;
@@ -116,25 +110,15 @@ void FontPage::Load( FontPageSettings cfg )
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;
g.fp = this;
/* Make a copy of each texture rect, reducing each to the actual dimensions
* of the character (most characters don't take a full block). */
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) );
g.rect = *m_pTexture->GetTextureCoordRect(i);;
/* Set the width and height to the width and line spacing, respectively. */
g.width = float(widths[i]);
@@ -160,9 +144,6 @@ void FontPage::SetTextureCoords(const vector<int> &widths)
iPixelsToChopOff--;
g.width++;
}
g.blitSrc.left += iPixelsToChopOff/2;
g.blitSrc.right -= iPixelsToChopOff/2;
float fTexCoordsToChopOff = float(iPixelsToChopOff) / m_pTexture->GetSourceWidth();
g.rect.left += fTexCoordsToChopOff/2;
@@ -170,11 +151,9 @@ void FontPage::SetTextureCoords(const vector<int> &widths)
}
g.Texture = m_pTexture;
g.Surface = m_pSurface;
glyphs.push_back(g);
}
}
}
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 );
/* 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.right += ExtraRight / m_pTexture->GetSourceWidth();
glyphs[i].hshift -= ExtraLeft;
@@ -211,10 +188,8 @@ void FontPage::SetExtraPixels(int DrawExtraPixelsLeft, int DrawExtraPixelsRight)
FontPage::~FontPage()
{
if( m_pTexture )
if( m_pTexture != NULL )
TEXTUREMAN->UnloadTexture( m_pTexture );
if( m_pSurface )
SDL_FreeSurface( m_pSurface );
}
int Font::GetLineWidthInSourcePixels( const wstring &szLine ) const
-7
View File
@@ -16,14 +16,11 @@
#include "IniFile.h"
class FontPage;
struct SDL_Surface;
struct glyph {
FontPage *fp;
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. */
int hadvance;
@@ -36,9 +33,6 @@ struct glyph {
/* Texture coordinate rect. */
RectF rect;
/* rect in pixels */
RectI blitSrc;
};
struct FontPageSettings
@@ -77,7 +71,6 @@ class FontPage
{
public:
RageTexture* m_pTexture;
SDL_Surface* m_pSurface;
CString m_sTexturePath;