diff --git a/common/gal/stroke_font.cpp b/common/gal/stroke_font.cpp index 47166c81f3..a809c6fed1 100644 --- a/common/gal/stroke_font.cpp +++ b/common/gal/stroke_font.cpp @@ -3,6 +3,8 @@ * * Copyright (C) 2012 Torsten Hueter, torstenhtr gmx.de * Copyright (C) 2012 Kicad Developers, see change_log.txt for contributors. + * Copyright (C) 2013 CERN + * @author Maciej Suminski * * Stroke font class * @@ -47,11 +49,6 @@ STROKE_FONT::STROKE_FONT( GAL* aGal ) : } -STROKE_FONT::~STROKE_FONT() -{ -} - - bool STROKE_FONT::LoadNewStrokeFont( const char* const aNewStrokeFont[], int aNewStrokeFontSize ) { m_glyphs.clear(); @@ -190,7 +187,7 @@ void STROKE_FONT::Draw( wxString aText, const VECTOR2D& aPosition, double aRotat // Split multiline strings into separate ones and draw them line by line int begin = 0; - int newlinePos = aText.find( '\n' ); + int newlinePos = aText.Find( '\n' ); while( newlinePos != wxNOT_FOUND ) { @@ -203,7 +200,8 @@ void STROKE_FONT::Draw( wxString aText, const VECTOR2D& aPosition, double aRotat } // Draw the last (or the only one) line - drawSingleLineText( aText.Mid( begin ) ); + if( !aText.IsEmpty() ) + drawSingleLineText( aText.Mid( begin ) ); m_gal->Restore(); } @@ -243,7 +241,6 @@ void STROKE_FONT::drawSingleLineText( const wxString& aText ) break; } - if( m_mirrored ) { // In case of mirrored text invert the X scale of points and their X direction @@ -256,13 +253,18 @@ void STROKE_FONT::drawSingleLineText( const wxString& aText ) xOffset = 0.0; } - for( wxString::const_iterator chIt = aText.begin(); chIt != aText.end(); chIt++ ) + for( wxString::const_iterator chIt = aText.begin(); chIt != aText.end(); ++chIt ) { // Toggle overbar if( *chIt == '~' ) { - m_overbar = !m_overbar; - continue; + if( ++chIt == aText.end() ) + break; + + if( *chIt != '~' ) // It was a single tilda, it toggles overbar + m_overbar = !m_overbar; + + // If it is a double tilda, just process the second one } unsigned dd = *chIt - ' '; @@ -282,12 +284,12 @@ void STROKE_FONT::drawSingleLineText( const wxString& aText ) } for( GLYPH::iterator pointListIt = glyph.begin(); pointListIt != glyph.end(); - pointListIt++ ) + ++pointListIt ) { std::deque pointListScaled; for( std::deque::iterator pointIt = pointListIt->begin(); - pointIt != pointListIt->end(); pointIt++ ) + pointIt != pointListIt->end(); ++pointIt ) { VECTOR2D pointPos( pointIt->x * glyphSize.x + xOffset, pointIt->y * glyphSize.y ); @@ -315,13 +317,18 @@ VECTOR2D STROKE_FONT::computeTextSize( const wxString& aText ) const { VECTOR2D result = VECTOR2D( 0.0, m_glyphSize.y ); - for( wxString::const_iterator chIt = aText.begin(); chIt != aText.end(); chIt++ ) + for( wxString::const_iterator chIt = aText.begin(); chIt != aText.end(); ++chIt ) { wxASSERT_MSG( *chIt != '\n', wxT( "This function is intended to work with single line strings" ) ); + // 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 if( *chIt == '~' ) - continue; + { + if( ++chIt == aText.end() ) + break; + } // Index in the bounding boxes table unsigned dd = *chIt - ' '; diff --git a/include/gal/stroke_font.h b/include/gal/stroke_font.h index 684eb80a61..a3619783f2 100644 --- a/include/gal/stroke_font.h +++ b/include/gal/stroke_font.h @@ -3,6 +3,8 @@ * * Copyright (C) 2012 Torsten Hueter, torstenhtr gmx.de * Copyright (C) 2012 Kicad Developers, see change_log.txt for contributors. + * Copyright (C) 2013 CERN + * @author Maciej Suminski * * Stroke font class * @@ -52,9 +54,6 @@ public: /// Constructor STROKE_FONT( GAL* aGal ); - /// Destructor - ~STROKE_FONT(); - /** * @brief Load the new stroke font. *