Pcbnew: PCAD2KICAD text conversion improvements.
* Fix text justification. * Fix caret return symbol. * Fix size of proportional font.
This commit is contained in:
parent
04000883f3
commit
89ea49ff14
|
@ -37,8 +37,11 @@
|
|||
|
||||
namespace PCAD2KICAD {
|
||||
|
||||
// PCAD stroke font average ratio of width to height
|
||||
const double TEXT_WIDTH_TO_HEIGHT = 0.79;
|
||||
// PCAD stroke font average ratio of width to size
|
||||
const double TEXT_WIDTH_TO_SIZE_AVERAGE = 0.79;
|
||||
// PCAD proportions of stroke font
|
||||
const double TEXT_HEIGHT_TO_SIZE = 0.656;
|
||||
const double TEXT_WIDTH_TO_SIZE = 0.656;
|
||||
|
||||
wxString GetWord( wxString* aStr )
|
||||
{
|
||||
|
@ -403,10 +406,53 @@ void SetFontProperty( XNODE* aNode,
|
|||
}
|
||||
}
|
||||
|
||||
void SetTextJustify( EDA_TEXT* aText, TTEXT_JUSTIFY aJustify )
|
||||
{
|
||||
switch( aJustify )
|
||||
{
|
||||
case LowerLeft:
|
||||
aText->SetVertJustify( GR_TEXT_VJUSTIFY_BOTTOM );
|
||||
aText->SetHorizJustify( GR_TEXT_HJUSTIFY_LEFT );
|
||||
break;
|
||||
case LowerCenter:
|
||||
aText->SetVertJustify( GR_TEXT_VJUSTIFY_BOTTOM );
|
||||
aText->SetHorizJustify( GR_TEXT_HJUSTIFY_CENTER );
|
||||
break;
|
||||
case LowerRight:
|
||||
aText->SetVertJustify( GR_TEXT_VJUSTIFY_BOTTOM );
|
||||
aText->SetHorizJustify( GR_TEXT_HJUSTIFY_RIGHT );
|
||||
break;
|
||||
case UpperLeft:
|
||||
aText->SetVertJustify( GR_TEXT_VJUSTIFY_TOP );
|
||||
aText->SetHorizJustify( GR_TEXT_HJUSTIFY_LEFT );
|
||||
break;
|
||||
case UpperCenter:
|
||||
aText->SetVertJustify( GR_TEXT_VJUSTIFY_TOP );
|
||||
aText->SetHorizJustify( GR_TEXT_HJUSTIFY_CENTER );
|
||||
break;
|
||||
case UpperRight:
|
||||
aText->SetVertJustify( GR_TEXT_VJUSTIFY_TOP );
|
||||
aText->SetHorizJustify( GR_TEXT_HJUSTIFY_RIGHT );
|
||||
break;
|
||||
case Left:
|
||||
aText->SetVertJustify( GR_TEXT_VJUSTIFY_CENTER );
|
||||
aText->SetHorizJustify( GR_TEXT_HJUSTIFY_LEFT );
|
||||
break;
|
||||
case Center:
|
||||
aText->SetVertJustify( GR_TEXT_VJUSTIFY_CENTER );
|
||||
aText->SetHorizJustify( GR_TEXT_HJUSTIFY_CENTER );
|
||||
break;
|
||||
case Right:
|
||||
aText->SetVertJustify( GR_TEXT_VJUSTIFY_CENTER );
|
||||
aText->SetHorizJustify( GR_TEXT_HJUSTIFY_RIGHT );
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
int CalculateTextLengthSize( TTEXTVALUE* aText )
|
||||
{
|
||||
return KiROUND( (double) aText->text.Len() *
|
||||
(double) aText->textHeight * TEXT_WIDTH_TO_HEIGHT );
|
||||
(double) aText->textHeight * TEXT_WIDTH_TO_SIZE_AVERAGE );
|
||||
}
|
||||
|
||||
void CorrectTextPosition( TTEXTVALUE* aValue )
|
||||
|
@ -502,6 +548,11 @@ void CorrectTextPosition( TTEXTVALUE* aValue )
|
|||
}
|
||||
}
|
||||
|
||||
void SetTextSizeFromStrokeFontHeight( EDA_TEXT* aText, int aTextHeight )
|
||||
{
|
||||
aText->SetSize( wxSize( KiROUND( aTextHeight * TEXT_WIDTH_TO_SIZE ),
|
||||
KiROUND( aTextHeight * TEXT_HEIGHT_TO_SIZE ) ) );
|
||||
}
|
||||
|
||||
XNODE* FindNode( XNODE* aChild, wxString aTag )
|
||||
{
|
||||
|
|
|
@ -34,6 +34,8 @@
|
|||
#include <wx/xml/xml.h>
|
||||
#include <xnode.h>
|
||||
|
||||
#include <eda_text.h>
|
||||
|
||||
namespace PCAD2KICAD
|
||||
{
|
||||
|
||||
|
@ -92,8 +94,11 @@ extern void SetFontProperty( XNODE* aNode,
|
|||
TTEXTVALUE* aTextValue,
|
||||
wxString aDefaultMeasurementUnit,
|
||||
wxString aActualConversion );
|
||||
extern void SetTextJustify( EDA_TEXT* aText, TTEXT_JUSTIFY aJustify );
|
||||
extern int CalculateTextLengthSize( TTEXTVALUE* aText );
|
||||
extern void CorrectTextPosition( TTEXTVALUE* aValue );
|
||||
extern void SetTextSizeFromStrokeFontHeight( EDA_TEXT* aText,
|
||||
int aTextHeight );
|
||||
|
||||
extern XNODE* FindNode( XNODE* aChild, wxString aTag );
|
||||
extern wxString FindNodeGetContent( XNODE* aChild, wxString aTag );
|
||||
|
|
|
@ -533,8 +533,7 @@ void PCB_MODULE::AddToBoard()
|
|||
ref_text->SetType( TEXTE_MODULE::TEXT_is_REFERENCE );
|
||||
|
||||
ref_text->SetPos0( wxPoint( m_name.correctedPositionX, m_name.correctedPositionY ) );
|
||||
ref_text->SetSize( wxSize( KiROUND( m_name.textHeight / 2 ),
|
||||
KiROUND( m_name.textHeight / 1.5 ) ) );
|
||||
SetTextSizeFromStrokeFontHeight( ref_text, m_name.textHeight );
|
||||
|
||||
r = m_name.textRotation - m_rotation;
|
||||
ref_text->SetOrientation( r );
|
||||
|
@ -556,8 +555,7 @@ void PCB_MODULE::AddToBoard()
|
|||
val_text->SetType( TEXTE_MODULE::TEXT_is_VALUE );
|
||||
|
||||
val_text->SetPos0( wxPoint( m_value.correctedPositionX, m_value.correctedPositionY ) );
|
||||
val_text->SetSize( wxSize( KiROUND( m_value.textHeight / 2 ),
|
||||
KiROUND( m_value.textHeight / 1.5 ) ) );
|
||||
SetTextSizeFromStrokeFontHeight( val_text, m_value.textHeight );
|
||||
|
||||
r = m_value.textRotation - m_rotation;
|
||||
val_text->SetOrientation( r );
|
||||
|
|
|
@ -77,6 +77,7 @@ void PCB_TEXT::Parse( XNODE* aNode,
|
|||
}
|
||||
|
||||
aNode->GetAttribute( wxT( "Name" ), &m_name.text );
|
||||
m_name.text.Replace( "\r", "" );
|
||||
|
||||
str = FindNodeGetContent( aNode, wxT( "justify" ) );
|
||||
m_name.justify = GetJustifyIdentificator( str );
|
||||
|
@ -100,25 +101,23 @@ void PCB_TEXT::AddToModule( MODULE* aModule )
|
|||
|
||||
void PCB_TEXT::AddToBoard()
|
||||
{
|
||||
// Simple, not the best, but acceptable text positioning.
|
||||
m_name.textPositionX = m_positionX;
|
||||
m_name.textPositionY = m_positionY;
|
||||
m_name.textRotation = m_rotation;
|
||||
CorrectTextPosition( &m_name );
|
||||
|
||||
TEXTE_PCB* pcbtxt = new TEXTE_PCB( m_board );
|
||||
m_board->Add( pcbtxt, ADD_APPEND );
|
||||
|
||||
pcbtxt->SetText( m_name.text );
|
||||
|
||||
pcbtxt->SetSize( wxSize( KiROUND( m_name.textHeight / 2 ),
|
||||
KiROUND( m_name.textHeight / 1.1 ) ) );
|
||||
SetTextSizeFromStrokeFontHeight( pcbtxt, m_name.textHeight );
|
||||
|
||||
pcbtxt->SetThickness( m_name.textstrokeWidth );
|
||||
pcbtxt->SetOrientation( m_name.textRotation );
|
||||
|
||||
pcbtxt->SetTextPosition( wxPoint( m_name.correctedPositionX,
|
||||
m_name.correctedPositionY ) );
|
||||
SetTextJustify( pcbtxt, m_name.justify );
|
||||
pcbtxt->SetTextPosition( wxPoint( m_name.textPositionX,
|
||||
m_name.textPositionY ) );
|
||||
|
||||
pcbtxt->SetMirrored( m_name.mirror );
|
||||
pcbtxt->SetTimeStamp( 0 );
|
||||
|
|
Loading…
Reference in New Issue