Inkscape
Vector Graphics Editor
Loading...
Searching...
No Matches
Inkscape::FontLister Class Reference

This class enumerates fonts using libnrtype into reusable data stores and allows for random access to the font-family list and the font-style list. More...

#include <font-lister.h>

Classes

struct  FontListClass
 GtkTreeModelColumnRecord for the font-family list Gtk::ListStore. More...
 
struct  FontStyleListClass
 

Public Types

enum class  Exception { FAMILY_NOT_FOUND , STYLE_NOT_FOUND }
 
using Styles = std::vector< StyleNames >
 

Public Member Functions

Glib::RefPtr< Gtk::ListStore > const & get_font_list () const
 
Glib::RefPtr< Gtk::ListStore > const & get_style_list () const
 
void insert_font_family (Glib::ustring const &new_family)
 Inserts a font family or font-fallback list (for use when not already in document or on system).
 
int add_document_fonts_at_top (SPDocument *document)
 
void update_font_list (SPDocument *document)
 Updates font list to include fonts in document.
 
bool find_string_case_insensitive (std::string const &text, std::string const &pat)
 Takes a hand written font spec and returns a Pango generated one in standard form.
 
void show_results (Glib::ustring const &search_text)
 
void apply_collections (std::set< Glib::ustring > &selected_collections)
 
void set_dragging_family (Glib::ustring const &new_family)
 
Glib::ustring canonize_fontspec (Glib::ustring const &fontspec) const
 
Glib::ustring system_fontspec (Glib::ustring const &fontspec)
 Find closest system font to given font.
 
std::pair< Glib::ustring, Glib::ustring > ui_from_fontspec (Glib::ustring const &fontspec) const
 Gets font-family and style from fontspec.
 
std::pair< Glib::ustring, Glib::ustring > selection_update ()
 Sets font-family and style after a selection change.
 
void set_fontspec (Glib::ustring const &fontspec, bool check=true)
 Sets current_fontspec, etc.
 
Glib::ustring get_fontspec () const
 
std::pair< Glib::ustring, Glib::ustring > new_font_family (Glib::ustring const &family, bool check_style=true)
 Changes font-family, updating style list and attempting to find closest style to current_style style (if check_style is true).
 
std::pair< Glib::ustring, Glib::ustring > set_font_family (Glib::ustring const &family, bool check_style=true, bool emit=true)
 Sets font-family, updating style list and attempting to find closest style to old current_style.
 
std::pair< Glib::ustring, Glib::ustring > set_font_family (int row, bool check_style=true, bool emit=true)
 Sets font-family from row in list store.
 
Glib::ustring const & get_font_family () const
 
Glib::ustring const & get_dragging_family () const
 
int get_font_family_row () const
 
void set_font_style (Glib::ustring style, bool emit=true)
 Sets style.
 
Glib::ustring const & get_font_style () const
 
Glib::ustring fontspec_from_style (SPStyle *style) const
 
