Add wxHAS_SVG feature test macro

This is more clear and future-proof than using wxHAS_RAW_BITMAP for
checking for SVG availability.
This commit is contained in:
Vadim Zeitlin
2021-10-05 16:12:01 +01:00
parent 0216654272
commit fb4e188cea
6 changed files with 21 additions and 10 deletions

View File

@@ -209,6 +209,7 @@ Currently the following symbols exist:
@itemdef{wxHAS_REGEX_ADVANCED, Defined if advanced syntax is available in
wxRegEx. This is always the case in wxWidgets 3.1.6 and later, so this
symbol doesn't need to be tested any more.}
@itemdef{wxHAS_SVG, Defined if SVG support (currently only via wxBitmapBundle::FromSVG()) is available.}
@itemdef{wxHAS_TASK_BAR_ICON, Defined if wxTaskBarIcon is available on the current platform.}
@itemdef{wxHAS_WINDOW_LABEL_IN_STATIC_BOX, Defined if wxStaticBox::Create()
overload taking @c wxWindow* instead of the text label is available on the current platform.}

View File

@@ -16,6 +16,13 @@
class wxBitmapBundleImpl;
// It should be possible to implement SVG rasterizing without raw bitmap
// support using wxDC::DrawSpline(), but currently we don't do it and so
// FromSVG() is only available in the ports providing raw bitmap access.
#ifdef wxHAS_RAW_BITMAP
#define wxHAS_SVG
#endif
// ----------------------------------------------------------------------------
// wxBitmapBundle provides 1 or more versions of a bitmap, all bundled together
// ----------------------------------------------------------------------------
@@ -62,7 +69,7 @@ public:
// It should be possible to implement SVG rasterizing without raw bitmap
// support using wxDC::DrawSpline(), but currently we don't do it and so
// FromSVG() is only available in the ports providing raw bitmap access.
#ifdef wxHAS_RAW_BITMAP
#ifdef wxHAS_SVG
// Create from the SVG data (data is supposed to be in UTF-8 encoding).
// Notice that the data here is non-const because it can be temporarily
// modified while parsing it.
@@ -70,7 +77,7 @@ public:
// This overload currently makes a copy of the data.
static wxBitmapBundle FromSVG(const char* data, const wxSize sizeDef);
#endif // wxHAS_RAW_BITMAP
#endif // wxHAS_SVG
// Create from the resources: all existing versions of the bitmap of the
// form name_2x or name@2x (and also using other factors) will be used.

View File

@@ -203,9 +203,9 @@ public:
These limitations will be relaxed in the future wxWidgets versions.
Please also note that this method is only available in the ports
providing raw bitmap access via wxPixelData and so defining
wxHAS_RAW_BITMAP symbol. Currently SVG images are not supported in the
ports without it, e.g. wxX11.
providing raw bitmap access via wxPixelData. This is the case for all
tier-1 ports, but not all of them, check if @c wxHAS_SVG is defined
before using this method if for maximum portability.
@param data This data may, or not, have the XML document preamble, i.e.
it can start either with @c "<?xml" processing instruction or

View File

@@ -421,8 +421,10 @@ void MyFrame::PopulateToolbar(wxToolBarBase* toolBar)
const wxSize sizeBitmap = toolBarBitmaps[Tool_new].GetDefaultSize() *
(m_smallToolbar ? 1 : 2);
#ifdef wxHAS_SVG
// Use vector SVG image for this button for demonstration purposes.
toolBarBitmaps[Tool_about] = wxBitmapBundle::FromSVG(svg_data, sizeBitmap);
#endif // wxHAS_SVG
// Note that there is no need for FromDIP() here, wxMSW will adjust the
// size on its own and under the other platforms there is no need for

View File

@@ -19,13 +19,14 @@
// for compilers that support precompilation, includes "wx.h".
#include "wx/wxprec.h"
#ifdef wxHAS_RAW_BITMAP
#include "wx/bmpbndl.h"
#ifdef wxHAS_SVG
#ifndef WX_PRECOMP
#include "wx/utils.h" // Only for wxMin()
#endif // WX_PRECOMP
#include "wx/bmpbndl.h"
#include "wx/rawbmp.h"
#include "wx/private/bmpbndl.h"
@@ -180,4 +181,4 @@ wxBitmapBundle wxBitmapBundle::FromSVG(const char* data, const wxSize sizeDef)
return FromSVG(copy.data(), sizeDef);
}
#endif // wxHAS_RAW_BITMAP
#endif // wxHAS_SVG

View File

@@ -47,7 +47,7 @@ TEST_CASE("BitmapBundle::FromBitmaps", "[bmpbundle]")
CHECK( b.GetBitmap(wxSize(24, 24)).GetSize() == wxSize(24, 24) );
}
#ifdef wxHAS_RAW_BITMAP
#ifdef wxHAS_SVG
TEST_CASE("BitmapBundle::FromSVG", "[bmpbundle][svg]")
{
@@ -76,4 +76,4 @@ TEST_CASE("BitmapBundle::FromSVG", "[bmpbundle][svg]")
CHECK( b.GetBitmap(wxSize(16, 16)).GetSize() == wxSize(16, 16) );
}
#endif // wxHAS_RAW_BITMAP
#endif // wxHAS_SVG