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