diff --git a/stepmania/src/BitmapText.cpp b/stepmania/src/BitmapText.cpp index c832eb72c3..d7d447d78a 100644 --- a/stepmania/src/BitmapText.cpp +++ b/stepmania/src/BitmapText.cpp @@ -119,10 +119,17 @@ void BitmapText::BuildChars() verts.clear(); tex.clear(); - int TotalHeight = 0; + if(m_szTextLines.empty()) return; + + int TotalHeight = m_pFont->GetHeight() * m_szTextLines.size(); unsigned i; - for(i = 0; i < m_szTextLines.size(); ++i) - TotalHeight += m_iLineHeights[i]; + int MinSpacing = 0; + + /* 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 switch( m_VertAlign ) @@ -135,6 +142,7 @@ void BitmapText::BuildChars() for( i=0; iGetHeight(); const lstring &szLine = m_szTextLines[i]; const int iLineWidth = m_iLineWidths[i]; @@ -153,14 +161,12 @@ void BitmapText::BuildChars() const glyph &g = m_pFont->GetGlyph(szLine[j]); /* 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 - * kanji, align the centers; otherwise align the baselines. */ + /* If either the font or the glyph is kanji, align the character + * centers. (Otherwise, leave it aligned at the baseline.) */ if(m_pFont->IsKanjiFont() || g.fp->kanji) - vshift += m_pFont->GetCenter() - g.fp->center; - else - vshift += m_pFont->GetBaseline() - g.fp->baseline; + vshift += g.fp->GetCenter() - m_pFont->GetCenter(); 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 @@ -180,7 +186,8 @@ void BitmapText::BuildChars() tex.push_back(m_pFont->GetGlyphTexture(szLine[j])); } - iY += m_iLineHeights[i]; + /* The amount of padding a line needs: */ + iY += Padding; } } diff --git a/stepmania/src/Font.cpp b/stepmania/src/Font.cpp index 0676f9033c..7a98c0d343 100644 --- a/stepmania/src/Font.cpp +++ b/stepmania/src/Font.cpp @@ -37,23 +37,6 @@ void FontPage::Load( const CString &TexturePath, const FontPageSettings &cfg ) m_pTexture = TEXTUREMAN->LoadTexture( m_sTexturePath ); 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; // load character widths @@ -85,15 +68,45 @@ void FontPage::Load( const CString &TexturePath, const FontPageSettings &cfg ) m_iCharToGlyphNo = cfg.CharToGlyphNo; - int LineSpacing = cfg.LineSpacing; + LineSpacing = cfg.LineSpacing; if(LineSpacing == -1) 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); + + LOG->Trace("Font %s: height %i, baseline %i ( == top %i)", + TexturePath.GetString(), height, baseline, baseline-height); } -void FontPage::SetTextureCoords(const vector &widths, int LineSpacing) +void FontPage::SetTextureCoords(const vector &widths) { for(int i = 0; i < m_pTexture->GetNumFrames(); ++i) { @@ -112,11 +125,6 @@ void FontPage::SetTextureCoords(const vector &widths, int LineSpacing) /* By default, advance one pixel more than the width. (This could be * an option.) */ 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 * 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 iLineHeight = 0; + + /* The spacing of a line is the spacing of its tallest used font page. XXX */ + for( unsigned i=0; iheight); +// iLineSpacing = max(iLineSpacing, def->LineSpacing); +// ? + return iLineHeight; +} + +int Font::GetLineSpacingInSourcePixels( const lstring &szLine ) const { 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; iLineSpacing); +// iLineSpacing = max(iLineSpacing, def->LineSpacing); +// ? return iLineSpacing; } diff --git a/stepmania/src/Font.h b/stepmania/src/Font.h index 7a5a264bc8..c10b68fe46 100644 --- a/stepmania/src/Font.h +++ b/stepmania/src/Font.h @@ -22,13 +22,13 @@ struct glyph { RageTexture *Texture; /* Number of pixels to advance horizontally after drawing this character. */ - int hadvance, vadvance; + int hadvance; /* Size of the actual rendered character. */ float width, height; /* Number of pixels to offset this character when rendering. */ - float hshift, vshift; + float hshift; // , vshift; /* Texture coordinate rect. */ RectF rect; @@ -39,8 +39,8 @@ struct FontPageSettings { DrawExtraPixelsRight, AddToAllWidths, LineSpacing, - Baseline, - Center; + Top, + Baseline; float ScaleAllWidthsBy; bool Kanji; @@ -53,8 +53,8 @@ struct FontPageSettings { AddToAllWidths(0), LineSpacing(-1), ScaleAllWidthsBy(1), + Top(-1), Baseline(-1), - Center(-1), Kanji(false) { } }; @@ -77,12 +77,14 @@ public: void Load( const CString &sASCIITexturePath, const FontPageSettings &cfg ); /* Page-global properties. */ - int baseline, center; + int height; bool kanji; + int LineSpacing, vshift; + int GetCenter() const { return height/2; } private: void SetExtraPixels(int DrawExtraPixelsLeft, int DrawExtraPixelsRight); - void SetTextureCoords(const vector &widths, int LineSpacing); + void SetTextureCoords(const vector &widths); }; class Font @@ -100,6 +102,7 @@ public: int GetLineWidthInSourcePixels( const lstring &szLine ) const; int GetLineHeightInSourcePixels( const lstring &szLine ) const; + int GetLineSpacingInSourcePixels( const lstring &szLine ) const; /* Add a FontPage to this font. */ void AddPage(FontPage *fp); @@ -110,9 +113,12 @@ public: /* Load font-wide settings. */ 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; } - 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); diff --git a/stepmania/src/FontManager.cpp b/stepmania/src/FontManager.cpp index 3e62ba0ddb..31c78f23a6 100644 --- a/stepmania/src/FontManager.cpp +++ b/stepmania/src/FontManager.cpp @@ -83,8 +83,8 @@ void FontManager::LoadFontPageSettings(FontPageSettings &cfg, IniFile &ini, cons ini.GetValueI( PageName, "AddToAllWidths", cfg.AddToAllWidths ); ini.GetValueF( PageName, "ScaleAllWidthsBy", cfg.ScaleAllWidthsBy ); ini.GetValueI( PageName, "LineSpacing", cfg.LineSpacing ); + ini.GetValueI( PageName, "Top", cfg.Top ); ini.GetValueI( PageName, "Baseline", cfg.Baseline ); - ini.GetValueI( PageName, "Center", cfg.Center ); ini.GetValueB( PageName, "Kanji", cfg.Kanji ); /* Iterate over all keys. */