update font stuff

This commit is contained in:
Glenn Maynard
2003-01-08 02:32:30 +00:00
parent b09c5702b4
commit 0452b492c5
4 changed files with 82 additions and 48 deletions
+17 -10
View File
@@ -119,10 +119,17 @@ void BitmapText::BuildChars()
verts.clear(); verts.clear();
tex.clear(); tex.clear();
int TotalHeight = 0; if(m_szTextLines.empty()) return;
int TotalHeight = m_pFont->GetHeight() * m_szTextLines.size();
unsigned i; unsigned i;
for(i = 0; i < m_szTextLines.size(); ++i) int MinSpacing = 0;
TotalHeight += m_iLineHeights[i];
/* The height (from the origin to the baseline): */
int Padding = max(m_pFont->GetLineSpacing(), MinSpacing) - m_pFont->GetHeight();
/* There's padding between every line: */
TotalHeight += Padding * (m_szTextLines.size()-1);
int iY; // the top position of the first row of characters int iY; // the top position of the first row of characters
switch( m_VertAlign ) switch( m_VertAlign )
@@ -135,6 +142,7 @@ void BitmapText::BuildChars()
for( i=0; i<m_szTextLines.size(); i++ ) // foreach line for( i=0; i<m_szTextLines.size(); i++ ) // foreach line
{ {
iY += m_pFont->GetHeight();
const lstring &szLine = m_szTextLines[i]; const lstring &szLine = m_szTextLines[i];
const int iLineWidth = m_iLineWidths[i]; const int iLineWidth = m_iLineWidths[i];
@@ -153,14 +161,12 @@ void BitmapText::BuildChars()
const glyph &g = m_pFont->GetGlyph(szLine[j]); const glyph &g = m_pFont->GetGlyph(szLine[j]);
/* set vertex positions */ /* set vertex positions */
float vshift = g.vshift; float vshift = float(g.fp->vshift);
/* Align the glyph with the font. If either the font or the glyph is /* If either the font or the glyph is kanji, align the character
* kanji, align the centers; otherwise align the baselines. */ * centers. (Otherwise, leave it aligned at the baseline.) */
if(m_pFont->IsKanjiFont() || g.fp->kanji) if(m_pFont->IsKanjiFont() || g.fp->kanji)
vshift += m_pFont->GetCenter() - g.fp->center; vshift += g.fp->GetCenter() - m_pFont->GetCenter();
else
vshift += m_pFont->GetBaseline() - g.fp->baseline;
v[0].p = RageVector3( iX+g.hshift, iY+vshift, 0 ); // top left v[0].p = RageVector3( iX+g.hshift, iY+vshift, 0 ); // top left
v[1].p = RageVector3( iX+g.hshift, iY+vshift+g.height, 0 );// bottom left v[1].p = RageVector3( iX+g.hshift, iY+vshift+g.height, 0 );// bottom left
@@ -180,7 +186,8 @@ void BitmapText::BuildChars()
tex.push_back(m_pFont->GetGlyphTexture(szLine[j])); tex.push_back(m_pFont->GetGlyphTexture(szLine[j]));
} }
iY += m_iLineHeights[i]; /* The amount of padding a line needs: */
iY += Padding;
} }
} }
+49 -28
View File
@@ -37,23 +37,6 @@ void FontPage::Load( const CString &TexturePath, const FontPageSettings &cfg )
m_pTexture = TEXTUREMAN->LoadTexture( m_sTexturePath ); m_pTexture = TEXTUREMAN->LoadTexture( m_sTexturePath );
ASSERT( m_pTexture != NULL ); ASSERT( m_pTexture != NULL );
/* All characters on a page have the same vertical spacing, baseline
* and center. */
baseline = cfg.Baseline;
if(baseline == -1)
{
/* The default baseline is 75% down the frame; this is where it
* tends to be. */
baseline = int(m_pTexture->GetTextureFrameHeight() * .75f);
}
center = cfg.Center;
if(center == -1)
{
/* We don't know the center, so assume it's the center of the frame. */
center = m_pTexture->GetSourceFrameHeight()/2;
}
kanji = cfg.Kanji; kanji = cfg.Kanji;
// load character widths // load character widths
@@ -85,15 +68,45 @@ void FontPage::Load( const CString &TexturePath, const FontPageSettings &cfg )
m_iCharToGlyphNo = cfg.CharToGlyphNo; m_iCharToGlyphNo = cfg.CharToGlyphNo;
int LineSpacing = cfg.LineSpacing; LineSpacing = cfg.LineSpacing;
if(LineSpacing == -1) if(LineSpacing == -1)
LineSpacing = m_pTexture->GetSourceFrameHeight(); LineSpacing = m_pTexture->GetSourceFrameHeight();
SetTextureCoords(FrameWidths, LineSpacing); /* All characters on a page have the same vertical spacing, baseline
* and ascender. */
if(cfg.Baseline != -1 && cfg.Top == -1)
RageException::Throw("Font %s has Baseline but no Top; must have both or neither",
TexturePath.GetString());
if(cfg.Baseline == -1 && cfg.Top != -1)
RageException::Throw("Font %s has Baseline but no Top; must have both or neither",
TexturePath.GetString());
int baseline=0;
if(cfg.Baseline == -1 && cfg.Top == -1)
{
/* We don't have a top and baseline. Assume we're centered in the
* frame, and that LineSpacing is the total height. */
float center = m_pTexture->GetSourceFrameHeight()/2.0f;
height = LineSpacing;
baseline = int(center + LineSpacing/2);
}
else if(cfg.Baseline != -1 && cfg.Top != -1)
{
baseline = cfg.Baseline;
height = baseline-cfg.Top;
}
/* Shift the character up so the top will be rendered at the baseline. */
vshift = -baseline;
SetTextureCoords(FrameWidths);
SetExtraPixels(cfg.DrawExtraPixelsLeft, cfg.DrawExtraPixelsRight); SetExtraPixels(cfg.DrawExtraPixelsLeft, cfg.DrawExtraPixelsRight);
LOG->Trace("Font %s: height %i, baseline %i ( == top %i)",
TexturePath.GetString(), height, baseline, baseline-height);
} }
void FontPage::SetTextureCoords(const vector<int> &widths, int LineSpacing) void FontPage::SetTextureCoords(const vector<int> &widths)
{ {
for(int i = 0; i < m_pTexture->GetNumFrames(); ++i) for(int i = 0; i < m_pTexture->GetNumFrames(); ++i)
{ {
@@ -112,11 +125,6 @@ void FontPage::SetTextureCoords(const vector<int> &widths, int LineSpacing)
/* By default, advance one pixel more than the width. (This could be /* By default, advance one pixel more than the width. (This could be
* an option.) */ * an option.) */
g.hadvance = int(g.width + 1); g.hadvance = int(g.width + 1);
g.vadvance = LineSpacing;
/* Shift the character up so the top of the rendered quad is at the top
* of the character. */
g.vshift = -(m_pTexture->GetSourceFrameHeight() - g.vadvance)/2.0f;
/* Do the same thing with X. Do this by changing the actual rendered /* Do the same thing with X. Do this by changing the actual rendered
* rect, instead of shifting it, so we don't render more than we need to. */ * rect, instead of shifting it, so we don't render more than we need to. */
@@ -189,13 +197,26 @@ int Font::GetLineWidthInSourcePixels( const lstring &szLine ) const
} }
int Font::GetLineHeightInSourcePixels( const lstring &szLine ) const int Font::GetLineHeightInSourcePixels( const lstring &szLine ) const
{
int iLineHeight = 0;
/* The spacing of a line is the spacing of its tallest used font page. XXX */
for( unsigned i=0; i<szLine.size(); i++ )
iLineHeight = max(iLineHeight, GetGlyph(szLine[i]).fp->height);
// iLineSpacing = max(iLineSpacing, def->LineSpacing);
// ?
return iLineHeight;
}
int Font::GetLineSpacingInSourcePixels( const lstring &szLine ) const
{ {
int iLineSpacing = 0; int iLineSpacing = 0;
/* The spacing of a line is the spacing of its tallest used font page. */ /* The spacing of a line is the spacing of its tallest used font page. XXX */
for( unsigned i=0; i<szLine.size(); i++ ) for( unsigned i=0; i<szLine.size(); i++ )
iLineSpacing = max(iLineSpacing, GetGlyph(szLine[i]).vadvance); iLineSpacing = max(iLineSpacing, GetGlyph(szLine[i]).fp->LineSpacing);
// iLineSpacing = max(iLineSpacing, def->LineSpacing);
// ?
return iLineSpacing; return iLineSpacing;
} }
+15 -9
View File
@@ -22,13 +22,13 @@ struct glyph {
RageTexture *Texture; RageTexture *Texture;
/* Number of pixels to advance horizontally after drawing this character. */ /* Number of pixels to advance horizontally after drawing this character. */
int hadvance, vadvance; int hadvance;
/* Size of the actual rendered character. */ /* Size of the actual rendered character. */
float width, height; float width, height;
/* Number of pixels to offset this character when rendering. */ /* Number of pixels to offset this character when rendering. */
float hshift, vshift; float hshift; // , vshift;
/* Texture coordinate rect. */ /* Texture coordinate rect. */
RectF rect; RectF rect;
@@ -39,8 +39,8 @@ struct FontPageSettings {
DrawExtraPixelsRight, DrawExtraPixelsRight,
AddToAllWidths, AddToAllWidths,
LineSpacing, LineSpacing,
Baseline, Top,
Center; Baseline;
float ScaleAllWidthsBy; float ScaleAllWidthsBy;
bool Kanji; bool Kanji;
@@ -53,8 +53,8 @@ struct FontPageSettings {
AddToAllWidths(0), AddToAllWidths(0),
LineSpacing(-1), LineSpacing(-1),
ScaleAllWidthsBy(1), ScaleAllWidthsBy(1),
Top(-1),
Baseline(-1), Baseline(-1),
Center(-1),
Kanji(false) Kanji(false)
{ } { }
}; };
@@ -77,12 +77,14 @@ public:
void Load( const CString &sASCIITexturePath, const FontPageSettings &cfg ); void Load( const CString &sASCIITexturePath, const FontPageSettings &cfg );
/* Page-global properties. */ /* Page-global properties. */
int baseline, center; int height;
bool kanji; bool kanji;
int LineSpacing, vshift;
int GetCenter() const { return height/2; }
private: private:
void SetExtraPixels(int DrawExtraPixelsLeft, int DrawExtraPixelsRight); void SetExtraPixels(int DrawExtraPixelsLeft, int DrawExtraPixelsRight);
void SetTextureCoords(const vector<int> &widths, int LineSpacing); void SetTextureCoords(const vector<int> &widths);
}; };
class Font class Font
@@ -100,6 +102,7 @@ public:
int GetLineWidthInSourcePixels( const lstring &szLine ) const; int GetLineWidthInSourcePixels( const lstring &szLine ) const;
int GetLineHeightInSourcePixels( const lstring &szLine ) const; int GetLineHeightInSourcePixels( const lstring &szLine ) const;
int GetLineSpacingInSourcePixels( const lstring &szLine ) const;
/* Add a FontPage to this font. */ /* Add a FontPage to this font. */
void AddPage(FontPage *fp); void AddPage(FontPage *fp);
@@ -110,9 +113,12 @@ public:
/* Load font-wide settings. */ /* Load font-wide settings. */
void CapsOnly(); void CapsOnly();
int GetBaseline() const { return def->baseline; } // int GetBaseline() const { return def->baseline; }
int GetHeight() const { return def->height; }
bool IsKanjiFont() const { return def->kanji; } bool IsKanjiFont() const { return def->kanji; }
int GetCenter() const { return def->center; } int GetCenter() const { return def->GetCenter(); }
int GetVshift() const { return def->vshift; }
int GetLineSpacing() const { return def->LineSpacing; }
void SetDefaultGlyph(FontPage *fp); void SetDefaultGlyph(FontPage *fp);
+1 -1
View File
@@ -83,8 +83,8 @@ void FontManager::LoadFontPageSettings(FontPageSettings &cfg, IniFile &ini, cons
ini.GetValueI( PageName, "AddToAllWidths", cfg.AddToAllWidths ); ini.GetValueI( PageName, "AddToAllWidths", cfg.AddToAllWidths );
ini.GetValueF( PageName, "ScaleAllWidthsBy", cfg.ScaleAllWidthsBy ); ini.GetValueF( PageName, "ScaleAllWidthsBy", cfg.ScaleAllWidthsBy );
ini.GetValueI( PageName, "LineSpacing", cfg.LineSpacing ); ini.GetValueI( PageName, "LineSpacing", cfg.LineSpacing );
ini.GetValueI( PageName, "Top", cfg.Top );
ini.GetValueI( PageName, "Baseline", cfg.Baseline ); ini.GetValueI( PageName, "Baseline", cfg.Baseline );
ini.GetValueI( PageName, "Center", cfg.Center );
ini.GetValueB( PageName, "Kanji", cfg.Kanji ); ini.GetValueB( PageName, "Kanji", cfg.Kanji );
/* Iterate over all keys. */ /* Iterate over all keys. */