=== modified file 'src/libnrtype/font-lister.cpp'
--- src/libnrtype/font-lister.cpp 2015-05-09 15:39:31 +0000
+++ src/libnrtype/font-lister.cpp 2015-11-08 10:18:34 +0000
@@ -4,7 +4,7 @@
#include <gtkmm/liststore.h>
#include <gtkmm/treemodel.h>
-
+#include "libnrtype/FontFactory.h"
#include <libnrtype/font-instance.h>
#include <libnrtype/TextWrapper.h>
#include <libnrtype/one-glyph.h>
@@ -59,8 +59,8 @@
// Get sorted font families from Pango
std::vector<PangoFontFamily *> familyVector;
+
font_factory::Default()->GetUIFamilies(familyVector);
-
// Traverse through the family names and set up the list store
for (size_t i = 0; i < familyVector.size(); ++i) {
const char* displayName = sp_font_family_get_name(familyVector[i]);
@@ -122,10 +122,21 @@
++iter;
}
}
-
-FontLister *FontLister::get_instance()
+//Añadimos un parametro a la función para que refresque/actualize la variable estatica (+- global) de la instancia de font lister
+//Si no durante el transcurso de Inkscape, FontLister seria siempre igual
+FontLister *FontLister::get_instance(bool refresh)
{
static Inkscape::FontLister *instance = new Inkscape::FontLister();
+ if(refresh){
+ //la sifuiente linea provoca que cuando llamemos despues a el constructor de
+ //font lister, este llame a font_factory::Default() generando un nuevo fontfactory
+ //con las nuevas fuentes. Estudiatelo para entender como funciona, tienes que seguir el hilo de los procesos
+ font_factory::lUsine = NULL;
+ //Creamos un nuevo valor de retorno para la variable instance
+ //que se queda guardado globalmente, asi que solo hay que llamar a get_instance(true) cuando
+ //queramos refrescar la lista de fuentes
+ instance = new Inkscape::FontLister();
+ }
return instance;
}
=== modified file 'src/libnrtype/font-lister.h'
--- src/libnrtype/font-lister.h 2014-10-17 20:03:14 +0000
+++ src/libnrtype/font-lister.h 2015-11-08 10:18:34 +0000
@@ -150,7 +150,12 @@
void update_font_list(SPDocument *document);
public:
- static Inkscape::FontLister *get_instance();
+ //a la cabecera de la función le hemos puesto un valor por defecto que en este caso
+ //hace que se pueda llamar a la función oviandolo, tal y como hacia inksape antes, es decir
+ //puedes llamarlo como originalmente get_instance() y actual normal, dandole el valor a refresh = false
+ //o puedes llamarlo get_instance(true)
+ //esto nos permite modificar la función y no tener que modificar todas las llamadas a esta dentro de inkscape
+ static Inkscape::FontLister *get_instance(bool refresh = false);
/**
* Takes a hand written font spec and returns a Pango generated one in
=== modified file 'src/ui/dialog/text-edit.h'
--- src/ui/dialog/text-edit.h 2015-06-25 11:46:43 +0000
+++ src/ui/dialog/text-edit.h 2015-11-08 10:18:34 +0000
@@ -56,7 +56,6 @@
public:
TextEdit();
virtual ~TextEdit();
-
/**
* Helper function which returns a new instance of the dialog.
* getInstance is needed by the dialog manager (Inkscape::UI::Dialog::DialogManager).
=== modified file 'src/widgets/font-selector.cpp'
--- src/widgets/font-selector.cpp 2014-10-17 20:03:14 +0000
+++ src/widgets/font-selector.cpp 2015-11-08 10:27:46 +0000
@@ -27,7 +27,7 @@
#include <gtk/gtk.h>
#include <glibmm/i18n.h>
-
+#include "inkscape.h"
#include "desktop.h"
#include "widgets/font-selector.h"
#include "preferences.h"
@@ -121,6 +121,30 @@
gtk_widget_set_tooltip_text (fsel->size, _(tooltip.c_str()));
}
+static void sp_gtk_fontconfig_timestamp_changed(SPFontSelector * fsel)
+{
+ //Creamos una instancia de fonlister con overwrite a true, lo explico en otro lado
+ Inkscape::FontLister* fontlister = Inkscape::FontLister::get_instance(true);
+ //Generamos el nuevo tree model con las todas, incluidas las nuevas tipografias
+ fontlister->update_font_list( SP_ACTIVE_DESKTOP->getDocument());
+ Glib::RefPtr<Gtk::ListStore> store = fontlister->get_font_list();
+ GtkListStore* model = store->gobj();
+ //actualizamos el model de la clase contenedora
+ gtk_tree_view_set_model(GTK_TREE_VIEW(fsel->family_treeview), GTK_TREE_MODEL(model));
+ gtk_tree_view_set_row_separator_func( GTK_TREE_VIEW(fsel->family_treeview),
+ GtkTreeViewRowSeparatorFunc ((gpointer)font_lister_separator_func),
+ NULL, NULL );
+ gtk_widget_show_all(GTK_WIDGET (fsel->family_treeview));
+ GtkTreeViewColumn *column = gtk_tree_view_column_new ();
+ GtkCellRenderer *cell = gtk_cell_renderer_text_new ();
+ gtk_tree_view_column_pack_start (column, cell, FALSE);
+ gtk_tree_view_column_set_attributes (column, cell, "text", 0, NULL);
+ gtk_tree_view_column_set_cell_data_func (column, cell,
+ GtkTreeCellDataFunc (font_lister_cell_data_func),
+ NULL, NULL );
+ gtk_tree_view_append_column (GTK_TREE_VIEW(fsel->family_treeview), column);
+ gtk_tree_view_set_headers_visible (GTK_TREE_VIEW(fsel->family_treeview), FALSE);
+}
/*
* Create a widget with children for selecting font-family, font-style, and font-size.
@@ -174,6 +198,9 @@
g_signal_connect (G_OBJECT(selection), "changed", G_CALLBACK (sp_font_selector_family_select_row), fsel);
g_object_set_data (G_OBJECT(fsel), "family-treeview", fsel->family_treeview);
+ //font update
+ GtkSettings *settings = gtk_widget_get_settings(fsel->family_treeview);
+ g_signal_connect_object (settings, "notify::gtk-fontconfig-timestamp", G_CALLBACK (sp_gtk_fontconfig_timestamp_changed), fsel, G_CONNECT_SWAPPED);
/* Style frame */
f = gtk_frame_new(C_("Font selector", "Style"));
@@ -220,6 +247,7 @@
selection = gtk_tree_view_get_selection (GTK_TREE_VIEW(fsel->style_treeview));
g_signal_connect (G_OBJECT(selection), "changed", G_CALLBACK (sp_font_selector_style_select_row), fsel);
+
#if GTK_CHECK_VERSION(3,0,0)
GtkWidget *hb = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 4);
gtk_box_set_homogeneous(GTK_BOX(hb), FALSE);
=== modified file 'src/widgets/text-toolbar.cpp'
--- src/widgets/text-toolbar.cpp 2015-04-29 20:51:23 +0000
+++ src/widgets/text-toolbar.cpp 2015-11-08 11:02:20 +0000
@@ -29,7 +29,6 @@
#endif
#include "libnrtype/font-lister.h"
-#include <glibmm/i18n.h>
#include "text-toolbar.h"
#include "desktop-style.h"
@@ -56,6 +55,7 @@
#include "ui/tools/tool-base.h"
#include "verbs.h"
#include "xml/repr.h"
+#include <glibmm/i18n.h>
using Inkscape::DocumentUndo;
using Inkscape::UI::ToolboxFactory;
@@ -113,6 +113,25 @@
}
#endif
+//Función de callback
+//Refresca la lista de fuentes
+static void sp_refresh_combobox(GtkSettings *settings, Ink_ComboBoxEntry_Action *act)
+{
+ std::cout << "refresh\n";
+ //Conseguimos el widget del combo de fuentes
+ GtkComboBox *fontCombo = act->combobox;
+ //Creamos una instancia de fonlister con overwrite a true, lo explico en otro lado
+ Inkscape::FontLister* fontlister = Inkscape::FontLister::get_instance(true);
+ //Generamos el nuevo tree model con las todas, incluidas las nuevas tipografias
+ fontlister->update_font_list( SP_ACTIVE_DESKTOP->getDocument());
+ Glib::RefPtr<Gtk::ListStore> store = fontlister->get_font_list();
+ GtkListStore* model = store->gobj();
+ //actualizamos el model de la clase contenedora
+ act->model = GTK_TREE_MODEL(model);
+ //actualizamos el combo con el nuevo modelo
+ gtk_combo_box_set_model(fontCombo, GTK_TREE_MODEL(model));
+ gtk_combo_box_set_active( fontCombo, fontlister->get_font_family_row());
+}
// Font family
static void sp_text_fontfamily_value_changed( Ink_ComboBoxEntry_Action *act, GObject *tbl )
@@ -122,7 +141,6 @@
std::cout << "MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM" << std::endl;
std::cout << "sp_text_fontfamily_value_changed: " << std::endl;
#endif
-
// quit if run by the _changed callbacks
if (g_object_get_data(G_OBJECT(tbl), "freeze")) {
#ifdef DEBUG_TEXT
@@ -1235,9 +1253,9 @@
//ink_comboboxentry_action_set_warning_callback( act, sp_text_fontfamily_select_all );
ink_comboboxentry_action_set_altx_name( act, "altx-text" ); // Set Alt-X keyboard shortcut
g_signal_connect( G_OBJECT(act), "changed", G_CALLBACK(sp_text_fontfamily_value_changed), holder );
+
gtk_action_group_add_action( mainActions, GTK_ACTION(act) );
- g_object_set_data( holder, "TextFontFamilyAction", act );
-
+ g_object_set_data( holder, "TextFontFamilyAction", act );
// Change style of drop-down from menu to list
gtk_rc_parse_string (
"style \"dropdown-as-list-style\"\n"
@@ -1251,6 +1269,8 @@
" GtkWidget::separator-height = 6\n"
"}\n"
"widget \"*gtk-combobox-popup-window.GtkScrolledWindow.GtkTreeView\" style \"fontfamily-separator-style\"");
+ GtkSettings *settings = gtk_widget_get_settings(GTK_WIDGET(act->combobox));
+ g_signal_connect_object (settings, "notify::gtk-fontconfig-timestamp", G_CALLBACK (sp_refresh_combobox), act, G_CONNECT_SWAPPED);
}
/* Font size */
-
Per favore accedi per lasciare un commento!