From: ishmal Date: Wed, 4 Jun 2008 21:21:15 +0000 (+0000) Subject: first try at attribute overloading X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=2526c9b46950f0c99bf41a4ea778140efc16a5ff;p=inkscape.git first try at attribute overloading --- diff --git a/src/dom/svgimpl.cpp b/src/dom/svgimpl.cpp index d2a7e2794..6b2a7fe70 100644 --- a/src/dom/svgimpl.cpp +++ b/src/dom/svgimpl.cpp @@ -45,6 +45,29 @@ namespace svg { +/*######################################################################### +## U T I L I T Y +#########################################################################*/ + +static DOMString d2s(double d) +{ + char buf[40]; + snprintf(buf, 40, "%f", d); + DOMString s(buf); + return s; +} + +static double s2d(const DOMString &s) +{ + const char *begin = s.c_str(); + char *end; + double val = strtod(begin, &end); + if (end <= begin) + return 0.0; + return val; +} + + /*######################################################################### ## Element type lookup table #########################################################################*/ @@ -667,6 +690,36 @@ void SVGDocumentImpl::init() #########################################################################*/ +/** + * Retrieves an attribute value by name. + */ +DOMString SVGSVGElementImpl::getAttribute(const DOMString& name) +{ + DOMString s; + if (name == "x") + s = d2s(x.getAnimVal().getValue()); + else if (name == "y") + s = d2s(y.getAnimVal().getValue()); + else + s = SVGElement::getAttribute(name); + return s; +} + +/** + * Sets an attribute value + */ +void SVGSVGElementImpl::setAttribute(const DOMString& name, + const DOMString& value) + throw(DOMException) +{ + if (name == "x") + x.getAnimVal().setValue(s2d(value)); + else if (name == "y") + y.getAnimVal().setValue(s2d(value)); + SVGElement::setAttribute(name, value); +} + + /** * */ diff --git a/src/dom/svgimpl.h b/src/dom/svgimpl.h index 701952b0b..4258de58e 100644 --- a/src/dom/svgimpl.h +++ b/src/dom/svgimpl.h @@ -638,6 +638,18 @@ class SVGSVGElementImpl : virtual public SVGSVGElement, { public: + /** + * Retrieves an attribute value by name. + */ + virtual DOMString getAttribute(const DOMString& name); + + /** + * Sets an attribute value + */ + virtual void setAttribute(const DOMString& name, + const DOMString& value) + throw(DOMException); + /** * */