Add patch from Baranovskiy Konstantin about vertical justification of multiline texts.
Fix issues created by this patch. Note, this fix slightly changes the vertical position of these texts. This is not really a problem in eeschema, but in pcbnew this is perhaps more annoying, if the verical multiline text is critical. Fix a very minor issue for vertical justification of single line texts in dxf import.
This commit is contained in:
parent
40eb9c9cc2
commit
7e3551d371
|
@ -32,6 +32,13 @@
|
|||
#include <trigo.h> // RotatePoint
|
||||
#include <class_drawpanel.h> // 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; i<list->Count(); 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;
|
||||
|
||||
|
|
|
@ -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 );
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue