Changed asserts and exceptions in Font to non-fatal error messages. Changed BitmapText::CropToWidth to ask the font how many glyphs will fit instead of removing one glyph at a time.

This commit is contained in:
Kyzentun
2015-02-27 17:38:30 -07:00
parent 7c2fd0153c
commit 50ab63b573
4 changed files with 165 additions and 59 deletions
+15 -7
View File
@@ -622,19 +622,27 @@ bool BitmapText::StringWillUseAlternate( const RString& sText, const RString& sA
return true;
}
void BitmapText::CropToWidth( int iMaxWidthInSourcePixels )
void BitmapText::CropLineToWidth(size_t l, int width)
{
iMaxWidthInSourcePixels = max( 0, iMaxWidthInSourcePixels );
for( unsigned l=0; l<m_wTextLines.size(); l++ ) // for each line
if(l < m_wTextLines.size())
{
while( m_iLineWidths[l] > iMaxWidthInSourcePixels )
int used_width= width;
wstring& line= m_wTextLines[l];
int fit= m_pFont->GetGlyphsThatFit(line, &used_width);
if(fit < line.size())
{
m_wTextLines[l].erase( m_wTextLines[l].end()-1, m_wTextLines[l].end() );
m_iLineWidths[l] = m_pFont->GetLineWidthInSourcePixels( m_wTextLines[l] );
line.erase(line.begin()+fit, line.end());
}
m_iLineWidths[l]= used_width;
}
}
void BitmapText::CropToWidth(int width)
{
for(size_t l= 0; l < m_wTextLines.size(); ++l)
{
CropLineToWidth(l, width);
}
BuildChars();
}