From 447bb98480fbb770211c0cf2a2efac68185e5705 Mon Sep 17 00:00:00 2001 From: Baranovskiy Konstantin Date: Mon, 23 Dec 2013 11:25:13 -0500 Subject: [PATCH] Fix worksheet multiple line text plotting bug. (fixes lp:1261906) --- common/common_plot_functions.cpp | 3 +- common/drawtxt.cpp | 55 +++++++++++++++++++++++++++----- include/plot_common.h | 3 +- 3 files changed, 51 insertions(+), 10 deletions(-) diff --git a/common/common_plot_functions.cpp b/common/common_plot_functions.cpp index 1a7312756b..3d10d81223 100644 --- a/common/common_plot_functions.cpp +++ b/common/common_plot_functions.cpp @@ -133,7 +133,8 @@ void PlotWorkSheet( PLOTTER* plotter, const TITLE_BLOCK& aTitleBlock, text->GetSize(), text->GetHorizJustify(), text->GetVertJustify(), text->GetPenWidth(), - text->IsItalic(), text->IsBold() ); + text->IsItalic(), text->IsBold(), + text->IsMultilineAllowed() ); } break; diff --git a/common/drawtxt.cpp b/common/drawtxt.cpp index 5fe1d5f768..29286be5b4 100644 --- a/common/drawtxt.cpp +++ b/common/drawtxt.cpp @@ -602,6 +602,7 @@ void DrawGraphicHaloText( EDA_RECT* aClipBox, wxDC * aDC, * Use a value min(aSize.x, aSize.y) / 5 for a bold text * @param aItalic = true to simulate an italic font * @param aBold = true to use a bold font Useful only with default width value (aWidth = 0) + * @param aMultilineAllowed = true to plot text as multiline, otherwise single line */ void PLOTTER::Text( const wxPoint& aPos, enum EDA_COLOR_T aColor, @@ -612,7 +613,8 @@ void PLOTTER::Text( const wxPoint& aPos, enum EDA_TEXT_VJUSTIFY_T aV_justify, int aWidth, bool aItalic, - bool aBold ) + bool aBold, + bool aMultilineAllowed ) { int textPensize = aWidth; @@ -630,13 +632,50 @@ void PLOTTER::Text( const wxPoint& aPos, if( aColor >= 0 ) SetColor( aColor ); - DrawGraphicText( NULL, NULL, aPos, aColor, aText, - aOrient, aSize, - aH_justify, aV_justify, - textPensize, aItalic, - aBold, - NULL, - this ); + if( aMultilineAllowed ) + { + // EDA_TEXT needs for calculations of the position of every + // line according to orientation and justifications + EDA_TEXT* multilineText = new EDA_TEXT( aText ); + multilineText->SetSize( aSize ); + multilineText->SetTextPosition( aPos ); + multilineText->SetOrientation( aOrient ); + multilineText->SetHorizJustify( aH_justify ); + multilineText->SetVertJustify( aV_justify ); + multilineText->SetThickness( aWidth ); + multilineText->SetMultilineAllowed( aMultilineAllowed ); + + std::vector positions; + wxArrayString* list = wxStringSplit( aText, '\n' ); + positions.reserve( list->Count() ); + + multilineText->GetPositionsOfLinesOfMultilineText( + positions, list->Count() ); + + for( unsigned ii = 0; ii < list->Count(); ii++ ) + { + wxString& txt = list->Item( ii ); + DrawGraphicText( NULL, NULL, positions[ii], aColor, txt, + aOrient, aSize, + aH_justify, aV_justify, + textPensize, aItalic, + aBold, + NULL, + this ); + } + delete multilineText; + delete list; + } + else + { + DrawGraphicText( NULL, NULL, aPos, aColor, aText, + aOrient, aSize, + aH_justify, aV_justify, + textPensize, aItalic, + aBold, + NULL, + this ); + } if( aWidth != textPensize ) SetCurrentLineWidth( aWidth ); diff --git a/include/plot_common.h b/include/plot_common.h index 1dff640eb4..f59a2fbd82 100644 --- a/include/plot_common.h +++ b/include/plot_common.h @@ -253,7 +253,8 @@ public: enum EDA_TEXT_VJUSTIFY_T aV_justify, int aWidth, bool aItalic, - bool aBold ); + bool aBold, + bool aMultilineAllowed = false ); /** * Draw a marker (used for the drill map)