summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 4095837)
raw | patch | inline | side by side (parent: 4095837)
author | ishmal <ishmal@users.sourceforge.net> | |
Sun, 10 Aug 2008 19:52:42 +0000 (19:52 +0000) | ||
committer | ishmal <ishmal@users.sourceforge.net> | |
Sun, 10 Aug 2008 19:52:42 +0000 (19:52 +0000) |
src/extension/internal/javafx-out.cpp | patch | blob | history | |
src/extension/internal/pov-out.cpp | patch | blob | history | |
src/extension/internal/pov-out.h | patch | blob | history |
index 070b59781a0334cd91aeef8dd4b21899d0990637..967ddd92d72a57fd541a29b13b08a42ae31f390e 100644 (file)
static void err(const char *fmt, ...)\r
{\r
va_list args;\r
+ g_log(NULL, G_LOG_LEVEL_WARNING, "javafx-out err: ");\r
va_start(args, fmt);\r
g_logv(NULL, G_LOG_LEVEL_WARNING, fmt, args);\r
va_end(args);\r
+ g_log(NULL, G_LOG_LEVEL_WARNING, "\n");\r
}\r
\r
\r
\r
\r
/**\r
- * We want to control floating output format\r
+ * We want to control floating output format.\r
+ * Especially to avoid localization. (decimal ',' for example)\r
*/\r
static JavaFXOutput::String dstr(double d)\r
{\r
\r
#define DSTR(d) (dstr(d).c_str())\r
\r
+\r
+/**\r
+ * Format a double as an integer\r
+ */\r
static JavaFXOutput::String istr(double d)\r
{\r
char dbuf[G_ASCII_DTOSTR_BUF_SIZE+1];\r
\r
#define ISTR(d) (istr(d).c_str())\r
\r
+\r
/**\r
* Format an rgba() string\r
*/\r
out("/*###################################################################\n");\r
out("### This JavaFX document was generated by Inkscape\n");\r
out("### http://www.inkscape.org\n");\r
- out("### Created: %s", ctime(&tim));\r
+ out("### Created: %s", ctime(&tim));\r
out("### Version: %s\n", INKSCAPE_VERSION);\r
out("#####################################################################\n");\r
out("### NOTES:\n");\r
// Frame\r
out("Frame {\n");\r
out(" title: \"%s\"\n", name.c_str());\r
- out(" width: %s\n", ISTR(maxx-minx + border * 2.0));\r
+ out(" width: %s\n", ISTR(maxx-minx + border * 2.0));\r
out(" height: %s\n", ISTR(maxy-miny + border * 2.0));\r
out(" visible: true\n");\r
\r
SPGradientStop stop = stops[i];\r
out(" Stop {\n");\r
out(" offset: %s\n", DSTR(stop.offset));\r
- out(" color: %s\n", rgba(stop.color, stop.opacity).c_str());\r
+ out(" color: %s\n", rgba(stop.color, stop.opacity).c_str());\r
out(" },\n");\r
}\r
out(" ]\n");\r
out(" RadialGradient {\n");\r
out(" centerX: %s\n", DSTR(g->cx.value));\r
out(" centerY: %s\n", DSTR(g->cy.value));\r
- out(" focusX: %s\n", DSTR(g->fx.value));\r
- out(" focusY: %s\n", DSTR(g->fy.value));\r
- out(" radius: %s\n", DSTR(g->r.value));\r
+ out(" focusX: %s\n", DSTR(g->fx.value));\r
+ out(" focusY: %s\n", DSTR(g->fy.value));\r
+ out(" radius: %s\n", DSTR(g->r.value ));\r
std::vector<SPGradientStop> stops = g->vector.stops;\r
if (stops.size() > 0)\r
{\r
SPGradientStop stop = stops[i];\r
out(" Stop {\n");\r
out(" offset: %s\n", DSTR(stop.offset));\r
- out(" color: %s\n", rgba(stop.color, stop.opacity).c_str());\r
+ out(" color: %s\n", rgba(stop.color, stop.opacity).c_str());\r
out(" },\n");\r
}\r
out(" ]\n");\r
out(" stroke: %s\n",\r
rgba(stroke.value.color, SP_SCALE24_TO_FLOAT(style->stroke_opacity.value)).c_str());\r
double strokewidth = style->stroke_width.value;\r
- unsigned linecap = style->stroke_linecap.value;\r
- unsigned linejoin = style->stroke_linejoin.value;\r
- out(" strokeWidth: %s\n", DSTR(strokewidth));\r
- out(" strokeLineCap: %s\n", getStrokeLineCap(linecap).c_str());\r
- out(" strokeLineJoin: %s\n", getStrokeLineJoin(linejoin).c_str());\r
+ unsigned linecap = style->stroke_linecap.value;\r
+ unsigned linejoin = style->stroke_linejoin.value;\r
+ out(" strokeWidth: %s\n", DSTR(strokewidth));\r
+ out(" strokeLineCap: %s\n", getStrokeLineCap(linecap).c_str());\r
+ out(" strokeLineJoin: %s\n", getStrokeLineJoin(linejoin).c_str());\r
out(" strokeMiterLimit: %s\n", DSTR(style->stroke_miterlimit.value));\r
if(style->stroke_dasharray_set) {\r
if(style->stroke_dashoffset_set) {\r
for (Geom::Path::const_iterator cit = pit->begin(); cit != pit->end_closed(); ++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
+ 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->finalPoint();\r
out(" LineTo {\n");\r
out(" controlY1: %s\n", DSTR(p1[Y]));\r
out(" controlX2: %s\n", DSTR(p2[X]));\r
out(" controlY2: %s\n", DSTR(p2[Y]));\r
- out(" x: %s\n", DSTR(p3[X]));\r
- out(" y: %s\n", DSTR(p3[Y]));\r
+ out(" x: %s\n", DSTR(p3[X]));\r
+ out(" y: %s\n", DSTR(p3[Y]));\r
out(" },\n");\r
nrNodes++;\r
}\r
index ea746eae72adc4a601bf93294e963b413e61545b..6b8a5ce070744cb441d3da50119fc146cd632710 100644 (file)
{
-
-
//########################################################################
-//# U T I L I T Y
+//# M E S S A G E S
//########################################################################
-
-
-/**
- * This function searches the Repr tree recursively from the given node,
- * and adds refs to all nodes with the given name, to the result vector
- */
-static void
-findElementsByTagName(std::vector<Inkscape::XML::Node *> &results,
- Inkscape::XML::Node *node,
- char const *name)
+static void err(const char *fmt, ...)
{
- if ( !name || strcmp(node->name(), name) == 0 )
- results.push_back(node);
+ va_list args;
+ g_log(NULL, G_LOG_LEVEL_WARNING, "Pov-out err: ");
+ va_start(args, fmt);
+ g_logv(NULL, G_LOG_LEVEL_WARNING, fmt, args);
+ va_end(args);
+ g_log(NULL, G_LOG_LEVEL_WARNING, "\n");
+}
- for (Inkscape::XML::Node *child = node->firstChild() ; child ;
- child = child->next())
- findElementsByTagName( results, child, name );
-}
+//########################################################################
+//# U T I L I T Y
+//########################################################################
return s;
}
-
+#define DSTR(d) (dstr(d).c_str())
/**
*/
void PovOutput::vec2(double a, double b)
{
- out("<%s, %s>", dstr(a).c_str(), dstr(b).c_str());
+ out("<%s, %s>", DSTR(a), DSTR(b));
}
*/
void PovOutput::vec3(double a, double b, double c)
{
- out("<%s, %s, %s>", dstr(a).c_str(), dstr(b).c_str(), dstr(c).c_str());
+ out("<%s, %s, %s>", DSTR(a), DSTR(b), DSTR(c));
}
*/
void PovOutput::vec4(double a, double b, double c, double d)
{
- out("<%s, %s, %s, %s>", dstr(a).c_str(), dstr(b).c_str(),
- dstr(c).c_str(), dstr(d).c_str());
+ out("<%s, %s, %s, %s>", DSTR(a), DSTR(b), DSTR(c), DSTR(d));
}
out("/*###################################################################\n");
out("### This PovRay document was generated by Inkscape\n");
out("### http://www.inkscape.org\n");
- out("### Created: %s", ctime(&tim));
+ out("### Created: %s", ctime(&tim));
out("### Version: %s\n", INKSCAPE_VERSION);
out("#####################################################################\n");
out("### NOTES:\n");
}
else
{
- g_warning("logical error, because pathv_to_linear_and_cubic_beziers was used");
+ err("logical error, because pathv_to_linear_and_cubic_beziers was used");
return false;
}
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());
+ out("#declare %s_MIN_X = %s;\n", id.c_str(), DSTR(cminx));
+ out("#declare %s_CENTER_X = %s;\n", id.c_str(), DSTR((cmaxx+cminx)/2.0));
+ out("#declare %s_MAX_X = %s;\n", id.c_str(), DSTR(cmaxx));
+ out("#declare %s_WIDTH = %s;\n", id.c_str(), DSTR(cmaxx-cminx));
+ out("#declare %s_MIN_Y = %s;\n", id.c_str(), DSTR(cminy));
+ out("#declare %s_CENTER_Y = %s;\n", id.c_str(), DSTR((cmaxy+cminy)/2.0));
+ out("#declare %s_MAX_Y = %s;\n", id.c_str(), DSTR(cmaxy));
+ out("#declare %s_HEIGHT = %s;\n", id.c_str(), DSTR(cmaxy-cminy));
if (shapeInfo.color.length()>0)
out("#declare %s_COLOR = %s;\n",
id.c_str(), shapeInfo.color.c_str());
}
/**
- * Output the curve data to buffer
+ * Descend the svg tree recursively, translating data
*/
-bool PovOutput::doCurvesRecursive(SPDocument *doc, Inkscape::XML::Node *node)
+bool PovOutput::doTreeRecursive(SPDocument *doc, SPObject *obj)
{
- /**
- * 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)
+
+ String id;
+ if (!obj->id)
{
- SPItem *item = SP_ITEM(reprobj);
- String id = str;
+ char buf[16];
+ sprintf(buf, "id%d", idIndex++);
+ id = buf;
+ }
+ else
+ {
+ id = obj->id;
+ }
+
+ if (SP_IS_ITEM(obj))
+ {
+ SPItem *item = SP_ITEM(obj);
if (!doCurve(item, id))
return false;
}
/**
* Descend into children
- */
- for (Inkscape::XML::Node *child = node->firstChild() ; child ;
- child = child->next())
+ */
+ for (SPObject *child = obj->firstChild() ; child ; child = child->next)
{
- if (!doCurvesRecursive(doc, child))
+ if (!doTreeRecursive(doc, child))
return false;
}
/**
* Output the curve data to buffer
*/
-bool PovOutput::doCurves(SPDocument *doc)
+bool PovOutput::doTree(SPDocument *doc)
{
double bignum = 1000000.0;
minx = bignum;
miny = bignum;
maxy = -bignum;
- if (!doCurvesRecursive(doc, doc->rroot))
+ if (!doTreeRecursive(doc, doc->root))
return false;
//## Let's make a union of all of the Shapes
out(" * Allow the user to redefine the Z-Increment\n");
out(" */\n");
out("#ifndef (AllShapes_Z_Increment)\n");
- out("#declare AllShapes_Z_Increment = %s;\n", dstr(zinc).c_str());
+ out("#declare AllShapes_Z_Increment = %s;\n", DSTR(zinc));
out("#end\n");
out("\n");
out("#declare AllShapes_Z_Scale = 1.0;\n");
out("}\n");
- out("#declare %s_MIN_X = %s;\n", pfx, dstr(minx).c_str());
- out("#declare %s_CENTER_X = %s;\n", pfx, dstr((maxx+minx)/2.0).c_str());
- out("#declare %s_MAX_X = %s;\n", pfx, dstr(maxx).c_str());
- out("#declare %s_WIDTH = %s;\n", pfx, dstr(maxx-minx).c_str());
- out("#declare %s_MIN_Y = %s;\n", pfx, dstr(miny).c_str());
- out("#declare %s_CENTER_Y = %s;\n", pfx, dstr((maxy+miny)/2.0).c_str());
- out("#declare %s_MAX_Y = %s;\n", pfx, dstr(maxy).c_str());
- out("#declare %s_HEIGHT = %s;\n", pfx, dstr(maxy-miny).c_str());
+ out("#declare %s_MIN_X = %s;\n", pfx, DSTR(minx));
+ out("#declare %s_CENTER_X = %s;\n", pfx, DSTR((maxx+minx)/2.0));
+ out("#declare %s_MAX_X = %s;\n", pfx, DSTR(maxx));
+ out("#declare %s_WIDTH = %s;\n", pfx, DSTR(maxx-minx));
+ out("#declare %s_MIN_Y = %s;\n", pfx, DSTR(miny));
+ out("#declare %s_CENTER_Y = %s;\n", pfx, DSTR((maxy+miny)/2.0));
+ out("#declare %s_MAX_Y = %s;\n", pfx, DSTR(maxy));
+ out("#declare %s_HEIGHT = %s;\n", pfx, DSTR(maxy-miny));
out("/*##############################################\n");
out("### end %s\n", id.c_str());
out("##############################################*/\n");
nrNodes = 0;
nrSegments = 0;
nrShapes = 0;
+ idIndex = 0;
outbuf.clear();
povShapes.clear();
}
//###### SAVE IN POV FORMAT TO BUFFER
//# Lets do the curves first, to get the stats
- if (!doCurves(doc))
+ if (!doTree(doc))
{
- g_warning("Could not output curves for %s\n", uri);
+ err("Could not output curves for %s", uri);
return;
}
if (!doHeader())
{
- g_warning("Could not write header for %s\n", uri);
+ err("Could not write header for %s", uri);
return;
}
if (!doTail())
{
- g_warning("Could not write footer for %s\n", uri);
+ err("Could not write footer for %s", uri);
return;
}
* API call to save document
*/
void
-PovOutput::save(Inkscape::Extension::Output *mod,
+PovOutput::save(Inkscape::Extension::Output */*mod*/,
SPDocument *doc, gchar const *uri)
{
saveDocument(doc, uri);
/**
* Make sure that we are in the database
*/
-bool PovOutput::check (Inkscape::Extension::Extension *module)
+bool PovOutput::check (Inkscape::Extension::Extension */*module*/)
{
/* We don't need a Key
if (NULL == Inkscape::Extension::db.get(SP_MODULE_KEY_OUTPUT_POV))
index 8689e2372d5133b9f92f284ae665eff7c6ca6d0b..a9f94b61ae46db3d7b723410dc17d9875e474eea 100644 (file)
* 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);
+ bool doTreeRecursive(SPDocument *doc, SPObject *obj);
+ bool doTree(SPDocument *doc);
/**
* Actual method to save document
int nrNodes;
int nrSegments;
int nrShapes;
+ int idIndex;
double minx;
double miny;