From 89ea49ff14f6f57ed1586e4e052f218efb53c74e Mon Sep 17 00:00:00 2001 From: Eldar Khayrullin Date: Sat, 27 Feb 2016 12:33:38 -0500 Subject: [PATCH] Pcbnew: PCAD2KICAD text conversion improvements. * Fix text justification. * Fix caret return symbol. * Fix size of proportional font. --- .../pcad2kicad_common.cpp | 57 ++++++++++++++++++- .../pcad2kicadpcb_plugin/pcad2kicad_common.h | 5 ++ pcbnew/pcad2kicadpcb_plugin/pcb_module.cpp | 6 +- pcbnew/pcad2kicadpcb_plugin/pcb_text.cpp | 11 ++-- 4 files changed, 66 insertions(+), 13 deletions(-) diff --git a/pcbnew/pcad2kicadpcb_plugin/pcad2kicad_common.cpp b/pcbnew/pcad2kicadpcb_plugin/pcad2kicad_common.cpp index 7ff4a60ed3..be0328fbc4 100644 --- a/pcbnew/pcad2kicadpcb_plugin/pcad2kicad_common.cpp +++ b/pcbnew/pcad2kicadpcb_plugin/pcad2kicad_common.cpp @@ -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 ) { diff --git a/pcbnew/pcad2kicadpcb_plugin/pcad2kicad_common.h b/pcbnew/pcad2kicadpcb_plugin/pcad2kicad_common.h index ce61cc2446..5d5a8127fb 100644 --- a/pcbnew/pcad2kicadpcb_plugin/pcad2kicad_common.h +++ b/pcbnew/pcad2kicadpcb_plugin/pcad2kicad_common.h @@ -34,6 +34,8 @@ #include #include +#include + 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 ); diff --git a/pcbnew/pcad2kicadpcb_plugin/pcb_module.cpp b/pcbnew/pcad2kicadpcb_plugin/pcb_module.cpp index 5bcf7d9aa4..39ebf79154 100644 --- a/pcbnew/pcad2kicadpcb_plugin/pcb_module.cpp +++ b/pcbnew/pcad2kicadpcb_plugin/pcb_module.cpp @@ -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 ); diff --git a/pcbnew/pcad2kicadpcb_plugin/pcb_text.cpp b/pcbnew/pcad2kicadpcb_plugin/pcb_text.cpp index db8b57f219..f2f096c428 100644 --- a/pcbnew/pcad2kicadpcb_plugin/pcb_text.cpp +++ b/pcbnew/pcad2kicadpcb_plugin/pcb_text.cpp @@ -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 );