17#include <glibmm/i18n.h>
18#include <glibmm/markup.h>
19#include <glibmm/value.h>
20#include <gdkmm/contentprovider.h>
21#include <gtkmm/dragsource.h>
22#include <sigc++/functors/mem_fun.h>
38 , family_frame (_(
"Font family"))
39 , style_frame (C_(
"Font selector",
"Style"))
40 , size_label (_(
"Font size"))
41 , size_combobox (true)
42 , signal_block (false)
46 Glib::RefPtr<Gtk::TreeModel> model = font_lister->
get_font_list();
50 int total = model->children().size();
54 g_warning(
"You have a huge number of font families (%d), "
55 "and Cairo is limiting the size of widgets you can draw.\n"
56 "Your preview cell height is capped to %d.",
62#if !PANGO_VERSION_CHECK(1,50,0)
96 style_scroll.set_policy (Gtk::PolicyType::AUTOMATIC, Gtk::PolicyType::AUTOMATIC);
107 entry->set_width_chars(6);
118 set_name (
"FontSelectorGrid");
120 set_column_spacing(4);
130 if (with_variations) {
178 Glib::RefPtr<Gdk::Drag>
const &drag)
181 Glib::RefPtr<Gtk::TreeSelection> selection =
family_treeview.get_selection();
182 Gtk::TreeModel::iterator iter = selection->get_selected();
183 Gtk::TreePath path(iter);
185 source.set_icon(paintable, 0, 0);
199 Glib::Value<Glib::ustring> value;
200 value.init(G_TYPE_STRING);
201 value.set(family_name);
214 4, 6, 8, 9, 10, 11, 12, 13, 14, 16, 18, 20, 22, 24, 28,
215 32, 36, 40, 48, 56, 64, 72, 144
220 double ratios[] = {1, 1, 1, 10, 4, 40, 100, 16, 8, 0.16};
224 double size = i/ratios[unit];
248 Glib::ustring family = font_lister->get_font_family();
249 Glib::ustring style = font_lister->get_font_style();
253 path = font_lister->get_row_for_font(family).get_iter();
255 std::cerr <<
"FontSelector::update_font: Couldn't find row for font-family: "
256 << family.raw() << std::endl;
261 Gtk::TreePath currentPath;
262 Gtk::TreeViewColumn *currentColumn;
264 if (currentPath.empty() || !font_lister->is_path_for_font(currentPath, family)) {
271 auto styles = row.get_value(font_lister->font_list.styles);
274 Gtk::TreeModel::iterator match;
276 for (
auto const &s : *styles) {
277 auto srow = *local_style_list_store->append();
278 srow[font_lister->font_style_list.cssStyle] = s.css_name;
279 srow[font_lister->font_style_list.displayStyle] = s.display_name;
280 if (style == s.css_name) {
281 match = srow.get_iter();
291 Glib::ustring fontspec = font_lister->get_fontspec();
303 std::stringstream ss;
320 Glib::RefPtr<Gtk::TreeModel> model = font_lister->
get_font_list();
330 Glib::ustring family =
"Sans";
331 Gtk::TreeModel::iterator iter =
family_treeview.get_selection()->get_selected();
333 (*iter).get_value(0, family);
336 Glib::ustring style =
"Normal";
339 (*iter).get_value(0, style);
342 if (family.empty()) {
343 std::cerr <<
"FontSelector::get_fontspec: empty family!" << std::endl;
347 std::cerr <<
"FontSelector::get_fontspec: empty style!" << std::endl;
350 Glib::ustring fontspec = family +
", ";
352 if (use_variations) {
354 auto pos = style.find(
'@');
355 if (pos != Glib::ustring::npos) {
356 style.erase (pos, style.length()-1);
361 if (variations.empty()) {
364 fontspec += variations;
375 Gtk::TreeModel::const_iterator
const &iter)
377 Glib::ustring family =
"Sans";
378 auto const iter_family =
family_treeview.get_selection()->get_selected();
380 (*iter_family).get_value(0, family);
383 Glib::ustring style =
"Normal";
384 (*iter).get_value(1, style);
386 Glib::ustring style_escaped = Glib::Markup::escape_text( style );
387 Glib::ustring font_desc = Glib::Markup::escape_text( family +
", " + style );
388 Glib::ustring markup;
390 markup =
"<span font='" + font_desc +
"'>" + style_escaped +
"</span>";
394 renderer->set_property(
"markup", markup);
406 Glib::RefPtr<Gtk::TreeModel> model;
407 Gtk::TreeModel::iterator iter =
family_treeview.get_selection()->get_selected(model);
416 fontlister->ensureRowStyles(iter);
418 Gtk::TreeModel::Row row = *iter;
421 Glib::ustring family;
422 row.get_value(0, family);
424 fontlister->set_dragging_family(family);
427 auto styles = row.get_value(fontlister->font_list.styles);
430 Glib::ustring style = fontlister->get_font_style();
431 Glib::ustring best = fontlister->get_best_style_match (family, style);
436 Gtk::TreeModel::iterator it_best;
441 for (
auto const &s : *styles) {
442 auto srow = *local_style_list_store->append();
443 srow[FontStyleList.
cssStyle] = s.css_name;
445 if (best == s.css_name) {
446 it_best = srow.get_iter();
484 size = std::stod (input);
486 catch (std::invalid_argument) {
487 std::cerr <<
"FontSelector::on_size_changed: Invalid input: " << input.raw() << std::endl;
493 int max_size = prefs->
getInt(
"/dialogs/textandfont/maxFontSize", 10000);
This class enumerates fonts using libnrtype into reusable data stores and allows for random access to...
Glib::ustring const & get_dragging_family() const
Glib::RefPtr< Gtk::ListStore > const & get_style_list() const
void update_font_list(SPDocument *document)
Updates font list to include fonts in document.
static Inkscape::FontLister * get_instance()
FontStyleListClass font_style_list
Glib::RefPtr< Gtk::ListStore > const & get_font_list() const
Preference storage class.
static Preferences * get()
Access the singleton Preferences object.
int getInt(Glib::ustring const &pref_path, int def=0)
Retrieve an integer.
Utilities to more easily use Gtk::EventController & subclasses like Gesture.
Editable view implementation.
TODO: insert short description here.
The data describing a single loaded font.
bool font_lister_separator_func(Glib::RefPtr< Gtk::TreeModel > const &, Gtk::TreeModel::const_iterator const &iter)
void font_lister_cell_data_func_markup(Gtk::CellRenderer *const renderer, Gtk::TreeModel::const_iterator const &iter)
void font_lister_cell_data_func(Gtk::CellRenderer *, Gtk::TreeModel::const_iterator const &)
The routines here create and manage a font selector widget with three parts, one each for font-family...
Gtk::DragSource & add_drag_source(Gtk::Widget &widget, AddDragSourceArgs &&args, Gtk::PropagationPhase const phase, When const when)
Create a drag source for the given widget.
Glib::ustring format_classic(T const &... args)
Gtk::TreeModelColumn< Glib::ustring > cssStyle
Column containing the styles in CSS/Pango format.
Gtk::TreeModelColumn< Glib::ustring > displayStyle
Column containing the styles as Font designer used.
gchar const * sp_style_get_css_unit_string(int unit)