Version: 3.3.4
Loading...
Searching...
No Matches
wxSVGGraphicsContext Class Reference

#include <wx/svggc.h>

Inheritance diagram for wxSVGGraphicsContext:

Detailed Description

wxSVGGraphicsContext is a specialized wxGraphicsContext that allows drawing to an SVG file using the wxGraphicsContext API.

This context provides access to advanced vector features not available in the standard wxDC API, such as cubic and quadratic Bézier curves, gradient brushes, and alpha blending.

This context is used when using wxGraphicsContext on a wxSVGFileDC.

Example of use:

wxSVGGraphicsContext gc("output.svg", 800, 600);
gc.SetPen(*wxRED_PEN);
gc.SetBrush(*wxCYAN_BRUSH);
gc.DrawRectangle(10, 10, 100, 100);
// Draw a Bézier curve
wxGraphicsPath path = gc.CreatePath();
path.MoveToPoint(150, 50);
path.AddCurveToPoint(200, 0, 250, 100, 300, 50);
gc.StrokePath(path);
wxBrush * wxCYAN_BRUSH
Cyan brush.
Definition brush.h:326
A wxGraphicsPath is a native representation of a geometric path.
Definition graphics.h:21
virtual void AddCurveToPoint(wxDouble cx1, wxDouble cy1, wxDouble cx2, wxDouble cy2, wxDouble x, wxDouble y)
Adds a cubic Bézier curve from the current point, using two control points and an end point.
virtual void MoveToPoint(wxDouble x, wxDouble y)
Begins a new subpath at (x,y).
wxSVGGraphicsContext(wxSVGFileDC &dc)
Constructor.
wxPen * wxRED_PEN
Red pen.
Definition pen.h:597

Library:  wxCore
Category:  Graphics Device Interface (GDI)
Since
3.3.3

Public Member Functions

 wxSVGGraphicsContext (wxSVGFileDC &dc)
 Constructor.
 wxSVGGraphicsContext (const wxString &filename, int width=320, int height=240, double dpi=wxSVG_DEFAULT_DPI, const wxString &title=wxString())
 Constructor for creating an SVG file directly.
 wxSVGGraphicsContext (const wxSize &size, const wxString &filename=wxString(), const wxString &title=wxString(), double dpi=wxSVG_DEFAULT_DPI)
 Constructor for creating an SVG file directly.
wxString GetSVGDocument () const
 Returns the SVG document as a string.
bool Save ()
 Writes the document to the configured filename.
void SetBitmapHandler (wxSVGBitmapHandler *handler)
 Sets a handler for bitmap processing (e.g., embedding).
virtual void * GetNativeContext () override
 This method is not applicable to the SVG renderer and always returns nullptr.
virtual bool SetAntialiasMode (wxAntialiasMode antialias) override
 Sets the antialiasing mode.
virtual bool SetInterpolationQuality (wxInterpolationQuality interpolation) override
 Sets the interpolation quality.
virtual bool SetCompositionMode (wxCompositionMode op) override
 Sets the composition mode.
Paint state
virtual void SetPen (const wxGraphicsPen &pen) override
 Sets the pen used for stroking.
virtual void SetBrush (const wxGraphicsBrush &brush) override
 Sets the brush for filling paths.
Public Member Functions inherited from wxGraphicsContext
virtual void ResetClip ()=0
 Resets the clipping to original shape.
virtual void Clip (const wxRegion &region)=0
 Sets the clipping region to the intersection of the given region and the previously set clipping region.
virtual void Clip (wxDouble x, wxDouble y, wxDouble w, wxDouble h)=0
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
void Clip (const wxRect2DDouble &rect)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
virtual void GetClipBox (wxDouble *x, wxDouble *y, wxDouble *w, wxDouble *h)=0
 Returns a bounding box of the current clipping region.
wxRect2DDouble GetClipBox ()
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
virtual wxGraphicsMatrix CreateMatrix (wxDouble a=1.0, wxDouble b=0.0, wxDouble c=0.0, wxDouble d=1.0, wxDouble tx=0.0, wxDouble ty=0.0) const
 Creates a native affine transformation matrix from the passed-in values.
wxGraphicsMatrix CreateMatrix (const wxAffineMatrix2DBase &mat) const
 Creates a native affine transformation matrix from the passed generic one.
virtual void ConcatTransform (const wxGraphicsMatrix &matrix)=0
 Concatenates the passed-in transform with the current transform of this context.
virtual wxGraphicsMatrix GetTransform () const =0
 Gets the current transformation matrix of this context.
