[gnome-font-viewer] sushi-font-widget: Add face_index argument



commit 3c48f73d62ab3138ceac6e930d2fbced6dacd481
Author: Peng Wu <alexepico gmail com>
Date:   Mon Jan 25 17:41:11 2016 +0900

    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

 src/font-view.c         |    5 +++--
 src/sushi-font-widget.c |   47 +++++++++++++++++++++++++++++++----------------
 src/sushi-font-widget.h |    4 +++-
 3 files changed, 37 insertions(+), 19 deletions(-)
---
diff --git a/src/font-view.c b/src/font-view.c
index 0cffae7..a150330 100644
--- a/src/font-view.c
+++ b/src/font-view.c
@@ -589,7 +589,7 @@ font_view_application_do_open (FontViewApplication *self,
     uri = g_file_get_uri (file);
 
     if (self->font_widget == NULL) {
-        self->font_widget = GTK_WIDGET (sushi_font_widget_new (uri));
+        self->font_widget = GTK_WIDGET (sushi_font_widget_new (uri, 0));
         gtk_container_add (GTK_CONTAINER (self->swin_preview), self->font_widget);
 
         g_signal_connect (self->font_widget, "loaded",
@@ -597,7 +597,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/src/sushi-font-widget.c b/src/sushi-font-widget.c
index 8f00ff7..104cf53 100644
--- a/src/sushi-font-widget.c
+++ b/src/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;
@@ -679,27 +681,17 @@ 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)
 {
   FT_Error err;
@@ -729,6 +721,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;
@@ -745,7 +740,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);
@@ -778,6 +776,16 @@ sushi_font_widget_finalize (GObject *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)
 {
   GObjectClass *oclass = G_OBJECT_CLASS (klass);
@@ -786,6 +794,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;
@@ -794,7 +803,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",
@@ -816,10 +830,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/src/sushi-font-widget.h b/src/sushi-font-widget.h
index 0e3c972..9f1bac1 100644
--- a/src/sushi-font-widget.h
+++ b/src/sushi-font-widget.h
@@ -58,12 +58,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__ */


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]