sp-polygon.cpp revision c87d0307348fcfdc65b6b4ab6999a3cb0de2431f
#define __SP_POLYGON_C__
/*
* SVG <polygon> implementation
*
* Authors:
* Lauris Kaplinski <lauris@kaplinski.com>
*
* Copyright (C) 1999-2002 Lauris Kaplinski
* Copyright (C) 2000-2001 Ximian, Inc.
*
* Released under GNU GPL, read the file 'COPYING' for more information
*/
#include "config.h"
#include "attributes.h"
#include "sp-polygon.h"
#include "libnr/n-art-bpath.h"
#include "svg/stringstream.h"
static Inkscape::XML::Node *sp_polygon_write(SPObject *object, Inkscape::XML::Node *repr, guint flags);
static SPShapeClass *parent_class;
GType sp_polygon_get_type(void)
{
static GType polygon_type = 0;
if (!polygon_type) {
sizeof(SPPolygonClass),
sizeof(SPPolygon),
16,
NULL, /* value_table */
};
}
return polygon_type;
}
{
}
{
/* Nothing here */
}
{
}
}
/*
* sp_svg_write_polygon: Write points attribute for polygon tag.
* @bpath:
*
* Return value: points attribute string.
*/
{
case NR_LINETO:
case NR_MOVETO:
case NR_MOVETO_OPEN:
break;
case NR_CURVETO:
default:
}
}
}
static Inkscape::XML::Node *sp_polygon_write(SPObject *object, Inkscape::XML::Node *repr, guint flags)
{
// Tolerable workaround: we need to update the object's curve before we set points=
// because it's out of sync when e.g. some extension attrs of the polygon or star are changed in XML editor
}
/* We can safely write points here, because all subclasses require it too (Lauris) */
}
return repr;
}
{
while (**p != '\0' && (**p == ',' || **p == '\x20' || **p == '\x9' || **p == '\xD' || **p == '\xA')) {
(*p)++;
}
if (*p == '\0') {
return false;
}
*v = g_ascii_strtod(*p, &e);
if (e == *p) {
return false;
}
*p = e;
return true;
}
{
switch (key) {
case SP_ATTR_POINTS: {
if (!value) {
/* fixme: The points attribute is required. We should handle its absence as per
* http://www.w3.org/TR/SVG11/implnote.html#ErrorProcessing. */
break;
}
bool has_error = false;
while (TRUE) {
gdouble x;
if (!polygon_get_value(&cptr, &x)) {
break;
}
gdouble y;
if (!polygon_get_value(&cptr, &y)) {
/* fixme: It is an error for an odd number of points to be specified. We
* should display the points up to now (as we currently do, though perhaps
* without the closepath: the spec isn't quite clear on whether to do a
* closepath or not, though I'd guess it's best not to do a closepath), but
* then flag the document as in error, as per
* http://www.w3.org/TR/SVG11/implnote.html#ErrorProcessing.
*
* (Ref: http://www.w3.org/TR/SVG11/shapes.html#PolygonElement.) */
has_error = true;
break;
}
if (hascpt) {
sp_curve_lineto(curve, x, y);
} else {
sp_curve_moveto(curve, x, y);
}
}
/* TODO: Flag the document as in error, as per
* http://www.w3.org/TR/SVG11/implnote.html#ErrorProcessing. */
/* We've done a moveto but no lineto. I'm not sure how we're supposed to represent
* a single-point polygon in SPCurve: sp_curve_closepath at the time of writing
* doesn't seem to like simply moveto followed by closepath. The following works,
* but won't round-trip properly: I believe it will write as two points rather than
* one. */
} else if (hascpt) {
}
break;
}
default:
}
break;
}
}
{
return g_strdup(_("<b>Polygon</b>"));
}
/*
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 :