1 // SPDX-License-Identifier: GPL-2.0-or-later 2 /* 3 * Author: 4 * Tavmjong Bah <tavmjong@free.fr> 5 * 6 * Copyright (C) 2018 Tavmong Bah 7 * 8 * Released under GNU GPL v2+, read the file 'COPYING' for more information. 9 * 10 * 11 * The routines here create and manage a font selector widget with three parts, 12 * one each for font-family, font-style, and font-size. 13 * 14 * It is used by the TextEdit and Glyphs panel dialogs. The FontLister class is used 15 * to access the list of font-families and their associated styles for fonts either 16 * on the system or in the document. The FontLister class is also used by the Text 17 * toolbar. Fonts are kept track of by their "fontspecs" which are the same as the 18 * strings that Pango generates. 19 * 20 * The main functions are: 21 * Create the font-seletor widget. 22 * Update the lists when a new text selection is made. 23 * Update the Style list when a new font-family is selected, highlighting the 24 * best match to the original font style (as not all fonts have the same style options). 25 * Emit a signal when any change is made so that the Text Preview can be updated. 26 * Provide the currently selected values. 27 */ 28 29 #ifndef INKSCAPE_UI_WIDGET_FONT_SELECTOR_H 30 #define INKSCAPE_UI_WIDGET_FONT_SELECTOR_H 31 32 #include <gtkmm/grid.h> 33 #include <gtkmm/frame.h> 34 #include <gtkmm/scrolledwindow.h> 35 #include <gtkmm/treeview.h> 36 #include <gtkmm/label.h> 37 #include <gtkmm/comboboxtext.h> 38 39 #include "ui/widget/font-variations.h" 40 #include "ui/widget/scrollprotected.h" 41 42 namespace Inkscape { 43 namespace UI { 44 namespace Widget { 45 46 /** 47 * A container of widgets for selecting font faces. 48 * 49 * It is used by the TextEdit and Glyphs panel dialogs. The FontSelector class utilizes the 50 * FontLister class to obtain a list of font-families and their associated styles for fonts either 51 * on the system or in the document. The FontLister class is also used by the Text toolbar. Fonts 52 * are kept track of by their "fontspecs" which are the same as the strings that Pango generates. 53 * 54 * The main functions are: 55 * Create the font-selector widget. 56 * Update the child widgets when a new text selection is made. 57 * Update the Style list when a new font-family is selected, highlighting the 58 * best match to the original font style (as not all fonts have the same style options). 59 * Emit a signal when any change is made to a child widget. 60 */ 61 class FontSelector : public Gtk::Grid 62 { 63 64 public: 65 66 /** 67 * Constructor 68 */ 69 FontSelector (bool with_size = true, bool with_variations = true); 70 71 protected: 72 73 // Font family 74 Gtk::Frame family_frame; 75 Gtk::ScrolledWindow family_scroll; 76 Gtk::TreeView family_treeview; 77 Gtk::TreeViewColumn family_treecolumn; 78 Gtk::CellRendererText family_cell; 79 80 // Font style 81 Gtk::Frame style_frame; 82 Gtk::ScrolledWindow style_scroll; 83 Gtk::TreeView style_treeview; 84 Gtk::TreeViewColumn style_treecolumn; 85 Gtk::CellRendererText style_cell; 86 87 // Font size 88 Gtk::Label size_label; 89 ScrollProtected<Gtk::ComboBoxText> size_combobox; 90 91 // Font variations 92 Gtk::ScrolledWindow font_variations_scroll; 93 FontVariations font_variations; 94 95 private: 96 97 // Set sizes in font size combobox. 98 void set_sizes(); 99 void set_fontsize_tooltip(); 100 101 // Use font style when listing style names. 102 void style_cell_data_func (Gtk::CellRenderer *renderer, Gtk::TreeIter const &iter); 103 104 // Signal handlers 105 void on_family_changed(); 106 void on_style_changed(); 107 void on_size_changed(); 108 void on_variations_changed(); 109 110 // Signals 111 sigc::signal<void, Glib::ustring> signal_changed; 112 void changed_emit(); 113 bool signal_block; 114 115 // Variables 116 double font_size; 117 118 // control font variations update and UI element size 119 void update_variations(const Glib::ustring& fontspec); 120 121 public: 122 123 /** 124 * Update GUI based on fontspec 125 */ 126 void update_font (); 127 void update_size (double size); 128 129 /** 130 * Get fontspec based on current settings. (Does not handle size, yet.) 131 */ 132 Glib::ustring get_fontspec(bool use_variations = true); 133 134 /** 135 * Get font size. Could be merged with fontspec. 136 */ get_fontsize()137 double get_fontsize() { return font_size; }; 138 139 /** 140 * Let others know that user has changed GUI settings. 141 * (Used to enable 'Apply' and 'Default' buttons.) 142 */ connectChanged(sigc::slot<void,Glib::ustring> slot)143 sigc::connection connectChanged(sigc::slot<void, Glib::ustring> slot) { 144 return signal_changed.connect(slot); 145 } 146 }; 147 148 149 } // namespace Widget 150 } // namespace UI 151 } // namespace Inkscape 152 153 #endif // INKSCAPE_UI_WIDGET_FONT_SETTINGS_H 154 155 /* 156 Local Variables: 157 mode:c++ 158 c-file-style:"stroustrup" 159 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) 160 indent-tabs-mode:nil 161 fill-column:99 162 End: 163 */ 164 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8 : 165