diff --git a/common/gal/stroke_font.cpp b/common/gal/stroke_font.cpp index ea08fa49ab..a6958f39c4 100644 --- a/common/gal/stroke_font.cpp +++ b/common/gal/stroke_font.cpp @@ -397,18 +397,22 @@ VECTOR2D STROKE_FONT::computeTextLineSize( const UTF8& aText ) const } -VECTOR2D STROKE_FONT::ComputeStringBoundaryLimits( const UTF8& aText, VECTOR2D aGlyphSize, - double aGlyphThickness, - double* aTopLimit, double* aBottomLimit ) const +VECTOR2D STROKE_FONT::ComputeStringBoundaryLimits( const UTF8& aText, const VECTOR2D& aGlyphSize, + double aGlyphThickness ) const { VECTOR2D string_bbox; - double ymax = 0.0; - double ymin = 0.0; + int line_count = 1; + double maxX = 0.0, curX = 0.0; for( UTF8::uni_iter it = aText.ubegin(), end = aText.uend(); it < end; ++it ) { - wxASSERT_MSG( *it != '\n', - wxT( "This function is intended to work with single line strings" ) ); + if( *it == '\n' ) + { + curX = 0.0; + maxX = std::max( maxX, curX ); + ++line_count; + continue; + } // If it is double tilda, then it is displayed as a single tilda // If it is single tilda, then it is toggling overbar, so we need to skip it @@ -425,36 +429,17 @@ VECTOR2D STROKE_FONT::ComputeStringBoundaryLimits( const UTF8& aText, VECTOR2D a dd = '?' - ' '; const BOX2D& box = m_glyphBoundingBoxes[dd]; - - string_bbox.x += box.GetEnd().x; - - // Calculate Y min and Y max - if( aTopLimit ) - { - ymax = std::max( ymax, box.GetY() ); - ymax = std::max( ymax, box.GetEnd().y ); - } - - if( aBottomLimit ) - { - ymin = std::min( ymin, box.GetY() ); - ymin = std::min( ymin, box.GetEnd().y ); - } + curX += box.GetEnd().x; } + string_bbox.x = std::max( maxX, curX ); string_bbox.x *= aGlyphSize.x; string_bbox.x += aGlyphThickness; - string_bbox.y = aGlyphSize.y + aGlyphThickness; + string_bbox.y = line_count * GetInterline( aGlyphSize.y, aGlyphThickness ); // For italic correction, take in account italic tilt if( m_gal->IsFontItalic() ) string_bbox.x += string_bbox.y * STROKE_FONT::ITALIC_TILT; - if( aTopLimit ) - *aTopLimit = ymax * aGlyphSize.y; - - if( aBottomLimit ) - *aBottomLimit = ymin * aGlyphSize.y; - return string_bbox; } diff --git a/include/gal/stroke_font.h b/include/gal/stroke_font.h index b92ccd9899..b1a6680bf8 100644 --- a/include/gal/stroke_font.h +++ b/include/gal/stroke_font.h @@ -87,24 +87,13 @@ public: } /** - * Compute the boundary limits of aText (the bbox of all shapes). - * The overbar is not taken in account, by ~ are skipped. - * @return a VECTOR2D giving the h size of line, and the V glyph size - * and ( if aTopLimit or aBottomLimit not NULL ) the top and bottom - * limits of the text. - */ - VECTOR2D ComputeStringBoundaryLimits( const UTF8& aText, VECTOR2D aGlyphSize, - double aGlyphThickness, - double* aTopLimit = NULL, double* aBottomLimit = NULL ) const; - - /** - * @brief Compute the X and Y size of a given text. The text is expected to be - * a only one line text. + * Compute the boundary limits of aText (the bounding box of all shapes). + * The overbar and alignment are not taken in account, '~' characters are skipped. * - * @param aText is the text string (one line). - * @return the text size. + * @return a VECTOR2D giving the width and height of text. */ - VECTOR2D ComputeTextLineSize( const UTF8& aText ) const; + VECTOR2D ComputeStringBoundaryLimits( const UTF8& aText, const VECTOR2D& aGlyphSize, + double aGlyphThickness ) const; /** * Compute the vertical position of an overbar, sometimes used in texts.