Inkscape
Vector Graphics Editor
Loading...
Searching...
No Matches
remember-styles.h
Go to the documentation of this file.
1// SPDX-License-Identifier: GPL-2.0-or-later
2/*
3 * Remember what the current style context is and test for changes.
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#ifndef EXTENSION_INTERNAL_PDFOUTPUT_REMEMBERSTYLES_H
14#define EXTENSION_INTERNAL_PDFOUTPUT_REMEMBERSTYLES_H
15
16#include <set>
17#include <stack>
18#include <string>
19
20#include "attributes.h"
21#include "style.h"
22#include "util/scope_exit.h"
23
24class SPStyle;
25
27
28using StyleMap = std::map<SPAttr, std::string>;
29
31{
32public:
38 explicit StyleMemory(std::set<SPAttr> remember_attrs)
39 : _attrs(std::move(remember_attrs))
40 {
41 _changes.emplace();
42 }
43
51 StyleMap get_changes(SPStyle const *style) const;
52
57 {
58 StyleMap changes = get_changes(style);
59 _push(changes);
60 return changes;
61 }
62
66 StyleMap get_ifset(SPStyle const *style) const;
67
74 StyleMap const &get_state() const
75 {
76 return _changes.top();
77 };
78
87 [[nodiscard]] auto remember(StyleMap map)
88 {
89 _push(std::move(map));
90 return scope_exit([this] { _changes.pop(); });
91 }
92
93private:
94 // A list of CSS properties to watch for changes in
95 std::set<SPAttr> const _attrs;
96
97 // A stack of complete StyleMaps strings
98 std::stack<StyleMap> _changes;
99
100 void _push(StyleMap changes)
101 {
102 // The incoming map is a delta, but we must store a merge between the previous and the delta.
103 auto current = get_state();
104 changes.merge(std::move(current));
105 _changes.push(std::move(changes));
106 }
107};
108
109} // namespace Inkscape::Extension::Internal
110
111#endif /* !EXTENSION_INTERNAL_PDFOUTPUT_REMEMBERSTYLES_H */
112
113/*
114 Local Variables:
115 mode:c++
116 c-file-style:"stroustrup"
117 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
118 indent-tabs-mode:nil
119 fill-column:99
120 End:
121*/
122// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :
Lookup dictionary for attributes/properties.
StyleMap get_changes(SPStyle const *style) const
Return a StyleMap of all the differences between the state and the given style.
StyleMap get_changes_and_remember(SPStyle const *style)
Modify the changes scope without managing the FILO stack.
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...
StyleMemory(std::set< SPAttr > remember_attrs)
Construct a new style memeory and ask for specific attrs.
auto remember(StyleMap map)
Add the given map to the stack and return a scoped object.
An SVG style object.
Definition style.h:45
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
STL namespace.
Run code on scope exit.
SPStyle - a style object for SPItem objects.