// SPDX-License-Identifier: GPL-2.0-or-later /** @file * TODO: insert short description here *//* * Authors: see git history * * Copyright (C) 2018 Authors * Released under GNU GPL v2+, read the file 'COPYING' for more information. */ #include <3rdparty/libcroco/cr-parser.h> #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; this->style_sheet = nullptr; } SPStyleElem::~SPStyleElem() = default; void SPStyleElem::set(SPAttributeEnum 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 != nullptr); 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 != nullptr); 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 != nullptr); 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