void fill_css (SPCSSAttr *css, Glib::ustring fontspec={})
 Fill css using given fontspec (doesn't need to be member function).
 
Gtk::TreeModel::Row get_row_for_font ()
 
Gtk::TreeModel::Row get_row_for_font (Glib::ustring const &family)
 
Gtk::TreePath get_path_for_font (Glib::ustring const &family)
 
bool is_path_for_font (Gtk::TreePath path, Glib::ustring family)
 
Gtk::TreeModel::Row get_row_for_style ()
 
Gtk::TreeModel::Row get_row_for_style (Glib::ustring const &style)
 
Gtk::TreePath get_path_for_style (Glib::ustring const &style)
 
std::pair< Gtk::TreePath, Gtk::TreePath > get_paths (Glib::ustring const &family, Glib::ustring const &style)
 
Glib::ustring get_best_style_match (Glib::ustring const &family, Glib::ustring const &style)
 Return best style match for new font given style for old font.
 
void ensureRowStyles (Gtk::TreeModel::iterator iter)
 Ensures the style list for a particular family has been created.
 
Glib::ustring get_font_family_markup (Gtk::TreeModel::const_iterator const &iter) const
 Get markup for font-family.
 
sigc::connection connectUpdate (sigc::slot< void()> slot)
 Let users of FontLister know to update GUI.
 
sigc::connection connectNewFonts (sigc::slot< void()> slot)
 
bool blocked () const
 
int get_font_families_size () const
 
bool font_installed_on_system (Glib::ustring const &font) const
 
void init_font_families (int group_offset=-1, int group_size=-1)
 
void init_default_styles ()
 
std::pair< bool, std::string > get_font_count_label () const
 

Static Public Member Functions

static Inkscape::FontListerget_instance ()
 

Public Attributes

FontListClass font_list
 
FontStyleListClass font_style_list
 
std::map< std::string, PangoFontFamily * > pango_family_map
 The list of fonts, sorted by the order they will appear in the UI.
 

Private Member Functions

 FontLister ()
 
 ~FontLister ()
 
void update_font_data_recursive (SPObject &r, std::map< Glib::ustring, std::set< Glib::ustring > > &font_data)
 
void font_family_row_update (int start=0)
 
void emit_update ()
 

Private Attributes

Glib::RefPtr< Gtk::ListStore > font_list_store
 
Glib::RefPtr< Gtk::ListStore > style_list_store
 
int current_family_row = 0
 Info for currently selected font (what is shown in the UI).
 
Glib::ustring current_family = "sans-serif"
 
Glib::ustring dragging_family
 
Glib::ustring current_style = "Normal"
 
std::shared_ptr< Stylesdefault_styles
 If a font-family is not on system, this list of styles is used.
 
bool block = false
 
sigc::signal< void()> update_signal
 
sigc::signal< void()> new_fonts_signal
 

Detailed Description

This class enumerates fonts using libnrtype into reusable data stores and allows for random access to the font-family list and the font-style list.

Setting the font-family updates the font-style list. "Style" in this case refers to everything but family and size (e.g. italic/oblique, weight).

This class handles font-family lists and fonts that are not on the system, where there is not an entry in the fontInstanceMap.

This class uses the idea of "font_spec". This is a plain text string as used by Pango. It is similar to the CSS font shorthand except that font-family comes first and in this class the font-size is not used.

This class uses the FontFactory class to get a list of system fonts and to find best matches via Pango. The Pango interface is only setup to deal with fonts that are on the system so care must be taken. For example, best matches should only be done with the first font-family in a font-family list. If the first font-family is not on the system then a generic font-family should be used (sans-serif -> Sans).

This class is used by the UI interface (text-toolbar, font-select, etc.). Those items can change the selected font family and style here. When that happens. this class emits a signal for those items to update their displayed values.

This class is a singleton (one instance per Inkscape session). Since fonts used in a document are added to the list, there really should be one instance per document.

"Font" includes family and style. It should not be used when one means font-family.

Definition at line 83 of file font-lister.h.

Member Typedef Documentation

◆ Styles

Definition at line 92 of file font-lister.h.

Member Enumeration Documentation

◆ Exception

Enumerator
FAMILY_NOT_FOUND 
STYLE_NOT_FOUND 

Definition at line 86 of file font-lister.h.

Constructor & Destructor Documentation

◆ FontLister()

◆ ~FontLister()

Inkscape::FontLister::~FontLister ( )
privatedefault

Member Function Documentation

◆ add_document_fonts_at_top()

◆ apply_collections()

◆ blocked()

bool Inkscape::FontLister::blocked ( ) const
inline

Definition at line 328 of file font-lister.h.

References block.

◆ canonize_fontspec()

Glib::ustring Inkscape::FontLister::canonize_fontspec ( Glib::ustring const &  fontspec) const

Definition at line 584 of file font-lister.cpp.

Referenced by get_fontspec().

◆ connectNewFonts()

sigc::connection Inkscape::FontLister::connectNewFonts ( sigc::slot< void()>  slot)
inline

Definition at line 324 of file font-lister.h.

References new_fonts_signal.

◆ connectUpdate()

sigc::connection Inkscape::FontLister::connectUpdate ( sigc::slot< void()>  slot)
inline

Let users of FontLister know to update GUI.

This is to allow synchronization of changes across multiple widgets. Handlers should block signals. Input is fontspec to set.

Definition at line 321 of file font-lister.h.

References update_signal.

Referenced by Inkscape::UI::Dialog::FontCollectionsManager::FontCollectionsManager(), and Inkscape::UI::Dialog::TextEdit::TextEdit().

◆ emit_update()

void Inkscape::FontLister::emit_update ( )
private

Definition at line 575 of file font-lister.cpp.

◆ ensureRowStyles()

void Inkscape::FontLister::ensureRowStyles ( Gtk::TreeModel::iterator  iter)

Ensures the style list for a particular family has been created.

Definition at line 285 of file font-lister.cpp.

References Inkscape::Util::EnableSingleton< FontFactory >::get().

◆ fill_css()

void Inkscape::FontLister::fill_css ( SPCSSAttr css,
Glib::ustring  fontspec = {} 
)

◆ find_string_case_insensitive()

bool Inkscape::FontLister::find_string_case_insensitive ( std::string const &  text,
std::string const &  pat 
)

Takes a hand written font spec and returns a Pango generated one in standard form.

Try to find in the Haystack the Needle - ignore case.

Functions to display the search results in the font list.

Definition at line 172 of file font-lister.cpp.

Referenced by show_results().

◆ font_family_row_update()

void Inkscape::FontLister::font_family_row_update ( int  start = 0)
private

Definition at line 663 of file font-lister.cpp.

References familyNamesAreEqual(), and start.

◆ font_installed_on_system()

bool Inkscape::FontLister::font_installed_on_system ( Glib::ustring const &  font) const

Definition at line 90 of file font-lister.cpp.

References pango_family_map.

Referenced by Inkscape::FontCollections::_read(), and font_lister_cell_data_func2().

◆ fontspec_from_style()

Glib::ustring Inkscape::FontLister::fontspec_from_style ( SPStyle style) const

Definition at line 1083 of file font-lister.cpp.

References ink_font_description_from_style().

◆ get_best_style_match()

Glib::ustring Inkscape::FontLister::get_best_style_match ( Glib::ustring const &  family,
Glib::ustring const &  style 
)

Return best style match for new font given style for old font.

Definition at line 1187 of file font-lister.cpp.

References Inkscape::font_description_better_match(), and Inkscape::Util::EnableSingleton< FontFactory >::get().

◆ get_dragging_family()

Glib::ustring const & Inkscape::FontLister::get_dragging_family ( ) const
inline

◆ get_font_count_label()

◆ get_font_families_size()

int Inkscape::FontLister::get_font_families_size ( ) const
inline

◆ get_font_family()

Glib::ustring const & Inkscape::FontLister::get_font_family ( ) const
inline

◆ get_font_family_markup()

Glib::ustring Inkscape::FontLister::get_font_family_markup ( Gtk::TreeModel::const_iterator const &  iter) const

◆ get_font_family_row()

int Inkscape::FontLister::get_font_family_row ( ) const
inline

Definition at line 262 of file font-lister.h.

References current_family_row.

◆ get_font_list()

Glib::RefPtr< Gtk::ListStore > const & Inkscape::FontLister::get_font_list ( ) const
inline
Returns
the ListStore with the family names

The ListStore is ready to be used after class instantiation and should not be modified.

Definition at line 157 of file font-lister.h.

References font_list_store.

Referenced by Inkscape::UI::Widget::FontSelector::FontSelector(), Inkscape::UI::Dialog::FontCollectionsManager::on_reset_button_pressed(), and Inkscape::UI::Widget::FontSelector::set_model().

◆ get_font_style()

Glib::ustring const & Inkscape::FontLister::get_font_style ( ) const
inline

Definition at line 272 of file font-lister.h.

References current_style.

Referenced by Inkscape::UI::Dialog::TextEdit::onReadSelection().

◆ get_fontspec()

Glib::ustring Inkscape::FontLister::get_fontspec ( ) const
inline

◆ get_instance()

FontLister * Inkscape::FontLister::get_instance ( )
static

Definition at line 165 of file font-lister.cpp.

Referenced by Inkscape::RecentlyUsedFonts::_read(), Inkscape::FontCollections::_read(), Inkscape::UI::Toolbar::TextToolbar::_selectionChanged(), Inkscape::FontCollections::add_font(), Inkscape::UI::Dialog::TextEdit::apply_changes(), Inkscape::UI::Dialog::FontCollectionsManager::change_font_count_label(), Inkscape::UI::Dialog::TextEdit::change_font_count_label(), Inkscape::LivePathEffect::LPEMeasureSegments::createTextLabel(), file_save(), Inkscape::UI::Dialog::TextEdit::fillTextStyle(), font_lister_cell_data_func2(), font_lister_cell_data_func_markup(), font_lister_separator_func(), font_lister_style_cell_data_func(), Inkscape::UI::Dialog::FontCollectionsManager::FontCollectionsManager(), Inkscape::UI::Toolbar::TextToolbar::fontfamily_value_changed(), Inkscape::UI::Widget::FontSelector::FontSelector(), Inkscape::UI::Toolbar::TextToolbar::fontstyle_value_changed(), Inkscape::UI::Widget::ComboBoxEntryToolItem::get_active_row_from_text(), Inkscape::UI::Widget::FontSelector::on_drag_prepare(), Inkscape::UI::Widget::FontCollectionSelector::on_drop_drop(), Inkscape::UI::Widget::FontSelector::on_family_changed(), Inkscape::UI::Dialog::FontCollectionsManager::on_reset_button_pressed(), Inkscape::UI::Dialog::TextEdit::on_reset_button_pressed(), Inkscape::UI::Toolbar::TextToolbar::on_reset_button_pressed(), Inkscape::UI::Dialog::FontCollectionsManager::on_search_entry_changed(), Inkscape::UI::Dialog::TextEdit::on_search_entry_changed(), Inkscape::UI::Dialog::TextEdit::onReadSelection(), Inkscape::UI::Dialog::GlyphsPanel::readSelection(), Inkscape::FontCollections::remove_collection(), Inkscape::FontCollections::remove_font(), Inkscape::UI::Widget::FontSelector::set_model(), Inkscape::UI::Toolbar::TextToolbar::setDesktop(), Inkscape::UI::Dialog::TextEdit::TextEdit(), Inkscape::UI::Toolbar::TextToolbar::TextToolbar(), Inkscape::UI::Widget::FontSelector::update_font(), and Inkscape::FontCollections::update_selected_collections().

◆ get_path_for_font()

Gtk::TreePath Inkscape::FontLister::get_path_for_font ( Glib::ustring const &  family)

Definition at line 1105 of file font-lister.cpp.

◆ get_path_for_style()

Gtk::TreePath Inkscape::FontLister::get_path_for_style ( Glib::ustring const &  style)

◆ get_paths()

std::pair< Gtk::TreePath, Gtk::TreePath > Inkscape::FontLister::get_paths ( Glib::ustring const &  family,
Glib::ustring const &  style 
)

◆ get_row_for_font() [1/2]

Gtk::TreeModel::Row Inkscape::FontLister::get_row_for_font ( )
inline

Definition at line 284 of file font-lister.h.

References current_family, and get_row_for_font().

Referenced by get_row_for_font().

◆ get_row_for_font() [2/2]

Gtk::TreeModel::Row Inkscape::FontLister::get_row_for_font ( Glib::ustring const &  family)

Definition at line 1094 of file font-lister.cpp.

References familyNamesAreEqual().

◆ get_row_for_style() [1/2]

Gtk::TreeModel::Row Inkscape::FontLister::get_row_for_style ( )
inline

Definition at line 292 of file font-lister.h.

References current_style, and get_row_for_style().

Referenced by get_row_for_style().

◆ get_row_for_style() [2/2]

Gtk::TreeModel::Row Inkscape::FontLister::get_row_for_style ( Glib::ustring const &  style)

Definition at line 1119 of file font-lister.cpp.

References familyNamesAreEqual().

◆ get_style_list()

Glib::RefPtr< Gtk::ListStore > const & Inkscape::FontLister::get_style_list ( ) const
inline
Returns
the ListStore with the styles

Definition at line 162 of file font-lister.h.

References style_list_store.

Referenced by Inkscape::UI::Widget::FontSelector::FontSelector().

◆ init_default_styles()

◆ init_font_families()

◆ insert_font_family()

void Inkscape::FontLister::insert_font_family ( Glib::ustring const &  new_family)

Inserts a font family or font-fallback list (for use when not already in document or on system).

Definition at line 371 of file font-lister.cpp.

References familyNamesAreEqual(), and Inkscape::Util::EnableSingleton< FontFactory >::get().

Referenced by init_font_families().

◆ is_path_for_font()

bool Inkscape::FontLister::is_path_for_font ( Gtk::TreePath  path,
Glib::ustring  family 
)

Definition at line 1110 of file font-lister.cpp.

References familyNamesAreEqual().

◆ new_font_family()

std::pair< Glib::ustring, Glib::ustring > Inkscape::FontLister::new_font_family ( Glib::ustring const &  family,
bool  check_style = true 
)

Changes font-family, updating style list and attempting to find closest style to current_style style (if check_style is true).

New font-family and style returned. Does NOT update current_family and current_style. (For potential use in font-selector which doesn't update until "Apply" button clicked.)

Definition at line 776 of file font-lister.cpp.

References familyNamesAreEqual(), and Inkscape::Util::EnableSingleton< FontFactory >::get().

◆ selection_update()

◆ set_dragging_family()

void Inkscape::FontLister::set_dragging_family ( Glib::ustring const &  new_family)

Definition at line 840 of file font-lister.cpp.

◆ set_font_family() [1/2]

std::pair< Glib::ustring, Glib::ustring > Inkscape::FontLister::set_font_family ( Glib::ustring const &  family,
bool  check_style = true,
bool  emit = true 
)

Sets font-family, updating style list and attempting to find closest style to old current_style.

New font-family and style returned. Updates current_family and current_style. Calls new_font_family(). (For use in text-toolbar where update is immediate.)

Definition at line 845 of file font-lister.cpp.

◆ set_font_family() [2/2]

std::pair< Glib::ustring, Glib::ustring > Inkscape::FontLister::set_font_family ( int  row,
bool  check_style = true,
bool  emit = true 
)

Sets font-family from row in list store.

The row can be used to determine if we are in the document or system part of the font-family list. This is needed to handle scrolling through the font-family list correctly. Calls set_font_family().

Definition at line 872 of file font-lister.cpp.

◆ set_font_style()

void Inkscape::FontLister::set_font_style ( Glib::ustring  style,
bool  emit = true 
)

Sets style.

Does not validate style for family.

Definition at line 898 of file font-lister.cpp.

◆ set_fontspec()

void Inkscape::FontLister::set_fontspec ( Glib::ustring const &  fontspec,
bool  check = true 
)

Sets current_fontspec, etc.

If check is false, won't try to find best style match (assumes style in fontspec valid for given font-family).

Definition at line 758 of file font-lister.cpp.

Referenced by Inkscape::UI::Dialog::TextEdit::apply_changes().

◆ show_results()

◆ system_fontspec()

Glib::ustring Inkscape::FontLister::system_fontspec ( Glib::ustring const &  fontspec)

Find closest system font to given font.

Definition at line 609 of file font-lister.cpp.

References FontFactory::Face(), Inkscape::Util::EnableSingleton< FontFactory >::get(), and sp_font_description_get_family().

◆ ui_from_fontspec()

std::pair< Glib::ustring, Glib::ustring > Inkscape::FontLister::ui_from_fontspec ( Glib::ustring const &  fontspec) const

Gets font-family and style from fontspec.

font-family and style returned.

Definition at line 625 of file font-lister.cpp.

References weight.

◆ update_font_data_recursive()

void Inkscape::FontLister::update_font_data_recursive ( SPObject r,
std::map< Glib::ustring, std::set< Glib::ustring > > &  font_data 
)
private

◆ update_font_list()

void Inkscape::FontLister::update_font_list ( SPDocument document)

Updates font list to include fonts in document.

Definition at line 501 of file font-lister.cpp.

References SPDocument::getRoot(), and root.

Referenced by Inkscape::UI::Dialog::TextEdit::apply_changes(), and Inkscape::UI::Widget::FontSelector::FontSelector().

Member Data Documentation

◆ block

bool Inkscape::FontLister::block = false
private

Definition at line 362 of file font-lister.h.

Referenced by blocked().

◆ current_family

Glib::ustring Inkscape::FontLister::current_family = "sans-serif"
private

Definition at line 353 of file font-lister.h.

Referenced by get_font_family(), get_fontspec(), and get_row_for_font().

◆ current_family_row

int Inkscape::FontLister::current_family_row = 0
private

Info for currently selected font (what is shown in the UI).

May include font-family lists and fonts not on system.

Definition at line 352 of file font-lister.h.

Referenced by get_font_family_row().

◆ current_style

Glib::ustring Inkscape::FontLister::current_style = "Normal"
private

Definition at line 355 of file font-lister.h.

Referenced by get_font_style(), get_fontspec(), and get_row_for_style().

◆ default_styles

std::shared_ptr<Styles> Inkscape::FontLister::default_styles
private

If a font-family is not on system, this list of styles is used.

Definition at line 360 of file font-lister.h.

Referenced by FontLister(), and init_default_styles().

◆ dragging_family

Glib::ustring Inkscape::FontLister::dragging_family
private

Definition at line 354 of file font-lister.h.

Referenced by get_dragging_family().

◆ font_list

FontListClass Inkscape::FontLister::font_list

Definition at line 126 of file font-lister.h.

Referenced by font_lister_separator_func(), init_font_families(), and show_results().

◆ font_list_store

Glib::RefPtr<Gtk::ListStore> Inkscape::FontLister::font_list_store
private

◆ font_style_list

◆ new_fonts_signal

sigc::signal<void ()> Inkscape::FontLister::new_fonts_signal
private

Definition at line 365 of file font-lister.h.

Referenced by connectNewFonts(), and FontLister().

◆ pango_family_map

std::map<std::string, PangoFontFamily *> Inkscape::FontLister::pango_family_map

The list of fonts, sorted by the order they will appear in the UI.

Also used to give log-time access to each font's PangoFontFamily, owned by the FontFactory.

Definition at line 149 of file font-lister.h.

Referenced by font_installed_on_system(), FontLister(), get_font_families_size(), init_font_families(), and show_results().

◆ style_list_store

Glib::RefPtr<Gtk::ListStore> Inkscape::FontLister::style_list_store
private

Definition at line 346 of file font-lister.h.

Referenced by FontLister(), get_style_list(), and init_default_styles().

◆ update_signal

sigc::signal<void ()> Inkscape::FontLister::update_signal
private

Definition at line 364 of file font-lister.h.

Referenced by connectUpdate(), and init_default_styles().


The documentation for this class was generated from the following files: