[sushi] Sync sushi-font-widget/sushi-font-loader



commit 2769d67ded8d44c8d4ce61fbc73e9aca5ad4f81e
Author: Cosimo Cecchi <cosimoc gnome org>
Date:   Mon Sep 3 17:53:41 2018 -0700

    Sync sushi-font-widget/sushi-font-loader
    
    From gnome-font-viewer, which got support to load multiple faces
    from a file.
    
    Credit for these changes to Peng Wu <alexepico gmail com>.

 flatpak/org.gnome.NautilusPreviewer.json |  2 +-
 src/libsushi/sushi-font-loader.c         |  9 ++++---
 src/libsushi/sushi-font-loader.h         |  2 ++
 src/libsushi/sushi-font-widget.c         | 46 +++++++++++++++++++++-----------
 src/libsushi/sushi-font-widget.h         |  4 ++-
 5 files changed, 43 insertions(+), 20 deletions(-)
---
diff --git a/flatpak/org.gnome.NautilusPreviewer.json b/flatpak/org.gnome.NautilusPreviewer.json
index 0dac3ea..d507465 100644
--- a/flatpak/org.gnome.NautilusPreviewer.json
+++ b/flatpak/org.gnome.NautilusPreviewer.json
@@ -112,7 +112,7 @@
             "sources": [
                 {
                     "type": "git",
-                    "url": "https://gitlab.gnome.org/GNOME/sushi.git";
+                    "url": ".."
                 }
             ]
         }
diff --git a/src/libsushi/sushi-font-loader.c b/src/libsushi/sushi-font-loader.c
index b927e3f..c612b41 100644
--- a/src/libsushi/sushi-font-loader.c
+++ b/src/libsushi/sushi-font-loader.c
@@ -43,13 +43,14 @@ typedef struct {
 static FontLoadJob *
 font_load_job_new (FT_Library library,
                    const gchar *uri,
+                   gint face_index,
                    GAsyncReadyCallback callback,
                    gpointer user_data)
 {
   FontLoadJob *job = g_slice_new0 (FontLoadJob);
 
   job->library = library;
-  job->face_index = 0;
+  job->face_index = (FT_Long) face_index;
   job->file = g_file_new_for_uri (uri);
 
   return job;
@@ -132,13 +133,14 @@ font_load_job (GTask *task,
 FT_Face
 sushi_new_ft_face_from_uri (FT_Library library,
                             const gchar *uri,
+                            gint face_index,
                             gchar **contents,
                             GError **error)
 {
   FontLoadJob *job = NULL;
   FT_Face face;
 
-  job = font_load_job_new (library, uri, NULL, NULL);
+  job = font_load_job_new (library, uri, face_index, NULL, NULL);
   font_load_job_do_load (job, error);
 
   if ((error != NULL) && (*error != NULL)) {
@@ -159,10 +161,11 @@ sushi_new_ft_face_from_uri (FT_Library library,
 void
 sushi_new_ft_face_from_uri_async (FT_Library library,
                                   const gchar *uri,
+                                  gint face_index,
                                   GAsyncReadyCallback callback,
                                   gpointer user_data)
 {
-  FontLoadJob *job = font_load_job_new (library, uri, callback, user_data);
+  FontLoadJob *job = font_load_job_new (library, uri, face_index, callback, user_data);
   GTask *task;
 
   task = g_task_new (NULL, NULL, callback, user_data);
diff --git a/src/libsushi/sushi-font-loader.h b/src/libsushi/sushi-font-loader.h
index 8a9df04..82aab03 100644
--- a/src/libsushi/sushi-font-loader.h
+++ b/src/libsushi/sushi-font-loader.h
@@ -32,11 +32,13 @@
 
 FT_Face sushi_new_ft_face_from_uri (FT_Library library,
                                     const gchar *uri,
+                                    gint face_index,
                                     gchar **contents,
                                     GError **error);
 
 void sushi_new_ft_face_from_uri_async (FT_Library library,
                                        const gchar *uri,
+                                       gint face_index,
                                        GAsyncReadyCallback callback,
                                        gpointer user_data);
 
diff --git a/src/libsushi/sushi-font-widget.c b/src/libsushi/sushi-font-widget.c
index 59313a8..104cf53 100644
--- a/src/libsushi/sushi-font-widget.c
+++ b/src/libsushi/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,25 +681,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,
+                                    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)
 {
@@ -728,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;
@@ -744,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);
@@ -776,6 +775,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)
 {
@@ -785,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;
@@ -793,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",
@@ -815,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/libsushi/sushi-font-widget.h b/src/libsushi/sushi-font-widget.h
index 0e3c972..9f1bac1 100644
--- a/src/libsushi/sushi-font-widget.h
+++ b/src/libsushi/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]