SCH_SEXPR_PARSER: fix missing init of pixels size in internal units.

(the pixel size was the default for 300PPI, so the bounding box was incorrect
for images not using 300 PPI)
Avoid also magic numbers in SCH_BITMAP code.
This commit is contained in:
jean-pierre charras 2023-09-25 12:06:23 +02:00
parent 050f812f5e
commit 938001250d
2 changed files with 8 additions and 5 deletions

View File

@ -2,7 +2,7 @@
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2011 jean-pierre.charras
* Copyright (C) 2011-2021 KiCad Developers, see AUTHORS.txt for contributors.
* Copyright (C) 2011-2023 KiCad Developers, see AUTHORS.txt for contributors.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@ -47,6 +47,7 @@ SCH_BITMAP::SCH_BITMAP( const VECTOR2I& pos ) :
m_layer = LAYER_NOTES; // used only to draw/plot a rectangle,
// when a bitmap cannot be drawn or plotted
m_bitmapBase = new BITMAP_BASE();
m_bitmapBase->SetPixelSizeIu( (double) schIUScale.MilsToIU( 1000 ) / m_bitmapBase->GetPPI() );
}
@ -84,7 +85,7 @@ bool SCH_BITMAP::ReadImageFile( const wxString& aFullFilename )
{
if( m_bitmapBase->ReadImageFile( aFullFilename ) )
{
m_bitmapBase->SetPixelSizeIu( 254000.0 / m_bitmapBase->GetPPI() );
m_bitmapBase->SetPixelSizeIu( (double) schIUScale.MilsToIU( 1000 ) / m_bitmapBase->GetPPI() );
return true;
}
@ -96,7 +97,7 @@ bool SCH_BITMAP::ReadImageFile( wxMemoryBuffer& aBuffer )
{
if( m_bitmapBase->ReadImageFile( aBuffer ) )
{
m_bitmapBase->SetPixelSizeIu( 254000.0 / m_bitmapBase->GetPPI() );
m_bitmapBase->SetPixelSizeIu( (double) schIUScale.MilsToIU( 1000 ) / m_bitmapBase->GetPPI() );
return true;
}
@ -127,7 +128,6 @@ void SCH_BITMAP::SwapData( SCH_ITEM* aItem )
const BOX2I SCH_BITMAP::GetBoundingBox() const
{
BOX2I bbox = m_bitmapBase->GetBoundingBox();
bbox.Move( m_pos );
return bbox;

View File

@ -3068,11 +3068,14 @@ SCH_BITMAP* SCH_SEXPR_PARSER::parseImage()
}
}
// Adjust the image pixel size in iu
BITMAP_BASE* image = bitmap->GetImage();
image->SetPixelSizeIu( (double) schIUScale.MilsToIU( 1000 ) / image->GetPPI() );
// 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 );
}