Add additional wxBitmapBundle::FromSVG() overload

This overload can work on non 0 terminated unsigned char arrays.
Especially useful for headers created by bin2c.py
This commit is contained in:
Tobias Taschner 2022-01-28 09:55:55 +01:00 committed by Tobias Taschner
parent ae7fa19ae3
commit f256e5ae59
No known key found for this signature in database
GPG Key ID: AE6ECD71294F87FD
3 changed files with 13 additions and 1 deletions

View File

@ -76,6 +76,9 @@ public:
// This overload currently makes a copy of the data.
static wxBitmapBundle FromSVG(const char* data, const wxSize& sizeDef);
// This overload works for data not terminated with 0
static wxBitmapBundle FromSVG(const wxByte* data, size_t len, const wxSize& sizeDef);
// Load SVG image from the given file (must be a local file, not an URL).
static wxBitmapBundle FromSVGFile(const wxString& path, const wxSize& sizeDef);

View File

@ -279,7 +279,7 @@ wxDefaultArtProvider::CreateBitmapBundle(const wxArtID& id,
sizeDef = wxSize(16, 16);
}
bb = wxBitmapBundle::FromSVG((const char*)wxlogo_svg_data, sizeDef);
bb = wxBitmapBundle::FromSVG(wxlogo_svg_data, sizeof(wxlogo_svg_data), sizeDef);
}
#else // !wxHAS_SVG
wxUnusedVar(id);

View File

@ -218,6 +218,15 @@ wxBitmapBundle wxBitmapBundle::FromSVG(const char* data, const wxSize& sizeDef)
return FromSVG(copy.data(), sizeDef);
}
/* static */
wxBitmapBundle wxBitmapBundle::FromSVG(const wxByte* data, size_t len, const wxSize& sizeDef)
{
wxCharBuffer copy(len);
memcpy(copy.data(), data, len);
return FromSVG(copy.data(), sizeDef);
}
/* static */
wxBitmapBundle wxBitmapBundle::FromSVGFile(const wxString& path, const wxSize& sizeDef)
{