//=======================================================================
- std::list<std::list<Vertice*> > k;
+
+ std::list<BLine*> k;
//if we are creating a bline
//First, create the list of vertices
}
}
- int n = k.size();
- String bline_id[n];
- String offset_id[n];
- for (int i=0;i<n;i++){
- bline_id[i]=new_guid();
- offset_id[i]=new_guid();
- }
+ std::list<BLine *>::iterator aux;
+ //int n = k.size();
- std::list<std::list<Vertice*> >::iterator aux = k.begin();
if(typeFill!=0){//region layer
- for (int i=0; aux!=k.end(); aux++){
+ for (aux = k.begin(); aux!=k.end(); aux++){
xmlpp::Element *child_region=child_fill->add_child("layer");
child_region->set_attribute("type","region");
child_region->set_attribute("active","true");
build_param (child_region->add_child("param"),"amount","real","1.0000000000");
build_param (child_region->add_child("param"),"blend_method","integer","0");
build_color (child_region->add_child("param"),getRed(fill),getGreen(fill),getBlue(fill),atof(fill_opacity.data())*atof(opacity.data()));
- build_vector (child_region->add_child("param"),"offset",0,0,offset_id[i]);
+ build_vector (child_region->add_child("param"),"offset",0,0, *(*aux)->offset_id );
build_param (child_region->add_child("param"),"invert","bool","false");
build_param (child_region->add_child("param"),"antialias","bool","true");
build_param (child_region->add_child("param"),"feather","real","0.0000000000");
if(fill_rule.compare("evenodd")==0) build_param (child_region->add_child("param"),"winding_style","integer","1");
else build_param (child_region->add_child("param"),"winding_style","integer","0");
- build_bline (child_region->add_child("param"),*aux,loop,bline_id[i]);
- i++;
+ build_bline (child_region->add_child("param"),*(*aux)->points,(*aux)->loop,*(*aux)->bline_id);
}
}
if(typeFill==2){ //gradient in onto mode (fill)
}
if(typeStroke!=0){//outline layer
- int i=0;
for (aux=k.begin(); aux!=k.end(); aux++){
xmlpp::Element *child_outline=child_stroke->add_child("layer");
child_outline->set_attribute("type","outline");
build_param (child_outline->add_child("param"),"amount","real","1.0000000000");
build_param (child_outline->add_child("param"),"blend_method","integer","0");
build_color (child_outline->add_child("param"),getRed(stroke),getGreen(stroke),getBlue(stroke),atof(stroke_opacity.data())*atof(opacity.data()));
- build_vector (child_outline->add_child("param"),"offset",0,0,offset_id[i]);
+ build_vector (child_outline->add_child("param"),"offset",0,0,*(*aux)->offset_id);
build_param (child_outline->add_child("param"),"invert","bool","false");
build_param (child_outline->add_child("param"),"antialias","bool","true");
build_param (child_outline->add_child("param"),"feather","real","0.0000000000");
//outline in nonzero
build_param (child_outline->add_child("param"),"winding_style","integer","0");
- build_bline (child_outline->add_child("param"),*aux,loop,bline_id[i]);
+ build_bline (child_outline->add_child("param"),*(*aux)->points,(*aux)->loop,*(*aux)->bline_id);
stroke_width=etl::strprintf("%f",getDimension(stroke_width)/kux);
build_param (child_outline->add_child("param"),"width","real",stroke_width);
}
build_param (child_outline->add_child("param"),"loopyness","real","1.0000000000");
build_param (child_outline->add_child("param"),"homogeneous_width","bool","true");
-
-
- i++;
}
if(typeStroke==2){ //gradient in onto mode (stroke)
parser_effects(nodeElement,child_layer,parent_style,NULL);
else
parser_effects(nodeElement,child_layer,parent_style,mtx);
-
+
}
}
}
/* === CONVERT TO PATH PARSERS ============================================= */
-std::list<std::list<Vertice*> >
+std::list<BLine *>
Svg_parser::parser_path_polygon(Glib::ustring polygon_points, Matrix* mtx){
- std::list<std::list<Vertice*> > k0;
+ std::list<BLine *> k0;
if(polygon_points.empty())
return k0;
- std::list<Vertice*> k;
+ std::list<Vertice*> points;
std::vector<String> tokens=get_tokens_path (polygon_points);
unsigned int i;
float ax,ay; ax=ay=0;
//adjust
coor2vect(&ax,&ay);
//save
- k.push_back(newVertice(ax,ay));
+ points.push_back(newVertice(ax,ay));
}
- k0.push_front(k);
+ k0.push_front(newBLine(&points, true));
return k0;
}
-std::list<std::list<Vertice*> >
+std::list<BLine *>
Svg_parser::parser_path_d(String path_d,Matrix* mtx){
- std::list<std::list<Vertice*> > k;
+ std::list<BLine *> k;
std::list<Vertice*> k1;
+
std::vector<String> tokens=get_tokens_path(path_d);
String command="M"; //the current command
float ax,ay,tgx,tgy,tgx2,tgy2;//each method
float actual_x=0,actual_y=0; //in svg coordinate space
float old_x=0,old_y=0; //needed in rare cases
float init_x=0,init_y=0; //for closepath commands
- loop=false;
for(unsigned int i=0;i<tokens.size();i++){
//if the token is a command, change the current command
//now parse the commands
if(command.compare("M")==0 || command.compare("m")==0){ //move to
- if(!k1.empty())
- k.push_front(k1);
- k1.clear();
+ if(!k1.empty()) {
+ k.push_front(newBLine(&k1, false));
+ k1.clear();
+ }
//read
actual_x+=atof(tokens.at(i).data());
i++; if(tokens.at(i).compare(",")==0) i++;
}
}
}else if(command.compare("z")==0){
- loop=true;
- if(!k1.empty())
- k.push_front(k1);
+ k.push_front(newBLine(&k1, true));
k1.clear();
if (i<tokens.size() && tokens.at(i).compare("M")!=0 && tokens.at(i).compare("m")!=0) {
//starting a new path, but not with a moveto
std::cout<<"unsupported path token: "<<tokens.at(i)<<std::endl;
}
}
- if(!k1.empty())
- k.push_front(k1); //last element
+ if(!k1.empty()) {
+ k.push_front(newBLine(&k1, false)); //last element
+ }
return k;
}
return data;
}
+BLine*
+Svg_parser::newBLine(std::list<Vertice*> *points,bool loop){
+ BLine* data;
+ data=(BLine*)malloc(sizeof(BLine));
+ //sprintf(data->name,"%s",name.data());
+ data->points=new std::list<Vertice*> (*points);
+ data->loop=loop;
+ data->bline_id=new String(new_guid());
+ data->offset_id=new String(new_guid());
+ return data;
+}
+
void
Svg_parser::build_gamma(xmlpp::Element* root,float gamma){
root->set_attribute("type","colorcorrect");
float radius2,angle2;
bool split;
}Vertice;
+
+typedef struct bline_t{
+ std::list<Vertice*> *points;
+ bool loop;
+ String* bline_id;
+ String* offset_id;
+}BLine;
+
class Svg_parser
{
//this is inkscape oriented in some cases
int uid;
int kux,set_canvas;
float ox,oy;
- bool loop;//aux :D
//urls
std::list<LinearGradient*> lg;
std::list<RadialGradient*> rg;
void parser_layer(const xmlpp::Node* node,xmlpp::Element* root,String parent_style,Matrix* mtx);
void parser_rect(const xmlpp::Element* nodeElement,xmlpp::Element* root,String fill, String fill_opacity, String opacity);
/* === CONVERT TO PATH PARSERS ==================== */
- std::list<std::list<Vertice*> > parser_path_polygon(Glib::ustring polygon_points, Matrix* mtx);
- std::list<std::list<Vertice*> > parser_path_d(String path_d,Matrix* mtx);
+ std::list<BLine *> parser_path_polygon(Glib::ustring polygon_points, Matrix* mtx);
+ std::list<BLine *> parser_path_d(String path_d,Matrix* mtx);
/* === EFFECTS PARSERS ============================ */
void parser_effects(const xmlpp::Element* nodeElement,xmlpp::Element* root,String parent_style,Matrix* mtx);
ColorStop* newColorStop(String color,float opacity,float pos);
LinearGradient* newLinearGradient(String name,float x1,float y1, float x2,float y2,std::list<ColorStop*> *stops, Matrix* transform);
RadialGradient* newRadialGradient(String name,float cx,float cy,float r,std::list<ColorStop*> *stops, Matrix* transform);
+ BLine* newBLine(std::list<Vertice*> *points,bool loop);
/* === BUILDS ===================================== */
void build_transform(xmlpp::Element* root,Matrix* mtx);