virtual void Rotate (wxDouble angle)=0
 Rotates the current transformation matrix (in radians).
virtual void Scale (wxDouble xScale, wxDouble yScale)=0
 Scales (i.e., shrinks or grows) the current transformation matrix.
virtual void SetTransform (const wxGraphicsMatrix &matrix)=0
 Sets the current transformation matrix of this context.
virtual void Translate (wxDouble dx, wxDouble dy)=0
 Translates (i.e., moves) the current transformation matrix.
void Translate (const wxPoint2DDouble &pt)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
virtual wxGraphicsBrush CreateBrush (const wxBrush &brush) const
 Creates a native brush from a wxBrush.
wxGraphicsBrush CreateLinearGradientBrush (wxDouble x1, wxDouble y1, wxDouble x2, wxDouble y2, const wxColour &c1, const wxColour &c2, const wxGraphicsMatrix &matrix=wxNullGraphicsMatrix) const
 Creates a native brush with a linear gradient.
wxGraphicsBrush CreateLinearGradientBrush (wxDouble x1, wxDouble y1, wxDouble x2, wxDouble y2, const wxGraphicsGradientStops &stops, const wxGraphicsMatrix &matrix=wxNullGraphicsMatrix) const
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
virtual wxGraphicsBrush CreateRadialGradientBrush (wxDouble startX, wxDouble startY, wxDouble endX, wxDouble endY, wxDouble radius, const wxColour &oColor, const wxColour &cColor, const wxGraphicsMatrix &matrix=wxNullGraphicsMatrix) const
 Creates a native brush with a radial gradient.
virtual wxGraphicsBrush CreateRadialGradientBrush (wxDouble startX, wxDouble startY, wxDouble endX, wxDouble endY, wxDouble radius, const wxGraphicsGradientStops &stops, const wxGraphicsMatrix &matrix=wxNullGraphicsMatrix)=0
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
void SetBrush (const wxBrush &brush)
 Sets the brush for filling paths.
wxGraphicsPen CreatePen (const wxPen &pen) const
 Creates a native pen from a wxPen.
wxGraphicsPen CreatePen (const wxGraphicsPenInfo &info) const
 Creates a native pen from a wxGraphicsPenInfo.
void SetPen (const wxPen &pen)
 Sets the pen used for stroking.
virtual void DrawBitmap (const wxGraphicsBitmap &bmp, wxDouble x, wxDouble y, wxDouble w, wxDouble h)=0
 Draws the bitmap.
virtual void DrawBitmap (const wxBitmap &bmp, wxDouble x, wxDouble y, wxDouble w, wxDouble h)=0
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
void DrawBitmap (const wxGraphicsBitmap &bmp, const wxRect2DDouble &rect)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
virtual void DrawEllipse (wxDouble x, wxDouble y, wxDouble w, wxDouble h)
 Draws an ellipse.
void DrawEllipse (const wxRect2DDouble &rect)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
virtual void DrawIcon (const wxIcon &icon, wxDouble x, wxDouble y, wxDouble w, wxDouble h)=0
 Draws the icon.
void DrawIcon (const wxIcon &icon, const wxRect2DDouble &rect)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
virtual void DrawLines (size_t n, const wxPoint2DDouble *points, wxPolygonFillMode fillStyle=wxODDEVEN_RULE)
 Draws a polygon.
virtual void DrawPath (const wxGraphicsPath &path, wxPolygonFillMode fillStyle=wxODDEVEN_RULE)
 Draws the path by first filling and then stroking.
virtual void DrawRectangle (wxDouble x, wxDouble y, wxDouble w, wxDouble h)
 Draws a rectangle.
void DrawRectangle (const wxRect2DDouble &rect)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
virtual void DrawRoundedRectangle (wxDouble x, wxDouble y, wxDouble w, wxDouble h, wxDouble radius)
 Draws a rounded rectangle.
void DrawRoundedRectangle (const wxRect2DDouble &rect, wxDouble radius)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
void DrawText (const wxString &str, wxDouble x, wxDouble y)
 Draws text at the defined position.
void DrawText (const wxString &str, const wxPoint2DDouble &pt)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
void DrawText (const wxString &str, wxDouble x, wxDouble y, wxDouble angle)
 Draws text at the defined position.
void DrawText (const wxString &str, wxDouble x, wxDouble y, const wxGraphicsBrush &backgroundBrush)
 Draws text at the defined position.
void DrawText (const wxString &str, wxDouble x, wxDouble y, wxDouble angle, const wxGraphicsBrush &backgroundBrush)
 Draws text at the defined position.
