diff --git a/src/sp-line.cpp b/src/sp-line.cpp
index 5fed6a62ea1aff7e5c019ae675a5c40f7a4583c4..d0ce32397d7ffe801b0447c7c5c8b39a902a42c7 100644 (file)
--- a/src/sp-line.cpp
+++ b/src/sp-line.cpp
#include "attributes.h"
#include "style.h"
#include "sp-line.h"
+#include "sp-guide.h"
#include "display/curve.h"
#include <glibmm/i18n.h>
#include <libnr/nr-matrix-fns.h>
#include <xml/repr.h>
#include "document.h"
+#include "inkscape.h"
static void sp_line_class_init (SPLineClass *klass);
static void sp_line_init (SPLine *line);
static void sp_line_build (SPObject * object, SPDocument * document, Inkscape::XML::Node * repr);
static void sp_line_set (SPObject *object, unsigned int key, const gchar *value);
-static Inkscape::XML::Node *sp_line_write (SPObject *object, Inkscape::XML::Node *repr, guint flags);
+static Inkscape::XML::Node *sp_line_write (SPObject *object, Inkscape::XML::Document *doc, Inkscape::XML::Node *repr, guint flags);
static gchar *sp_line_description (SPItem * item);
-static NR::Matrix sp_line_set_transform(SPItem *item, NR::Matrix const &xform);
+static Geom::Matrix sp_line_set_transform(SPItem *item, Geom::Matrix const &xform);
static void sp_line_update (SPObject *object, SPCtx *ctx, guint flags);
static void sp_line_set_shape (SPShape *shape);
+static void sp_line_convert_to_guides(SPItem *item);
static SPShapeClass *parent_class;
SPItemClass *item_class = (SPItemClass *) klass;
item_class->description = sp_line_description;
item_class->set_transform = sp_line_set_transform;
+ item_class->convert_to_guides = sp_line_convert_to_guides;
sp_object_class->update = sp_line_update;
SPLine *line = SP_LINE (object);
SPStyle const *style = object->style;
- double const d = 1.0 / NR::expansion(((SPItemCtx const *) ctx)->i2vp);
+ SPItemCtx const *ictx = (SPItemCtx const *) ctx;
+ double const w = (ictx->vp.x1 - ictx->vp.x0);
+ double const h = (ictx->vp.y1 - ictx->vp.y0);
double const em = style->font_size.computed;
double const ex = em * 0.5; // fixme: get from pango or libnrtype.
- line->x1.update(em, ex, d);
- line->x2.update(em, ex, d);
- line->y1.update(em, ex, d);
- line->y2.update(em, ex, d);
+ line->x1.update(em, ex, w);
+ line->x2.update(em, ex, w);
+ line->y1.update(em, ex, h);
+ line->y2.update(em, ex, h);
sp_shape_set_shape ((SPShape *) object);
}
static Inkscape::XML::Node *
-sp_line_write (SPObject *object, Inkscape::XML::Node *repr, guint flags)
+sp_line_write (SPObject *object, Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags)
{
SPLine *line = SP_LINE (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:line");
}
sp_repr_set_svg_double(repr, "y2", line->y2.computed);
if (((SPObjectClass *) (parent_class))->write)
- ((SPObjectClass *) (parent_class))->write (object, repr, flags);
+ ((SPObjectClass *) (parent_class))->write (object, xml_doc, repr, flags);
return repr;
}
return g_strdup(_("<b>Line</b>"));
}
-static NR::Matrix
-sp_line_set_transform (SPItem *item, NR::Matrix const &xform)
+static void
+sp_line_convert_to_guides(SPItem *item)
+{
+ SPLine *line = SP_LINE(item);
+ Geom::Point points[2];
+
+ Geom::Matrix const i2d (sp_item_i2d_affine(item));
+
+ points[0] = Geom::Point(line->x1.computed, line->y1.computed)*i2d;
+ points[1] = Geom::Point(line->x2.computed, line->y2.computed)*i2d;
+
+ sp_guide_create(inkscape_active_desktop(), points[0], points[1]);
+}
+
+static Geom::Matrix
+sp_line_set_transform (SPItem *item, Geom::Matrix const &xform)
{
SPLine *line = SP_LINE (item);
- NR::Point points[2];
+ Geom::Point points[2];
- points[0] = NR::Point(line->x1.computed, line->y1.computed);
- points[1] = NR::Point(line->x2.computed, line->y2.computed);
+ points[0] = Geom::Point(line->x1.computed, line->y1.computed);
+ points[1] = Geom::Point(line->x2.computed, line->y2.computed);
points[0] *= xform;
points[1] *= xform;
- line->x1.computed = points[0][NR::X];
- line->y1.computed = points[0][NR::Y];
- line->x2.computed = points[1][NR::X];
- line->y2.computed = points[1][NR::Y];
+ line->x1.computed = points[0][Geom::X];
+ line->y1.computed = points[0][Geom::Y];
+ line->x2.computed = points[1][Geom::X];
+ line->y2.computed = points[1][Geom::Y];
- sp_item_adjust_stroke(item, NR::expansion(xform));
+ sp_item_adjust_stroke(item, xform.descrim());
SP_OBJECT (item)->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_STYLE_MODIFIED_FLAG);
- return NR::identity();
+ return Geom::identity();
}
static void