Ejemplo n.º 1
0
void SPLine::set(SPObject *object, unsigned int key, const gchar *value)
{
    SPLine * line = SP_LINE(object);

    /* fixme: we should really collect updates */

    switch (key) {
        case SP_ATTR_X1:
            line->x1.readOrUnset(value);
            object->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
            break;
        case SP_ATTR_Y1:
            line->y1.readOrUnset(value);
            object->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
            break;
        case SP_ATTR_X2:
            line->x2.readOrUnset(value);
            object->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
            break;
        case SP_ATTR_Y2:
            line->y2.readOrUnset(value);
            object->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
            break;
        default:
            if (((SPObjectClass *) SPLineClass::static_parent_class)->set) {
                ((SPObjectClass *) SPLineClass::static_parent_class)->set(object, key, value);
            }
            break;
    }
}
Ejemplo n.º 2
0
void SPLine::convertToGuides(SPItem *item)
{
    SPLine *line = SP_LINE(item);
    Geom::Point points[2];

    Geom::Affine const i2dt(item->i2dt_affine());

    points[0] = Geom::Point(line->x1.computed, line->y1.computed)*i2dt;
    points[1] = Geom::Point(line->x2.computed, line->y2.computed)*i2dt;

    SPGuide::createSPGuide(item->document, points[0], points[1]);
}
Ejemplo n.º 3
0
static void
sp_line_set_shape (SPShape *shape)
{
	SPLine *line = SP_LINE (shape);

	SPCurve *c = new SPCurve ();

	c->moveto(line->x1.computed, line->y1.computed);
	c->lineto(line->x2.computed, line->y2.computed);

	sp_shape_set_curve_insync (shape, c, TRUE); // *_insync does not call update, avoiding infinite recursion when set_shape is called by update

	c->unref();
}
Ejemplo n.º 4
0
void SPLine::setShape(SPShape *shape)
{
    SPLine *line = SP_LINE(shape);

    SPCurve *c = new SPCurve();

    c->moveto(line->x1.computed, line->y1.computed);
    c->lineto(line->x2.computed, line->y2.computed);

    shape->setCurveInsync(c, TRUE); // *_insync does not call update, avoiding infinite recursion when set_shape is called by update
    shape->setCurveBeforeLPE(c);

    // LPE's cannot be applied to lines. (the result can (generally) not be represented as SPLine)

    c->unref();
}
Ejemplo n.º 5
0
static void
sp_line_update (SPObject *object, SPCtx *ctx, guint flags)
{
	if (flags & (SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_STYLE_MODIFIED_FLAG | SP_OBJECT_VIEWPORT_MODIFIED_FLAG)) {
		SPLine *line = SP_LINE (object);

 		SPStyle const *style = object->style;
 		double const d = 1.0 / NR::expansion(((SPItemCtx const *) ctx)->i2vp);
		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);

		sp_shape_set_shape ((SPShape *) object);
	}

	if (((SPObjectClass *) parent_class)->update)
		((SPObjectClass *) parent_class)->update (object, ctx, flags);
}
Ejemplo n.º 6
0
Geom::Affine SPLine::setTransform(SPItem *item, Geom::Affine const &xform)
{
    SPLine *line = SP_LINE(item);
    Geom::Point points[2];

    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][Geom::X];
    line->y1.computed = points[0][Geom::Y];
    line->x2.computed = points[1][Geom::X];
    line->y2.computed = points[1][Geom::Y];

    item->adjust_stroke(xform.descrim());

    SP_OBJECT(item)->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_STYLE_MODIFIED_FLAG);

    return Geom::identity();
}
Ejemplo n.º 7
0
Inkscape::XML::Node * SPLine::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) {
        repr = xml_doc->createElement("svg:line");
    }

    if (repr != object->getRepr()) {
        repr->mergeFrom(object->getRepr(), "id");
    }

    sp_repr_set_svg_double(repr, "x1", line->x1.computed);
    sp_repr_set_svg_double(repr, "y1", line->y1.computed);
    sp_repr_set_svg_double(repr, "x2", line->x2.computed);
    sp_repr_set_svg_double(repr, "y2", line->y2.computed);

    if (((SPObjectClass *) (SPLineClass::static_parent_class))->write) {
        ((SPObjectClass *) (SPLineClass::static_parent_class))->write(object, xml_doc, repr, flags);
    }

    return repr;
}
Ejemplo n.º 8
0
void SPLine::update(SPObject *object, SPCtx *ctx, guint flags)
{
    if (flags & (SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_STYLE_MODIFIED_FLAG | SP_OBJECT_VIEWPORT_MODIFIED_FLAG)) {
        SPLine *line = SP_LINE(object);

        SPStyle const *style = object->style;
        SPItemCtx const *ictx = (SPItemCtx const *) ctx;
        double const w = ictx->viewport.width();
        double const h = ictx->viewport.height();
        double const em = style->font_size.computed;
        double const ex = em * 0.5;  // fixme: get from pango or libnrtype.
        line->x1.update(em, ex, w);
        line->x2.update(em, ex, w);
        line->y1.update(em, ex, h);
        line->y2.update(em, ex, h);

        ((SPShape *) object)->setShape();
    }

    if (((SPObjectClass *) SPLineClass::static_parent_class)->update) {
        ((SPObjectClass *) SPLineClass::static_parent_class)->update(object, ctx, flags);
    }
}
Ejemplo n.º 9
0
static Geom::Matrix
sp_line_set_transform (SPItem *item, Geom::Matrix const &xform)
{
	SPLine *line = SP_LINE (item);
	Geom::Point points[2];

	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][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, xform.descrim());

	SP_OBJECT (item)->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_STYLE_MODIFIED_FLAG);

	return Geom::identity();
}