1 /* === S Y N F I G ========================================================= */
3 ** \brief Implementation of the Svg parser
4 ** \brief Based on SVG XML specification 1.1
5 ** \brief See: http://www.w3.org/TR/xml11/ for deatils
10 ** Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
11 ** Copyright (c) 2007, 2008 Chris Moore
12 ** Copyright (c) 2009 Carlos A. Sosa Navarro
13 ** Copyright (c) 2009 Nikita Kitaev
15 ** This package is free software; you can redistribute it and/or
16 ** modify it under the terms of the GNU General Public License as
17 ** published by the Free Software Foundation; either version 2 of
18 ** the License, or (at your option) any later version.
20 ** This package is distributed in the hope that it will be useful,
21 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
22 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
23 ** General Public License for more details.
26 /* ========================================================================= */
28 /* === S T A R T =========================================================== */
30 #ifndef __SVG_PARSER_H
31 #define __SVG_PARSER_H
33 /* === H E A D E R S ======================================================= */
40 #include <libxml++/libxml++.h>
42 #include <ETL/stringf>
43 #include <synfig/canvas.h>
44 #include <synfig/loadcanvas.h>
45 #include <synfig/color.h>
46 #include <synfig/gamma.h>
47 #include <synfig/guid.h>
49 /* === M A C R O S ========================================================= */
51 /* === T Y P E D E F S ===================================================== */
53 /* === C L A S S E S & S T R U C T S ======================================= */
57 typedef struct matrix_t{
62 typedef struct stop_t{
67 typedef struct linear_g{
70 std::list<ColorStop*> *stops;
73 typedef struct radial_g{
75 float cx,cy;//center point
76 //float fx,fy; //not supported by Synfig
78 std::list<ColorStop*> *stops;
87 typedef struct vertice_t{
95 //this is inkscape oriented in some cases
102 xmlpp::DomParser parser;
103 xmlpp::Document document;
104 xmlpp::Element* nodeRoot;//output
106 Glib::ustring height;
107 Glib::ustring docname;
113 std::list<LinearGradient*> lg;
114 std::list<RadialGradient*> rg;
118 Canvas::Handle load_svg_canvas(std::string _filepath,String &errors, String &warnings);
120 //void set_id(String source);
123 /* === PARSERS ==================================== */
124 void parser_node(const xmlpp::Node* node);
126 void parser_svg(const xmlpp::Node* node);
127 void parser_canvas(const xmlpp::Node* node);
128 void parser_graphics(const xmlpp::Node* node,xmlpp::Element* root,String parent_style,Matrix* mtx_parent);
130 /* === LAYER PARSERS ============================== */
131 void parser_layer(const xmlpp::Node* node,xmlpp::Element* root,String parent_style,Matrix* mtx);
132 void parser_rect(const xmlpp::Element* nodeElement,xmlpp::Element* root,String fill, String fill_opacity, String opacity);
133 /* === CONVERT TO PATH PARSERS ==================== */
134 std::list<std::list<Vertice*> > parser_path_polygon(Glib::ustring polygon_points, Matrix* mtx);
135 std::list<std::list<Vertice*> > parser_path_d(String path_d,Matrix* mtx);
137 /* === EFFECTS PARSERS ============================ */
138 void parser_effects(const xmlpp::Element* nodeElement,xmlpp::Element* root,String parent_style,Matrix* mtx);
140 /* === DEFS PARSERS =============================== */
141 void parser_defs(const xmlpp::Node* node);
142 void parser_linearGradient(const xmlpp::Node* node);
143 void parser_radialGradient(const xmlpp::Node* node);
144 ColorStop* newColorStop(String color,float opacity,float pos);
145 LinearGradient* newLinearGradient(String name,float x1,float y1, float x2,float y2,std::list<ColorStop*> *stops, Matrix* transform);
146 RadialGradient* newRadialGradient(String name,float cx,float cy,float r,std::list<ColorStop*> *stops, Matrix* transform);
148 /* === BUILDS ===================================== */
149 void build_transform(xmlpp::Element* root,Matrix* mtx);
150 std::list<ColorStop*>* find_colorStop(String name);
151 void build_fill(xmlpp::Element* root, String name,Matrix *mtx);
152 void build_linearGradient(xmlpp::Element* root,LinearGradient* data,Matrix* mtx);
153 void build_radialGradient(xmlpp::Element* root,RadialGradient* data,Matrix* mtx);
154 void build_stop_color(xmlpp::Element* root, std::list<ColorStop*> *stops);
155 void build_stop_color(xmlpp::Element* root, std::list<ColorStop*> *stops,String name);
156 Color adjustGamma(float r,float g,float b,float a);
158 void build_gamma(xmlpp::Element* root,float gamma);
159 void build_rotate(xmlpp::Element* root,float dx,float dy,float angle);
160 void build_translate(xmlpp::Element* root,float dx,float dy);
161 void build_points(xmlpp::Element* root,std::list<Vertice*> p);
162 void build_vertice(xmlpp::Element* root , Vertice *p);
163 void build_bline(xmlpp::Element* root,std::list<Vertice*> p,bool loop,String blinegui);
164 void build_param (xmlpp::Element* root,String name,String type,String value);
165 void build_param (xmlpp::Element* root,String name,String type,float value);
166 void build_param (xmlpp::Element* root,String name,String type,int value);
167 void build_integer (xmlpp::Element* root,String name, int value);
168 void build_real (xmlpp::Element* root,String name,float value);
169 void build_vector (xmlpp::Element* root,String name,float x,float y);
170 void build_vector (xmlpp::Element* root,String name,float x,float y,String guid);
171 void build_color(xmlpp::Element* root,float r,float g,float b,float a);
172 xmlpp::Element* nodeStartBasicLayer(xmlpp::Element* root);
174 /* === COORDINATES & TRANSFORMATIONS ============== */
177 void coor2vect(float *x,float *y);
178 void setTg2(Vertice* p,float p1x,float p1y,float p2x,float p2y);
179 void setTg1(Vertice *p,float p1x,float p1y,float p2x,float p2y);
180 void setSplit(Vertice* p,bool val);
181 int isFirst(Vertice* nodo,float a, float b);
182 Vertice* newVertice(float x,float y);
185 Matrix* parser_transform(const String transform);
186 Matrix* newMatrix(float a,float b,float c,float d,float e,float f);
187 Matrix* newMatrix(const String mvector);
188 Matrix* newMatrix(Matrix *a);
189 void transformPoint2D(Matrix *mtx,float *a,float *b);
190 bool matrixIsNull(Matrix* mtx);
191 void composeMatrix(Matrix **mtx,Matrix *mtx1,Matrix *mtx2);
192 void multiplyMatrix(Matrix **mtx1,Matrix *mtx2);
193 float getRadian(float sexa);
195 /* === EXTRA METHODS ============================== */
198 int extractSubAttribute(const String attribute, String name,String* value);
199 String loadAttribute(String name,const String path_style,const String master_style,const String subattribute,const String defaultVal);
200 String loadAttribute(String name,const String path_style,const String master_style,const String defaultVal);
201 std::vector<String> get_tokens_path(String path);
203 int getRed(String hex);
204 int getGreen(String hex);
205 int getBlue(String hex);
206 int hextodec(String hex);
207 float getDimension(const String ac);
209 void removeS(String *input);
210 void removeIntoS(String *input);
211 std::vector<String> tokenize(const String& str,const String& delimiters);
212 void get_canvas_name(String _filepath);
215 // END of Svg_parser class
217 /* === E X T E R N S ======================================================= */
219 extern Canvas::Handle open_svg(std::string _filepath,String &errors, String &warnings);
221 }; // END of namespace synfig
223 /* === E N D =============================================================== */