diff --git a/common/eda_text.cpp b/common/eda_text.cpp index b1bda567cd..fdadf86c82 100644 --- a/common/eda_text.cpp +++ b/common/eda_text.cpp @@ -265,47 +265,17 @@ void EDA_TEXT::Draw( EDA_RECT* aClipBox, wxDC* aDC, const wxPoint& aOffset, { if( m_MultilineAllowed ) { + std::vector positions; wxArrayString* list = wxStringSplit( m_Text, '\n' ); + positions.reserve( list->Count() ); - wxPoint pos = m_Pos; // Position of first line of the - // multiline text according to - // the center of the multiline text block + GetPositionsOfLinesOfMultilineText(positions, list->Count() ); - wxPoint offset; // Offset to next line. - - offset.y = GetInterline(); - -#ifdef FIX_MULTILINE_VERT_JUSTIF - if( list->Count() > 1 ) + for( unsigned ii = 0; ii < list->Count(); ii++ ) { - switch( m_VJustify ) - { - case GR_TEXT_VJUSTIFY_TOP: - break; - - case GR_TEXT_VJUSTIFY_CENTER: - pos.y -= ( list->Count() - 1 ) * offset.y / 2; - break; - - case GR_TEXT_VJUSTIFY_BOTTOM: - pos.y -= ( list->Count() - 1 ) * offset.y; - break; - } - } - - // Rotate the position of the first line - // around the center of the multiline text block - RotatePoint( &pos, m_Pos, m_Orient ); -#endif - // Rotate the offset lines to increase happened in the right direction - RotatePoint( &offset, m_Orient ); - - for( unsigned i = 0; iCount(); i++ ) - { - wxString txt = list->Item( i ); + wxString& txt = list->Item( ii ); drawOneLineOfText( aClipBox, aDC, aOffset, aColor, - aDrawMode, aFillMode, txt, pos ); - pos += offset; + aDrawMode, aFillMode, txt, positions[ii] ); } delete (list); @@ -324,6 +294,49 @@ void EDA_TEXT::Draw( EDA_RECT* aClipBox, wxDC* aDC, const wxPoint& aOffset, } +void EDA_TEXT::GetPositionsOfLinesOfMultilineText( + std::vector& aPositions, int aLineCount ) +{ + wxPoint pos = m_Pos; // Position of first line of the + // multiline text according to + // the center of the multiline text block + + wxPoint offset; // Offset to next line. + + offset.y = GetInterline(); + +#ifdef FIX_MULTILINE_VERT_JUSTIF + if( aLineCount > 1 ) + { + switch( m_VJustify ) + { + case GR_TEXT_VJUSTIFY_TOP: + break; + + case GR_TEXT_VJUSTIFY_CENTER: + pos.y -= ( aLineCount - 1 ) * offset.y / 2; + break; + + case GR_TEXT_VJUSTIFY_BOTTOM: + pos.y -= ( aLineCount - 1 ) * offset.y; + break; + } + } + + // Rotate the position of the first line + // around the center of the multiline text block + RotatePoint( &pos, m_Pos, m_Orient ); +#endif + // Rotate the offset lines to increase happened in the right direction + RotatePoint( &offset, m_Orient ); + + for( int ii = 0; ii < aLineCount; ii++ ) + { + aPositions.push_back( pos ); + pos += offset; + } +} + void EDA_TEXT::drawOneLineOfText( EDA_RECT* aClipBox, wxDC* aDC, const wxPoint& aOffset, EDA_COLOR_T aColor, GR_DRAWMODE aDrawMode, EDA_DRAW_MODE_T aFillMode, diff --git a/eeschema/sch_text.cpp b/eeschema/sch_text.cpp index c719cff2b1..e6e3bbf915 100644 --- a/eeschema/sch_text.cpp +++ b/eeschema/sch_text.cpp @@ -673,20 +673,17 @@ void SCH_TEXT::Plot( PLOTTER* aPlotter ) if( m_MultilineAllowed ) { - wxPoint pos = textpos; + std::vector positions; wxArrayString* list = wxStringSplit( m_Text, '\n' ); - wxPoint offset; + positions.reserve( list->Count() ); - offset.y = GetInterline(); + GetPositionsOfLinesOfMultilineText(positions, list->Count() ); - RotatePoint( &offset, m_Orient ); - - for( unsigned i = 0; iCount(); i++ ) + for( unsigned ii = 0; ii < list->Count(); ii++ ) { - wxString txt = list->Item( i ); - aPlotter->Text( pos, color, txt, m_Orient, m_Size, m_HJustify, + wxString& txt = list->Item( ii ); + aPlotter->Text( positions[ii], color, txt, m_Orient, m_Size, m_HJustify, m_VJustify, thickness, m_Italic, m_Bold ); - pos += offset; } delete (list); diff --git a/include/eda_text.h b/include/eda_text.h index b5988c244f..7de9dbd2c7 100644 --- a/include/eda_text.h +++ b/include/eda_text.h @@ -265,6 +265,17 @@ public: void SetHorizJustify( EDA_TEXT_HJUSTIFY_T aType ) { m_HJustify = aType; }; void SetVertJustify( EDA_TEXT_VJUSTIFY_T aType ) { m_VJustify = aType; }; + /** + * Function GetPositionsOfLinesOfMultilineText + * Populates aPositions with the position of each line of + * a multiline text, according to the vertical justification and the + * rotation of the whole text + * @param aPositions is the list to populate by the wxPoint positions + * @param aLineCount is the number of lines (not recalculated here + * for efficiency reasons + */ + void GetPositionsOfLinesOfMultilineText( + std::vector& aPositions, int aLineCount ); /** * Function Format * outputs the object to \a aFormatter in s-expression form. diff --git a/pcbnew/plot_brditems_plotter.cpp b/pcbnew/plot_brditems_plotter.cpp index 1922a20091..e9272f1ca8 100644 --- a/pcbnew/plot_brditems_plotter.cpp +++ b/pcbnew/plot_brditems_plotter.cpp @@ -477,20 +477,18 @@ void BRDITEMS_PLOTTER::PlotTextePcb( TEXTE_PCB* pt_texte ) if( pt_texte->IsMultilineAllowed() ) { + std::vector positions; wxArrayString* list = wxStringSplit( pt_texte->GetText(), '\n' ); - wxPoint offset; + positions.reserve( list->Count() ); - offset.y = pt_texte->GetInterline(); + pt_texte->GetPositionsOfLinesOfMultilineText( positions, list->Count() ); - RotatePoint( &offset, orient ); - - for( unsigned i = 0; i < list->Count(); i++ ) + for( unsigned ii = 0; ii < list->Count(); ii++ ) { - wxString txt = list->Item( i ); - m_plotter->Text( pos, UNSPECIFIED_COLOR, txt, orient, size, + wxString& txt = list->Item( ii ); + m_plotter->Text( positions[ii], UNSPECIFIED_COLOR, txt, orient, size, pt_texte->GetHorizJustify(), pt_texte->GetVertJustify(), thickness, pt_texte->IsItalic(), allow_bold ); - pos += offset; } delete list;