pcad2kicadpcb_plugin: use a valid font properties
Use current selected font (Stroke, TrueType) properties. Import TrueType Font properties: bold, italic.
This commit is contained in:
parent
897702b2dc
commit
08b71cd252
|
@ -43,6 +43,10 @@ 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;
|
||||
// True type font
|
||||
const double TRUETYPE_WIDTH_PER_HEIGHT = 0.073;
|
||||
const double TRUETYPE_BOLD_WIDTH_MUL = 1.6;
|
||||
const long TRUETYPE_BOLD_MIN_WEIGHT = 700;
|
||||
|
||||
wxString GetWord( wxString* aStr )
|
||||
{
|
||||
|
@ -289,6 +293,7 @@ void SetDoublePrecisionPosition( wxString aStr,
|
|||
aActualConversion );
|
||||
}
|
||||
|
||||
|
||||
TTEXT_JUSTIFY GetJustifyIdentificator( wxString aJustify )
|
||||
{
|
||||
TTEXT_JUSTIFY id;
|
||||
|
@ -315,6 +320,7 @@ TTEXT_JUSTIFY GetJustifyIdentificator( wxString aJustify )
|
|||
return id;
|
||||
}
|
||||
|
||||
|
||||
void SetTextParameters( XNODE* aNode,
|
||||
TTEXTVALUE* aTextValue,
|
||||
wxString aDefaultMeasurementUnit,
|
||||
|
@ -382,49 +388,77 @@ void SetFontProperty( XNODE* aNode,
|
|||
aNode = aNode->GetParent();
|
||||
|
||||
aNode = FindNode( aNode, wxT( "library" ) );
|
||||
|
||||
if( aNode )
|
||||
aNode = FindNode( aNode, wxT( "textStyleDef" ) );
|
||||
|
||||
while( aNode )
|
||||
{
|
||||
aNode->GetAttribute( wxT( "Name" ), &propValue );
|
||||
propValue.Trim( false );
|
||||
propValue.Trim( true );
|
||||
|
||||
if( propValue == n )
|
||||
break;
|
||||
|
||||
aNode = aNode->GetNext();
|
||||
}
|
||||
|
||||
if( aNode )
|
||||
{
|
||||
while( true )
|
||||
{
|
||||
aNode->GetAttribute( wxT( "Name" ), &propValue );
|
||||
propValue.Trim( false );
|
||||
propValue.Trim( true );
|
||||
bool isTrueType;
|
||||
wxString fontType;
|
||||
|
||||
if( propValue == n )
|
||||
break;
|
||||
propValue = FindNodeGetContent( aNode, wxT( "textStyleDisplayTType" ) );
|
||||
isTrueType = ( propValue == wxT( "True" ) );
|
||||
|
||||
aNode = FindNode( aNode, wxT( "font" ) );
|
||||
fontType = FindNodeGetContent( aNode, wxT( "fontType" ) );
|
||||
if( ( isTrueType && ( fontType != wxT( "TrueType" ) ) ) ||
|
||||
( !isTrueType && ( fontType != wxT( "Stroke" ) ) ) )
|
||||
aNode = aNode->GetNext();
|
||||
}
|
||||
|
||||
if( aNode )
|
||||
{
|
||||
aNode = FindNode( aNode, wxT( "font" ) );
|
||||
|
||||
if( aNode )
|
||||
if( isTrueType )
|
||||
{
|
||||
if( FindNode( aNode, wxT( "fontHeight" ) ) )
|
||||
// // SetWidth(iNode.ChildNodes.FindNode('fontHeight').Text,
|
||||
// // DefaultMeasurementUnit,tv.TextHeight);
|
||||
// Fixed By Lubo, 02/2008
|
||||
SetHeight( FindNode( aNode, wxT(
|
||||
"fontHeight" ) )->GetNodeContent(),
|
||||
aDefaultMeasurementUnit, &aTextValue->textHeight,
|
||||
aActualConversion );
|
||||
propValue = FindNodeGetContent( aNode, wxT( "fontItalic" ) );
|
||||
aTextValue->isItalic = ( propValue == wxT( "True" ) );
|
||||
|
||||
if( FindNode( aNode, wxT( "strokeWidth" ) ) )
|
||||
SetWidth( FindNode( aNode, wxT(
|
||||
"strokeWidth" ) )->GetNodeContent(),
|
||||
aDefaultMeasurementUnit, &aTextValue->textstrokeWidth,
|
||||
aActualConversion );
|
||||
propValue = FindNodeGetContent( aNode, wxT( "fontWeight" ) );
|
||||
if( propValue != wxEmptyString )
|
||||
{
|
||||
long fontWeight;
|
||||
|
||||
propValue.ToLong( &fontWeight );
|
||||
aTextValue->isBold = ( fontWeight >= TRUETYPE_BOLD_MIN_WEIGHT );
|
||||
}
|
||||
}
|
||||
|
||||
XNODE* lNode;
|
||||
|
||||
lNode = FindNode( aNode, wxT( "fontHeight" ) );
|
||||
if( lNode )
|
||||
SetHeight( lNode->GetNodeContent(), aDefaultMeasurementUnit,
|
||||
&aTextValue->textHeight, aActualConversion );
|
||||
|
||||
if( isTrueType )
|
||||
{
|
||||
aTextValue->textstrokeWidth = TRUETYPE_WIDTH_PER_HEIGHT * aTextValue->textHeight;
|
||||
if( aTextValue->isBold )
|
||||
aTextValue->textstrokeWidth *= TRUETYPE_BOLD_WIDTH_MUL;
|
||||
}
|
||||
else
|
||||
{
|
||||
lNode = FindNode( aNode, wxT( "strokeWidth" ) );
|
||||
if( lNode )
|
||||
SetWidth( lNode->GetNodeContent(), aDefaultMeasurementUnit,
|
||||
&aTextValue->textstrokeWidth, aActualConversion );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void SetTextJustify( EDA_TEXT* aText, TTEXT_JUSTIFY aJustify )
|
||||
{
|
||||
switch( aJustify )
|
||||
|
@ -468,12 +502,14 @@ void SetTextJustify( EDA_TEXT* aText, TTEXT_JUSTIFY aJustify )
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
int CalculateTextLengthSize( TTEXTVALUE* aText )
|
||||
{
|
||||
return KiROUND( (double) aText->text.Len() *
|
||||
(double) aText->textHeight * TEXT_WIDTH_TO_SIZE_AVERAGE );
|
||||
}
|
||||
|
||||
|
||||
void CorrectTextPosition( TTEXTVALUE* aValue )
|
||||
{
|
||||
int cm = aValue->mirror ? -1 : 1;
|
||||
|
@ -620,6 +656,8 @@ void InitTTextValue( TTEXTVALUE* aTextValue )
|
|||
aTextValue->correctedPositionX = 0;
|
||||
aTextValue->correctedPositionY = 0;
|
||||
aTextValue->justify = LowerLeft;
|
||||
aTextValue->isBold = false;
|
||||
aTextValue->isItalic = false;
|
||||
}
|
||||
|
||||
} // namespace PCAD2KICAD
|
||||
|
|
|
@ -56,12 +56,14 @@ enum TTEXT_JUSTIFY
|
|||
|
||||
typedef struct _TTEXTVALUE
|
||||
{
|
||||
wxString text;
|
||||
int textPositionX, textPositionY,
|
||||
textRotation, textHeight, textstrokeWidth;
|
||||
int textIsVisible, mirror, textUnit;
|
||||
int correctedPositionX, correctedPositionY;
|
||||
wxString text;
|
||||
int textPositionX, textPositionY,
|
||||
textRotation, textHeight, textstrokeWidth;
|
||||
int textIsVisible, mirror, textUnit;
|
||||
int correctedPositionX, correctedPositionY;
|
||||
TTEXT_JUSTIFY justify;
|
||||
bool isBold;
|
||||
bool isItalic;
|
||||
} TTEXTVALUE;
|
||||
|
||||
extern wxString GetWord( wxString* aStr );
|
||||
|
|
|
@ -535,6 +535,7 @@ void PCB_MODULE::AddToBoard()
|
|||
r = m_name.textRotation - m_rotation;
|
||||
ref_text->SetTextAngle( r );
|
||||
|
||||
ref_text->SetItalic( m_name.isItalic );
|
||||
ref_text->SetThickness( m_name.textstrokeWidth );
|
||||
|
||||
ref_text->SetMirrored( m_name.mirror );
|
||||
|
@ -557,6 +558,7 @@ void PCB_MODULE::AddToBoard()
|
|||
r = m_value.textRotation - m_rotation;
|
||||
val_text->SetTextAngle( r );
|
||||
|
||||
val_text->SetItalic( m_value.isItalic );
|
||||
val_text->SetThickness( m_value.textstrokeWidth );
|
||||
|
||||
val_text->SetMirrored( m_value.mirror );
|
||||
|
|
|
@ -112,6 +112,7 @@ void PCB_TEXT::AddToBoard()
|
|||
|
||||
SetTextSizeFromStrokeFontHeight( pcbtxt, m_name.textHeight );
|
||||
|
||||
pcbtxt->SetItalic( m_name.isItalic );
|
||||
pcbtxt->SetThickness( m_name.textstrokeWidth );
|
||||
pcbtxt->SetTextAngle( m_name.textRotation );
|
||||
|
||||
|
|
Loading…
Reference in New Issue