summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog37
-rw-r--r--components/hardware/nautilus-hardware-view.c15
-rw-r--r--components/music/nautilus-music-view.c9
-rw-r--r--components/rpmview/nautilus-rpm-view.c10
-rw-r--r--components/services/startup/nautilus-view/nautilus-service-startup-view.c10
-rw-r--r--libnautilus-extensions/Makefile.am2
-rw-r--r--libnautilus-extensions/nautilus-font-factory.c320
-rw-r--r--libnautilus-extensions/nautilus-font-factory.h49
-rw-r--r--libnautilus-extensions/nautilus-icon-container.c30
-rw-r--r--libnautilus-private/Makefile.am2
-rw-r--r--libnautilus-private/nautilus-font-factory.c320
-rw-r--r--libnautilus-private/nautilus-font-factory.h49
-rw-r--r--libnautilus-private/nautilus-icon-container.c30
-rw-r--r--src/nautilus-property-browser.c14
-rw-r--r--src/nautilus-sidebar-title.c20
15 files changed, 844 insertions, 73 deletions
diff --git a/ChangeLog b/ChangeLog
index 7fb653e71..2f5ddaed0 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,40 @@
+2000-06-02 Ramiro Estrugo <ramiro@eazel.com>
+
+ Task 667. Unhardcode font strings.
+
+ * libnautilus-extensions/nautilus-font-factory.c:
+ (nautilus_get_current_font_factory), (nautilus_font_factory_get),
+ (nautilus_font_factory_new), (nautilus_font_factory_initialize),
+ (nautilus_font_factory_initialize_class), (font_hash_node_alloc),
+ (font_hash_node_free), (font_hash_node_lookup),
+ (font_hash_node_lookup_with_insertion),
+ (nautilus_font_factory_get_font_by_family),
+ (nautilus_font_factory_get_font_from_preferences),
+ (nautilus_font_factory_get_fallback_font), (make_font_name_string):
+ * libnautilus-extensions/nautilus-font-factory.h:
+ New class to obtain fonts either by family or from preferences. A
+ specific size can be requested.
+
+ Right now its a pretty dumb class, but it can be enhanced to do
+ smart things like looking at gtkstyles and/or smarted choosing of
+ fonts if the specifically requested size is not avialable.
+
+ * components/hardware/nautilus-hardware-view.c: (setup_form_title):
+ * components/music/nautilus-music-view.c:
+ (nautilus_music_view_initialize):
+ * components/rpmview/nautilus-rpm-view.c:
+ (nautilus_rpm_view_initialize):
+ * components/services/startup/nautilus-view/nautilus-service-startup-view.c:
+ (setup_form_title):
+ * libnautilus-extensions/Makefile.am:
+ * libnautilus-extensions/nautilus-icon-container.c:
+ (nautilus_icon_container_initialize):
+ * src/nautilus-property-browser.c:
+ (nautilus_property_browser_initialize):
+ * src/nautilus-sidebar-title.c: (nautilus_index_title_update_info):
+ Unhardcode xlfd font strings in all of these and use the font
+ factory instead.
+
2000-06-02 Pavel Cisler <pavel@eazel.com>
* src/file-manager/fm-list-view.c: (fm_list_handle_dropped_icons):
diff --git a/components/hardware/nautilus-hardware-view.c b/components/hardware/nautilus-hardware-view.c
index 20a0dbed5..ae4f43676 100644
--- a/components/hardware/nautilus-hardware-view.c
+++ b/components/hardware/nautilus-hardware-view.c
@@ -35,8 +35,9 @@
#include <libnautilus/libnautilus.h>
#include <libnautilus-extensions/nautilus-background.h>
#include <libnautilus-extensions/nautilus-directory-background.h>
-#include <libnautilus-extensions/nautilus-file.h>
#include <libnautilus-extensions/nautilus-file-utilities.h>
+#include <libnautilus-extensions/nautilus-file.h>
+#include <libnautilus-extensions/nautilus-font-factory.h>
#include <libnautilus-extensions/nautilus-glib-extensions.h>
#include <libnautilus-extensions/nautilus-gtk-extensions.h>
#include <libnautilus-extensions/nautilus-gtk-macros.h>
@@ -276,7 +277,8 @@ setup_form_title (NautilusHardwareView *view, const char* image_name, const char
GtkWidget *temp_widget;
char *file_name;
GtkWidget *temp_container = gtk_hbox_new(FALSE, 0);
-
+ GdkFont *font;
+
gtk_box_pack_start (GTK_BOX(view->details->form), temp_container, 0, 0, 4);
gtk_widget_show(temp_container);
@@ -289,9 +291,12 @@ setup_form_title (NautilusHardwareView *view, const char* image_name, const char
}
temp_widget = gtk_label_new (title_text);
- /* FIXME bugzilla.eazel.com 667: don't use hardwired font like this */
- nautilus_gtk_widget_set_font_by_name (temp_widget,
- "-*-helvetica-medium-r-normal-*-18-*-*-*-*-*-*-*"); ;
+
+ font = nautilus_font_factory_get_font_from_preferences (18);
+
+ nautilus_gtk_widget_set_font (temp_widget, font);
+ gdk_font_unref (font);
+
gtk_box_pack_start (GTK_BOX (temp_container), temp_widget, 0, 0, 8);
gtk_widget_show (temp_widget);
}
diff --git a/components/music/nautilus-music-view.c b/components/music/nautilus-music-view.c
index d166aa6ac..836bbe79e 100644
--- a/components/music/nautilus-music-view.c
+++ b/components/music/nautilus-music-view.c
@@ -46,6 +46,7 @@
#include <libnautilus-extensions/nautilus-gtk-macros.h>
#include <libnautilus-extensions/nautilus-metadata.h>
#include <libnautilus-extensions/nautilus-string.h>
+#include <libnautilus-extensions/nautilus-font-factory.h>
#include <gdk-pixbuf/gdk-pixbuf.h>
#include <gtk/gtksignal.h>
#include <gnome.h>
@@ -195,6 +196,7 @@ nautilus_music_view_initialize (NautilusMusicView *music_view)
{
GtkWidget *scrollwindow;
char *titles[] = {_("Track "), _("Title"), _("Artist"), _("Year"), _("Bitrate "), _("Time "), _("Album"), _("Comment"),};
+ GdkFont *font;
music_view->details = g_new0 (NautilusMusicViewDetails, 1);
@@ -219,9 +221,10 @@ nautilus_music_view_initialize (NautilusMusicView *music_view)
/* allocate a widget for the album title */
music_view->details->album_title = gtk_label_new (_("Album Title"));
- /* FIXME bugzilla.eazel.com 667: don't use hardwired font like this */
- nautilus_gtk_widget_set_font_by_name (music_view->details->album_title,
- "-*-helvetica-medium-r-normal-*-18-*-*-*-*-*-*-*"); ;
+
+ font = nautilus_font_factory_get_font_from_preferences (18);
+ nautilus_gtk_widget_set_font (music_view->details->album_title, font);
+
gtk_box_pack_start (GTK_BOX (music_view->details->album_container), music_view->details->album_title, FALSE, FALSE, 0);
gtk_widget_show (music_view->details->album_title);
diff --git a/components/rpmview/nautilus-rpm-view.c b/components/rpmview/nautilus-rpm-view.c
index 544bce275..89ec7c7be 100644
--- a/components/rpmview/nautilus-rpm-view.c
+++ b/components/rpmview/nautilus-rpm-view.c
@@ -43,6 +43,7 @@
#include <libnautilus-extensions/nautilus-gtk-macros.h>
#include <libnautilus-extensions/nautilus-metadata.h>
#include <libnautilus-extensions/nautilus-string.h>
+#include <libnautilus-extensions/nautilus-font-factory.h>
#include <gdk-pixbuf/gdk-pixbuf.h>
#include <gtk/gtksignal.h>
#include <gnome.h>
@@ -136,6 +137,7 @@ nautilus_rpm_view_initialize (NautilusRPMView *rpm_view)
GtkWidget *temp_box, *temp_title_box, *temp_widget;
GtkTable *table;
static gchar *list_headers[] = { N_("Package Contents") };
+ GdkFont *font;
rpm_view->details = g_new0 (NautilusRPMViewDetails, 1);
@@ -176,9 +178,11 @@ nautilus_rpm_view_initialize (NautilusRPMView *rpm_view)
/* allocate the name field */
rpm_view->details->package_title = gtk_label_new (_("Package Title"));
- /* FIXME bugzilla.eazel.com 667: don't use hardwired font like this */
- nautilus_gtk_widget_set_font_by_name (rpm_view->details->package_title,
- "-*-helvetica-medium-r-normal-*-18-*-*-*-*-*-*-*");
+
+ font = nautilus_font_factory_get_font_from_preferences (18);
+ nautilus_gtk_widget_set_font (rpm_view->details->package_title, font);
+ gdk_font_unref (font);
+
gtk_box_pack_start (GTK_BOX (temp_title_box), rpm_view->details->package_title, 0, 0, 0);
gtk_widget_show (rpm_view->details->package_title);
diff --git a/components/services/startup/nautilus-view/nautilus-service-startup-view.c b/components/services/startup/nautilus-view/nautilus-service-startup-view.c
index 2494138ba..fa922d284 100644
--- a/components/services/startup/nautilus-view/nautilus-service-startup-view.c
+++ b/components/services/startup/nautilus-view/nautilus-service-startup-view.c
@@ -38,6 +38,7 @@
#include <libnautilus-extensions/nautilus-global-preferences.h>
#include <libnautilus-extensions/nautilus-file-utilities.h>
#include <libnautilus-extensions/nautilus-string.h>
+#include <libnautilus-extensions/nautilus-font-factory.h>
#include <stdio.h>
#include "nautilus-service-startup-view.h"
@@ -469,6 +470,7 @@ setup_form_title (NautilusServicesContentView* view,
GtkWidget* temp_widget;
char* file_name;
GtkWidget* temp_container;
+ GdkFont *font;
temp_container = gtk_hbox_new (FALSE, 0);
@@ -482,9 +484,11 @@ setup_form_title (NautilusServicesContentView* view,
g_free (file_name);
view->details->form_title = gtk_label_new (title_text);
- /* FIXME bugzilla.eazel.com 667: don't use hardwired font like this */
- nautilus_gtk_widget_set_font_by_name (view->details->form_title,
- "-*-helvetica-medium-r-normal-*-18-*-*-*-*-*-*-*"); ;
+
+ font = nautilus_font_factory_get_font_from_preferences (18);
+ nautilus_gtk_widget_set_font (view->details->form_title, font);
+ gdk_font_unref (font);
+
gtk_box_pack_start (GTK_BOX (temp_container), view->details->form_title, 0, 0, 8);
gtk_widget_show (view->details->form_title);
}
diff --git a/libnautilus-extensions/Makefile.am b/libnautilus-extensions/Makefile.am
index dd3ea50b0..fee044a0f 100644
--- a/libnautilus-extensions/Makefile.am
+++ b/libnautilus-extensions/Makefile.am
@@ -55,6 +55,7 @@ libnautilus_extensionsinclude_HEADERS= \
nautilus-gtk-macros.h \
nautilus-icon-container.h \
nautilus-icon-factory.h \
+ nautilus-font-factory.h \
nautilus-icon-text-item.h \
nautilus-keep-last-vertical-box.h \
nautilus-link.h \
@@ -109,6 +110,7 @@ libnautilus_extensions_la_SOURCES = \
nautilus-drag.c \
nautilus-icon-dnd.c \
nautilus-icon-factory.c \
+ nautilus-font-factory.c \
nautilus-icon-grid.c \
nautilus-icon-text-item.c \
nautilus-keep-last-vertical-box.c \
diff --git a/libnautilus-extensions/nautilus-font-factory.c b/libnautilus-extensions/nautilus-font-factory.c
new file mode 100644
index 000000000..e5abff60f
--- /dev/null
+++ b/libnautilus-extensions/nautilus-font-factory.c
@@ -0,0 +1,320 @@
+/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*-
+
+ nautilus-font-factory.c: Class for obtaining fonts.
+
+ Copyright (C) 2000 Eazel, Inc.
+
+ This program is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ This program 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
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public
+ License along with this program; if not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+
+ Authors: Ramiro Estrugo <ramiro@eazel.com>
+*/
+
+#include <config.h>
+
+#include "nautilus-font-factory.h"
+#include "nautilus-gtk-macros.h"
+#include "nautilus-string.h"
+#include "nautilus-global-preferences.h"
+
+#include <unistd.h>
+#include <pthread.h>
+
+/* The font factory */
+typedef struct {
+ GtkObject object;
+
+ GHashTable *fonts;
+} NautilusFontFactory;
+
+typedef struct {
+ GtkObjectClass parent_class;
+} NautilusFontFactoryClass;
+
+/* FontHashNode */
+typedef struct {
+ char *name;
+ GdkFont *font;
+} FontHashNode;
+
+static GtkType nautilus_font_factory_get_type (void);
+static void nautilus_font_factory_initialize_class (NautilusFontFactoryClass *class);
+static void nautilus_font_factory_initialize (NautilusFontFactory *factory);
+static NautilusFontFactory *nautilus_get_current_font_factory (void);
+static NautilusFontFactory *nautilus_font_factory_new (void);
+static char * make_font_name_string (const char *foundry,
+ const char *familiy,
+ const char *weight,
+ const char *slant,
+ const char *set_width,
+ const char *add_style,
+ guint size_in_pixels);
+static FontHashNode * font_hash_node_alloc (const char *name);
+static FontHashNode * font_hash_node_lookup (const char *name);
+static FontHashNode * font_hash_node_lookup_with_insertion (const char *name);
+
+#if 0
+static void font_hash_node_free (FontHashNode *node);
+#endif
+
+NAUTILUS_DEFINE_CLASS_BOILERPLATE (NautilusFontFactory, nautilus_font_factory, GTK_TYPE_OBJECT)
+
+/* Return a pointer to the single global font factory. */
+static NautilusFontFactory *
+nautilus_get_current_font_factory (void)
+{
+ static NautilusFontFactory *global_font_factory = NULL;
+
+ if (global_font_factory == NULL) {
+ global_font_factory = nautilus_font_factory_new ();
+ }
+
+ return global_font_factory;
+}
+
+GtkObject *
+nautilus_font_factory_get (void)
+{
+ return GTK_OBJECT (nautilus_get_current_font_factory ());
+}
+
+/* Create the font factory. */
+static NautilusFontFactory *
+nautilus_font_factory_new (void)
+{
+ NautilusFontFactory *factory;
+
+ factory = (NautilusFontFactory *) gtk_object_new (nautilus_font_factory_get_type (), NULL);
+
+ return factory;
+}
+
+static void
+nautilus_font_factory_initialize (NautilusFontFactory *factory)
+{
+ factory->fonts = g_hash_table_new (g_str_hash, g_str_equal);
+}
+
+static void
+nautilus_font_factory_initialize_class (NautilusFontFactoryClass *class)
+{
+ GtkObjectClass *object_class;
+
+ object_class = GTK_OBJECT_CLASS (class);
+}
+
+static FontHashNode *
+font_hash_node_alloc (const char *name)
+{
+ FontHashNode * node;
+
+ g_assert (name != NULL);
+
+ node = g_new (FontHashNode, 1);
+
+ node->name = g_strdup (name);
+
+ node->font = NULL;
+
+ return node;
+}
+
+#if 0
+static void
+font_hash_node_free (FontHashNode *node)
+{
+ g_assert (node != NULL);
+
+ g_free (node->name);
+
+ g_free (node);
+}
+#endif
+
+static FontHashNode *
+font_hash_node_lookup (const char *name)
+{
+ static NautilusFontFactory *factory;
+
+ gpointer hash_value;
+
+ g_assert (name != NULL);
+
+ factory = nautilus_get_current_font_factory ();
+ g_assert (factory != NULL);
+
+ hash_value = g_hash_table_lookup (factory->fonts, (gconstpointer) name);
+
+ return (FontHashNode *) hash_value;
+}
+
+static FontHashNode *
+font_hash_node_lookup_with_insertion (const char *name)
+{
+ static NautilusFontFactory *factory;
+
+ FontHashNode *node = NULL;
+
+ g_assert (name != NULL);
+
+ factory = nautilus_get_current_font_factory ();
+ g_assert (factory != NULL);
+
+
+ node = font_hash_node_lookup (name);
+
+ if (node == NULL) {
+ GdkFont *font;
+
+ font = gdk_font_load (name);
+
+ if (font != NULL) {
+ node = font_hash_node_alloc (name);
+ node->font = font;
+
+ gdk_font_ref (node->font);
+
+ g_hash_table_insert (factory->fonts, (gpointer) name, (gpointer) node);
+ }
+ }
+
+ return node;
+}
+
+static char *
+make_font_name_string (const char *foundry,
+ const char *familiy,
+ const char *weight,
+ const char *slant,
+ const char *set_width,
+ const char *add_style,
+ guint size_in_pixels)
+{
+ char *font_name;
+
+ const char *points = "*";
+ const char *hor_res = "*";
+ const char *ver_res = "*";
+ const char *spacing = "*";
+ const char *average_width = "*";
+ const char *char_set_registry = "*";
+ const char *char_set_encoding = "*";
+
+
+ /* +---------------------------------------------------- foundry
+ | +------------------------------------------------- family
+ | | +---------------------------------------------- weight
+ | | | +------------------------------------------- slant
+ | | | | +---------------------------------------- sel_width
+ | | | | | +------------------------------------- add-style
+ | | | | | | +---------------------------------- pixels
+ | | | | | | | +------------------------------- points
+ | | | | | | | | +---------------------------- hor_res
+ | | | | | | | | | +------------------------- ver_res
+ | | | | | | | | | | +---------------------- spacing
+ | | | | | | | | | | | +------------------- average_width
+ | | | | | | | | | | | | +---------------- char_set_registry
+ | | | | | | | | | | | | | +------------- char_set_encoding */
+ font_name = g_strdup_printf ("-%s-%s-%s-%s-%s-%s-%d-%s-%s-%s-%s-%s-%s-%s",
+ foundry,
+ familiy,
+ weight,
+ slant,
+ set_width,
+ add_style,
+ size_in_pixels,
+ points,
+ hor_res,
+ ver_res,
+ spacing,
+ average_width,
+ char_set_registry,
+ char_set_encoding);
+
+ return font_name;
+}
+
+/* Public functions */
+GdkFont *
+nautilus_font_factory_get_font_by_family (const char *family,
+ guint size_in_pixels)
+{
+ static NautilusFontFactory *factory;
+ GdkFont *font = NULL;
+ FontHashNode *node;
+ char *font_name;
+
+ g_return_val_if_fail (family != NULL, NULL);
+ g_return_val_if_fail (size_in_pixels > 0, NULL);
+
+ factory = nautilus_get_current_font_factory ();
+ g_assert (factory != NULL);
+
+ font_name = make_font_name_string ("*",
+ family,
+ "medium",
+ "r",
+ "normal",
+ "*",
+ size_in_pixels);
+
+ g_assert (font_name != NULL);
+
+ node = font_hash_node_lookup_with_insertion (font_name);
+
+ if (node != NULL) {
+ g_assert (node->font);
+
+ font = node->font;
+
+ gdk_font_ref (font);
+ }
+ else {
+ font = nautilus_font_factory_get_fallback_font ();
+ }
+
+ g_free (font_name);
+
+ return font;
+}
+
+GdkFont *
+nautilus_font_factory_get_font_from_preferences (guint size_in_pixels)
+{
+ char *family;
+ GdkFont *font;
+
+ family = nautilus_preferences_get (NAUTILUS_PREFERENCES_DIRECTORY_VIEW_FONT_FAMILY, "helvectica");
+
+ font = nautilus_font_factory_get_font_by_family (family, size_in_pixels);
+
+ g_free (family);
+
+ return font;
+}
+
+GdkFont *
+nautilus_font_factory_get_fallback_font (void)
+{
+ static GdkFont *fixed_font;
+
+ if (fixed_font == NULL) {
+ fixed_font = gdk_font_load ("fixed");
+ g_assert (fixed_font != NULL);
+ gdk_font_ref (fixed_font);
+ }
+
+ return fixed_font;
+}
diff --git a/libnautilus-extensions/nautilus-font-factory.h b/libnautilus-extensions/nautilus-font-factory.h
new file mode 100644
index 000000000..e5f933581
--- /dev/null
+++ b/libnautilus-extensions/nautilus-font-factory.h
@@ -0,0 +1,49 @@
+/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*-
+
+ nautilus-font-factory.h: Class for obtaining fonts.
+
+ Copyright (C) 2000 Eazel, Inc.
+
+ This program is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ This program 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
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public
+ License along with this program; if not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+
+ Authors: Ramiro Estrugo <ramiro@eazel.com>
+*/
+
+#ifndef NAUTILUS_FONT_FACTORY_H
+#define NAUTILUS_FONT_FACTORY_H
+
+#include <gdk/gdk.h>
+#include <gtk/gtkobject.h>
+
+/* A There's a single NautilusFontFactory object. */
+GtkObject *nautilus_font_factory_get (void);
+
+
+/* Get a font by familiy. */
+GdkFont * nautilus_font_factory_get_font_by_family (const char *family,
+ guint size_in_pixels);
+
+
+/* Get a font according to the family set in preferences. */
+GdkFont * nautilus_font_factory_get_font_from_preferences (guint size_in_pixels);
+
+
+
+/* Get the fallback font */
+GdkFont * nautilus_font_factory_get_fallback_font (void);
+
+
+#endif /* NAUTILUS_FONT_FACTORY_H */
diff --git a/libnautilus-extensions/nautilus-icon-container.c b/libnautilus-extensions/nautilus-icon-container.c
index c89b96475..bc8ae379e 100644
--- a/libnautilus-extensions/nautilus-icon-container.c
+++ b/libnautilus-extensions/nautilus-icon-container.c
@@ -43,6 +43,7 @@
#include "nautilus-gtk-extensions.h"
#include "nautilus-gtk-macros.h"
#include "nautilus-icon-text-item.h"
+#include "nautilus-font-factory.h"
#include "nautilus-lib-self-check-functions.h"
@@ -2404,20 +2405,6 @@ nautilus_icon_container_initialize_class (NautilusIconContainerClass *class)
stipple = gdk_bitmap_create_from_data (NULL, stipple_bits, 2, 2);
}
-static GdkFont *
-load_font (const char *name)
-{
- GdkFont *font;
-
- /* FIXME bugzilla.eazel.com 40:
- * Eventually we need a runtime check, but an assert is better than nothing.
- */
- font = gdk_font_load (name);
- g_assert (font != NULL);
- return font;
-}
-
-
/* Handler for the editing_started signal of an icon text item. We block the
* event handler so that it will not be called while the text is being edited.
*/
@@ -2459,14 +2446,13 @@ nautilus_icon_container_initialize (NautilusIconContainer *container)
details->zoom_level = NAUTILUS_ZOOM_LEVEL_STANDARD;
/* font table - this isn't exactly proportional, but it looks better than computed */
- /* FIXME bugzilla.eazel.com 619: read font from metadata and/or preferences */
- details->label_font[NAUTILUS_ZOOM_LEVEL_SMALLEST] = load_font ("-*-helvetica-medium-r-normal-*-8-*-*-*-*-*-*-*");
- details->label_font[NAUTILUS_ZOOM_LEVEL_SMALLER] = load_font ("-*-helvetica-medium-r-normal-*-8-*-*-*-*-*-*-*");
- details->label_font[NAUTILUS_ZOOM_LEVEL_SMALL] = load_font ("-*-helvetica-medium-r-normal-*-10-*-*-*-*-*-*-*");
- details->label_font[NAUTILUS_ZOOM_LEVEL_STANDARD] = load_font ("-*-helvetica-medium-r-normal-*-12-*-*-*-*-*-*-*");
- details->label_font[NAUTILUS_ZOOM_LEVEL_LARGE] = load_font ("-*-helvetica-medium-r-normal-*-14-*-*-*-*-*-*-*");
- details->label_font[NAUTILUS_ZOOM_LEVEL_LARGER] = load_font ("-*-helvetica-medium-r-normal-*-18-*-*-*-*-*-*-*");
- details->label_font[NAUTILUS_ZOOM_LEVEL_LARGEST] = load_font ("-*-helvetica-medium-r-normal-*-18-*-*-*-*-*-*-*");
+ details->label_font[NAUTILUS_ZOOM_LEVEL_SMALLEST] = nautilus_font_factory_get_font_from_preferences (8);
+ details->label_font[NAUTILUS_ZOOM_LEVEL_SMALLER] = nautilus_font_factory_get_font_from_preferences (8);
+ details->label_font[NAUTILUS_ZOOM_LEVEL_SMALL] = nautilus_font_factory_get_font_from_preferences (10);
+ details->label_font[NAUTILUS_ZOOM_LEVEL_STANDARD] = nautilus_font_factory_get_font_from_preferences (12);
+ details->label_font[NAUTILUS_ZOOM_LEVEL_LARGE] = nautilus_font_factory_get_font_from_preferences (14);
+ details->label_font[NAUTILUS_ZOOM_LEVEL_LARGER] = nautilus_font_factory_get_font_from_preferences (18);
+ details->label_font[NAUTILUS_ZOOM_LEVEL_LARGEST] = nautilus_font_factory_get_font_from_preferences (18);
container->details = details;
diff --git a/libnautilus-private/Makefile.am b/libnautilus-private/Makefile.am
index dd3ea50b0..fee044a0f 100644
--- a/libnautilus-private/Makefile.am
+++ b/libnautilus-private/Makefile.am
@@ -55,6 +55,7 @@ libnautilus_extensionsinclude_HEADERS= \
nautilus-gtk-macros.h \
nautilus-icon-container.h \
nautilus-icon-factory.h \
+ nautilus-font-factory.h \
nautilus-icon-text-item.h \
nautilus-keep-last-vertical-box.h \
nautilus-link.h \
@@ -109,6 +110,7 @@ libnautilus_extensions_la_SOURCES = \
nautilus-drag.c \
nautilus-icon-dnd.c \
nautilus-icon-factory.c \
+ nautilus-font-factory.c \
nautilus-icon-grid.c \
nautilus-icon-text-item.c \
nautilus-keep-last-vertical-box.c \
diff --git a/libnautilus-private/nautilus-font-factory.c b/libnautilus-private/nautilus-font-factory.c
new file mode 100644
index 000000000..e5abff60f
--- /dev/null
+++ b/libnautilus-private/nautilus-font-factory.c
@@ -0,0 +1,320 @@
+/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*-
+
+ nautilus-font-factory.c: Class for obtaining fonts.
+
+ Copyright (C) 2000 Eazel, Inc.
+
+ This program is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ This program 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
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public
+ License along with this program; if not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+
+ Authors: Ramiro Estrugo <ramiro@eazel.com>
+*/
+
+#include <config.h>
+
+#include "nautilus-font-factory.h"
+#include "nautilus-gtk-macros.h"
+#include "nautilus-string.h"
+#include "nautilus-global-preferences.h"
+
+#include <unistd.h>
+#include <pthread.h>
+
+/* The font factory */
+typedef struct {
+ GtkObject object;
+
+ GHashTable *fonts;
+} NautilusFontFactory;
+
+typedef struct {
+ GtkObjectClass parent_class;
+} NautilusFontFactoryClass;
+
+/* FontHashNode */
+typedef struct {
+ char *name;
+ GdkFont *font;
+} FontHashNode;
+
+static GtkType nautilus_font_factory_get_type (void);
+static void nautilus_font_factory_initialize_class (NautilusFontFactoryClass *class);
+static void nautilus_font_factory_initialize (NautilusFontFactory *factory);
+static NautilusFontFactory *nautilus_get_current_font_factory (void);
+static NautilusFontFactory *nautilus_font_factory_new (void);
+static char * make_font_name_string (const char *foundry,
+ const char *familiy,
+ const char *weight,
+ const char *slant,
+ const char *set_width,
+ const char *add_style,
+ guint size_in_pixels);
+static FontHashNode * font_hash_node_alloc (const char *name);
+static FontHashNode * font_hash_node_lookup (const char *name);
+static FontHashNode * font_hash_node_lookup_with_insertion (const char *name);
+
+#if 0
+static void font_hash_node_free (FontHashNode *node);
+#endif
+
+NAUTILUS_DEFINE_CLASS_BOILERPLATE (NautilusFontFactory, nautilus_font_factory, GTK_TYPE_OBJECT)
+
+/* Return a pointer to the single global font factory. */
+static NautilusFontFactory *
+nautilus_get_current_font_factory (void)
+{
+ static NautilusFontFactory *global_font_factory = NULL;
+
+ if (global_font_factory == NULL) {
+ global_font_factory = nautilus_font_factory_new ();
+ }
+
+ return global_font_factory;
+}
+
+GtkObject *
+nautilus_font_factory_get (void)
+{
+ return GTK_OBJECT (nautilus_get_current_font_factory ());
+}
+
+/* Create the font factory. */
+static NautilusFontFactory *
+nautilus_font_factory_new (void)
+{
+ NautilusFontFactory *factory;
+
+ factory = (NautilusFontFactory *) gtk_object_new (nautilus_font_factory_get_type (), NULL);
+
+ return factory;
+}
+
+static void
+nautilus_font_factory_initialize (NautilusFontFactory *factory)
+{
+ factory->fonts = g_hash_table_new (g_str_hash, g_str_equal);
+}
+
+static void
+nautilus_font_factory_initialize_class (NautilusFontFactoryClass *class)
+{
+ GtkObjectClass *object_class;
+
+ object_class = GTK_OBJECT_CLASS (class);
+}
+
+static FontHashNode *
+font_hash_node_alloc (const char *name)
+{
+ FontHashNode * node;
+
+ g_assert (name != NULL);
+
+ node = g_new (FontHashNode, 1);
+
+ node->name = g_strdup (name);
+
+ node->font = NULL;
+
+ return node;
+}
+
+#if 0
+static void
+font_hash_node_free (FontHashNode *node)
+{
+ g_assert (node != NULL);
+
+ g_free (node->name);
+
+ g_free (node);
+}
+#endif
+
+static FontHashNode *
+font_hash_node_lookup (const char *name)
+{
+ static NautilusFontFactory *factory;
+
+ gpointer hash_value;
+
+ g_assert (name != NULL);
+
+ factory = nautilus_get_current_font_factory ();
+ g_assert (factory != NULL);
+
+ hash_value = g_hash_table_lookup (factory->fonts, (gconstpointer) name);
+
+ return (FontHashNode *) hash_value;
+}
+
+static FontHashNode *
+font_hash_node_lookup_with_insertion (const char *name)
+{
+ static NautilusFontFactory *factory;
+
+ FontHashNode *node = NULL;
+
+ g_assert (name != NULL);
+
+ factory = nautilus_get_current_font_factory ();
+ g_assert (factory != NULL);
+
+
+ node = font_hash_node_lookup (name);
+
+ if (node == NULL) {
+ GdkFont *font;
+
+ font = gdk_font_load (name);
+
+ if (font != NULL) {
+ node = font_hash_node_alloc (name);
+ node->font = font;
+
+ gdk_font_ref (node->font);
+
+ g_hash_table_insert (factory->fonts, (gpointer) name, (gpointer) node);
+ }
+ }
+
+ return node;
+}
+
+static char *
+make_font_name_string (const char *foundry,
+ const char *familiy,
+ const char *weight,
+ const char *slant,
+ const char *set_width,
+ const char *add_style,
+ guint size_in_pixels)
+{
+ char *font_name;
+
+ const char *points = "*";
+ const char *hor_res = "*";
+ const char *ver_res = "*";
+ const char *spacing = "*";
+ const char *average_width = "*";
+ const char *char_set_registry = "*";
+ const char *char_set_encoding = "*";
+
+
+ /* +---------------------------------------------------- foundry
+ | +------------------------------------------------- family
+ | | +---------------------------------------------- weight
+ | | | +------------------------------------------- slant
+ | | | | +---------------------------------------- sel_width
+ | | | | | +------------------------------------- add-style
+ | | | | | | +---------------------------------- pixels
+ | | | | | | | +------------------------------- points
+ | | | | | | | | +---------------------------- hor_res
+ | | | | | | | | | +------------------------- ver_res
+ | | | | | | | | | | +---------------------- spacing
+ | | | | | | | | | | | +------------------- average_width
+ | | | | | | | | | | | | +---------------- char_set_registry
+ | | | | | | | | | | | | | +------------- char_set_encoding */
+ font_name = g_strdup_printf ("-%s-%s-%s-%s-%s-%s-%d-%s-%s-%s-%s-%s-%s-%s",
+ foundry,
+ familiy,
+ weight,
+ slant,
+ set_width,
+ add_style,
+ size_in_pixels,
+ points,
+ hor_res,
+ ver_res,
+ spacing,
+ average_width,
+ char_set_registry,
+ char_set_encoding);
+
+ return font_name;
+}
+
+/* Public functions */
+GdkFont *
+nautilus_font_factory_get_font_by_family (const char *family,
+ guint size_in_pixels)
+{
+ static NautilusFontFactory *factory;
+ GdkFont *font = NULL;
+ FontHashNode *node;
+ char *font_name;
+
+ g_return_val_if_fail (family != NULL, NULL);
+ g_return_val_if_fail (size_in_pixels > 0, NULL);
+
+ factory = nautilus_get_current_font_factory ();
+ g_assert (factory != NULL);
+
+ font_name = make_font_name_string ("*",
+ family,
+ "medium",
+ "r",
+ "normal",
+ "*",
+ size_in_pixels);
+
+ g_assert (font_name != NULL);
+
+ node = font_hash_node_lookup_with_insertion (font_name);
+
+ if (node != NULL) {
+ g_assert (node->font);
+
+ font = node->font;
+
+ gdk_font_ref (font);
+ }
+ else {
+ font = nautilus_font_factory_get_fallback_font ();
+ }
+
+ g_free (font_name);
+
+ return font;
+}
+
+GdkFont *
+nautilus_font_factory_get_font_from_preferences (guint size_in_pixels)
+{
+ char *family;
+ GdkFont *font;
+
+ family = nautilus_preferences_get (NAUTILUS_PREFERENCES_DIRECTORY_VIEW_FONT_FAMILY, "helvectica");
+
+ font = nautilus_font_factory_get_font_by_family (family, size_in_pixels);
+
+ g_free (family);
+
+ return font;
+}
+
+GdkFont *
+nautilus_font_factory_get_fallback_font (void)
+{
+ static GdkFont *fixed_font;
+
+ if (fixed_font == NULL) {
+ fixed_font = gdk_font_load ("fixed");
+ g_assert (fixed_font != NULL);
+ gdk_font_ref (fixed_font);
+ }
+
+ return fixed_font;
+}
diff --git a/libnautilus-private/nautilus-font-factory.h b/libnautilus-private/nautilus-font-factory.h
new file mode 100644
index 000000000..e5f933581
--- /dev/null
+++ b/libnautilus-private/nautilus-font-factory.h
@@ -0,0 +1,49 @@
+/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*-
+
+ nautilus-font-factory.h: Class for obtaining fonts.
+
+ Copyright (C) 2000 Eazel, Inc.
+
+ This program is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ This program 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
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public
+ License along with this program; if not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+
+ Authors: Ramiro Estrugo <ramiro@eazel.com>
+*/
+
+#ifndef NAUTILUS_FONT_FACTORY_H
+#define NAUTILUS_FONT_FACTORY_H
+
+#include <gdk/gdk.h>
+#include <gtk/gtkobject.h>
+
+/* A There's a single NautilusFontFactory object. */
+GtkObject *nautilus_font_factory_get (void);
+
+
+/* Get a font by familiy. */
+GdkFont * nautilus_font_factory_get_font_by_family (const char *family,
+ guint size_in_pixels);
+
+
+/* Get a font according to the family set in preferences. */
+GdkFont * nautilus_font_factory_get_font_from_preferences (guint size_in_pixels);
+
+
+
+/* Get the fallback font */
+GdkFont * nautilus_font_factory_get_fallback_font (void);
+
+
+#endif /* NAUTILUS_FONT_FACTORY_H */
diff --git a/libnautilus-private/nautilus-icon-container.c b/libnautilus-private/nautilus-icon-container.c
index c89b96475..bc8ae379e 100644
--- a/libnautilus-private/nautilus-icon-container.c
+++ b/libnautilus-private/nautilus-icon-container.c
@@ -43,6 +43,7 @@
#include "nautilus-gtk-extensions.h"
#include "nautilus-gtk-macros.h"
#include "nautilus-icon-text-item.h"
+#include "nautilus-font-factory.h"
#include "nautilus-lib-self-check-functions.h"
@@ -2404,20 +2405,6 @@ nautilus_icon_container_initialize_class (NautilusIconContainerClass *class)
stipple = gdk_bitmap_create_from_data (NULL, stipple_bits, 2, 2);
}
-static GdkFont *
-load_font (const char *name)
-{
- GdkFont *font;
-
- /* FIXME bugzilla.eazel.com 40:
- * Eventually we need a runtime check, but an assert is better than nothing.
- */
- font = gdk_font_load (name);
- g_assert (font != NULL);
- return font;
-}
-
-
/* Handler for the editing_started signal of an icon text item. We block the
* event handler so that it will not be called while the text is being edited.
*/
@@ -2459,14 +2446,13 @@ nautilus_icon_container_initialize (NautilusIconContainer *container)
details->zoom_level = NAUTILUS_ZOOM_LEVEL_STANDARD;
/* font table - this isn't exactly proportional, but it looks better than computed */
- /* FIXME bugzilla.eazel.com 619: read font from metadata and/or preferences */
- details->label_font[NAUTILUS_ZOOM_LEVEL_SMALLEST] = load_font ("-*-helvetica-medium-r-normal-*-8-*-*-*-*-*-*-*");
- details->label_font[NAUTILUS_ZOOM_LEVEL_SMALLER] = load_font ("-*-helvetica-medium-r-normal-*-8-*-*-*-*-*-*-*");
- details->label_font[NAUTILUS_ZOOM_LEVEL_SMALL] = load_font ("-*-helvetica-medium-r-normal-*-10-*-*-*-*-*-*-*");
- details->label_font[NAUTILUS_ZOOM_LEVEL_STANDARD] = load_font ("-*-helvetica-medium-r-normal-*-12-*-*-*-*-*-*-*");
- details->label_font[NAUTILUS_ZOOM_LEVEL_LARGE] = load_font ("-*-helvetica-medium-r-normal-*-14-*-*-*-*-*-*-*");
- details->label_font[NAUTILUS_ZOOM_LEVEL_LARGER] = load_font ("-*-helvetica-medium-r-normal-*-18-*-*-*-*-*-*-*");
- details->label_font[NAUTILUS_ZOOM_LEVEL_LARGEST] = load_font ("-*-helvetica-medium-r-normal-*-18-*-*-*-*-*-*-*");
+ details->label_font[NAUTILUS_ZOOM_LEVEL_SMALLEST] = nautilus_font_factory_get_font_from_preferences (8);
+ details->label_font[NAUTILUS_ZOOM_LEVEL_SMALLER] = nautilus_font_factory_get_font_from_preferences (8);
+ details->label_font[NAUTILUS_ZOOM_LEVEL_SMALL] = nautilus_font_factory_get_font_from_preferences (10);
+ details->label_font[NAUTILUS_ZOOM_LEVEL_STANDARD] = nautilus_font_factory_get_font_from_preferences (12);
+ details->label_font[NAUTILUS_ZOOM_LEVEL_LARGE] = nautilus_font_factory_get_font_from_preferences (14);
+ details->label_font[NAUTILUS_ZOOM_LEVEL_LARGER] = nautilus_font_factory_get_font_from_preferences (18);
+ details->label_font[NAUTILUS_ZOOM_LEVEL_LARGEST] = nautilus_font_factory_get_font_from_preferences (18);
container->details = details;
diff --git a/src/nautilus-property-browser.c b/src/nautilus-property-browser.c
index a609e71e5..514d1e518 100644
--- a/src/nautilus-property-browser.c
+++ b/src/nautilus-property-browser.c
@@ -39,14 +39,15 @@
#include <libnautilus-extensions/nautilus-background.h>
#include <libnautilus-extensions/nautilus-directory.h>
-#include <libnautilus-extensions/nautilus-file.h>
#include <libnautilus-extensions/nautilus-file-utilities.h>
+#include <libnautilus-extensions/nautilus-file.h>
+#include <libnautilus-extensions/nautilus-font-factory.h>
#include <libnautilus-extensions/nautilus-gdk-pixbuf-extensions.h>
#include <libnautilus-extensions/nautilus-glib-extensions.h>
#include <libnautilus-extensions/nautilus-global-preferences.h>
+#include <libnautilus-extensions/nautilus-gnome-extensions.h>
#include <libnautilus-extensions/nautilus-gtk-extensions.h>
#include <libnautilus-extensions/nautilus-gtk-macros.h>
-#include <libnautilus-extensions/nautilus-gnome-extensions.h>
#include <libnautilus-extensions/nautilus-metadata.h>
#include <libnautilus-extensions/nautilus-string.h>
#include <libnautilus-extensions/nautilus-xml-extensions.h>
@@ -161,6 +162,7 @@ nautilus_property_browser_initialize (GtkObject *object)
NautilusPropertyBrowser *property_browser;
char *image_file_name;
GtkWidget* widget, *temp_hbox, *temp_frame;
+ GdkFont *font;
property_browser = NAUTILUS_PROPERTY_BROWSER (object);
widget = GTK_WIDGET (object);
@@ -224,8 +226,12 @@ nautilus_property_browser_initialize (GtkObject *object)
/* add the title label */
property_browser->details->title_label = gtk_label_new (_("Select A Category:"));
- /* FIXME bugzilla.eazel.com 667: Hardcoded font. */
- nautilus_gtk_widget_set_font_by_name(property_browser->details->title_label, "-*-helvetica-medium-r-normal-*-18-*-*-*-*-*-*-*");
+
+
+ font = nautilus_font_factory_get_font_from_preferences (18);
+ nautilus_gtk_widget_set_font(property_browser->details->title_label, font);
+ gdk_font_unref (font);
+
gtk_widget_show(property_browser->details->title_label);
gtk_box_pack_start (GTK_BOX(temp_hbox), property_browser->details->title_label, FALSE, FALSE, 8);
diff --git a/src/nautilus-sidebar-title.c b/src/nautilus-sidebar-title.c
index c49f1f17b..87edd835a 100644
--- a/src/nautilus-sidebar-title.c
+++ b/src/nautilus-sidebar-title.c
@@ -43,6 +43,7 @@
#include <libnautilus-extensions/nautilus-directory.h>
#include <libnautilus-extensions/nautilus-icon-factory.h>
#include <libnautilus-extensions/nautilus-metadata.h>
+#include <libnautilus-extensions/nautilus-font-factory.h>
static void nautilus_index_title_initialize_class (NautilusIndexTitleClass *klass);
static void nautilus_index_title_destroy (GtkObject *object);
@@ -268,6 +269,7 @@ nautilus_index_title_update_info (NautilusIndexTitle *index_title)
char *notes_text;
char *temp_string;
char *info_string;
+ GdkFont *font;
/* NULL can happen because nautilus_file_get returns NULL for the root. */
file = index_title->details->file;
@@ -334,12 +336,10 @@ nautilus_index_title_update_info (NautilusIndexTitle *index_title)
gtk_box_pack_start (GTK_BOX (index_title), index_title->details->more_info, 0, 0, 0);
gtk_box_reorder_child (GTK_BOX (index_title), index_title->details->more_info, 2);
}
-
- /* FIXME bugzilla.eazel.com 667:
- * don't use hardwired font like this - get it from preferences
- */
- nautilus_gtk_widget_set_font_by_name (index_title->details->more_info,
- "-*-helvetica-medium-r-normal-*-12-*-*-*-*-*-*-*");
+
+ font = nautilus_font_factory_get_font_from_preferences (12);
+ nautilus_gtk_widget_set_font (index_title->details->more_info, font);
+ gdk_font_unref (font);
g_free(info_string);
@@ -356,11 +356,9 @@ nautilus_index_title_update_info (NautilusIndexTitle *index_title)
gtk_box_reorder_child (GTK_BOX (index_title), index_title->details->notes, 3);
}
- /* FIXME bugzilla.eazel.com 667:
- * don't use hardwired font like this - get it from preferences
- */
- nautilus_gtk_widget_set_font_by_name (index_title->details->notes,
- "-*-helvetica-medium-r-normal-*-12-*-*-*-*-*-*-*");
+ font = nautilus_font_factory_get_font_from_preferences (12);
+ nautilus_gtk_widget_set_font (index_title->details->notes, font);
+ gdk_font_unref (font);
g_free (notes_text);
} else if (index_title->details->notes != NULL) {