eagle: Change font size calculation

Eagle includes stroke thickness into font size, KiCAD does not. Remove
the hack with scaling down the font, compute size precisely.

CHANGED: Fixed font calculation in Eagle import
This commit is contained in:
Jan Mrázek 2020-06-09 09:32:52 +02:00 committed by Seth Hillbrand
parent e34a01dc68
commit 3091bb1459
2 changed files with 17 additions and 14 deletions

View File

@ -240,11 +240,11 @@ const wxString EAGLE_PLUGIN::GetFileExtension() const
} }
wxSize inline EAGLE_PLUGIN::kicad_fontz( const ECOORD& d ) const wxSize inline EAGLE_PLUGIN::kicad_fontz( const ECOORD& d, int aTextThickness ) const
{ {
// texts seem to better match eagle when scaled down by 0.95 // Eagle includes stroke thickness in the text size, KiCAD does not
int kz = d.ToPcbUnits() * 95 / 100; int kz = d.ToPcbUnits();
return wxSize( kz, kz ); return wxSize( kz - aTextThickness, kz - aTextThickness );
} }
@ -578,11 +578,10 @@ void EAGLE_PLUGIN::loadPlain( wxXmlNode* aGraphics )
pcbtxt->SetText( FROM_UTF8( t.text.c_str() ) ); pcbtxt->SetText( FROM_UTF8( t.text.c_str() ) );
pcbtxt->SetTextPos( wxPoint( kicad_x( t.x ), kicad_y( t.y ) ) ); pcbtxt->SetTextPos( wxPoint( kicad_x( t.x ), kicad_y( t.y ) ) );
pcbtxt->SetTextSize( kicad_fontz( t.size ) );
double ratio = t.ratio ? *t.ratio : 8; // DTD says 8 is default double ratio = t.ratio ? *t.ratio : 8; // DTD says 8 is default
int textThickness = KiROUND( t.size.ToPcbUnits() * ratio / 100 );
pcbtxt->SetTextThickness( KiROUND( t.size.ToPcbUnits() * ratio / 100 )); pcbtxt->SetTextThickness( textThickness );
pcbtxt->SetTextSize( kicad_fontz( t.size, textThickness ) );
int align = t.align ? *t.align : ETEXT::BOTTOM_LEFT; int align = t.align ? *t.align : ETEXT::BOTTOM_LEFT;
@ -1364,17 +1363,19 @@ void EAGLE_PLUGIN::orientModuleText( MODULE* m, const EELEMENT& e,
// a case where ratio is present but size is not. // a case where ratio is present but size is not.
double ratio = 8; double ratio = 8;
wxSize fontz = txt->GetTextSize(); wxSize fontz = txt->GetTextSize();
int textThickness = KiROUND( fontz.y * ratio / 100 );
txt->SetTextThickness( textThickness );
if( a.size ) if( a.size )
{ {
fontz = kicad_fontz( *a.size ); fontz = kicad_fontz( *a.size, textThickness );
txt->SetTextSize( fontz ); txt->SetTextSize( fontz );
if( a.ratio ) if( a.ratio )
ratio = *a.ratio; ratio = *a.ratio;
} }
txt->SetTextThickness( KiROUND( fontz.y * ratio / 100 ));
int align = ETEXT::BOTTOM_LEFT; // bottom-left is eagle default int align = ETEXT::BOTTOM_LEFT; // bottom-left is eagle default
@ -1722,11 +1723,13 @@ void EAGLE_PLUGIN::packageText( MODULE* aModule, wxXmlNode* aTree ) const
txt->SetPos0( pos - aModule->GetPosition() ); txt->SetPos0( pos - aModule->GetPosition() );
txt->SetLayer( layer ); txt->SetLayer( layer );
txt->SetTextSize( kicad_fontz( t.size ) );
double ratio = t.ratio ? *t.ratio : 8; // DTD says 8 is default double ratio = t.ratio ? *t.ratio : 8; // DTD says 8 is default
int textThickness = KiROUND( t.size.ToPcbUnits() * ratio / 100 );
txt->SetTextThickness( KiROUND( t.size.ToPcbUnits() * ratio / 100 )); txt->SetTextThickness( textThickness );
txt->SetTextSize( kicad_fontz( t.size, textThickness ) );
int align = t.align ? *t.align : ETEXT::BOTTOM_LEFT; // bottom-left is eagle default int align = t.align ? *t.align : ETEXT::BOTTOM_LEFT; // bottom-left is eagle default

View File

@ -204,8 +204,8 @@ private:
int kicad_y( const ECOORD& y ) const { return -y.ToPcbUnits(); } int kicad_y( const ECOORD& y ) const { return -y.ToPcbUnits(); }
int kicad_x( const ECOORD& x ) const { return x.ToPcbUnits(); } int kicad_x( const ECOORD& x ) const { return x.ToPcbUnits(); }
/// create a font size (fontz) from an eagle font size scalar /// create a font size (fontz) from an eagle font size scalar and KiCAD font thickness
wxSize kicad_fontz( const ECOORD& d ) const; wxSize kicad_fontz( const ECOORD& d, int aTextThickness ) const;
/// Convert an Eagle layer to a KiCad layer. /// Convert an Eagle layer to a KiCad layer.
PCB_LAYER_ID kicad_layer( int aLayer ) const; PCB_LAYER_ID kicad_layer( int aLayer ) const;