1 // SPDX-License-Identifier: GPL-2.0-or-later 2 /** @file 3 * @brief SVG Fonts dialog 4 */ 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 <2geom/pathvector.h> 16 #include <gtkmm/box.h> 17 #include <gtkmm/comboboxtext.h> 18 #include <gtkmm/drawingarea.h> 19 #include <gtkmm/entry.h> 20 #include <gtkmm/liststore.h> 21 #include <gtkmm/scrolledwindow.h> 22 #include <gtkmm/treeview.h> 23 24 #include "attributes.h" 25 #include "ui/dialog/dialog-base.h" 26 #include "ui/widget/spinbutton.h" 27 #include "xml/helper-observer.h" 28 29 namespace Gtk { 30 class Scale; 31 } 32 33 class SPGlyph; 34 class SPGlyphKerning; 35 class SvgFont; 36 37 class SvgFontDrawingArea : Gtk::DrawingArea{ 38 public: 39 SvgFontDrawingArea(); 40 void set_text(Glib::ustring); 41 void set_svgfont(SvgFont*); 42 void set_size(int x, int y); 43 void redraw(); 44 private: 45 int _x,_y; 46 SvgFont* _svgfont; 47 Glib::ustring _text; 48 bool on_draw(const Cairo::RefPtr<Cairo::Context> &cr) override; 49 }; 50 51 class SPFont; 52 53 namespace Inkscape { 54 namespace UI { 55 namespace Dialog { 56 57 class GlyphComboBox : public Gtk::ComboBoxText { 58 public: 59 GlyphComboBox(); 60 void update(SPFont*); 61 }; 62 63 class SvgFontsDialog : public DialogBase 64 { 65 public: 66 SvgFontsDialog(); 67 ~SvgFontsDialog() override; 68 getInstance()69 static SvgFontsDialog &getInstance() { return *new SvgFontsDialog(); } 70 71 void update() override; 72 73 void update_fonts(); 74 SvgFont* get_selected_svgfont(); 75 SPFont* get_selected_spfont(); 76 SPGlyph* get_selected_glyph(); 77 SPGlyphKerning* get_selected_kerning_pair(); 78 79 //TODO: these methods should be private, right?! 80 void on_font_selection_changed(); 81 void on_kerning_pair_selection_changed(); 82 void on_preview_text_changed(); 83 void on_kerning_pair_changed(); 84 void on_kerning_value_changed(); 85 void on_setfontdata_changed(); 86 void add_font(); 87 Geom::PathVector flip_coordinate_system(Geom::PathVector pathv); 88 bool updating; 89 90 // Used for font-family 91 class AttrEntry : public Gtk::Box 92 { 93 public: 94 AttrEntry(SvgFontsDialog* d, gchar* lbl, Glib::ustring tooltip, const SPAttr attr); 95 void set_text(char*); 96 private: 97 SvgFontsDialog* dialog; 98 void on_attr_changed(); 99 Gtk::Entry entry; 100 SPAttr attr; 101 }; 102 103 class AttrSpin : public Gtk::Box 104 { 105 public: 106 AttrSpin(SvgFontsDialog* d, gchar* lbl, Glib::ustring tooltip, const SPAttr attr); 107 void set_value(double v); 108 void set_range(double low, double high); getSpin()109 Inkscape::UI::Widget::SpinButton* getSpin() { return &spin; } 110 private: 111 SvgFontsDialog* dialog; 112 void on_attr_changed(); 113 Inkscape::UI::Widget::SpinButton spin; 114 SPAttr attr; 115 }; 116 117 private: 118 void update_glyphs(); 119 void update_sensitiveness(); 120 void update_global_settings_tab(); 121 void populate_glyphs_box(); 122 void populate_kerning_pairs_box(); 123 void set_glyph_description_from_selected_path(); 124 void missing_glyph_description_from_selected_path(); 125 void reset_missing_glyph_description(); 126 void add_glyph(); 127 void glyph_unicode_edit(const Glib::ustring&, const Glib::ustring&); 128 void glyph_name_edit( const Glib::ustring&, const Glib::ustring&); 129 void glyph_advance_edit(const Glib::ustring&, const Glib::ustring&); 130 void remove_selected_glyph(); 131 void remove_selected_font(); 132 void remove_selected_kerning_pair(); 133 134 void add_kerning_pair(); 135 136 void create_glyphs_popup_menu(Gtk::Widget& parent, sigc::slot<void> rem); 137 void glyphs_list_button_release(GdkEventButton* event); 138 139 void create_fonts_popup_menu(Gtk::Widget& parent, sigc::slot<void> rem); 140 void fonts_list_button_release(GdkEventButton* event); 141 142 void create_kerning_pairs_popup_menu(Gtk::Widget& parent, sigc::slot<void> rem); 143 void kerning_pairs_list_button_release(GdkEventButton* event); 144 145 Inkscape::XML::SignalObserver _defs_observer; //in order to update fonts 146 Inkscape::XML::SignalObserver _glyphs_observer; 147 148 sigc::connection _defs_observer_connection; 149 150 Gtk::Box* AttrCombo(gchar* lbl, const SPAttr attr); 151 // Gtk::Box* AttrSpin(gchar* lbl, const SPAttr attr); 152 Gtk::Box* global_settings_tab(); 153 154 // <font> 155 Gtk::Label* _font_label; 156 AttrSpin* _horiz_adv_x_spin; 157 AttrSpin* _horiz_origin_x_spin; 158 AttrSpin* _horiz_origin_y_spin; 159 160 // <font-face> 161 Gtk::Label* _font_face_label; 162 AttrEntry* _familyname_entry; 163 AttrSpin* _units_per_em_spin; 164 AttrSpin* _ascent_spin; 165 AttrSpin* _descent_spin; 166 AttrSpin* _cap_height_spin; 167 AttrSpin* _x_height_spin; 168 169 Gtk::Box* kerning_tab(); 170 Gtk::Box* glyphs_tab(); 171 Gtk::Button _add; 172 Gtk::Button add_glyph_button; 173 Gtk::Button glyph_from_path_button; 174 Gtk::Button missing_glyph_button; 175 Gtk::Button missing_glyph_reset_button; 176 177 class Columns : public Gtk::TreeModel::ColumnRecord 178 { 179 public: Columns()180 Columns() 181 { 182 add(spfont); 183 add(svgfont); 184 add(label); 185 } 186 187 Gtk::TreeModelColumn<SPFont*> spfont; 188 Gtk::TreeModelColumn<SvgFont*> svgfont; 189 Gtk::TreeModelColumn<Glib::ustring> label; 190 }; 191 Glib::RefPtr<Gtk::ListStore> _model; 192 Columns _columns; 193 Gtk::TreeView _FontsList; 194 195 class GlyphsColumns : public Gtk::TreeModel::ColumnRecord 196 { 197 public: GlyphsColumns()198 GlyphsColumns() 199 { 200 add(glyph_node); 201 add(glyph_name); 202 add(unicode); 203 add(advance); 204 } 205 206 Gtk::TreeModelColumn<SPGlyph*> glyph_node; 207 Gtk::TreeModelColumn<Glib::ustring> glyph_name; 208 Gtk::TreeModelColumn<Glib::ustring> unicode; 209 Gtk::TreeModelColumn<double> advance; 210 }; 211 GlyphsColumns _GlyphsListColumns; 212 Glib::RefPtr<Gtk::ListStore> _GlyphsListStore; 213 Gtk::TreeView _GlyphsList; 214 Gtk::ScrolledWindow _GlyphsListScroller; 215 216 class KerningPairColumns : public Gtk::TreeModel::ColumnRecord 217 { 218 public: KerningPairColumns()219 KerningPairColumns() 220 { 221 add(first_glyph); 222 add(second_glyph); 223 add(kerning_value); 224 add(spnode); 225 } 226 227 Gtk::TreeModelColumn<Glib::ustring> first_glyph; 228 Gtk::TreeModelColumn<Glib::ustring> second_glyph; 229 Gtk::TreeModelColumn<double> kerning_value; 230 Gtk::TreeModelColumn<SPGlyphKerning*> spnode; 231 }; 232 KerningPairColumns _KerningPairsListColumns; 233 Glib::RefPtr<Gtk::ListStore> _KerningPairsListStore; 234 Gtk::TreeView _KerningPairsList; 235 Gtk::ScrolledWindow _KerningPairsListScroller; 236 Gtk::Button add_kernpair_button; 237 238 Gtk::Box _font_settings; 239 Gtk::Box global_vbox; 240 Gtk::Box glyphs_vbox; 241 Gtk::Box kerning_vbox; 242 Gtk::Entry _preview_entry; 243 244 Gtk::Menu _FontsContextMenu; 245 Gtk::Menu _GlyphsContextMenu; 246 Gtk::Menu _KerningPairsContextMenu; 247 248 SvgFontDrawingArea _font_da, kerning_preview; 249 GlyphComboBox first_glyph, second_glyph; 250 SPGlyphKerning* kerning_pair; 251 Inkscape::UI::Widget::SpinButton setwidth_spin; 252 Gtk::Scale* kerning_slider; 253 254 class EntryWidget : public Gtk::Box 255 { 256 public: EntryWidget()257 EntryWidget() 258 : Gtk::Box(Gtk::ORIENTATION_HORIZONTAL) 259 { 260 this->add(this->_label); 261 this->add(this->_entry); 262 } set_label(const gchar * l)263 void set_label(const gchar* l){ 264 this->_label.set_text(l); 265 } 266 private: 267 Gtk::Label _label; 268 Gtk::Entry _entry; 269 }; 270 EntryWidget _font_family, _font_variant; 271 }; 272 273 } // namespace Dialog 274 } // namespace UI 275 } // namespace Inkscape 276 277 #endif //#ifndef INKSCAPE_UI_DIALOG_SVG_FONTS_H 278 279 /* 280 Local Variables: 281 mode:c++ 282 c-file-style:"stroustrup" 283 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) 284 indent-tabs-mode:nil 285 fill-column:99 286 End: 287 */ 288 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 : 289