2007-04-05 14:26:59 -04:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Name: wx/dcsvg.h
|
|
|
|
// Purpose: wxSVGFileDC
|
|
|
|
// Author: Chris Elliott
|
|
|
|
// Modified by:
|
|
|
|
// Created:
|
|
|
|
// Copyright: (c) Chris Elliott
|
|
|
|
// Licence: wxWindows licence
|
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2007-07-11 16:42:37 -04:00
|
|
|
#ifndef _WX_DCSVG_H_
|
|
|
|
#define _WX_DCSVG_H_
|
2007-04-05 14:26:59 -04:00
|
|
|
|
2019-08-10 15:56:14 -04:00
|
|
|
#if wxUSE_SVG
|
|
|
|
|
2005-10-07 10:01:37 -04:00
|
|
|
#include "wx/string.h"
|
2019-04-23 15:20:02 -04:00
|
|
|
#include "wx/filename.h"
|
2007-07-11 16:42:37 -04:00
|
|
|
#include "wx/dc.h"
|
2017-07-31 17:50:06 -04:00
|
|
|
#include "wx/scopedptr.h"
|
|
|
|
|
2016-03-15 18:51:41 -04:00
|
|
|
#define wxSVGVersion wxT("v0101")
|
2002-06-19 05:17:46 -04:00
|
|
|
|
2019-08-10 15:56:14 -04:00
|
|
|
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
|
|
|
|
};
|
|
|
|
|
2007-07-11 16:42:37 -04:00
|
|
|
class WXDLLIMPEXP_FWD_BASE wxFileOutputStream;
|
|
|
|
|
2014-02-22 12:26:27 -05:00
|
|
|
class WXDLLIMPEXP_FWD_CORE wxSVGFileDC;
|
2007-09-24 05:30:24 -04:00
|
|
|
|
2014-02-22 12:26:27 -05:00
|
|
|
// Base class for bitmap handlers used by wxSVGFileDC, used by the standard
|
|
|
|
// "embed" and "link" handlers below but can also be used to create a custom
|
|
|
|
// handler.
|
|
|
|
class WXDLLIMPEXP_CORE wxSVGBitmapHandler
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
// Write the representation of the given bitmap, appearing at the specified
|
|
|
|
// position, to the provided stream.
|
|
|
|
virtual bool ProcessBitmap(const wxBitmap& bitmap,
|
|
|
|
wxCoord x, wxCoord y,
|
|
|
|
wxOutputStream& stream) const = 0;
|
2007-09-24 05:30:24 -04:00
|
|
|
|
2014-02-22 12:26:27 -05:00
|
|
|
virtual ~wxSVGBitmapHandler() {}
|
|
|
|
};
|
|
|
|
|
|
|
|
// Predefined standard bitmap handler: creates a file, stores the bitmap in
|
2019-04-10 17:41:58 -04:00
|
|
|
// this file and uses the file name in the generated SVG.
|
2014-02-22 12:26:27 -05:00
|
|
|
class WXDLLIMPEXP_CORE wxSVGBitmapFileHandler : public wxSVGBitmapHandler
|
|
|
|
{
|
|
|
|
public:
|
2019-04-10 17:41:58 -04:00
|
|
|
wxSVGBitmapFileHandler()
|
|
|
|
: m_path()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2019-04-23 15:20:02 -04:00
|
|
|
explicit wxSVGBitmapFileHandler(const wxFileName& path)
|
2019-04-10 17:41:58 -04:00
|
|
|
: m_path(path)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2014-02-22 12:26:27 -05:00
|
|
|
virtual bool ProcessBitmap(const wxBitmap& bitmap,
|
|
|
|
wxCoord x, wxCoord y,
|
2014-03-29 20:02:23 -04:00
|
|
|
wxOutputStream& stream) const wxOVERRIDE;
|
2019-04-10 17:41:58 -04:00
|
|
|
|
|
|
|
private:
|
2019-04-23 15:20:02 -04:00
|
|
|
wxFileName m_path; // When set, name will be appended with _image#.png
|
2014-02-22 12:26:27 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
// Predefined handler which embeds the bitmap (base64-encoding it) inside the
|
|
|
|
// generated SVG file.
|
|
|
|
class WXDLLIMPEXP_CORE wxSVGBitmapEmbedHandler : public wxSVGBitmapHandler
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
virtual bool ProcessBitmap(const wxBitmap& bitmap,
|
|
|
|
wxCoord x, wxCoord y,
|
2014-03-29 20:02:23 -04:00
|
|
|
wxOutputStream& stream) const wxOVERRIDE;
|
2014-02-22 12:26:27 -05:00
|
|
|
};
|
2007-09-24 05:30:24 -04:00
|
|
|
|
2007-11-30 08:48:22 -05:00
|
|
|
class WXDLLIMPEXP_CORE wxSVGFileDCImpl : public wxDCImpl
|
2002-06-19 05:17:46 -04:00
|
|
|
{
|
2007-05-01 17:28:29 -04:00
|
|
|
public:
|
2019-08-21 15:15:38 -04:00
|
|
|
wxSVGFileDCImpl(wxSVGFileDC* owner, const wxString& filename,
|
2019-04-10 17:37:34 -04:00
|
|
|
int width = 320, int height = 240, double dpi = 72.0,
|
2019-08-21 15:15:38 -04:00
|
|
|
const wxString& title = wxString());
|
2007-09-24 05:30:24 -04:00
|
|
|
|
2007-11-30 08:48:22 -05:00
|
|
|
virtual ~wxSVGFileDCImpl();
|
2009-08-21 06:41:26 -04:00
|
|
|
|
2014-03-29 20:02:23 -04:00
|
|
|
bool IsOk() const wxOVERRIDE { return m_OK; }
|
2007-07-11 16:42:37 -04:00
|
|
|
|
2014-03-29 20:02:23 -04:00
|
|
|
virtual bool CanDrawBitmap() const wxOVERRIDE { return true; }
|
|
|
|
virtual bool CanGetTextExtent() const wxOVERRIDE { return true; }
|
2007-07-11 16:42:37 -04:00
|
|
|
|
2014-03-29 20:02:23 -04:00
|
|
|
virtual int GetDepth() const wxOVERRIDE
|
2007-07-11 16:42:37 -04:00
|
|
|
{
|
|
|
|
wxFAIL_MSG(wxT("wxSVGFILEDC::GetDepth Call not implemented"));
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2016-03-15 17:12:13 -04:00
|
|
|
virtual void Clear() wxOVERRIDE;
|
2007-07-11 16:42:37 -04:00
|
|
|
|
2014-03-29 20:02:23 -04:00
|
|
|
virtual void DestroyClippingRegion() wxOVERRIDE;
|
2007-07-11 16:42:37 -04:00
|
|
|
|
2014-03-29 20:02:23 -04:00
|
|
|
virtual wxCoord GetCharHeight() const wxOVERRIDE;
|
|
|
|
virtual wxCoord GetCharWidth() const wxOVERRIDE;
|
2007-07-11 16:42:37 -04:00
|
|
|
|
2018-10-10 01:24:58 -04:00
|
|
|
#if wxUSE_PALETTE
|
2019-08-21 15:15:38 -04:00
|
|
|
virtual void SetPalette(const wxPalette& WXUNUSED(palette)) wxOVERRIDE
|
2007-07-11 16:42:37 -04:00
|
|
|
{
|
|
|
|
wxFAIL_MSG(wxT("wxSVGFILEDC::SetPalette not implemented"));
|
|
|
|
}
|
2018-10-10 01:24:58 -04:00
|
|
|
#endif
|
2007-07-11 16:42:37 -04:00
|
|
|
|
2014-03-29 20:02:23 -04:00
|
|
|
virtual void SetLogicalFunction(wxRasterOperationMode WXUNUSED(function)) wxOVERRIDE
|
2007-07-11 16:42:37 -04:00
|
|
|
{
|
|
|
|
wxFAIL_MSG(wxT("wxSVGFILEDC::SetLogicalFunction Call not implemented"));
|
|
|
|
}
|
|
|
|
|
2014-03-29 20:02:23 -04:00
|
|
|
virtual wxRasterOperationMode GetLogicalFunction() const wxOVERRIDE
|
2007-07-11 16:42:37 -04:00
|
|
|
{
|
|
|
|
wxFAIL_MSG(wxT("wxSVGFILEDC::GetLogicalFunction() not implemented"));
|
2009-01-08 09:21:53 -05:00
|
|
|
return wxCOPY;
|
2007-07-11 16:42:37 -04:00
|
|
|
}
|
|
|
|
|
2021-07-26 14:30:57 -04:00
|
|
|
virtual void ComputeScaleAndOrigin() wxOVERRIDE;
|
2016-06-04 08:10:46 -04:00
|
|
|
|
2019-08-21 15:15:38 -04:00
|
|
|
virtual void SetBackground(const wxBrush& brush) wxOVERRIDE;
|
2019-04-10 17:37:34 -04:00
|
|
|
virtual void SetBackgroundMode(int mode) wxOVERRIDE;
|
2014-03-29 20:02:23 -04:00
|
|
|
virtual void SetBrush(const wxBrush& brush) wxOVERRIDE;
|
|
|
|
virtual void SetFont(const wxFont& font) wxOVERRIDE;
|
|
|
|
virtual void SetPen(const wxPen& pen) wxOVERRIDE;
|
2007-07-11 16:42:37 -04:00
|
|
|
|
2014-03-29 20:02:23 -04:00
|
|
|
virtual void* GetHandle() const wxOVERRIDE { return NULL; }
|
2012-07-28 15:31:03 -04:00
|
|
|
|
2014-02-22 12:26:27 -05:00
|
|
|
void SetBitmapHandler(wxSVGBitmapHandler* handler);
|
|
|
|
|
2019-08-10 15:56:14 -04:00
|
|
|
void SetShapeRenderingMode(wxSVGShapeRenderingMode renderingMode);
|
|
|
|
|
2007-05-01 17:28:29 -04:00
|
|
|
private:
|
2019-08-21 15:49:25 -04:00
|
|
|
virtual bool DoGetPixel(wxCoord WXUNUSED(x), wxCoord WXUNUSED(y),
|
|
|
|
wxColour* WXUNUSED(col)) const wxOVERRIDE
|
2019-04-10 17:37:34 -04:00
|
|
|
{
|
|
|
|
wxFAIL_MSG(wxT("wxSVGFILEDC::DoGetPixel Call not implemented"));
|
|
|
|
return true;
|
|
|
|
}
|
2007-07-11 16:42:37 -04:00
|
|
|
|
2019-08-21 15:49:25 -04:00
|
|
|
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;
|
2002-06-19 05:17:46 -04:00
|
|
|
|
2019-08-21 15:49:25 -04:00
|
|
|
virtual void DoCrossHair(wxCoord WXUNUSED(x), wxCoord WXUNUSED(y)) wxOVERRIDE
|
2019-04-10 17:37:34 -04:00
|
|
|
{
|
|
|
|
wxFAIL_MSG(wxT("wxSVGFILEDC::CrossHair Call not implemented"));
|
|
|
|
}
|
2002-06-19 05:17:46 -04:00
|
|
|
|
2019-08-21 15:49:25 -04:00
|
|
|
virtual void DoDrawArc(wxCoord x1, wxCoord y1,
|
|
|
|
wxCoord x2, wxCoord y2,
|
|
|
|
wxCoord xc, wxCoord yc) wxOVERRIDE;
|
2002-06-19 05:17:46 -04:00
|
|
|
|
2019-08-21 15:49:25 -04:00
|
|
|
virtual void DoDrawBitmap(const wxBitmap& bmp, wxCoord x, wxCoord y,
|
|
|
|
bool useMask = false) wxOVERRIDE;
|
2002-06-19 05:17:46 -04:00
|
|
|
|
2019-08-21 15:49:25 -04:00
|
|
|
virtual void DoDrawEllipse(wxCoord x, wxCoord y,
|
|
|
|
wxCoord width, wxCoord height) wxOVERRIDE;
|
2002-06-19 05:17:46 -04:00
|
|
|
|
2019-04-10 17:37:34 -04:00
|
|
|
virtual void DoDrawEllipticArc(wxCoord x, wxCoord y, wxCoord w, wxCoord h,
|
|
|
|
double sa, double ea) wxOVERRIDE;
|
2002-06-19 05:17:46 -04:00
|
|
|
|
2019-08-21 15:49:25 -04:00
|
|
|
virtual void DoDrawIcon(const wxIcon& icon, wxCoord x, wxCoord y) wxOVERRIDE;
|
2002-06-19 05:17:46 -04:00
|
|
|
|
2019-04-10 17:37:34 -04:00
|
|
|
virtual void DoDrawLine(wxCoord x1, wxCoord y1, wxCoord x2, wxCoord y2) wxOVERRIDE;
|
2002-06-19 05:17:46 -04:00
|
|
|
|
2019-04-10 17:37:34 -04:00
|
|
|
virtual void DoDrawLines(int n, const wxPoint points[],
|
2019-08-21 15:49:25 -04:00
|
|
|
wxCoord xoffset, wxCoord yoffset) wxOVERRIDE;
|
2021-07-04 13:22:02 -04:00
|
|
|
#if wxUSE_SPLINES
|
|
|
|
void DoDrawSpline(const wxPointList* points) wxOVERRIDE;
|
|
|
|
#endif // wxUSE_SPLINES
|
2002-06-19 05:17:46 -04:00
|
|
|
|
2019-08-21 15:49:25 -04:00
|
|
|
virtual void DoDrawPoint(wxCoord x, wxCoord y) wxOVERRIDE;
|
2007-05-01 17:28:29 -04:00
|
|
|
|
2019-04-10 17:37:34 -04:00
|
|
|
virtual void DoDrawPolygon(int n, const wxPoint points[],
|
|
|
|
wxCoord xoffset, wxCoord yoffset,
|
2019-08-21 15:49:25 -04:00
|
|
|
wxPolygonFillMode fillStyle = wxODDEVEN_RULE) wxOVERRIDE;
|
2002-06-19 05:17:46 -04:00
|
|
|
|
2019-04-10 17:37:34 -04:00
|
|
|
virtual void DoDrawPolyPolygon(int n, const int count[], const wxPoint points[],
|
|
|
|
wxCoord xoffset, wxCoord yoffset,
|
|
|
|
wxPolygonFillMode fillStyle) wxOVERRIDE;
|
2016-03-15 15:36:55 -04:00
|
|
|
|
2019-08-21 15:49:25 -04:00
|
|
|
virtual void DoDrawRectangle(wxCoord x, wxCoord y, wxCoord width, wxCoord height) wxOVERRIDE;
|
2002-06-19 05:17:46 -04:00
|
|
|
|
2019-04-10 17:37:34 -04:00
|
|
|
virtual void DoDrawRotatedText(const wxString& text, wxCoord x, wxCoord y,
|
|
|
|
double angle) wxOVERRIDE;
|
2002-06-19 05:17:46 -04:00
|
|
|
|
2019-04-10 17:37:34 -04:00
|
|
|
virtual void DoDrawRoundedRectangle(wxCoord x, wxCoord y,
|
2019-08-21 15:49:25 -04:00
|
|
|
wxCoord width, wxCoord height,
|
|
|
|
double radius) wxOVERRIDE;
|
2002-06-19 05:17:46 -04:00
|
|
|
|
2019-04-10 17:37:34 -04:00
|
|
|
virtual void DoDrawText(const wxString& text, wxCoord x, wxCoord y) wxOVERRIDE;
|
2002-06-19 05:17:46 -04:00
|
|
|
|
2019-04-10 17:37:34 -04:00
|
|
|
virtual bool DoFloodFill(wxCoord WXUNUSED(x), wxCoord WXUNUSED(y),
|
|
|
|
const wxColour& WXUNUSED(col),
|
2019-08-21 15:49:25 -04:00
|
|
|
wxFloodFillStyle WXUNUSED(style)) wxOVERRIDE
|
2019-04-10 17:37:34 -04:00
|
|
|
{
|
|
|
|
wxFAIL_MSG(wxT("wxSVGFILEDC::DoFloodFill Call not implemented"));
|
|
|
|
return false;
|
|
|
|
}
|
2002-06-19 05:17:46 -04:00
|
|
|
|
2019-08-11 12:25:09 -04:00
|
|
|
virtual void DoGradientFillLinear(const wxRect& rect,
|
|
|
|
const wxColour& initialColour,
|
|
|
|
const wxColour& destColour,
|
2019-08-21 15:49:25 -04:00
|
|
|
wxDirection nDirection) wxOVERRIDE;
|
2019-08-11 12:25:09 -04:00
|
|
|
|
|
|
|
virtual void DoGradientFillConcentric(const wxRect& rect,
|
2019-08-21 15:15:38 -04:00
|
|
|
const wxColour& initialColour,
|
|
|
|
const wxColour& destColour,
|
|
|
|
const wxPoint& circleCenter) wxOVERRIDE;
|
2019-08-11 12:25:09 -04:00
|
|
|
|
2019-08-21 15:49:25 -04:00
|
|
|
virtual void DoGetSize(int* width, int* height) const wxOVERRIDE
|
2019-04-10 17:37:34 -04:00
|
|
|
{
|
2019-08-21 15:49:25 -04:00
|
|
|
if ( width )
|
|
|
|
*width = m_width;
|
|
|
|
if ( height )
|
|
|
|
*height = m_height;
|
2019-04-10 17:37:34 -04:00
|
|
|
}
|
2002-06-19 05:17:46 -04:00
|
|
|
|
2019-08-21 15:49:25 -04:00
|
|
|
virtual void DoGetTextExtent(const wxString& string,
|
|
|
|
wxCoord* x, wxCoord* y,
|
2019-08-21 15:15:38 -04:00
|
|
|
wxCoord* descent = NULL,
|
|
|
|
wxCoord* externalLeading = NULL,
|
2019-08-21 15:49:25 -04:00
|
|
|
const wxFont* theFont = NULL) const wxOVERRIDE;
|
2002-06-19 05:17:46 -04:00
|
|
|
|
2021-07-26 14:33:40 -04:00
|
|
|
virtual void DoSetDeviceClippingRegion(const wxRegion& region) wxOVERRIDE;
|
2007-09-24 05:30:24 -04:00
|
|
|
|
2019-08-21 15:49:25 -04:00
|
|
|
virtual void DoSetClippingRegion(wxCoord x, wxCoord y,
|
|
|
|
wxCoord w, wxCoord h) wxOVERRIDE;
|
2002-06-19 05:17:46 -04:00
|
|
|
|
2019-08-21 15:15:38 -04:00
|
|
|
virtual void DoGetSizeMM(int* width, int* height) const wxOVERRIDE;
|
2009-08-21 06:41:26 -04:00
|
|
|
|
2019-04-10 17:37:34 -04:00
|
|
|
virtual wxSize GetPPI() const wxOVERRIDE;
|
2007-09-24 05:30:24 -04:00
|
|
|
|
2019-08-21 15:15:38 -04:00
|
|
|
void Init(const wxString& filename, int width, int height,
|
|
|
|
double dpi, const wxString& title);
|
2002-06-19 05:17:46 -04:00
|
|
|
|
2019-08-21 15:15:38 -04:00
|
|
|
void write(const wxString& s);
|
2007-05-01 17:28:29 -04:00
|
|
|
|
|
|
|
private:
|
2019-04-10 17:37:34 -04:00
|
|
|
// If m_graphics_changed is true, close the current <g> element and start a
|
|
|
|
// new one for the last pen/brush change.
|
|
|
|
void NewGraphicsIfNeeded();
|
|
|
|
|
|
|
|
// Open a new graphics group setting up all the attributes according to
|
|
|
|
// their current values in wxDC.
|
|
|
|
void DoStartNewGraphics();
|
|
|
|
|
|
|
|
wxString m_filename;
|
|
|
|
bool m_OK;
|
|
|
|
bool m_graphics_changed; // set by Set{Brush,Pen}()
|
|
|
|
int m_width, m_height;
|
|
|
|
double m_dpi;
|
|
|
|
wxScopedPtr<wxFileOutputStream> m_outfile;
|
|
|
|
wxScopedPtr<wxSVGBitmapHandler> m_bmp_handler; // class to handle bitmaps
|
2019-08-10 15:56:14 -04:00
|
|
|
wxSVGShapeRenderingMode m_renderingMode;
|
2019-04-10 17:37:34 -04:00
|
|
|
|
|
|
|
// The clipping nesting level is incremented by every call to
|
|
|
|
// SetClippingRegion() and reset when DestroyClippingRegion() is called.
|
|
|
|
size_t m_clipNestingLevel;
|
|
|
|
|
|
|
|
// Unique ID for every clipping graphics group: this is simply always
|
|
|
|
// incremented in each SetClippingRegion() call.
|
|
|
|
size_t m_clipUniqueId;
|
|
|
|
|
2019-08-11 12:25:09 -04:00
|
|
|
// Unique ID for every gradient.
|
|
|
|
size_t m_gradientUniqueId;
|
|
|
|
|
2019-04-10 17:37:34 -04:00
|
|
|
wxDECLARE_ABSTRACT_CLASS(wxSVGFileDCImpl);
|
2019-08-10 16:22:32 -04:00
|
|
|
wxDECLARE_NO_COPY_CLASS(wxSVGFileDCImpl);
|
2007-09-24 05:30:24 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class WXDLLIMPEXP_CORE wxSVGFileDC : public wxDC
|
|
|
|
{
|
|
|
|
public:
|
2009-08-21 06:41:26 -04:00
|
|
|
wxSVGFileDC(const wxString& filename,
|
2007-11-30 15:56:12 -05:00
|
|
|
int width = 320,
|
|
|
|
int height = 240,
|
2016-03-15 18:50:33 -04:00
|
|
|
double dpi = 72.0,
|
|
|
|
const wxString& title = wxString())
|
|
|
|
: wxDC(new wxSVGFileDCImpl(this, filename, width, height, dpi, title))
|
2009-08-21 06:41:26 -04:00
|
|
|
{
|
2007-09-24 05:30:24 -04:00
|
|
|
}
|
2014-02-22 12:26:27 -05:00
|
|
|
|
|
|
|
// wxSVGFileDC-specific methods:
|
|
|
|
|
|
|
|
// Use a custom bitmap handler: takes ownership of the handler.
|
|
|
|
void SetBitmapHandler(wxSVGBitmapHandler* handler);
|
2019-08-10 15:56:14 -04:00
|
|
|
|
|
|
|
void SetShapeRenderingMode(wxSVGShapeRenderingMode renderingMode);
|
2019-08-10 16:22:32 -04:00
|
|
|
|
|
|
|
private:
|
2019-11-28 19:10:43 -05:00
|
|
|
wxDECLARE_ABSTRACT_CLASS(wxSVGFileDC);
|
2002-06-19 05:17:46 -04:00
|
|
|
};
|
|
|
|
|
2007-07-11 16:52:41 -04:00
|
|
|
#endif // wxUSE_SVG
|
|
|
|
|
2007-07-11 16:42:37 -04:00
|
|
|
#endif // _WX_DCSVG_H_
|