20#include <gtkmm/eventcontrollerkey.h>
32#include <glibmm/i18n.h>
33#include <glibmm/markup.h>
34#include <glibmm/ustring.h>
36#include <gtkmm/builder.h>
37#include <gtkmm/button.h>
38#include <gtkmm/label.h>
39#include <gtkmm/listbox.h>
40#include <gtkmm/listboxrow.h>
41#include <gtkmm/menubutton.h>
42#include <gtkmm/notebook.h>
43#include <gtkmm/searchentry2.h>
44#include <gtkmm/separator.h>
45#include <gtkmm/textbuffer.h>
46#include <gtkmm/textview.h>
47#ifdef WITH_LIBSPELLING
50#include <sigc++/functors/mem_fun.h>
77Glib::ustring
const &getSamplePhrase()
83 static auto const samplephrase = Glib::ustring{_(
"AaBbCcIiPpQq12369$\342\202\254\302\242?.;/()")};
119 Inkscape::UI::Widget::FontList::create_font_list(
"/font-selector") :
124 auto contents = &get_widget<Gtk::Box> (
builder,
"contents");
125 auto notebook = &get_widget<Gtk::Notebook>(
builder,
"notebook");
126 auto font_box = &get_widget<Gtk::Box> (
builder,
"font_box");
127 auto feat_box = &get_widget<Gtk::Box> (
builder,
"feat_box");
129#ifdef WITH_LIBSPELLING
130 text_view = Gtk::manage(Glib::wrap(GTK_TEXT_VIEW(gtk_source_view_new())));
132 text_view = Gtk::make_managed<Gtk::TextView>();
135 text_view->property_height_request().set_value(64);
137 text_view->set_wrap_mode(Gtk::WrapMode::WORD);
138 auto &text_view_container = get_widget<Gtk::ScrolledWindow>(
builder,
"text_view_container");
139 text_view_container.set_child(*
text_view);
150 feat_box->reorder_child_after(
font_features, *feat_box->get_first_child());
157#ifdef WITH_LIBSPELLING
169 auto const key = Gtk::EventControllerKey::create();
170 key->signal_key_pressed().connect([
this, &
key = *
key](
auto&& ...args) {
return captureUndo(
key, args...); },
true);
186 int selected_count = font_collections->get_selected_collections_count();
203 unsigned keyval,
unsigned keycode, Gdk::ModifierType state)
206 if (accel->isTriggeredBy(controller, keyval, keycode, state)) {
228 auto phrase = getSamplePhrase();
233 bool has_one_item =
items == 1;
257 if (dostyle && text) {
291 int result_features =
305 Glib::ustring
const &phrase)
309 if (font_spec.empty()) {
317 const int max_lines = 4;
319 auto start_pos = phrase.find_first_not_of(
" \n\r\t");
320 if (start_pos == Glib::ustring::npos) {
324 auto end_pos = Glib::ustring::npos;
325 auto from = start_pos;
326 for (
int i = 0; i < max_lines; ++i) {
327 end_pos = phrase.find(
"\n", from);
328 if (end_pos == Glib::ustring::npos) {
break; }
331 Glib::ustring phrase_trimmed = phrase.substr(start_pos, end_pos != Glib::ustring::npos ? end_pos - start_pos : end_pos);
333 Glib::ustring font_spec_escaped = Glib::Markup::escape_text( font_spec );
334 Glib::ustring phrase_escaped = Glib::Markup::escape_text(phrase_trimmed);
341 pt_size = std::min(pt_size, 100.0);
343 auto const size = std::to_string(
static_cast<int>(pt_size * PANGO_SCALE));
345 auto font_features_attr = Glib::ustring{};
347 font_features_attr = Glib::ustring::compose(
"font_features='%1'",
font_features);
350 auto const markup = Glib::ustring::compose(
"<span font='%1' size='%2' %3>%4</span>",
351 font_spec_escaped,
size, font_features_attr,
363 for(
auto i=tmp.begin();i!=tmp.end();++i)
365 if (is<SPText>(*i) || is<SPFlowtext>(*i))
378 unsigned int items = 0;
381 for(
auto i=tmp.begin();i!=tmp.end();++i)
383 if (is<SPText>(*i) || is<SPFlowtext>(*i))
402 bool style = ((flags & (SP_OBJECT_CHILD_MODIFIED_FLAG |
403 SP_OBJECT_STYLE_MODIFIED_FLAG )) != 0 );
404 bool content = ((flags & (SP_OBJECT_CHILD_MODIFIED_FLAG |
405 SP_TEXT_CONTENT_MODIFIED_FLAG )) != 0 );
427 Glib::ustring fontspec =
font_list->get_fontspec();
429 if( !fontspec.empty() ) {
438 if (prefs->
getBool(
"/options/font/textOutputPx",
true)) {
481 for(
auto i=item_list.begin();i!=item_list.end();++i){
483 if (is<SPText>(*i) || (is<SPFlowtext>(*i)) ) {
489 prefs->
setDouble(
"/options/font/scaleLineHeightFromFontSIze", factor);
498 }
else if (
items == 1) {
501 if (is<SPText>(
item) || is<SPFlowtext>(
item)) {
513 Glib::ustring fontspec =
font_list->get_fontspec();
515 if( !fontspec.empty() ) {
521 if (continuous && recent_fonts->get_continuous_streak()) {
522 recent_fonts->pop_front();
526 recent_fonts->set_continuous_streak(continuous);
551 auto const btn = Gtk::make_managed<Gtk::CheckButton>(col);
552 btn->set_margin_bottom(2);
554 btn->signal_toggled().connect([=](){
558 auto const row = Gtk::make_managed<Gtk::ListBoxRow>();
559 row->set_focusable(
false);
560 row->set_child(*btn);
565 auto const sep = Gtk::make_managed<Gtk::Separator>();
566 sep->set_margin_bottom(2);
567 auto const sep_row = Gtk::make_managed<Gtk::ListBoxRow>();
568 sep_row->set_focusable(
false);
569 sep_row->set_child(*sep);
574 auto const btn = Gtk::make_managed<Gtk::CheckButton>(col);
575 btn->set_margin_bottom(2);
577 btn->signal_toggled().connect([=](){
581 auto const row = Gtk::make_managed<Gtk::ListBoxRow>();
582 row->set_focusable(
false);
583 row->set_child(*btn);
593 Glib::ustring fontspec =
font_list->get_fontspec();
594 if (!fontspec.empty()) {
639 if(
auto desktop = SP_ACTIVE_DESKTOP) {
641 container->new_floating_dialog(
"FontCollections");
656 Glib::ustring fontspec =
font_list->get_fontspec();
658 auto const &phrase = str.empty() ? getSamplePhrase() : str;
std::shared_ptr< FontInstance > FaceFromFontSpecification(char const *fontSpecification)
A thin wrapper around std::ostringstream, but writing floating point numbers in the format required b...
static void done(SPDocument *document, Glib::ustring const &event_description, Glib::ustring const &undo_icon, unsigned int object_modified_tag=0)
static void maybeDone(SPDocument *document, const gchar *keyconst, Glib::ustring const &event_description, Glib::ustring const &undo_icon, unsigned int object_modified_tag=0)
static FontCollections * get()
void clear_selected_collections()
void update_selected_collections(const Glib::ustring &collection_name)
bool is_collection_selected(const Glib::ustring &collection_name)
std::vector< Glib::ustring > get_collections(bool is_system=false) const
This class enumerates fonts using libnrtype into reusable data stores and allows for random access to...
std::pair< bool, std::string > get_font_count_label() const
void set_fontspec(Glib::ustring const &fontspec, bool check=true)
Sets current_fontspec, etc.
std::pair< Glib::ustring, Glib::ustring > selection_update()
Sets font-family and style after a selection change.
void update_font_list(SPDocument *document)
Updates font list to include fonts in document.
void init_default_styles()
void fill_css(SPCSSAttr *css, Glib::ustring fontspec={})
Fill css using given fontspec (doesn't need to be member function).
void init_font_families(int group_offset=-1, int group_size=-1)
int add_document_fonts_at_top(SPDocument *document)
Glib::ustring const & get_font_style() const
void show_results(Glib::ustring const &search_text)
static Inkscape::FontLister * get_instance()
Glib::ustring get_fontspec() const
sigc::connection connectUpdate(sigc::slot< void()> slot)
Let users of FontLister know to update GUI.
Glib::ustring const & get_font_family() const
SPItemRange items()
Returns a range of selected SPItems.
SPItem * singleItem()
Returns a single selected item.
Preference storage class.
bool getBool(Glib::ustring const &pref_path, bool def=false)
Retrieve a Boolean value.
static Preferences * get()
Access the singleton Preferences object.
int getInt(Glib::ustring const &pref_path, int def=0)
Retrieve an integer.
void setDouble(Glib::ustring const &pref_path, double value)
Set a floating point value.
void mergeStyle(Glib::ustring const &pref_path, SPCSSAttr *style)
Merge a CSS style with the current preference value.
static RecentlyUsedFonts * get()
The set of selected SPObjects for a given document and layer model.
DialogBase is the base class for the dialog system.
SPDesktop * getDesktop() const
Gtk::SearchEntry2 & search_entry
Glib::RefPtr< Gtk::TextBuffer > text_buffer
SPCSSAttr * fillTextStyle()
Gtk::Label & font_count_label
sigc::scoped_connection fontFeaturesChangedConn
Gtk::Button & reset_button
void on_fcm_button_clicked()
void apply_changes(bool continuous)
Gtk::Label & preview_label
Gtk::Popover & filter_popover
Gtk::Label & preview_label2
void onApply()
Callback for pressing the apply button.
Gtk::Button & apply_button
void on_search_entry_changed()
void onFontChange(Glib::ustring const &fontspec)
Callback invoked when the user modifies the font through the dialog or the tools control bar.
void change_font_count_label()
void onReadSelection(bool style, bool content)
Called whenever something 'changes' on canvas.
void display_font_collections()
Function to list the font collections in the popover menu.
Inkscape::UI::Widget::FontVariants font_features
void onChange()
Callback invoked when the user modifies the text of the selected text object.
void on_reset_button_pressed()
sigc::scoped_connection fontCollectionsChangedSelection
void onSetDefault()
Callback for pressing the default button.
SPItem * getSelectedTextItem()
Get the selected text off the main canvas.
bool captureUndo(Gtk::EventControllerKey const &controller, unsigned keyval, unsigned keycode, Gdk::ModifierType state)
This function would disable undo and redo if the text_view widget is in focus It is to fix the issue:...
Gtk::Box & settings_and_filters_box
Glib::RefPtr< Gtk::Builder > builder
void selectionModified(Selection *selection, guint flags) final
unsigned getSelectedTextCount()
Count the number of text objects in the selection on the canvas.
sigc::scoped_connection _apply_font
void selectionChanged(Selection *selection) final
void updateObjectText(SPItem *text)
Gtk::Button & collection_editor_button
Gtk::Button & setasdefault_button
sigc::scoped_connection _font_changed
void setPreviewText(Glib::ustring const &font_spec, Glib::ustring const &font_features, Glib::ustring const &phrase)
Helper function to create markup from a fontspec and display in the preview label.
void documentReplaced() final
sigc::scoped_connection fontCollectionsUpdate
Gtk::TextView * text_view
void on_page_changed(Gtk::Widget *widgt, int pos)
Gtk::ListBox & collections_list
std::unique_ptr< FontSelectorInterface > font_list
static FontFactory & get(Args &&... args)
static double convert(double from_dist, Unit const *from, Unit const *to)
Convert distances.
To do: update description of desktop.
SPDocument * getDocument() const
Inkscape::UI::Dialog::DialogContainer * getContainer()
Inkscape::Selection * getSelection() const
Typed SVG document implementation.
Base class for visual SVG elements.
void changeCSS(SPCSSAttr *css, char const *attr)
SPStyle * style
Represents the style properties, whether from presentation attributes, the style attribute,...
Inkscape::XML::Node * getRepr()
Returns the XML representation of tree.
T< SPAttr::INLINE_SIZE, SPILength > inline_size
void readFromPrefs(Glib::ustring const &path)
Read style properties from preferences.
T< SPAttr::FONT_SIZE, SPIFontSize > font_size
Size of the font.
Utilities to more easily use Gtk::EventController & subclasses like Gesture.
TODO: insert short description here.
std::shared_ptr< Css const > css
void sp_desktop_set_style(SPDesktop *desktop, SPCSSAttr *css, bool change, bool write_current, bool switch_style)
Apply style on selection on desktop.
int sp_desktop_query_style(SPDesktop *desktop, SPStyle *style, int property)
Query the subselection (if any) or selection on the given desktop for the given property,...
@ QUERY_STYLE_PROPERTY_FONTNUMBERS
@ QUERY_STYLE_PROPERTY_FONTFEATURESETTINGS
@ QUERY_STYLE_PROPERTY_FONTVARIANTS
@ QUERY_STYLE_MULTIPLE_DIFFERENT
Editable view implementation.
A widget that manages DialogNotebook's and other widgets inside a horizontal DialogMultipaned.
TODO: insert short description here.
TODO: insert short description here.
Macro for icon names used in Inkscape.
C++ wrapping for libspelling C API.
void remove_all_children(Widget &widget)
For each child in get_children(widget), call widget.remove(*child). May not cause delete child!
void set_enabled(SpellingTextBufferAdapter &adapter, bool enabled)
auto spelling_text_buffer_adapter_create(GtkSourceBuffer *buffer, SpellingChecker *checker)
auto get_menu_model(SpellingTextBufferAdapter &adapter)
W & get_widget(const Glib::RefPtr< Gtk::Builder > &builder, const char *id)
auto as_action_group(SpellingTextBufferAdapter &adapter)
void pack_start(Gtk::Box &box, Gtk::Widget &child, bool const expand, bool const fill, unsigned const padding)
Adds child to box, packed with reference to the start of box.
Glib::RefPtr< Gtk::Builder > create_builder(const char *filename)
static void append(std::vector< T > &target, std::vector< T > &&source)
static cairo_user_data_key_t key
Helpers for using Gtk::Boxes, encapsulating large changes between GTK3 & GTK4.
Singleton class to access the preferences file in a convenient way.
SPCSSAttr * sp_repr_css_attr_new()
Creates an empty SPCSSAttr (a class for manipulating CSS style properties).
void sp_repr_css_attr_unref(SPCSSAttr *css)
Unreferences an SPCSSAttr (will be garbage collected if no references remain).
void sp_repr_css_unset_property(SPCSSAttr *css, gchar const *name)
Set a style property to "inkscape:unset".
void sp_repr_css_set_property(SPCSSAttr *css, gchar const *name, gchar const *value)
Set a style property to a new value (e.g.
TODO: insert short description here.
static const unsigned SP_STYLE_FLAG_IFSET(1<< 0)
double sp_style_css_size_px_to_units(double size, int unit, double font_size)
double sp_style_css_size_units_to_px(double size, int unit, double font_size)
SPCSSAttr * sp_css_attr_from_style(SPStyle const *const style, guint const flags)
gchar const * sp_style_get_css_unit_string(int unit)
SPStyle - a style object for SPItem objects.
Glib::ustring sp_te_get_string_multiline(SPItem const *text)
Gets a text-only representation of the given text or flowroot object, replacing line break elements w...
void sp_te_set_repr_text_multiline(SPItem *text, gchar const *str)
Glib::RefPtr< Gtk::Builder > builder