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
14 ** This package is free software; you can redistribute it and/or
15 ** modify it under the terms of the GNU General Public License as
16 ** published by the Free Software Foundation; either version 2 of
17 ** the License, or (at your option) any later version.
19 ** This package is distributed in the hope that it will be useful,
20 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
21 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
22 ** General Public License for more details.
25 /* ========================================================================= */
27 /* === S T A R T =========================================================== */
29 #ifndef __SVG_PARSER_H
30 #define __SVG_PARSER_H
32 /* === H E A D E R S ======================================================= */
39 #include <libxml++/libxml++.h>
41 #include <ETL/stringf>
42 #include <synfig/canvas.h>
43 #include <synfig/loadcanvas.h>
44 #include <synfig/color.h>
45 #include <synfig/gamma.h>
46 #include <synfig/guid.h>
48 /* === M A C R O S ========================================================= */
50 /* === T Y P E D E F S ===================================================== */
52 /* === C L A S S E S & S T R U C T S ======================================= */
56 typedef struct matrix_t{
61 typedef struct stop_t{
66 typedef struct linear_g{
69 std::list<ColorStop*> *stops; //paradas de color
71 typedef struct radial_g{
73 float cx,cy;//center point
75 //focus, i dont see it in synfig
76 //if this value is omitted then will be = cx,cy
77 float r; //radio radius
78 std::list<ColorStop*> *stops; //paradas de color
86 typedef struct vertice_t{
94 //this is inkscape oriented in some cases
101 xmlpp::DomParser parser;
102 xmlpp::Document document;
103 xmlpp::Element* nodeRoot;//output
105 Glib::ustring height;
106 Glib::ustring docname;
112 std::list<LinearGradient*> lg;
113 std::list<RadialGradient*> rg;
117 Canvas::Handle load_svg_canvas(std::string _filepath,String &errors, String &warnings);
119 //void set_id(String source);
121 private: //parser bucle
122 void parser_node(const xmlpp::Node* node);
124 void parser_svg(const xmlpp::Node* node);
125 void parser_canvas(const xmlpp::Node* node);
127 void parser_graphics(const xmlpp::Node* node,xmlpp::Element* root,String parent_style,Matrix* mtx_parent);
128 void rect_simple(const xmlpp::Element* nodeElement,xmlpp::Element* root,String fill, String fill_opacity, String opacity);
129 void parser_layer(const xmlpp::Node* node,xmlpp::Element* root,String parent_style,Matrix* mtx);
130 std::list<std::list<Vertice*> > parser_polygon_path(Glib::ustring polygon_points, Matrix* mtx);
131 void parser_effects(const xmlpp::Element* nodeElement,xmlpp::Element* root,String parent_style,Matrix* mtx);
133 void parser_defs(const xmlpp::Node* node);
134 void parser_linearGradient(const xmlpp::Node* node);
135 void parser_radialGradient(const xmlpp::Node* node);
136 ColorStop* newColorStop(String color,float opacity,float pos);
137 LinearGradient* newLinearGradient(String name,float x1,float y1, float x2,float y2,std::list<ColorStop*> *stops);
138 RadialGradient* newRadialGradient(String name,float cx,float cy,float r,std::list<ColorStop*> *stops);
140 void AdjustPointUrl();
141 std::list<ColorStop*>* find_colorStop(String name);
142 void build_url(xmlpp::Element* root, String name,Matrix *mtx);
143 void build_linearGradient(xmlpp::Element* root,LinearGradient* data,Matrix* mtx);
144 void build_radialGradient(xmlpp::Element* root,RadialGradient* data,Matrix* mtx);
145 void build_stop_color(xmlpp::Element* root, std::list<ColorStop*> *stops);
146 void build_stop_color(xmlpp::Element* root, std::list<ColorStop*> *stops,String name);
147 Color adjustGamma(float r,float g,float b,float a);
149 void build_gamma(xmlpp::Element* root,float gamma);
150 Matrix* build_transform(const String transform);
151 void build_rotate(xmlpp::Element* root,float dx,float dy,float angle);
152 void build_translate(xmlpp::Element* root,float dx,float dy);
153 void build_points(xmlpp::Element* root,std::list<Vertice*> p);
154 void build_vertice(xmlpp::Element* root , Vertice *p);
155 void build_bline(xmlpp::Element* root,std::list<Vertice*> p,bool loop,String blinegui);
156 void build_param (xmlpp::Element* root,String name,String type,String value);
157 void build_param (xmlpp::Element* root,String name,String type,float value);
158 void build_param (xmlpp::Element* root,String name,String type,int value);
159 void build_integer (xmlpp::Element* root,String name, int value);
160 void build_real (xmlpp::Element* root,String name,float value);
161 void build_vector (xmlpp::Element* root,String name,float x,float y);
162 void build_vector (xmlpp::Element* root,String name,float x,float y,String guid);
163 void build_color(xmlpp::Element* root,float r,float g,float b,float a);
164 xmlpp::Element* nodeStartBasicLayer(xmlpp::Element* root);
167 void coor2vect(float *x,float *y);
168 void setTg2(Vertice* p,float p1x,float p1y,float p2x,float p2y);
169 void setTg1(Vertice *p,float p1x,float p1y,float p2x,float p2y);
170 void setSplit(Vertice* p,bool val);
171 int isFirst(Vertice* nodo,float a, float b);
172 Vertice* newVertice(float x,float y);
175 Matrix* newMatrix(float a,float b,float c,float d,float e,float f);
176 Matrix* newMatrix(const String mvector);
177 Matrix* newMatrix(Matrix *a);
178 void transformPoint2D(Matrix *mtx,float *a,float *b);
179 bool matrixIsNull(Matrix* mtx);
180 void composeMatrix(Matrix **mtx,Matrix *mtx1,Matrix *mtx2);
181 void multiplyMatrix(Matrix **mtx1,Matrix *mtx2);
182 float getRadian(float sexa);
184 int extractSubAttribute(const String attribute, String name,String* value);
185 String loadAttribute(String name,const String path_style,const String master_style,const String subattribute,const String defaultVal);
186 String loadAttribute(String name,const String path_style,const String master_style,const String defaultVal);
187 std::vector<String> get_tokens_path(String path);
188 std::list<std::list<Vertice*> > parser_path_d(String path_d,Matrix* mtx);
190 int getRed(String hex);
191 int getGreen(String hex);
192 int getBlue(String hex);
193 int hextodec(String hex);
194 float getDimension(const String ac);
196 void removeS(String *input);
197 void removeIntoS(String *input);
198 std::vector<String> tokenize(const String& str,const String& delimiters);
199 void get_canvas_name(String _filepath);
202 // END of Svg_parser class
204 /* === E X T E R N S ======================================================= */
206 extern Canvas::Handle open_svg(std::string _filepath,String &errors, String &warnings);
208 }; // END of namespace synfig
210 /* === E N D =============================================================== */