Fixed vertical alignment for strings that contain a newline character at the end (GAL).

This commit is contained in:
Maciej Suminski 2014-07-07 13:09:44 +02:00
parent fb0045a898
commit 0304598a71
2 changed files with 12 additions and 12 deletions

View File

@ -40,7 +40,8 @@ STROKE_FONT::STROKE_FONT( GAL* aGal ) :
m_gal( aGal ), m_gal( aGal ),
m_bold( false ), m_bold( false ),
m_italic( false ), m_italic( false ),
m_mirrored( false ) m_mirrored( false ),
m_overbar( false )
{ {
// Default values // Default values
m_glyphSize = VECTOR2D( 10.0, 10.0 ); m_glyphSize = VECTOR2D( 10.0, 10.0 );
@ -149,6 +150,9 @@ BOX2D STROKE_FONT::computeBoundingBox( const GLYPH& aGLYPH, const VECTOR2D& aGLY
void STROKE_FONT::Draw( const UTF8& aText, const VECTOR2D& aPosition, double aRotationAngle ) void STROKE_FONT::Draw( const UTF8& aText, const VECTOR2D& aPosition, double aRotationAngle )
{ {
if( aText.empty() )
return;
// Context needs to be saved before any transformations // Context needs to be saved before any transformations
m_gal->Save(); m_gal->Save();

View File

@ -189,17 +189,13 @@ private:
* @param aText is the text to be checked. * @param aText is the text to be checked.
* @return unsigned - The number of lines in aText. * @return unsigned - The number of lines in aText.
*/ */
unsigned linesCount( const UTF8& aText ) const inline unsigned linesCount( const UTF8& aText ) const
{ {
unsigned lines = 1; if( aText.empty() )
return 0; // std::count does not work well with empty strings
for( UTF8::const_iterator it = aText.begin(), itEnd = aText.end(); it != itEnd; ++it ) else
{ // aText.end() - 1 is to skip a newline character that is potentially at the end
if( *it == '\n' ) return std::count( aText.begin(), aText.end() - 1, '\n' ) + 1;
++lines;
}
return lines;
} }
///> Factor that determines relative height of overbar. ///> Factor that determines relative height of overbar.
@ -208,7 +204,7 @@ private:
///> Factor that determines relative line width for bold text. ///> Factor that determines relative line width for bold text.
static const double BOLD_FACTOR; static const double BOLD_FACTOR;
///> Scale factor for the glyph ///> Scale factor for a glyph
static const double HERSHEY_SCALE; static const double HERSHEY_SCALE;
}; };
} // namespace KIGFX } // namespace KIGFX