diff --git a/eeschema/sch_sexpr_parser.cpp b/eeschema/sch_sexpr_parser.cpp index 515663bd9c..80cd0a0745 100644 --- a/eeschema/sch_sexpr_parser.cpp +++ b/eeschema/sch_sexpr_parser.cpp @@ -5,22 +5,18 @@ * * @author Wayne Stambaugh * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation, either version 3 of the License, or (at your + * option) any later version. * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. * - * You should have received a copy of the GNU General Public License - * along with this program; if not, you may find one here: - * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html - * or you may search the http://www.gnu.org website for the version 2 license, - * or you may write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA + * You should have received a copy of the GNU General Public License along + * with this program. If not, see . */ /** @@ -28,6 +24,10 @@ * @brief Schematic and symbol library s-expression file format parser implementations. */ +// For some reason wxWidgets is built with wxUSE_BASE64 unset so expose the wxWidgets +// base64 code. +#define wxUSE_BASE64 1 +#include #include #include @@ -2076,19 +2076,20 @@ SCH_BITMAP* SCH_SEXPR_PARSER::parseImage() case T_data: { - wxMemoryOutputStream stream; - token = NextTok(); + wxString data; + while( token != T_RIGHT ) { - if( !IsSymbol( token ) || CurStr().find_first_of( "0x" ) != 0 ) - Expecting( "hex image data" ); + if( !IsSymbol( token ) ) + Expecting( "base64 image data" ); - stream.PutC( static_cast( strtol( CurText() + 2, NULL, 16 ) & 0xFF ) ); - token = NextTok(); + data += FromUTF8(); } + wxMemoryBuffer buffer = wxBase64Decode( data ); + wxMemoryOutputStream stream( buffer.GetData(), buffer.GetBufSize() ); wxImage* image = new wxImage(); wxMemoryInputStream istream( stream ); image->LoadFile( istream, wxBITMAP_TYPE_PNG ); diff --git a/eeschema/sch_sexpr_plugin.cpp b/eeschema/sch_sexpr_plugin.cpp index 3b2f63d6bd..7a007644f9 100644 --- a/eeschema/sch_sexpr_plugin.cpp +++ b/eeschema/sch_sexpr_plugin.cpp @@ -23,6 +23,10 @@ #include #include +// For some reason wxWidgets is built with wxUSE_BASE64 unset so expose the wxWidgets +// base64 code. +#define wxUSE_BASE64 1 +#include #include #include #include @@ -918,21 +922,19 @@ void SCH_SEXPR_PLUGIN::saveBitmap( SCH_BITMAP* aBitmap, int aNestLevel ) // Write binary data in hexadecimal form (ASCII) wxStreamBuffer* buffer = stream.GetOutputStreamBuffer(); - char* begin = (char*) buffer->GetBufferStart(); + wxString out = wxBase64Encode( buffer->GetBufferStart(), buffer->GetBufferSize() ); - for( int ii = 0; begin < buffer->GetBufferEnd(); begin++, ii++ ) + // Apparently the MIME standard character width for base64 encoding is 76 (unconfirmed) + // so use it in a vein attempt to be standard like. +#define MIME_BASE64_LENGTH 76 + + size_t first = 0; + + while( first < out.Length() ) { - if( ii % 16 ) - { - - m_out->Print( 0, " 0x%2.2X", *begin & 0xFF ); - } - else - { - ii = 0; - m_out->Print( 0, "\n" ); - m_out->Print( aNestLevel + 2, "0x%2.2X", *begin & 0xFF ); - } + m_out->Print( 0, "\n" ); + m_out->Print( aNestLevel + 2, "%s", TO_UTF8( out( first, MIME_BASE64_LENGTH ) ) ); + first += MIME_BASE64_LENGTH; } m_out->Print( 0, "\n" );