13#include <gdkmm/contentprovider.h>
14#include <glibmm/i18n.h>
15#include <glibmm/markup.h>
16#include <glibmm/value.h>
17#include <gtkmm/dragsource.h>
18#include <gtkmm/grid.h>
19#include <sigc++/functors/mem_fun.h>
23#include <glibmm/i18n.h>
24#include <glibmm/main.h>
25#include <glibmm/markup.h>
44 return std::make_unique<FontSelector>();
49 , family_frame(_(
"Font family"))
50 , style_frame(C_(
"Font selector",
"Style"))
51 , size_label(_(
"Font size"))
57 Glib::RefPtr<Gtk::TreeModel> model = font_lister->
get_font_list();
61 int total = model->children().size();
65 g_warning(
"You have a huge number of font families (%d), "
66 "and Cairo is limiting the size of widgets you can draw.\n"
67 "Your preview cell height is capped to %d.",
73#if !PANGO_VERSION_CHECK(1,50,0)
86 family_scroll.set_policy (Gtk::PolicyType::NEVER, Gtk::PolicyType::AUTOMATIC);
107 style_scroll.set_policy (Gtk::PolicyType::AUTOMATIC, Gtk::PolicyType::AUTOMATIC);
118 entry->set_width_chars(6);
129 set_name (
"FontSelectorGrid");
132 auto const grid = Gtk::make_managed<Gtk::Grid>();
133 grid->set_column_homogeneous(
true);
134 grid->set_column_spacing(4);
140 auto const size_grid = Gtk::make_managed<Gtk::Grid>();
141 size_grid->set_column_spacing(4);
146 if (with_variations) {
153 auto const drag = Gtk::DragSource::create();
155 drag->signal_drag_begin().connect([
this, &drag = *drag](
auto &&...args) {
on_drag_begin(drag, args...); });
195 Glib::RefPtr<Gdk::Drag>
const &drag)
198 Glib::RefPtr<Gtk::TreeSelection> selection =
family_treeview.get_selection();
199 Gtk::TreeModel::iterator iter = selection->get_selected();
200 Gtk::TreePath path(iter);
202 source.set_icon(paintable, 0, 0);
210 Glib::Value<Glib::ustring> value;
211 value.init(G_TYPE_STRING);
212 value.set(family_name);
213 return Gdk::ContentProvider::create(value);
225 4, 6, 8, 9, 10, 11, 12, 13, 14, 16, 18, 20, 22, 24, 28,
226 32, 36, 40, 48, 56, 64, 72, 144
231 double ratios[] = {1, 1, 1, 10, 4, 40, 100, 16, 8, 0.16};
235 double size = i/ratios[unit];
259 Glib::ustring family = font_lister->get_font_family();
260 Glib::ustring style = font_lister->get_font_style();
264 path = font_lister->get_row_for_font(family).get_iter();
266 std::cerr <<
"FontSelector::update_font: Couldn't find row for font-family: "
267 << family.raw() << std::endl;
272 Gtk::TreePath currentPath;
273 Gtk::TreeViewColumn *currentColumn;
275 if (currentPath.empty() || !font_lister->is_path_for_font(currentPath, family)) {
282 auto styles = row.get_value(font_lister->font_list.styles);
285 Gtk::TreeModel::iterator match;
286 auto local_style_list_store = Gtk::ListStore::create(font_lister->font_style_list);
287 for (
auto const &s : *styles) {
288 auto srow = *local_style_list_store->append();
289 srow[font_lister->font_style_list.cssStyle] = s.css_name;
290 srow[font_lister->font_style_list.displayStyle] = s.display_name;
291 if (style == s.css_name) {
292 match = srow.get_iter();
302 Glib::ustring fontspec = font_lister->get_fontspec();
314 std::stringstream ss;
331 Glib::RefPtr<Gtk::TreeModel> model = font_lister->
get_font_list();
341 Glib::ustring family =
"Sans";
342 Gtk::TreeModel::iterator iter =
family_treeview.get_selection()->get_selected();
344 (*iter).get_value(0, family);
347 Glib::ustring style =
"Normal";
350 (*iter).get_value(0, style);
353 if (family.empty()) {
354 std::cerr <<
"FontSelector::get_fontspec: empty family!" << std::endl;
358 std::cerr <<
"FontSelector::get_fontspec: empty style!" << std::endl;
361 Glib::ustring fontspec = family +
", ";
363 if (use_variations) {
365 auto pos = style.find(
'@');
366 if (pos != Glib::ustring::npos) {
367 style.erase (pos, style.length()-1);
372 if (variations.empty()) {
375 fontspec += variations;
386 Gtk::TreeModel::const_iterator
const &iter)
388 Glib::ustring family =
"Sans";
389 auto const iter_family =
family_treeview.get_selection()->get_selected();
391 (*iter_family).get_value(0, family);
394 Glib::ustring style =
"Normal";
395 (*iter).get_value(1, style);
397 Glib::ustring style_escaped = Glib::Markup::escape_text( style );
398 Glib::ustring font_desc = Glib::Markup::escape_text( family +
", " + style );
399 Glib::ustring markup;
401 markup =
"<span font='" + font_desc +
"'>" + style_escaped +
"</span>";
403 renderer->set_property(
"markup", markup);
415 Glib::RefPtr<Gtk::TreeModel> model;
416 Gtk::TreeModel::iterator iter =
family_treeview.get_selection()->get_selected(model);
425 fontlister->ensureRowStyles(iter);
427 Gtk::TreeModel::Row row = *iter;
430 Glib::ustring family;
431 row.get_value(0, family);
433 fontlister->set_dragging_family(family);
436 auto styles = row.get_value(fontlister->font_list.styles);
439 Glib::ustring style = fontlister->get_font_style();
440 Glib::ustring best = fontlister->get_best_style_match (family, style);
445 Gtk::TreeModel::iterator it_best;
447 Glib::RefPtr<Gtk::ListStore> local_style_list_store = Gtk::ListStore::create(FontStyleList);
450 for (
auto const &s : *styles) {
451 auto srow = *local_style_list_store->append();
452 srow[FontStyleList.
cssStyle] = s.css_name;
454 if (best == s.css_name) {
455 it_best = srow.get_iter();
493 size = std::stod (input);
495 catch (std::invalid_argument) {
496 std::cerr <<
"FontSelector::on_size_changed: Invalid input: " << input.raw() << std::endl;
502 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
Glib::ustring get_fontspec() 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...
Glib::ustring format_classic(T const &... args)
static void append(std::vector< T > &target, std::vector< T > &&source)
Singleton class to access the preferences file in a convenient way.
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)