OSX: fix bug caused by wxBitmap drawing 0 width or heigth bitmap. (fixes lp:1529159)
This commit is contained in:
parent
c8b2971d1c
commit
ab0e3d0ce2
|
@ -6,7 +6,7 @@
|
||||||
* This program source code file is part of KiCad, a free EDA CAD application.
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
||||||
*
|
*
|
||||||
* Copyright (C) 2011 jean-pierre.charras
|
* Copyright (C) 2011 jean-pierre.charras
|
||||||
* Copyright (C) 2011 KiCad Developers, see change_log.txt for contributors.
|
* Copyright (C) 2011-2016 KiCad Developers, see change_log.txt for contributors.
|
||||||
*
|
*
|
||||||
* This program is free software; you can redistribute it and/or
|
* This program is free software; you can redistribute it and/or
|
||||||
* modify it under the terms of the GNU General Public License
|
* modify it under the terms of the GNU General Public License
|
||||||
|
@ -108,14 +108,17 @@ bool BITMAP_BASE::SaveData( FILE* aFile ) const
|
||||||
wxStreamBuffer* buffer = stream.GetOutputStreamBuffer();
|
wxStreamBuffer* buffer = stream.GetOutputStreamBuffer();
|
||||||
char* begin = (char*) buffer->GetBufferStart();
|
char* begin = (char*) buffer->GetBufferStart();
|
||||||
int ii;
|
int ii;
|
||||||
|
|
||||||
for( ii = 0; begin <= buffer->GetBufferEnd(); begin++, ii++ )
|
for( ii = 0; begin <= buffer->GetBufferEnd(); begin++, ii++ )
|
||||||
{
|
{
|
||||||
if( ii >= 32 )
|
if( ii >= 32 )
|
||||||
{
|
{
|
||||||
ii = 0;
|
ii = 0;
|
||||||
|
|
||||||
if( fprintf( aFile, "\n" ) == EOF )
|
if( fprintf( aFile, "\n" ) == EOF )
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if( fprintf( aFile, "%2.2X ", *begin & 0xFF ) == EOF )
|
if( fprintf( aFile, "%2.2X ", *begin & 0xFF ) == EOF )
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -124,6 +127,7 @@ bool BITMAP_BASE::SaveData( FILE* aFile ) const
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void BITMAP_BASE::SaveData( wxArrayString& aPngStrings ) const
|
void BITMAP_BASE::SaveData( wxArrayString& aPngStrings ) const
|
||||||
{
|
{
|
||||||
if( m_image )
|
if( m_image )
|
||||||
|
@ -134,7 +138,8 @@ void BITMAP_BASE::SaveData( wxArrayString& aPngStrings ) const
|
||||||
// Write binary data in hexadecimal form (ASCII)
|
// Write binary data in hexadecimal form (ASCII)
|
||||||
wxStreamBuffer* buffer = stream.GetOutputStreamBuffer();
|
wxStreamBuffer* buffer = stream.GetOutputStreamBuffer();
|
||||||
char* begin = (char*) buffer->GetBufferStart();
|
char* begin = (char*) buffer->GetBufferStart();
|
||||||
wxString line;
|
wxString line;
|
||||||
|
|
||||||
for( int ii = 0; begin <= buffer->GetBufferEnd(); begin++, ii++ )
|
for( int ii = 0; begin <= buffer->GetBufferEnd(); begin++, ii++ )
|
||||||
{
|
{
|
||||||
if( ii >= 32 )
|
if( ii >= 32 )
|
||||||
|
@ -144,7 +149,7 @@ void BITMAP_BASE::SaveData( wxArrayString& aPngStrings ) const
|
||||||
line.Empty();
|
line.Empty();
|
||||||
}
|
}
|
||||||
|
|
||||||
line << wxString::Format( wxT("%2.2X "), *begin & 0xFF );
|
line << wxString::Format( wxT( "%2.2X " ), *begin & 0xFF );
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add last line:
|
// Add last line:
|
||||||
|
@ -218,6 +223,11 @@ void BITMAP_BASE::DrawBitmap( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint&
|
||||||
wxPoint pos = aPos;
|
wxPoint pos = aPos;
|
||||||
wxSize size = GetSize();
|
wxSize size = GetSize();
|
||||||
|
|
||||||
|
// This fixes a bug in OSX that should be fixed in the 3.0.3 version or later.
|
||||||
|
// See: http://trac.wxwidgets.org/ticket/16329 for more information.
|
||||||
|
if( ( size.x == 0 ) || ( size.y == 0 ) )
|
||||||
|
return;
|
||||||
|
|
||||||
// To draw the bitmap, pos is the upper left corner position
|
// To draw the bitmap, pos is the upper left corner position
|
||||||
pos.x -= size.x / 2;
|
pos.x -= size.x / 2;
|
||||||
pos.y -= size.y / 2;
|
pos.y -= size.y / 2;
|
||||||
|
@ -228,7 +238,7 @@ void BITMAP_BASE::DrawBitmap( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint&
|
||||||
aDC->GetLogicalOrigin( &logicalOriginX, &logicalOriginY );
|
aDC->GetLogicalOrigin( &logicalOriginX, &logicalOriginY );
|
||||||
aDC->SetUserScale( scale * GetScalingFactor(), scale * GetScalingFactor() );
|
aDC->SetUserScale( scale * GetScalingFactor(), scale * GetScalingFactor() );
|
||||||
aDC->SetLogicalOrigin( logicalOriginX / GetScalingFactor(),
|
aDC->SetLogicalOrigin( logicalOriginX / GetScalingFactor(),
|
||||||
logicalOriginY / GetScalingFactor() );
|
logicalOriginY / GetScalingFactor() );
|
||||||
aDC->DrawBitmap( *m_bitmap,
|
aDC->DrawBitmap( *m_bitmap,
|
||||||
KiROUND( pos.x / GetScalingFactor() ),
|
KiROUND( pos.x / GetScalingFactor() ),
|
||||||
KiROUND( pos.y / GetScalingFactor() ),
|
KiROUND( pos.y / GetScalingFactor() ),
|
||||||
|
@ -238,9 +248,6 @@ void BITMAP_BASE::DrawBitmap( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint&
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* Function GetSize
|
|
||||||
* returns the actual size (in user units, not in pixels) of the image
|
|
||||||
*/
|
|
||||||
wxSize BITMAP_BASE::GetSize() const
|
wxSize BITMAP_BASE::GetSize() const
|
||||||
{
|
{
|
||||||
wxSize size;
|
wxSize size;
|
||||||
|
@ -258,12 +265,6 @@ wxSize BITMAP_BASE::GetSize() const
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Mirror image vertically (i.e. relative to its horizontal X axis )
|
|
||||||
* or horizontally (i.e relative to its vertical Y axis)
|
|
||||||
* param aVertically = false to mirror horizontally
|
|
||||||
* or true to mirror vertically
|
|
||||||
*/
|
|
||||||
void BITMAP_BASE::Mirror( bool aVertically )
|
void BITMAP_BASE::Mirror( bool aVertically )
|
||||||
{
|
{
|
||||||
if( m_image )
|
if( m_image )
|
||||||
|
@ -292,10 +293,9 @@ void BITMAP_BASE::PlotImage( PLOTTER* aPlotter,
|
||||||
if( m_image == NULL )
|
if( m_image == NULL )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// These 2 lines are useful only fot plotters that cannot plot a bitmap
|
// These 2 lines are useful only for plotters that cannot plot a bitmap
|
||||||
// and plot a rectangle instead of.
|
// and plot a rectangle instead of.
|
||||||
aPlotter->SetColor( aDefaultColor );
|
aPlotter->SetColor( aDefaultColor );
|
||||||
aPlotter->SetCurrentLineWidth( aDefaultPensize );
|
aPlotter->SetCurrentLineWidth( aDefaultPensize );
|
||||||
|
|
||||||
aPlotter->PlotImage( *m_image, aPos, GetScalingFactor() );
|
aPlotter->PlotImage( *m_image, aPos, GetScalingFactor() );
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue