summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/extension/internal/javafx-out.cpp44
-rw-r--r--src/extension/internal/pov-out.cpp129
-rw-r--r--src/extension/internal/pov-out.h5
3 files changed, 93 insertions, 85 deletions
diff --git a/src/extension/internal/javafx-out.cpp b/src/extension/internal/javafx-out.cpp
index 070b59781..967ddd92d 100644
--- a/src/extension/internal/javafx-out.cpp
+++ b/src/extension/internal/javafx-out.cpp
@@ -60,9 +60,11 @@ namespace Internal
static void err(const char *fmt, ...)
{
va_list args;
+ g_log(NULL, G_LOG_LEVEL_WARNING, "javafx-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");
}
@@ -96,7 +98,8 @@ static double effective_opacity(const SPStyle *style)
/**
- * We want to control floating output format
+ * We want to control floating output format.
+ * Especially to avoid localization. (decimal ',' for example)
*/
static JavaFXOutput::String dstr(double d)
{
@@ -109,6 +112,10 @@ static JavaFXOutput::String dstr(double d)
#define DSTR(d) (dstr(d).c_str())
+
+/**
+ * Format a double as an integer
+ */
static JavaFXOutput::String istr(double d)
{
char dbuf[G_ASCII_DTOSTR_BUF_SIZE+1];
@@ -120,6 +127,7 @@ static JavaFXOutput::String istr(double d)
#define ISTR(d) (istr(d).c_str())
+
/**
* Format an rgba() string
*/
@@ -204,7 +212,7 @@ bool JavaFXOutput::doHeader()
out("/*###################################################################\n");
out("### This JavaFX 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");
@@ -263,7 +271,7 @@ bool JavaFXOutput::doTail()
// Frame
out("Frame {\n");
out(" title: \"%s\"\n", name.c_str());
- out(" width: %s\n", ISTR(maxx-minx + border * 2.0));
+ out(" width: %s\n", ISTR(maxx-minx + border * 2.0));
out(" height: %s\n", ISTR(maxy-miny + border * 2.0));
out(" visible: true\n");
@@ -306,7 +314,7 @@ bool JavaFXOutput::doGradient(SPGradient *grad, const String &id)
SPGradientStop stop = stops[i];
out(" Stop {\n");
out(" offset: %s\n", DSTR(stop.offset));
- out(" color: %s\n", rgba(stop.color, stop.opacity).c_str());
+ out(" color: %s\n", rgba(stop.color, stop.opacity).c_str());
out(" },\n");
}
out(" ]\n");
@@ -323,9 +331,9 @@ bool JavaFXOutput::doGradient(SPGradient *grad, const String &id)
out(" RadialGradient {\n");
out(" centerX: %s\n", DSTR(g->cx.value));
out(" centerY: %s\n", DSTR(g->cy.value));
- out(" focusX: %s\n", DSTR(g->fx.value));
- out(" focusY: %s\n", DSTR(g->fy.value));
- out(" radius: %s\n", DSTR(g->r.value));
+ out(" focusX: %s\n", DSTR(g->fx.value));
+ out(" focusY: %s\n", DSTR(g->fy.value));
+ out(" radius: %s\n", DSTR(g->r.value ));
std::vector<SPGradientStop> stops = g->vector.stops;
if (stops.size() > 0)
{
@@ -336,7 +344,7 @@ bool JavaFXOutput::doGradient(SPGradient *grad, const String &id)
SPGradientStop stop = stops[i];
out(" Stop {\n");
out(" offset: %s\n", DSTR(stop.offset));
- out(" color: %s\n", rgba(stop.color, stop.opacity).c_str());
+ out(" color: %s\n", rgba(stop.color, stop.opacity).c_str());
out(" },\n");
}
out(" ]\n");
@@ -411,11 +419,11 @@ bool JavaFXOutput::doStyle(SPStyle *style)
out(" stroke: %s\n",
rgba(stroke.value.color, SP_SCALE24_TO_FLOAT(style->stroke_opacity.value)).c_str());
double strokewidth = style->stroke_width.value;
- unsigned linecap = style->stroke_linecap.value;
- unsigned linejoin = style->stroke_linejoin.value;
- out(" strokeWidth: %s\n", DSTR(strokewidth));
- out(" strokeLineCap: %s\n", getStrokeLineCap(linecap).c_str());
- out(" strokeLineJoin: %s\n", getStrokeLineJoin(linejoin).c_str());
+ unsigned linecap = style->stroke_linecap.value;
+ unsigned linejoin = style->stroke_linejoin.value;
+ out(" strokeWidth: %s\n", DSTR(strokewidth));
+ out(" strokeLineCap: %s\n", getStrokeLineCap(linecap).c_str());
+ out(" strokeLineJoin: %s\n", getStrokeLineJoin(linejoin).c_str());
out(" strokeMiterLimit: %s\n", DSTR(style->stroke_miterlimit.value));
if(style->stroke_dasharray_set) {
if(style->stroke_dashoffset_set) {
@@ -509,9 +517,9 @@ bool JavaFXOutput::doCurve(SPItem *item, const String &id)
for (Geom::Path::const_iterator cit = pit->begin(); cit != pit->end_closed(); ++cit)
{
//### LINE
- if( dynamic_cast<Geom::LineSegment const *> (&*cit) ||
- dynamic_cast<Geom::HLineSegment const *>(&*cit) ||
- dynamic_cast<Geom::VLineSegment const *>(&*cit) )
+ if( dynamic_cast<Geom::LineSegment const *> (&*cit) ||
+ dynamic_cast<Geom::HLineSegment const *> (&*cit) ||
+ dynamic_cast<Geom::VLineSegment const *> (&*cit) )
{
Geom::Point p = cit->finalPoint();
out(" LineTo {\n");
@@ -532,8 +540,8 @@ bool JavaFXOutput::doCurve(SPItem *item, const String &id)
out(" controlY1: %s\n", DSTR(p1[Y]));
out(" controlX2: %s\n", DSTR(p2[X]));
out(" controlY2: %s\n", DSTR(p2[Y]));
- out(" x: %s\n", DSTR(p3[X]));
- out(" y: %s\n", DSTR(p3[Y]));
+ out(" x: %s\n", DSTR(p3[X]));
+ out(" y: %s\n", DSTR(p3[Y]));
out(" },\n");
nrNodes++;
}
diff --git a/src/extension/internal/pov-out.cpp b/src/extension/internal/pov-out.cpp
index ea746eae7..6b8a5ce07 100644
--- a/src/extension/internal/pov-out.cpp
+++ b/src/extension/internal/pov-out.cpp
@@ -48,33 +48,26 @@ namespace Internal
{
-
-
//########################################################################
-//# 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
+//########################################################################
@@ -112,7 +105,7 @@ static PovOutput::String dstr(double d)
return s;
}
-
+#define DSTR(d) (dstr(d).c_str())
/**
@@ -137,7 +130,7 @@ void PovOutput::out(const char *fmt, ...)
*/
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));
}
@@ -147,7 +140,7 @@ void PovOutput::vec2(double a, double 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));
}
@@ -157,8 +150,7 @@ void PovOutput::vec3(double a, double b, double 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));
}
@@ -208,7 +200,7 @@ bool PovOutput::doHeader()
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");
@@ -374,7 +366,7 @@ bool PovOutput::doCurve(SPItem *item, const String &id)
}
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;
}
@@ -395,14 +387,14 @@ bool PovOutput::doCurve(SPItem *item, const String &id)
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());
@@ -423,30 +415,36 @@ bool PovOutput::doCurve(SPItem *item, const String &id)
}
/**
- * 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;
}
@@ -456,7 +454,7 @@ bool PovOutput::doCurvesRecursive(SPDocument *doc, Inkscape::XML::Node *node)
/**
* Output the curve data to buffer
*/
-bool PovOutput::doCurves(SPDocument *doc)
+bool PovOutput::doTree(SPDocument *doc)
{
double bignum = 1000000.0;
minx = bignum;
@@ -464,7 +462,7 @@ bool PovOutput::doCurves(SPDocument *doc)
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
@@ -511,7 +509,7 @@ bool PovOutput::doCurves(SPDocument *doc)
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");
@@ -536,14 +534,14 @@ bool PovOutput::doCurves(SPDocument *doc)
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");
@@ -568,6 +566,7 @@ void PovOutput::reset()
nrNodes = 0;
nrSegments = 0;
nrShapes = 0;
+ idIndex = 0;
outbuf.clear();
povShapes.clear();
}
@@ -583,9 +582,9 @@ void PovOutput::saveDocument(SPDocument *doc, gchar const *uri)
//###### 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;
}
@@ -594,7 +593,7 @@ void PovOutput::saveDocument(SPDocument *doc, gchar const *uri)
if (!doHeader())
{
- g_warning("Could not write header for %s\n", uri);
+ err("Could not write header for %s", uri);
return;
}
@@ -602,7 +601,7 @@ void PovOutput::saveDocument(SPDocument *doc, gchar const *uri)
if (!doTail())
{
- g_warning("Could not write footer for %s\n", uri);
+ err("Could not write footer for %s", uri);
return;
}
@@ -641,7 +640,7 @@ void PovOutput::saveDocument(SPDocument *doc, gchar const *uri)
* 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);
@@ -652,7 +651,7 @@ PovOutput::save(Inkscape::Extension::Output *mod,
/**
* 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))
diff --git a/src/extension/internal/pov-out.h b/src/extension/internal/pov-out.h
index 8689e2372..a9f94b61a 100644
--- a/src/extension/internal/pov-out.h
+++ b/src/extension/internal/pov-out.h
@@ -120,8 +120,8 @@ private:
* 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
@@ -164,6 +164,7 @@ private:
int nrNodes;
int nrSegments;
int nrShapes;
+ int idIndex;
double minx;
double miny;