Fix LIB_TEXT plotting alignment

LIB_TEXT is not all aligned to the center, so place the proper flags
when calling Plot.  This requires handling alignment offsets properly
when rotated as well
This commit is contained in:
Seth Hillbrand 2023-01-23 12:23:14 -08:00
parent 509b39e9e4
commit 67c703e9e2
1 changed files with 21 additions and 1 deletions

View File

@ -277,6 +277,26 @@ void LIB_TEXT::Plot( PLOTTER* plotter, bool aBackground, const VECTOR2I& offset,
// convert coordinates from draw Y axis to symbol_editor Y axis // convert coordinates from draw Y axis to symbol_editor Y axis
bBox.RevertYAxis(); bBox.RevertYAxis();
VECTOR2I txtpos = bBox.Centre(); VECTOR2I txtpos = bBox.Centre();
TEXT_ATTRIBUTES attrs = GetAttributes();
if( attrs.m_Angle == ANGLE_VERTICAL )
{
switch( attrs.m_Halign )
{
case GR_TEXT_H_ALIGN_LEFT: txtpos.y = bBox.GetTop(); break;
case GR_TEXT_H_ALIGN_CENTER: txtpos.y = bBox.GetCenter().y; break;
case GR_TEXT_H_ALIGN_RIGHT: txtpos.y = bBox.GetBottom(); break;
}
}
else
{
switch( attrs.m_Halign )
{
case GR_TEXT_H_ALIGN_LEFT: txtpos.x = bBox.GetLeft(); break;
case GR_TEXT_H_ALIGN_CENTER: txtpos.x = bBox.GetCenter().x; break;
case GR_TEXT_H_ALIGN_RIGHT: txtpos.x = bBox.GetRight(); break;
}
}
// The text orientation may need to be flipped if the transformation matrix causes xy // The text orientation may need to be flipped if the transformation matrix causes xy
// axes to be flipped. // axes to be flipped.
@ -307,7 +327,7 @@ void LIB_TEXT::Plot( PLOTTER* plotter, bool aBackground, const VECTOR2I& offset,
font = KIFONT::FONT::GetFont( settings->GetDefaultFont(), IsBold(), IsItalic() ); font = KIFONT::FONT::GetFont( settings->GetDefaultFont(), IsBold(), IsItalic() );
plotter->Text( pos, color, GetText(), t1 ? ANGLE_HORIZONTAL : ANGLE_VERTICAL, GetTextSize(), plotter->Text( pos, color, GetText(), t1 ? ANGLE_HORIZONTAL : ANGLE_VERTICAL, GetTextSize(),
GR_TEXT_H_ALIGN_CENTER, GR_TEXT_V_ALIGN_CENTER, penWidth, IsItalic(), IsBold(), GetHorizJustify(), GetVertJustify(), penWidth, IsItalic(), IsBold(),
true, font ); true, font );
} }