Commit 877dd3f7 authored by Maciej Suminski's avatar Maciej Suminski

Added multiline strings and text overbars rendering using GAL.

parent 53ec1efc
...@@ -125,7 +125,7 @@ void STROKE_FONT::LoadAttributes( const EDA_TEXT* aText ) ...@@ -125,7 +125,7 @@ void STROKE_FONT::LoadAttributes( const EDA_TEXT* aText )
} }
BOX2D STROKE_FONT::computeBoundingBox( Glyph aGlyph, VECTOR2D aGlyphBoundingX ) BOX2D STROKE_FONT::computeBoundingBox( const Glyph& aGlyph, const VECTOR2D& aGlyphBoundingX ) const
{ {
BOX2D boundingBox; BOX2D boundingBox;
...@@ -134,9 +134,9 @@ BOX2D STROKE_FONT::computeBoundingBox( Glyph aGlyph, VECTOR2D aGlyphBoundingX ) ...@@ -134,9 +134,9 @@ BOX2D STROKE_FONT::computeBoundingBox( Glyph aGlyph, VECTOR2D aGlyphBoundingX )
boundingPoints.push_back( VECTOR2D( aGlyphBoundingX.x, 0 ) ); boundingPoints.push_back( VECTOR2D( aGlyphBoundingX.x, 0 ) );
boundingPoints.push_back( VECTOR2D( aGlyphBoundingX.y, 0 ) ); boundingPoints.push_back( VECTOR2D( aGlyphBoundingX.y, 0 ) );
for( Glyph::iterator pointListIt = aGlyph.begin(); pointListIt != aGlyph.end(); ++pointListIt ) for( Glyph::const_iterator pointListIt = aGlyph.begin(); pointListIt != aGlyph.end(); ++pointListIt )
{ {
for( std::deque<VECTOR2D>::iterator pointIt = pointListIt->begin(); for( std::deque<VECTOR2D>::const_iterator pointIt = pointListIt->begin();
pointIt != pointListIt->end(); ++pointIt ) pointIt != pointListIt->end(); ++pointIt )
{ {
boundingPoints.push_back( VECTOR2D( aGlyphBoundingX.x, pointIt->y ) ); boundingPoints.push_back( VECTOR2D( aGlyphBoundingX.x, pointIt->y ) );
...@@ -149,11 +149,26 @@ BOX2D STROKE_FONT::computeBoundingBox( Glyph aGlyph, VECTOR2D aGlyphBoundingX ) ...@@ -149,11 +149,26 @@ BOX2D STROKE_FONT::computeBoundingBox( Glyph aGlyph, VECTOR2D aGlyphBoundingX )
} }
void STROKE_FONT::Draw( std::string aText, VECTOR2D aPosition, double aRotationAngle ) void STROKE_FONT::Draw( std::string aText, const VECTOR2D& aPosition, double aRotationAngle )
{ {
// Split multiline strings into separate ones and draw line by line
size_t newlinePos = aText.find( '\n' );
if( newlinePos != std::string::npos )
{
VECTOR2D nextlinePosition( aPosition );
nextlinePosition += VECTOR2D( 0.0, m_glyphSize.y * 1.6 ); // FIXME remove magic number
Draw( aText.substr( newlinePos + 1 ), nextlinePosition, aRotationAngle );
aText = aText.substr( 0, newlinePos );
}
// Compute the text size // Compute the text size
VECTOR2D textsize = computeTextSize( aText ); VECTOR2D textsize = computeTextSize( aText );
// By default overbar is turned off
m_overbar = false;
// Context needs to be saved before any transformations // Context needs to be saved before any transformations
m_gal->Save(); m_gal->Save();
...@@ -221,8 +236,14 @@ void STROKE_FONT::Draw( std::string aText, VECTOR2D aPosition, double aRotationA ...@@ -221,8 +236,14 @@ void STROKE_FONT::Draw( std::string aText, VECTOR2D aPosition, double aRotationA
m_gal->SetLineWidth( m_gal->GetLineWidth() * 1.3 ); m_gal->SetLineWidth( m_gal->GetLineWidth() * 1.3 );
} }
for( std::string::iterator chIt = aText.begin(); chIt != aText.end(); chIt++ ) for( std::string::const_iterator chIt = aText.begin(); chIt != aText.end(); chIt++ )
{
if( *chIt == '~' )
{ {
m_overbar = !m_overbar;
continue;
}
GlyphList::iterator glyphIt = m_glyphs.begin(); GlyphList::iterator glyphIt = m_glyphs.begin();
std::deque<BOX2D>::iterator bbIt = m_glyphBoundingBoxes.begin(); std::deque<BOX2D>::iterator bbIt = m_glyphBoundingBoxes.begin();
...@@ -254,26 +275,34 @@ void STROKE_FONT::Draw( std::string aText, VECTOR2D aPosition, double aRotationA ...@@ -254,26 +275,34 @@ void STROKE_FONT::Draw( std::string aText, VECTOR2D aPosition, double aRotationA
m_gal->DrawPolyline( pointListScaled ); m_gal->DrawPolyline( pointListScaled );
} }
xOffset += m_scaleFactor * glyphSizeX * if( m_overbar )
( bbIt->GetEnd().x - bbIt->GetOrigin().x ); {
VECTOR2D startOverbar( xOffset, -textsize.y * 1.2 );
VECTOR2D endOverbar( xOffset + m_scaleFactor * glyphSizeX * bbIt->GetEnd().x,
-textsize.y * 1.2 );
m_gal->DrawLine( startOverbar, endOverbar );
}
xOffset += m_scaleFactor * glyphSizeX * bbIt->GetEnd().x;
} }
m_gal->Restore(); m_gal->Restore();
} }
VECTOR2D STROKE_FONT::computeTextSize( std::string aText ) VECTOR2D STROKE_FONT::computeTextSize( const std::string& aText ) const
{ {
VECTOR2D result = VECTOR2D( 0.0, 0.0 ); VECTOR2D result = VECTOR2D( 0.0, m_glyphSize.y );
for( std::string::iterator chIt = aText.begin(); chIt != aText.end(); chIt++ ) for( std::string::const_iterator chIt = aText.begin(); chIt != aText.end(); chIt++ )
{ {
std::deque<BOX2D>::iterator bbIt = m_glyphBoundingBoxes.begin(); if( *chIt == '~' )
continue;
std::deque<BOX2D>::const_iterator bbIt = m_glyphBoundingBoxes.begin();
advance( bbIt, (int) ( *chIt ) - (int) ' ' ); advance( bbIt, (int) ( *chIt ) - (int) ' ' );
result.x += m_scaleFactor * m_glyphSize.x * ( bbIt->GetEnd().x - bbIt->GetOrigin().x ); result.x += m_scaleFactor * m_glyphSize.x * bbIt->GetEnd().x;
} }
result.y = m_glyphSize.y;
return result; return result;
} }
...@@ -80,7 +80,7 @@ public: ...@@ -80,7 +80,7 @@ public:
* @param aPosition is the text position in world coordinates. * @param aPosition is the text position in world coordinates.
* @param aRotationAngle is the text rotation angle. * @param aRotationAngle is the text rotation angle.
*/ */
void Draw( std::string aText, VECTOR2D aPosition, double aRotationAngle ); void Draw( std::string aText, const VECTOR2D& aPosition, double aRotationAngle );
/** /**
* @brief Set the scale factor of the font for the glyph size. * @brief Set the scale factor of the font for the glyph size.
...@@ -154,14 +154,13 @@ public: ...@@ -154,14 +154,13 @@ public:
private: private:
GAL* m_gal; ///< Pointer to the GAL GAL* m_gal; ///< Pointer to the GAL
GlyphList m_glyphs; ///< Glyph list GlyphList m_glyphs; ///< Glyph list
std::deque<BOX2D> m_glyphBoundingBoxes; ///< Bounding boxes of the glyphs std::deque<BOX2D> m_glyphBoundingBoxes; ///< Bounding boxes of the glyphs
double m_scaleFactor; ///< Scale factor for the glyph double m_scaleFactor; ///< Scale factor for the glyph
VECTOR2D m_glyphSize; ///< Size of the glyphs VECTOR2D m_glyphSize; ///< Size of the glyphs
EDA_TEXT_HJUSTIFY_T m_horizontalJustify; ///< Horizontal justification EDA_TEXT_HJUSTIFY_T m_horizontalJustify; ///< Horizontal justification
EDA_TEXT_VJUSTIFY_T m_verticalJustify; ///< Vertical justification EDA_TEXT_VJUSTIFY_T m_verticalJustify; ///< Vertical justification
bool m_bold, m_italic, m_mirrored; ///< Properties of text bool m_bold, m_italic, m_mirrored, m_overbar; ///< Properties of text
/** /**
* @brief Compute the bounding box of a given glyph. * @brief Compute the bounding box of a given glyph.
...@@ -170,7 +169,7 @@ private: ...@@ -170,7 +169,7 @@ private:
* @param aGlyphBoundingX is the x-component of the bounding box size. * @param aGlyphBoundingX is the x-component of the bounding box size.
* @return is the complete bounding box size. * @return is the complete bounding box size.
*/ */
BOX2D computeBoundingBox( Glyph aGlyph, VECTOR2D aGlyphBoundingX ); BOX2D computeBoundingBox( const Glyph& aGlyph, const VECTOR2D& aGlyphBoundingX ) const;
/** /**
* @brief Compute the size of a given text. * @brief Compute the size of a given text.
...@@ -178,7 +177,7 @@ private: ...@@ -178,7 +177,7 @@ private:
* @param aText is the text string. * @param aText is the text string.
* @return is the text size. * @return is the text size.
*/ */
VECTOR2D computeTextSize( const std::string aText ); VECTOR2D computeTextSize( const std::string& aText ) const;
}; };
} // namespace KiGfx } // namespace KiGfx
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment