Better fix for incorrect page preview in Page Settings when the worksheet contains a bitmap

The actual size of pixels was incorrectly set.
Fix also bad names for a few vars and methods in BITMAP_BASE.
This commit is contained in:
jean-pierre charras 2020-11-28 10:53:26 +01:00
parent b1adb93c16
commit 005c3b84ad
10 changed files with 36 additions and 37 deletions

View File

@ -44,12 +44,12 @@
BITMAP_BASE::BITMAP_BASE( const wxPoint& pos ) BITMAP_BASE::BITMAP_BASE( const wxPoint& pos )
{ {
m_scale = 1.0; // 1.0 = original bitmap size m_scale = 1.0; // 1.0 = original bitmap size
m_bitmap = NULL; m_bitmap = NULL;
m_image = NULL; m_image = NULL;
m_ppi = 300; // the bitmap definition. the default is 300PPI m_ppi = 300; // the bitmap definition. the default is 300PPI
m_pixelScaleFactor = 254000.0 / m_ppi; // a value OK for bitmaps using 300 PPI m_pixelSizeIu = 254000.0 / m_ppi; // a pixel size value OK for bitmaps using 300 PPI
// for Eeschema which uses currently 254000PPI // for Eeschema which uses currently 254000PPI
} }
@ -57,7 +57,7 @@ BITMAP_BASE::BITMAP_BASE( const BITMAP_BASE& aSchBitmap )
{ {
m_scale = aSchBitmap.m_scale; m_scale = aSchBitmap.m_scale;
m_ppi = aSchBitmap.m_ppi; m_ppi = aSchBitmap.m_ppi;
m_pixelScaleFactor = aSchBitmap.m_pixelScaleFactor; m_pixelSizeIu = aSchBitmap.m_pixelSizeIu;
m_image = nullptr; m_image = nullptr;
m_bitmap = nullptr; m_bitmap = nullptr;
@ -80,7 +80,7 @@ void BITMAP_BASE::ImportData( BITMAP_BASE* aItem )
*m_bitmap = *aItem->m_bitmap; *m_bitmap = *aItem->m_bitmap;
m_scale = aItem->m_scale; m_scale = aItem->m_scale;
m_ppi = aItem->m_ppi; m_ppi = aItem->m_ppi;
m_pixelScaleFactor = aItem->m_pixelScaleFactor; m_pixelSizeIu = aItem->m_pixelSizeIu;
} }

View File

@ -308,7 +308,6 @@ bool EnsureFileDirectoryExists( wxFileName* aTargetFullFileName,
if( !wxFileName::DirExists( outputPath ) ) if( !wxFileName::DirExists( outputPath ) )
{ {
// Make every directory provided when the provided path doesn't exist // Make every directory provided when the provided path doesn't exist
// Fixes GitLab Issue #6394
if( wxFileName::Mkdir( outputPath, wxS_DIR_DEFAULT, wxPATH_MKDIR_FULL ) ) if( wxFileName::Mkdir( outputPath, wxS_DIR_DEFAULT, wxPATH_MKDIR_FULL ) )
{ {
if( aReporter ) if( aReporter )

View File

@ -823,13 +823,13 @@ static const wxString productName = wxT( "KiCad E.D.A. " );
void PrintPageLayout( RENDER_SETTINGS* aSettings, const PAGE_INFO& aPageInfo, void PrintPageLayout( RENDER_SETTINGS* aSettings, const PAGE_INFO& aPageInfo,
const wxString& aFullSheetName, const wxString& aFileName, const wxString& aFullSheetName, const wxString& aFileName,
const TITLE_BLOCK& aTitleBlock, int aSheetCount, const wxString& aPageNumber, const TITLE_BLOCK& aTitleBlock, int aSheetCount, const wxString& aPageNumber,
double aScalar, const PROJECT* aProject, const wxString& aSheetLayer, double aMils2Iu, const PROJECT* aProject, const wxString& aSheetLayer,
bool aIsFirstPage ) bool aIsFirstPage )
{ {
WS_DRAW_ITEM_LIST drawList; WS_DRAW_ITEM_LIST drawList;
drawList.SetDefaultPenSize( aSettings->GetDefaultPenWidth() ); drawList.SetDefaultPenSize( aSettings->GetDefaultPenWidth() );
drawList.SetMilsToIUfactor( aScalar ); drawList.SetMilsToIUfactor( aMils2Iu );
drawList.SetPageNumber( aPageNumber ); drawList.SetPageNumber( aPageNumber );
drawList.SetSheetCount( aSheetCount ); drawList.SetSheetCount( aSheetCount );
drawList.SetFileName( aFileName ); drawList.SetFileName( aFileName );
@ -846,7 +846,7 @@ void PrintPageLayout( RENDER_SETTINGS* aSettings, const PAGE_INFO& aPageInfo,
void EDA_DRAW_FRAME::PrintWorkSheet( RENDER_SETTINGS* aSettings, BASE_SCREEN* aScreen, void EDA_DRAW_FRAME::PrintWorkSheet( RENDER_SETTINGS* aSettings, BASE_SCREEN* aScreen,
double aScalar, const wxString &aFilename, double aMils2Iu, const wxString &aFilename,
const wxString &aSheetLayer ) const wxString &aSheetLayer )
{ {
if( !m_showBorderAndTitleBlock ) if( !m_showBorderAndTitleBlock )
@ -862,7 +862,7 @@ void EDA_DRAW_FRAME::PrintWorkSheet( RENDER_SETTINGS* aSettings, BASE_SCREEN* aS
} }
PrintPageLayout( aSettings, GetPageSettings(), GetScreenDesc(), aFilename, GetTitleBlock(), PrintPageLayout( aSettings, GetPageSettings(), GetScreenDesc(), aFilename, GetTitleBlock(),
aScreen->GetPageCount(), aScreen->GetPageNumber(), aScalar, &Prj(), aScreen->GetPageCount(), aScreen->GetPageNumber(), aMils2Iu, &Prj(),
aSheetLayer, aScreen->GetVirtualPageNumber() == 1 ); aSheetLayer, aScreen->GetVirtualPageNumber() == 1 );
if( origin.y > 0 ) if( origin.y > 0 )

View File

@ -762,7 +762,11 @@ void WS_DATA_ITEM_BITMAP::SyncDrawItems( WS_DRAW_ITEM_LIST* aCollector, KIGFX::V
if( j && !IsInsidePage( j ) ) if( j && !IsInsidePage( j ) )
continue; continue;
auto bitmap = new WS_DRAW_ITEM_BITMAP( this, j, GetStartPosUi( j ) ); double pix_size_iu = aCollector->GetMilsToIUfactor() * 1000 / m_ImageBitmap->GetPPI();
m_ImageBitmap->SetPixelSizeIu( pix_size_iu );
WS_DRAW_ITEM_BITMAP* bitmap = new WS_DRAW_ITEM_BITMAP( this, j, GetStartPosUi( j ) );
bitmap->SetFlags( itemFlags[ j ] ); bitmap->SetFlags( itemFlags[ j ] );
m_drawItems.push_back( bitmap ); m_drawItems.push_back( bitmap );

View File

@ -401,16 +401,7 @@ void WS_DRAW_ITEM_BITMAP::PrintWsItem( RENDER_SETTINGS* aSettings, const wxPoint
if( !bitmap->m_ImageBitmap ) if( !bitmap->m_ImageBitmap )
return; return;
// We are using here internal unit = 1 mil for historical reason
// the PixelScaleFactor in mils is:
double pix_scale = 1000.0 / bitmap->GetPPI();
double ps = bitmap->m_ImageBitmap->GetPixelScaleFactor(); // Store initial value
bitmap->m_ImageBitmap->SetPixelScaleFactor( pix_scale );
bitmap->m_ImageBitmap->DrawBitmap( aSettings->GetPrintDC(), m_pos + aOffset ); bitmap->m_ImageBitmap->DrawBitmap( aSettings->GetPrintDC(), m_pos + aOffset );
bitmap->m_ImageBitmap->SetPixelScaleFactor( ps ); // restore initial value
} }

View File

@ -52,10 +52,10 @@ class BITMAP_BASE
{ {
private: private:
double m_scale; // The scaling factor of the bitmap double m_scale; // The scaling factor of the bitmap
// With m_pixelScaleFactor, controls the actual draw size // With m_pixelSizeIu, controls the actual draw size
wxImage* m_image; // the raw image data (png format) wxImage* m_image; // the raw image data (png format)
wxBitmap* m_bitmap; // the bitmap used to draw/plot image wxBitmap* m_bitmap; // the bitmap used to draw/plot image
double m_pixelScaleFactor; // The scaling factor of the bitmap double m_pixelSizeIu; // The scaling factor of the bitmap
// to convert the bitmap size (in pixels) // to convert the bitmap size (in pixels)
// to internal KiCad units // to internal KiCad units
// Usually does not change // Usually does not change
@ -77,8 +77,8 @@ public:
/* /*
* Accessors: * Accessors:
*/ */
double GetPixelScaleFactor() const { return m_pixelScaleFactor; } double GetPixelSizeIu() const { return m_pixelSizeIu; }
void SetPixelScaleFactor( double aSF ) { m_pixelScaleFactor = aSF; } void SetPixelSizeIu( double aPixSize ) { m_pixelSizeIu = aPixSize; }
wxImage* GetImageData() { return m_image; } wxImage* GetImageData() { return m_image; }
const wxImage* GetImageData() const { return m_image; } const wxImage* GetImageData() const { return m_image; }
@ -114,8 +114,8 @@ public:
/** /**
* Function GetScalingFactor * Function GetScalingFactor
* @return the scaling factor from pixel size to actual draw size * @return the scaling factor from pixel size to actual draw size
* this scaling factor depends on m_pixelScaleFactor and m_scale * this scaling factor depends on m_pixelSizeIu and m_scale
* m_pixelScaleFactor gives the scaling factor between a pixel size and * m_pixelSizeIu gives the scaling factor between a pixel size and
* the internal schematic units * the internal schematic units
* m_scale is an user dependant value, and gives the "zoom" value * m_scale is an user dependant value, and gives the "zoom" value
* m_scale = 1.0 = original size of bitmap. * m_scale = 1.0 = original size of bitmap.
@ -124,7 +124,7 @@ public:
*/ */
double GetScalingFactor() const double GetScalingFactor() const
{ {
return m_pixelScaleFactor * m_scale; return m_pixelSizeIu * m_scale;
} }

View File

@ -362,11 +362,11 @@ public:
* Prints the page layout with the frame and the basic inscriptions. * Prints the page layout with the frame and the basic inscriptions.
* *
* @param aScreen screen to draw * @param aScreen screen to draw
* @param aScale The mils to Iu conversion factor. * @param aMils2Iu The mils to Iu conversion factor.
* @param aFilename The filename to display in basic inscriptions. * @param aFilename The filename to display in basic inscriptions.
* @param aSheetLayer The layer displayed from pcbnew. * @param aSheetLayer The layer displayed from pcbnew.
*/ */
void PrintWorkSheet( RENDER_SETTINGS* aSettings, BASE_SCREEN* aScreen, double aScale, void PrintWorkSheet( RENDER_SETTINGS* aSettings, BASE_SCREEN* aScreen, double aMils2Iu,
const wxString &aFilename, const wxString &aSheetLayer = wxEmptyString ); const wxString &aFilename, const wxString &aSheetLayer = wxEmptyString );
void DisplayToolMsg( const wxString& msg ) override; void DisplayToolMsg( const wxString& msg ) override;

View File

@ -440,11 +440,16 @@ public:
/** /**
* Set the scalar to convert pages units (mils) to draw/plot units * Set the scalar to convert pages units (mils) to draw/plot units
*/ */
void SetMilsToIUfactor( double aScale ) void SetMilsToIUfactor( double aMils2Iu )
{ {
m_milsToIu = aScale; m_milsToIu = aMils2Iu;
} }
/**
* Get the scalar to convert pages units (mils) to draw/plot units
*/
double GetMilsToIUfactor() { return m_milsToIu; }
/** /**
* Set the value of the sheet number. * Set the value of the sheet number.
*/ */
@ -512,7 +517,7 @@ public:
* *
* Before calling this function, some parameters should be initialized by calling: * Before calling this function, some parameters should be initialized by calling:
* SetPenSize( aPenWidth ); * SetPenSize( aPenWidth );
* SetMilsToIUfactor( aScalar ); * SetMilsToIUfactor( aMils2Iu );
* SetSheetNumber( aSheetNumber ); * SetSheetNumber( aSheetNumber );
* SetSheetCount( aSheetCount ); * SetSheetCount( aSheetCount );
* SetFileName( aFileName ); * SetFileName( aFileName );

View File

@ -202,8 +202,8 @@ void PLEDITOR_PRINTOUT::PrintPage( int aPageNum )
continue; continue;
WS_DATA_ITEM_BITMAP* itemBM = static_cast<WS_DATA_ITEM_BITMAP*>( dataItem ); WS_DATA_ITEM_BITMAP* itemBM = static_cast<WS_DATA_ITEM_BITMAP*>( dataItem );
itemBM->m_ImageBitmap->SetPixelScaleFactor( IU_PER_MILS * 1000 / itemBM->m_ImageBitmap->SetPixelSizeIu( IU_PER_MILS * 1000 /
itemBM->m_ImageBitmap->GetPPI() ); itemBM->m_ImageBitmap->GetPPI() );
} }
m_parent->PrintWorkSheet( &renderSettings, screen, IU_PER_MILS, wxEmptyString ); m_parent->PrintWorkSheet( &renderSettings, screen, IU_PER_MILS, wxEmptyString );

View File

@ -782,7 +782,7 @@ void PL_EDITOR_FRAME::PrintPage( RENDER_SETTINGS* aSettings )
continue; continue;
WS_DATA_ITEM_BITMAP* itemBM = static_cast<WS_DATA_ITEM_BITMAP*>( dataItem ); WS_DATA_ITEM_BITMAP* itemBM = static_cast<WS_DATA_ITEM_BITMAP*>( dataItem );
itemBM->m_ImageBitmap->SetPixelScaleFactor( IU_PER_MILS * 1000 itemBM->m_ImageBitmap->SetPixelSizeIu( IU_PER_MILS * 1000
/ itemBM->m_ImageBitmap->GetPPI() ); / itemBM->m_ImageBitmap->GetPPI() );
} }
@ -870,7 +870,7 @@ WS_DATA_ITEM* PL_EDITOR_FRAME::AddPageLayoutItem( int aType )
} }
// Set the scale factor for pl_editor (it is set for eeschema by default) // Set the scale factor for pl_editor (it is set for eeschema by default)
image->SetPixelScaleFactor( 25400.0 / image->GetPPI() ); image->SetPixelSizeIu( 25400.0 / image->GetPPI() );
item = new WS_DATA_ITEM_BITMAP( image ); item = new WS_DATA_ITEM_BITMAP( image );
} }
break; break;