Restore original wxSVGBitmapFileHandler behaviour
Save the embedded images in the same directory as the SVG file, not in the runtime directory.
This commit is contained in:
@@ -40,13 +40,26 @@ public:
|
|||||||
};
|
};
|
||||||
|
|
||||||
// Predefined standard bitmap handler: creates a file, stores the bitmap in
|
// Predefined standard bitmap handler: creates a file, stores the bitmap in
|
||||||
// this file and uses the file URI in the generated SVG.
|
// this file and uses the file name in the generated SVG.
|
||||||
class WXDLLIMPEXP_CORE wxSVGBitmapFileHandler : public wxSVGBitmapHandler
|
class WXDLLIMPEXP_CORE wxSVGBitmapFileHandler : public wxSVGBitmapHandler
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
wxSVGBitmapFileHandler()
|
||||||
|
: m_path()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
explicit wxSVGBitmapFileHandler(const wxString& path)
|
||||||
|
: m_path(path)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
virtual bool ProcessBitmap(const wxBitmap& bitmap,
|
virtual bool ProcessBitmap(const wxBitmap& bitmap,
|
||||||
wxCoord x, wxCoord y,
|
wxCoord x, wxCoord y,
|
||||||
wxOutputStream& stream) const wxOVERRIDE;
|
wxOutputStream& stream) const wxOVERRIDE;
|
||||||
|
|
||||||
|
private:
|
||||||
|
wxString m_path; // When set, will be appended with _image#.png
|
||||||
};
|
};
|
||||||
|
|
||||||
// Predefined handler which embeds the bitmap (base64-encoding it) inside the
|
// Predefined handler which embeds the bitmap (base64-encoding it) inside the
|
||||||
|
@@ -335,24 +335,24 @@ wxSVGBitmapFileHandler::ProcessBitmap(const wxBitmap& bmp,
|
|||||||
wxImage::AddHandler(new wxPNGHandler);
|
wxImage::AddHandler(new wxPNGHandler);
|
||||||
|
|
||||||
// find a suitable file name
|
// find a suitable file name
|
||||||
wxString sPNG;
|
wxFileName sPNG = wxFileName(m_path);
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
sPNG = wxString::Format("image%d.png", sub_images++);
|
sPNG.SetFullName(wxString::Format("%s%simage%d.png",
|
||||||
|
sPNG.GetName(),
|
||||||
|
sPNG.GetName().IsEmpty() ? "" : "_",
|
||||||
|
sub_images++));
|
||||||
}
|
}
|
||||||
while (wxFile::Exists(sPNG));
|
while ( sPNG.FileExists() );
|
||||||
|
|
||||||
if ( !bmp.SaveFile(sPNG, wxBITMAP_TYPE_PNG) )
|
if ( !bmp.SaveFile(sPNG.GetFullPath(), wxBITMAP_TYPE_PNG) )
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
// reference the bitmap from the SVG doc using only filename & ext
|
|
||||||
sPNG = sPNG.AfterLast(wxFileName::GetPathSeparator());
|
|
||||||
|
|
||||||
// reference the bitmap from the SVG doc
|
// reference the bitmap from the SVG doc
|
||||||
wxString s;
|
wxString s;
|
||||||
s += wxString::Format(" <image x=\"%d\" y=\"%d\" width=\"%dpx\" height=\"%dpx\"",
|
s += wxString::Format(" <image x=\"%d\" y=\"%d\" width=\"%dpx\" height=\"%dpx\"",
|
||||||
x, y, bmp.GetWidth(), bmp.GetHeight());
|
x, y, bmp.GetWidth(), bmp.GetHeight());
|
||||||
s += wxString::Format(" xlink:href=\"%s\"/>\n", sPNG);
|
s += wxString::Format(" xlink:href=\"%s\"/>\n", sPNG.GetFullName());
|
||||||
|
|
||||||
// write to the SVG file
|
// write to the SVG file
|
||||||
const wxCharBuffer buf = s.utf8_str();
|
const wxCharBuffer buf = s.utf8_str();
|
||||||
@@ -1111,7 +1111,7 @@ void wxSVGFileDCImpl::DoDrawBitmap(const class wxBitmap & bmp, wxCoord x, wxCoor
|
|||||||
|
|
||||||
// If we don't have any bitmap handler yet, use the default one.
|
// If we don't have any bitmap handler yet, use the default one.
|
||||||
if ( !m_bmp_handler )
|
if ( !m_bmp_handler )
|
||||||
m_bmp_handler.reset(new wxSVGBitmapFileHandler());
|
m_bmp_handler.reset(new wxSVGBitmapFileHandler(m_filename));
|
||||||
|
|
||||||
m_bmp_handler->ProcessBitmap(bmp, x, y, *m_outfile);
|
m_bmp_handler->ProcessBitmap(bmp, x, y, *m_outfile);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user