Line data Source code
1 : /******************************************************************************
2 : * $Id$
3 : *
4 : * Project: SVG Translator
5 : * Purpose: Definition of classes for OGR .svg driver.
6 : * Author: Even Rouault, even dot rouault at spatialys.com
7 : *
8 : ******************************************************************************
9 : * Copyright (c) 2011-2013, Even Rouault <even dot rouault at spatialys.com>
10 : *
11 : * Permission is hereby granted, free of charge, to any person obtaining a
12 : * copy of this software and associated documentation files (the "Software"),
13 : * to deal in the Software without restriction, including without limitation
14 : * the rights to use, copy, modify, merge, publish, distribute, sublicense,
15 : * and/or sell copies of the Software, and to permit persons to whom the
16 : * Software is furnished to do so, subject to the following conditions:
17 : *
18 : * The above copyright notice and this permission notice shall be included
19 : * in all copies or substantial portions of the Software.
20 : *
21 : * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
22 : * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23 : * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
24 : * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25 : * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
26 : * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
27 : * DEALINGS IN THE SOFTWARE.
28 : ****************************************************************************/
29 :
30 : #ifndef OGR_SVG_H_INCLUDED
31 : #define OGR_SVG_H_INCLUDED
32 :
33 : #include "ogrsf_frmts.h"
34 :
35 : #ifdef HAVE_EXPAT
36 : #include "ogr_expat.h"
37 : #endif
38 :
39 : class OGRSVGDataSource;
40 :
41 : typedef enum
42 : {
43 : SVG_POINTS,
44 : SVG_LINES,
45 : SVG_POLYGONS,
46 : } SVGGeometryType;
47 :
48 : constexpr int PARSER_BUF_SIZE = 8192;
49 :
50 : /************************************************************************/
51 : /* OGRSVGLayer */
52 : /************************************************************************/
53 :
54 : class OGRSVGLayer final : public OGRLayer
55 : {
56 : OGRFeatureDefn *poFeatureDefn;
57 : OGRSpatialReference *poSRS;
58 : #ifdef HAVE_EXPAT
59 : OGRSVGDataSource *poDS;
60 : #endif
61 : CPLString osLayerName;
62 :
63 : SVGGeometryType svgGeomType;
64 :
65 : int nTotalFeatures;
66 : int nNextFID;
67 : VSILFILE *fpSVG; // Large file API.
68 :
69 : #ifdef HAVE_EXPAT
70 : XML_Parser oParser;
71 : XML_Parser oSchemaParser;
72 : #endif
73 : char *pszSubElementValue;
74 : int nSubElementValueLen;
75 : int iCurrentField;
76 :
77 : OGRFeature *poFeature;
78 : OGRFeature **ppoFeatureTab;
79 : int nFeatureTabLength;
80 : int nFeatureTabIndex;
81 :
82 : int depthLevel;
83 : int interestingDepthLevel;
84 : bool inInterestingElement;
85 :
86 : bool bStopParsing;
87 : #ifdef HAVE_EXPAT
88 : int nWithoutEventCounter;
89 : int nDataHandlerCounter;
90 :
91 : OGRSVGLayer *poCurLayer;
92 : #endif
93 :
94 : private:
95 : void LoadSchema();
96 :
97 : public:
98 : OGRSVGLayer(const char *pszFilename, const char *layerName,
99 : SVGGeometryType svgGeomType, OGRSVGDataSource *poDS);
100 : virtual ~OGRSVGLayer();
101 :
102 : virtual void ResetReading() override;
103 : virtual OGRFeature *GetNextFeature() override;
104 :
105 6 : virtual const char *GetName() override
106 : {
107 6 : return osLayerName.c_str();
108 : }
109 :
110 : virtual OGRwkbGeometryType GetGeomType() override;
111 :
112 : virtual GIntBig GetFeatureCount(int bForce = TRUE) override;
113 :
114 : virtual OGRFeatureDefn *GetLayerDefn() override;
115 :
116 : virtual int TestCapability(const char *) override;
117 :
118 : #ifdef HAVE_EXPAT
119 : void startElementCbk(const char *pszName, const char **ppszAttr);
120 : void endElementCbk(const char *pszName);
121 : void dataHandlerCbk(const char *data, int nLen);
122 :
123 : void startElementLoadSchemaCbk(const char *pszName, const char **ppszAttr);
124 : void endElementLoadSchemaCbk(const char *pszName);
125 : void dataHandlerLoadSchemaCbk(const char *data, int nLen);
126 : #endif
127 : };
128 :
129 : /************************************************************************/
130 : /* OGRSVGDataSource */
131 : /************************************************************************/
132 :
133 : typedef enum
134 : {
135 : SVG_VALIDITY_UNKNOWN,
136 : SVG_VALIDITY_INVALID,
137 : SVG_VALIDITY_VALID
138 : } OGRSVGValidity;
139 :
140 : class OGRSVGDataSource final : public OGRDataSource
141 : {
142 : char *pszName;
143 :
144 : OGRSVGLayer **papoLayers;
145 : int nLayers;
146 :
147 : #ifdef HAVE_EXPAT
148 : OGRSVGValidity eValidity;
149 : int bIsCloudmade;
150 : XML_Parser oCurrentParser;
151 : int nDataHandlerCounter;
152 : #endif
153 :
154 : public:
155 : OGRSVGDataSource();
156 : virtual ~OGRSVGDataSource();
157 :
158 : int Open(const char *pszFilename);
159 :
160 0 : virtual const char *GetName() override
161 : {
162 0 : return pszName;
163 : }
164 :
165 11 : virtual int GetLayerCount() override
166 : {
167 11 : return nLayers;
168 : }
169 :
170 : virtual OGRLayer *GetLayer(int) override;
171 :
172 : virtual int TestCapability(const char *) override;
173 :
174 : #ifdef HAVE_EXPAT
175 : void startElementValidateCbk(const char *pszName, const char **ppszAttr);
176 : void dataHandlerValidateCbk(const char *data, int nLen);
177 : #endif
178 : };
179 :
180 : #endif /* ndef OGR_SVG_H_INCLUDED */
|