From 35f3012334a832a83878bfee21ec4324d2662def Mon Sep 17 00:00:00 2001 From: raveit65 Date: Wed, 8 Mar 2017 13:41:05 +0100 Subject: font-viewer: sushi-font-widget: Add face_index argument sushi_font_widget_new() now takes face index as the second argument. All callers changed. The face index of the widget can be accessed through the "face-index" property. Setting the "uri" property with g_object_set() no longer starts font loading, while it does when it is set through the constructor. This is to prevent the same font from being loaded twice, when both "uri" and "face-index" are set with g_object_set(). To start loading, you can explicitly call sushi_font_widget_load() after setting the properties. https://bugzilla.gnome.org/show_bug.cgi?id=752005 taken from: https://git.gnome.org/browse/gnome-font-viewer/commit/?id=3c48f73 --- font-viewer/font-view.c | 5 +++-- font-viewer/sushi-font-widget.c | 47 +++++++++++++++++++++++++++-------------- font-viewer/sushi-font-widget.h | 4 +++- 3 files changed, 37 insertions(+), 19 deletions(-) (limited to 'font-viewer') diff --git a/font-viewer/font-view.c b/font-viewer/font-view.c index c08eff1e..aab821b3 100644 --- a/font-viewer/font-view.c +++ b/font-viewer/font-view.c @@ -526,7 +526,7 @@ font_view_application_do_open (FontViewApplication *self, GdkRGBA black = { 0.0, 0.0, 0.0, 1.0 }; GtkWidget *w; - self->font_widget = GTK_WIDGET (sushi_font_widget_new (uri)); + self->font_widget = GTK_WIDGET (sushi_font_widget_new (uri, 0)); gtk_widget_override_color (self->font_widget, GTK_STATE_NORMAL, &black); gtk_widget_override_background_color (self->font_widget, GTK_STATE_FLAG_NORMAL, &white); @@ -542,7 +542,8 @@ font_view_application_do_open (FontViewApplication *self, g_signal_connect (self->font_widget, "error", G_CALLBACK (font_widget_error_cb), self); } else { - g_object_set (self->font_widget, "uri", uri, NULL); + g_object_set (self->font_widget, "uri", uri, "face-index", 0, NULL); + sushi_font_widget_load (SUSHI_FONT_WIDGET (self->font_widget)); } g_free (uri); diff --git a/font-viewer/sushi-font-widget.c b/font-viewer/sushi-font-widget.c index e4c18f28..ef778579 100644 --- a/font-viewer/sushi-font-widget.c +++ b/font-viewer/sushi-font-widget.c @@ -32,6 +32,7 @@ enum { PROP_URI = 1, + PROP_FACE_INDEX, NUM_PROPERTIES }; @@ -43,6 +44,7 @@ enum { struct _SushiFontWidgetPrivate { gchar *uri; + gint face_index; FT_Library library; FT_Face face; @@ -569,26 +571,16 @@ font_face_async_ready_cb (GObject *object, g_signal_emit (self, signals[LOADED], 0); } -static void -load_font_face (SushiFontWidget *self) +void +sushi_font_widget_load (SushiFontWidget *self) { sushi_new_ft_face_from_uri_async (self->priv->library, self->priv->uri, - 0, + self->priv->face_index, font_face_async_ready_cb, self); } -static void -sushi_font_widget_set_uri (SushiFontWidget *self, - const gchar *uri) -{ - g_free (self->priv->uri); - self->priv->uri = g_strdup (uri); - - load_font_face (self); -} - static void sushi_font_widget_init (SushiFontWidget *self) { @@ -619,6 +611,9 @@ sushi_font_widget_get_property (GObject *object, case PROP_URI: g_value_set_string (value, self->priv->uri); break; + case PROP_FACE_INDEX: + g_value_set_int (value, self->priv->face_index); + break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); break; @@ -635,7 +630,10 @@ sushi_font_widget_set_property (GObject *object, switch (prop_id) { case PROP_URI: - sushi_font_widget_set_uri (self, g_value_get_string (value)); + self->priv->uri = g_value_dup_string (value); + break; + case PROP_FACE_INDEX: + self->priv->face_index = g_value_get_int (value); break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); @@ -667,6 +665,16 @@ sushi_font_widget_finalize (GObject *object) G_OBJECT_CLASS (sushi_font_widget_parent_class)->finalize (object); } +static void +sushi_font_widget_constructed (GObject *object) +{ + SushiFontWidget *self = SUSHI_FONT_WIDGET (object); + + sushi_font_widget_load (self); + + G_OBJECT_CLASS (sushi_font_widget_parent_class)->constructed (object); +} + static void sushi_font_widget_class_init (SushiFontWidgetClass *klass) { @@ -676,6 +684,7 @@ sushi_font_widget_class_init (SushiFontWidgetClass *klass) oclass->finalize = sushi_font_widget_finalize; oclass->set_property = sushi_font_widget_set_property; oclass->get_property = sushi_font_widget_get_property; + oclass->constructed = sushi_font_widget_constructed; wclass->draw = sushi_font_widget_draw; wclass->get_preferred_width = sushi_font_widget_get_preferred_width; @@ -684,7 +693,12 @@ sushi_font_widget_class_init (SushiFontWidgetClass *klass) properties[PROP_URI] = g_param_spec_string ("uri", "Uri", "Uri", - NULL, G_PARAM_READWRITE); + NULL, G_PARAM_READWRITE | G_PARAM_CONSTRUCT); + properties[PROP_FACE_INDEX] = + g_param_spec_int ("face-index", + "Face index", "Face index", + 0, G_MAXINT, + 0, G_PARAM_READWRITE | G_PARAM_CONSTRUCT); signals[LOADED] = g_signal_new ("loaded", @@ -706,10 +720,11 @@ sushi_font_widget_class_init (SushiFontWidgetClass *klass) } SushiFontWidget * -sushi_font_widget_new (const gchar *uri) +sushi_font_widget_new (const gchar *uri, gint face_index) { return g_object_new (SUSHI_TYPE_FONT_WIDGET, "uri", uri, + "face-index", face_index, NULL); } diff --git a/font-viewer/sushi-font-widget.h b/font-viewer/sushi-font-widget.h index 28b8f727..e794b871 100644 --- a/font-viewer/sushi-font-widget.h +++ b/font-viewer/sushi-font-widget.h @@ -59,12 +59,14 @@ struct _SushiFontWidgetClass GType sushi_font_widget_get_type (void) G_GNUC_CONST; -SushiFontWidget *sushi_font_widget_new (const gchar *uri); +SushiFontWidget *sushi_font_widget_new (const gchar *uri, gint face_index); FT_Face sushi_font_widget_get_ft_face (SushiFontWidget *self); const gchar *sushi_font_widget_get_uri (SushiFontWidget *self); +void sushi_font_widget_load (SushiFontWidget *self); + G_END_DECLS #endif /* __SUSHI_FONT_WIDGET_H__ */ -- cgit v1.2.1