sp-rect.cpp revision 1b5ad44f5a431316b6f618a44320e22e5908abcb
/*
* SVG <rect> implementation
*
* Authors:
* Lauris Kaplinski <lauris@kaplinski.com>
* bulia byak <buliabyak@users.sf.net>
*
* Copyright (C) 1999-2002 Lauris Kaplinski
* Copyright (C) 2000-2001 Ximian, Inc.
*
* Released under GNU GPL, read the file 'COPYING' for more information
*/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include <libnr/nr-matrix-ops.h>
#include <libnr/nr-matrix-fns.h>
#include "inkscape.h"
#include "document.h"
#include "attributes.h"
#include "style.h"
#include "sp-rect.h"
#include "sp-guide.h"
#include "preferences.h"
#define noRECT_VERBOSE
static Inkscape::XML::Node *sp_rect_write(SPObject *object, Inkscape::XML::Document *doc, Inkscape::XML::Node *repr, guint flags);
static void sp_rect_snappoints(SPItem const *item, bool const target, SnapPointsWithType &p, Inkscape::SnapPreferences const *snapprefs);
static SPShapeClass *parent_class;
sp_rect_get_type(void)
{
if (!type) {
sizeof(SPRectClass),
NULL, /* base_init */
NULL, /* base_finalize */
NULL, /* class_finalize */
NULL, /* class_data */
sizeof(SPRect),
16, /* n_preallocs */
NULL, /* value_table */
};
}
return type;
}
static void
{
item_class->snappoints = sp_rect_snappoints; //override the default sp_shape_snappoints; see sp_rect_snappoints for details
}
static void
{
/* Initializing to zero is automatic */
/* sp_svg_length_unset(&rect->x, SP_SVG_UNIT_NONE, 0.0, 0.0); */
/* sp_svg_length_unset(&rect->y, SP_SVG_UNIT_NONE, 0.0, 0.0); */
/* sp_svg_length_unset(&rect->width, SP_SVG_UNIT_NONE, 0.0, 0.0); */
/* sp_svg_length_unset(&rect->height, SP_SVG_UNIT_NONE, 0.0, 0.0); */
/* sp_svg_length_unset(&rect->rx, SP_SVG_UNIT_NONE, 0.0, 0.0); */
/* sp_svg_length_unset(&rect->ry, SP_SVG_UNIT_NONE, 0.0, 0.0); */
}
static void
{
}
static void
{
/* fixme: We need real error processing some time */
switch (key) {
case SP_ATTR_X:
break;
case SP_ATTR_Y:
break;
case SP_ATTR_WIDTH:
}
break;
case SP_ATTR_HEIGHT:
}
break;
case SP_ATTR_RX:
}
break;
case SP_ATTR_RY:
}
break;
default:
break;
}
}
static void
{
if (flags & (SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_STYLE_MODIFIED_FLAG | SP_OBJECT_VIEWPORT_MODIFIED_FLAG)) {
flags &= ~SP_OBJECT_USER_MODIFIED_FLAG_B; // since we change the description, it's not a "just translation" anymore
}
}
sp_rect_write(SPObject *object, Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags)
{
}
return repr;
}
static gchar *
{
return g_strdup(_("<b>Rectangle</b>"));
}
#define C1 0.554
static void
{
return;
}
double const w2 = w / 2;
double const h2 = h / 2;
: 0.0 ) ),
: 0.0 ) ),
/* TODO: Handle negative rx or ry as per
* http://www.w3.org/TR/SVG11/shapes.html#RectElementRXAttribute once Inkscape has proper error
* handling (see http://www.w3.org/TR/SVG11/implnote.html#ErrorProcessing).
*/
/* We don't use proper circular/elliptical arcs, but bezier curves can approximate a 90-degree
* arc fairly well.
*/
} else {
c->lineto(x + w, y + 0.0);
c->lineto(x + w, y + h);
c->lineto(x + 0.0, y + h);
}
c->closepath_current();
c->unref();
}
/* fixme: Think (Lauris) */
void
{
}
void
{
}
void
{
}
/*
* Initially we'll do:
* Transform x, y, set x, y, clear translation
*/
/* fixme: Use preferred units somehow (Lauris) */
/* fixme: Alternately preserve whatever units there are (lauris) */
{
/* Calculate rect start in parent coords. */
/* This function takes care of translation and scaling, we return whatever parts we can't
handle. */
if (sw > 1e-9) {
} else {
ret[0] = 1.0;
}
if (sh > 1e-9) {
} else {
}
/* fixme: Would be nice to preserve units here */
}
}
/* Find start in item coords */
// Adjust stroke width
// Adjust pattern fill
// Adjust gradient fill
return ret;
}
/**
Returns the ratio in which the vector from p0 to p1 is stretched by transform
*/
static gdouble
{
return 0;
}
void
{
if (rx == 0) {
} else {
}
}
void
{
if (ry == 0) {
} else {
}
}
{
return 0;
}
{
return 0;
}
void
{
return; // nothing to compensate
// test unit vectors to find out compensation:
// apply previous transform if any
// find out stretches that we need to compensate
// If only one of the radii is set, set both radii so they have the same visible length
// This is needed because if we just set them the same length in SVG, they might end up unequal because of transform
} else {
}
// Note that a radius may end up larger than half-side if the rect is scaled down;
// that's ok because this preserves the intended radii in case the rect is enlarged again,
// and set_shape will take care of trimming too large radii when generating d=
}
void
{
}
void
{
}
{
return 0;
}
{
return 0;
}
/**
* Sets the snappoint p to the unrounded corners of the rectangle
*/
static void sp_rect_snappoints(SPItem const *item, bool const target, SnapPointsWithType &p, Inkscape::SnapPreferences const *snapprefs)
{
/* This method overrides sp_shape_snappoints, which is the default for any shape. The default method
returns all eight points along the path of a rounded rectangle, but not the real corners. Snapping
the startpoint and endpoint of each rounded corner is not very useful and really confusing. Instead
we could snap either the real corners, or not snap at all. Bulia Byak opted to snap the real corners,
but it should be noted that this might be confusing in some cases with relatively large radii. With
small radii though the user will easily understand which point is snapping. */
// Help enforcing strict snapping, i.e. only return nodes when we're snapping nodes to nodes or a guide to nodes
return;
}
Geom::Point p2 = Geom::Point(rect->x.computed + rect->width.computed, rect->y.computed + rect->height.computed) * i2d;
int type;
if (snapprefs->getSnapToItemNode()) {
}
if (snapprefs->getSnapLineMidpoints()) { // only do this when we're snapping nodes (enforce strict snapping)
}
if (snapprefs->getSnapObjectMidpoints()) { // only do this when we're snapping nodes (enforce strict snapping)
type = target ? int(Inkscape::SNAPTARGET_OBJECT_MIDPOINT) : int(Inkscape::SNAPSOURCE_OBJECT_MIDPOINT);
}
}
void
return;
}
Geom::Point A3(Geom::Point(rect->x.computed + rect->width.computed, rect->y.computed + rect->height.computed) * i2d);
}
/*
Local Variables:
mode:c++
c-file-style:"stroustrup"
c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
indent-tabs-mode:nil
fill-column:99
End:
*/
// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :