pcad2kicadpcb_plugin: fix size of text

This commit is contained in:
Eldar Khayrullin 2017-12-12 21:21:44 +03:00 committed by Maciej Suminski
parent 613272852d
commit 87566eedc5
4 changed files with 39 additions and 20 deletions

View File

@ -39,13 +39,15 @@
namespace PCAD2KICAD { namespace PCAD2KICAD {
// PCAD stroke font average ratio of width to size // PCAD stroke font average ratio of width to size
const double TEXT_WIDTH_TO_SIZE_AVERAGE = 0.79; const double TEXT_WIDTH_TO_SIZE_AVERAGE = 0.5;
// PCAD proportions of stroke font // PCAD proportions of stroke font
const double TEXT_HEIGHT_TO_SIZE = 0.656; const double STROKE_HEIGHT_TO_SIZE = 0.656;
const double TEXT_WIDTH_TO_SIZE = 0.656; const double STROKE_WIDTH_TO_SIZE = 0.69;
// True type font // TrueType font
const double TRUETYPE_WIDTH_PER_HEIGHT = 0.073; const double TRUETYPE_HEIGHT_TO_SIZE = 0.585;
const double TRUETYPE_BOLD_WIDTH_MUL = 1.6; const double TRUETYPE_WIDTH_TO_SIZE = 0.585;
const double TRUETYPE_THICK_PER_HEIGHT = 0.073;
const double TRUETYPE_BOLD_THICK_MUL = 1.6;
const long TRUETYPE_BOLD_MIN_WEIGHT = 700; const long TRUETYPE_BOLD_MIN_WEIGHT = 700;
wxString GetWord( wxString* aStr ) wxString GetWord( wxString* aStr )
@ -405,21 +407,20 @@ void SetFontProperty( XNODE* aNode,
if( aNode ) if( aNode )
{ {
bool isTrueType;
wxString fontType; wxString fontType;
propValue = FindNodeGetContent( aNode, wxT( "textStyleDisplayTType" ) ); propValue = FindNodeGetContent( aNode, wxT( "textStyleDisplayTType" ) );
isTrueType = ( propValue == wxT( "True" ) ); aTextValue->isTrueType = ( propValue == wxT( "True" ) );
aNode = FindNode( aNode, wxT( "font" ) ); aNode = FindNode( aNode, wxT( "font" ) );
fontType = FindNodeGetContent( aNode, wxT( "fontType" ) ); fontType = FindNodeGetContent( aNode, wxT( "fontType" ) );
if( ( isTrueType && ( fontType != wxT( "TrueType" ) ) ) || if( ( aTextValue->isTrueType && ( fontType != wxT( "TrueType" ) ) ) ||
( !isTrueType && ( fontType != wxT( "Stroke" ) ) ) ) ( !aTextValue->isTrueType && ( fontType != wxT( "Stroke" ) ) ) )
aNode = aNode->GetNext(); aNode = aNode->GetNext();
if( aNode ) if( aNode )
{ {
if( isTrueType ) if( aTextValue->isTrueType )
{ {
propValue = FindNodeGetContent( aNode, wxT( "fontItalic" ) ); propValue = FindNodeGetContent( aNode, wxT( "fontItalic" ) );
aTextValue->isItalic = ( propValue == wxT( "True" ) ); aTextValue->isItalic = ( propValue == wxT( "True" ) );
@ -441,11 +442,11 @@ void SetFontProperty( XNODE* aNode,
SetHeight( lNode->GetNodeContent(), aDefaultMeasurementUnit, SetHeight( lNode->GetNodeContent(), aDefaultMeasurementUnit,
&aTextValue->textHeight, aActualConversion ); &aTextValue->textHeight, aActualConversion );
if( isTrueType ) if( aTextValue->isTrueType )
{ {
aTextValue->textstrokeWidth = TRUETYPE_WIDTH_PER_HEIGHT * aTextValue->textHeight; aTextValue->textstrokeWidth = TRUETYPE_THICK_PER_HEIGHT * aTextValue->textHeight;
if( aTextValue->isBold ) if( aTextValue->isBold )
aTextValue->textstrokeWidth *= TRUETYPE_BOLD_WIDTH_MUL; aTextValue->textstrokeWidth *= TRUETYPE_BOLD_THICK_MUL;
} }
else else
{ {
@ -545,8 +546,15 @@ void CorrectTextPosition( TTEXTVALUE* aValue )
void SetTextSizeFromStrokeFontHeight( EDA_TEXT* aText, int aTextHeight ) void SetTextSizeFromStrokeFontHeight( EDA_TEXT* aText, int aTextHeight )
{ {
aText->SetTextSize( wxSize( KiROUND( aTextHeight * TEXT_WIDTH_TO_SIZE ), aText->SetTextSize( wxSize( KiROUND( aTextHeight * STROKE_WIDTH_TO_SIZE ),
KiROUND( aTextHeight * TEXT_HEIGHT_TO_SIZE ) ) ); KiROUND( aTextHeight * STROKE_HEIGHT_TO_SIZE ) ) );
}
void SetTextSizeFromTrueTypeFontHeight( EDA_TEXT* aText, int aTextHeight )
{
aText->SetTextSize( wxSize( KiROUND( aTextHeight * TRUETYPE_WIDTH_TO_SIZE ),
KiROUND( aTextHeight * TRUETYPE_HEIGHT_TO_SIZE ) ) );
} }
@ -597,6 +605,7 @@ void InitTTextValue( TTEXTVALUE* aTextValue )
aTextValue->justify = LowerLeft; aTextValue->justify = LowerLeft;
aTextValue->isBold = false; aTextValue->isBold = false;
aTextValue->isItalic = false; aTextValue->isItalic = false;
aTextValue->isTrueType = false;
} }
} // namespace PCAD2KICAD } // namespace PCAD2KICAD

View File

@ -64,6 +64,7 @@ typedef struct _TTEXTVALUE
TTEXT_JUSTIFY justify; TTEXT_JUSTIFY justify;
bool isBold; bool isBold;
bool isItalic; bool isItalic;
bool isTrueType;
} TTEXTVALUE; } TTEXTVALUE;
extern wxString GetWord( wxString* aStr ); extern wxString GetWord( wxString* aStr );
@ -102,7 +103,7 @@ extern int CalculateTextLengthSize( TTEXTVALUE* aText );
extern void CorrectTextPosition( TTEXTVALUE* aValue ); extern void CorrectTextPosition( TTEXTVALUE* aValue );
extern void SetTextSizeFromStrokeFontHeight( EDA_TEXT* aText, extern void SetTextSizeFromStrokeFontHeight( EDA_TEXT* aText,
int aTextHeight ); int aTextHeight );
extern void SetTextSizeFromTrueTypeFontHeight( EDA_TEXT* aText, int aTextHeight );
extern XNODE* FindNode( XNODE* aChild, wxString aTag ); extern XNODE* FindNode( XNODE* aChild, wxString aTag );
extern wxString FindNodeGetContent( XNODE* aChild, wxString aTag ); extern wxString FindNodeGetContent( XNODE* aChild, wxString aTag );
extern void InitTTextValue( TTEXTVALUE* aTextValue ); extern void InitTTextValue( TTEXTVALUE* aTextValue );

View File

@ -530,6 +530,9 @@ void PCB_MODULE::AddToBoard()
ref_text->SetType( TEXTE_MODULE::TEXT_is_REFERENCE ); ref_text->SetType( TEXTE_MODULE::TEXT_is_REFERENCE );
ref_text->SetPos0( wxPoint( m_name.correctedPositionX, m_name.correctedPositionY ) ); ref_text->SetPos0( wxPoint( m_name.correctedPositionX, m_name.correctedPositionY ) );
if( m_name.isTrueType )
SetTextSizeFromTrueTypeFontHeight( ref_text, m_name.textHeight );
else
SetTextSizeFromStrokeFontHeight( ref_text, m_name.textHeight ); SetTextSizeFromStrokeFontHeight( ref_text, m_name.textHeight );
r = m_name.textRotation - m_rotation; r = m_name.textRotation - m_rotation;
@ -554,6 +557,9 @@ void PCB_MODULE::AddToBoard()
val_text->SetType( TEXTE_MODULE::TEXT_is_VALUE ); val_text->SetType( TEXTE_MODULE::TEXT_is_VALUE );
val_text->SetPos0( wxPoint( m_value.correctedPositionX, m_value.correctedPositionY ) ); val_text->SetPos0( wxPoint( m_value.correctedPositionX, m_value.correctedPositionY ) );
if( m_value.isTrueType )
SetTextSizeFromTrueTypeFontHeight( val_text, m_value.textHeight );
else
SetTextSizeFromStrokeFontHeight( val_text, m_value.textHeight ); SetTextSizeFromStrokeFontHeight( val_text, m_value.textHeight );
r = m_value.textRotation - m_rotation; r = m_value.textRotation - m_rotation;

View File

@ -110,6 +110,9 @@ void PCB_TEXT::AddToBoard()
pcbtxt->SetText( m_name.text ); pcbtxt->SetText( m_name.text );
if( m_name.isTrueType )
SetTextSizeFromTrueTypeFontHeight( pcbtxt, m_name.textHeight );
else
SetTextSizeFromStrokeFontHeight( pcbtxt, m_name.textHeight ); SetTextSizeFromStrokeFontHeight( pcbtxt, m_name.textHeight );
pcbtxt->SetItalic( m_name.isItalic ); pcbtxt->SetItalic( m_name.isItalic );