index 7dd9dcf5e8f0cff19362e7cb3dd7a5d78e120b2d..a130b692354142786208ac3b1bd8fcfe97aa75bd 100644 (file)
*
* Authors:
* Bob Jamison <ishmal@inkscape.org>
+ * Abhishek Sharma
*
* Copyright (C) 2004-2008 Authors
*
povShapes.push_back(shapeInfo); //passed all tests. save the info
// convert the path to only lineto's and cubic curveto's:
- Geom::Matrix tf = sp_item_i2d_affine(item);
+ Geom::Matrix tf = item->i2d_affine();
Geom::PathVector pathv = pathv_to_linear_and_cubic_beziers( curve->get_pathvector() * tf );
- //Count the NR_CURVETOs/LINETOs (including closing line segment)
+ /*
+ * We need to know the number of segments (NR_CURVETOs/LINETOs, including
+ * closing line segment) before we write out segment data. Since we are
+ * going to skip degenerate (zero length) paths, we need to loop over all
+ * subpaths and segments first.
+ */
int segmentCount = 0;
- for(Geom::PathVector::const_iterator it = pathv.begin(); it != pathv.end(); ++it)
- {
- segmentCount += (*it).size();
- if (it->closed())
- segmentCount += 1;
+ /**
+ * For all Subpaths in the <path>
+ */
+ for (Geom::PathVector::const_iterator pit = pathv.begin(); pit != pathv.end(); ++pit)
+ {
+ /**
+ * For all segments in the subpath, including extra closing segment defined by 2geom
+ */
+ for (Geom::Path::const_iterator cit = pit->begin(); cit != pit->end_closed(); ++cit)
+ {
+
+ // Skip zero length segments.
+ if( !cit->isDegenerate() ) ++segmentCount;
}
+ }
out("/*###################################################\n");
out("### PRISM: %s\n", id.c_str());
nrSegments += segmentCount;
/**
- * at moment of writing, 2geom lacks proper initialization of empty intervals in rect...
- */
- Geom::Rect cminmax( pathv.front().initialPoint(), pathv.front().initialPoint() );
-
-
+ * at moment of writing, 2geom lacks proper initialization of empty intervals in rect...
+ */
+ Geom::Rect cminmax( pathv.front().initialPoint(), pathv.front().initialPoint() );
+
+
/**
* For all Subpaths in the <path>
- */
+ */
for (Geom::PathVector::const_iterator pit = pathv.begin(); pit != pathv.end(); ++pit)
{
cminmax.expandTo(pit->initialPoint());
/**
- * For all segments in the subpath
- */
+ * For all segments in the subpath, including extra closing segment defined by 2geom
+ */
for (Geom::Path::const_iterator cit = pit->begin(); cit != pit->end_closed(); ++cit)
- {
+ {
+
+ // Skip zero length segments
+ if( cit->isDegenerate() )
+ continue;
if( is_straight_curve(*cit) )
{
nrNodes += 8;
}
else if(Geom::CubicBezier const *cubic = dynamic_cast<Geom::CubicBezier const*>(&*cit))
- {
+ {
std::vector<Geom::Point> points = cubic->points();
Geom::Point p0 = points[0];
Geom::Point p1 = points[1];
nrNodes += 8;
}
else
- {
+ {
err("logical error, because pathv_to_linear_and_cubic_beziers was used");
return false;
}
out(",\n");
else
out("\n");
+ if (segmentNr > segmentCount)
+ {
+ err("Too many segments");
+ return false;
+ }
cminmax.expandTo(cit->finalPoint());
{
String id;
- if (!obj->id)
+ if (!obj->getId())
{
char buf[16];
sprintf(buf, "id%d", idIndex++);
}
else
{
- id = obj->id;
+ id = obj->getId();
}
if (SP_IS_ITEM(obj))
*/
for (SPObject *child = obj->firstChild() ; child ; child = child->next)
{
- if (!doTreeRecursive(doc, child))
- return false;
- }
+ if (!doTreeRecursive(doc, child))
+ return false;
+ }
return true;
}
/**
* Saves the Shapes of an Inkscape SVG file as PovRay spline definitions
*/
-void PovOutput::saveDocument(SPDocument *doc, gchar const *uri)
+void PovOutput::saveDocument(SPDocument *doc, gchar const *filename_utf8)
{
reset();
//# Lets do the curves first, to get the stats
if (!doTree(doc))
{
- err("Could not output curves for %s", uri);
+ err("Could not output curves for %s", filename_utf8);
return;
}
-
+
String curveBuf = outbuf;
outbuf.clear();
if (!doHeader())
{
- err("Could not write header for %s", uri);
+ err("Could not write header for %s", filename_utf8);
return;
}
if (!doTail())
{
- err("Could not write footer for %s", uri);
+ err("Could not write footer for %s", filename_utf8);
return;
}
//###### WRITE TO FILE
- Inkscape::IO::dump_fopen_call(uri, "L");
- FILE *f = Inkscape::IO::fopen_utf8name(uri, "w");
+ Inkscape::IO::dump_fopen_call(filename_utf8, "L");
+ FILE *f = Inkscape::IO::fopen_utf8name(filename_utf8, "w");
if (!f)
return;
*/
void
PovOutput::save(Inkscape::Extension::Output */*mod*/,
- SPDocument *doc, gchar const *uri)
+ SPDocument *doc, gchar const *filename_utf8)
{
- saveDocument(doc, uri);
+ /* See comments in JavaFSOutput::save re the name `filename_utf8'. */
+ saveDocument(doc, filename_utf8);
}
"<output>\n"
"<extension>.pov</extension>\n"
"<mimetype>text/x-povray-script</mimetype>\n"
- "<filetypename>" N_("PovRay (*.pov) (export splines)") "</filetypename>\n"
+ "<filetypename>" N_("PovRay (*.pov) (paths and shapes only)") "</filetypename>\n"
"<filetypetooltip>" N_("PovRay Raytracer File") "</filetypetooltip>\n"
"</output>\n"
"</inkscape-extension>",
fill-column:99
End:
*/
-// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :
+// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :