summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 5b20351)
raw | patch | inline | side by side (parent: 5b20351)
author | ishmal <ishmal@users.sourceforge.net> | |
Fri, 1 Aug 2008 19:16:47 +0000 (19:16 +0000) | ||
committer | ishmal <ishmal@users.sourceforge.net> | |
Fri, 1 Aug 2008 19:16:47 +0000 (19:16 +0000) |
index f4cfc9200b8bb98c6fdc4ca78bb0f4d6c5053c48..6e7b21b86c1020b85dd820059a157e4407238dd3 100644 (file)
\r
\r
\r
-//########################################################################\r
-//# U T I L I T Y\r
-//########################################################################\r
-\r
-\r
-\r
-/**\r
- * This function searches the Repr tree recursively from the given node,\r
- * and adds refs to all nodes with the given name, to the result vector\r
- */\r
-static void\r
-findElementsByTagName(std::vector<Inkscape::XML::Node *> &results,\r
- Inkscape::XML::Node *node,\r
- char const *name)\r
-{\r
- if ( !name || strcmp(node->name(), name) == 0 )\r
- results.push_back(node);\r
-\r
- for (Inkscape::XML::Node *child = node->firstChild() ; child ;\r
- child = child->next())\r
- findElementsByTagName( results, child, name );\r
-\r
-}\r
-\r
-\r
-\r
//########################################################################\r
//# OUTPUT FORMATTING\r
//########################################################################\r
out("public class %s extends CompositeNode {\n", name.c_str());\r
out("}\n");\r
out("\n\n");\r
+ out("function %s.composeNode() =\n", name.c_str());\r
+ out("Group\n");\r
+ out(" {\n");\r
+ out(" content:\n");\r
+ out(" [\n");\r
return true;\r
}\r
\r
*/\r
bool JavaFXOutput::doTail(const String &name)\r
{\r
+ out(" ] // content\n");\r
+ out(" }; // Group\n");\r
+ out("// end function %s.composeNode()\n", name.c_str());\r
out("\n\n\n\n");\r
out("Frame {\n");\r
out(" title: \"Test\"\n");\r
}\r
\r
\r
-\r
/**\r
* Output the curve data to buffer\r
*/\r
-bool JavaFXOutput::doCurves(SPDocument *doc, const String &name)\r
+bool JavaFXOutput::doCurve(SPItem *item, const String &id)\r
{\r
using Geom::X;\r
using Geom::Y;\r
- \r
-\r
- std::vector<Inkscape::XML::Node *>results;\r
- findElementsByTagName(results, doc->rroot, NULL);\r
- //findElementsByTagName(results, SP_ACTIVE_DOCUMENT->rroot, NULL);\r
- if (results.size() == 0)\r
- return true;\r
\r
- out("function %s.composeNode() =\n", name.c_str());\r
- out("Group\n");\r
- out(" {\n");\r
- out(" content:\n");\r
- out(" [\n");\r
+ Geom::Matrix tf = sp_item_i2d_affine(item);\r
\r
- for (unsigned int indx = 0; indx < results.size() ; indx++)\r
- {\r
- //### Fetch the object from the repr info\r
- Inkscape::XML::Node *rpath = results[indx];\r
- char *str = (char *) rpath->attribute("id");\r
- if (!str)\r
- continue;\r
+ //### Get the Shape\r
+ if (!SP_IS_SHAPE(item))//Bulia's suggestion. Allow all shapes\r
+ return true;\r
\r
- String id = str;\r
- SPObject *reprobj = SP_ACTIVE_DOCUMENT->getObjectByRepr(rpath);\r
- if (!reprobj)\r
- continue;\r
+ SPShape *shape = SP_SHAPE(item);\r
+ SPCurve *curve = shape->curve;\r
+ if (curve->is_empty())\r
+ return true;\r
\r
- //### Get the transform of the item\r
- if (!SP_IS_ITEM(reprobj))\r
- continue;\r
+ nrShapes++;\r
\r
- SPItem *item = SP_ITEM(reprobj);\r
- Geom::Matrix tf = sp_item_i2d_affine(item);\r
-\r
- //### Get the Shape\r
- if (!SP_IS_SHAPE(reprobj))//Bulia's suggestion. Allow all shapes\r
- continue;\r
-\r
- SPShape *shape = SP_SHAPE(reprobj);\r
- SPCurve *curve = shape->curve;\r
- if (curve->is_empty())\r
- continue;\r
- \r
- nrShapes++;\r
-\r
- out(" /*###################################################\n");\r
- out(" ### PATH: %s\n", id.c_str());\r
- out(" ###################################################*/\n");\r
- out(" Path \n");\r
- out(" {\n");\r
- out(" id: \"%s\"\n", id.c_str());\r
+ out(" /*###################################################\n");\r
+ out(" ### PATH: %s\n", id.c_str());\r
+ out(" ###################################################*/\n");\r
+ out(" Path \n");\r
+ out(" {\n");\r
+ out(" id: \"%s\"\n", id.c_str());\r
\r
+ /**\r
+ * Get the fill and stroke of the shape\r
+ */\r
+ SPStyle *style = SP_OBJECT_STYLE(shape);\r
+ if (style)\r
+ {\r
/**\r
- * Get the fill and stroke of the shape\r
+ * Fill\r
*/\r
- SPStyle *style = SP_OBJECT_STYLE(shape);\r
- if (style)\r
+ if (style->fill.isColor())\r
{\r
- /**\r
- * Fill\r
- */\r
- if (style->fill.isColor())\r
- {\r
- // see color.h for how to parse SPColor\r
- gint alpha = 0xffffffff;\r
- guint32 rgba = style->fill.value.color.toRGBA32(alpha);\r
- unsigned int r = SP_RGBA32_R_U(rgba);\r
- unsigned int g = SP_RGBA32_G_U(rgba);\r
- unsigned int b = SP_RGBA32_B_U(rgba);\r
- unsigned int a = SP_RGBA32_A_U(rgba);\r
- out(" fill: rgba(0x%02x, 0x%02x, 0x%02x, 0x%02x)\n",\r
- r, g, b, a);\r
- }\r
- /**\r
- * Stroke\r
- */\r
- /**\r
- * TODO: stroke code here\r
- */\r
+ // see color.h for how to parse SPColor\r
+ gint alpha = 0xffffffff;\r
+ guint32 rgba = style->fill.value.color.toRGBA32(alpha);\r
+ unsigned int r = SP_RGBA32_R_U(rgba);\r
+ unsigned int g = SP_RGBA32_G_U(rgba);\r
+ unsigned int b = SP_RGBA32_B_U(rgba);\r
+ unsigned int a = SP_RGBA32_A_U(rgba);\r
+ out(" fill: rgba(0x%02x, 0x%02x, 0x%02x, 0x%02x)\n",\r
+ r, g, b, a);\r
}\r
+ /**\r
+ * Stroke\r
+ */\r
+ /**\r
+ * TODO: stroke code here\r
+ */\r
+ }\r
\r
\r
- // convert the path to only lineto's and cubic curveto's:\r
- Geom::PathVector pathv = pathv_to_linear_and_cubic_beziers( curve->get_pathvector() * tf );\r
+ // convert the path to only lineto's and cubic curveto's:\r
+ Geom::PathVector pathv = pathv_to_linear_and_cubic_beziers( curve->get_pathvector() * tf );\r
\r
- //Count the NR_CURVETOs/LINETOs (including closing line segment)\r
- guint segmentCount = 0;\r
- for(Geom::PathVector::const_iterator it = pathv.begin(); it != pathv.end(); ++it) {\r
- segmentCount += (*it).size();\r
- if (it->closed())\r
- segmentCount += 1;\r
- }\r
+ //Count the NR_CURVETOs/LINETOs (including closing line segment)\r
+ guint segmentCount = 0;\r
+ for(Geom::PathVector::const_iterator it = pathv.begin(); it != pathv.end(); ++it) {\r
+ segmentCount += (*it).size();\r
+ if (it->closed())\r
+ segmentCount += 1;\r
+ }\r
\r
- out(" d:\n");\r
- out(" [\n");\r
+ out(" d:\n");\r
+ out(" [\n");\r
\r
- unsigned int segmentNr = 0;\r
+ unsigned int segmentNr = 0;\r
\r
- nrSegments += segmentCount;\r
+ nrSegments += segmentCount;\r
\r
- for (Geom::PathVector::const_iterator pit = pathv.begin(); pit != pathv.end(); ++pit)\r
+ /**\r
+ * For all Subpaths in the <path>\r
+ */ \r
+ for (Geom::PathVector::const_iterator pit = pathv.begin(); pit != pathv.end(); ++pit)\r
+ {\r
+ Geom::Point p = pit->front().initialPoint() * tf;\r
+ out(" MoveTo {\n");\r
+ out(" x: %s\n", dstr(p[X]).c_str());\r
+ out(" y: %s\n", dstr(p[Y]).c_str());\r
+ out(" absolute: true\n");\r
+ out(" },\n");\r
+ \r
+ /**\r
+ * For all segments in the subpath\r
+ */ \r
+ for (Geom::Path::const_iterator cit = pit->begin(); cit != pit->end_closed(); ++cit)\r
{\r
- Geom::Point p = pit->front().initialPoint() * tf;\r
- out(" MoveTo {\n");\r
- out(" x: %s\n", dstr(p[X]).c_str());\r
- out(" y: %s\n", dstr(p[Y]).c_str());\r
- out(" absolute: true\n");\r
- out(" },\n");\r
- for (Geom::Path::const_iterator cit = pit->begin(); cit != pit->end_closed(); ++cit)\r
+ //### LINE\r
+ if( dynamic_cast<Geom::LineSegment const *> (&*cit) ||\r
+ dynamic_cast<Geom::HLineSegment const *>(&*cit) ||\r
+ dynamic_cast<Geom::VLineSegment const *>(&*cit) )\r
{\r
- //### LINE\r
- if( dynamic_cast<Geom::LineSegment const *> (&*cit) ||\r
- dynamic_cast<Geom::HLineSegment const *>(&*cit) ||\r
- dynamic_cast<Geom::VLineSegment const *>(&*cit) )\r
- {\r
- Geom::Point p = cit->initialPoint() * tf;\r
- out(" LineTo {\n");\r
- out(" x: %s\n", dstr(p[X]).c_str());\r
- out(" y: %s\n", dstr(p[Y]).c_str());\r
- out(" absolute: true\n");\r
- out(" },\n");\r
- nrNodes++;\r
- }\r
- //### BEZIER\r
- else if(Geom::CubicBezier const *cubic = dynamic_cast<Geom::CubicBezier const*>(&*cit))\r
- {\r
- std::vector<Geom::Point> points = cubic->points();\r
- Geom::Point p0 = points[0] * tf;\r
- Geom::Point p1 = points[1] * tf;\r
- Geom::Point p2 = points[2] * tf;\r
- out(" CurveTo {\n");\r
- out(" x1: %s\n", dstr(p0[X]).c_str());\r
- out(" y1: %s\n", dstr(p0[Y]).c_str());\r
- out(" x2: %s\n", dstr(p1[X]).c_str());\r
- out(" y2: %s\n", dstr(p1[Y]).c_str());\r
- out(" x3: %s\n", dstr(p2[X]).c_str());\r
- out(" y3: %s\n", dstr(p2[Y]).c_str());\r
- out(" smooth: false\n");\r
- out(" absolute: true\n");\r
- out(" },\n");\r
- nrNodes++;\r
- }\r
- else\r
- {\r
- g_error ("logical error, because pathv_to_linear_and_cubic_beziers was used");\r
- }\r
+ Geom::Point p = cit->initialPoint() * tf;\r
+ out(" LineTo {\n");\r
+ out(" x: %s\n", dstr(p[X]).c_str());\r
+ out(" y: %s\n", dstr(p[Y]).c_str());\r
+ out(" absolute: true\n");\r
+ out(" },\n");\r
+ nrNodes++;\r
}\r
- if (pit->closed())\r
+ //### BEZIER\r
+ else if(Geom::CubicBezier const *cubic = dynamic_cast<Geom::CubicBezier const*>(&*cit))\r
{\r
- out(" ClosePath {},\n");\r
+ std::vector<Geom::Point> points = cubic->points();\r
+ Geom::Point p0 = points[1] * tf;\r
+ Geom::Point p1 = points[2] * tf;\r
+ Geom::Point p2 = points[3] * tf;\r
+ out(" CurveTo {\n");\r
+ out(" x1: %s\n", dstr(p0[X]).c_str());\r
+ out(" y1: %s\n", dstr(p0[Y]).c_str());\r
+ out(" x2: %s\n", dstr(p1[X]).c_str());\r
+ out(" y2: %s\n", dstr(p1[Y]).c_str());\r
+ out(" x3: %s\n", dstr(p2[X]).c_str());\r
+ out(" y3: %s\n", dstr(p2[Y]).c_str());\r
+ out(" absolute: true\n");\r
+ out(" },\n");\r
+ nrNodes++;\r
}\r
+ else\r
+ {\r
+ g_error ("logical error, because pathv_to_linear_and_cubic_beziers was used");\r
+ }\r
+ segmentNr++;\r
+ }\r
+ if (pit->closed())\r
+ {\r
+ out(" ClosePath {},\n");\r
}\r
+ }\r
\r
- out(" ] // d\n");\r
- out(" }, // Path\n");\r
+ out(" ] // d\n");\r
+ out(" }, // Path\n");\r
\r
- \r
- out(" /*###################################################\n");\r
- out(" ### end path %s\n", id.c_str());\r
- out(" ###################################################*/\n\n\n\n");\r
+ \r
+ out(" /*###################################################\n");\r
+ out(" ### end path %s\n", id.c_str());\r
+ out(" ###################################################*/\n\n\n\n");\r
\r
- }//for\r
+ return true;\r
+}\r
\r
- out(" ] // content\n");\r
- out(" }; // Group\n");\r
- out("// end function %s.composeNode()\n", name.c_str());\r
+\r
+/**\r
+ * Output the curve data to buffer\r
+ */\r
+bool JavaFXOutput::doCurvesRecursive(SPDocument *doc, Inkscape::XML::Node *node)\r
+{\r
+ /**\r
+ * If the object is an Item, try processing it\r
+ */ \r
+ char *str = (char *) node->attribute("id");\r
+ SPObject *reprobj = doc->getObjectByRepr(node);\r
+ if (SP_IS_ITEM(reprobj) && str)\r
+ {\r
+ SPItem *item = SP_ITEM(reprobj);\r
+ String id = str;\r
+ if (!doCurve(item, id))\r
+ return false;\r
+ }\r
+\r
+ /**\r
+ * Descend into children\r
+ */ \r
+ for (Inkscape::XML::Node *child = node->firstChild() ; child ;\r
+ child = child->next())\r
+ {\r
+ if (!doCurvesRecursive(doc, child))\r
+ return false;\r
+ }\r
+\r
+ return true;\r
+}\r
+\r
+\r
+/**\r
+ * Output the curve data to buffer\r
+ */\r
+bool JavaFXOutput::doCurves(SPDocument *doc)\r
+{\r
+\r
+ double bignum = 1000000.0;\r
+ minx = bignum;\r
+ maxx = -bignum;\r
+ miny = bignum;\r
+ maxy = -bignum;\r
+\r
+ if (!doCurvesRecursive(doc, doc->rroot))\r
+ return false;\r
\r
return true;\r
\r
//###### SAVE IN POV FORMAT TO BUFFER\r
//# Lets do the curves first, to get the stats\r
\r
- if (!doCurves(doc, name))\r
+ if (!doCurves(doc))\r
return false;\r
String curveBuf = outbuf;\r
outbuf.clear();\r
index 471d021d633922279a9f54cfaa5a6ef3729a4e1b..27a742861cbc067d11959df2f780666e45e2a99a 100644 (file)
/**\r
* Output the SVG document's curve data as POV curves\r
*/\r
- bool doCurves(SPDocument *doc, const String &name);\r
+ bool doCurve(SPItem *item, const String &id);\r
+ bool doCurvesRecursive(SPDocument *doc, Inkscape::XML::Node *node);\r
+ bool doCurves(SPDocument *doc);\r
\r
/**\r
* Output the file footer\r
int nrSegments;\r
int nrShapes;\r
\r
+ double minx;\r
+ double miny;\r
+ double maxx;\r
+ double maxy;\r
+\r
};\r
\r
\r
index 4a09512247815a881e1876cf9960742aa5fcb775..a46b55d42705cf1de20d9e800596bf80037bf6fd 100644 (file)
/**
* Output the curve data to buffer
*/
-bool PovOutput::doCurves(SPDocument *doc)
+bool PovOutput::doCurve(SPItem *item, const String &id)
{
using Geom::X;
using Geom::Y;
- std::vector<Inkscape::XML::Node *>results;
- //findElementsByTagName(results, SP_ACTIVE_DOCUMENT->rroot, "path");
- findElementsByTagName(results, SP_ACTIVE_DOCUMENT->rroot, NULL);
- if (results.size() == 0)
- return true;
-
- double bignum = 1000000.0;
- double minx = bignum;
- double maxx = -bignum;
- double miny = bignum;
- double maxy = -bignum;
-
- for (unsigned int indx = 0; indx < results.size() ; indx++)
- {
- //### Fetch the object from the repr info
- Inkscape::XML::Node *rpath = results[indx];
- char *str = (char *) rpath->attribute("id");
- if (!str)
- continue;
-
- String id = str;
- SPObject *reprobj = SP_ACTIVE_DOCUMENT->getObjectByRepr(rpath);
- if (!reprobj)
- continue;
-
- //### Get the transform of the item
- if (!SP_IS_ITEM(reprobj))
- continue;
-
- SPItem *item = SP_ITEM(reprobj);
- Geom::Matrix tf = sp_item_i2d_affine(item);
+ Geom::Matrix tf = sp_item_i2d_affine(item);
- //### Get the Shape
- if (!SP_IS_SHAPE(reprobj))//Bulia's suggestion. Allow all shapes
- continue;
+ //### Get the Shape
+ if (!SP_IS_SHAPE(item))//Bulia's suggestion. Allow all shapes
+ return true;
- SPShape *shape = SP_SHAPE(reprobj);
- SPCurve *curve = shape->curve;
- if (curve->is_empty())
- continue;
+ SPShape *shape = SP_SHAPE(item);
+ SPCurve *curve = shape->curve;
+ if (curve->is_empty())
+ return true;
- nrShapes++;
+ nrShapes++;
- PovShapeInfo shapeInfo;
- shapeInfo.id = id;
- shapeInfo.color = "";
+ PovShapeInfo shapeInfo;
+ shapeInfo.id = id;
+ shapeInfo.color = "";
- //Try to get the fill color of the shape
- SPStyle *style = SP_OBJECT_STYLE(shape);
- /* fixme: Handle other fill types, even if this means translating gradients to a single
+ //Try to get the fill color of the shape
+ SPStyle *style = SP_OBJECT_STYLE(shape);
+ /* fixme: Handle other fill types, even if this means translating gradients to a single
flat colour. */
- if (style && (style->fill.isColor()))
+ if (style)
+ {
+ if (style->fill.isColor())
{
// see color.h for how to parse SPColor
float rgb[3];
rgbf.append(dstr(1.0 - dopacity)); rgbf.append(">");
shapeInfo.color += rgbf;
}
+ }
- povShapes.push_back(shapeInfo); //passed all tests. save the info
+ povShapes.push_back(shapeInfo); //passed all tests. save the info
- // convert the path to only lineto's and cubic curveto's:
- Geom::PathVector pathv = pathv_to_linear_and_cubic_beziers( curve->get_pathvector() * tf );
+ // convert the path to only lineto's and cubic curveto's:
+ Geom::PathVector pathv = pathv_to_linear_and_cubic_beziers( curve->get_pathvector() * tf );
- //Count the NR_CURVETOs/LINETOs (including closing line segment)
- guint segmentCount = 0;
- for(Geom::PathVector::const_iterator it = pathv.begin(); it != pathv.end(); ++it) {
- segmentCount += (*it).size();
- if (it->closed())
- segmentCount += 1;
+ //Count the NR_CURVETOs/LINETOs (including closing line segment)
+ int segmentCount = 0;
+ for(Geom::PathVector::const_iterator it = pathv.begin(); it != pathv.end(); ++it)
+ {
+ segmentCount += (*it).size();
+ if (it->closed())
+ segmentCount += 1;
}
- out("/*###################################################\n");
- out("### PRISM: %s\n", id.c_str());
- out("###################################################*/\n");
- out("#declare %s = prism {\n", id.c_str());
- out(" linear_sweep\n");
- out(" bezier_spline\n");
- out(" 1.0, //top\n");
- out(" 0.0, //bottom\n");
- out(" %d //nr points\n", segmentCount * 4);
- int segmentNr = 0;
-
- nrSegments += segmentCount;
-
- Geom::Rect cminmax( pathv.front().initialPoint(), pathv.front().initialPoint() ); // at moment of writing, 2geom lacks proper initialization of empty intervals in rect...
+ out("/*###################################################\n");
+ out("### PRISM: %s\n", id.c_str());
+ out("###################################################*/\n");
+ out("#declare %s = prism {\n", id.c_str());
+ out(" linear_sweep\n");
+ out(" bezier_spline\n");
+ out(" 1.0, //top\n");
+ out(" 0.0, //bottom\n");
+ out(" %d //nr points\n", segmentCount * 4);
+ int segmentNr = 0;
+
+ nrSegments += segmentCount;
+
+ /**
+ * at moment of writing, 2geom lacks proper initialization of empty intervals in rect...
+ */
+ Geom::Rect cminmax( pathv.front().initialPoint(), pathv.front().initialPoint() );
- for (Geom::PathVector::const_iterator pit = pathv.begin(); pit != pathv.end(); ++pit)
- {
+ /**
+ * For all Subpaths in the <path>
+ */
+ for (Geom::PathVector::const_iterator pit = pathv.begin(); pit != pathv.end(); ++pit)
+ {
- cminmax.expandTo(pit->initialPoint());
+ cminmax.expandTo(pit->initialPoint());
- for (Geom::Path::const_iterator cit = pit->begin(); cit != pit->end_closed(); ++cit)
- {
+ /**
+ * For all segments in the subpath
+ */
+ for (Geom::Path::const_iterator cit = pit->begin(); cit != pit->end_closed(); ++cit)
+ {
- if( dynamic_cast<Geom::LineSegment const *> (&*cit) ||
+ if( dynamic_cast<Geom::LineSegment const *> (&*cit) ||
dynamic_cast<Geom::HLineSegment const *>(&*cit) ||
dynamic_cast<Geom::VLineSegment const *>(&*cit) )
- {
- Geom::Point p0 = cit->initialPoint() * tf;
- Geom::Point p1 = cit->finalPoint() * tf;
- segment(segmentNr++,
- p0[X], p0[Y], p0[X], p0[Y], p1[X], p1[Y], p1[X], p1[Y] );
- 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] * tf;
- Geom::Point p1 = points[1] * tf;
- Geom::Point p2 = points[2] * tf;
- Geom::Point p3 = points[3] * tf;
- segment(segmentNr++,
+ {
+ Geom::Point p0 = cit->initialPoint();
+ Geom::Point p1 = cit->finalPoint();
+ segment(segmentNr++,
+ p0[X], p0[Y], p0[X], p0[Y], p1[X], p1[Y], p1[X], p1[Y] );
+ 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];
+ Geom::Point p2 = points[2];
+ Geom::Point p3 = points[3];
+ segment(segmentNr++,
p0[X],p0[Y], p1[X],p1[Y], p2[X],p2[Y], p3[X],p3[Y]);
- nrNodes += 8;
- }
- else
- {
- g_warning("logical error, because pathv_to_linear_and_cubic_beziers was used");
- return false;
- }
+ nrNodes += 8;
+ }
+ else
+ {
+ g_warning("logical error, because pathv_to_linear_and_cubic_beziers was used");
+ return false;
+ }
- if (segmentNr <= static_cast<int>(segmentCount))
- out(",\n");
- else
- out("\n");
+ if (segmentNr < segmentCount)
+ out(",\n");
+ else
+ out("\n");
- cminmax.expandTo(cit->finalPoint());
+ cminmax.expandTo(cit->finalPoint());
}
}
- out("}\n");
+ out("}\n");
+
+ double cminx = cminmax.min()[X];
+ double cmaxx = cminmax.max()[X];
+ double cminy = cminmax.min()[Y];
+ double cmaxy = cminmax.max()[Y];
+
+ out("#declare %s_MIN_X = %s;\n", id.c_str(), dstr(cminx).c_str());
+ out("#declare %s_CENTER_X = %s;\n", id.c_str(), dstr((cmaxx+cminx)/2.0).c_str());
+ out("#declare %s_MAX_X = %s;\n", id.c_str(), dstr(cmaxx).c_str());
+ out("#declare %s_WIDTH = %s;\n", id.c_str(), dstr(cmaxx-cminx).c_str());
+ out("#declare %s_MIN_Y = %s;\n", id.c_str(), dstr(cminy).c_str());
+ out("#declare %s_CENTER_Y = %s;\n", id.c_str(), dstr((cmaxy+cminy)/2.0).c_str());
+ out("#declare %s_MAX_Y = %s;\n", id.c_str(), dstr(cmaxy).c_str());
+ out("#declare %s_HEIGHT = %s;\n", id.c_str(), dstr(cmaxy-cminy).c_str());
+ if (shapeInfo.color.length()>0)
+ out("#declare %s_COLOR = %s;\n",
+ id.c_str(), shapeInfo.color.c_str());
+ out("/*###################################################\n");
+ out("### end %s\n", id.c_str());
+ out("###################################################*/\n\n\n\n");
+
+ if (cminx < minx)
+ minx = cminx;
+ if (cmaxx > maxx)
+ maxx = cmaxx;
+ if (cminy < miny)
+ miny = cminy;
+ if (cmaxy > maxy)
+ maxy = cmaxy;
- double cminx = cminmax.min()[X];
- double cmaxx = cminmax.max()[X];
- double cminy = cminmax.min()[Y];
- double cmaxy = cminmax.max()[Y];
+ return true;
+}
- //# prefix for following declarations
- char *pfx = (char *)id.c_str();
+/**
+ * Output the curve data to buffer
+ */
+bool PovOutput::doCurvesRecursive(SPDocument *doc, Inkscape::XML::Node *node)
+{
+ /**
+ * If the object is an Item, try processing it
+ */
+ char *str = (char *) node->attribute("id");
+ SPObject *reprobj = doc->getObjectByRepr(node);
+ if (SP_IS_ITEM(reprobj) && str)
+ {
+ SPItem *item = SP_ITEM(reprobj);
+ String id = str;
+ if (!doCurve(item, id))
+ return false;
+ }
- out("#declare %s_MIN_X = %s;\n", pfx, dstr(cminx).c_str());
- out("#declare %s_CENTER_X = %s;\n", pfx, dstr((cmaxx+cminx)/2.0).c_str());
- out("#declare %s_MAX_X = %s;\n", pfx, dstr(cmaxx).c_str());
- out("#declare %s_WIDTH = %s;\n", pfx, dstr(cmaxx-cminx).c_str());
- out("#declare %s_MIN_Y = %s;\n", pfx, dstr(cminy).c_str());
- out("#declare %s_CENTER_Y = %s;\n", pfx, dstr((cmaxy+cminy)/2.0).c_str());
- out("#declare %s_MAX_Y = %s;\n", pfx, dstr(cmaxy).c_str());
- out("#declare %s_HEIGHT = %s;\n", pfx, dstr(cmaxy-cminy).c_str());
- if (shapeInfo.color.length()>0)
- out("#declare %s_COLOR = %s;\n",
- pfx, shapeInfo.color.c_str());
- out("/*###################################################\n");
- out("### end %s\n", id.c_str());
- out("###################################################*/\n\n\n\n");
- if (cminx < minx)
- minx = cminx;
- if (cmaxx > maxx)
- maxx = cmaxx;
- if (cminy < miny)
- miny = cminy;
- if (cmaxy > maxy)
- maxy = cmaxy;
+ /**
+ * Descend into children
+ */
+ for (Inkscape::XML::Node *child = node->firstChild() ; child ;
+ child = child->next())
+ {
+ if (!doCurvesRecursive(doc, child))
+ return false;
+ }
- }//for
+ return true;
+}
+/**
+ * Output the curve data to buffer
+ */
+bool PovOutput::doCurves(SPDocument *doc)
+{
+ double bignum = 1000000.0;
+ minx = bignum;
+ maxx = -bignum;
+ miny = bignum;
+ maxy = -bignum;
+ if (!doCurvesRecursive(doc, doc->rroot))
+ return false;
//## Let's make a union of all of the Shapes
if (povShapes.size()>0)
}
-
-
//########################################################################
//# M A I N O U T P U T
//########################################################################
index fa19a3e0cf96d3fab12ef37bfd738de095b5c27c..8689e2372d5133b9f92f284ae665eff7c6ca6d0b 100644 (file)
#include <glib.h>
#include "extension/implementation/implementation.h"
+#include <sp-path.h>
+
namespace Inkscape
{
/**
* Output the SVG document's curve data as POV curves
*/
+ bool doCurve(SPItem *item, const String &id);
+ bool doCurvesRecursive(SPDocument *doc, Inkscape::XML::Node *node);
bool doCurves(SPDocument *doc);
/**
int nrNodes;
int nrSegments;
int nrShapes;
+
+ double minx;
+ double miny;
+ double maxx;
+ double maxy;
};