From 80d8974f873df6382059f703e3b68c6fc748ffb5 Mon Sep 17 00:00:00 2001 From: Roberto Fernandez Bautista Date: Thu, 4 Feb 2021 18:57:09 +0000 Subject: [PATCH] CADSTAR Archive Importer: Fix loading of non-cadstar font text sizes Non-cadstar fonts use a width of 0. --- .../cadstar/cadstar_sch_archive_loader.cpp | 9 ++++++++- .../cadstar/cadstar_pcb_archive_loader.cpp | 16 ++++++++++++++-- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/eeschema/sch_plugins/cadstar/cadstar_sch_archive_loader.cpp b/eeschema/sch_plugins/cadstar/cadstar_sch_archive_loader.cpp index 9ea4269afd..7a59fae277 100644 --- a/eeschema/sch_plugins/cadstar/cadstar_sch_archive_loader.cpp +++ b/eeschema/sch_plugins/cadstar/cadstar_sch_archive_loader.cpp @@ -2252,7 +2252,14 @@ void CADSTAR_SCH_ARCHIVE_LOADER::applyTextSettings( const TEXTCODE_ID& aCadstarT { TEXTCODE textCode = getTextCode( aCadstarTextCodeID ); int textHeight = KiROUND( (double) getKiCadLength( textCode.Height ) * TXT_HEIGHT_RATIO ); - aKiCadTextItem->SetTextWidth( getKiCadLength( textCode.Width ) ); + int textWidth = getKiCadLength( textCode.Width ); + + // The width is zero for all non-cadstar fonts. Using a width equal to the height seems + // to work well for most fonts. + if( textWidth == 0 ) + textWidth = getKiCadLength( textCode.Height ); + + aKiCadTextItem->SetTextWidth( textWidth ); aKiCadTextItem->SetTextHeight( textHeight ); aKiCadTextItem->SetTextThickness( getKiCadLength( textCode.LineWidth ) ); diff --git a/pcbnew/plugins/cadstar/cadstar_pcb_archive_loader.cpp b/pcbnew/plugins/cadstar/cadstar_pcb_archive_loader.cpp index 5030db08b4..8925928950 100644 --- a/pcbnew/plugins/cadstar/cadstar_pcb_archive_loader.cpp +++ b/pcbnew/plugins/cadstar/cadstar_pcb_archive_loader.cpp @@ -2045,6 +2045,12 @@ void CADSTAR_PCB_ARCHIVE_LOADER::drawCadstarText( const TEXT& aCadstarText, wxSize unscaledTextSize; unscaledTextSize.x = getKiCadLength( tc.Width ); + + // The width is zero for all non-cadstar fonts. Using a width equal to the height seems + // to work well for most fonts. + if( unscaledTextSize.x == 0 ) + unscaledTextSize.x = getKiCadLength( tc.Height ); + unscaledTextSize.y = KiROUND( TXT_HEIGHT_RATIO * (double) getKiCadLength( tc.Height ) ); txt->SetTextSize( unscaledTextSize ); @@ -2109,8 +2115,8 @@ void CADSTAR_PCB_ARCHIVE_LOADER::drawCadstarText( const TEXT& aCadstarText, if( aScalingFactor != 1.0 ) { wxSize scaledTextSize; - scaledTextSize.x = KiROUND( (double) getKiCadLength( tc.Width ) * aScalingFactor ); - scaledTextSize.y = KiROUND( (double) getKiCadLength( tc.Height ) * aScalingFactor ); + scaledTextSize.x = KiROUND( (double) unscaledTextSize.x * aScalingFactor ); + scaledTextSize.y = KiROUND( (double) unscaledTextSize.y * aScalingFactor ); txt->SetTextSize( scaledTextSize ); txt->SetTextThickness( KiROUND( (double) getKiCadLength( tc.LineWidth ) * aScalingFactor ) ); @@ -2669,6 +2675,12 @@ void CADSTAR_PCB_ARCHIVE_LOADER::addAttribute( const ATTRIBUTE_LOCATION& aCadsta wxSize txtSize; txtSize.x = getKiCadLength( tc.Width ); + + // The width is zero for all non-cadstar fonts. Using a width equal to the height seems + // to work well for most fonts. + if( txtSize.x == 0 ) + txtSize.x = getKiCadLength( tc.Height ); + txtSize.y = KiROUND( TXT_HEIGHT_RATIO * (double) getKiCadLength( tc.Height ) ); txt->SetTextSize( txtSize ); txt->SetKeepUpright( false ); //Keeping it upright seems to result in incorrect orientation