From b63d0a3138e79b784487dc34ecd56b48e248c350 Mon Sep 17 00:00:00 2001 From: Alex Date: Fri, 17 Feb 2023 03:41:57 +0300 Subject: [PATCH] Keep image sizes when loading/saving 7.0- schematic file formats. Previously, images were assumed to have 300 PPI density when loading from schematic, but not after initial placement. (cherry picked from commit bd4758e4df2024884946f71fe83c4aaeabeb0847) --- eeschema/sch_plugins/kicad/sch_sexpr_parser.cpp | 8 ++++++++ eeschema/sch_plugins/kicad/sch_sexpr_plugin.cpp | 14 ++++++++++++-- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/eeschema/sch_plugins/kicad/sch_sexpr_parser.cpp b/eeschema/sch_plugins/kicad/sch_sexpr_parser.cpp index 1045e381a8..57f17c2bea 100644 --- a/eeschema/sch_plugins/kicad/sch_sexpr_parser.cpp +++ b/eeschema/sch_plugins/kicad/sch_sexpr_parser.cpp @@ -2976,6 +2976,14 @@ SCH_BITMAP* SCH_SEXPR_PARSER::parseImage() } } + // 20230121 or older file format versions assumed 300 image PPI at load/save. + // Let's keep compatibility by changing image scale. + if( m_requiredVersion <= 20230121 ) + { + BITMAP_BASE* image = bitmap->GetImage(); + image->SetScale( image->GetScale() * image->GetPPI() / 300.0 ); + } + return bitmap.release(); } diff --git a/eeschema/sch_plugins/kicad/sch_sexpr_plugin.cpp b/eeschema/sch_plugins/kicad/sch_sexpr_plugin.cpp index 8555d74d14..1847d2b0f0 100644 --- a/eeschema/sch_plugins/kicad/sch_sexpr_plugin.cpp +++ b/eeschema/sch_plugins/kicad/sch_sexpr_plugin.cpp @@ -920,8 +920,18 @@ void SCH_SEXPR_PLUGIN::saveBitmap( SCH_BITMAP* aBitmap, int aNestLevel ) EDA_UNIT_UTILS::FormatInternalUnits( schIUScale, aBitmap->GetPosition().y ).c_str() ); - if( aBitmap->GetImage()->GetScale() != 1.0 ) - m_out->Print( 0, " (scale %g)", aBitmap->GetImage()->GetScale() ); + double scale = aBitmap->GetImage()->GetScale(); + + // 20230121 or older file format versions assumed 300 image PPI at load/save. + // Let's keep compatibility by changing image scale. + if( SEXPR_SCHEMATIC_FILE_VERSION <= 20230121 ) + { + BITMAP_BASE* image = aBitmap->GetImage(); + scale = scale * 300.0 / image->GetPPI(); + } + + if( scale != 1.0 ) + m_out->Print( 0, " (scale %g)", scale ); m_out->Print( 0, "\n" );