diff --git a/common/gal/stroke_font.cpp b/common/gal/stroke_font.cpp index f12f9ad80e..31441f5776 100644 --- a/common/gal/stroke_font.cpp +++ b/common/gal/stroke_font.cpp @@ -40,7 +40,8 @@ STROKE_FONT::STROKE_FONT( GAL* aGal ) : m_gal( aGal ), m_bold( false ), m_italic( false ), - m_mirrored( false ) + m_mirrored( false ), + m_overbar( false ) { // Default values 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 ) { + if( aText.empty() ) + return; + // Context needs to be saved before any transformations m_gal->Save(); diff --git a/include/gal/stroke_font.h b/include/gal/stroke_font.h index 71b2d421ed..fa16f6f0ac 100644 --- a/include/gal/stroke_font.h +++ b/include/gal/stroke_font.h @@ -189,17 +189,13 @@ private: * @param aText is the text to be checked. * @return unsigned - The number of lines in aText. */ - unsigned linesCount( const UTF8& aText ) const + inline unsigned linesCount( const UTF8& aText ) const { - unsigned lines = 1; - - for( UTF8::const_iterator it = aText.begin(), itEnd = aText.end(); it != itEnd; ++it ) - { - if( *it == '\n' ) - ++lines; - } - - return lines; + if( aText.empty() ) + return 0; // std::count does not work well with empty strings + else + // aText.end() - 1 is to skip a newline character that is potentially at the end + return std::count( aText.begin(), aText.end() - 1, '\n' ) + 1; } ///> Factor that determines relative height of overbar. @@ -208,7 +204,7 @@ private: ///> Factor that determines relative line width for bold text. static const double BOLD_FACTOR; - ///> Scale factor for the glyph + ///> Scale factor for a glyph static const double HERSHEY_SCALE; }; } // namespace KIGFX