OSX: fix bug caused by wxBitmap drawing 0 width or heigth bitmap. (fixes lp:1529159)

This commit is contained in:
Nick Winters 2016-02-23 09:05:52 -05:00 committed by Wayne Stambaugh
parent c8b2971d1c
commit ab0e3d0ce2
1 changed files with 15 additions and 15 deletions

View File

@ -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 )
@ -135,6 +139,7 @@ void BITMAP_BASE::SaveData( wxArrayString& aPngStrings ) const
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 )
@ -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;
@ -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() );
} }