Inkscape
Vector Graphics Editor
Loading...
Searching...
No Matches
font-tags.cpp
Go to the documentation of this file.
1// SPDX-License-Identifier: GPL-2.0-or-later
2#include "font-tags.h"
3#include <glibmm/i18n.h>
4
5namespace Inkscape {
6
8
10 static bool init = true;
11 static FontTags ft;
12 if (init) {
13 init = false;
14 // ft.add_tag(FontTag{"favorites", C_("Font category", "Favorites")});
15 ft.add_tag(FontTag{"sans", C_("Font category", "Sans Serif")});
16 ft.add_tag(FontTag{"serif", C_("Font category", "Serif")});
17 ft.add_tag(FontTag{"script", C_("Font category", "Script")});
18 // ft.add_tag(FontTag{"decorative", C_("Font category", "Decorative")});
19 ft.add_tag(FontTag{"symbols", C_("Font category", "Symbols")});
20 ft.add_tag(FontTag{"monospace", C_("Font category", "Monospace")});
21 ft.add_tag(FontTag{"variable", C_("Font category", "Variable")});
22 ft.add_tag(FontTag{"oblique", C_("Font category", "Oblique")});
23 }
24 return ft;
25}
26
27std::vector<FontTag> FontTags::get_tags() const {
28 return _tags;
29}
30
31void FontTags::add_tag(const FontTag& tag) {
32 _tags.push_back(tag);
33}
34
35std::set<std::string> FontTags::get_font_tags(Glib::RefPtr<Pango::FontFace>& face) const {
36 auto it = _map.find(face);
37 if (it != _map.end()) {
38 return it->second;
39 }
40 return std::set<std::string>();
41}
42
43void FontTags::tag_font(Glib::RefPtr<Pango::FontFace>& face, std::string tag) {
44 g_assert(find_tag(tag));
45
46 _map[face].insert(tag);
47}
48
49const std::vector<FontTag>& FontTags::get_selected_tags() const {
50 return _selected;
51}
52
53const FontTag* FontTags::find_tag(const std::string& tag_id) const {
54 auto it = std::find_if(begin(_tags), end(_tags), [&](const FontTag& ft){ return ft.tag == tag_id; });
55 if (it != end(_tags)) {
56 return &(*it);
57 }
58 return nullptr;
59}
60
61bool FontTags::is_tag_selected(const std::string& tag_id) const {
62 auto it = std::find_if(begin(_selected), end(_selected), [&](const FontTag& ft){ return ft.tag == tag_id; });
63 return it != end(_selected);
64}
65
67 if (!_selected.empty()) {
68 _selected.clear();
69 _signal_tag_changed.emit(nullptr, false);
70 return true;
71 }
72 return false;
73}
74
75bool FontTags::select_tag(const std::string& tag_id, bool selected) {
76 bool modified = false;
77
78 const FontTag* tag = find_tag(tag_id);
79 if (!tag) return modified;
80
81 auto it = std::find(begin(_selected), end(_selected), *tag);
82 if (it != _selected.end()) {
83 // it is selected already
84
85 if (!selected) {
86 _selected.erase(it);
87 modified = true;
88 }
89 }
90 else {
91 // not selected yet
92
93 if (selected) {
94 _selected.push_back(*tag);
95 modified = true;
96 }
97 }
98
99 if (modified) {
100 _signal_tag_changed.emit(tag, selected);
101 }
102
103 return modified;
104}
105
106sigc::signal<void (const FontTag*, bool)>& FontTags::get_signal_tag_changed() {
107 return _signal_tag_changed;
108}
109
110} // namespace
sigc::signal< void(const FontTag *, bool)> _signal_tag_changed
Definition font-tags.h:51
bool is_tag_selected(const std::string &tag_id) const
Definition font-tags.cpp:61
std::vector< FontTag > _selected
Definition font-tags.h:50
static FontTags & get()
Definition font-tags.cpp:9
std::unordered_map< Glib::RefPtr< Pango::FontFace >, std::set< std::string > > _map
Definition font-tags.h:48
sigc::signal< void(const FontTag *, bool)> & get_signal_tag_changed()
const FontTag * find_tag(const std::string &tag_id) const
Definition font-tags.cpp:53
bool select_tag(const std::string &tag_id, bool selected)
Definition font-tags.cpp:75
const std::vector< FontTag > & get_selected_tags() const
Definition font-tags.cpp:49
std::set< std::string > get_font_tags(Glib::RefPtr< Pango::FontFace > &face) const
Definition font-tags.cpp:35
void tag_font(Glib::RefPtr< Pango::FontFace > &face, std::string tag)
Definition font-tags.cpp:43
std::vector< FontTag > get_tags() const
Definition font-tags.cpp:27
std::vector< FontTag > _tags
Definition font-tags.h:49
void add_tag(const FontTag &tag)
Definition font-tags.cpp:31
Geom::Point end
Helper class to stream background task notifications as a series of messages.
std::string tag
Definition font-tags.h:21
void init(int argc, char **argv, Toy *t, int width=600, int height=600)