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
|
|
|
|
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"
|
2002-06-19 05:17:46 -04:00
|
|
|
|
2007-07-11 16:52:41 -04:00
|
|
|
#if wxUSE_SVG
|
|
|
|
|
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
|
|
|
|
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-04-10 17:37:34 -04:00
|
|
|
wxSVGFileDCImpl(wxSVGFileDC *owner, const wxString &filename,
|
|
|
|
int width = 320, int height = 240, double dpi = 72.0,
|
|
|
|
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
|
2014-03-29 20:02:23 -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
|
|
|
}
|
|
|
|
|
2016-06-04 08:10:46 -04:00
|
|
|
virtual void SetLogicalOrigin(wxCoord x, wxCoord y) wxOVERRIDE
|
|
|
|
{
|
|
|
|
wxDCImpl::SetLogicalOrigin(x, y);
|
|
|
|
m_graphics_changed = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void SetDeviceOrigin(wxCoord x, wxCoord y) wxOVERRIDE
|
|
|
|
{
|
|
|
|
wxDCImpl::SetDeviceOrigin(x, y);
|
|
|
|
m_graphics_changed = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void SetAxisOrientation(bool xLeftRight, bool yBottomUp) wxOVERRIDE
|
|
|
|
{
|
|
|
|
wxDCImpl::SetAxisOrientation(xLeftRight, yBottomUp);
|
|
|
|
m_graphics_changed = true;
|
|
|
|
}
|
|
|
|
|
2019-04-10 17:37:34 -04:00
|
|
|
virtual void SetBackground(const wxBrush &brush) wxOVERRIDE;
|
|
|
|
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);
|
|
|
|
|
2007-05-01 17:28:29 -04:00
|
|
|
private:
|
2019-04-10 17:37:34 -04:00
|
|
|
virtual bool DoGetPixel(wxCoord, wxCoord, wxColour *) const wxOVERRIDE
|
|
|
|
{
|
|
|
|
wxFAIL_MSG(wxT("wxSVGFILEDC::DoGetPixel Call not implemented"));
|
|
|
|
return true;
|
|
|
|
}
|
2007-07-11 16:42:37 -04:00
|
|
|
|
2019-04-10 17:37:34 -04:00
|
|
|
virtual bool DoBlit(wxCoord, wxCoord, wxCoord, wxCoord, wxDC *,
|
|
|
|
wxCoord, wxCoord, wxRasterOperationMode = wxCOPY,
|
|
|
|
bool = 0, int = -1, int = -1) wxOVERRIDE;
|
2002-06-19 05:17:46 -04:00
|
|
|
|
2019-04-10 17:37:34 -04:00
|
|
|
virtual void DoCrossHair(wxCoord, wxCoord) wxOVERRIDE
|
|
|
|
{
|
|
|
|
wxFAIL_MSG(wxT("wxSVGFILEDC::CrossHair Call not implemented"));
|
|
|
|
}
|
2002-06-19 05:17:46 -04:00
|
|
|
|
2019-04-10 17:37:34 -04:00
|
|
|
virtual void DoDrawArc(wxCoord, wxCoord, wxCoord, wxCoord, wxCoord, wxCoord) wxOVERRIDE;
|
2002-06-19 05:17:46 -04:00
|
|
|
|
2019-04-10 17:37:34 -04:00
|
|
|
virtual void DoDrawBitmap(const wxBitmap &, wxCoord, wxCoord, bool = false) wxOVERRIDE;
|
2002-06-19 05:17:46 -04:00
|
|
|
|
2019-04-10 17:37:34 -04:00
|
|
|
virtual void DoDrawCheckMark(wxCoord x, wxCoord y, wxCoord w, wxCoord h) wxOVERRIDE;
|
2002-06-19 05:17:46 -04:00
|
|
|
|
2019-04-10 17:37:34 -04:00
|
|
|
virtual void DoDrawEllipse(wxCoord x, wxCoord y, wxCoord w, wxCoord h) 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-04-10 17:37:34 -04:00
|
|
|
virtual void DoDrawIcon(const wxIcon &, wxCoord, wxCoord) 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[],
|
|
|
|
wxCoord xoffset = 0, wxCoord yoffset = 0) wxOVERRIDE;
|
2002-06-19 05:17:46 -04:00
|
|
|
|
2019-04-10 17:37:34 -04:00
|
|
|
virtual void DoDrawPoint(wxCoord, wxCoord) 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,
|
|
|
|
wxPolygonFillMode fillStyle) 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-04-10 17:37:34 -04:00
|
|
|
virtual void DoDrawRectangle(wxCoord x, wxCoord y, wxCoord w, wxCoord h) 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,
|
|
|
|
wxCoord w, wxCoord h,
|
|
|
|
double radius = 20) 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),
|
|
|
|
wxFloodFillStyle WXUNUSED(style) = wxFLOOD_SURFACE) wxOVERRIDE
|
|
|
|
{
|
|
|
|
wxFAIL_MSG(wxT("wxSVGFILEDC::DoFloodFill Call not implemented"));
|
|
|
|
return false;
|
|
|
|
}
|
2002-06-19 05:17:46 -04:00
|
|
|
|
2019-04-10 17:37:34 -04:00
|
|
|
virtual void DoGetSize(int * x, int *y) const wxOVERRIDE
|
|
|
|
{
|
|
|
|
if ( x )
|
|
|
|
*x = m_width;
|
|
|
|
if ( y )
|
|
|
|
*y = m_height;
|
|
|
|
}
|
2002-06-19 05:17:46 -04:00
|
|
|
|
2019-04-10 17:37:34 -04:00
|
|
|
virtual void DoGetTextExtent(const wxString& string, wxCoord *w, wxCoord *h,
|
|
|
|
wxCoord *descent = NULL,
|
|
|
|
wxCoord *externalLeading = NULL,
|
|
|
|
const wxFont *font = NULL) const wxOVERRIDE;
|
2002-06-19 05:17:46 -04:00
|
|
|
|
2019-04-10 17:37:34 -04:00
|
|
|
virtual void DoSetDeviceClippingRegion(const wxRegion& region) wxOVERRIDE
|
|
|
|
{
|
2016-03-15 15:15:07 -04:00
|
|
|
DoSetClippingRegion(region.GetBox().x, region.GetBox().y,
|
|
|
|
region.GetBox().width, region.GetBox().height);
|
2019-04-10 17:37:34 -04:00
|
|
|
}
|
2007-09-24 05:30:24 -04:00
|
|
|
|
2019-04-10 17:37:34 -04:00
|
|
|
virtual void DoSetClippingRegion(int x, int y, int width, int height) wxOVERRIDE;
|
2002-06-19 05:17:46 -04:00
|
|
|
|
2019-04-10 17:37:34 -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-04-10 17:37:34 -04:00
|
|
|
void Init(const wxString &filename, int width, int height,
|
2016-03-15 18:50:33 -04:00
|
|
|
double dpi, const wxString &title);
|
2002-06-19 05:17:46 -04:00
|
|
|
|
2019-04-10 17:37:34 -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
|
|
|
|
|
|
|
|
// 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;
|
|
|
|
|
|
|
|
wxDECLARE_ABSTRACT_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);
|
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_
|