pcad2kicadpcb_plugin: correct text position with arbitrary angle

This commit is contained in:
Eldar Khayrullin 2017-12-11 21:34:50 +03:00 committed by Maciej Suminski
parent 6f0e0826fa
commit 9620a43022
1 changed files with 21 additions and 82 deletions

View File

@ -513,94 +513,33 @@ int CalculateTextLengthSize( TTEXTVALUE* aText )
void CorrectTextPosition( TTEXTVALUE* aValue ) void CorrectTextPosition( TTEXTVALUE* aValue )
{ {
int cm = aValue->mirror ? -1 : 1; int cm = aValue->mirror ? -1 : 1;
// sizes of justify correction
int cl = KiROUND( (double) CalculateTextLengthSize( aValue ) / 2.0 ); int cl = KiROUND( (double) CalculateTextLengthSize( aValue ) / 2.0 );
int ch = KiROUND( (double) aValue->textHeight / 2.0 ); int ch = KiROUND( (double) aValue->textHeight / 2.0 );
int posX = 0;
aValue->correctedPositionX = aValue->textPositionX; int posY = 0;
aValue->correctedPositionY = aValue->textPositionY;
switch( aValue->textRotation )
{
case 0:
if( aValue->justify == LowerLeft ||
aValue->justify == Left ||
aValue->justify == UpperLeft )
aValue->correctedPositionX += cl * cm;
else if( aValue->justify == LowerRight ||
aValue->justify == Right ||
aValue->justify == UpperRight )
aValue->correctedPositionX -= cl * cm;
if( aValue->justify == LowerLeft ||
aValue->justify == LowerCenter ||
aValue->justify == LowerRight )
aValue->correctedPositionY -= ch;
else if( aValue->justify == UpperLeft ||
aValue->justify == UpperCenter ||
aValue->justify == UpperRight )
aValue->correctedPositionY += ch;
break;
case 900:
if( aValue->justify == LowerLeft ||
aValue->justify == LowerCenter ||
aValue->justify == LowerRight )
aValue->correctedPositionX -= ch * cm;
else if( aValue->justify == UpperLeft ||
aValue->justify == UpperCenter ||
aValue->justify == UpperRight )
aValue->correctedPositionX += ch * cm;
if( aValue->justify == LowerLeft || if( aValue->justify == LowerLeft ||
aValue->justify == Left || aValue->justify == Left ||
aValue->justify == UpperLeft ) aValue->justify == UpperLeft )
aValue->correctedPositionY -= cl; posX += cl * cm;
else if( aValue->justify == LowerRight || else if( aValue->justify == LowerRight ||
aValue->justify == Right || aValue->justify == Right ||
aValue->justify == UpperRight ) aValue->justify == UpperRight )
aValue->correctedPositionY += cl; posX -= cl * cm;
break;
case 1800:
if( aValue->justify == LowerLeft ||
aValue->justify == Left ||
aValue->justify == UpperLeft )
aValue->correctedPositionX -= cl * cm;
else if( aValue->justify == LowerRight ||
aValue->justify == Right ||
aValue->justify == UpperRight )
aValue->correctedPositionX += cl * cm;
if( aValue->justify == LowerLeft || if( aValue->justify == LowerLeft ||
aValue->justify == LowerCenter || aValue->justify == LowerCenter ||
aValue->justify == LowerRight ) aValue->justify == LowerRight )
aValue->correctedPositionY += ch; posY -= ch;
else if( aValue->justify == UpperLeft || else if( aValue->justify == UpperLeft ||
aValue->justify == UpperCenter || aValue->justify == UpperCenter ||
aValue->justify == UpperRight ) aValue->justify == UpperRight )
aValue->correctedPositionY -= ch; posY += ch;
break;
case 2700:
if( aValue->justify == LowerLeft ||
aValue->justify == LowerCenter ||
aValue->justify == LowerRight )
aValue->correctedPositionX += ch * cm;
else if( aValue->justify == UpperLeft ||
aValue->justify == UpperCenter ||
aValue->justify == UpperRight )
aValue->correctedPositionX -= ch * cm;
if( aValue->justify == LowerLeft || RotatePoint( &posX, &posY, aValue->textRotation );
aValue->justify == Left ||
aValue->justify == UpperLeft ) aValue->correctedPositionX = aValue->textPositionX + posX;
aValue->correctedPositionY += cl; aValue->correctedPositionY = aValue->textPositionY + posY;
else if( aValue->justify == LowerRight ||
aValue->justify == Right ||
aValue->justify == UpperRight )
aValue->correctedPositionY -= cl;
break;
default:
break;
}
} }