diff --git a/common/eda_text.cpp b/common/eda_text.cpp index a08ba35527..1817de2029 100644 --- a/common/eda_text.cpp +++ b/common/eda_text.cpp @@ -32,6 +32,13 @@ #include // RotatePoint #include // EDA_DRAW_PANEL +// until bzr rev 4410, Y position of vertical justification +// of multiline texts was incorrectly calculated for BOTTOM +// and CENTER vertical justification. (Only the first line was justified) +// If this line is left uncommented, the bug is fixed, but +// creates a (very minor) issue for existing texts, mainly in Pcbnew +// because the text position is sometimes critical. +#define FIX_MULTILINE_VERT_JUSTIF // Conversion to application internal units defined at build time. #if defined( PCBNEW ) @@ -90,6 +97,16 @@ int EDA_TEXT::LenSize( const wxString& aLine ) const return ReturnGraphicTextWidth( aLine, m_Size.x, m_Italic, m_Bold ); } +/** + * Function GetInterline + * return the distance between 2 text lines + * has meaning only for multiline texts + */ +int EDA_TEXT::GetInterline( int aTextThickness ) const +{ + int thickness = aTextThickness <= 0 ? m_Thickness : aTextThickness; + return (( m_Size.y * 14 ) / 10) + thickness; +} EDA_RECT EDA_TEXT::GetTextBox( int aLine, int aThickness, bool aInvertY ) const { @@ -98,6 +115,7 @@ EDA_RECT EDA_TEXT::GetTextBox( int aLine, int aThickness, bool aInvertY ) const wxArrayString* list = NULL; wxString text = m_Text; int thickness = ( aThickness < 0 ) ? m_Thickness : aThickness; + int linecount = 1; if( m_MultilineAllowed ) { @@ -109,12 +127,14 @@ EDA_RECT EDA_TEXT::GetTextBox( int aLine, int aThickness, bool aInvertY ) const text = list->Item( aLine ); else text = list->Item( 0 ); + + linecount = list->GetCount(); } } // calculate the H and V size int dx = LenSize( text ); - int dy = GetInterline(); + int dy = GetInterline( aThickness ); /* Creates bounding box (rectangle) for an horizontal text */ wxSize textsize = wxSize( dx, dy ); @@ -175,7 +195,7 @@ EDA_RECT EDA_TEXT::GetTextBox( int aLine, int aThickness, bool aInvertY ) const break; case GR_TEXT_VJUSTIFY_CENTER: - rect.SetY( rect.GetY() - (dy / 2) ); + rect.SetY( rect.GetY() - ( dy / 2) ); break; case GR_TEXT_VJUSTIFY_BOTTOM: @@ -183,6 +203,30 @@ EDA_RECT EDA_TEXT::GetTextBox( int aLine, int aThickness, bool aInvertY ) const break; } + if( linecount > 1 ) + { +#ifdef FIX_MULTILINE_VERT_JUSTIF + int yoffset; + linecount -= 1; + + switch( m_VJustify ) + { + case GR_TEXT_VJUSTIFY_TOP: + break; + + case GR_TEXT_VJUSTIFY_CENTER: + yoffset = linecount * GetInterline() / 2; + rect.SetY( rect.GetY() - yoffset ); + break; + + case GR_TEXT_VJUSTIFY_BOTTOM: + yoffset = linecount * GetInterline( aThickness ); + rect.SetY( rect.GetY() - yoffset ); + break; + } +#endif + } + rect.Inflate( thickness / 2 ); rect.Normalize(); // Make h and v sizes always >= 0 @@ -227,15 +271,31 @@ void EDA_TEXT::Draw( EDA_RECT* aClipBox, wxDC* aDC, const wxPoint& aOffset, offset.y = GetInterline(); +#ifdef FIX_MULTILINE_VERT_JUSTIF + if( list->Count() > 1 ) + { + 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; + } + } +#endif RotatePoint( &offset, m_Orient ); for( unsigned i = 0; iCount(); i++ ) { wxString txt = list->Item( i ); drawOneLineOfText( aClipBox, aDC, aOffset, aColor, - aDrawMode, aFillMode, - i ? UNSPECIFIED_COLOR : aAnchor_color, - txt, pos ); + aDrawMode, aFillMode, txt, pos ); pos += offset; } @@ -243,15 +303,21 @@ void EDA_TEXT::Draw( EDA_RECT* aClipBox, wxDC* aDC, const wxPoint& aOffset, } else drawOneLineOfText( aClipBox, aDC, aOffset, aColor, - aDrawMode, aFillMode, - aAnchor_color, m_Text, m_Pos ); + aDrawMode, aFillMode, m_Text, m_Pos ); + + // Draw text anchor, if requested + if( aAnchor_color != UNSPECIFIED_COLOR ) + { + GRDrawAnchor( aClipBox, aDC, + m_Pos.x + aOffset.x, m_Pos.y + aOffset.y, + DIM_ANCRE_TEXTE, aAnchor_color ); + } } void EDA_TEXT::drawOneLineOfText( EDA_RECT* aClipBox, wxDC* aDC, const wxPoint& aOffset, EDA_COLOR_T aColor, GR_DRAWMODE aDrawMode, EDA_DRAW_MODE_T aFillMode, - EDA_COLOR_T aAnchor_color, wxString& aText, wxPoint aPos ) { int width = m_Thickness; @@ -262,14 +328,6 @@ void EDA_TEXT::drawOneLineOfText( EDA_RECT* aClipBox, wxDC* aDC, if( aDrawMode != UNSPECIFIED_DRAWMODE ) GRSetDrawMode( aDC, aDrawMode ); - // Draw text anchor, if requested - if( aAnchor_color != UNSPECIFIED_COLOR ) - { - GRDrawAnchor( aClipBox, aDC, - aPos.x + aOffset.x, aPos.y + aOffset.y, - DIM_ANCRE_TEXTE, aAnchor_color ); - } - if( aFillMode == SKETCH ) width = -width; diff --git a/include/eda_text.h b/include/eda_text.h index 301dda0637..7fca31fdaa 100644 --- a/include/eda_text.h +++ b/include/eda_text.h @@ -236,6 +236,8 @@ public: * for single line text, aLine is unused * If aLine == -1, the full area (considering all lines) is returned * @param aThickness Overrides the current thickness when greater than 0. + * this is needed when the current m_Thickness is 0 and a default line thickness + * is used * @param aInvertY Invert the Y axis when calculating bounding box. */ EDA_RECT GetTextBox( int aLine = -1, int aThickness = -1, bool aInvertY = false ) const; @@ -244,11 +246,11 @@ public: * Function GetInterline * return the distance between 2 text lines * has meaning only for multiline texts + * @param aTextThickness Overrides the current thickness when greater than 0. + * this is needed when the current m_Thickness is 0 and a default line thickness + * is used */ - int GetInterline() const - { - return (( m_Size.y * 14 ) / 10) + m_Thickness; - } + int GetInterline( int aTextThickness = -1 ) const; /** * Function GetTextStyleName @@ -286,15 +288,13 @@ private: * @param aColor = text color * @param aDrawMode = GR_OR, GR_XOR.., -1 to use the current mode. * @param aFillMode = LINE, FILLED or SKETCH - * @param aAnchor_color = anchor color ( UNSPECIFIED_COLOR = do not draw anchor ). * @param aText = the single line of text to draw. * @param aPos = the position of this line ). */ void drawOneLineOfText( EDA_RECT* aClipBox, wxDC* aDC, const wxPoint& aOffset, EDA_COLOR_T aColor, GR_DRAWMODE aDrawMode, EDA_DRAW_MODE_T aFillMode, - EDA_COLOR_T aAnchor_color, wxString& aText, - wxPoint aPos ); + wxString& aText, wxPoint aPos ); }; diff --git a/pcbnew/import_dxf/dxf2brd_items.cpp b/pcbnew/import_dxf/dxf2brd_items.cpp index 229d2c1d03..5d48bb8e2d 100644 --- a/pcbnew/import_dxf/dxf2brd_items.cpp +++ b/pcbnew/import_dxf/dxf2brd_items.cpp @@ -112,6 +112,7 @@ bool DXF2BRD_CONVERTER::ImportDxfFile( const wxString& aFile, BOARD* aBoard ) */ void DXF2BRD_CONVERTER::addLayer( const DRW_Layer& data ) { + // Not yet useful in Pcbnew. #if 0 wxString name = wxString::FromUTF8( data.name.c_str() ); wxLogMessage( name ); @@ -215,8 +216,8 @@ void DXF2BRD_CONVERTER::addText(const DRW_Text& data) switch( data.alignV ) { - case DRW_Text::VBaseLine: // Top - pcb_text->SetVertJustify( GR_TEXT_VJUSTIFY_TOP ); + case DRW_Text::VBaseLine: + pcb_text->SetVertJustify( GR_TEXT_VJUSTIFY_BOTTOM ); break; case DRW_Text::VBottom: @@ -248,7 +249,7 @@ void DXF2BRD_CONVERTER::addText(const DRW_Text& data) case DRW_Text::HAligned: // no equivalent options in text pcb. - pcb_text->SetHorizJustify( GR_TEXT_HJUSTIFY_RIGHT ); + pcb_text->SetHorizJustify( GR_TEXT_HJUSTIFY_LEFT ); break; case DRW_Text::HMiddle: @@ -258,7 +259,7 @@ void DXF2BRD_CONVERTER::addText(const DRW_Text& data) case DRW_Text::HFit: // no equivalent options in text pcb. - pcb_text->SetHorizJustify( GR_TEXT_HJUSTIFY_RIGHT ); + pcb_text->SetHorizJustify( GR_TEXT_HJUSTIFY_LEFT ); break; }