Inkscape
Vector Graphics Editor
Loading...
Searching...
No Matches
svg-fonts-dialog.h
Go to the documentation of this file.
1// SPDX-License-Identifier: GPL-2.0-or-later
5/* Authors:
6 * Felipe Corrêa da Silva Sanches <juca@members.fsf.org>
7 *
8 * Copyright (C) 2008 Authors
9 * Released under GNU GPL v2+, read the file 'COPYING' for more information.
10 */
11
12#ifndef INKSCAPE_UI_DIALOG_SVG_FONTS_H
13#define INKSCAPE_UI_DIALOG_SVG_FONTS_H
14
15#include <glibmm/property.h>
16#include <gtkmm/combobox.h>
17#include <gtkmm/drawingarea.h>
18#include <gtkmm/entry.h>
19#include <gtkmm/grid.h>
20#include <gtkmm/iconview.h>
21#include <gtkmm/label.h>
22#include <gtkmm/menubutton.h>
23#include <gtkmm/scrolledwindow.h>
24#include <gtkmm/treeview.h>
25
26#include "attributes.h"
30#include "xml/helper-observer.h"
31
32namespace Gtk {
33class ListStore;
34class Scale;
35} // namespace Gtk
36
37class SPGlyph;
38class SPGlyphKerning;
39class SvgFont;
40
41class SvgFontDrawingArea final : public Gtk::DrawingArea {
42public:
44
45 void set_text(Glib::ustring);
46 void set_svgfont(SvgFont*);
47 void set_size(int x, int y);
48 void redraw();
49
50private:
51 int _x = 0, _y = 0;
52 SvgFont *_svgfont = nullptr;
53 Glib::ustring _text;
54 void draw_func(Cairo::RefPtr<Cairo::Context> const &cr, int width, int height);
55};
56
57class SPFont;
58
59namespace Inkscape::UI {
60
61namespace Widget {
62class PopoverMenu;
63class PopoverMenuItem;
64} // namespace Widget
65
66namespace Dialog {
67
68class GlyphMenuButton final : public Gtk::MenuButton {
69public:
72
73 void update(SPFont const *spfont);
74 [[nodiscard]] Glib::ustring get_active_text() const;
75
76private:
77 Gtk::Label _label;
78 std::unique_ptr<UI::Widget::PopoverMenu> _menu;
79};
80
81// cell text renderer for SVG font glyps (relying on Cairo "user font");
82// it can accept mouse clicks and report them via signal_clicked()
83class SvgGlyphRenderer final : public Gtk::CellRenderer {
84public:
86 Glib::ObjectBase(typeid(CellRenderer)),
87 Gtk::CellRenderer(),
88 _property_active(*this, "active", true),
89 _property_activatable(*this, "activatable", true),
90 _property_glyph(*this, "glyph", "") {
91
92 property_mode() = Gtk::CellRendererMode::ACTIVATABLE;
93 }
94
95 Glib::PropertyProxy<Glib::ustring> property_glyph() { return _property_glyph.get_proxy(); }
96 Glib::PropertyProxy<bool> property_active() { return _property_active.get_proxy(); }
97 Glib::PropertyProxy<bool> property_activatable() { return _property_activatable.get_proxy(); }
98
99 [[nodiscard]] auto signal_clicked() {
100 return _signal_clicked;
101 }
102
103 void set_svg_font(SvgFont* font) {
104 _font = font;
105 }
106
107 void set_font_size(int size) {
108 _font_size = size;
109 }
110
111 void set_tree(Gtk::Widget* tree) {
112 _tree = tree;
113 }
114
115 void set_cell_size(int w, int h) {
116 _width = w;
117 _height = h;
118 }
119
120 int get_width() const {
121 return _width;
122 }
123
124 void snapshot_vfunc(Glib::RefPtr<Gtk::Snapshot> const& snapshot,
125 Gtk::Widget &widget,
126 Gdk::Rectangle const &background_area,
127 Gdk::Rectangle const &cell_area,
128 Gtk::CellRendererState flags) final;
129
130 bool activate_vfunc(Glib::RefPtr<Gdk::Event const> const &event,
131 Gtk::Widget &widget,
132 Glib::ustring const &path,
133 Gdk::Rectangle const &background_area,
134 Gdk::Rectangle const &cell_area,
135 Gtk::CellRendererState flags) final;
136
137 void get_preferred_width_vfunc(Gtk::Widget& widget, int& min_w, int& nat_w) const final
138 {
139 min_w = nat_w = _width;
140 }
141
142 void get_preferred_height_vfunc(Gtk::Widget& widget, int& min_h, int& nat_h) const final
143 {
144 min_h = nat_h = _height;
145 }
146
147private:
148 int _width = 0;
149 int _height = 0;
150 int _font_size = 0;
151 Glib::Property<Glib::ustring> _property_glyph;
152 Glib::Property<bool> _property_active;
153 Glib::Property<bool> _property_activatable;
154 SvgFont* _font = nullptr;
155 Gtk::Widget* _tree = nullptr;
156 sigc::signal<void (Glib::RefPtr<Gdk::Event const> const &,
157 Glib::ustring const &)> _signal_clicked;
158};
159
160
161class SvgFontsDialog final : public DialogBase
162{
163public:
166
167 void documentReplaced() final;
168
169private:
170 void update_fonts(bool document_replaced);
171 SvgFont* get_selected_svgfont();
172 SPFont* get_selected_spfont();
173 SPGlyph* get_selected_glyph();
174 SPGlyphKerning* get_selected_kerning_pair();
175
176 void on_font_selection_changed();
177 void on_kerning_pair_selection_changed();
178 void on_preview_text_changed();
179 void on_kerning_pair_changed();
180 void on_kerning_value_changed();
181 void on_setfontdata_changed();
182 void add_font();
183
184 // Used for font-family
186 {
187 public:
188 AttrEntry(SvgFontsDialog* d, gchar* lbl, Glib::ustring tooltip, const SPAttr attr);
189 void set_text(const char*);
190 Gtk::Entry* get_entry() { return &entry; }
191 Gtk::Label* get_label() { return _label; }
192 private:
194 void on_attr_changed();
195 Gtk::Entry entry;
197 Gtk::Label* _label;
198 };
199
201 {
202 public:
203 AttrSpin(SvgFontsDialog* d, gchar* lbl, Glib::ustring tooltip, const SPAttr attr);
204 void set_value(double v);
205 void set_range(double low, double high);
207 Gtk::Label* get_label() { return _label; }
208 private:
210 void on_attr_changed();
213 Gtk::Label* _label;
214 };
215
217
218 void update_glyphs(SPGlyph* changed_glyph = nullptr);
219 void update_glyph(SPGlyph* glyph);
220 void set_glyph_row(Gtk::TreeRow &row, SPGlyph &glyph);
221 void refresh_svgfont();
222 void update_sensitiveness();
223 void update_global_settings_tab();
224 void populate_glyphs_box();
225 void populate_kerning_pairs_box();
226 void set_glyph_description_from_selected_path();
227 void missing_glyph_description_from_selected_path();
228 void reset_missing_glyph_description();
229 void add_glyph();
230 void glyph_unicode_edit(const Glib::ustring&, const Glib::ustring&);
231 void glyph_name_edit( const Glib::ustring&, const Glib::ustring&);
232 void glyph_advance_edit(const Glib::ustring&, const Glib::ustring&);
233 void remove_selected_glyph();
234 void remove_selected_font();
235 void remove_selected_kerning_pair();
236 void font_selected(SvgFont* svgfont, SPFont* spfont);
237
238 void add_kerning_pair();
239
240 Gtk::TreeModel::iterator get_selected_glyph_iter();
241 void set_selected_glyph(SPGlyph* glyph);
242 void edit_glyph(SPGlyph* glyph);
243 void sort_glyphs(SPFont* font);
244
247 sigc::scoped_connection _defs_observer_connection;
248
249 Gtk::Box* AttrCombo(gchar* lbl, const SPAttr attr);
250 Gtk::Box* global_settings_tab();
251
252 // <font>
253 Gtk::Label* _font_label;
254 std::unique_ptr<AttrSpin> _horiz_adv_x_spin;
255 std::unique_ptr<AttrSpin> _horiz_origin_x_spin;
256 std::unique_ptr<AttrSpin> _horiz_origin_y_spin;
257
258 // <font-face>
259 Gtk::Label* _font_face_label;
260 std::unique_ptr<AttrEntry> _familyname_entry;
261 std::unique_ptr<AttrSpin> _units_per_em_spin;
262 std::unique_ptr<AttrSpin> _ascent_spin;
263 std::unique_ptr<AttrSpin> _descent_spin;
264 std::unique_ptr<AttrSpin> _cap_height_spin;
265 std::unique_ptr<AttrSpin> _x_height_spin;
266
267 Gtk::Box* kerning_tab();
268 Gtk::Box* glyphs_tab();
269 Gtk::Button _font_add;
270 Gtk::Button _font_remove;
271
272 class Columns : public Gtk::TreeModel::ColumnRecord
273 {
274 public:
276 add(spfont);
277 add(svgfont);
278 add(label);
279 }
280
281 Gtk::TreeModelColumn<SPFont*> spfont;
282 Gtk::TreeModelColumn<SvgFont*> svgfont;
283 Gtk::TreeModelColumn<Glib::ustring> label;
284 };
285 Glib::RefPtr<Gtk::ListStore> _model;
287 Gtk::TreeView _FontsList;
288 Gtk::ScrolledWindow _fonts_scroller;
289
290 /* Glyph Tab */
291 class GlyphsColumns : public Gtk::TreeModel::ColumnRecord
292 {
293 public:
295 add(glyph_node);
296 add(glyph_name);
297 add(unicode);
298 add(UplusCode);
299 add(advance);
300 add(name_markup);
301 }
302
303 Gtk::TreeModelColumn<SPGlyph*> glyph_node;
304 Gtk::TreeModelColumn<Glib::ustring> glyph_name;
305 Gtk::TreeModelColumn<Glib::ustring> unicode;
306 Gtk::TreeModelColumn<Glib::ustring> UplusCode;
307 Gtk::TreeModelColumn<double> advance;
308 Gtk::TreeModelColumn<Glib::ustring> name_markup;
309 };
310 enum GlyphColumnIndex { ColGlyph, ColName, ColString, ColUplusCode, ColAdvance };
312 Glib::RefPtr<Gtk::ListStore> _GlyphsListStore;
313 Gtk::TreeView _GlyphsList;
314 Gtk::ScrolledWindow _GlyphsListScroller;
315 Gtk::ScrolledWindow _glyphs_icon_scroller;
316 Gtk::IconView _glyphs_grid;
317 SvgGlyphRenderer* _glyph_renderer = nullptr;
318 SvgGlyphRenderer* _glyph_cell_renderer = nullptr;
319
320 /* Kerning Tab */
321 class KerningPairColumns : public Gtk::TreeModel::ColumnRecord
322 {
323 public:
325 add(first_glyph);
326 add(second_glyph);
327 add(kerning_value);
328 add(spnode);
329 }
330
331 Gtk::TreeModelColumn<Glib::ustring> first_glyph;
332 Gtk::TreeModelColumn<Glib::ustring> second_glyph;
333 Gtk::TreeModelColumn<double> kerning_value;
334 Gtk::TreeModelColumn<SPGlyphKerning *> spnode;
335 };
336
338 Glib::RefPtr<Gtk::ListStore> _KerningPairsListStore;
339 Gtk::TreeView _KerningPairsList;
340 Gtk::ScrolledWindow _KerningPairsListScroller;
342
343 Gtk::Grid _header_box;
344 Gtk::Grid _grid;
345 Gtk::Box global_vbox;
346 Gtk::Box glyphs_vbox;
347 Gtk::Box kerning_vbox;
348 Gtk::Entry _preview_entry;
349 bool _show_glyph_list = true;
350 void set_glyphs_view_mode(bool list);
351
352 SvgFontDrawingArea _font_da, kerning_preview;
356 Gtk::Scale* kerning_slider;
357
358 class EntryWidget : public Gtk::Box
359 {
360 public:
362 : Gtk::Box(Gtk::Orientation::HORIZONTAL) {
363 append(_label);
364 append(_entry);
365 }
366 void set_label(const gchar* l){
367 this->_label.set_text(l);
368 }
369 private:
370 Gtk::Label _label;
371 Gtk::Entry _entry;
372 };
373 EntryWidget _font_family, _font_variant;
374};
375
376} // namespace Dialog
377
378} // namespace Inkscape::UI
379
380#endif // INKSCAPE_UI_DIALOG_SVG_FONTS_H
381
382/*
383 Local Variables:
384 mode:c++
385 c-file-style:"stroustrup"
386 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
387 indent-tabs-mode:nil
388 fill-column:99
389 End:
390*/
391// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :
Lookup dictionary for attributes/properties.
SPAttr
Definition attributes.h:27
DialogBase is the base class for the dialog system.
Definition dialog-base.h:40
std::unique_ptr< UI::Widget::PopoverMenu > _menu
Inkscape::UI::Widget::SpinButton * getSpin()
Gtk::TreeModelColumn< SPFont * > spfont
Gtk::TreeModelColumn< Glib::ustring > label
Gtk::TreeModelColumn< SvgFont * > svgfont
Gtk::TreeModelColumn< Glib::ustring > glyph_name
Gtk::TreeModelColumn< Glib::ustring > name_markup
Gtk::TreeModelColumn< Glib::ustring > UplusCode
Gtk::TreeModelColumn< Glib::ustring > unicode
Gtk::TreeModelColumn< SPGlyphKerning * > spnode
std::unique_ptr< AttrEntry > _familyname_entry
Glib::RefPtr< Gtk::ListStore > _GlyphsListStore
Inkscape::XML::SignalObserver _glyphs_observer
std::unique_ptr< AttrSpin > _horiz_adv_x_spin
std::unique_ptr< AttrSpin > _ascent_spin
std::unique_ptr< AttrSpin > _x_height_spin
Glib::RefPtr< Gtk::ListStore > _model
Inkscape::UI::Widget::SpinButton setwidth_spin
std::unique_ptr< AttrSpin > _descent_spin
sigc::scoped_connection _defs_observer_connection
Inkscape::XML::SignalObserver _defs_observer
Glib::RefPtr< Gtk::ListStore > _KerningPairsListStore
std::unique_ptr< AttrSpin > _units_per_em_spin
std::unique_ptr< AttrSpin > _horiz_origin_x_spin
std::unique_ptr< AttrSpin > _cap_height_spin
std::unique_ptr< AttrSpin > _horiz_origin_y_spin
Glib::PropertyProxy< Glib::ustring > property_glyph()
void get_preferred_width_vfunc(Gtk::Widget &widget, int &min_w, int &nat_w) const final
Glib::PropertyProxy< bool > property_activatable()
Glib::PropertyProxy< bool > property_active()
void get_preferred_height_vfunc(Gtk::Widget &widget, int &min_h, int &nat_h) const final
sigc::signal< void(Glib::RefPtr< Gdk::Event const > const &, Glib::ustring const &)> _signal_clicked
Glib::Property< Glib::ustring > _property_glyph
A replacement for GTK3ʼs Gtk::Menu, as removed in GTK4.
SpinButton widget, that allows entry of simple math expressions (also units, when linked with UnitMen...
Definition spinbutton.h:52
void set_svgfont(SvgFont *)
void set_text(Glib::ustring)
void draw_func(Cairo::RefPtr< Cairo::Context > const &cr, int width, int height)
void set_size(int x, int y)
const double w
Definition conic-4.cpp:19
A base class for all dialogs.
Util::TreeifyResult const & _tree
TODO: insert short description here.
Glib::ustring label
Definition desktop.h:50
User interface code.
Definition desktop.h:113
STL namespace.
SpatialIndex::ISpatialIndex * tree
void append(std::vector< T > &vec, std::vector< T > const &other)
Definition sanitize.cpp:55
double height
double width