// 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 "sp-style-elem.h" #include "3rdparty/libcroco/src/cr-parser.h" #include "attributes.h" #include "document.h" #include "sp-root.h" #include "style.h" #include "xml/repr.h" // For external style sheets #include #include #include "io/resource.h" // For font-rule #include "libnrtype/font-factory.h" void SPStyleElemTextNodeObserver::notifyContentChanged(Inkscape::XML::Node &, Inkscape::Util::ptr_shared, Inkscape::Util::ptr_shared) { auto styleelem = static_cast(this); styleelem->read_content(); styleelem->document->getRoot()->emitModified(SP_OBJECT_MODIFIED_CASCADE); } void SPStyleElemNodeObserver::notifyChildAdded(Inkscape::XML::Node &, Inkscape::XML::Node &child, Inkscape::XML::Node *) { auto styleelem = static_cast(this); if (child.type() == Inkscape::XML::NodeType::TEXT_NODE) { child.addObserver(styleelem->textNodeObserver()); } styleelem->read_content(); } void SPStyleElemNodeObserver::notifyChildRemoved(Inkscape::XML::Node &, Inkscape::XML::Node &child, Inkscape::XML::Node *) { auto styleelem = static_cast(this); child.removeObserver(styleelem->textNodeObserver()); styleelem->read_content(); } void SPStyleElemNodeObserver::notifyChildOrderChanged(Inkscape::XML::Node &, Inkscape::XML::Node &, Inkscape::XML::Node *, Inkscape::XML::Node *) { auto stylelem = static_cast(this); stylelem->read_content(); } SPStyleElem::SPStyleElem() { media_set_all(this->media); } SPStyleElem::~SPStyleElem() = default; void SPStyleElem::set(SPAttr key, char const *value) { switch (key) { case SPAttr::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 SPAttr::MEDIA: { parse_media(style_elem, value); break; } #endif /* title is ignored. */ default: { SPObject::set(key, value); break; } } } 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