diff --git a/common/font/outline_font.cpp b/common/font/outline_font.cpp index 9379b6367c..bf36929f1b 100644 --- a/common/font/outline_font.cpp +++ b/common/font/outline_font.cpp @@ -238,6 +238,58 @@ VECTOR2I OUTLINE_FONT::GetTextAsGlyphs( BOX2I* aBBox, std::vectorSetOrigin( aPosition ); + aBBox->SetEnd( aPosition ); + } + + for( wxUniChar c : aText ) + { + // Handle tabs as locked to the nearest 4th column (in space-widths). + if( c == '\t' ) + { + if( !textRun.IsEmpty() ) + { + position = getTextAsGlyphs( aBBox, aGlyphs, textRun, aSize, position, aAngle, + aMirror, aOrigin, aTextStyle ); + textRun.clear(); + } + + int tabWidth = KiROUND( aSize.x * TAB_WIDTH ); + int currentIntrusion = ( position.x - aOrigin.x ) % tabWidth; + + position.x += tabWidth - currentIntrusion; + } + else + { + textRun += c; + } + } + + if( !textRun.IsEmpty() ) + { + position = getTextAsGlyphs( aBBox, aGlyphs, textRun, aSize, position, aAngle, aMirror, + aOrigin, aTextStyle ); + } + + return position; +} + + +VECTOR2I OUTLINE_FONT::getTextAsGlyphs( BOX2I* aBBox, std::vector>* aGlyphs, + const wxString& aText, const VECTOR2I& aSize, + const VECTOR2I& aPosition, const EDA_ANGLE& aAngle, + bool aMirror, const VECTOR2I& aOrigin, + TEXT_STYLE_FLAGS aTextStyle ) const { VECTOR2D glyphSize = aSize; FT_Face face = m_face; @@ -407,10 +459,7 @@ VECTOR2I OUTLINE_FONT::GetTextAsGlyphs( BOX2I* aBBox, std::vectorSetOrigin( aPosition.x, aPosition.y ); - aBBox->SetEnd( aPosition + extents ); - } + aBBox->Merge( aPosition + extents ); return VECTOR2I( aPosition.x + cursorDisplacement.x, aPosition.y + cursorDisplacement.y ); } diff --git a/include/font/outline_font.h b/include/font/outline_font.h index 5a4414e5e9..aa2e8c66ee 100644 --- a/include/font/outline_font.h +++ b/include/font/outline_font.h @@ -110,6 +110,11 @@ protected: BOX2I getBoundingBox( const std::vector>& aGlyphs ) const; + VECTOR2I getTextAsGlyphs( BOX2I* aBoundingBox, std::vector>* aGlyphs, + const wxString& aText, const VECTOR2I& aSize, + const VECTOR2I& aPosition, const EDA_ANGLE& aAngle, bool aMirror, + const VECTOR2I& aOrigin, TEXT_STYLE_FLAGS aTextStyle ) const; + private: // FreeType variables static FT_Library m_freeType;