sp-polyline.cpp revision 544f621be9be523852514d3f0924ceb6240c5807
6741N/A/*
6741N/A * SVG <polyline> implementation
6741N/A *
6741N/A * Authors:
6741N/A * Lauris Kaplinski <lauris@kaplinski.com>
6741N/A * Abhishek Sharma
6741N/A * Jon A. Cruz <jon@joncruz.org>
6741N/A *
6741N/A * Copyright (C) 1999-2002 Lauris Kaplinski
6741N/A *
6741N/A * Released under GNU GPL, read the file 'COPYING' for more information
6741N/A */
6741N/A
6741N/A#include "config.h"
6741N/A
6741N/A#include "attributes.h"
6741N/A#include "sp-polyline.h"
6741N/A#include "display/curve.h"
6741N/A#include <glibmm/i18n.h>
6741N/A#include "xml/repr.h"
6741N/A#include "document.h"
6741N/A
6741N/ASPShapeClass * SPPolyLineClass::static_parent_class=0;
6741N/A
6741N/AGType SPPolyLine::sp_polyline_get_type(void)
6741N/A{
6741N/A static GType polyline_type = 0;
6741N/A
6741N/A if (!polyline_type) {
6741N/A GTypeInfo polyline_info = {
6741N/A sizeof (SPPolyLineClass),
6741N/A NULL, /* base_init */
6741N/A NULL, /* base_finalize */
6741N/A (GClassInitFunc) SPPolyLineClass::sp_polyline_class_init,
6741N/A NULL, /* klass_finalize */
6741N/A NULL, /* klass_data */
6741N/A sizeof (SPPolyLine),
6741N/A 16, /* n_preallocs */
6741N/A (GInstanceInitFunc) SPPolyLine::init,
6741N/A NULL, /* value_table */
6741N/A };
6741N/A polyline_type = g_type_register_static (SP_TYPE_SHAPE, "SPPolyLine", &polyline_info, (GTypeFlags)0);
6741N/A }
6741N/A return polyline_type;
6741N/A}
6741N/A
6741N/Avoid SPPolyLineClass::sp_polyline_class_init(SPPolyLineClass *klass)
6741N/A{
6741N/A //GObjectClass * gobject_class = (GObjectClass *) klass;
6741N/A SPObjectClass * sp_object_class = (SPObjectClass *) klass;
6741N/A SPItemClass * item_class = (SPItemClass *) klass;
6741N/A
6741N/A static_parent_class = (SPShapeClass *)g_type_class_ref(SP_TYPE_SHAPE);
6741N/A
6741N/A sp_object_class->build = SPPolyLine::build;
6741N/A sp_object_class->set = SPPolyLine::set;
6741N/A sp_object_class->write = SPPolyLine::write;
item_class->description = SPPolyLine::getDescription;
}
CPolyLine::CPolyLine(SPPolyLine* polyline) : CShape(polyline) {
this->sppolyline = polyline;
}
CPolyLine::~CPolyLine() {
}
void SPPolyLine::init(SPPolyLine * polyline)
{
polyline->cpolyline = new CPolyLine(polyline);
polyline->cshape = polyline->cpolyline;
polyline->clpeitem = polyline->cpolyline;
polyline->citem = polyline->cpolyline;
polyline->cobject = polyline->cpolyline;
}
void CPolyLine::onBuild(SPDocument * document, Inkscape::XML::Node * repr) {
SPPolyLine* object = this->sppolyline;
CShape::onBuild(document, repr);
object->readAttr( "points" );
}
// CPPIFY: remove
void SPPolyLine::build(SPObject * object, SPDocument * document, Inkscape::XML::Node * repr)
{
((SPPolyLine*)object)->cpolyline->onBuild(document, repr);
}
void CPolyLine::onSet(unsigned int key, const gchar* value) {
SPPolyLine* object = this->sppolyline;
SPPolyLine *polyline = object;
switch (key) {
case SP_ATTR_POINTS: {
SPCurve * curve;
const gchar * cptr;
char * eptr;
gboolean hascpt;
if (!value) break;
curve = new SPCurve ();
hascpt = FALSE;
cptr = value;
eptr = NULL;
while (TRUE) {
gdouble x, y;
while (*cptr != '\0' && (*cptr == ',' || *cptr == '\x20' || *cptr == '\x9' || *cptr == '\xD' || *cptr == '\xA')) {
cptr++;
}
if (!*cptr) break;
x = g_ascii_strtod (cptr, &eptr);
if (eptr == cptr) break;
cptr = eptr;
while (*cptr != '\0' && (*cptr == ',' || *cptr == '\x20' || *cptr == '\x9' || *cptr == '\xD' || *cptr == '\xA')) {
cptr++;
}
if (!*cptr) break;
y = g_ascii_strtod (cptr, &eptr);
if (eptr == cptr) break;
cptr = eptr;
if (hascpt) {
curve->lineto(x, y);
} else {
curve->moveto(x, y);
hascpt = TRUE;
}
}
(SP_SHAPE (polyline))->setCurve (curve, TRUE);
curve->unref();
break;
}
default:
CShape::onSet(key, value);
break;
}
}
// CPPIFY: remove
void SPPolyLine::set(SPObject *object, unsigned int key, const gchar *value)
{
((SPPolyLine*)object)->cpolyline->onSet(key, value);
}
Inkscape::XML::Node* CPolyLine::onWrite(Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags) {
SPPolyLine* object = this->sppolyline;
// CPPIFY: This is a simple type check?
//SP_POLYLINE(object);
if ((flags & SP_OBJECT_WRITE_BUILD) && !repr) {
repr = xml_doc->createElement("svg:polyline");
}
if (repr != object->getRepr()) {
repr->mergeFrom(object->getRepr(), "id");
}
CShape::onWrite(xml_doc, repr, flags);
return repr;
}
// CPPIFY: remove
Inkscape::XML::Node *SPPolyLine::write(SPObject *object, Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags)
{
return ((SPPolyLine*)object)->cpolyline->onWrite(xml_doc, repr, flags);
}
gchar* CPolyLine::onDescription() {
return g_strdup(_("<b>Polyline</b>"));
}
// CPPIFY: remove
gchar *SPPolyLine::getDescription(SPItem * item)
{
return ((SPPolyLine*)item)->cpolyline->onDescription();
}
/*
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 :