virtual void ClearRectangle (wxDouble x, wxDouble y, wxDouble w, wxDouble h)
 Paints a transparent rectangle (only useful for bitmaps or windows).
void ClearRectangle (const wxRect2DDouble &rect)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
wxGraphicsPath CreatePath () const
 Creates a native graphics path which is initially empty.
virtual void FillPath (const wxGraphicsPath &path, wxPolygonFillMode fillStyle=wxODDEVEN_RULE)=0
 Fills the path with the current brush.
virtual void StrokeLine (wxDouble x1, wxDouble y1, wxDouble x2, wxDouble y2)
 Strokes a single line.
void StrokeLine (const wxPoint2DDouble &pt1, const wxPoint2DDouble &pt2)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
virtual void StrokeLines (size_t n, const wxPoint2DDouble *beginPoints, const wxPoint2DDouble *endPoints)
 Stroke disconnected lines from begin to end points, using the fastest method available.
virtual void StrokeLines (size_t n, const wxPoint2DDouble *points)
 Stroke lines connecting all the points.
virtual void StrokePath (const wxGraphicsPath &path)=0
 Strokes along a path with the current pen.
virtual wxGraphicsFont CreateFont (const wxFont &font, const wxColour &col= *wxBLACK) const
 Creates a native graphics font from a wxFont and a text colour.
virtual wxGraphicsFont CreateFont (double sizeInPixels, const wxString &facename, int flags=wxFONTFLAG_DEFAULT, const wxColour &col= *wxBLACK) const
 Creates a font object with the specified attributes.
void SetFont (const wxFont &font, const wxColour &colour)
 Sets the font for drawing text.
virtual void SetFont (const wxGraphicsFont &font)
 Sets the font for drawing text.
virtual void GetPartialTextExtents (const wxString &text, wxArrayDouble &widths) const =0
 Fills the widths array with the widths from the beginning of text to the corresponding character of text.
virtual void GetTextExtent (const wxString &text, wxDouble *width, wxDouble *height, wxDouble *descent, wxDouble *externalLeading) const =0
 Gets the dimensions of the string using the currently selected font.
virtual bool StartDoc (const wxString &message)
 Begin a new document (relevant only for printing / pdf / etc.) If there is a progress dialog, message will be shown.
virtual void EndDoc ()
 Done with that document (relevant only for printing / pdf / etc.).
virtual void StartPage (wxDouble width=0, wxDouble height=0)
 Opens a new page (relevant only for printing / pdf etc.) with the given size in points.
virtual void EndPage ()
 Ends the current page (relevant only for printing / pdf / etc.).
virtual wxGraphicsBitmap CreateBitmap (const wxBitmap &bitmap)=0
 Creates wxGraphicsBitmap from an existing wxBitmap.
virtual wxGraphicsBitmap CreateBitmapFromImage (const wxImage &image)
 Creates wxGraphicsBitmap from an existing wxImage.
virtual wxGraphicsBitmap CreateSubBitmap (const wxGraphicsBitmap &bitmap, wxDouble x, wxDouble y, wxDouble w, wxDouble h)=0
 Extracts a sub-bitmap from an existing bitmap.
virtual void BeginLayer (wxDouble opacity)=0
 All rendering will be done into a fully transparent, temporary context.
virtual void EndLayer ()=0
 Composites back the drawings into the context with the opacity given at the BeginLayer() call.
virtual void PushState ()=0
 Push the current state (like transformations, clipping region and quality settings) of the context on a stack.
virtual void PopState ()=0
 Sets current state of the context to the state saved by a preceding call to PushState() and removes that state from the stack of saved states.
virtual void Flush ()
 Make sure that the current content of this context is immediately visible.
virtual wxAntialiasMode GetAntialiasMode () const
 Returns the current shape antialiasing mode.
virtual wxInterpolationQuality GetInterpolationQuality () const
 Returns the current interpolation quality.
virtual wxCompositionMode GetCompositionMode () const
 Returns the current compositing operator.
void GetSize (wxDouble *width, wxDouble *height) const
 Returns the size of the graphics context in device coordinates.
virtual void GetDPI (wxDouble *dpiX, wxDouble *dpiY) const
 Returns the resolution of the graphics context in device points per inch.
wxWindow * GetWindow () const
 Returns the associated window, if any.
virtual bool ShouldOffset () const
 Helper to determine if a 0.5 offset should be applied for the drawing operation.
virtual void EnableOffset (bool enable=true)
 Indicates whether the context should try to offset for pixel boundaries.
void DisableOffset ()
 Helper to determine if a 0.5 offset should be applied for the drawing operation.
bool OffsetEnabled () const
 Helper to determine if a 0.5 offset should be applied for the drawing operation.
wxSize FromDIP (const wxSize &sz) const
 Convert DPI-independent pixel values to the value in pixels appropriate for the graphics context.
wxPoint FromDIP (const wxPoint &pt) const
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
int FromDIP (int d) const
 Convert DPI-independent value in pixels to the value in pixels appropriate for the graphics context.
wxSize ToDIP (const wxSize &sz) const
 Convert pixel values of the current graphics context to DPI-independent pixel values.
wxPoint ToDIP (const wxPoint &pt) const
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
int ToDIP (int d) const
 Convert pixel values of the current graphics context to DPI-independent pixel values.
Public Member Functions inherited from wxGraphicsObject
wxGraphicsRenderer * GetRenderer () const
 Returns the renderer that was used to create this instance, or nullptr if it has not been initialized yet.
bool IsNull () const
Public Member Functions inherited from wxObject
 wxObject ()
 Default ctor; initializes to nullptr the internal reference data.
 wxObject (const wxObject &other)
 Copy ctor.
virtual ~wxObject ()
 Destructor.
virtual wxClassInfo * GetClassInfo () const
 This virtual function is redefined for every class that requires run-time type information, when using the wxDECLARE_CLASS macro (or similar).
wxObjectRefData * GetRefData () const
 Returns the wxObject::m_refData pointer, i.e. the data referenced by this object.
bool IsKindOf (const wxClassInfo *info) const
 Determines whether this class is a subclass of (or the same class as) the given class.
bool IsSameAs (const wxObject &obj) const
 Returns true if this object has the same data pointer as obj.
void Ref (const wxObject &clone)
 Makes this object refer to the data in clone.
void SetRefData (wxObjectRefData *data)
 Sets the wxObject::m_refData pointer.
void UnRef ()
 Decrements the reference count in the associated data, and if it is zero, deletes the data.
void UnShare ()
 This is the same of AllocExclusive() but this method is public.
void operator delete (void *buf)
 The delete operator is defined for debugging versions of the library only, when the identifier __WXDEBUG__ is defined.
void * operator new (size_t size, const wxString &filename=nullptr, int lineNum=0)
 The new operator is defined for debugging versions of the library only, when the identifier __WXDEBUG__ is defined.

Static Public Member Functions

static wxGraphicsContext * Create (wxSVGFileDC &dc)
 Creates a graphics context that draws into the given SVG DC.
Static Public Member Functions inherited from wxGraphicsContext
static wxGraphicsContext * Create (wxWindow *window)
 Creates a wxGraphicsContext from a wxWindow.
static wxGraphicsContext * Create (const wxWindowDC &windowDC)
 Creates a wxGraphicsContext from a wxWindowDC.
static wxGraphicsContext * Create (const wxMemoryDC &memoryDC)
 Creates a wxGraphicsContext from a wxMemoryDC.
static wxGraphicsContext * Create (const wxPrinterDC &printerDC)
 Creates a wxGraphicsContext from a wxPrinterDC.
static wxGraphicsContext * Create (const wxEnhMetaFileDC &metaFileDC)
 Creates a wxGraphicsContext from a wxEnhMetaFileDC.
static wxGraphicsContext * CreateFromUnknownDC (wxDC &dc)
 Creates a wxGraphicsContext from a DC of unknown specific type.
static wxGraphicsContext * Create (wxImage &image)
 Creates a wxGraphicsContext associated with a wxImage.
static wxGraphicsContext * CreateFromNative (void *context)
 Creates a wxGraphicsContext from a native context.
static wxGraphicsContext * CreateFromNativeWindow (void *window)
 Creates a wxGraphicsContext from a native window.
static wxGraphicsContext * CreateFromNativeHDC (WXHDC dc)
 Creates a wxGraphicsContext from a native DC handle.
static wxGraphicsContext * Create ()
 Create a lightweight context that can be used only for measuring text.

Additional Inherited Members

Protected Member Functions inherited from wxObject
void AllocExclusive ()
 Ensure that this object's data is not shared with any other object.
virtual wxObjectRefData * CreateRefData () const
 Creates a new instance of the wxObjectRefData-derived class specific to this object and returns it.
virtual wxObjectRefData * CloneRefData (const wxObjectRefData *data) const
 Creates a new instance of the wxObjectRefData-derived class specific to this object and initializes it copying data.
