wxArt2D
parssvg.h
Go to the documentation of this file.
1 /*! \file wx/svgio/parssvg.h
2  \brief SVG loader and saver of a wxCanvasDocument
3  \author Klaas Holwerda
4 
5  Copyright: 2000-2004 (c) Klaas Holwerda
6 
7  Licence: wxWidgets Licence
8 
9  RCS-ID: $Id: parssvg.h,v 1.17 2009/05/15 16:34:28 titato Exp $
10 */
11 
12 #ifndef _WX_CANVASSVGIO_H_
13 #define _WX_CANVASSVGIO_H_
14 
15 #include <map>
16 #include "wx/canvas/xmlpars.h"
17 #include "wx/canvas/layerinf.h"
18 #include "wx/canvas/canprop.h"
19 #include "wx/canvas/vpath.h"
20 #include "wx/canvas/polygon.h"
21 #include "wx/editor/candoc.h"
22 
23 #if wxART2D_USE_SVGIO
24 
25 #if (wxART2D_USE_XMLPARSE == 0)
26 #error Cannot build with SVG support without XMLPARSE module
27 #else
28 #include "wx/xmlparse/genxmlpars.h"
29 #include "wx/xmlparse/xmlencode.h"
30 #endif
31 
32 using namespace std;
33 
34 class a2dCanvasDocument;
35 
36 //! input handler for the SVG format
37 /*!
38  \ingroup fileio svgfileio
39 */
40 class A2DCANVASDLLEXP a2dIOHandlerSVGIn : public a2dIOHandlerXMLPull
41 {
42 public:
43 
45 
47 
48  virtual bool CanLoad( a2dDocumentInputStream& stream, const wxObject* obj = NULL, wxClassInfo* docClassInfo = NULL );
49 
50  virtual bool Load( a2dDocumentInputStream& stream , wxObject* doc );
51 
52 protected:
53 
54  bool LoadSvg( a2dCanvasDocument* doc );
55  bool LoadSvgGroup( a2dCanvasObject* parent );
56  bool LoadSvgAnchor( a2dCanvasObject* parent );
57  bool LoadSvgGroupElement( a2dCanvasObject* parent );
58 
59  bool LoadSvgRect( a2dCanvasObject* parent );
60 
61  bool LoadSvgCircle( a2dCanvasObject* parent );
62 
63  bool LoadSvgEllipse( a2dCanvasObject* parent );
64 
65  bool LoadSvgText( a2dCanvasObject* parent );
66 
67  bool ParsePoints( a2dVertexList* points );
68 
69  bool LoadSvgPolygon( a2dCanvasObject* parent );
70 
71  bool LoadSvgPolyline( a2dCanvasObject* parent );
72 
73  bool LoadSvgLine( a2dCanvasObject* parent );
74 
75  bool ParsePathPoints( a2dVpath* points );
76 
77  bool LoadSvgPath( a2dCanvasObject* parent );
78 
79  bool LoadSvgImage( a2dCanvasObject* parent );
80 
81  bool ParseSvgTransForm( a2dCanvasObject* parent );
82 
83  bool ParseSvgStyle( a2dCanvasObject* parent );
84 
85  bool ParseSvgLink( a2dCanvasObject* parent );
86 
87  //! the document to store/load the data found into
89 
90  //current object under creation
91  a2dCanvasObjectPtr m_currentobject;
92 
93  //! currentfill style
95 
96  //! currentstroke style
98 };
99 
100 //! output handler for the SVG format
101 /*!
102  \ingroup fileio svgfileio
103 */
104 class A2DCANVASDLLEXP a2dIOHandlerSVGOut : public a2dIOHandlerXMLWrite
105 {
106 public:
107 
109 
111 
112  //! document will be saved as seen from this object, if NULL, the root of the document will be used.
113  void SetShowObject( a2dCanvasObject* showObject ) { m_showObject = showObject; };
114 
115  //!return pointer of the currently set object to save.
116  /*!
117  \return: pointer to the current object that is shown.
118  */
119  a2dCanvasObject* GetShowObject() const { return m_showObject; }
120 
121  void SetIterC( a2dIterC& ic ) { m_ic = &ic; }
122 
123  bool CanSave( const wxObject* obj = NULL );
124 
125  virtual bool Save( a2dDocumentOutputStream& stream, const wxObject* doc );
126 
127 protected:
128  void Save( const a2dCanvasObject* object, int layer );
129  void SetSVGStyle( const a2dFill& fill, const a2dStroke& stroke, const a2dCanvasObject* object, int layer );
130  void SaveGradient( const a2dFill& fill, const a2dCanvasObject* object );
131 
132  //! Generates a quadratic spline path in SVG from a set of points representing the control polygon. This correctly renders the spline in the same way as the drawers for both polylines and polygons.
133  void CreateSVGSpline( const a2dVertexList* vertexList, bool asPolygon = false, const wxString& style = _T( "" ) );
134  void CreateSVGSpline( const a2dVertexArray* vertexArray, bool asPolygon = false, const wxString& style = _T( "" ) );
135 
136  //! Generates SVG XML code for different types of canvas objects
137  void DoSave( const a2dCanvasObject* object, int layer );
138 
139  void DoSaveProperty( const a2dCanvasObject* object, const a2dNamedProperty* property, int layer );
140 
141  wxString UniqueName( wxString baseName );
142 
143  //! the document to store/load the data found into
145 
146  //current object under creation
147  a2dCanvasObjectPtr m_currentobject;
148 
149  //! currentfill style
151 
152  //! currentstroke style
154 
155  a2dIterC* m_ic;
156 
157  //! save the document from this object down.
159 
160  map<wxString, int> m_nameMap;
161 };
162 #endif //wxART2D_USE_SVGIO
163 
164 #endif
a2dStroke m_stroke
currentstroke style
Definition: parssvg.h:97
(In) Visible property that can be added to Docview Objects.
Definition: gen.h:1785
Base class for all types of strokes, understood by a2dDrawer2D classes.
Definition: stylebase.h:378
a2dCanvasDocument * m_doc
the document to store/load the data found into
Definition: parssvg.h:144
a2dCanvasObject * m_showObject
save the document from this object down.
Definition: parssvg.h:158
output handler for the SVG format
Definition: parssvg.h:104
a2dIOHandlerCVGIn and a2dIOHandlerCVGOut - XML I/O classes for the CVG format.
wxOutputStream a2dDocumentOutputStream
output stream based wxStreams
Definition: gen.h:3458
vertex array of line and arc segments.
Definition: polyver.h:494
a2dCanvasObject is the base class for Canvas Objects.
Definition: canobj.h:371
vertex list of line and arc segments.
Definition: polyver.h:600
vector path a2dVectorPath derived from a2dCanvasObject
void SetShowObject(a2dCanvasObject *showObject)
document will be saved as seen from this object, if NULL, the root of the document will be used...
Definition: parssvg.h:113
XML I/O classes which is Pull parser based for reading XML files.
a2dFill m_fill
currentfill style
Definition: parssvg.h:150
input handler for the SVG format
Definition: parssvg.h:40
a2dFill m_fill
currentfill style
Definition: parssvg.h:94
layer settings for a a2dCanvasDocument Holds layers settings classes
a2dCanvasDocument * m_doc
the document to store/load the data found into
Definition: parssvg.h:88
functions for encoding characters in xml
properties specific for a2dCanvasOject
a2dCanvasObject * GetShowObject() const
return pointer of the currently set object to save.
Definition: parssvg.h:119
while iterating a a2dCanvasDocument, this holds the context.
Definition: canobj.h:3212
wxInputStream a2dDocumentInputStream
input stream based wxStreams
Definition: gen.h:3456
a2dStroke m_stroke
currentstroke style
Definition: parssvg.h:153
Each a2dCanvasView needs to have a a2dCanvasDocument set in order to render data. ...
Definition: candoc.h:374
Input and output handler for XML alike files.
Definition: genxmlpars.h:308
for writing XML files.
Definition: genxmlpars.h:576
all polygon and polyline a2dCanvasObject are here.
Vector Path.
Definition: polyver.h:1211
parssvg.h Source File -- Sun Oct 12 2014 17:04:23 -- Sun Oct 12 2014 -- 1.8.5 -- wxArt2D -- . -- Main Page Reference Documentation