Miscellaneous improvements to wxSVGFileDC, notably add gradient fill
support and shape rendering mode.

See https://github.com/wxWidgets/wxWidgets/pull/1493
This commit is contained in:
Vadim Zeitlin
2019-08-22 17:19:30 +02:00
3 changed files with 463 additions and 215 deletions

View File

@@ -11,16 +11,25 @@
#ifndef _WX_DCSVG_H_
#define _WX_DCSVG_H_
#if wxUSE_SVG
#include "wx/string.h"
#include "wx/filename.h"
#include "wx/dc.h"
#if wxUSE_SVG
#include "wx/scopedptr.h"
#define wxSVGVersion wxT("v0101")
enum wxSVGShapeRenderingMode
{
wxSVG_SHAPE_RENDERING_AUTO = 0,
wxSVG_SHAPE_RENDERING_OPTIMIZE_SPEED,
wxSVG_SHAPE_RENDERING_CRISP_EDGES,
wxSVG_SHAPE_RENDERING_GEOMETRIC_PRECISION,
wxSVG_SHAPE_RENDERING_OPTIMISE_SPEED = wxSVG_SHAPE_RENDERING_OPTIMIZE_SPEED
};
class WXDLLIMPEXP_FWD_BASE wxFileOutputStream;
class WXDLLIMPEXP_FWD_CORE wxSVGFileDC;
@@ -76,9 +85,9 @@ public:
class WXDLLIMPEXP_CORE wxSVGFileDCImpl : public wxDCImpl
{
public:
wxSVGFileDCImpl(wxSVGFileDC *owner, const wxString &filename,
wxSVGFileDCImpl(wxSVGFileDC* owner, const wxString& filename,
int width = 320, int height = 240, double dpi = 72.0,
const wxString &title = wxString());
const wxString& title = wxString());
virtual ~wxSVGFileDCImpl();
@@ -101,7 +110,7 @@ public:
virtual wxCoord GetCharWidth() const wxOVERRIDE;
#if wxUSE_PALETTE
virtual void SetPalette(const wxPalette& WXUNUSED(palette)) wxOVERRIDE
virtual void SetPalette(const wxPalette& WXUNUSED(palette)) wxOVERRIDE
{
wxFAIL_MSG(wxT("wxSVGFILEDC::SetPalette not implemented"));
}
@@ -136,7 +145,7 @@ public:
m_graphics_changed = true;
}
virtual void SetBackground(const wxBrush &brush) wxOVERRIDE;
virtual void SetBackground(const wxBrush& brush) wxOVERRIDE;
virtual void SetBackgroundMode(int mode) wxOVERRIDE;
virtual void SetBrush(const wxBrush& brush) wxOVERRIDE;
virtual void SetFont(const wxFont& font) wxOVERRIDE;
@@ -146,81 +155,102 @@ public:
void SetBitmapHandler(wxSVGBitmapHandler* handler);
void SetShapeRenderingMode(wxSVGShapeRenderingMode renderingMode);
private:
virtual bool DoGetPixel(wxCoord, wxCoord, wxColour *) const wxOVERRIDE
virtual bool DoGetPixel(wxCoord WXUNUSED(x), wxCoord WXUNUSED(y),
wxColour* WXUNUSED(col)) const wxOVERRIDE
{
wxFAIL_MSG(wxT("wxSVGFILEDC::DoGetPixel Call not implemented"));
return true;
}
virtual bool DoBlit(wxCoord, wxCoord, wxCoord, wxCoord, wxDC *,
wxCoord, wxCoord, wxRasterOperationMode = wxCOPY,
bool = 0, int = -1, int = -1) wxOVERRIDE;
virtual bool DoBlit(wxCoord xdest, wxCoord ydest,
wxCoord width, wxCoord height,
wxDC* source,
wxCoord xsrc, wxCoord ysrc,
wxRasterOperationMode rop,
bool useMask = false,
wxCoord xsrcMask = wxDefaultCoord,
wxCoord ysrcMask = wxDefaultCoord) wxOVERRIDE;
virtual void DoCrossHair(wxCoord, wxCoord) wxOVERRIDE
virtual void DoCrossHair(wxCoord WXUNUSED(x), wxCoord WXUNUSED(y)) wxOVERRIDE
{
wxFAIL_MSG(wxT("wxSVGFILEDC::CrossHair Call not implemented"));
}
virtual void DoDrawArc(wxCoord, wxCoord, wxCoord, wxCoord, wxCoord, wxCoord) wxOVERRIDE;
virtual void DoDrawArc(wxCoord x1, wxCoord y1,
wxCoord x2, wxCoord y2,
wxCoord xc, wxCoord yc) wxOVERRIDE;
virtual void DoDrawBitmap(const wxBitmap &, wxCoord, wxCoord, bool = false) wxOVERRIDE;
virtual void DoDrawBitmap(const wxBitmap& bmp, wxCoord x, wxCoord y,
bool useMask = false) wxOVERRIDE;
virtual void DoDrawCheckMark(wxCoord x, wxCoord y, wxCoord w, wxCoord h) wxOVERRIDE;
virtual void DoDrawEllipse(wxCoord x, wxCoord y, wxCoord w, wxCoord h) wxOVERRIDE;
virtual void DoDrawEllipse(wxCoord x, wxCoord y,
wxCoord width, wxCoord height) wxOVERRIDE;
virtual void DoDrawEllipticArc(wxCoord x, wxCoord y, wxCoord w, wxCoord h,
double sa, double ea) wxOVERRIDE;
virtual void DoDrawIcon(const wxIcon &, wxCoord, wxCoord) wxOVERRIDE;
virtual void DoDrawIcon(const wxIcon& icon, wxCoord x, wxCoord y) wxOVERRIDE;
virtual void DoDrawLine(wxCoord x1, wxCoord y1, wxCoord x2, wxCoord y2) wxOVERRIDE;
virtual void DoDrawLines(int n, const wxPoint points[],
wxCoord xoffset = 0, wxCoord yoffset = 0) wxOVERRIDE;
wxCoord xoffset, wxCoord yoffset) wxOVERRIDE;
virtual void DoDrawPoint(wxCoord, wxCoord) wxOVERRIDE;
virtual void DoDrawPoint(wxCoord x, wxCoord y) wxOVERRIDE;
virtual void DoDrawPolygon(int n, const wxPoint points[],
wxCoord xoffset, wxCoord yoffset,
wxPolygonFillMode fillStyle) wxOVERRIDE;
wxPolygonFillMode fillStyle = wxODDEVEN_RULE) 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 DoDrawRectangle(wxCoord x, wxCoord y, wxCoord width, wxCoord height) wxOVERRIDE;
virtual void DoDrawRotatedText(const wxString& text, wxCoord x, wxCoord y,
double angle) wxOVERRIDE;
virtual void DoDrawRoundedRectangle(wxCoord x, wxCoord y,
wxCoord w, wxCoord h,
double radius = 20) wxOVERRIDE;
wxCoord width, wxCoord height,
double radius) wxOVERRIDE;
virtual void DoDrawText(const wxString& text, wxCoord x, wxCoord y) wxOVERRIDE;
virtual bool DoFloodFill(wxCoord WXUNUSED(x), wxCoord WXUNUSED(y),
const wxColour& WXUNUSED(col),
wxFloodFillStyle WXUNUSED(style) = wxFLOOD_SURFACE) wxOVERRIDE
wxFloodFillStyle WXUNUSED(style)) wxOVERRIDE
{
wxFAIL_MSG(wxT("wxSVGFILEDC::DoFloodFill Call not implemented"));
return false;
}
virtual void DoGetSize(int * x, int *y) const wxOVERRIDE
virtual void DoGradientFillLinear(const wxRect& rect,
const wxColour& initialColour,
const wxColour& destColour,
wxDirection nDirection) wxOVERRIDE;
virtual void DoGradientFillConcentric(const wxRect& rect,
const wxColour& initialColour,
const wxColour& destColour,
const wxPoint& circleCenter) wxOVERRIDE;
virtual void DoGetSize(int* width, int* height) const wxOVERRIDE
{
if ( x )
*x = m_width;
if ( y )
*y = m_height;
if ( width )
*width = m_width;
if ( height )
*height = m_height;
}
virtual void DoGetTextExtent(const wxString& string, wxCoord *w, wxCoord *h,
wxCoord *descent = NULL,
wxCoord *externalLeading = NULL,
const wxFont *font = NULL) const wxOVERRIDE;
virtual void DoGetTextExtent(const wxString& string,
wxCoord* x, wxCoord* y,
wxCoord* descent = NULL,
wxCoord* externalLeading = NULL,
const wxFont* theFont = NULL) const wxOVERRIDE;
virtual void DoSetDeviceClippingRegion(const wxRegion& region) wxOVERRIDE
{
@@ -228,16 +258,17 @@ private:
region.GetBox().width, region.GetBox().height);
}
virtual void DoSetClippingRegion(int x, int y, int width, int height) wxOVERRIDE;
virtual void DoSetClippingRegion(wxCoord x, wxCoord y,
wxCoord w, wxCoord h) wxOVERRIDE;
virtual void DoGetSizeMM(int *width, int *height) const wxOVERRIDE;
virtual void DoGetSizeMM(int* width, int* height) const wxOVERRIDE;
virtual wxSize GetPPI() const wxOVERRIDE;
void Init(const wxString &filename, int width, int height,
double dpi, const wxString &title);
void Init(const wxString& filename, int width, int height,
double dpi, const wxString& title);
void write(const wxString &s);
void write(const wxString& s);
private:
// If m_graphics_changed is true, close the current <g> element and start a
@@ -255,6 +286,7 @@ private:
double m_dpi;
wxScopedPtr<wxFileOutputStream> m_outfile;
wxScopedPtr<wxSVGBitmapHandler> m_bmp_handler; // class to handle bitmaps
wxSVGShapeRenderingMode m_renderingMode;
// The clipping nesting level is incremented by every call to
// SetClippingRegion() and reset when DestroyClippingRegion() is called.
@@ -264,7 +296,11 @@ private:
// incremented in each SetClippingRegion() call.
size_t m_clipUniqueId;
// Unique ID for every gradient.
size_t m_gradientUniqueId;
wxDECLARE_ABSTRACT_CLASS(wxSVGFileDCImpl);
wxDECLARE_NO_COPY_CLASS(wxSVGFileDCImpl);
};
@@ -284,6 +320,16 @@ public:
// Use a custom bitmap handler: takes ownership of the handler.
void SetBitmapHandler(wxSVGBitmapHandler* handler);
void SetShapeRenderingMode(wxSVGShapeRenderingMode renderingMode);
private:
wxSVGFileDC()
: wxDC(new wxSVGFileDCImpl(this, wxString()))
{
}
wxDECLARE_DYNAMIC_CLASS(wxSVGFileDC);
};
#endif // wxUSE_SVG