summaryrefslogtreecommitdiff
path: root/font-viewer/font-view.c
diff options
context:
space:
mode:
authorraveit65 <[email protected]>2017-01-08 17:50:33 +0100
committerraveit65 <[email protected]>2017-02-17 12:28:22 +0100
commit2b9497eb135e91d101e330b6407ebcff3f5a3798 (patch)
treeef2933c4f1eb4e5ffca4c175a4625316ad057546 /font-viewer/font-view.c
parent818bcecc7ce816f5ec273f88d4bbc92d303cfbc0 (diff)
downloadmate-control-center-2b9497eb135e91d101e330b6407ebcff3f5a3798.tar.bz2
mate-control-center-2b9497eb135e91d101e330b6407ebcff3f5a3798.tar.xz
Fontviewer: don't recreate a different SushiFontWidget every time
Creating one initializes a FreeType library object, so it's not cheap. It's better to just change the URI on the existing widget, like Sushi does, if possible. taken from: https://git.gnome.org/browse/gnome-font-viewer/commit/?id=39a188f
Diffstat (limited to 'font-viewer/font-view.c')
-rw-r--r--font-viewer/font-view.c37
1 files changed, 19 insertions, 18 deletions
diff --git a/font-viewer/font-view.c b/font-viewer/font-view.c
index 4457fe16..f789bf2e 100644
--- a/font-viewer/font-view.c
+++ b/font-viewer/font-view.c
@@ -388,14 +388,6 @@ static void
font_view_application_do_open (FontViewApplication *self)
{
gchar *uri;
- GtkWidget *font_widget;
- GdkRGBA white = { 1.0, 1.0, 1.0, 1.0 };
- GdkRGBA black = { 0.0, 0.0, 0.0, 1.0 };
- GtkWidget *w;
-
- w = gtk_bin_get_child (GTK_BIN (self->swin_preview));
- if (w)
- gtk_widget_destroy (w);
self->info_button = gd_main_toolbar_add_button (GD_MAIN_TOOLBAR (self->toolbar),
NULL, _("Info"),
@@ -420,20 +412,29 @@ font_view_application_do_open (FontViewApplication *self)
gtk_widget_set_vexpand (self->toolbar, FALSE);
uri = g_file_get_uri (self->font_file);
- self->font_widget = font_widget = GTK_WIDGET (sushi_font_widget_new (uri));
+ if (self->font_widget == NULL) {
+ GdkRGBA white = { 1.0, 1.0, 1.0, 1.0 };
+ GdkRGBA black = { 0.0, 0.0, 0.0, 1.0 };
+ GtkWidget *w;
- gtk_widget_override_color (font_widget, GTK_STATE_NORMAL, &black);
- gtk_widget_override_background_color (font_widget, GTK_STATE_FLAG_NORMAL, &white);
- g_free (uri);
+ self->font_widget = GTK_WIDGET (sushi_font_widget_new (uri));
+
+ gtk_widget_override_color (self->font_widget, GTK_STATE_NORMAL, &black);
+ gtk_widget_override_background_color (self->font_widget, GTK_STATE_FLAG_NORMAL, &white);
- w = gtk_viewport_new (NULL, NULL);
- gtk_viewport_set_shadow_type (GTK_VIEWPORT (w), GTK_SHADOW_NONE);
+ w = gtk_viewport_new (NULL, NULL);
+ gtk_viewport_set_shadow_type (GTK_VIEWPORT (w), GTK_SHADOW_NONE);
- gtk_container_add (GTK_CONTAINER (w), font_widget);
- gtk_container_add (GTK_CONTAINER (self->swin_preview), w);
+ gtk_container_add (GTK_CONTAINER (w), self->font_widget);
+ gtk_container_add (GTK_CONTAINER (self->swin_preview), w);
- g_signal_connect (font_widget, "loaded",
- G_CALLBACK (font_widget_loaded_cb), self);
+ g_signal_connect (self->font_widget, "loaded",
+ G_CALLBACK (font_widget_loaded_cb), self);
+ } else {
+ g_object_set (self->font_widget, "uri", uri, NULL);
+ }
+
+ g_free (uri);
gtk_widget_show_all (self->swin_preview);
gtk_notebook_set_current_page (GTK_NOTEBOOK (self->notebook), 1);