From 73bf5715250b01217421ccdcb61bbd454aa705ea Mon Sep 17 00:00:00 2001 From: Martin Owens Date: Mon, 2 Jun 2025 10:41:52 -0400 Subject: [PATCH 1/2] Refactor SPCSSAttr so it can be tested properly The SPCSSAttr class was not effectively a realy object which made it a pretty bad C++ API as well as more dificult to test overall. We carefully clean the API without changing it's usage too much and add some tests. --- src/actions/actions-svg-processing.cpp | 1 + src/attribute-rel-util.h | 2 +- src/attribute-sort-util.cpp | 2 +- src/desktop-style.cpp | 2 +- .../internal/pdfinput/svg-builder.cpp | 2 +- src/file.cpp | 2 +- src/gradient-drag.cpp | 2 +- src/live_effects/effect.cpp | 2 +- src/live_effects/lpe-clone-original.cpp | 2 +- src/live_effects/lpe-copy_rotate.cpp | 2 +- src/live_effects/lpe-measure-segments.cpp | 2 +- src/live_effects/lpe-slice.cpp | 2 +- src/object/sp-item.h | 1 + src/text-editing.cpp | 2 +- src/ui/clipboard.cpp | 2 +- src/ui/dialog/selectorsdialog.cpp | 2 +- src/ui/dialog/styledialog.cpp | 2 +- src/ui/tools/pencil-tool.cpp | 2 +- src/ui/tools/text-tool.cpp | 2 +- src/ui/widget/style-subject.cpp | 2 +- src/ui/widget/style-swatch.cpp | 2 +- src/util/object-renderer.cpp | 2 + src/xml/CMakeLists.txt | 2 +- src/xml/repr-css.cpp | 12 ++--- src/xml/repr-css.h | 53 +++++++++++++++++++ src/xml/repr-util.cpp | 1 + src/xml/repr.h | 26 --------- testfiles/CMakeLists.txt | 1 + .../src/xml-css-test.cpp | 31 ++++++----- 29 files changed, 101 insertions(+), 67 deletions(-) create mode 100644 src/xml/repr-css.h rename src/xml/sp-css-attr.h => testfiles/src/xml-css-test.cpp (55%) diff --git a/src/actions/actions-svg-processing.cpp b/src/actions/actions-svg-processing.cpp index f22cf79ad4..52ce659de7 100644 --- a/src/actions/actions-svg-processing.cpp +++ b/src/actions/actions-svg-processing.cpp @@ -33,6 +33,7 @@ #include "svg/svg.h" #include "xml/attribute-record.h" #include "xml/node.h" +#include "xml/repr-css.h" /* * Removes all sodipodi and inkscape elements and attributes from an xml tree. diff --git a/src/attribute-rel-util.h b/src/attribute-rel-util.h index 490c9bc5da..b1542d8226 100644 --- a/src/attribute-rel-util.h +++ b/src/attribute-rel-util.h @@ -14,7 +14,7 @@ #include -#include "xml/sp-css-attr.h" +#include "xml/repr-css.h" using Inkscape::XML::Node; diff --git a/src/attribute-sort-util.cpp b/src/attribute-sort-util.cpp index 56072b3a4e..28271f3b87 100644 --- a/src/attribute-sort-util.cpp +++ b/src/attribute-sort-util.cpp @@ -31,7 +31,7 @@ #include "xml/repr.h" #include "xml/attribute-record.h" -#include "xml/sp-css-attr.h" +#include "xml/repr-css.h" #include "attributes.h" diff --git a/src/desktop-style.cpp b/src/desktop-style.cpp index ce09066081..d94525e597 100644 --- a/src/desktop-style.cpp +++ b/src/desktop-style.cpp @@ -53,7 +53,7 @@ #include "ui/tools/tool-base.h" #include -#include "xml/sp-css-attr.h" +#include "xml/repr-css.h" #include "xml/attribute-record.h" static bool isTextualItem(SPObject const *obj) diff --git a/src/extension/internal/pdfinput/svg-builder.cpp b/src/extension/internal/pdfinput/svg-builder.cpp index 979a5048cf..db248f3d1e 100644 --- a/src/extension/internal/pdfinput/svg-builder.cpp +++ b/src/extension/internal/pdfinput/svg-builder.cpp @@ -51,7 +51,7 @@ #include "xml/document.h" #include "xml/node.h" #include "xml/repr.h" -#include "xml/sp-css-attr.h" +#include "xml/repr-css.h" #include "helper/geom.h" namespace Inkscape { diff --git a/src/file.cpp b/src/file.cpp index 60d148ad89..a5d6a4eb8c 100644 --- a/src/file.cpp +++ b/src/file.cpp @@ -72,7 +72,7 @@ #include "ui/tools/tool-base.h" #include "util/recently-used-fonts.h" #include "xml/rebase-hrefs.h" -#include "xml/sp-css-attr.h" +#include "xml/repr-css.h" using Inkscape::DocumentUndo; using Inkscape::IO::Resource::TEMPLATES; diff --git a/src/gradient-drag.cpp b/src/gradient-drag.cpp index 9000030a1b..ca6d638b6b 100644 --- a/src/gradient-drag.cpp +++ b/src/gradient-drag.cpp @@ -51,7 +51,7 @@ #include "ui/tools/tool-base.h" #include "ui/widget/events/canvas-event.h" -#include "xml/sp-css-attr.h" +#include "xml/repr-css.h" using Inkscape::DocumentUndo; using Inkscape::allPaintTargets; diff --git a/src/live_effects/effect.cpp b/src/live_effects/effect.cpp index cef2dbfb95..6efe782aa8 100644 --- a/src/live_effects/effect.cpp +++ b/src/live_effects/effect.cpp @@ -88,7 +88,7 @@ #include "ui/pack.h" #include "ui/tools/node-tool.h" #include "ui/tools/pen-tool.h" -#include "xml/sp-css-attr.h" +#include "xml/repr-css.h" #include "helper/geom.h" namespace Inkscape { diff --git a/src/live_effects/lpe-clone-original.cpp b/src/live_effects/lpe-clone-original.cpp index 98b8488859..1bda9b0d6e 100644 --- a/src/live_effects/lpe-clone-original.cpp +++ b/src/live_effects/lpe-clone-original.cpp @@ -34,7 +34,7 @@ #include "ui/pack.h" #include "ui/tools/node-tool.h" #include "util/optstr.h" -#include "xml/sp-css-attr.h" +#include "xml/repr-css.h" namespace Inkscape { namespace LivePathEffect { diff --git a/src/live_effects/lpe-copy_rotate.cpp b/src/live_effects/lpe-copy_rotate.cpp index afae108da1..2ab067cd3d 100644 --- a/src/live_effects/lpe-copy_rotate.cpp +++ b/src/live_effects/lpe-copy_rotate.cpp @@ -37,7 +37,7 @@ #include "svg/path-string.h" #include "svg/svg.h" #include "ui/pack.h" -#include "xml/sp-css-attr.h" +#include "xml/repr-css.h" // TODO due to internal breakage in glibmm headers, this must be last: #include diff --git a/src/live_effects/lpe-measure-segments.cpp b/src/live_effects/lpe-measure-segments.cpp index bc073d299d..0d50a75b5a 100644 --- a/src/live_effects/lpe-measure-segments.cpp +++ b/src/live_effects/lpe-measure-segments.cpp @@ -53,7 +53,7 @@ #include "util/units.h" #include "util-string/ustring-format.h" #include "xml/node.h" -#include "xml/sp-css-attr.h" +#include "xml/repr-css.h" using namespace Geom; diff --git a/src/live_effects/lpe-slice.cpp b/src/live_effects/lpe-slice.cpp index 74afa2af57..3576e68f03 100644 --- a/src/live_effects/lpe-slice.cpp +++ b/src/live_effects/lpe-slice.cpp @@ -41,7 +41,7 @@ #include "ui/icon-names.h" #include "ui/pack.h" #include "util-string/ustring-format.h" -#include "xml/sp-css-attr.h" +#include "xml/repr-css.h" // this is only to flatten nonzero fillrule #include "livarot/Path.h" diff --git a/src/object/sp-item.h b/src/object/sp-item.h index 2eda04ae85..1b6dde850d 100644 --- a/src/object/sp-item.h +++ b/src/object/sp-item.h @@ -33,6 +33,7 @@ #include "sp-marker-loc.h" #include "display/drawing-item-ptr.h" #include "xml/repr.h" +#include "xml/repr-css.h" class SPGroup; class SPClipPath; diff --git a/src/text-editing.cpp b/src/text-editing.cpp index dbaa72a81e..d57d05c1ce 100644 --- a/src/text-editing.cpp +++ b/src/text-editing.cpp @@ -38,7 +38,7 @@ #include "util/units.h" #include "xml/attribute-record.h" -#include "xml/sp-css-attr.h" +#include "xml/repr-css.h" static const gchar *tref_edit_message = _("You cannot edit cloned character data."); static void move_child_nodes(Inkscape::XML::Node *from_repr, Inkscape::XML::Node *to_repr, bool prepend = false); diff --git a/src/ui/clipboard.cpp b/src/ui/clipboard.cpp index 250d182edf..662a1f6ead 100644 --- a/src/ui/clipboard.cpp +++ b/src/ui/clipboard.cpp @@ -92,7 +92,7 @@ #include "util/scope_exit.h" #include "util/value-utils.h" #include "xml/repr.h" -#include "xml/sp-css-attr.h" +#include "xml/repr-css.h" #ifdef _WIN32 #undef NOGDI diff --git a/src/ui/dialog/selectorsdialog.cpp b/src/ui/dialog/selectorsdialog.cpp index 006a03d1a0..1609efe192 100644 --- a/src/ui/dialog/selectorsdialog.cpp +++ b/src/ui/dialog/selectorsdialog.cpp @@ -45,7 +45,7 @@ #include "ui/widget/iconrenderer.h" #include "util/trim.h" #include "xml/attribute-record.h" -#include "xml/sp-css-attr.h" +#include "xml/repr-css.h" // G_MESSAGES_DEBUG=DEBUG_SELECTORSDIALOG gdb ./inkscape // #define DEBUG_SELECTORSDIALOG diff --git a/src/ui/dialog/styledialog.cpp b/src/ui/dialog/styledialog.cpp index db626cb9a1..3c515d98e6 100644 --- a/src/ui/dialog/styledialog.cpp +++ b/src/ui/dialog/styledialog.cpp @@ -66,7 +66,7 @@ #include "util/trim.h" #include "xml/attribute-record.h" #include "xml/node-observer.h" -#include "xml/sp-css-attr.h" +#include "xml/repr-css.h" // G_MESSAGES_DEBUG=DEBUG_STYLEDIALOG gdb ./inkscape // #define DEBUG_STYLEDIALOG diff --git a/src/ui/tools/pencil-tool.cpp b/src/ui/tools/pencil-tool.cpp index 5a52b3cdbf..1bee988f1a 100644 --- a/src/ui/tools/pencil-tool.cpp +++ b/src/ui/tools/pencil-tool.cpp @@ -63,7 +63,7 @@ #include "ui/widget/events/canvas-event.h" #include "xml/node.h" -#include "xml/sp-css-attr.h" +#include "xml/repr-css.h" #define DDC_MIN_PRESSURE 0.0 #define DDC_MAX_PRESSURE 1.0 diff --git a/src/ui/tools/text-tool.cpp b/src/ui/tools/text-tool.cpp index 211757836c..d5f1fecede 100644 --- a/src/ui/tools/text-tool.cpp +++ b/src/ui/tools/text-tool.cpp @@ -63,7 +63,7 @@ #include "ui/widget/events/debug.h" #include "util/callback-converter.h" #include "util/units.h" -#include "xml/sp-css-attr.h" +#include "xml/repr-css.h" using Inkscape::DocumentUndo; diff --git a/src/ui/widget/style-subject.cpp b/src/ui/widget/style-subject.cpp index 5f8c9803d4..f1a7fd0188 100644 --- a/src/ui/widget/style-subject.cpp +++ b/src/ui/widget/style-subject.cpp @@ -13,7 +13,7 @@ #include "layer-manager.h" #include "selection.h" -#include "xml/sp-css-attr.h" +#include "xml/repr-css.h" namespace Inkscape { namespace UI { diff --git a/src/ui/widget/style-swatch.cpp b/src/ui/widget/style-swatch.cpp index bc8c75a7e1..0c1fda5470 100644 --- a/src/ui/widget/style-swatch.cpp +++ b/src/ui/widget/style-swatch.cpp @@ -34,7 +34,7 @@ #include "ui/util.h" #include "ui/widget/color-preview.h" #include "util/units.h" -#include "xml/sp-css-attr.h" +#include "xml/repr-css.h" static constexpr int STYLE_SWATCH_WIDTH = 135; diff --git a/src/util/object-renderer.cpp b/src/util/object-renderer.cpp index bef875d287..6b5a117f98 100644 --- a/src/util/object-renderer.cpp +++ b/src/util/object-renderer.cpp @@ -38,6 +38,8 @@ #include "ui/cache/svg_preview_cache.h" #include "ui/util.h" #include "xml/href-attribute-helper.h" +#include "xml/repr-css.h" + using namespace std::literals; namespace Inkscape { diff --git a/src/xml/CMakeLists.txt b/src/xml/CMakeLists.txt index a9cd74bd82..d20e764cf6 100644 --- a/src/xml/CMakeLists.txt +++ b/src/xml/CMakeLists.txt @@ -44,11 +44,11 @@ set(xml_SRC quote.h rebase-hrefs.h repr-action-test.h + repr-css.h repr-sorting.h repr.h simple-document.h simple-node.h - sp-css-attr.h subtree.h text-node.h href-attribute-helper.h diff --git a/src/xml/repr-css.cpp b/src/xml/repr-css.cpp index 39bd286116..e2ddb4703f 100644 --- a/src/xml/repr-css.cpp +++ b/src/xml/repr-css.cpp @@ -1,18 +1,18 @@ // SPDX-License-Identifier: GPL-2.0-or-later /** @file - * TODO: insert short description here + * CSSAttr - interface for CSS Attributes *//* * Authors: see git history * - * Copyright (C) 2018 Authors + * Copyright (C) 2010-2025 Authors + * * Released under GNU GPL v2+, read the file 'COPYING' for more information. */ /* * bulia byak * Tavmjong Bah (Documentation) * - * Functions to manipulate SPCSSAttr which is a class derived from Inkscape::XML::Node See - * sp-css-attr.h and node.h + * Functions to manipulate SPCSSAttr which is a class derived from Inkscape::XML::Node * * SPCSSAttr is a special node type where the "attributes" are the properties in an element's style * attribute. For example, style="fill:blue;stroke:none" is stored in a List (Inkscape::Util:List) @@ -21,8 +21,6 @@ * changing an item in the List. Utility functions are provided to go back and forth between the * two ways of representing properties (by a string or by a list). * - * Use sp_repr_css_write_string to go from a property list to a style string. - * */ #define SP_REPR_CSS_C @@ -38,8 +36,8 @@ #include "svg/css-ostringstream.h" #include "xml/repr.h" +#include "xml/repr-css.h" #include "xml/simple-document.h" -#include "xml/sp-css-attr.h" using Inkscape::XML::SimpleNode; using Inkscape::XML::Node; diff --git a/src/xml/repr-css.h b/src/xml/repr-css.h new file mode 100644 index 0000000000..2831743e81 --- /dev/null +++ b/src/xml/repr-css.h @@ -0,0 +1,53 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/** @file + * SPCSSAttr - interface for CSS Attributes + *//* + * Authors: see git history + * + * Copyright (C) 2010-2025 Authors + * + * Released under GNU GPL v2+, read the file 'COPYING' for more information. + */ + +#ifndef SEEN_INKSCAPE_XML_SP_SPCSSATTR_H +#define SEEN_INKSCAPE_XML_SP_SPCSSATTR_H + +#include "xml/node.h" + +class SPCSSAttr : virtual public Inkscape::XML::Node { +}; + +SPCSSAttr *sp_repr_css_attr_new(); +void sp_repr_css_attr_unref(SPCSSAttr *css); +SPCSSAttr *sp_repr_css_attr(Inkscape::XML::Node const *repr, char const *attr); +SPCSSAttr *sp_repr_css_attr_inherited(Inkscape::XML::Node const *repr, char const *attr); +SPCSSAttr *sp_repr_css_attr_unset_all(SPCSSAttr *css); + +char const *sp_repr_css_property(SPCSSAttr *css, char const *name, char const *defval); +Glib::ustring sp_repr_css_property(SPCSSAttr *css, Glib::ustring const &name, Glib::ustring const &defval); +void sp_repr_css_set_property(SPCSSAttr *css, char const *name, char const *value); +void sp_repr_css_unset_property(SPCSSAttr *css, char const *name); +bool sp_repr_css_property_is_unset(SPCSSAttr *css, char const *name); +double sp_repr_css_double_property(SPCSSAttr *css, char const *name, double defval); +void sp_repr_css_set_property_double(SPCSSAttr *css, char const *name, double value); +void sp_repr_css_set_property_string(SPCSSAttr *css, char const *name, std::string const &value); + +void sp_repr_css_write_string(SPCSSAttr *css, Glib::ustring &str); +void sp_repr_css_set(Inkscape::XML::Node *repr, SPCSSAttr *css, char const *key); +void sp_repr_css_merge(SPCSSAttr *dst, SPCSSAttr *src); +void sp_repr_css_attr_add_from_string(SPCSSAttr *css, const char *data); +void sp_repr_css_change(Inkscape::XML::Node *repr, SPCSSAttr *css, char const *key); +void sp_repr_css_change_recursive(Inkscape::XML::Node *repr, SPCSSAttr *css, char const *key); +void sp_repr_css_print(SPCSSAttr *css); + +#endif +/* + 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:fileencoding=utf-8:textwidth=99 : diff --git a/src/xml/repr-util.cpp b/src/xml/repr-util.cpp index d36045b3b8..a7297540b2 100644 --- a/src/xml/repr-util.cpp +++ b/src/xml/repr-util.cpp @@ -24,6 +24,7 @@ #include "svg/svg-length.h" #include "xml/repr.h" +#include "xml/repr-css.h" #include "xml/repr-sorting.h" diff --git a/src/xml/repr.h b/src/xml/repr.h index d118349542..3205ee07c8 100644 --- a/src/xml/repr.h +++ b/src/xml/repr.h @@ -31,7 +31,6 @@ #define SP_OLD_CC_NS_URI "http://web.resource.org/cc/" #define SP_DC_NS_URI "http://purl.org/dc/elements/1.1/" -class SPCSSAttr; class SVGLength; namespace Inkscape { @@ -77,31 +76,6 @@ bool sp_repr_save_rebased_file(Inkscape::XML::Document *doc, char const *filenam char const *old_base, char const *new_base_filename); -/* CSS stuff */ - -SPCSSAttr *sp_repr_css_attr_new(); -void sp_repr_css_attr_unref(SPCSSAttr *css); -SPCSSAttr *sp_repr_css_attr(Inkscape::XML::Node const *repr, char const *attr); -SPCSSAttr *sp_repr_css_attr_inherited(Inkscape::XML::Node const *repr, char const *attr); -SPCSSAttr *sp_repr_css_attr_unset_all(SPCSSAttr *css); - -char const *sp_repr_css_property(SPCSSAttr *css, char const *name, char const *defval); -Glib::ustring sp_repr_css_property(SPCSSAttr *css, Glib::ustring const &name, Glib::ustring const &defval); -void sp_repr_css_set_property(SPCSSAttr *css, char const *name, char const *value); -void sp_repr_css_unset_property(SPCSSAttr *css, char const *name); -bool sp_repr_css_property_is_unset(SPCSSAttr *css, char const *name); -double sp_repr_css_double_property(SPCSSAttr *css, char const *name, double defval); -void sp_repr_css_set_property_double(SPCSSAttr *css, char const *name, double value); -void sp_repr_css_set_property_string(SPCSSAttr *css, char const *name, std::string const &value); - -void sp_repr_css_write_string(SPCSSAttr *css, Glib::ustring &str); -void sp_repr_css_set(Inkscape::XML::Node *repr, SPCSSAttr *css, char const *key); -void sp_repr_css_merge(SPCSSAttr *dst, SPCSSAttr *src); -void sp_repr_css_attr_add_from_string(SPCSSAttr *css, const char *data); -void sp_repr_css_change(Inkscape::XML::Node *repr, SPCSSAttr *css, char const *key); -void sp_repr_css_change_recursive(Inkscape::XML::Node *repr, SPCSSAttr *css, char const *key); -void sp_repr_css_print(SPCSSAttr *css); - /* Utility finctions */ /// Remove \a repr from children of its parent node. inline void sp_repr_unparent(Inkscape::XML::Node *repr) { diff --git a/testfiles/CMakeLists.txt b/testfiles/CMakeLists.txt index b7e0199058..61e43bfab6 100644 --- a/testfiles/CMakeLists.txt +++ b/testfiles/CMakeLists.txt @@ -127,6 +127,7 @@ set(TEST_SOURCES svg-extension-test curve-test 2geom-characterization-test + xml-css-test xml-test sp-item-group-test store-test diff --git a/src/xml/sp-css-attr.h b/testfiles/src/xml-css-test.cpp similarity index 55% rename from src/xml/sp-css-attr.h rename to testfiles/src/xml-css-test.cpp index 07db9caa86..b0fb0d674f 100644 --- a/src/xml/sp-css-attr.h +++ b/testfiles/src/xml-css-test.cpp @@ -1,24 +1,27 @@ // SPDX-License-Identifier: GPL-2.0-or-later -/** @file - * SPCSSAttr - interface for CSS Attributes - *//* - * Authors: see git history +/** + * @file + * Test SPCSSAttr node + */ +/* + * Authors: + * Martin Owens + * + * Copyright (C) 2025 Authors * - * Copyright (C) 2010 Authors - * Copyright 2005 Kees Cook - * * Released under GNU GPL v2+, read the file 'COPYING' for more information. */ -#ifndef SEEN_INKSCAPE_XML_SP_SPCSSATTR_H -#define SEEN_INKSCAPE_XML_SP_SPCSSATTR_H - -#include "xml/node.h" +#include +#include +#include +#include +#include "xml/repr-css.h" -class SPCSSAttr : virtual public Inkscape::XML::Node { -}; +TEST(XmlCssTest, parse) +{ +} -#endif /* Local Variables: mode:c++ -- GitLab From c506c6ac692d310a14e9298db22ebea5ce1436f7 Mon Sep 17 00:00:00 2001 From: Martin Owens Date: Thu, 5 Jun 2025 11:17:07 -0400 Subject: [PATCH 2/2] Radioactive: Plan to replace SPCSSAttr MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit See code changes for details on what this project entails. The end goal is the complete removal of SPCSSAttr and replacement with a more capable SPStyle. This will involve writing so many tests, you'll get bored scrolling through them in the code review. ☺ --- src/actions/actions-svg-processing.cpp | 1 - src/attribute-rel-util.h | 2 +- src/attribute-sort-util.cpp | 2 +- src/desktop-style.cpp | 2 +- .../internal/pdfinput/svg-builder.cpp | 2 +- src/file.cpp | 2 +- src/gradient-drag.cpp | 2 +- src/live_effects/effect.cpp | 2 +- src/live_effects/lpe-clone-original.cpp | 2 +- src/live_effects/lpe-copy_rotate.cpp | 2 +- src/live_effects/lpe-measure-segments.cpp | 2 +- src/live_effects/lpe-slice.cpp | 2 +- src/object/sp-item.h | 1 - src/style.h | 29 +- src/text-editing.cpp | 2 +- src/ui/clipboard.cpp | 2 +- src/ui/dialog/selectorsdialog.cpp | 2 +- src/ui/dialog/styledialog.cpp | 2 +- src/ui/tools/pencil-tool.cpp | 2 +- src/ui/tools/text-tool.cpp | 2 +- src/ui/widget/style-subject.cpp | 2 +- src/ui/widget/style-swatch.cpp | 2 +- src/util/object-renderer.cpp | 2 - src/xml/CMakeLists.txt | 2 - src/xml/repr-css.cpp | 403 ------------------ src/xml/repr-css.h | 53 --- src/xml/repr-util.cpp | 1 - testfiles/CMakeLists.txt | 1 - testfiles/src/xml-css-test.cpp | 34 -- 29 files changed, 47 insertions(+), 518 deletions(-) delete mode 100644 src/xml/repr-css.cpp delete mode 100644 src/xml/repr-css.h delete mode 100644 testfiles/src/xml-css-test.cpp diff --git a/src/actions/actions-svg-processing.cpp b/src/actions/actions-svg-processing.cpp index 52ce659de7..f22cf79ad4 100644 --- a/src/actions/actions-svg-processing.cpp +++ b/src/actions/actions-svg-processing.cpp @@ -33,7 +33,6 @@ #include "svg/svg.h" #include "xml/attribute-record.h" #include "xml/node.h" -#include "xml/repr-css.h" /* * Removes all sodipodi and inkscape elements and attributes from an xml tree. diff --git a/src/attribute-rel-util.h b/src/attribute-rel-util.h index b1542d8226..490c9bc5da 100644 --- a/src/attribute-rel-util.h +++ b/src/attribute-rel-util.h @@ -14,7 +14,7 @@ #include -#include "xml/repr-css.h" +#include "xml/sp-css-attr.h" using Inkscape::XML::Node; diff --git a/src/attribute-sort-util.cpp b/src/attribute-sort-util.cpp index 28271f3b87..56072b3a4e 100644 --- a/src/attribute-sort-util.cpp +++ b/src/attribute-sort-util.cpp @@ -31,7 +31,7 @@ #include "xml/repr.h" #include "xml/attribute-record.h" -#include "xml/repr-css.h" +#include "xml/sp-css-attr.h" #include "attributes.h" diff --git a/src/desktop-style.cpp b/src/desktop-style.cpp index d94525e597..ce09066081 100644 --- a/src/desktop-style.cpp +++ b/src/desktop-style.cpp @@ -53,7 +53,7 @@ #include "ui/tools/tool-base.h" #include -#include "xml/repr-css.h" +#include "xml/sp-css-attr.h" #include "xml/attribute-record.h" static bool isTextualItem(SPObject const *obj) diff --git a/src/extension/internal/pdfinput/svg-builder.cpp b/src/extension/internal/pdfinput/svg-builder.cpp index db248f3d1e..979a5048cf 100644 --- a/src/extension/internal/pdfinput/svg-builder.cpp +++ b/src/extension/internal/pdfinput/svg-builder.cpp @@ -51,7 +51,7 @@ #include "xml/document.h" #include "xml/node.h" #include "xml/repr.h" -#include "xml/repr-css.h" +#include "xml/sp-css-attr.h" #include "helper/geom.h" namespace Inkscape { diff --git a/src/file.cpp b/src/file.cpp index a5d6a4eb8c..60d148ad89 100644 --- a/src/file.cpp +++ b/src/file.cpp @@ -72,7 +72,7 @@ #include "ui/tools/tool-base.h" #include "util/recently-used-fonts.h" #include "xml/rebase-hrefs.h" -#include "xml/repr-css.h" +#include "xml/sp-css-attr.h" using Inkscape::DocumentUndo; using Inkscape::IO::Resource::TEMPLATES; diff --git a/src/gradient-drag.cpp b/src/gradient-drag.cpp index ca6d638b6b..9000030a1b 100644 --- a/src/gradient-drag.cpp +++ b/src/gradient-drag.cpp @@ -51,7 +51,7 @@ #include "ui/tools/tool-base.h" #include "ui/widget/events/canvas-event.h" -#include "xml/repr-css.h" +#include "xml/sp-css-attr.h" using Inkscape::DocumentUndo; using Inkscape::allPaintTargets; diff --git a/src/live_effects/effect.cpp b/src/live_effects/effect.cpp index 6efe782aa8..cef2dbfb95 100644 --- a/src/live_effects/effect.cpp +++ b/src/live_effects/effect.cpp @@ -88,7 +88,7 @@ #include "ui/pack.h" #include "ui/tools/node-tool.h" #include "ui/tools/pen-tool.h" -#include "xml/repr-css.h" +#include "xml/sp-css-attr.h" #include "helper/geom.h" namespace Inkscape { diff --git a/src/live_effects/lpe-clone-original.cpp b/src/live_effects/lpe-clone-original.cpp index 1bda9b0d6e..98b8488859 100644 --- a/src/live_effects/lpe-clone-original.cpp +++ b/src/live_effects/lpe-clone-original.cpp @@ -34,7 +34,7 @@ #include "ui/pack.h" #include "ui/tools/node-tool.h" #include "util/optstr.h" -#include "xml/repr-css.h" +#include "xml/sp-css-attr.h" namespace Inkscape { namespace LivePathEffect { diff --git a/src/live_effects/lpe-copy_rotate.cpp b/src/live_effects/lpe-copy_rotate.cpp index 2ab067cd3d..afae108da1 100644 --- a/src/live_effects/lpe-copy_rotate.cpp +++ b/src/live_effects/lpe-copy_rotate.cpp @@ -37,7 +37,7 @@ #include "svg/path-string.h" #include "svg/svg.h" #include "ui/pack.h" -#include "xml/repr-css.h" +#include "xml/sp-css-attr.h" // TODO due to internal breakage in glibmm headers, this must be last: #include diff --git a/src/live_effects/lpe-measure-segments.cpp b/src/live_effects/lpe-measure-segments.cpp index 0d50a75b5a..bc073d299d 100644 --- a/src/live_effects/lpe-measure-segments.cpp +++ b/src/live_effects/lpe-measure-segments.cpp @@ -53,7 +53,7 @@ #include "util/units.h" #include "util-string/ustring-format.h" #include "xml/node.h" -#include "xml/repr-css.h" +#include "xml/sp-css-attr.h" using namespace Geom; diff --git a/src/live_effects/lpe-slice.cpp b/src/live_effects/lpe-slice.cpp index 3576e68f03..74afa2af57 100644 --- a/src/live_effects/lpe-slice.cpp +++ b/src/live_effects/lpe-slice.cpp @@ -41,7 +41,7 @@ #include "ui/icon-names.h" #include "ui/pack.h" #include "util-string/ustring-format.h" -#include "xml/repr-css.h" +#include "xml/sp-css-attr.h" // this is only to flatten nonzero fillrule #include "livarot/Path.h" diff --git a/src/object/sp-item.h b/src/object/sp-item.h index 1b6dde850d..2eda04ae85 100644 --- a/src/object/sp-item.h +++ b/src/object/sp-item.h @@ -33,7 +33,6 @@ #include "sp-marker-loc.h" #include "display/drawing-item-ptr.h" #include "xml/repr.h" -#include "xml/repr-css.h" class SPGroup; class SPClipPath; diff --git a/src/style.h b/src/style.h index edb8c9667c..20dfaab5b0 100644 --- a/src/style.h +++ b/src/style.h @@ -45,6 +45,31 @@ class SPStyle { public: SPStyle(SPDocument *document = nullptr, SPObject *object = nullptr); // document is ignored if valid object given + + // Create detached SPStyle from css string + SPStyle(Glib::ustring const &css); + + // Make a detached copy of the SPStyle, for temporary mutations + SPStyle copy() const; + + // Replacement for sp_repr_css_attr_add_from_string + void addItemFromString(Glib::ustring const &css); + + // Manage the concept of an "attached" style vs. a parsed CSS + void attach(SPDocument *document); + void attach(SPObject *object); + bool isAttached() const { return _document || _object; } + + // Remove the style from it's current SPObject, cascade and SPDocument context + // When unset uris is true, it acts like sp_css_attr_unset_uris + void detach(bool unset_uris=false); + + // A detached style can remember ids as strings, but can't resolve them + // to Paint objects. So we add some errors to this effect. + // Later we might want to invent the concept of a detached gradient, pattern + // etc which can be encoded in memory without a document (or id) and so when + // the style is 'attached' it can be added to the document at that point. + ~SPStyle(); std::vector const &properties() const { return _properties; } void clear(); @@ -66,7 +91,7 @@ public: void cascade(SPStyle const *parent); void merge( SPStyle const *parent); void mergeString(char const *p); - void mergeCSS(SPCSSAttr *css); + // DROP void mergeCSS(SPCSSAttr *css); void mergeStatement(CRStatement *statement); bool operator==(SPStyle const &rhs) const; @@ -368,12 +393,14 @@ double sp_style_css_size_px_to_units(double size, int unit, double font_size = S double sp_style_css_size_units_to_px(double size, int unit, double font_size = SP_CSS_FONT_SIZE_DEFAULT); // No change? +/* SPCSSAttr *sp_css_attr_from_style (SPStyle const *const style, unsigned int flags); SPCSSAttr *sp_css_attr_from_object(SPObject *object, unsigned int flags = SP_STYLE_FLAG_IFSET); SPCSSAttr *sp_css_attr_unset_text(SPCSSAttr *css); SPCSSAttr *sp_css_attr_unset_blacklist(SPCSSAttr *css); SPCSSAttr *sp_css_attr_unset_uris(SPCSSAttr *css); SPCSSAttr *sp_css_attr_scale(SPCSSAttr *css, double ex); +*/ void sp_style_unset_property_attrs(SPObject *o); diff --git a/src/text-editing.cpp b/src/text-editing.cpp index d57d05c1ce..dbaa72a81e 100644 --- a/src/text-editing.cpp +++ b/src/text-editing.cpp @@ -38,7 +38,7 @@ #include "util/units.h" #include "xml/attribute-record.h" -#include "xml/repr-css.h" +#include "xml/sp-css-attr.h" static const gchar *tref_edit_message = _("You cannot edit cloned character data."); static void move_child_nodes(Inkscape::XML::Node *from_repr, Inkscape::XML::Node *to_repr, bool prepend = false); diff --git a/src/ui/clipboard.cpp b/src/ui/clipboard.cpp index 662a1f6ead..250d182edf 100644 --- a/src/ui/clipboard.cpp +++ b/src/ui/clipboard.cpp @@ -92,7 +92,7 @@ #include "util/scope_exit.h" #include "util/value-utils.h" #include "xml/repr.h" -#include "xml/repr-css.h" +#include "xml/sp-css-attr.h" #ifdef _WIN32 #undef NOGDI diff --git a/src/ui/dialog/selectorsdialog.cpp b/src/ui/dialog/selectorsdialog.cpp index 1609efe192..006a03d1a0 100644 --- a/src/ui/dialog/selectorsdialog.cpp +++ b/src/ui/dialog/selectorsdialog.cpp @@ -45,7 +45,7 @@ #include "ui/widget/iconrenderer.h" #include "util/trim.h" #include "xml/attribute-record.h" -#include "xml/repr-css.h" +#include "xml/sp-css-attr.h" // G_MESSAGES_DEBUG=DEBUG_SELECTORSDIALOG gdb ./inkscape // #define DEBUG_SELECTORSDIALOG diff --git a/src/ui/dialog/styledialog.cpp b/src/ui/dialog/styledialog.cpp index 3c515d98e6..db626cb9a1 100644 --- a/src/ui/dialog/styledialog.cpp +++ b/src/ui/dialog/styledialog.cpp @@ -66,7 +66,7 @@ #include "util/trim.h" #include "xml/attribute-record.h" #include "xml/node-observer.h" -#include "xml/repr-css.h" +#include "xml/sp-css-attr.h" // G_MESSAGES_DEBUG=DEBUG_STYLEDIALOG gdb ./inkscape // #define DEBUG_STYLEDIALOG diff --git a/src/ui/tools/pencil-tool.cpp b/src/ui/tools/pencil-tool.cpp index 1bee988f1a..5a52b3cdbf 100644 --- a/src/ui/tools/pencil-tool.cpp +++ b/src/ui/tools/pencil-tool.cpp @@ -63,7 +63,7 @@ #include "ui/widget/events/canvas-event.h" #include "xml/node.h" -#include "xml/repr-css.h" +#include "xml/sp-css-attr.h" #define DDC_MIN_PRESSURE 0.0 #define DDC_MAX_PRESSURE 1.0 diff --git a/src/ui/tools/text-tool.cpp b/src/ui/tools/text-tool.cpp index d5f1fecede..211757836c 100644 --- a/src/ui/tools/text-tool.cpp +++ b/src/ui/tools/text-tool.cpp @@ -63,7 +63,7 @@ #include "ui/widget/events/debug.h" #include "util/callback-converter.h" #include "util/units.h" -#include "xml/repr-css.h" +#include "xml/sp-css-attr.h" using Inkscape::DocumentUndo; diff --git a/src/ui/widget/style-subject.cpp b/src/ui/widget/style-subject.cpp index f1a7fd0188..5f8c9803d4 100644 --- a/src/ui/widget/style-subject.cpp +++ b/src/ui/widget/style-subject.cpp @@ -13,7 +13,7 @@ #include "layer-manager.h" #include "selection.h" -#include "xml/repr-css.h" +#include "xml/sp-css-attr.h" namespace Inkscape { namespace UI { diff --git a/src/ui/widget/style-swatch.cpp b/src/ui/widget/style-swatch.cpp index 0c1fda5470..bc8c75a7e1 100644 --- a/src/ui/widget/style-swatch.cpp +++ b/src/ui/widget/style-swatch.cpp @@ -34,7 +34,7 @@ #include "ui/util.h" #include "ui/widget/color-preview.h" #include "util/units.h" -#include "xml/repr-css.h" +#include "xml/sp-css-attr.h" static constexpr int STYLE_SWATCH_WIDTH = 135; diff --git a/src/util/object-renderer.cpp b/src/util/object-renderer.cpp index 6b5a117f98..bef875d287 100644 --- a/src/util/object-renderer.cpp +++ b/src/util/object-renderer.cpp @@ -38,8 +38,6 @@ #include "ui/cache/svg_preview_cache.h" #include "ui/util.h" #include "xml/href-attribute-helper.h" -#include "xml/repr-css.h" - using namespace std::literals; namespace Inkscape { diff --git a/src/xml/CMakeLists.txt b/src/xml/CMakeLists.txt index d20e764cf6..09c67ebf96 100644 --- a/src/xml/CMakeLists.txt +++ b/src/xml/CMakeLists.txt @@ -10,7 +10,6 @@ set(xml_SRC node-iterators.cpp quote.cpp repr.cpp - repr-css.cpp repr-io.cpp repr-sorting.cpp repr-util.cpp @@ -44,7 +43,6 @@ set(xml_SRC quote.h rebase-hrefs.h repr-action-test.h - repr-css.h repr-sorting.h repr.h simple-document.h diff --git a/src/xml/repr-css.cpp b/src/xml/repr-css.cpp deleted file mode 100644 index e2ddb4703f..0000000000 --- a/src/xml/repr-css.cpp +++ /dev/null @@ -1,403 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-or-later -/** @file - * CSSAttr - interface for CSS Attributes - *//* - * Authors: see git history - * - * Copyright (C) 2010-2025 Authors - * - * Released under GNU GPL v2+, read the file 'COPYING' for more information. - */ -/* - * bulia byak - * Tavmjong Bah (Documentation) - * - * Functions to manipulate SPCSSAttr which is a class derived from Inkscape::XML::Node - * - * SPCSSAttr is a special node type where the "attributes" are the properties in an element's style - * attribute. For example, style="fill:blue;stroke:none" is stored in a List (Inkscape::Util:List) - * where the key is the property (e.g. "fill" or "stroke") and the value is the property's value - * (e.g. "blue" or "none"). An element's properties are manipulated by adding, removing, or - * changing an item in the List. Utility functions are provided to go back and forth between the - * two ways of representing properties (by a string or by a list). - * - */ - -#define SP_REPR_CSS_C - -#include -#include -#include - -#include - -#include "3rdparty/libcroco/src/cr-declaration.h" - -#include "svg/css-ostringstream.h" - -#include "xml/repr.h" -#include "xml/repr-css.h" -#include "xml/simple-document.h" - -using Inkscape::XML::SimpleNode; -using Inkscape::XML::Node; -using Inkscape::XML::NodeType; -using Inkscape::XML::Document; - -struct SPCSSAttrImpl : public SimpleNode, public SPCSSAttr { -public: - SPCSSAttrImpl(Document *doc) - : SimpleNode(g_quark_from_static_string("css"), doc) {} - SPCSSAttrImpl(SPCSSAttrImpl const &other, Document *doc) - : SimpleNode(other, doc) {} - - NodeType type() const override { return Inkscape::XML::NodeType::ELEMENT_NODE; } - -protected: - SimpleNode *duplicate(Document *doc) const override { return new SPCSSAttrImpl(*this, doc); } -}; - -static void sp_repr_css_add_components(SPCSSAttr *css, Node const *repr, gchar const *attr); - -/** - * Creates an empty SPCSSAttr (a class for manipulating CSS style properties). - */ -SPCSSAttr *sp_repr_css_attr_new() -{ - static auto const attr_doc = new Inkscape::XML::SimpleDocument(); - return new SPCSSAttrImpl(attr_doc); -} - -/** - * Unreferences an SPCSSAttr (will be garbage collected if no references remain). - */ -void sp_repr_css_attr_unref(SPCSSAttr *css) -{ - g_assert(css != nullptr); - Inkscape::GC::release((Node *) css); -} - -/** - * Creates a new SPCSSAttr with one attribute (i.e. style) copied from an existing repr (node). The - * repr attribute data is in the form of a char const * string (e.g. fill:#00ff00;stroke:none). The - * string is parsed by libcroco which returns a CRDeclaration list (a typical C linked list) of - * properties and values. This list is then used to fill the attributes of the new SPCSSAttr. - */ -SPCSSAttr *sp_repr_css_attr(Node const *repr, gchar const *attr) -{ - g_assert(repr != nullptr); - g_assert(attr != nullptr); - - SPCSSAttr *css = sp_repr_css_attr_new(); - sp_repr_css_add_components(css, repr, attr); - return css; -} - - -/** - * Adds an attribute to an existing SPCSAttr with the cascaded value including all parents. - */ -static void sp_repr_css_attr_inherited_recursive(SPCSSAttr *css, Node const *repr, gchar const *attr) -{ - const Node *parent = repr->parent(); - - // read the ancestors from root down, using head recursion, so that children override parents - if (parent) { - sp_repr_css_attr_inherited_recursive(css, parent, attr); - } - sp_repr_css_add_components(css, repr, attr); -} - -/** - * Creates a new SPCSSAttr with one attribute whose value is determined by cascading. - */ -SPCSSAttr *sp_repr_css_attr_inherited(Node const *repr, gchar const *attr) -{ - g_assert(repr != nullptr); - g_assert(attr != nullptr); - - SPCSSAttr *css = sp_repr_css_attr_new(); - - sp_repr_css_attr_inherited_recursive(css, repr, attr); - - return css; -} - -/** - * Adds components (style properties) to an existing SPCSAttr from the specified attribute's data - * (nominally a style attribute). - * - */ -static void sp_repr_css_add_components(SPCSSAttr *css, Node const *repr, gchar const *attr) -{ - g_assert(css != nullptr); - g_assert(repr != nullptr); - g_assert(attr != nullptr); - - char const *data = repr->attribute(attr); - sp_repr_css_attr_add_from_string(css, data); -} - -/** - * Returns a character string of the value of a given style property or a default value if the - * attribute is not found. - */ -char const *sp_repr_css_property(SPCSSAttr *css, gchar const *name, gchar const *defval) -{ - g_assert(css != nullptr); - g_assert(name != nullptr); - - char const *attr = ((Node *)css)->attribute(name); - return ( attr == nullptr - ? defval - : attr ); -} - -/** - * Returns a character string of the value of a given style property or a default value if the - * attribute is not found. - */ -Glib::ustring sp_repr_css_property(SPCSSAttr *css, Glib::ustring const &name, Glib::ustring const &defval) -{ - g_assert(css != nullptr); - - Glib::ustring retval = defval; - char const *attr = ((Node *)css)->attribute(name.c_str()); - if (attr) { - retval = attr; - } - - return retval; -} - -/** - * Returns true if a style property is present and its value is unset. - */ -bool sp_repr_css_property_is_unset(SPCSSAttr *css, gchar const *name) -{ - g_assert(css != nullptr); - g_assert(name != nullptr); - - char const *attr = ((Node *)css)->attribute(name); - return (attr && !strcmp(attr, "inkscape:unset")); -} - - -/** - * Set a style property to a new value (e.g. fill to #ffff00). - */ -void sp_repr_css_set_property(SPCSSAttr *css, gchar const *name, gchar const *value) -{ - g_assert(css != nullptr); - g_assert(name != nullptr); - - ((Node *) css)->setAttribute(name, value); -} - -/** - * Set a style property to "inkscape:unset". - */ -void sp_repr_css_unset_property(SPCSSAttr *css, gchar const *name) -{ - g_assert(css != nullptr); - g_assert(name != nullptr); - - ((Node *) css)->setAttribute(name, "inkscape:unset"); -} - -/** - * Return the value of a style property if property define, or a default value if not. - */ -double sp_repr_css_double_property(SPCSSAttr *css, gchar const *name, double defval) -{ - g_assert(css != nullptr); - g_assert(name != nullptr); - - return css->getAttributeDouble(name, defval); -} - -/** - * Set a style property to a new float value (e.g. opacity to 0.5). - */ -void sp_repr_css_set_property_double(SPCSSAttr *css, gchar const *name, double value) -{ - g_assert(css != nullptr); - g_assert(name != nullptr); - - ((Node *) css)->setAttributeCssDouble(name, value); -} - -/** - * Set a style property to a standard string. - */ -void sp_repr_css_set_property_string(SPCSSAttr *css, char const *name, std::string const &value) -{ - sp_repr_css_set_property(css, name, value.c_str()); -} - -/** - * Write a style attribute string from a list of properties stored in an SPCSAttr object. - */ -void sp_repr_css_write_string(SPCSSAttr *css, Glib::ustring &str) -{ - str.clear(); - for (const auto & iter : css->attributeList()) - { - if (iter.value && !strcmp(iter.value, "inkscape:unset")) { - continue; - } - - if (!str.empty()) { - str.push_back(';'); - } - - str.append(g_quark_to_string(iter.key)); - str.push_back(':'); - str.append(iter.value); // Any necessary quoting to be done by calling routine. - } -} - -/** - * Sets an attribute (e.g. style) to a string created from a list of style properties. - */ -void sp_repr_css_set(Node *repr, SPCSSAttr *css, gchar const *attr) -{ - g_assert(repr != nullptr); - g_assert(css != nullptr); - g_assert(attr != nullptr); - - Glib::ustring value; - sp_repr_css_write_string(css, value); - - /* - * If the new value is different from the old value, this will sometimes send a signal via - * CompositeNodeObserver::notiftyAttributeChanged() which results in calling - * SPObject::repr_attr_changed and thus updates the object's SPStyle. This update - * results in another call to repr->setAttribute(). - */ - repr->setAttributeOrRemoveIfEmpty(attr, value); -} - -/** - * Loops through a List of style properties, printing key/value pairs. - */ -void sp_repr_css_print(SPCSSAttr *css) -{ - for ( const auto & attr: css->attributeList() ) - { - gchar const * key = g_quark_to_string(attr.key); - gchar const * val = attr.value; - g_print("%s:\t%s\n",key,val); - } -} - -/** - * Merges two SPCSSAttr's. Properties in src overwrite properties in dst if present in both. - */ -void sp_repr_css_merge(SPCSSAttr *dst, SPCSSAttr *src) -{ - g_assert(dst != nullptr); - g_assert(src != nullptr); - - dst->mergeFrom(src, ""); -} - -/** - * Merges style properties as parsed by libcroco into an existing SPCSSAttr. - * libcroco converts all single quotes to double quotes, which needs to be - * undone as we always use single quotes inside our 'style' strings since - * double quotes are used outside: e.g.: - * style="font-family:'DejaVu Sans'" - */ -static void sp_repr_css_merge_from_decl(SPCSSAttr *css, CRDeclaration const *const decl) -{ - guchar *const str_value_unsigned = cr_term_to_string(decl->value); - css->setAttribute(decl->property->stryng->str, reinterpret_cast(str_value_unsigned)); - g_free(str_value_unsigned); -} - -/** - * Merges style properties as parsed by libcroco into an existing SPCSSAttr. - * - * \pre decl_list != NULL - */ -static void sp_repr_css_merge_from_decl_list(SPCSSAttr *css, CRDeclaration const *const decl_list) -{ - // read the decls from start to end, using tail recursion, so that latter declarations override - // (Ref: http://www.w3.org/TR/REC-CSS2/cascade.html#cascading-order point 4.) - // because sp_repr_css_merge_from_decl sets properties unconditionally - sp_repr_css_merge_from_decl(css, decl_list); - if (decl_list->next) { - sp_repr_css_merge_from_decl_list(css, decl_list->next); - } -} - -/** - * Use libcroco to parse a string for CSS properties and then merge - * them into an existing SPCSSAttr. - */ -void sp_repr_css_attr_add_from_string(SPCSSAttr *css, gchar const *p) -{ - if (p != nullptr) { - CRDeclaration *const decl_list - = cr_declaration_parse_list_from_buf(reinterpret_cast(p), CR_UTF_8); - if (decl_list) { - sp_repr_css_merge_from_decl_list(css, decl_list); - cr_declaration_destroy(decl_list); - } - } -} - -/** - * Creates a new SPCSAttr with the values filled from a repr, merges in properties from the given - * SPCSAttr, and then replaces that SPCSAttr with the new one. This is called, for example, for - * each object in turn when a selection's style is updated via sp_desktop_set_style(). - */ -void sp_repr_css_change(Node *repr, SPCSSAttr *css, gchar const *attr) -{ - g_assert(repr != nullptr); - g_assert(css != nullptr); - g_assert(attr != nullptr); - - SPCSSAttr *current = sp_repr_css_attr(repr, attr); - sp_repr_css_merge(current, css); - sp_repr_css_set(repr, current, attr); - - sp_repr_css_attr_unref(current); -} - -void sp_repr_css_change_recursive(Node *repr, SPCSSAttr *css, gchar const *attr) -{ - g_assert(repr != nullptr); - g_assert(css != nullptr); - g_assert(attr != nullptr); - - sp_repr_css_change(repr, css, attr); - - for (Node *child = repr->firstChild(); child != nullptr; child = child->next()) { - sp_repr_css_change_recursive(child, css, attr); - } -} - -/** - * Return a new SPCSSAttr with all the properties found in the input SPCSSAttr unset. - */ -SPCSSAttr* sp_repr_css_attr_unset_all(SPCSSAttr *css) -{ - SPCSSAttr* css_unset = sp_repr_css_attr_new(); - for ( const auto & iter : css->attributeList() ) { - sp_repr_css_set_property (css_unset, g_quark_to_string(iter.key), "inkscape:unset"); - } - return css_unset; -} - -/* - 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:fileencoding=utf-8:textwidth=99 : diff --git a/src/xml/repr-css.h b/src/xml/repr-css.h deleted file mode 100644 index 2831743e81..0000000000 --- a/src/xml/repr-css.h +++ /dev/null @@ -1,53 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-or-later -/** @file - * SPCSSAttr - interface for CSS Attributes - *//* - * Authors: see git history - * - * Copyright (C) 2010-2025 Authors - * - * Released under GNU GPL v2+, read the file 'COPYING' for more information. - */ - -#ifndef SEEN_INKSCAPE_XML_SP_SPCSSATTR_H -#define SEEN_INKSCAPE_XML_SP_SPCSSATTR_H - -#include "xml/node.h" - -class SPCSSAttr : virtual public Inkscape::XML::Node { -}; - -SPCSSAttr *sp_repr_css_attr_new(); -void sp_repr_css_attr_unref(SPCSSAttr *css); -SPCSSAttr *sp_repr_css_attr(Inkscape::XML::Node const *repr, char const *attr); -SPCSSAttr *sp_repr_css_attr_inherited(Inkscape::XML::Node const *repr, char const *attr); -SPCSSAttr *sp_repr_css_attr_unset_all(SPCSSAttr *css); - -char const *sp_repr_css_property(SPCSSAttr *css, char const *name, char const *defval); -Glib::ustring sp_repr_css_property(SPCSSAttr *css, Glib::ustring const &name, Glib::ustring const &defval); -void sp_repr_css_set_property(SPCSSAttr *css, char const *name, char const *value); -void sp_repr_css_unset_property(SPCSSAttr *css, char const *name); -bool sp_repr_css_property_is_unset(SPCSSAttr *css, char const *name); -double sp_repr_css_double_property(SPCSSAttr *css, char const *name, double defval); -void sp_repr_css_set_property_double(SPCSSAttr *css, char const *name, double value); -void sp_repr_css_set_property_string(SPCSSAttr *css, char const *name, std::string const &value); - -void sp_repr_css_write_string(SPCSSAttr *css, Glib::ustring &str); -void sp_repr_css_set(Inkscape::XML::Node *repr, SPCSSAttr *css, char const *key); -void sp_repr_css_merge(SPCSSAttr *dst, SPCSSAttr *src); -void sp_repr_css_attr_add_from_string(SPCSSAttr *css, const char *data); -void sp_repr_css_change(Inkscape::XML::Node *repr, SPCSSAttr *css, char const *key); -void sp_repr_css_change_recursive(Inkscape::XML::Node *repr, SPCSSAttr *css, char const *key); -void sp_repr_css_print(SPCSSAttr *css); - -#endif -/* - 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:fileencoding=utf-8:textwidth=99 : diff --git a/src/xml/repr-util.cpp b/src/xml/repr-util.cpp index a7297540b2..d36045b3b8 100644 --- a/src/xml/repr-util.cpp +++ b/src/xml/repr-util.cpp @@ -24,7 +24,6 @@ #include "svg/svg-length.h" #include "xml/repr.h" -#include "xml/repr-css.h" #include "xml/repr-sorting.h" diff --git a/testfiles/CMakeLists.txt b/testfiles/CMakeLists.txt index 61e43bfab6..b7e0199058 100644 --- a/testfiles/CMakeLists.txt +++ b/testfiles/CMakeLists.txt @@ -127,7 +127,6 @@ set(TEST_SOURCES svg-extension-test curve-test 2geom-characterization-test - xml-css-test xml-test sp-item-group-test store-test diff --git a/testfiles/src/xml-css-test.cpp b/testfiles/src/xml-css-test.cpp deleted file mode 100644 index b0fb0d674f..0000000000 --- a/testfiles/src/xml-css-test.cpp +++ /dev/null @@ -1,34 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-or-later -/** - * @file - * Test SPCSSAttr node - */ -/* - * Authors: - * Martin Owens - * - * Copyright (C) 2025 Authors - * - * Released under GNU GPL v2+, read the file 'COPYING' for more information. - */ - -#include -#include -#include -#include -#include "xml/repr-css.h" - -TEST(XmlCssTest, parse) -{ -} - -/* - 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:fileencoding=utf-8:textwidth=99 : -- GitLab