2007-04-05 18:26:59 +00:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Name: wx/dcsvg.h
|
|
|
|
// Purpose: wxSVGFileDC
|
|
|
|
// Author: Chris Elliott
|
|
|
|
// Modified by:
|
|
|
|
// Created:
|
|
|
|
// Copyright: (c) Chris Elliott
|
|
|
|
// Licence: wxWindows licence
|
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2007-07-11 20:42:37 +00:00
|
|
|
#ifndef _WX_DCSVG_H_
|
|
|
|
#define _WX_DCSVG_H_
|
2007-04-05 18:26:59 +00:00
|
|
|
|
2005-10-07 14:01:37 +00:00
|
|
|
#include "wx/string.h"
|
2007-07-11 20:42:37 +00:00
|
|
|
#include "wx/dc.h"
|
2002-06-19 09:17:46 +00:00
|
|
|
|
2007-07-11 20:52:41 +00:00
|
|
|
#if wxUSE_SVG
|
|
|
|
|
2002-06-19 09:17:46 +00:00
|
|
|
#define wxSVGVersion wxT("v0100")
|
|
|
|
|
2007-04-26 11:11:28 +00:00
|
|
|
#ifdef __BORLANDC__
|
|
|
|
#pragma warn -8008
|
|
|
|
#pragma warn -8066
|
|
|
|
#endif
|
|
|
|
|
2007-07-11 20:42:37 +00:00
|
|
|
class WXDLLIMPEXP_FWD_BASE wxFileOutputStream;
|
|
|
|
|
2014-02-22 17:26:27 +00:00
|
|
|
class WXDLLIMPEXP_FWD_CORE wxSVGFileDC;
|
2007-09-24 09:30:24 +00:00
|
|
|
|
2014-02-22 17:26:27 +00: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 09:30:24 +00:00
|
|
|
|
2014-02-22 17:26:27 +00:00
|
|
|
virtual ~wxSVGBitmapHandler() {}
|
|
|
|
};
|
|
|
|
|
|
|
|
// Predefined standard bitmap handler: creates a file, stores the bitmap in
|
|
|
|
// this file and uses the file URI in the generated SVG.
|
|
|
|
class WXDLLIMPEXP_CORE wxSVGBitmapFileHandler : public wxSVGBitmapHandler
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
virtual bool ProcessBitmap(const wxBitmap& bitmap,
|
|
|
|
wxCoord x, wxCoord y,
|
2014-03-30 00:02:23 +00:00
|
|
|
wxOutputStream& stream) const wxOVERRIDE;
|
2014-02-22 17:26:27 +00: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-30 00:02:23 +00:00
|
|
|
wxOutputStream& stream) const wxOVERRIDE;
|
2014-02-22 17:26:27 +00:00
|
|
|
};
|
2007-09-24 09:30:24 +00:00
|
|
|
|
2007-11-30 13:48:22 +00:00
|
|
|
class WXDLLIMPEXP_CORE wxSVGFileDCImpl : public wxDCImpl
|
2002-06-19 09:17:46 +00:00
|
|
|
{
|
2007-05-01 21:28:29 +00:00
|
|
|
public:
|
2009-08-21 10:41:26 +00:00
|
|
|
wxSVGFileDCImpl( wxSVGFileDC *owner, const wxString &filename,
|
2007-09-24 09:30:24 +00:00
|
|
|
int width=320, int height=240, double dpi=72.0 );
|
|
|
|
|
2007-11-30 13:48:22 +00:00
|
|
|
virtual ~wxSVGFileDCImpl();
|
2009-08-21 10:41:26 +00:00
|
|
|
|
2014-03-30 00:02:23 +00:00
|
|
|
bool IsOk() const wxOVERRIDE { return m_OK; }
|
2007-07-11 20:42:37 +00:00
|
|
|
|
2014-03-30 00:02:23 +00:00
|
|
|
virtual bool CanDrawBitmap() const wxOVERRIDE { return true; }
|
|
|
|
virtual bool CanGetTextExtent() const wxOVERRIDE { return true; }
|
2007-07-11 20:42:37 +00:00
|
|
|
|
2014-03-30 00:02:23 +00:00
|
|
|
virtual int GetDepth() const wxOVERRIDE
|
2007-07-11 20:42:37 +00:00
|
|
|
{
|
|
|
|
wxFAIL_MSG(wxT("wxSVGFILEDC::GetDepth Call not implemented"));
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2014-03-30 00:02:23 +00:00
|
|
|
virtual void Clear() wxOVERRIDE
|
2007-07-11 20:42:37 +00:00
|
|
|
{
|
|
|
|
wxFAIL_MSG(wxT("wxSVGFILEDC::Clear() Call not implemented \nNot sensible for an output file?"));
|
|
|
|
}
|
|
|
|
|
2014-03-30 00:02:23 +00:00
|
|
|
virtual void DestroyClippingRegion() wxOVERRIDE;
|
2007-07-11 20:42:37 +00:00
|
|
|
|
2014-03-30 00:02:23 +00:00
|
|
|
virtual wxCoord GetCharHeight() const wxOVERRIDE;
|
|
|
|
virtual wxCoord GetCharWidth() const wxOVERRIDE;
|
2007-07-11 20:42:37 +00:00
|
|
|
|
|
|
|
virtual void SetClippingRegion(wxCoord WXUNUSED(x), wxCoord WXUNUSED(y),
|
|
|
|
wxCoord WXUNUSED(w), wxCoord WXUNUSED(h))
|
|
|
|
{
|
|
|
|
wxFAIL_MSG(wxT("wxSVGFILEDC::SetClippingRegion not implemented"));
|
|
|
|
}
|
|
|
|
|
2014-03-30 00:02:23 +00:00
|
|
|
virtual void SetPalette(const wxPalette& WXUNUSED(palette)) wxOVERRIDE
|
2007-07-11 20:42:37 +00:00
|
|
|
{
|
|
|
|
wxFAIL_MSG(wxT("wxSVGFILEDC::SetPalette not implemented"));
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void GetClippingBox(wxCoord *WXUNUSED(x), wxCoord *WXUNUSED(y),
|
|
|
|
wxCoord *WXUNUSED(w), wxCoord *WXUNUSED(h))
|
|
|
|
{
|
|
|
|
wxFAIL_MSG(wxT("wxSVGFILEDC::GetClippingBox not implemented"));
|
|
|
|
}
|
|
|
|
|
2014-03-30 00:02:23 +00:00
|
|
|
virtual void SetLogicalFunction(wxRasterOperationMode WXUNUSED(function)) wxOVERRIDE
|
2007-07-11 20:42:37 +00:00
|
|
|
{
|
|
|
|
wxFAIL_MSG(wxT("wxSVGFILEDC::SetLogicalFunction Call not implemented"));
|
|
|
|
}
|
|
|
|
|
2014-03-30 00:02:23 +00:00
|
|
|
virtual wxRasterOperationMode GetLogicalFunction() const wxOVERRIDE
|
2007-07-11 20:42:37 +00:00
|
|
|
{
|
|
|
|
wxFAIL_MSG(wxT("wxSVGFILEDC::GetLogicalFunction() not implemented"));
|
2009-01-08 14:21:53 +00:00
|
|
|
return wxCOPY;
|
2007-07-11 20:42:37 +00:00
|
|
|
}
|
|
|
|
|
2014-03-30 00:02:23 +00:00
|
|
|
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;
|
|
|
|
virtual void SetPen(const wxPen& pen) wxOVERRIDE;
|
2007-07-11 20:42:37 +00:00
|
|
|
|
2014-03-30 00:02:23 +00:00
|
|
|
virtual void* GetHandle() const wxOVERRIDE { return NULL; }
|
2012-07-28 19:31:03 +00:00
|
|
|
|
2014-02-22 17:26:27 +00:00
|
|
|
void SetBitmapHandler(wxSVGBitmapHandler* handler);
|
|
|
|
|
2007-05-01 21:28:29 +00:00
|
|
|
private:
|
2014-03-30 00:02:23 +00:00
|
|
|
virtual bool DoGetPixel(wxCoord, wxCoord, wxColour *) const wxOVERRIDE
|
2007-07-11 20:42:37 +00:00
|
|
|
{
|
|
|
|
wxFAIL_MSG(wxT("wxSVGFILEDC::DoGetPixel Call not implemented"));
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual bool DoBlit(wxCoord, wxCoord, wxCoord, wxCoord, wxDC *,
|
2009-01-08 14:21:53 +00:00
|
|
|
wxCoord, wxCoord, wxRasterOperationMode = wxCOPY,
|
2014-03-30 00:02:23 +00:00
|
|
|
bool = 0, int = -1, int = -1) wxOVERRIDE;
|
2002-06-19 09:17:46 +00:00
|
|
|
|
2014-03-30 00:02:23 +00:00
|
|
|
virtual void DoCrossHair(wxCoord, wxCoord) wxOVERRIDE
|
2007-07-11 20:42:37 +00:00
|
|
|
{
|
|
|
|
wxFAIL_MSG(wxT("wxSVGFILEDC::CrossHair Call not implemented"));
|
|
|
|
}
|
2002-06-19 09:17:46 +00:00
|
|
|
|
2014-03-30 00:02:23 +00:00
|
|
|
virtual void DoDrawArc(wxCoord, wxCoord, wxCoord, wxCoord, wxCoord, wxCoord) wxOVERRIDE;
|
2002-06-19 09:17:46 +00:00
|
|
|
|
2014-03-30 00:02:23 +00:00
|
|
|
virtual void DoDrawBitmap(const wxBitmap &, wxCoord, wxCoord, bool = false) wxOVERRIDE;
|
2002-06-19 09:17:46 +00:00
|
|
|
|
2014-03-30 00:02:23 +00:00
|
|
|
virtual void DoDrawCheckMark(wxCoord x, wxCoord y, wxCoord w, wxCoord h) wxOVERRIDE;
|
2002-06-19 09:17:46 +00:00
|
|
|
|
2014-03-30 00:02:23 +00:00
|
|
|
virtual void DoDrawEllipse(wxCoord x, wxCoord y, wxCoord w, wxCoord h) wxOVERRIDE;
|
2002-06-19 09:17:46 +00:00
|
|
|
|
2007-07-11 20:42:37 +00:00
|
|
|
virtual void DoDrawEllipticArc(wxCoord x, wxCoord y, wxCoord w, wxCoord h,
|
2014-03-30 00:02:23 +00:00
|
|
|
double sa, double ea) wxOVERRIDE;
|
2002-06-19 09:17:46 +00:00
|
|
|
|
2014-03-30 00:02:23 +00:00
|
|
|
virtual void DoDrawIcon(const wxIcon &, wxCoord, wxCoord) wxOVERRIDE;
|
2002-06-19 09:17:46 +00:00
|
|
|
|
2014-03-30 00:02:23 +00:00
|
|
|
virtual void DoDrawLine (wxCoord x1, wxCoord y1, wxCoord x2, wxCoord y2) wxOVERRIDE;
|
2002-06-19 09:17:46 +00:00
|
|
|
|
2013-01-18 17:27:51 +00:00
|
|
|
virtual void DoDrawLines(int n, const wxPoint points[],
|
2014-03-30 00:02:23 +00:00
|
|
|
wxCoord xoffset = 0, wxCoord yoffset = 0) wxOVERRIDE;
|
2002-06-19 09:17:46 +00:00
|
|
|
|
2014-03-30 00:02:23 +00:00
|
|
|
virtual void DoDrawPoint(wxCoord, wxCoord) wxOVERRIDE;
|
2007-05-01 21:28:29 +00:00
|
|
|
|
2013-01-18 17:27:51 +00:00
|
|
|
virtual void DoDrawPolygon(int n, const wxPoint points[],
|
2009-01-08 14:21:53 +00:00
|
|
|
wxCoord xoffset, wxCoord yoffset,
|
2014-03-30 00:02:23 +00:00
|
|
|
wxPolygonFillMode fillStyle) wxOVERRIDE;
|
2002-06-19 09:17:46 +00:00
|
|
|
|
2014-03-30 00:02:23 +00:00
|
|
|
virtual void DoDrawRectangle(wxCoord x, wxCoord y, wxCoord w, wxCoord h) wxOVERRIDE;
|
2002-06-19 09:17:46 +00:00
|
|
|
|
2007-07-11 20:42:37 +00:00
|
|
|
virtual void DoDrawRotatedText(const wxString& text, wxCoord x, wxCoord y,
|
2014-03-30 00:02:23 +00:00
|
|
|
double angle) wxOVERRIDE;
|
2002-06-19 09:17:46 +00:00
|
|
|
|
2007-07-11 20:42:37 +00:00
|
|
|
virtual void DoDrawRoundedRectangle(wxCoord x, wxCoord y,
|
|
|
|
wxCoord w, wxCoord h,
|
2014-03-30 00:02:23 +00:00
|
|
|
double radius = 20) wxOVERRIDE ;
|
2002-06-19 09:17:46 +00:00
|
|
|
|
2014-03-30 00:02:23 +00:00
|
|
|
virtual void DoDrawText(const wxString& text, wxCoord x, wxCoord y) wxOVERRIDE;
|
2002-06-19 09:17:46 +00:00
|
|
|
|
2007-07-11 20:42:37 +00:00
|
|
|
virtual bool DoFloodFill(wxCoord WXUNUSED(x), wxCoord WXUNUSED(y),
|
|
|
|
const wxColour& WXUNUSED(col),
|
2014-03-30 00:02:23 +00:00
|
|
|
wxFloodFillStyle WXUNUSED(style) = wxFLOOD_SURFACE) wxOVERRIDE
|
2007-07-11 20:42:37 +00:00
|
|
|
{
|
|
|
|
wxFAIL_MSG(wxT("wxSVGFILEDC::DoFloodFill Call not implemented"));
|
|
|
|
return false;
|
|
|
|
}
|
2002-06-19 09:17:46 +00:00
|
|
|
|
2014-03-30 00:02:23 +00:00
|
|
|
virtual void DoGetSize(int * x, int *y) const wxOVERRIDE
|
2007-07-11 20:42:37 +00:00
|
|
|
{
|
|
|
|
if ( x )
|
|
|
|
*x = m_width;
|
|
|
|
if ( y )
|
|
|
|
*y = m_height;
|
|
|
|
}
|
2002-06-19 09:17:46 +00:00
|
|
|
|
2007-07-11 20:42:37 +00:00
|
|
|
virtual void DoGetTextExtent(const wxString& string, wxCoord *w, wxCoord *h,
|
|
|
|
wxCoord *descent = NULL,
|
|
|
|
wxCoord *externalLeading = NULL,
|
2014-03-30 00:02:23 +00:00
|
|
|
const wxFont *font = NULL) const wxOVERRIDE;
|
2002-06-19 09:17:46 +00:00
|
|
|
|
2014-03-30 00:02:23 +00:00
|
|
|
virtual void DoSetDeviceClippingRegion(const wxRegion& WXUNUSED(region)) wxOVERRIDE
|
2007-07-11 20:42:37 +00:00
|
|
|
{
|
2008-06-08 01:45:56 +00:00
|
|
|
wxFAIL_MSG(wxT("wxSVGFILEDC::DoSetDeviceClippingRegion not yet implemented"));
|
2007-09-24 09:30:24 +00:00
|
|
|
}
|
|
|
|
|
2014-03-30 00:02:23 +00:00
|
|
|
virtual void DoSetClippingRegion(int x, int y, int width, int height) wxOVERRIDE;
|
2002-06-19 09:17:46 +00:00
|
|
|
|
2014-03-30 00:02:23 +00:00
|
|
|
virtual void DoGetSizeMM( int *width, int *height ) const wxOVERRIDE;
|
2009-08-21 10:41:26 +00:00
|
|
|
|
2014-03-30 00:02:23 +00:00
|
|
|
virtual wxSize GetPPI() const wxOVERRIDE;
|
2007-09-24 09:30:24 +00:00
|
|
|
|
|
|
|
void Init (const wxString &filename, int width, int height, double dpi);
|
2002-06-19 09:17:46 +00:00
|
|
|
|
2007-07-11 20:42:37 +00:00
|
|
|
void write( const wxString &s );
|
2007-05-01 21:28:29 +00:00
|
|
|
|
|
|
|
private:
|
2012-09-15 23:19:11 +00: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();
|
|
|
|
|
2012-10-24 23:40:41 +00:00
|
|
|
// Open a new graphics group setting up all the attributes according to
|
|
|
|
// their current values in wxDC.
|
|
|
|
void DoStartNewGraphics();
|
|
|
|
|
2007-07-11 20:42:37 +00:00
|
|
|
wxFileOutputStream *m_outfile;
|
|
|
|
wxString m_filename;
|
|
|
|
int m_sub_images; // number of png format images we have
|
|
|
|
bool m_OK;
|
2012-09-15 23:19:11 +00:00
|
|
|
bool m_graphics_changed; // set by Set{Brush,Pen}()
|
2007-07-11 20:42:37 +00:00
|
|
|
int m_width, m_height;
|
2007-09-24 09:30:24 +00:00
|
|
|
double m_dpi;
|
2014-02-22 17:26:27 +00:00
|
|
|
wxSVGBitmapHandler* m_bmp_handler; // class to handle bitmaps
|
2007-07-11 20:42:37 +00:00
|
|
|
|
2012-10-24 23:40:41 +00: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;
|
|
|
|
|
2007-11-30 13:48:22 +00:00
|
|
|
DECLARE_ABSTRACT_CLASS(wxSVGFileDCImpl)
|
2007-09-24 09:30:24 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class WXDLLIMPEXP_CORE wxSVGFileDC : public wxDC
|
|
|
|
{
|
|
|
|
public:
|
2009-08-21 10:41:26 +00:00
|
|
|
wxSVGFileDC(const wxString& filename,
|
2007-11-30 20:56:12 +00:00
|
|
|
int width = 320,
|
|
|
|
int height = 240,
|
|
|
|
double dpi = 72.0)
|
|
|
|
: wxDC(new wxSVGFileDCImpl(this, filename, width, height, dpi))
|
2009-08-21 10:41:26 +00:00
|
|
|
{
|
2007-09-24 09:30:24 +00:00
|
|
|
}
|
2014-02-22 17:26:27 +00:00
|
|
|
|
|
|
|
// wxSVGFileDC-specific methods:
|
|
|
|
|
|
|
|
// Use a custom bitmap handler: takes ownership of the handler.
|
|
|
|
void SetBitmapHandler(wxSVGBitmapHandler* handler);
|
2002-06-19 09:17:46 +00:00
|
|
|
};
|
|
|
|
|
2007-07-11 20:52:41 +00:00
|
|
|
#endif // wxUSE_SVG
|
|
|
|
|
2007-07-11 20:42:37 +00:00
|
|
|
#endif // _WX_DCSVG_H_
|