Репозиторий Sisyphus
Последнее обновление: 1 октября 2023 | Пакетов: 18631 | Посещений: 37401406
en ru br
Репозитории ALT

Группа :: Graphical desktop/MATE
Пакет: mate-control-center

 Главная   Изменения   Спек   Патчи   Sources   Загрузить   Gear   Bugs and FR  Repocop 

Патч: mate-control-center_fv-font-model-add-API-to-get-an-iter-from-a-FT_Face.patch
Скачать


diff -uprN mate-control-center/font-viewer/font-model.c mate-control-center-test/font-viewer/font-model.c
--- mate-control-center/font-viewer/font-model.c	2015-08-24 17:53:12.388481000 +0200
+++ mate-control-center-test/font-viewer/font-model.c	2015-08-24 18:45:58.312862548 +0200
@@ -39,6 +39,7 @@
 #include <libmate-desktop/mate-desktop-thumbnail.h>
 
 #include "font-model.h"
+#include "font-utils.h"
 #include "sushi-font-loader.h"
 
 struct _FontViewModelPrivate {
@@ -150,6 +151,7 @@ gd_queue_thumbnail_job_for_file_finish (
 
 typedef struct {
     const gchar *file;
+    FT_Face face;
     GtkTreeIter iter;
     gboolean found;
 } IterForFileData;
@@ -161,15 +163,24 @@ iter_for_file_foreach (GtkTreeModel *mod
                        gpointer user_data)
 {
     IterForFileData *data = user_data;
-    gchar *font_path;
+    gchar *font_path, *font_name, *match_name;
     gboolean retval;
 
     gtk_tree_model_get (GTK_TREE_MODEL (model), iter,
+                        COLUMN_NAME, &font_name,
                         COLUMN_PATH, &font_path,
                         -1);
 
-    retval = (g_strcmp0 (font_path, data->file) == 0);
+    if (data->file) {
+        retval = (g_strcmp0 (font_path, data->file) == 0);
+    } else if (data->face) {
+        match_name = font_utils_get_font_name (data->face);
+        retval = (g_strcmp0 (font_name, match_name) == 0);
+        g_free (match_name);
+    }
+
     g_free (font_path);
+    g_free (font_name);
 
     if (retval) {
         data->iter = *iter;
@@ -179,15 +190,17 @@ iter_for_file_foreach (GtkTreeModel *mod
     return retval;
 }
 
-gboolean
-font_view_model_get_iter_for_file (FontViewModel *self,
+static gboolean
+font_view_model_get_iter_internal (FontViewModel *self,
                                    const gchar *file,
+                                   FT_Face face,
                                    GtkTreeIter *iter)
 {
     IterForFileData *data = g_slice_new0 (IterForFileData);
     gboolean found;
 
     data->file = file;
+    data->face = face;
     data->found = FALSE;
 
     gtk_tree_model_foreach (GTK_TREE_MODEL (self),
@@ -203,6 +216,24 @@ font_view_model_get_iter_for_file (FontV
     return found;
 }
 
+gboolean
+font_view_model_get_iter_for_file (FontViewModel *self,
+                                   const gchar *file,
+                                   GtkTreeIter *iter)
+{
+    return font_view_model_get_iter_internal
+        (self, file, NULL, iter);
+}
+
+gboolean
+font_view_model_get_iter_for_face (FontViewModel *self,
+                                   FT_Face face,
+                                   GtkTreeIter *iter)
+{
+    return font_view_model_get_iter_internal
+        (self, NULL, face, iter);
+}
+
 typedef struct {
     FontViewModel *self;
     gchar *font_path;
@@ -348,37 +379,6 @@ ensure_thumbnail (FontViewModel *self,
     g_clear_object (&info);
 }
 
-static gchar *
-get_font_name (FontViewModel *self,
-               const gchar *path)
-{
-    GFile *file;
-    gchar *uri, *contents = NULL, *name = NULL;
-    GError *error = NULL;
-    FT_Face face;
-
-    file = g_file_new_for_path (path);
-    uri = g_file_get_uri (file);
-
-    face = sushi_new_ft_face_from_uri (self->priv->library, uri, &contents, &error);
-    if (face != NULL) {
-        if (g_strcmp0 (face->style_name, "Regular") == 0)
-            name = g_strdup (face->family_name);
-        else
-            name = g_strconcat (face->family_name, ", ", face->style_name, NULL);
-        FT_Done_Face (face);
-    } else if (error != NULL) {
-        g_warning ("Can't get font name: %s\n", error->message);
-        g_error_free (error);
-    }
-
-    g_free (uri);
-    g_object_unref (file);
-    g_free (contents);
-
-    return name;
-}
-
 /* make sure the font list is valid */
 static void
 ensure_font_list (FontViewModel *self)
@@ -414,7 +414,7 @@ ensure_font_list (FontViewModel *self)
 
     for (i = 0; i < self->priv->font_list->nfont; i++) {
 	FcPatternGetString (self->priv->font_list->fonts[i], FC_FILE, 0, &file);
-        font_name = get_font_name (self, (const gchar *) file);
+        font_name = font_utils_get_font_name_for_file (self->priv->library, (const gchar *) file);
 
         gtk_list_store_append (GTK_LIST_STORE (self), &iter);
         gtk_list_store_set (GTK_LIST_STORE (self), &iter,
diff -uprN mate-control-center/font-viewer/font-model.h mate-control-center-test/font-viewer/font-model.h
--- mate-control-center/font-viewer/font-model.h	2015-08-23 21:04:46.918416311 +0200
+++ mate-control-center-test/font-viewer/font-model.h	2015-08-24 18:46:42.026322392 +0200
@@ -60,6 +60,9 @@ GtkTreeModel * font_view_model_new (void
 gboolean font_view_model_get_iter_for_file (FontViewModel *self,
                                             const gchar *file,
                                             GtkTreeIter *iter);
+gboolean font_view_model_get_iter_for_face (FontViewModel *self,
+                                            FT_Face face,
+                                            GtkTreeIter *iter);
 
 G_END_DECLS
 
diff -uprN mate-control-center/font-viewer/font-utils.c mate-control-center-test/font-viewer/font-utils.c
--- mate-control-center/font-viewer/font-utils.c	1970-01-01 01:00:00.000000000 +0100
+++ mate-control-center-test/font-viewer/font-utils.c	2015-08-24 18:48:00.119143888 +0200
@@ -0,0 +1,65 @@
+/* -*- mode: C; c-basic-offset: 4 -*-
+ * mate-font-viewer:
+ *
+ * Copyright (C) 2012 Cosimo Cecchi <cosimoc@gnome.org>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+#include "font-utils.h"
+
+#include "sushi-font-loader.h"
+
+gchar *
+font_utils_get_font_name (FT_Face face)
+{
+  gchar *name;
+
+  if (g_strcmp0 (face->style_name, "Regular") == 0)
+    name = g_strdup (face->family_name);
+  else
+    name = g_strconcat (face->family_name, ", ", face->style_name, NULL);
+
+  return name;
+}
+
+gchar *
+font_utils_get_font_name_for_file (FT_Library library,
+                                   const gchar *path)
+{
+    GFile *file;
+    gchar *uri, *contents = NULL, *name = NULL;
+    GError *error = NULL;
+    FT_Face face;
+
+    file = g_file_new_for_path (path);
+    uri = g_file_get_uri (file);
+
+    face = sushi_new_ft_face_from_uri (library, uri, &contents, &error);
+    if (face != NULL) {
+        name = font_utils_get_font_name (face);
+        FT_Done_Face (face);
+    } else if (error != NULL) {
+        g_warning ("Can't get font name: %s\n", error->message);
+        g_error_free (error);
+    }
+
+    g_free (uri);
+    g_object_unref (file);
+    g_free (contents);
+
+    return name;
+}
+
diff -uprN mate-control-center/font-viewer/font-utils.h mate-control-center-test/font-viewer/font-utils.h
--- mate-control-center/font-viewer/font-utils.h	1970-01-01 01:00:00.000000000 +0100
+++ mate-control-center-test/font-viewer/font-utils.h	2015-08-24 18:49:00.685781018 +0200
@@ -0,0 +1,33 @@
+/* -*- mode: C; c-basic-offset: 4 -*-
+ * mate-font-viewer:
+ *
+ * Copyright (C) 2012 Cosimo Cecchi <cosimoc@gnome.org>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+#ifndef __FONT_UTILS_H__
+#define __FONT_UTILS_H__
+
+#include <ft2build.h>
+#include FT_FREETYPE_H
+#include <glib.h>
+
+gchar * font_utils_get_font_name (FT_Face face);
+gchar * font_utils_get_font_name_for_file (FT_Library library,
+                                           const gchar *path);
+
+#endif /* __FONT_UTILS_H__ */
+
diff -uprN mate-control-center/font-viewer/Makefile.am mate-control-center-test/font-viewer/Makefile.am
--- mate-control-center/font-viewer/Makefile.am	2015-08-23 21:15:10.644887858 +0200
+++ mate-control-center-test/font-viewer/Makefile.am	2015-08-24 18:40:12.523222645 +0200
@@ -20,6 +20,8 @@ mate_font_viewer_SOURCES = \
 	$(font_loader_SOURCES) \
 	font-model.h \
 	font-model.c \
+	font-utils.h \
+	font-utils.c \
 	gd-main-toolbar.h \
 	gd-main-toolbar.c \
 	sushi-font-widget.h \
 
дизайн и разработка: Vladimir Lettiev aka crux © 2004-2005, Andrew Avramenko aka liks © 2007-2008
текущий майнтейнер: Michael Shigorin