From 9620a430220c2b698d391da4f419a4e40aeaac7e Mon Sep 17 00:00:00 2001 From: Eldar Khayrullin Date: Mon, 11 Dec 2017 21:34:50 +0300 Subject: [PATCH] pcad2kicadpcb_plugin: correct text position with arbitrary angle --- .../pcad2kicad_common.cpp | 103 ++++-------------- 1 file changed, 21 insertions(+), 82 deletions(-) diff --git a/pcbnew/pcad2kicadpcb_plugin/pcad2kicad_common.cpp b/pcbnew/pcad2kicadpcb_plugin/pcad2kicad_common.cpp index 39569a51ce..8e954ce095 100644 --- a/pcbnew/pcad2kicadpcb_plugin/pcad2kicad_common.cpp +++ b/pcbnew/pcad2kicadpcb_plugin/pcad2kicad_common.cpp @@ -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 ); + int posX = 0; + int posY = 0; - aValue->correctedPositionX = aValue->textPositionX; - aValue->correctedPositionY = aValue->textPositionY; + if( aValue->justify == LowerLeft || + aValue->justify == Left || + aValue->justify == UpperLeft ) + posX += cl * cm; + else if( aValue->justify == LowerRight || + aValue->justify == Right || + aValue->justify == UpperRight ) + posX -= cl * cm; - 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 ) + posY -= ch; + else if( aValue->justify == UpperLeft || + aValue->justify == UpperCenter || + aValue->justify == UpperRight ) + posY += ch; - 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; + RotatePoint( &posX, &posY, aValue->textRotation ); - 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; - 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 || - 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 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 || - 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; - } + aValue->correctedPositionX = aValue->textPositionX + posX; + aValue->correctedPositionY = aValue->textPositionY + posY; }