X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;ds=sidebyside;f=src%2Fsp-ellipse.cpp;h=b6f510201e5e45d6584167af3a7264be22ed68e4;hb=6c3e745a94ef6b25a4ef9f018d350a7535aa45af;hp=83c3e288d624e96c8ab9c488829613c951d33b1c;hpb=baa74b7b366585fca6d90ece888c678f580cb5d9;p=inkscape.git diff --git a/src/sp-ellipse.cpp b/src/sp-ellipse.cpp index 83c3e288d..b6f510201 100644 --- a/src/sp-ellipse.cpp +++ b/src/sp-ellipse.cpp @@ -19,8 +19,6 @@ #endif -#include "libnr/n-art-bpath.h" -#include "libnr/nr-path.h" #include "libnr/nr-matrix-fns.h" #include "svg/svg.h" #include "svg/path-string.h" @@ -29,11 +27,12 @@ #include "style.h" #include "display/curve.h" #include +#include <2geom/transforms.h> #include "document.h" #include "sp-ellipse.h" -#include "prefs-utils.h" +#include "preferences.h" /* Common parent class */ @@ -73,12 +72,12 @@ static void sp_genericellipse_init(SPGenericEllipse *ellipse); static void sp_genericellipse_update(SPObject *object, SPCtx *ctx, guint flags); -static void sp_genericellipse_snappoints(SPItem const *item, SnapPointsIter p); +static void sp_genericellipse_snappoints(SPItem const *item, SnapPointsIter p, Inkscape::SnapPreferences const *snapprefs); static void sp_genericellipse_set_shape(SPShape *shape); -static void sp_genericellipse_update_patheffect (SPShape *shape, bool write); +static void sp_genericellipse_update_patheffect (SPLPEItem *lpeitem, bool write); -static Inkscape::XML::Node *sp_genericellipse_write(SPObject *object, Inkscape::XML::Node *repr, +static Inkscape::XML::Node *sp_genericellipse_write(SPObject *object, Inkscape::XML::Document *doc, Inkscape::XML::Node *repr, guint flags); static gboolean sp_arc_set_elliptical_path_attribute(SPArc *arc, Inkscape::XML::Node *repr); @@ -111,6 +110,7 @@ static void sp_genericellipse_class_init(SPGenericEllipseClass *klass) { SPObjectClass *sp_object_class = (SPObjectClass *) klass; SPItemClass *item_class = (SPItemClass *) klass; + SPLPEItemClass *lpe_item_class = (SPLPEItemClass *) klass; SPShapeClass *shape_class = (SPShapeClass *) klass; ge_parent_class = (SPShapeClass*) g_type_class_ref(SP_TYPE_SHAPE); @@ -121,7 +121,7 @@ static void sp_genericellipse_class_init(SPGenericEllipseClass *klass) item_class->snappoints = sp_genericellipse_snappoints; shape_class->set_shape = sp_genericellipse_set_shape; - shape_class->update_patheffect = sp_genericellipse_update_patheffect; + lpe_item_class->update_patheffect = sp_genericellipse_update_patheffect; } static void @@ -158,21 +158,17 @@ sp_genericellipse_update(SPObject *object, SPCtx *ctx, guint flags) } static void -sp_genericellipse_update_patheffect(SPShape *shape, bool write) +sp_genericellipse_update_patheffect(SPLPEItem *lpeitem, bool write) { + SPShape *shape = (SPShape *) lpeitem; sp_genericellipse_set_shape(shape); if (write) { Inkscape::XML::Node *repr = SP_OBJECT_REPR(shape); if ( shape->curve != NULL ) { - NArtBpath *abp = sp_curve_first_bpath(shape->curve); - if (abp) { - gchar *str = sp_svg_write_path(abp); - repr->setAttribute("d", str); - g_free(str); - } else { - repr->setAttribute("d", ""); - } + gchar *str = sp_svg_write_path(shape->curve->get_pathvector()); + repr->setAttribute("d", str); + g_free(str); } else { repr->setAttribute("d", NULL); } @@ -185,14 +181,14 @@ sp_genericellipse_update_patheffect(SPShape *shape, bool write) #define C1 0.552 /* fixme: Think (Lauris) */ - +/* Can't we use arcto in this method? */ static void sp_genericellipse_set_shape(SPShape *shape) { double rx, ry, s, e; double x0, y0, x1, y1, x2, y2, x3, y3; double len; gint slice = FALSE; - gint i; + // gint i; SPGenericEllipse *ellipse = (SPGenericEllipse *) shape; @@ -214,20 +210,8 @@ static void sp_genericellipse_set_shape(SPShape *shape) slice = TRUE; } - NR::Matrix aff = NR::Matrix(NR::scale(rx, ry)); - aff[4] = ellipse->cx.computed; - aff[5] = ellipse->cy.computed; - - NArtBpath bpath[16]; - i = 0; - if (ellipse->closed) { - bpath[i].code = NR_MOVETO; - } else { - bpath[i].code = NR_MOVETO_OPEN; - } - bpath[i].x3 = cos(ellipse->start); - bpath[i].y3 = sin(ellipse->start); - i++; + SPCurve * curve = new SPCurve(); + curve->moveto(cos(ellipse->start), sin(ellipse->start)); for (s = ellipse->start; s < ellipse->end; s += M_PI_2) { e = s + M_PI_2; @@ -246,40 +230,34 @@ static void sp_genericellipse_set_shape(SPShape *shape) g_print("step %d s %f e %f coords %f %f %f %f %f %f\n", i, s, e, x1, y1, x2, y2, x3, y3); #endif - bpath[i].code = NR_CURVETO; - bpath[i].x1 = x1; - bpath[i].y1 = y1; - bpath[i].x2 = x2; - bpath[i].y2 = y2; - bpath[i].x3 = x3; - bpath[i].y3 = y3; - i++; + curve->curveto(x1,y1, x2,y2, x3,y3); } - if (slice && ellipse->closed) { - bpath[i].code = NR_LINETO; - bpath[i].x3 = 0.0; - bpath[i].y3 = 0.0; - i++; - bpath[i].code = NR_LINETO; - bpath[i].x3 = bpath[0].x3; - bpath[i].y3 = bpath[0].y3; - i++; - } else if (ellipse->closed) { - bpath[i-1].x3 = bpath[0].x3; - bpath[i-1].y3 = bpath[0].y3; + if (slice && ellipse->closed) { // TODO: is this check for "ellipse->closed" necessary? + curve->lineto(0., 0.); + } + if (ellipse->closed) { + curve->closepath(); } - bpath[i].code = NR_END; - SPCurve *c = sp_curve_new_from_bpath(nr_artpath_affine(bpath, aff)); - g_assert(c != NULL); - - sp_shape_perform_path_effect(c, SP_SHAPE (ellipse)); - sp_shape_set_curve_insync((SPShape *) ellipse, c, TRUE); - sp_curve_unref(c); + Geom::Matrix aff = Geom::Scale(rx, ry) * Geom::Translate(ellipse->cx.computed, ellipse->cy.computed); + curve->transform(aff); + + /* Reset the shape'scurve to the "original_curve" + * This is very important for LPEs to work properly! (the bbox might be recalculated depending on the curve in shape)*/ + sp_shape_set_curve_insync (shape, curve, TRUE); + if (sp_lpe_item_has_path_effect(SP_LPE_ITEM(shape)) && sp_lpe_item_path_effects_enabled(SP_LPE_ITEM(shape))) { + SPCurve *c_lpe = curve->copy(); + bool success = sp_lpe_item_perform_path_effect(SP_LPE_ITEM (shape), c_lpe); + if (success) { + sp_shape_set_curve_insync (shape, c_lpe, TRUE); + } + c_lpe->unref(); + } + curve->unref(); } -static void sp_genericellipse_snappoints(SPItem const *item, SnapPointsIter p) +static void sp_genericellipse_snappoints(SPItem const *item, SnapPointsIter p, Inkscape::SnapPreferences const *snapprefs) { g_assert(item != NULL); g_assert(SP_IS_GENERICELLIPSE(item)); @@ -345,13 +323,12 @@ sp_genericellipse_normalize(SPGenericEllipse *ellipse) /* Now we keep: 0 <= start < end <= 2*PI */ } -static Inkscape::XML::Node *sp_genericellipse_write(SPObject *object, Inkscape::XML::Node *repr, guint flags) +static Inkscape::XML::Node *sp_genericellipse_write(SPObject *object, Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags) { SPGenericEllipse *ellipse = SP_GENERICELLIPSE(object); if (flags & SP_OBJECT_WRITE_EXT) { if ((flags & SP_OBJECT_WRITE_BUILD) && !repr) { - Inkscape::XML::Document *xml_doc = sp_document_repr_doc(SP_OBJECT_DOCUMENT(object)); repr = xml_doc->createElement("svg:path"); } @@ -365,7 +342,7 @@ static Inkscape::XML::Node *sp_genericellipse_write(SPObject *object, Inkscape:: } if (((SPObjectClass *) ge_parent_class)->write) - ((SPObjectClass *) ge_parent_class)->write(object, repr, flags); + ((SPObjectClass *) ge_parent_class)->write(object, xml_doc, repr, flags); return repr; } @@ -376,7 +353,7 @@ static void sp_ellipse_class_init(SPEllipseClass *klass); static void sp_ellipse_init(SPEllipse *ellipse); static void sp_ellipse_build(SPObject *object, SPDocument *document, Inkscape::XML::Node *repr); -static Inkscape::XML::Node *sp_ellipse_write(SPObject *object, Inkscape::XML::Node *repr, guint flags); +static Inkscape::XML::Node *sp_ellipse_write(SPObject *object, Inkscape::XML::Document *doc, Inkscape::XML::Node *repr, guint flags); static void sp_ellipse_set(SPObject *object, unsigned int key, gchar const *value); static gchar *sp_ellipse_description(SPItem *item); @@ -427,7 +404,6 @@ sp_ellipse_init(SPEllipse */*ellipse*/) static void sp_ellipse_build(SPObject *object, SPDocument *document, Inkscape::XML::Node *repr) { - g_print ("sp_ellipse_build\n"); if (((SPObjectClass *) ellipse_parent_class)->build) (* ((SPObjectClass *) ellipse_parent_class)->build) (object, document, repr); @@ -438,14 +414,13 @@ sp_ellipse_build(SPObject *object, SPDocument *document, Inkscape::XML::Node *re } static Inkscape::XML::Node * -sp_ellipse_write(SPObject *object, Inkscape::XML::Node *repr, guint flags) +sp_ellipse_write(SPObject *object, Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags) { SPGenericEllipse *ellipse; ellipse = SP_GENERICELLIPSE(object); if ((flags & SP_OBJECT_WRITE_BUILD) && !repr) { - Inkscape::XML::Document *xml_doc = sp_document_repr_doc(SP_OBJECT_DOCUMENT(object)); repr = xml_doc->createElement("svg:ellipse"); } @@ -455,7 +430,7 @@ sp_ellipse_write(SPObject *object, Inkscape::XML::Node *repr, guint flags) sp_repr_set_svg_double(repr, "ry", ellipse->ry.computed); if (((SPObjectClass *) ellipse_parent_class)->write) - (* ((SPObjectClass *) ellipse_parent_class)->write) (object, repr, flags); + (* ((SPObjectClass *) ellipse_parent_class)->write) (object, xml_doc, repr, flags); return repr; } @@ -525,7 +500,7 @@ static void sp_circle_class_init(SPCircleClass *klass); static void sp_circle_init(SPCircle *circle); static void sp_circle_build(SPObject *object, SPDocument *document, Inkscape::XML::Node *repr); -static Inkscape::XML::Node *sp_circle_write(SPObject *object, Inkscape::XML::Node *repr, guint flags); +static Inkscape::XML::Node *sp_circle_write(SPObject *object, Inkscape::XML::Document *doc, Inkscape::XML::Node *repr, guint flags); static void sp_circle_set(SPObject *object, unsigned int key, gchar const *value); static gchar *sp_circle_description(SPItem *item); @@ -586,14 +561,13 @@ sp_circle_build(SPObject *object, SPDocument *document, Inkscape::XML::Node *rep } static Inkscape::XML::Node * -sp_circle_write(SPObject *object, Inkscape::XML::Node *repr, guint flags) +sp_circle_write(SPObject *object, Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags) { SPGenericEllipse *ellipse; ellipse = SP_GENERICELLIPSE(object); if ((flags & SP_OBJECT_WRITE_BUILD) && !repr) { - Inkscape::XML::Document *xml_doc = sp_document_repr_doc(SP_OBJECT_DOCUMENT(object)); repr = xml_doc->createElement("svg:circle"); } @@ -602,7 +576,7 @@ sp_circle_write(SPObject *object, Inkscape::XML::Node *repr, guint flags) sp_repr_set_svg_double(repr, "r", ellipse->rx.computed); if (((SPObjectClass *) circle_parent_class)->write) - ((SPObjectClass *) circle_parent_class)->write(object, repr, flags); + ((SPObjectClass *) circle_parent_class)->write(object, xml_doc, repr, flags); return repr; } @@ -648,7 +622,7 @@ static void sp_arc_class_init(SPArcClass *klass); static void sp_arc_init(SPArc *arc); static void sp_arc_build(SPObject *object, SPDocument *document, Inkscape::XML::Node *repr); -static Inkscape::XML::Node *sp_arc_write(SPObject *object, Inkscape::XML::Node *repr, guint flags); +static Inkscape::XML::Node *sp_arc_write(SPObject *object, Inkscape::XML::Document *doc, Inkscape::XML::Node *repr, guint flags); static void sp_arc_set(SPObject *object, unsigned int key, gchar const *value); static void sp_arc_modified(SPObject *object, guint flags); @@ -761,13 +735,12 @@ sp_arc_set_elliptical_path_attribute(SPArc *arc, Inkscape::XML::Node *repr) } static Inkscape::XML::Node * -sp_arc_write(SPObject *object, Inkscape::XML::Node *repr, guint flags) +sp_arc_write(SPObject *object, Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags) { SPGenericEllipse *ge = SP_GENERICELLIPSE(object); SPArc *arc = SP_ARC(object); if ((flags & SP_OBJECT_WRITE_BUILD) && !repr) { - Inkscape::XML::Document *xml_doc = sp_document_repr_doc(SP_OBJECT_DOCUMENT(object)); repr = xml_doc->createElement("svg:path"); } @@ -796,7 +769,7 @@ sp_arc_write(SPObject *object, Inkscape::XML::Node *repr, guint flags) sp_arc_set_elliptical_path_attribute(arc, repr); if (((SPObjectClass *) arc_parent_class)->write) - ((SPObjectClass *) arc_parent_class)->write(object, repr, flags); + ((SPObjectClass *) arc_parent_class)->write(object, xml_doc, repr, flags); return repr; } @@ -894,11 +867,12 @@ sp_arc_position_set(SPArc *arc, gdouble x, gdouble y, gdouble rx, gdouble ry) ge->cy.computed = y; ge->rx.computed = rx; ge->ry.computed = ry; - if (prefs_get_double_attribute("tools.shapes.arc", "start", 0.0) != 0) - ge->start = prefs_get_double_attribute("tools.shapes.arc", "start", 0.0); - if (prefs_get_double_attribute("tools.shapes.arc", "end", 0.0) != 0) - ge->end = prefs_get_double_attribute("tools.shapes.arc", "end", 0.0); - if (!prefs_get_string_attribute("tools.shapes.arc", "open")) + Inkscape::Preferences *prefs = Inkscape::Preferences::get(); + if (prefs->getDouble("/tools/shapes/arc/start", 0.0) != 0) + ge->start = prefs->getDouble("/tools/shapes/arc/start", 0.0); + if (prefs->getDouble("/tools/shapes/arc/end", 0.0) != 0) + ge->end = prefs->getDouble("/tools/shapes/arc/end", 0.0); + if (!prefs->getBool("/tools/shapes/arc/open")) ge->closed = 1; else ge->closed = 0;