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 {
// 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
const double TEXT_HEIGHT_TO_SIZE = 0.656;
const double TEXT_WIDTH_TO_SIZE = 0.656;
// True type font
const double TRUETYPE_WIDTH_PER_HEIGHT = 0.073;
const double TRUETYPE_BOLD_WIDTH_MUL = 1.6;
const double STROKE_HEIGHT_TO_SIZE = 0.656;
const double STROKE_WIDTH_TO_SIZE = 0.69;
// TrueType font
const double TRUETYPE_HEIGHT_TO_SIZE = 0.585;
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;
wxString GetWord( wxString* aStr )
@ -405,21 +407,20 @@ void SetFontProperty( XNODE* aNode,
if( aNode )
{
bool isTrueType;
wxString fontType;
propValue = FindNodeGetContent( aNode, wxT( "textStyleDisplayTType" ) );
isTrueType = ( propValue == wxT( "True" ) );
aTextValue->isTrueType = ( propValue == wxT( "True" ) );
aNode = FindNode( aNode, wxT( "font" ) );
fontType = FindNodeGetContent( aNode, wxT( "fontType" ) );
if( ( isTrueType && ( fontType != wxT( "TrueType" ) ) ) ||
( !isTrueType && ( fontType != wxT( "Stroke" ) ) ) )
if( ( aTextValue->isTrueType && ( fontType != wxT( "TrueType" ) ) ) ||
( !aTextValue->isTrueType && ( fontType != wxT( "Stroke" ) ) ) )
aNode = aNode->GetNext();
if( aNode )
{
if( isTrueType )
if( aTextValue->isTrueType )
{
propValue = FindNodeGetContent( aNode, wxT( "fontItalic" ) );
aTextValue->isItalic = ( propValue == wxT( "True" ) );
@ -441,11 +442,11 @@ void SetFontProperty( XNODE* aNode,
SetHeight( lNode->GetNodeContent(), aDefaultMeasurementUnit,
&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 )
aTextValue->textstrokeWidth *= TRUETYPE_BOLD_WIDTH_MUL;
aTextValue->textstrokeWidth *= TRUETYPE_BOLD_THICK_MUL;
}
else
{
@ -545,8 +546,15 @@ void CorrectTextPosition( TTEXTVALUE* aValue )
void SetTextSizeFromStrokeFontHeight( EDA_TEXT* aText, int aTextHeight )
{
aText->SetTextSize( wxSize( KiROUND( aTextHeight * TEXT_WIDTH_TO_SIZE ),
KiROUND( aTextHeight * TEXT_HEIGHT_TO_SIZE ) ) );
aText->SetTextSize( wxSize( KiROUND( aTextHeight * STROKE_WIDTH_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->isBold = false;
aTextValue->isItalic = false;
aTextValue->isTrueType = false;
}
} // namespace PCAD2KICAD

View File

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

View File

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

View File

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