Evince
Evince is a document viewer capable of displaying multiple and single page document formats like PDF and Postscript.
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
ev-properties-fonts.c
Go to the documentation of this file.
1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8; c-indent-level: 8 -*- */
2 /* this file is part of evince, a gnome document viewer
3  *
4  * Copyright (C) 2005 Red Hat, Inc
5  *
6  * Evince is free software; you can redistribute it and/or modify it
7  * under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * Evince is distributed in the hope that it will be useful, but
12  * WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19  */
20 
21 #ifdef HAVE_CONFIG_H
22 #include "config.h"
23 #endif
24 
25 #include <glib/gi18n.h>
26 #include <gtk/gtk.h>
27 
28 #include "ev-document-fonts.h"
29 #include "ev-job-scheduler.h"
30 #include "ev-jobs.h"
31 #include "ev-properties-fonts.h"
32 
34  GtkVBox base_instance;
35 
36  GtkWidget *fonts_treeview;
38  GtkWidget *fonts_summary;
40 
42 };
43 
45  GtkVBoxClass base_class;
46 };
47 
48 static void
50 
51 G_DEFINE_TYPE (EvPropertiesFonts, ev_properties_fonts, GTK_TYPE_BOX)
52 
53 static void
54 ev_properties_fonts_dispose (GObject *object)
55 {
57 
58  if (properties->fonts_job) {
59  g_signal_handlers_disconnect_by_func (properties->fonts_job,
61  properties);
62  ev_job_cancel (properties->fonts_job);
63 
64  g_object_unref (properties->fonts_job);
65  properties->fonts_job = NULL;
66  }
67 
68  G_OBJECT_CLASS (ev_properties_fonts_parent_class)->dispose (object);
69 }
70 
71 static void
73 {
74  GObjectClass *g_object_class = G_OBJECT_CLASS (properties_class);
75 
76  g_object_class->dispose = ev_properties_fonts_dispose;
77 }
78 
79 static void
80 font_cell_data_func (GtkTreeViewColumn *col, GtkCellRenderer *renderer,
81  GtkTreeModel *model, GtkTreeIter *iter, gpointer user_data)
82 {
83  char *name;
84  char *details;
85  char *markup;
86 
87  gtk_tree_model_get (model, iter,
90  -1);
91 
92  if (details) {
93  markup = g_strdup_printf ("<b><big>%s</big></b>\n<small>%s</small>",
94  name, details);
95  } else {
96  markup = g_strdup_printf ("<b><big>%s</big></b>", name);
97  }
98 
99  g_object_set (renderer, "markup", markup, NULL);
100 
101  g_free (markup);
102  g_free (details);
103  g_free (name);
104 }
105 
106 static void
108 {
109  GtkWidget *swindow;
110  GtkCellRenderer *renderer;
111  GtkTreeViewColumn *column;
112 
113  gtk_container_set_border_width (GTK_CONTAINER (properties), 12);
114  gtk_box_set_spacing (GTK_BOX (properties), 6);
115 
116  properties->fonts_summary = gtk_label_new (NULL);
117  g_object_set (G_OBJECT (properties->fonts_summary),
118  "xalign", 0.0,
119  NULL);
120  gtk_label_set_line_wrap (GTK_LABEL (properties->fonts_summary), TRUE);
121  gtk_box_pack_start (GTK_BOX (properties),
122  properties->fonts_summary,
123  FALSE, FALSE, 0);
124 
125  swindow = gtk_scrolled_window_new (NULL, NULL);
126  gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (swindow),
127  GTK_SHADOW_IN);
128 
129  properties->fonts_treeview = gtk_tree_view_new ();
130  gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (properties->fonts_treeview),
131  FALSE);
132  column = gtk_tree_view_column_new ();
133  gtk_tree_view_column_set_expand (GTK_TREE_VIEW_COLUMN (column), TRUE);
134  gtk_tree_view_append_column (GTK_TREE_VIEW (properties->fonts_treeview),
135  column);
136 
137  renderer = GTK_CELL_RENDERER (g_object_new (GTK_TYPE_CELL_RENDERER_TEXT,
138  "ypad", 6, NULL));
139  gtk_tree_view_column_pack_start (GTK_TREE_VIEW_COLUMN (column),
140  renderer, FALSE);
141  gtk_tree_view_column_set_title (GTK_TREE_VIEW_COLUMN (column),
142  _("Font"));
143  gtk_tree_view_column_set_cell_data_func (column, renderer,
145  NULL, NULL);
146 
147  gtk_container_add (GTK_CONTAINER (swindow), properties->fonts_treeview);
148  gtk_widget_show (properties->fonts_treeview);
149 
150  gtk_box_pack_start (GTK_BOX (properties), swindow,
151  TRUE, TRUE, 0);
152  gtk_widget_show (swindow);
153 
154  properties->fonts_progress_label = gtk_label_new (NULL);
155  g_object_set (G_OBJECT (properties->fonts_progress_label),
156  "xalign", 0.0,
157  NULL);
158  gtk_box_pack_start (GTK_BOX (properties),
159  properties->fonts_progress_label,
160  FALSE, FALSE, 0);
161  gtk_widget_show (properties->fonts_progress_label);
162 }
163 
164 static void
165 update_progress_label (GtkWidget *label, double progress)
166 {
167  if (progress > 0) {
168  char *progress_text;
169  progress_text = g_strdup_printf (_("Gathering font information… %3d%%"),
170  (int) (progress * 100));
171  gtk_label_set_text (GTK_LABEL (label), progress_text);
172  g_free (progress_text);
173  gtk_widget_show (label);
174  } else {
175  gtk_widget_hide (label);
176  }
177 }
178 
179 static void
181 {
182  EvDocumentFonts *document_fonts = EV_DOCUMENT_FONTS (properties->document);
183  const gchar *font_summary;
184 
185  g_signal_handlers_disconnect_by_func (job, job_fonts_finished_cb, properties);
186  g_object_unref (properties->fonts_job);
187  properties->fonts_job = NULL;
188 
189  font_summary = ev_document_fonts_get_fonts_summary (document_fonts);
190  if (font_summary) {
191  gtk_label_set_text (GTK_LABEL (properties->fonts_summary),
192  font_summary);
193  /* show the label only when fonts are scanned, so the label
194  * does not take space while it is loading */
195  gtk_widget_show (properties->fonts_summary);
196  }
197 }
198 
199 static void
201 {
202  GtkTreeModel *model;
203  EvDocumentFonts *document_fonts = EV_DOCUMENT_FONTS (properties->document);
204 
205  update_progress_label (properties->fonts_progress_label, progress);
206 
207  model = gtk_tree_view_get_model (GTK_TREE_VIEW (properties->fonts_treeview));
208  /* Documen lock is already held by the jop */
209  ev_document_fonts_fill_model (document_fonts, model);
210 }
211 
212 void
214  EvDocument *document)
215 {
216  GtkTreeView *tree_view = GTK_TREE_VIEW (properties->fonts_treeview);
217  GtkListStore *list_store;
218 
219  properties->document = document;
220 
221  list_store = gtk_list_store_new (EV_DOCUMENT_FONTS_COLUMN_NUM_COLUMNS,
222  G_TYPE_STRING, G_TYPE_STRING);
223  gtk_tree_view_set_model (tree_view, GTK_TREE_MODEL (list_store));
224 
225  properties->fonts_job = ev_job_fonts_new (properties->document);
226  g_signal_connect (properties->fonts_job, "updated",
227  G_CALLBACK (job_fonts_updated_cb),
228  properties);
229  g_signal_connect (properties->fonts_job, "finished",
230  G_CALLBACK (job_fonts_finished_cb),
231  properties);
232  ev_job_scheduler_push_job (properties->fonts_job, EV_JOB_PRIORITY_NONE);
233 }
234 
235 GtkWidget *
237 {
239 
240  properties = g_object_new (EV_TYPE_PROPERTIES_FONTS,
241  "orientation", GTK_ORIENTATION_VERTICAL,
242  NULL);
243 
244  return GTK_WIDGET (properties);
245 }