10#include <glibmm/i18n.h>
11#include <gtkmm/checkbutton.h>
12#include <gtkmm/scrolledwindow.h>
13#include <gtkmm/textview.h>
32void show(std::vector<SPItem*>
const &list, Glib::ustring
const &out)
34 Gtk::MessageDialog warning(_(
"Some fonts are not available and have been substituted."),
35 false, Gtk::MessageType::INFO, Gtk::ButtonsType::OK,
true);
36 warning.set_resizable(
true);
37 warning.set_title(_(
"Font substitution"));
41 Gtk::TextView textview;
42 textview.set_editable(
false);
43 textview.set_wrap_mode(Gtk::WrapMode::WORD);
44 textview.set_visible(
true);
45 textview.get_buffer()->set_text(_(out.c_str()));
47 Gtk::ScrolledWindow scrollwindow;
48 scrollwindow.set_child(textview);
49 scrollwindow.set_policy(Gtk::PolicyType::AUTOMATIC, Gtk::PolicyType::AUTOMATIC);
50 scrollwindow.set_has_frame(
true);
51 scrollwindow.set_size_request(0, 100);
52 scrollwindow.set_visible(
true);
54 Gtk::CheckButton cbSelect;
55 cbSelect.set_label(_(
"Select all the affected items"));
56 cbSelect.set_active(
true);
57 cbSelect.set_visible(
true);
59 Gtk::CheckButton cbWarning;
60 cbWarning.set_label(_(
"Don't show this warning again"));
61 cbWarning.set_visible(
true);
63 auto box = warning.get_content_area();
72 if (cbWarning.get_active()) {
76 if (cbSelect.get_active()) {
77 auto desktop = SP_ACTIVE_DESKTOP;
80 selection->setList(list);
95std::pair<std::vector<SPItem*>, Glib::ustring> getFontReplacedItems(
SPDocument *doc)
97 std::vector<SPItem*> outList;
98 std::set<Glib::ustring> setErrors;
99 std::set<Glib::ustring> setFontSpans;
100 std::map<SPItem*, Glib::ustring> mapFontStyles;
104 for (
auto item : allList) {
106 Glib::ustring family =
"";
111 setFontSpans.insert(family);
113 else if (
auto textpath = cast<SPTextPath>(
item)) {
114 if (textpath->originalPath) {
115 family = cast<SPText>(
item->
parent)->layout.getFontFamily(0);
116 setFontSpans.insert(family);
119 else if (is<SPTSpan>(
item) || is<SPFlowtspan>(
item)) {
123 while (parent_text && !is<SPText>(parent_text)) {
124 parent_text = parent_text->
parent;
127 family = cast<SPText>(parent_text)->layout.getFontFamily(0);
129 for (
unsigned int f = 0; f < parent_text->
children.size(); f++) {
130 family = cast<SPText>(parent_text)->layout.getFontFamily(f);
131 setFontSpans.insert(family);
137 char const *style_font =
nullptr;
138 if (style->font_family.set) {
139 style_font = style->font_family.value();
140 }
else if (style->font_specification.set) {
141 style_font = style->font_specification.value();
143 style_font = style->font_family.value();
148 mapFontStyles.insert(std::make_pair(
item, style_font));
155 for (
auto mapIter = mapFontStyles.rbegin(); mapIter != mapFontStyles.rend(); ++mapIter) {
157 Glib::ustring fonts = mapIter->second;
160 std::vector<Glib::ustring> vFonts = Glib::Regex::split_simple(
"," , fonts);
161 bool fontFound =
false;
162 for (
auto const &font : vFonts) {
164 size_t startpos = font.find_first_not_of(
" \n\r\t");
165 size_t endpos = font.find_last_not_of(
" \n\r\t");
166 if (startpos == std::string::npos || endpos == std::string::npos) {
169 auto const trimmed = font.substr(startpos, endpos - startpos + 1);
170 if (setFontSpans.find(trimmed) != setFontSpans.end() ||
171 trimmed == Glib::ustring(
"sans-serif") ||
172 trimmed == Glib::ustring(
"Sans") ||
173 trimmed == Glib::ustring(
"serif") ||
174 trimmed == Glib::ustring(
"Serif") ||
175 trimmed == Glib::ustring(
"monospace") ||
176 trimmed == Glib::ustring(
"Monospace"))
184 Glib::ustring err = Glib::ustring::compose(_(
"Font '%1' substituted with '%2'"), fonts.c_str(), subName.c_str());
185 setErrors.insert(err);
186 outList.emplace_back(
item);
190 for (
auto const &err : setErrors) {
191 out.append(err +
"\n");
192 g_warning(
"%s", err.c_str());
195 return std::make_pair(std::move(outList), std::move(out));
207 auto [list,
msg] = getFontReplacedItems(doc);
void clear()
Unselects all selected objects.
bool getBool(Glib::ustring const &pref_path, bool def=false)
Retrieve a Boolean value.
static Preferences * get()
Access the singleton Preferences object.
void setBool(Glib::ustring const &pref_path, bool value)
Set a Boolean value.
Inkscape::Selection * getSelection() const
Typed SVG document implementation.
SPRoot * getRoot()
Returns our SPRoot.
Base class for visual SVG elements.
SPObject is an abstract base class of all of the document nodes at the SVG document level.
SPStyle * style
Represents the style properties, whether from presentation attributes, the style attribute,...
void sp_transientize(Gtk::Window &window)
Make the argument dialog transient to the currently active document window.
Event handler for dialog windows.
std::string getSubstituteFontName(std::string const &font)
TODO: insert short description here.
void checkFontSubstitutions(SPDocument *doc)
void pack_start(Gtk::Box &box, Gtk::Widget &child, bool const expand, bool const fill, unsigned const padding)
Adds child to box, packed with reference to the start of box.
int dialog_run(Gtk::Dialog &dialog)
This is a GTK4 porting aid meant to replace the removal of the Gtk::Dialog synchronous API.
Helpers for using Gtk::Boxes, encapsulating large changes between GTK3 & GTK4.
Singleton class to access the preferences file in a convenient way.
std::vector< SPItem * > get_all_items(SPObject *from, SPDesktop *desktop, bool onlyvisible, bool onlysensitive, bool ingroups, std::vector< SPItem * > const &exclude)
TODO: insert short description here.
SPRoot: SVG <svg> implementation.
TODO: insert short description here.
TODO: insert short description here.
Text::Layout const * te_get_layout(SPItem const *item)
bool has_visible_text(SPObject const *obj)
bool is_top_level_text_object(SPObject const *obj)