From: ishmal Date: Thu, 8 Mar 2007 21:40:13 +0000 (+0000) Subject: changed curve->length to SP_CURVE_LENGTH(curve). Fixes bug 1676273. X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=9d512f19bcd0d42bee26fb99c5e8a5fff3345bbd;p=inkscape.git changed curve->length to SP_CURVE_LENGTH(curve). Fixes bug 1676273. --- diff --git a/src/extension/internal/pov-out.cpp b/src/extension/internal/pov-out.cpp index 8450b1040..c26af6f36 100644 --- a/src/extension/internal/pov-out.cpp +++ b/src/extension/internal/pov-out.cpp @@ -9,9 +9,9 @@ * http://www.povray.org * * Authors: - * Bob Jamison + * Bob Jamison * - * Copyright (C) 2004 Authors + * Copyright (C) 2004-2007 Authors * * Released under GNU GPL, read the file 'COPYING' for more information */ @@ -53,15 +53,14 @@ dstr(gchar *sbuffer, double d) /** * 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)) return FALSE; */ - return TRUE; + return true; } @@ -76,12 +75,11 @@ findElementsByTagName(std::vector &results, Inkscape::XML::Node *node, char const *name) { - if ( !name - || strcmp(node->name(), name) == 0 ) { + if ( !name || strcmp(node->name(), name) == 0 ) results.push_back(node); - } - for (Inkscape::XML::Node *child = node->firstChild() ; child ; child = child->next()) + for (Inkscape::XML::Node *child = node->firstChild() ; child ; + child = child->next()) findElementsByTagName( results, child, name ); } @@ -94,11 +92,22 @@ class PovShapeInfo { public: PovShapeInfo() - {} + {} + PovShapeInfo(const PovShapeInfo &other) + { assign(other); } + PovShapeInfo operator=(const PovShapeInfo &other) + { assign(other); return *this; } virtual ~PovShapeInfo() - {} + {} std::string id; std::string color; + +private: + void assign(const PovShapeInfo &other) + { + id = other.id; + color = other.color; + } }; @@ -107,15 +116,18 @@ static double effective_opacity(SPItem const *item) { double ret = 1.0; - for (SPObject const *obj = item; obj; obj = obj->parent) { + for (SPObject const *obj = item; obj; obj = obj->parent) + { SPStyle const *const style = SP_OBJECT_STYLE(obj); g_return_val_if_fail(style, ret); ret *= SP_SCALE24_TO_FLOAT(style->opacity.value); - } + } return ret; } + + /** * Saves the of an Inkscape SVG file as PovRay spline definitions */ @@ -127,6 +139,7 @@ PovOutput::save(Inkscape::Extension::Output *mod, SPDocument *doc, gchar const * findElementsByTagName(results, SP_ACTIVE_DOCUMENT->rroot, NULL);//Check all nodes if (results.size() == 0) return; + Inkscape::IO::dump_fopen_call(uri, "L"); FILE *f = Inkscape::IO::fopen_utf8name(uri, "w"); if (!f) @@ -137,6 +150,7 @@ PovOutput::save(Inkscape::Extension::Output *mod, SPDocument *doc, gchar const * fprintf(f, "### This PovRay document was generated by Inkscape\n"); fprintf(f, "### http://www.inkscape.org\n"); fprintf(f, "### Created: %s", ctime(&tim)); + fprintf(f, "### Version: %s\n", VERSION); fprintf(f, "##################################################*/\n\n\n"); std::vectorpovShapes; //A list for saving information about the shapes @@ -161,7 +175,7 @@ PovOutput::save(Inkscape::Extension::Output *mod, SPDocument *doc, gchar const * unsigned indx; for (indx = 0; indx < results.size() ; indx++) - { + { //### Fetch the object from the repr info Inkscape::XML::Node *rpath = results[indx]; gchar *id = (gchar *)rpath->attribute("id"); @@ -171,32 +185,30 @@ PovOutput::save(Inkscape::Extension::Output *mod, SPDocument *doc, gchar const * //### Get the transform of the item if (!SP_IS_ITEM(reprobj)) - { continue; - } + SPItem *item = SP_ITEM(reprobj); NR::Matrix tf = sp_item_i2d_affine(item); //### Get the Shape if (!SP_IS_SHAPE(reprobj))//Bulia's suggestion. Allow all shapes - { continue; - } + SPShape *shape = SP_SHAPE(reprobj); SPCurve *curve = shape->curve; if (sp_curve_empty(curve)) continue; PovShapeInfo shapeInfo; - - shapeInfo.id = id; - shapeInfo.color = ""; + 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 flat colour. */ - if (style && (style->fill.type == SP_PAINT_TYPE_COLOR)) { + if (style && (style->fill.type == SP_PAINT_TYPE_COLOR)) + { // see color.h for how to parse SPColor float rgb[3]; sp_color_get_rgb_floatv(&style->fill.value.color, rgb); @@ -209,20 +221,20 @@ PovOutput::save(Inkscape::Extension::Output *mod, SPDocument *doc, gchar const * shapeInfo.color += str; g_free(str); - } + } povShapes.push_back(shapeInfo); //passed all tests. save the info int curveNr; + int curveLength = SP_CURVE_LENGTH(curve); //Count the NR_CURVETOs/LINETOs int segmentCount=0; NArtBpath *bp = SP_CURVE_BPATH(curve); - for (curveNr=0 ; curveNrlength ; curveNr++, bp++) + for (curveNr=0 ; curveNrcode == NR_CURVETO || bp->code == NR_LINETO) segmentCount++; - bp = SP_CURVE_BPATH(curve); double cminx = bignum; double cmaxx = -bignum; double cminy = bignum; @@ -240,7 +252,9 @@ PovOutput::save(Inkscape::Extension::Output *mod, SPDocument *doc, gchar const * fprintf(f, " 0.0, //bottom\n"); fprintf(f, " %d, //nr points\n", segmentCount * 4); int segmentNr = 0; - for (bp = SP_CURVE_BPATH(curve), curveNr=0 ; curveNrlength ; curveNr++, bp++) { + curveNr = 0; + for (bp = SP_CURVE_BPATH(curve) ; curveNr < curveLength ; curveNr++, bp++) + { using NR::X; using NR::Y; NR::Point const p1(bp->c(1) * tf); @@ -250,7 +264,8 @@ PovOutput::save(Inkscape::Extension::Output *mod, SPDocument *doc, gchar const * double const x2 = p2[X], y2 = p2[Y]; double const x3 = p3[X], y3 = p3[Y]; - switch (bp->code) { + switch (bp->code) + { case NR_MOVETO: case NR_MOVETO_OPEN: //fprintf(f, "moveto: %f %f\n", bp->x3, bp->y3); @@ -261,10 +276,10 @@ PovOutput::save(Inkscape::Extension::Output *mod, SPDocument *doc, gchar const * // segmentNr++, lastx, lasty, x1, y1, x2, y2, x3, y3); fprintf(f, " /*%4d*/ <%s, %s>, <%s, %s>, <%s,%s>, <%s,%s>", segmentNr++, - dstr(s1, lastx), dstr(s2, lasty), - dstr(s3, x1), dstr(s4, y1), - dstr(s5, x2), dstr(s6, y2), - dstr(s7, x3), dstr(s8, y3)); + dstr(s1, lastx), dstr(s2, lasty), + dstr(s3, x1), dstr(s4, y1), + dstr(s5, x2), dstr(s6, y2), + dstr(s7, x3), dstr(s8, y3)); if (segmentNr < segmentCount) fprintf(f, ",\n"); @@ -280,16 +295,17 @@ PovOutput::save(Inkscape::Extension::Output *mod, SPDocument *doc, gchar const * if (lasty > cmaxy) cmaxy = lasty; break; + case NR_LINETO: //fprintf(f, " /*%4d*/ <%f, %f>, <%f, %f>, <%f,%f>, <%f,%f>", // segmentNr++, lastx, lasty, lastx, lasty, x3, y3, x3, y3); fprintf(f, " /*%4d*/ <%s, %s>, <%s, %s>, <%s,%s>, <%s,%s>", segmentNr++, - dstr(s1, lastx), dstr(s2, lasty), - dstr(s3, lastx), dstr(s4, lasty), - dstr(s5, x3), dstr(s6, y3), - dstr(s7, x3), dstr(s8, y3)); + dstr(s1, lastx), dstr(s2, lasty), + dstr(s3, lastx), dstr(s4, lasty), + dstr(s5, x3), dstr(s6, y3), + dstr(s7, x3), dstr(s8, y3)); if (segmentNr < segmentCount) fprintf(f, ",\n"); @@ -309,13 +325,15 @@ PovOutput::save(Inkscape::Extension::Output *mod, SPDocument *doc, gchar const * case NR_END: //fprintf(f, "end\n"); break; - } + } lastx = x3; lasty = y3; - } + } fprintf(f, "}\n"); + + /* - fprintf(f, "#declare %s_MIN_X = %4.3f;\n", id, cminx); + fprintf(f, "#declare %s_MIN_X = %4.3f;\n", id, cminx); fprintf(f, "#declare %s_CENTER_X = %4.3f;\n", id, (cmaxx+cminx)/2.0); fprintf(f, "#declare %s_MAX_X = %4.3f;\n", id, cmaxx); fprintf(f, "#declare %s_WIDTH = %4.3f;\n", id, cmaxx-cminx); @@ -323,8 +341,8 @@ PovOutput::save(Inkscape::Extension::Output *mod, SPDocument *doc, gchar const * fprintf(f, "#declare %s_CENTER_Y = %4.3f;\n", id, (cmaxy+cminy)/2.0); fprintf(f, "#declare %s_MAX_Y = %4.3f;\n", id, cmaxy); fprintf(f, "#declare %s_HEIGHT = %4.3f;\n", id, cmaxy-cminy); - */ - fprintf(f, "#declare %s_MIN_X = %s;\n", id, dstr(s1, cminx)); + */ + fprintf(f, "#declare %s_MIN_X = %s;\n", id, dstr(s1, cminx)); fprintf(f, "#declare %s_CENTER_X = %s;\n", id, dstr(s1, (cmaxx+cminx)/2.0)); fprintf(f, "#declare %s_MAX_X = %s;\n", id, dstr(s1, cmaxx)); fprintf(f, "#declare %s_WIDTH = %s;\n", id, dstr(s1, cmaxx-cminx)); @@ -347,13 +365,12 @@ PovOutput::save(Inkscape::Extension::Output *mod, SPDocument *doc, gchar const * if (cmaxy > maxy) maxy = cmaxy; - - }//for + }//for //## Let's make a union of all of the Shapes - if (!povShapes.empty()) { + if (povShapes.size()>0) { char const *id = "AllShapes"; fprintf(f, "/*##############################################\n"); fprintf(f, "### UNION OF ALL SHAPES IN DOCUMENT\n");