From e1af3a58b56295d50de07d98705bfc516556866d Mon Sep 17 00:00:00 2001 From: Nikita Kitaev Date: Sat, 7 Nov 2009 15:53:50 -0800 Subject: [PATCH] Path looping support --- synfig-core/src/modules/mod_svg/svg_parser.cpp | 74 +++++++++++++------------- synfig-core/src/modules/mod_svg/svg_parser.h | 14 +++-- 2 files changed, 49 insertions(+), 39 deletions(-) diff --git a/synfig-core/src/modules/mod_svg/svg_parser.cpp b/synfig-core/src/modules/mod_svg/svg_parser.cpp index 28b2c60..e10df9d 100644 --- a/synfig-core/src/modules/mod_svg/svg_parser.cpp +++ b/synfig-core/src/modules/mod_svg/svg_parser.cpp @@ -301,7 +301,8 @@ Svg_parser::parser_graphics(const xmlpp::Node* node,xmlpp::Element* root,String //======================================================================= - std::list > k; + + std::list k; //if we are creating a bline //First, create the list of vertices @@ -319,17 +320,11 @@ Svg_parser::parser_graphics(const xmlpp::Node* node,xmlpp::Element* root,String } } - int n = k.size(); - String bline_id[n]; - String offset_id[n]; - for (int i=0;i::iterator aux; + //int n = k.size(); - std::list >::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"); @@ -339,7 +334,7 @@ Svg_parser::parser_graphics(const xmlpp::Node* node,xmlpp::Element* root,String 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"); @@ -347,8 +342,7 @@ Svg_parser::parser_graphics(const xmlpp::Node* node,xmlpp::Element* root,String 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) @@ -359,7 +353,6 @@ Svg_parser::parser_graphics(const xmlpp::Node* node,xmlpp::Element* root,String } 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"); @@ -370,7 +363,7 @@ Svg_parser::parser_graphics(const xmlpp::Node* node,xmlpp::Element* root,String 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"); @@ -378,7 +371,7 @@ Svg_parser::parser_graphics(const xmlpp::Node* node,xmlpp::Element* root,String //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); @@ -394,9 +387,6 @@ Svg_parser::parser_graphics(const xmlpp::Node* node,xmlpp::Element* root,String } 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) @@ -409,7 +399,7 @@ Svg_parser::parser_graphics(const xmlpp::Node* node,xmlpp::Element* root,String parser_effects(nodeElement,child_layer,parent_style,NULL); else parser_effects(nodeElement,child_layer,parent_style,mtx); - + } } } @@ -495,12 +485,12 @@ Svg_parser::parser_rect(const xmlpp::Element* nodeElement,xmlpp::Element* root,S /* === CONVERT TO PATH PARSERS ============================================= */ -std::list > +std::list Svg_parser::parser_path_polygon(Glib::ustring polygon_points, Matrix* mtx){ - std::list > k0; + std::list k0; if(polygon_points.empty()) return k0; - std::list k; + std::list points; std::vector tokens=get_tokens_path (polygon_points); unsigned int i; float ax,ay; ax=ay=0; @@ -513,16 +503,17 @@ Svg_parser::parser_path_polygon(Glib::ustring polygon_points, Matrix* mtx){ //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 Svg_parser::parser_path_d(String path_d,Matrix* mtx){ - std::list > k; + std::list k; std::list k1; + std::vector tokens=get_tokens_path(path_d); String command="M"; //the current command float ax,ay,tgx,tgy,tgx2,tgy2;//each method @@ -530,7 +521,6 @@ Svg_parser::parser_path_d(String path_d,Matrix* mtx){ 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 *points,bool loop){ + BLine* data; + data=(BLine*)malloc(sizeof(BLine)); + //sprintf(data->name,"%s",name.data()); + data->points=new std::list (*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"); diff --git a/synfig-core/src/modules/mod_svg/svg_parser.h b/synfig-core/src/modules/mod_svg/svg_parser.h index 54e57b0..a65407f 100644 --- a/synfig-core/src/modules/mod_svg/svg_parser.h +++ b/synfig-core/src/modules/mod_svg/svg_parser.h @@ -90,6 +90,14 @@ typedef struct vertice_t{ float radius2,angle2; bool split; }Vertice; + +typedef struct bline_t{ + std::list *points; + bool loop; + String* bline_id; + String* offset_id; +}BLine; + class Svg_parser { //this is inkscape oriented in some cases @@ -108,7 +116,6 @@ private: int uid; int kux,set_canvas; float ox,oy; - bool loop;//aux :D //urls std::list lg; std::list rg; @@ -131,8 +138,8 @@ private: 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 > parser_path_polygon(Glib::ustring polygon_points, Matrix* mtx); - std::list > parser_path_d(String path_d,Matrix* mtx); + std::list parser_path_polygon(Glib::ustring polygon_points, Matrix* mtx); + std::list 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); @@ -144,6 +151,7 @@ private: ColorStop* newColorStop(String color,float opacity,float pos); LinearGradient* newLinearGradient(String name,float x1,float y1, float x2,float y2,std::list *stops, Matrix* transform); RadialGradient* newRadialGradient(String name,float cx,float cy,float r,std::list *stops, Matrix* transform); + BLine* newBLine(std::list *points,bool loop); /* === BUILDS ===================================== */ void build_transform(xmlpp::Element* root,Matrix* mtx); -- 2.7.4