From 267299811df952d08324a39008f52c19641de9e0 Mon Sep 17 00:00:00 2001 From: Tavmjong Bah Date: Tue, 30 Jan 2018 09:33:01 +0100 Subject: Move classes derived from SPObject to own directory. A lot of header clean-up. --- src/object/sp-style-elem.cpp | 533 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 533 insertions(+) create mode 100644 src/object/sp-style-elem.cpp (limited to 'src/object/sp-style-elem.cpp') diff --git a/src/object/sp-style-elem.cpp b/src/object/sp-style-elem.cpp new file mode 100644 index 000000000..da02d4ef1 --- /dev/null +++ b/src/object/sp-style-elem.cpp @@ -0,0 +1,533 @@ +#include +#include "xml/node-event-vector.h" +#include "xml/repr.h" +#include "document.h" +#include "sp-style-elem.h" +#include "sp-root.h" +#include "attributes.h" +#include "style.h" + +// For external style sheets +#include "io/resource.h" +#include +#include + +// For font-rule +#include "libnrtype/FontFactory.h" + +using Inkscape::XML::TEXT_NODE; + +SPStyleElem::SPStyleElem() : SPObject() { + media_set_all(this->media); + this->is_css = false; +} + +SPStyleElem::~SPStyleElem() { +} + +void SPStyleElem::set(unsigned int key, const gchar* value) { + switch (key) { + case SP_ATTR_TYPE: { + if (!value) { + /* TODO: `type' attribute is required. Give error message as per + http://www.w3.org/TR/SVG11/implnote.html#ErrorProcessing. */ + is_css = false; + } else { + /* fixme: determine what whitespace is allowed. Will probably need to ask on SVG + list; though the relevant RFC may give info on its lexer. */ + is_css = ( g_ascii_strncasecmp(value, "text/css", 8) == 0 + && ( value[8] == '\0' || + value[8] == ';' ) ); + } + break; + } + +#if 0 /* unfinished */ + case SP_ATTR_MEDIA: { + parse_media(style_elem, value); + break; + } +#endif + + /* title is ignored. */ + default: { + SPObject::set(key, value); + break; + } + } +} + + +static void +child_add_rm_cb(Inkscape::XML::Node *, Inkscape::XML::Node *, Inkscape::XML::Node *, + void *const data) +{ + SPObject *obj = reinterpret_cast(data); + g_assert(data != NULL); + obj->read_content(); +} + +static void +content_changed_cb(Inkscape::XML::Node *, gchar const *, gchar const *, + void *const data) +{ + SPObject *obj = reinterpret_cast(data); + g_assert(data != NULL); + obj->read_content(); + obj->document->getRoot()->emitModified( SP_OBJECT_MODIFIED_CASCADE ); +} + +static void +child_order_changed_cb(Inkscape::XML::Node *, Inkscape::XML::Node *, + Inkscape::XML::Node *, Inkscape::XML::Node *, + void *const data) +{ + SPObject *obj = reinterpret_cast(data); + g_assert(data != NULL); + obj->read_content(); +} + +Inkscape::XML::Node* SPStyleElem::write(Inkscape::XML::Document* xml_doc, Inkscape::XML::Node* repr, guint flags) { + if ((flags & SP_OBJECT_WRITE_BUILD) && !repr) { + repr = xml_doc->createElement("svg:style"); + } + + if (flags & SP_OBJECT_WRITE_BUILD) { + g_warning("nyi: Forming