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 )
{
int cm = aValue->mirror ? -1 : 1;
// sizes of justify correction
int cl = KiROUND( (double) CalculateTextLengthSize( aValue ) / 2.0 );
int ch = KiROUND( (double) aValue->textHeight / 2.0 );
aValue->correctedPositionX = aValue->textPositionX;
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;
int posX = 0;
int posY = 0;
if( aValue->justify == LowerLeft ||
aValue->justify == Left ||
aValue->justify == UpperLeft )
aValue->correctedPositionY -= cl;
posX += cl * cm;
else if( aValue->justify == LowerRight ||
aValue->justify == Right ||
aValue->justify == UpperRight )
aValue->correctedPositionY += cl;
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;
posX -= cl * cm;
if( aValue->justify == LowerLeft ||
aValue->justify == LowerCenter ||
aValue->justify == LowerRight )
aValue->correctedPositionY += ch;
posY -= ch;
else if( aValue->justify == UpperLeft ||
aValue->justify == UpperCenter ||
aValue->justify == UpperRight )
aValue->correctedPositionY -= 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;
posY += ch;
if( aValue->justify == LowerLeft ||
aValue->justify == Left ||
aValue->justify == UpperLeft )
aValue->correctedPositionY += cl;
else if( aValue->justify == LowerRight ||
aValue->justify == Right ||
aValue->justify == UpperRight )
aValue->correctedPositionY -= cl;
break;
default:
break;
}
RotatePoint( &posX, &posY, aValue->textRotation );
aValue->correctedPositionX = aValue->textPositionX + posX;
aValue->correctedPositionY = aValue->textPositionY + posY;
}