Protected Attributes inherited from wxObject
wxObjectRefData * m_refData
 Pointer to an object which is the object's reference-counted data.

Constructor & Destructor Documentation

◆ wxSVGGraphicsContext() [1/3]

wxSVGGraphicsContext::wxSVGGraphicsContext ( wxSVGFileDC & dc)
explicit

Constructor.

The DC must outlive the context.

Since
3.3.3

◆ wxSVGGraphicsContext() [2/3]

wxSVGGraphicsContext::wxSVGGraphicsContext ( const wxString & filename,
int width = 320,
int height = 240,
double dpi = wxSVG_DEFAULT_DPI,
const wxString & title = wxString() )
explicit

Constructor for creating an SVG file directly.

Since
3.3.3

◆ wxSVGGraphicsContext() [3/3]

wxSVGGraphicsContext::wxSVGGraphicsContext ( const wxSize & size,
const wxString & filename = wxString(),
const wxString & title = wxString(),
double dpi = wxSVG_DEFAULT_DPI )

Constructor for creating an SVG file directly.

Since
3.3.3

Member Function Documentation

◆ Create()

wxGraphicsContext * wxSVGGraphicsContext::Create ( wxSVGFileDC & dc)
static

Creates a graphics context that draws into the given SVG DC.

Equivalent to calling wxSVGFileDC::GetGraphicsContext(). The DC must outlive the returned context.

Example:

wxSVGFileDC dc("output.svg", 800, 600);
A wxGraphicsContext instance is the object that is drawn upon.
Definition graphics.h:505
static wxGraphicsContext * Create()
Create a lightweight context that can be used only for measuring text.
A wxSVGFileDC is a device context onto which graphics and text can be drawn, and the output produced ...
Definition dcsvg.h:257
Since
3.3.3

◆ GetNativeContext()

virtual void * wxSVGGraphicsContext::GetNativeContext ( )
overridevirtual

This method is not applicable to the SVG renderer and always returns nullptr.

Implements wxGraphicsContext.

◆ GetSVGDocument()

wxString wxSVGGraphicsContext::GetSVGDocument ( ) const

Returns the SVG document as a string.

Since
3.3.3

◆ Save()

bool wxSVGGraphicsContext::Save ( )

Writes the document to the configured filename.

Returns
true if the file was written successfully, false otherwise.
Since
3.3.3

◆ SetAntialiasMode()

virtual bool wxSVGGraphicsContext::SetAntialiasMode ( wxAntialiasMode antialias)
overridevirtual

Sets the antialiasing mode.

For the SVG renderer, this method maps the wxAntialiasMode to the SVG shape-rendering attribute. (For example, wxANTIALIAS_NONE maps to wxSVG_SHAPE_RENDERING_CRISP_EDGES.)

Returns true.

Implements wxGraphicsContext.

◆ SetBitmapHandler()

void wxSVGGraphicsContext::SetBitmapHandler ( wxSVGBitmapHandler * handler)

Sets a handler for bitmap processing (e.g., embedding).

Takes ownership of the handler.

Since
3.3.3

◆ SetBrush()

virtual void wxSVGGraphicsContext::SetBrush ( const wxGraphicsBrush & brush)
overridevirtual

Sets the brush for filling paths.

Note
Stippled brush styles are not supported by the SVG renderer.

Reimplemented from wxGraphicsContext.

◆ SetCompositionMode()

virtual bool wxSVGGraphicsContext::SetCompositionMode ( wxCompositionMode op)
overridevirtual

Sets the composition mode.

For the SVG renderer, the following modes are supported:

  • wxCOMPOSITION_ADD
  • wxCOMPOSITION_DIFF
  • wxCOMPOSITION_OVER (the default)

Returns true if the mode is supported, false otherwise.

Implements wxGraphicsContext.

◆ SetInterpolationQuality()

virtual bool wxSVGGraphicsContext::SetInterpolationQuality ( wxInterpolationQuality interpolation)
overridevirtual

Sets the interpolation quality.

For the SVG renderer, this method maps the wxInterpolationQuality to the SVG shape-rendering attribute as a quality hint. (For example, wxINTERPOLATION_BEST maps to wxSVG_SHAPE_RENDERING_GEOMETRIC_PRECISION.)

Returns true.

Implements wxGraphicsContext.

◆ SetPen()

virtual void wxSVGGraphicsContext::SetPen ( const wxGraphicsPen & pen)
overridevirtual

Sets the pen used for stroking.

Note
Stippled pen styles are not supported by the SVG renderer.

Reimplemented from wxGraphicsContext.