Make wxConvFile safe to use during static initialization phase wxConvFileName may not be initialized yet and there is nothing we can do about this because it has to remain a simple variable to allow setting it. However we can change wxConvFile and wxFNCONV to use wxGetFileNameConv() accessor function which ensures that we initialize wxConvFileName before using it at least via these functions. Also update a couple of direct references to wxConvFileName in the code which might conceivably be used at this stage.
Fix using wxStandardPaths during static initialization phase Static gs_stdPaths variable may not be initialized yet at this stage and so an invalid wxStandardPaths object could be created. Fix this by simply making this global variable static in the only function using it -- it doesn't need to be global at all and this ensures that it's initialized before use.
Fix bug with broken AUI sash drag in some layout Don't end the AUI resize action when the new size can't be computed, as can happen for a perfectly ordinary layout: it's enough to have a resizable pane followed in its dock by a fixed one. This is the case for the panes in the bottom row of the "aui" sample itself, after all panes are shown using the corresponding "Perspectives" menu item. This fixes a serious user-visible problem as mouse renamed captured forever and the application was left with the resize cursor and with keyboard input going to the capturing window. Add a unit test checking for this problem: without the fix in this commit, "stillCaptured" remained true in it. Closes #27025. Co-authored-by: Vadim Zeitlin <va...@wxwidgets.org>
Add basic wxSVGFileDC unit tests Add them directly to test_gui instead of using a separate test as before to keep things simple. Closes #27022.
Merge branch 'fix-static-init-problems' Fix static initialization problems. See #27039. Closes #27038.
| ... | ... | @@ -25,6 +25,7 @@ set(TEST_GUI_SRC |
| 25 | 25 | graphics/clipper.cpp
|
| 26 | 26 | graphics/clippingbox.cpp
|
| 27 | 27 | graphics/svgattributes.cpp
|
| 28 | + graphics/svgfiledc.cpp
|
|
| 28 | 29 | graphics/coords.cpp
|
| 29 | 30 | graphics/graphbitmap.cpp
|
| 30 | 31 | graphics/graphmatrix.cpp
|
| ... | ... | @@ -627,12 +627,23 @@ WX_DECLARE_GLOBAL_CONV(wxWhateverWorksConv, wxConvWhateverWorks) |
| 627 | 627 | //
|
| 628 | 628 | // this is used by all file functions, can be changed by the application
|
| 629 | 629 | //
|
| 630 | +// Don't access this variable directly, use wxGetFileNameConv() to ensure that
|
|
| 631 | +// it is initialized before use.
|
|
| 632 | +//
|
|
| 630 | 633 | // by default UTF-8 under Mac OS X and wxConvLibc elsewhere (but it's not used
|
| 631 | 634 | // under Windows normally)
|
| 632 | 635 | extern WXDLLIMPEXP_DATA_BASE(wxMBConv *) wxConvFileName;
|
| 633 | 636 | |
| 637 | +extern WXDLLIMPEXP_BASE wxMBConv* wxGetFileNameConvPtr();
|
|
| 638 | +inline wxMBConv& wxGetFileNameConv()
|
|
| 639 | +{
|
|
| 640 | + if ( !wxConvFileName )
|
|
| 641 | + wxConvFileName = wxGetFileNameConvPtr();
|
|
| 642 | + return *wxConvFileName;
|
|
| 643 | +}
|
|
| 644 | + |
|
| 634 | 645 | // backwards compatible define
|
| 635 | -#define wxConvFile (*wxConvFileName)
|
|
| 646 | +#define wxConvFile (wxGetFileNameConv())
|
|
| 636 | 647 | |
| 637 | 648 | // the current conversion object, may be set to any conversion, is used by
|
| 638 | 649 | // default in a couple of places inside wx (initially same as wxConvLibc)
|
| ... | ... | @@ -668,11 +679,11 @@ extern WXDLLIMPEXP_DATA_BASE(wxMBConv *) wxConvUI; |
| 668 | 679 | |
| 669 | 680 | // filenames are multibyte on Unix and widechar on Windows
|
| 670 | 681 | #if wxMBFILES
|
| 671 | - #define wxFNCONV(name) wxConvFileName->cWX2MB(name)
|
|
| 682 | + #define wxFNCONV(name) wxGetFileNameConv().cWX2MB(name)
|
|
| 672 | 683 | #define wxFNSTRINGCAST wxMBSTRINGCAST
|
| 673 | 684 | #else
|
| 674 | 685 | #if defined(__WXOSX__) && wxMBFILES
|
| 675 | - #define wxFNCONV(name) wxConvFileName->cWC2MB( wxConvLocal.cWX2WC(name) )
|
|
| 686 | + #define wxFNCONV(name) wxGetFileNameConv().cWC2MB( wxConvLocal.cWX2WC(name) )
|
|
| 676 | 687 | #else
|
| 677 | 688 | #define wxFNCONV(name) name
|
| 678 | 689 | #endif
|
| ... | ... | @@ -5239,10 +5239,7 @@ bool wxAuiManager::DoEndResizeAction(wxMouseEvent& event) |
| 5239 | 5239 | |
| 5240 | 5240 | // prevent division by zero
|
| 5241 | 5241 | if (dock_pixels == 0 || total_proportion == 0 || borrow_pane == -1)
|
| 5242 | - {
|
|
| 5243 | - m_action = actionNone;
|
|
| 5244 | 5242 | return false;
|
| 5245 | - }
|
|
| 5246 | 5243 | |
| 5247 | 5244 | // calculate the new proportion of the pane
|
| 5248 | 5245 | int new_proportion = (new_pixsize*total_proportion)/dock_pixels;
|
| ... | ... | @@ -156,7 +156,7 @@ void wxInitData::Initialize(int argcIn, char **argvIn) |
| 156 | 156 | for ( int i = 0; i < argcIn; i++ )
|
| 157 | 157 | {
|
| 158 | 158 | #ifdef __DARWIN__
|
| 159 | - wxWCharBuffer buf(wxConvFileName->cMB2WX(argvIn[i]));
|
|
| 159 | + wxWCharBuffer buf(wxGetFileNameConv().cMB2WX(argvIn[i]));
|
|
| 160 | 160 | #else
|
| 161 | 161 | wxWCharBuffer buf(wxConvLocal.cMB2WX(argvIn[i]));
|
| 162 | 162 | #endif
|
| ... | ... | @@ -44,8 +44,6 @@ public: |
| 44 | 44 | wxStandardPathsDefault() { }
|
| 45 | 45 | };
|
| 46 | 46 | |
| 47 | -static wxStandardPathsDefault gs_stdPaths;
|
|
| 48 | - |
|
| 49 | 47 | } // anonymous namespace
|
| 50 | 48 | |
| 51 | 49 | // ============================================================================
|
| ... | ... | @@ -79,7 +77,9 @@ wxString wxStandardPathsBase::GetExecutablePath() const |
| 79 | 77 | |
| 80 | 78 | wxStandardPaths& wxAppTraitsBase::GetStandardPaths()
|
| 81 | 79 | {
|
| 82 | - return gs_stdPaths;
|
|
| 80 | + static wxStandardPathsDefault s_stdPaths;
|
|
| 81 | + |
|
| 82 | + return s_stdPaths;
|
|
| 83 | 83 | }
|
| 84 | 84 | |
| 85 | 85 | wxStandardPathsBase::wxStandardPathsBase()
|
| ... | ... | @@ -3430,16 +3430,18 @@ WX_DEFINE_GLOBAL_CONV(wxCSConv, wxConvISO8859_1, (wxFONTENCODING_ISO8859_1)); |
| 3430 | 3430 | WXDLLIMPEXP_DATA_BASE(wxMBConv *) wxConvCurrent = wxGet_wxConvLibcPtr();
|
| 3431 | 3431 | WXDLLIMPEXP_DATA_BASE(wxMBConv *) wxConvUI = wxGet_wxConvLocalPtr();
|
| 3432 | 3432 | |
| 3433 | -#ifdef __DARWIN__
|
|
| 3434 | -// It is important to use this conversion object under Darwin as it ensures
|
|
| 3435 | -// that Unicode strings are (re)composed correctly even though xnu kernel uses
|
|
| 3436 | -// decomposed form internally (at least for the file names).
|
|
| 3437 | -static wxMBConvD_cf wxConvMacUTF8DObj(wxFONTENCODING_UTF8);
|
|
| 3438 | -#endif
|
|
| 3433 | +WXDLLIMPEXP_DATA_BASE(wxMBConv *) wxConvFileName = nullptr;
|
|
| 3439 | 3434 | |
| 3440 | -WXDLLIMPEXP_DATA_BASE(wxMBConv *) wxConvFileName =
|
|
| 3435 | +wxMBConv* wxGetFileNameConvPtr()
|
|
| 3436 | +{
|
|
| 3441 | 3437 | #ifdef __DARWIN__
|
| 3442 | - &wxConvMacUTF8DObj;
|
|
| 3438 | + // It is important to use this conversion object under Darwin as it ensures
|
|
| 3439 | + // that Unicode strings are (re)composed correctly even though xnu kernel uses
|
|
| 3440 | + // decomposed form internally (at least for the file names).
|
|
| 3441 | + static wxMBConvD_cf wxConvMacUTF8DObj(wxFONTENCODING_UTF8);
|
|
| 3442 | + |
|
| 3443 | + return &wxConvMacUTF8DObj;
|
|
| 3443 | 3444 | #else // !__DARWIN__
|
| 3444 | - wxGet_wxConvWhateverWorksPtr();
|
|
| 3445 | + return wxGet_wxConvWhateverWorksPtr();
|
|
| 3445 | 3446 | #endif // __DARWIN__/!__DARWIN__
|
| 3447 | +} |
| ... | ... | @@ -127,7 +127,7 @@ bool wxDirData::Read(wxString *filename) |
| 127 | 127 | if ( !de )
|
| 128 | 128 | return false;
|
| 129 | 129 | |
| 130 | - de_d_name = wxString(de->d_name, *wxConvFileName);
|
|
| 130 | + de_d_name = wxString(de->d_name, wxGetFileNameConv());
|
|
| 131 | 131 | |
| 132 | 132 | // don't return "." and ".." unless asked for
|
| 133 | 133 | if ( de->d_name[0] == '.' &&
|
| ... | ... | @@ -171,6 +171,7 @@ TEST_GUI_OBJECTS = \ |
| 171 | 171 | test_gui_clipper.o \
|
| 172 | 172 | test_gui_clippingbox.o \
|
| 173 | 173 | test_gui_svgattributes.o \
|
| 174 | + test_gui_svgfiledc.o \
|
|
| 174 | 175 | test_gui_coords.o \
|
| 175 | 176 | test_gui_graphbitmap.o \
|
| 176 | 177 | test_gui_graphmatrix.o \
|
| ... | ... | @@ -940,6 +941,9 @@ test_gui_clippingbox.o: $(srcdir)/graphics/clippingbox.cpp $(TEST_GUI_ODEP) |
| 940 | 941 | test_gui_svgattributes.o: $(srcdir)/graphics/svgattributes.cpp $(TEST_GUI_ODEP)
|
| 941 | 942 | $(CXXC) -c -o $@ $(TEST_GUI_CXXFLAGS) $(srcdir)/graphics/svgattributes.cpp
|
| 942 | 943 | |
| 944 | +test_gui_svgfiledc.o: $(srcdir)/graphics/svgfiledc.cpp $(TEST_GUI_ODEP)
|
|
| 945 | + $(CXXC) -c -o $@ $(TEST_GUI_CXXFLAGS) $(srcdir)/graphics/svgfiledc.cpp
|
|
| 946 | + |
|
| 943 | 947 | test_gui_coords.o: $(srcdir)/graphics/coords.cpp $(TEST_GUI_ODEP)
|
| 944 | 948 | $(CXXC) -c -o $@ $(TEST_GUI_CXXFLAGS) $(srcdir)/graphics/coords.cpp
|
| 945 | 949 |
| ... | ... | @@ -83,6 +83,12 @@ public: |
| 83 | 83 | }
|
| 84 | 84 | |
| 85 | 85 | void ClickWithoutMoving(wxAuiDockUIPart* part)
|
| 86 | + {
|
|
| 87 | + DragBy(part, wxPoint());
|
|
| 88 | + }
|
|
| 89 | + |
|
| 90 | + // Simulate a complete drag of the given sash by the given offset.
|
|
| 91 | + void DragBy(wxAuiDockUIPart* part, const wxPoint& offset)
|
|
| 86 | 92 | {
|
| 87 | 93 | const wxPoint pos = part->rect.GetPosition() +
|
| 88 | 94 | wxPoint(part->rect.GetWidth()/2, part->rect.GetHeight()/2);
|
| ... | ... | @@ -93,13 +99,13 @@ public: |
| 93 | 99 | OnLeftDown(down);
|
| 94 | 100 | |
| 95 | 101 | wxMouseEvent motion(wxEVT_MOTION);
|
| 96 | - motion.m_x = pos.x;
|
|
| 97 | - motion.m_y = pos.y;
|
|
| 102 | + motion.m_x = pos.x + offset.x;
|
|
| 103 | + motion.m_y = pos.y + offset.y;
|
|
| 98 | 104 | OnMotion(motion);
|
| 99 | 105 | |
| 100 | 106 | wxMouseEvent up(wxEVT_LEFT_UP);
|
| 101 | - up.m_x = pos.x;
|
|
| 102 | - up.m_y = pos.y;
|
|
| 107 | + up.m_x = pos.x + offset.x;
|
|
| 108 | + up.m_y = pos.y + offset.y;
|
|
| 103 | 109 | OnLeftUp(up);
|
| 104 | 110 | }
|
| 105 | 111 | };
|
| ... | ... | @@ -201,6 +207,39 @@ TEST_CASE_METHOD(AuiManagerTestCase, "wxAuiManager::SizerClick", "[aui]") |
| 201 | 207 | CHECK( manager.GetPane(second).dock_proportion == secondProportion );
|
| 202 | 208 | }
|
| 203 | 209 | |
| 210 | +TEST_CASE_METHOD(AuiManagerTestCase, "wxAuiManager::SizerDragReleasesMouse", "[aui]")
|
|
| 211 | +{
|
|
| 212 | + // Use a dock in which the resizable pane is followed by a fixed one: there
|
|
| 213 | + // is then no pane after it to take the space from and DoEndResizeAction()
|
|
| 214 | + // gives up -- but this must still not leave the mouse captured once the
|
|
| 215 | + // drag is over.
|
|
| 216 | + wxWindow* const first = new wxPanel(frame.get());
|
|
| 217 | + wxWindow* const second = new wxPanel(frame.get());
|
|
| 218 | + wxWindow* const center = new wxPanel(frame.get());
|
|
| 219 | + |
|
| 220 | + REQUIRE( manager.AddPane(first, wxAuiPaneInfo().Top().
|
|
| 221 | + MinSize(200, 100).CaptionVisible(false).PaneBorder(false)) );
|
|
| 222 | + REQUIRE( manager.AddPane(second, wxAuiPaneInfo().Top().Fixed().
|
|
| 223 | + MinSize(200, 100).CaptionVisible(false).PaneBorder(false)) );
|
|
| 224 | + REQUIRE( manager.AddPane(center, wxAuiPaneInfo().CenterPane()) );
|
|
| 225 | + |
|
| 226 | + manager.Update();
|
|
| 227 | + |
|
| 228 | + wxAuiDockUIPart* const sizer = manager.FindPaneSizer();
|
|
| 229 | + REQUIRE( sizer );
|
|
| 230 | + |
|
| 231 | + manager.DragBy(sizer, wxPoint(20, 0));
|
|
| 232 | + |
|
| 233 | + const bool stillCaptured = wxWindow::GetCapture() == frame.get();
|
|
| 234 | + |
|
| 235 | + // Don't let the rest of the tests run with the mouse captured even if the
|
|
| 236 | + // check below fails.
|
|
| 237 | + if ( stillCaptured )
|
|
| 238 | + frame->ReleaseMouse();
|
|
| 239 | + |
|
| 240 | + CHECK( !stillCaptured );
|
|
| 241 | +}
|
|
| 242 | + |
|
| 204 | 243 | TEST_CASE_METHOD(AuiNotebookTestCase, "wxAuiNotebook::DoGetBestSize", "[aui]")
|
| 205 | 244 | {
|
| 206 | 245 | wxPanel *p = new wxPanel(nb.get());
|
| 1 | +///////////////////////////////////////////////////////////////////////////////
|
|
| 2 | +// Name: tests/graphics/svgfiledc.cpp
|
|
| 3 | +// Purpose: wxSVGFileDC unit tests
|
|
| 4 | +// Author: Blake Madden
|
|
| 5 | +// Created: 2026-09-18
|
|
| 6 | +// Copyright: (c) Blake Madden
|
|
| 7 | +// Licence: wxWindows licence
|
|
| 8 | +///////////////////////////////////////////////////////////////////////////////
|
|
| 9 | + |
|
| 10 | +#include "testprec.h"
|
|
| 11 | + |
|
| 12 | +#if wxUSE_SVG
|
|
| 13 | + |
|
| 14 | +#include "wx/dcsvg.h"
|
|
| 15 | +#include "wx/ffile.h"
|
|
| 16 | + |
|
| 17 | +#include "testfile.h"
|
|
| 18 | + |
|
| 19 | +namespace
|
|
| 20 | +{
|
|
| 21 | + |
|
| 22 | +wxSVGFileDC MakeDC(int width = 200, int height = 100)
|
|
| 23 | +{
|
|
| 24 | + return wxSVGFileDC(wxString{}, width, height);
|
|
| 25 | +}
|
|
| 26 | + |
|
| 27 | +} // namespace
|
|
| 28 | + |
|
| 29 | +TEST_CASE("wxSVGFileDC::Ctor", "[svg][dcsvg]")
|
|
| 30 | +{
|
|
| 31 | + wxSVGFileDC dc(wxString{}, 320, 240);
|
|
| 32 | + |
|
| 33 | + CHECK( dc.IsOk() );
|
|
| 34 | + |
|
| 35 | + wxSize size = dc.GetSize();
|
|
| 36 | + CHECK( size.GetWidth() == 320 );
|
|
| 37 | + CHECK( size.GetHeight() == 240 );
|
|
| 38 | + |
|
| 39 | + const std::string svg = dc.GetSVGDocument().utf8_string();
|
|
| 40 | + CHECK_THAT( svg, Catch::StartsWith("<?xml") );
|
|
| 41 | + CHECK_THAT( svg, Catch::Contains("<svg") );
|
|
| 42 | + CHECK_THAT( svg, Catch::Contains("viewBox=\"0 0 320 240\"") );
|
|
| 43 | + CHECK_THAT( svg, Catch::Contains("</svg>") );
|
|
| 44 | +}
|
|
| 45 | + |
|
| 46 | +TEST_CASE("wxSVGFileDC::Title", "[svg][dcsvg]")
|
|
| 47 | +{
|
|
| 48 | + wxSVGFileDC dc(wxString{}, 100, 100, wxSVG_DEFAULT_DPI, "My Drawing");
|
|
| 49 | + |
|
| 50 | + CHECK_THAT( dc.GetSVGDocument().utf8_string(), Catch::Contains("<title>My Drawing</title>") );
|
|
| 51 | +}
|
|
| 52 | + |
|
| 53 | +TEST_CASE("wxSVGFileDC::DrawLine", "[svg][dcsvg]")
|
|
| 54 | +{
|
|
| 55 | + wxSVGFileDC dc = MakeDC();
|
|
| 56 | + dc.SetPen(wxPen{ *wxRED, 2 });
|
|
| 57 | + |
|
| 58 | + dc.DrawLine(10, 20, 110, 20);
|
|
| 59 | + |
|
| 60 | + const std::string svg = dc.GetSVGDocument().utf8_string();
|
|
| 61 | + CHECK_THAT( svg, Catch::Contains("<path d=\"M10 20 L110 20\"") );
|
|
| 62 | + CHECK_THAT( svg, Catch::Contains("stroke=\"#FF0000\"") );
|
|
| 63 | + CHECK_THAT( svg, Catch::Contains("stroke-width=\"2\"") );
|
|
| 64 | +}
|
|
| 65 | + |
|
| 66 | +TEST_CASE("wxSVGFileDC::DrawRectangle", "[svg][dcsvg]")
|
|
| 67 | +{
|
|
| 68 | + wxSVGFileDC dc = MakeDC();
|
|
| 69 | + dc.SetPen(wxPen{ *wxRED, 1 });
|
|
| 70 | + dc.SetBrush(*wxBLUE_BRUSH);
|
|
| 71 | + |
|
| 72 | + dc.DrawRectangle(10, 10, 50, 30);
|
|
| 73 | + |
|
| 74 | + const std::string svg = dc.GetSVGDocument().utf8_string();
|
|
| 75 | + CHECK_THAT( svg, Catch::Contains("<rect x=\"10\" y=\"10\" width=\"50\" height=\"30\"") );
|
|
| 76 | + CHECK_THAT( svg, Catch::Contains("fill=\"#0000FF\"") );
|
|
| 77 | + CHECK_THAT( svg, Catch::Contains("stroke=\"#FF0000\"") );
|
|
| 78 | +}
|
|
| 79 | + |
|
| 80 | +TEST_CASE("wxSVGFileDC::DrawEllipse", "[svg][dcsvg]")
|
|
| 81 | +{
|
|
| 82 | + wxSVGFileDC dc = MakeDC();
|
|
| 83 | + dc.SetBrush(*wxGREEN_BRUSH);
|
|
| 84 | + |
|
| 85 | + dc.DrawEllipse(0, 0, 40, 20);
|
|
| 86 | + |
|
| 87 | + const std::string svg = dc.GetSVGDocument().utf8_string();
|
|
| 88 | + CHECK_THAT( svg, Catch::Contains("<ellipse cx=\"20.00\" cy=\"10.00\" rx=\"20.00\" ry=\"10.00\"") );
|
|
| 89 | + CHECK_THAT( svg, Catch::Contains("fill=\"#00FF00\"") );
|
|
| 90 | +}
|
|
| 91 | + |
|
| 92 | +TEST_CASE("wxSVGFileDC::DrawPolygon", "[svg][dcsvg]")
|
|
| 93 | +{
|
|
| 94 | + wxSVGFileDC dc = MakeDC();
|
|
| 95 | + dc.SetBrush(*wxCYAN_BRUSH);
|
|
| 96 | + |
|
| 97 | + const wxPoint points[3] = { wxPoint{0, 0}, wxPoint{10, 0}, wxPoint{5, 10} };
|
|
| 98 | + dc.DrawPolygon(3, points);
|
|
| 99 | + |
|
| 100 | + const std::string svg = dc.GetSVGDocument().utf8_string();
|
|
| 101 | + CHECK_THAT( svg, Catch::Contains("<polygon points=\"0 0 10 0 5 10 \"") );
|
|
| 102 | + CHECK_THAT( svg, Catch::Contains("fill=\"#00FFFF\"") );
|
|
| 103 | + CHECK_THAT( svg, Catch::Contains("fill-rule=\"evenodd\"") );
|
|
| 104 | +}
|
|
| 105 | + |
|
| 106 | +TEST_CASE("wxSVGFileDC::DrawText", "[svg][dcsvg]")
|
|
| 107 | +{
|
|
| 108 | + wxSVGFileDC dc = MakeDC();
|
|
| 109 | + |
|
| 110 | + dc.DrawText("Hello SVG", 5, 5);
|
|
| 111 | + |
|
| 112 | + const std::string svg = dc.GetSVGDocument().utf8_string();
|
|
| 113 | + CHECK_THAT( svg, Catch::Contains("<text ") );
|
|
| 114 | + CHECK_THAT( svg, Catch::Contains(">Hello SVG</text>") );
|
|
| 115 | +}
|
|
| 116 | + |
|
| 117 | +TEST_CASE("wxSVGFileDC::DrawRotatedText", "[svg][dcsvg]")
|
|
| 118 | +{
|
|
| 119 | + wxSVGFileDC dc = MakeDC();
|
|
| 120 | + |
|
| 121 | + dc.DrawRotatedText("Angled", 5, 5, 45.0);
|
|
| 122 | + |
|
| 123 | + const std::string svg = dc.GetSVGDocument().utf8_string();
|
|
| 124 | + CHECK_THAT( svg, Catch::Contains(">Angled</text>") );
|
|
| 125 | + CHECK_THAT( svg, Catch::Contains("rotate(-45.00") );
|
|
| 126 | +}
|
|
| 127 | + |
|
| 128 | +TEST_CASE("wxSVGFileDC::AccessibleGroup", "[svg][dcsvg]")
|
|
| 129 | +{
|
|
| 130 | + wxSVGFileDC dc = MakeDC();
|
|
| 131 | + |
|
| 132 | + wxSVGAttributes attr;
|
|
| 133 | + attr.Role("img").AriaLabel("A red square");
|
|
| 134 | + |
|
| 135 | + dc.BeginAccessibleGroup(attr, "Square", "A simple red square");
|
|
| 136 | + dc.SetBrush(*wxRED_BRUSH);
|
|
| 137 | + dc.DrawRectangle(0, 0, 10, 10);
|
|
| 138 | + dc.EndAccessibleGroup();
|
|
| 139 | + |
|
| 140 | + const std::string svg = dc.GetSVGDocument().utf8_string();
|
|
| 141 | + CHECK_THAT( svg, Catch::Contains("role=\"img\"") );
|
|
| 142 | + CHECK_THAT( svg, Catch::Contains("aria-label=\"A red square\"") );
|
|
| 143 | + CHECK_THAT( svg, Catch::Contains("<title>Square</title>") );
|
|
| 144 | + CHECK_THAT( svg, Catch::Contains("<desc>A simple red square</desc>") );
|
|
| 145 | +}
|
|
| 146 | + |
|
| 147 | +TEST_CASE("wxSVGFileDC::Layer", "[svg][dcsvg]")
|
|
| 148 | +{
|
|
| 149 | + wxSVGFileDC dc = MakeDC();
|
|
| 150 | + |
|
| 151 | + dc.BeginLayer(0.5);
|
|
| 152 | + dc.SetBrush(*wxBLUE_BRUSH);
|
|
| 153 | + dc.DrawRectangle(0, 0, 10, 10);
|
|
| 154 | + dc.EndLayer();
|
|
| 155 | + |
|
| 156 | + const std::string svg = dc.GetSVGDocument().utf8_string();
|
|
| 157 | + CHECK_THAT( svg, Catch::Contains("<g opacity=\"0.50\">") );
|
|
| 158 | + CHECK_THAT( svg, Catch::Contains("fill=\"#0000FF\"") );
|
|
| 159 | +}
|
|
| 160 | + |
|
| 161 | +TEST_CASE("wxSVGFileDC::Clipping", "[svg][dcsvg]")
|
|
| 162 | +{
|
|
| 163 | + wxSVGFileDC dc = MakeDC();
|
|
| 164 | + |
|
| 165 | + dc.SetClippingRegion(10, 10, 50, 50);
|
|
| 166 | + dc.SetBrush(*wxRED_BRUSH);
|
|
| 167 | + dc.DrawRectangle(0, 0, 100, 100);
|
|
| 168 | + dc.DestroyClippingRegion();
|
|
| 169 | + |
|
| 170 | + const std::string svg = dc.GetSVGDocument().utf8_string();
|
|
| 171 | + CHECK_THAT( svg, Catch::Contains("<clipPath id=\"clip") );
|
|
| 172 | + CHECK_THAT( svg, Catch::Contains("clip-path=\"url(#clip") );
|
|
| 173 | + CHECK_THAT( svg, Catch::Contains("x=\"10\" y=\"10\" width=\"50\" height=\"50\"") );
|
|
| 174 | +}
|
|
| 175 | + |
|
| 176 | +TEST_CASE("wxSVGFileDC::Save", "[svg][dcsvg]")
|
|
| 177 | +{
|
|
| 178 | + TestFile file;
|
|
| 179 | + const wxString filename = file.GetName();
|
|
| 180 | + |
|
| 181 | + {
|
|
| 182 | + wxSVGFileDC dc{ filename, 50, 50 };
|
|
| 183 | + dc.SetBrush(*wxYELLOW_BRUSH);
|
|
| 184 | + dc.DrawRectangle(0, 0, 20, 20);
|
|
| 185 | + |
|
| 186 | + REQUIRE( dc.Save() );
|
|
| 187 | + }
|
|
| 188 | + |
|
| 189 | + wxString content;
|
|
| 190 | + REQUIRE( wxFFile{ filename, "r" }.ReadAll(&content) );
|
|
| 191 | + |
|
| 192 | + const std::string svg = content.utf8_string();
|
|
| 193 | + CHECK_THAT( svg, Catch::Contains("<svg") );
|
|
| 194 | + CHECK_THAT( svg, Catch::Contains("fill=\"#FFFF00\"") );
|
|
| 195 | +}
|
|
| 196 | + |
|
| 197 | +#endif // wxUSE_SVG |
| ... | ... | @@ -145,6 +145,7 @@ TEST_GUI_OBJECTS = \ |
| 145 | 145 | $(OBJS)\test_gui_clipper.o \
|
| 146 | 146 | $(OBJS)\test_gui_clippingbox.o \
|
| 147 | 147 | $(OBJS)\test_gui_svgattributes.o \
|
| 148 | + $(OBJS)\test_gui_svgfiledc.o \
|
|
| 148 | 149 | $(OBJS)\test_gui_coords.o \
|
| 149 | 150 | $(OBJS)\test_gui_graphbitmap.o \
|
| 150 | 151 | $(OBJS)\test_gui_graphmatrix.o \
|
| ... | ... | @@ -878,6 +879,9 @@ $(OBJS)\test_gui_clippingbox.o: ./graphics/clippingbox.cpp |
| 878 | 879 | $(OBJS)\test_gui_svgattributes.o: ./graphics/svgattributes.cpp
|
| 879 | 880 | $(CXX) -c -o $@ $(TEST_GUI_CXXFLAGS) $(CPPDEPS) $<
|
| 880 | 881 | |
| 882 | +$(OBJS)\test_gui_svgfiledc.o: ./graphics/svgfiledc.cpp
|
|
| 883 | + $(CXX) -c -o $@ $(TEST_GUI_CXXFLAGS) $(CPPDEPS) $<
|
|
| 884 | + |
|
| 881 | 885 | $(OBJS)\test_gui_coords.o: ./graphics/coords.cpp
|
| 882 | 886 | $(CXX) -c -o $@ $(TEST_GUI_CXXFLAGS) $(CPPDEPS) $<
|
| 883 | 887 |
| ... | ... | @@ -152,6 +152,7 @@ TEST_GUI_OBJECTS = \ |
| 152 | 152 | $(OBJS)\test_gui_clipper.obj \
|
| 153 | 153 | $(OBJS)\test_gui_clippingbox.obj \
|
| 154 | 154 | $(OBJS)\test_gui_svgattributes.obj \
|
| 155 | + $(OBJS)\test_gui_svgfiledc.obj \
|
|
| 155 | 156 | $(OBJS)\test_gui_coords.obj \
|
| 156 | 157 | $(OBJS)\test_gui_graphbitmap.obj \
|
| 157 | 158 | $(OBJS)\test_gui_graphmatrix.obj \
|
| ... | ... | @@ -1165,6 +1166,9 @@ $(OBJS)\test_gui_clippingbox.obj: .\graphics\clippingbox.cpp |
| 1165 | 1166 | $(OBJS)\test_gui_svgattributes.obj: .\graphics\svgattributes.cpp
|
| 1166 | 1167 | $(CXX) /c /nologo /TP /Fo$@ $(TEST_GUI_CXXFLAGS) .\graphics\svgattributes.cpp
|
| 1167 | 1168 | |
| 1169 | +$(OBJS)\test_gui_svgfiledc.obj: .\graphics\svgfiledc.cpp
|
|
| 1170 | + $(CXX) /c /nologo /TP /Fo$@ $(TEST_GUI_CXXFLAGS) .\graphics\svgfiledc.cpp
|
|
| 1171 | + |
|
| 1168 | 1172 | $(OBJS)\test_gui_coords.obj: .\graphics\coords.cpp
|
| 1169 | 1173 | $(CXX) /c /nologo /TP /Fo$@ $(TEST_GUI_CXXFLAGS) .\graphics\coords.cpp
|
| 1170 | 1174 |
| ... | ... | @@ -167,6 +167,7 @@ |
| 167 | 167 | graphics/clipper.cpp
|
| 168 | 168 | graphics/clippingbox.cpp
|
| 169 | 169 | graphics/svgattributes.cpp
|
| 170 | + graphics/svgfiledc.cpp
|
|
| 170 | 171 | graphics/coords.cpp
|
| 171 | 172 | graphics/graphbitmap.cpp
|
| 172 | 173 | graphics/graphmatrix.cpp
|
| ... | ... | @@ -1002,6 +1002,7 @@ |
| 1002 | 1002 | <ClCompile Include="graphics\clipper.cpp" />
|
| 1003 | 1003 | <ClCompile Include="graphics\clippingbox.cpp" />
|
| 1004 | 1004 | <ClCompile Include="graphics\svgattributes.cpp" />
|
| 1005 | + <ClCompile Include="graphics\svgfiledc.cpp" />
|
|
| 1005 | 1006 | <ClCompile Include="graphics\coords.cpp" />
|
| 1006 | 1007 | <ClCompile Include="graphics\graphbitmap.cpp" />
|
| 1007 | 1008 | <ClCompile Include="graphics\graphmatrix.cpp" />
|
| ... | ... | @@ -320,6 +320,9 @@ |
| 320 | 320 | <ClCompile Include="graphics\svgattributes.cpp">
|
| 321 | 321 | <Filter>Source Files</Filter>
|
| 322 | 322 | </ClCompile>
|
| 323 | + <ClCompile Include="graphics\svgfiledc.cpp">
|
|
| 324 | + <Filter>Source Files</Filter>
|
|
| 325 | + </ClCompile>
|
|
| 323 | 326 | <ClCompile Include="graphics\coords.cpp">
|
| 324 | 327 | <Filter>Source Files</Filter>
|
| 325 | 328 | </ClCompile>
|
—
View it on GitLab.
You're receiving this email because of your account on gitlab.com. Manage all notifications · Help