- if(n==1 && typeStroke==2){ //gradient in onto mode (stroke)
- build_url(child_stroke->add_child("layer"),stroke,mtx);
- }
- }
- }
- if(n!=1){//only fill for several canvas in one path
- if(typeFill==2){
- build_url(root->add_child("layer"),fill,mtx);
- }
- }
-}
-
-std::vector<String>
-Svg_parser::get_tokens_path(String path){ //mini path lexico-parser
- std::vector<String> tokens;
- String buffer;
- int e=0;
- unsigned int i=0;
- char a;
- while(i<path.size()){
- a=path.at(i);
- switch(e){
- case 0: //initial state
- if(a=='m'){ e=1; i++;}
- else if(a=='c'){ e= 2; i++;}
- else if(a=='q'){ e= 3; i++;}
- else if(a=='t'){ e= 4; i++;}
- else if(a=='a'){ e= 5; i++;}
- else if(a=='l'){ e= 6; i++;}
- else if(a=='v'){ e= 7; i++;}
- else if(a=='h'){ e= 8; i++;}
- else if(a=='M'){ e= 9; i++;}
- else if(a=='C'){ e=10; i++;}
- else if(a=='Q'){ e=11; i++;}
- else if(a=='T'){ e=12; i++;}
- else if(a=='A'){ e=13; i++;}
- else if(a=='L'){ e=14; i++;}
- else if(a=='V'){ e=15; i++;}
- else if(a=='H'){ e=16; i++;}
- else if(a=='z' || a=='Z'){ e=17; i++;}
- else if(a=='-' ||a=='.'|| isdigit (a)){ e=18;}
- else if(a==','){ e=19; i++;}
- else if(a==' '){i++;}
- break;
- //relative
- case 1 : tokens.push_back("m"); e=0; break;//move
- case 2 : tokens.push_back("c"); e=0; break;//curve
- case 3 : tokens.push_back("q"); e=0; break;//quadratic
- case 4 : tokens.push_back("t"); e=0; break;//smooth quadratic
- case 5 : tokens.push_back("a"); e=0; break;//elliptic arc
- case 6 : tokens.push_back("l"); e=0; break;//line to
- case 7 : tokens.push_back("v"); e=0; break;//vertical
- case 8 : tokens.push_back("h"); e=0; break;//horizontal
- //absolute
- case 9 : tokens.push_back("M"); e=0; break;
- case 10: tokens.push_back("C"); e=0; break;
- case 11: tokens.push_back("Q"); e=0; break;
- case 12: tokens.push_back("T"); e=0; break;
- case 13: tokens.push_back("A"); e=0; break;
- case 14: tokens.push_back("L"); e=0; break;
- case 15: tokens.push_back("V"); e=0; break;
- case 16: tokens.push_back("H"); e=0; break;
-
- case 17: tokens.push_back("z"); e=0; break;//loop
- case 18: if(a=='-'||a=='.'|| isdigit (a)){
- buffer.append(path.substr(i,1));i++;
- }else{
- e=20;
- }
- break;
- case 19: tokens.push_back(","); e=0; break;
- case 20: tokens.push_back(buffer);
- buffer.clear();
- e=0; break;
- default: break;
- }
- }
- switch(e){//last element
- case 1 : tokens.push_back("m"); break;
- case 2 : tokens.push_back("c"); break;
- case 3 : tokens.push_back("q"); break;
- case 4 : tokens.push_back("t"); break;
- case 5 : tokens.push_back("a"); break;
- case 6 : tokens.push_back("l"); break;
- case 7 : tokens.push_back("v"); break;
- case 8 : tokens.push_back("h"); break;
- case 9 : tokens.push_back("M"); break;
- case 10: tokens.push_back("C"); break;
- case 11: tokens.push_back("Q"); break;
- case 12: tokens.push_back("T"); break;
- case 13: tokens.push_back("A"); break;
- case 14: tokens.push_back("L"); break;
- case 15: tokens.push_back("V"); break;
- case 16: tokens.push_back("H"); break;
- case 17: tokens.push_back("z"); break;
- case 18: tokens.push_back(buffer); break;
- case 19: tokens.push_back(","); break;
- case 20: tokens.push_back(buffer); break;
- default: break;
- }
- return tokens;
-}
-
-std::list<std::list<Vertice*> >
-Svg_parser::parser_path_d(String path_d,Matrix* mtx){
- std::list<std::list<Vertice*> > k;
- std::list<Vertice*> k1;
- float ax,ay,tgx,tgy,tgx2,tgy2;//each method
- float actual_x=0,actual_y=0;//for relative methods;
- loop=false;
- unsigned int i;
- std::vector<String> tokens=get_tokens_path(path_d);
- for(i=0;i<tokens.size();i++){
- if(tokens.at(i).compare("M")==0){//absolute move to
- if(!k1.empty())
- k.push_front(k1);
- k1.clear();
- //read
- i++; ax=atof(tokens.at(i).data());
- i++; if(tokens.at(i).compare(",")==0) i++;
- ay=atof(tokens.at(i).data());
- actual_x=ax;
- actual_y=ay;
- //operate and save
- if(mtx) transformPoint2D(mtx,&ax,&ay);
- coor2vect(&ax,&ay);
- k1.push_back(newVertice (ax,ay)); //first element
- setSplit(k1.back(),TRUE);
- }else if(tokens.at(i).compare("C")==0){ //absolute curve
- //tg2
- i++; tgx2=atof(tokens.at(i).data());
- i++; if(tokens.at(i).compare(",")==0) i++;
- tgy2=atof(tokens.at(i).data());
- //tg1
- i++; tgx=atof(tokens.at(i).data());
- i++; if(tokens.at(i).compare(",")==0) i++;
- tgy=atof(tokens.at(i).data());
- //point
- i++; ax=atof(tokens.at(i).data());
- i++; if(tokens.at(i).compare(",")==0) i++;
- ay=atof(tokens.at(i).data());
- actual_x=ax;
- actual_y=ay;
- //mtx
- if(mtx){
- transformPoint2D(mtx,&tgx2,&tgy2);
- transformPoint2D(mtx,&ax,&ay);
- transformPoint2D(mtx,&tgx,&tgy);
- }
- //adjust
- coor2vect(&tgx2,&tgy2);
- coor2vect(&ax,&ay);
- coor2vect(&tgx,&tgy);
- //save
- setTg2(k1.back(),k1.back()->x,k1.back()->y,tgx2,tgy2);
- if(isFirst(k1.front(),ax,ay)){
- setTg1(k1.front(),k1.front()->x,k1.front()->y,tgx,tgy);
- }else{
- k1.push_back(newVertice (ax,ay));
- setTg1(k1.back(),k1.back()->x,k1.back()->y,tgx,tgy);
- setSplit(k1.back(),TRUE);
- }
- }else if(tokens.at(i).compare("Q")==0){ //absolute quadractic curve
- //tg1 and tg2
- i++; tgx=ax=atof(tokens.at(i).data());
- i++; if(tokens.at(i).compare(",")==0) i++;
- tgy=ay=atof(tokens.at(i).data());
- //point
- i++; ax=atof(tokens.at(i).data());
- i++; if(tokens.at(i).compare(",")==0) i++;
- ay=atof(tokens.at(i).data());
- actual_x=ax;
- actual_y=ay;
- //mtx
- if(mtx){
- transformPoint2D(mtx,&ax,&ay);
- transformPoint2D(mtx,&tgx,&tgy);