Inkscape
Vector Graphics Editor
Loading...
Searching...
No Matches
remember-styles.cpp
Go to the documentation of this file.
1// SPDX-License-Identifier: GPL-2.0-or-later
2/*
3 * Create a memory of styles we can use to compare.
4 *
5 * Authors:
6 * Martin Owens <doctormo@geek-2.com>
7 *
8 * Copyright (C) 2025 Authors
9 *
10 * Released under GNU GPL v2+, read the file 'COPYING' for more information.
11 */
12
13#include "remember-styles.h"
14
16
18{
20 auto const &current = get_state();
21
22 for (auto prop : style->properties()) {
23 auto attr = prop->id();
24 // get_value ALWAYS gives a value, even if it's from a cascade. This is intentional
25 // as we want to know if the effective value has changed, not if the style would write a value out.
26 auto value = prop->get_value().raw();
27
28 if (_attrs.contains(attr)) {
29 auto const it = current.find(attr);
30 if (it == current.end() || it->second != value) {
31 map[attr] = std::move(value);
32 }
33 }
34 }
35 return map;
36}
37
39{
41 for (auto prop : style->properties()) {
42 if (prop->set) {
43 map[prop->id()] = prop->get_value();
44 }
45 }
46 return map;
47}
48
49} // namespace Inkscape::Extension::Internal
StyleMap get_changes(SPStyle const *style) const
Return a StyleMap of all the differences between the state and the given style.
StyleMap get_ifset(SPStyle const *style) const
Return a StyleMap of all the set styles, filtered in the same way as get_changes.
StyleMap const & get_state() const
Get the current state map, empty if nothing is on the stack or contains every attr at the current sta...
An SVG style object.
Definition style.h:45
std::vector< SPIBase * > const & properties() const
Definition style.h:49
std::unordered_map< std::string, std::unique_ptr< SPDocument > > map
static char const *const current
Definition dir-util.cpp:71
std::map< SPAttr, std::string > StyleMap