Ok,It working fine.
void write_coordinates(SPObject *obj,FILE *fp) { if(!SP_IS_ITEM(obj)) return ;
Inkscape::XML::Node *path= obj->getRepr(); if (path->name() != Glib::ustring("svg:path")) return;
gchar const *svgd = path->attribute("d");
if ( path != NULL ) { Geom::PathVector pathv = sp_svg_read_pathv(svgd); for (Geom::PathVector::const_iterator pit = pathv.begin(); pit != pathv.end(); ++pit) { Geom::Point p = pit->front().initialPoint(); fprintf(fp,"MoveTo: %f,%f \n ", p[0],p[1]);
for (Geom::Path::const_iterator cit = pit->begin(); cit != pit->end_closed(); ++cit) { if(Geom::LineSegment const *line_segment = dynamic_cast<Geom::LineSegment const *>(&*cit)) { // don't serialize stitch segments if (!dynamic_cast<Geom::Path::StitchSegment const *>(&*cit)) { fprintf(fp,"LineTo: %f,%f \n ", (*line_segment)[1][0], (*line_segment)[1][1] ); } } else if (Geom::CubicBezier const *cubic_bezier = dynamic_cast<Geom::CubicBezier const*>(&*cit)) { fprintf(fp,"Curve To1: %f,%f \n ",(*cubic_bezier)[1][0], (*cubic_bezier)[1][1]); fprintf(fp,"Curve To2: %f,%f \n ",(*cubic_bezier)[2][0], (*cubic_bezier)[2][1]); fprintf(fp,"Curve To3: %f,%f \n ",(*cubic_bezier)[3][0], (*cubic_bezier)[3][1]);
} else if (Geom::QuadraticBezier const *Qcubic = dynamic_cast<Geom::QuadraticBezier const*>(&*cit)) { fprintf(fp,"QuadraticBezier \n "); } } pit->closed(); }
fprintf(fp,"PATH2: %s \n ", svgd ); } } How i get each parameter of gchar const *svgd = path->attribute("d"); here i parse with above function but gives screen coordinate instead of the svg file coordinate. Please let me know how can i get original coordinate which i write in file in variable.(actually i don't want to parse string)Is there any function in inkscape ,so i can get original value directly.
Thanks
mahendra1 wrote:
Ok,Its working with following way.I used SPObject *obj = doc->getRoot(); insted of doc->getRoot()->firstChild(); But it give outPut Four line ,The first line repeat 2 times. http://old.nabble.com/file/p32080719/Data.txt Data.txt why its happen ,is there any error in code ?
void write_coordinates(SPObject *obj,FILE *fp) { if(!SP_IS_ITEM(obj)) return ;
Inkscape::XML::Node *newitem= obj->getRepr(); Inkscape::XML::Node *path = sp_repr_lookup_name(newitem, "svg:path",
-1);
if ( path != NULL ) { gchar const *svgd = path->attribute("d"); fprintf(fp,"PATH2: %s \n ", svgd ); }
}
void visit_all_objects(SPObject *obj,FILE *fp) { if (obj == NULL) return;
write_coordinates(obj, fp); // write object's coordinates to a file here SPObject *child = obj->children; for (; child; child = child->next) { visit_all_objects(child,fp); } } bool sp_file_save_as(Gtk::Window &parentWindow, gpointer /*object*/, gpointer /*data*/) { if (!SP_ACTIVE_DOCUMENT) return false;
SPDocument *doc = inkscape_active_document(); SPObject *obj = doc->getRoot();//->firstChild(); FILE *fp = fopen("D:\\Data.txt","w"); visit_all_objects(obj, fp); fclose(fp); return true;
}
One more things , How i get each parameter of gchar const *svgd = path->attribute("d"); here i try with following function but gives screen coordinate instead of the svg file coordinate. Geom::PathVector pathv = sp_svg_read_pathv(svgd); Please let me know how can i get original coordinate which i write in file in variable.(actually i don't want to parse string)Is there any function in inkscape ,so i can get original value directly.
Krzysztof KosiĆski wrote:
2011/7/16 mahendra1 <mahendra.gajera@...2640...>:
I try to implement your code in another following way .
The Input file name :drawing-1.svg http://old.nabble.com/file/p32072659/drawing-1.svg drawing-1.svg
with above code I can get only One line coordinate instead of the two line.Please check the attached output file The OutPut file name :Data1.txt http://old.nabble.com/file/p32072659/Data1.txt Data1.txt
Now how can i get next line coordinate ?
This cannot be done this way. You must define a recursive function (a function that calls itself) like I told you earlier. Please tell me what was wrong with the code I posted. If it gave an error, please post the error.
I guess the previous code could have crashed, so here is another attempt:
void write_coordinates(SPObject *obj) { Inkscape::XML::Node *path = obj->getRepr(); gchar const *svgd = path->attribute("d"); if (svgd) fprintf(fp,"PATH2: %s \n ", svgd ); }
void visit_all_objects(SPObject *obj, FILE *fp) { if (obj == NULL) return;
write_coordinates(obj, fp); // write object's coordinates to a file here SPObject *child = obj->children; for (; child; child = child->next) { visit_all_objects(child); } }
bool sp_file_save_as(Gtk::Window &parentWindow, gpointer /*object*/, gpointer /*data*/) { if (!SP_ACTIVE_DOCUMENT) return false;
SPDocument *doc = inkscape_active_document(); SPObject *obj = doc->getRoot()->firstChild();
FILE *fp = fopen("D:\Data.txt","a"); visit_all_objects(obj, fp); fclose(fp);
return true; }
Regards, Krzysztof
AppSumo Presents a FREE Video for the SourceForge Community by Eric Ries, the creator of the Lean Startup Methodology on "Lean Startup Secrets Revealed." This video shows you how to validate your ideas, optimize your ideas and identify your business strategy. http://p.sf.net/sfu/appsumosfdev2dev _______________________________________________ Inkscape-devel mailing list Inkscape-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/inkscape-devel