From 444c5fd6300aea8e4bb7d5aca78c3ffcbfa471ef Mon Sep 17 00:00:00 2001 From: Maarten Bent Date: Tue, 15 Mar 2016 20:36:55 +0100 Subject: [PATCH] Correctly draw poly-polygons in wxSVGFileDC. Each polygon in the poly-polygon needs to end with the start-point. The implementation is similar to the wxDCImpl implementation, except for the extra end points that are inserted. --- include/wx/dcsvg.h | 4 ++++ src/common/dcsvg.cpp | 43 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+) diff --git a/include/wx/dcsvg.h b/include/wx/dcsvg.h index aaab9475de..8a368f102d 100644 --- a/include/wx/dcsvg.h +++ b/include/wx/dcsvg.h @@ -169,6 +169,10 @@ private: wxCoord xoffset, wxCoord yoffset, wxPolygonFillMode fillStyle) wxOVERRIDE; + virtual void DoDrawPolyPolygon(int n, const int count[], const wxPoint points[], + wxCoord xoffset, wxCoord yoffset, + wxPolygonFillMode fillStyle) wxOVERRIDE; + virtual void DoDrawRectangle(wxCoord x, wxCoord y, wxCoord w, wxCoord h) wxOVERRIDE; virtual void DoDrawRotatedText(const wxString& text, wxCoord x, wxCoord y, diff --git a/src/common/dcsvg.cpp b/src/common/dcsvg.cpp index 2110200f1f..0446afeee2 100644 --- a/src/common/dcsvg.cpp +++ b/src/common/dcsvg.cpp @@ -29,6 +29,7 @@ #include "wx/wfstream.h" #include "wx/filename.h" #include "wx/mstream.h" +#include "wx/scopedarray.h" #include "wx/private/markupparser.h" @@ -496,6 +497,48 @@ void wxSVGFileDCImpl::DoDrawPolygon(int n, const wxPoint points[], write(s); } +void wxSVGFileDCImpl::DoDrawPolyPolygon(int n, const int count[], const wxPoint points[], + wxCoord xoffset, wxCoord yoffset, + wxPolygonFillMode fillStyle) +{ + if (n == 1) + { + DoDrawPolygon(count[0], points, xoffset, yoffset, fillStyle); + return; + } + + int i, j; + int totalPts = 0; + for (j = 0; j < n; ++j) + totalPts += count[j]; + + wxScopedArray pts(totalPts + n); + + int polyCounter = 0, polyIndex = 0; + for (i = j = 0; i < totalPts; ++i) + { + pts[j++] = points[i]; + ++polyCounter; + if (polyCounter == count[polyIndex]) + { + pts[j++] = points[i - count[polyIndex] + 1]; + ++polyIndex; + polyCounter = 0; + } + } + + { + wxDCPenChanger setTransp(*GetOwner(), *wxTRANSPARENT_PEN); + DoDrawPolygon(j, pts.get(), xoffset, yoffset, fillStyle); + } + + for (i = j = 0; i < n; i++) + { + DoDrawLines(count[i] + 1, pts.get() + j, xoffset, yoffset); + j += count[i] + 1; + } +} + void wxSVGFileDCImpl::DoDrawEllipse (wxCoord x, wxCoord y, wxCoord width, wxCoord height) {