summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRamiro Estrugo <ramiro@eazel.com>2001-03-03 03:49:25 +0000
committerRamiro Estrugo <ramiro@src.gnome.org>2001-03-03 03:49:25 +0000
commita5eedddc21e6f257f21ed4bb29bcc8fbd507084e (patch)
tree1c7c0b29aab0f4602b321cf0d486635aebdcb792
parent8eb6d4160dbdb21cb149ae6ddbdc9b5daa64ee52 (diff)
downloadnautilus-a5eedddc21e6f257f21ed4bb29bcc8fbd507084e.tar.gz
reviewed by: <delete if not using a buddy>
2001-03-02 Ramiro Estrugo <ramiro@eazel.com> reviewed by: <delete if not using a buddy> Bug 2673 - Need to hook up the new font picker to nautilus . * configure.in: Remove an old font setup hack that never really worked. * data/fonts/urw/fonts.dir: Rename the fonts to "Helvetica Default" in order not to clash with system fonts. * libnautilus-extensions/nautilus-font-manager.h: * libnautilus-extensions/nautilus-font-manager.c: (font_description_new): Add a font type parameter. (font_lists_total_num_fonts): New function to count the total number of scalable fonts detetected. (font_description_table_add): Pass in the detected font lists to do reality checks. (font_get_font_type): New function. (font_description_table_get_length), (font_description_table_peek_nth), (font_description_table_get_nth_file_name): Name the parameters more consistently. (font_description_table_for_each): Add font type parameter (font_description_table_new): Rework to not require storing the detected font list. We now use that only for the duration of the constructor. Lost the install_font_lists dumbness. (font_server_for_each_font_directory_internal): Use g_warning instead of g_print. (font_ignore_directory): New function to determine whether we should ignore a directory - makes things much faster. (font_manager_collect_font_tables): New function to handle all the work of collecting font directories into tables. (font_server_for_each_callback), (font_table_list_free), (font_table_list_for_each), (free_font_tables), (ensure_at_exit_handler), (ensure_fallback_font_table), (ensure_user_font_table), (ensure_system_font_tables): Add 3 tables for fallback, system and users fonts. These are populated as needed. (nautilus_font_manager_for_each_font): Iterate the 3 font talbles. (nautilus_font_manager_get_fallback_font) : New function to obtain a fallback font quickly without having to check the system. (call_chop_off_comments), (nautilus_self_check_font_manager): Rework the checks to not create a temp directory. Unfortunately they now only run for me. * libnautilus-extensions/nautilus-font-picker.h: * libnautilus-extensions/nautilus-font-picker.c: (nautilus_font_picker_initialize_class), (nautilus_font_picker_initialize), (nautilus_font_picker_destroy), (font_entry_list_find), (font_picker_update), (font_name_picker_changed_callback), (style_picker_changed_callback), (ignore_font), (font_manager_callback), (style_list_for_each_callback), (font_entry_list_for_each_callback), (nautilus_font_picker_get_selected_font), (nautilus_font_picker_set_selected_font), (nautilus_font_picker_set_title_label): Use the new font manager. * libnautilus-extensions/nautilus-global-preferences.h: * libnautilus-extensions/nautilus-global-preferences.c: (global_preferences_install_descriptions), (global_preferences_install_defaults), (global_preferences_create_dialog), (appearnace_pane_update), (global_preferences_create_font_group), (global_preferences_install_home_location_defaults), (global_preferences_install_font_defaults): Add a new preference for the smooth font. Factor our the default font code to its own function. Setup the font pickers items to be mutually exclusive according to the smooth graphics mode preference value. * libnautilus-extensions/nautilus-gtk-extensions.h: * libnautilus-extensions/nautilus-gtk-extensions.c: (nautilus_gtk_widget_set_shown): New function to show or hide a widget in one go. * libnautilus-extensions/nautilus-preferences-group.c: (nautilus_preferences_group_update): Dont show the widget if a controlling preference prevents it. * libnautilus-extensions/nautilus-preferences-item.h: * libnautilus-extensions/nautilus-preferences-item.c: (preferences_item_update_smooth_font), (preferences_smooth_font_changed_callback), (preferences_item_create_smooth_font): Add support for a smooth font picker. (preferences_item_destroy), (preferences_item_construct), (nautilus_preferences_item_set_control_preference), (nautilus_preferences_item_set_control_action), (nautilus_preferences_item_get_control_showing): Add support for using a controlling preference which can force the widget to be shown or hidden depending on its value. * libnautilus-extensions/nautilus-preferences-pane.c: (nautilus_preferences_pane_update): Use new gtk extension to show or hide the widget in one go. * libnautilus-extensions/nautilus-scalable-font.h: * libnautilus-extensions/nautilus-scalable-font.c: (font_family_string_map_new): Update fallback font name. (nautilus_scalable_font_new_from_file_name): New function to create a font directly from a font file name. (nautilus_scalable_font_get_default_font): Update fallback font name. (nautilus_scalable_font_get_default_bold_font): New function to get a fallback bold font. Remove some unsed functions. Remove the font setup hack, the font manager takes care of that now. * libnautilus-extensions/nautilus-string-picker.h: * libnautilus-extensions/nautilus-string-picker.c: (nautilus_string_picker_clear): New function to clear the string picker. * libnautilus-extensions/nautilus-tabs.c: (nautilus_tabs_initialize): Fix the hard coded font name. * src/nautilus-first-time-druid.c: (new_title_label): Fix the hard coded font name. * src/nautilus-sidebar-tabs.c: (nautilus_sidebar_tabs_load_theme_data): Fix the hard coded font name. * test/Makefile.am: * test/test-nautilus-font-manager.c: (font_type_to_string), (font_iterator_callback), (font_table_for_each_callback), (main): * test/test-nautilus-font-picker.c: (font_picker_changed_callback), (main): * test/test-nautilus-glyph-simple.c: (main): * test/test-nautilus-label.c: (main): Update for new font picker and font manager changes.
-rw-r--r--ChangeLog137
-rw-r--r--configure.in6
-rw-r--r--data/fonts/urw/fonts.dir8
-rw-r--r--libnautilus-extensions/nautilus-font-manager.c653
-rw-r--r--libnautilus-extensions/nautilus-font-manager.h33
-rw-r--r--libnautilus-extensions/nautilus-font-picker.c592
-rw-r--r--libnautilus-extensions/nautilus-font-picker.h43
-rw-r--r--libnautilus-extensions/nautilus-global-preferences.c91
-rw-r--r--libnautilus-extensions/nautilus-global-preferences.h1
-rw-r--r--libnautilus-extensions/nautilus-gtk-extensions.c19
-rw-r--r--libnautilus-extensions/nautilus-gtk-extensions.h2
-rw-r--r--libnautilus-extensions/nautilus-preferences-group.c17
-rw-r--r--libnautilus-extensions/nautilus-preferences-item.c128
-rw-r--r--libnautilus-extensions/nautilus-preferences-item.h20
-rw-r--r--libnautilus-extensions/nautilus-preferences-pane.c10
-rw-r--r--libnautilus-extensions/nautilus-scalable-font.c88
-rw-r--r--libnautilus-extensions/nautilus-scalable-font.h7
-rw-r--r--libnautilus-extensions/nautilus-string-picker.c24
-rw-r--r--libnautilus-extensions/nautilus-string-picker.h34
-rw-r--r--libnautilus-extensions/nautilus-tabs.c4
-rw-r--r--libnautilus-private/nautilus-font-manager.c653
-rw-r--r--libnautilus-private/nautilus-font-manager.h33
-rw-r--r--libnautilus-private/nautilus-font-picker.c592
-rw-r--r--libnautilus-private/nautilus-font-picker.h43
-rw-r--r--libnautilus-private/nautilus-global-preferences.c91
-rw-r--r--libnautilus-private/nautilus-global-preferences.h1
-rw-r--r--libnautilus-private/nautilus-gtk-extensions.c19
-rw-r--r--libnautilus-private/nautilus-gtk-extensions.h2
-rw-r--r--libnautilus-private/nautilus-preferences-group.c17
-rw-r--r--libnautilus-private/nautilus-preferences-item.c128
-rw-r--r--libnautilus-private/nautilus-preferences-item.h20
-rw-r--r--libnautilus-private/nautilus-preferences-pane.c10
-rw-r--r--libnautilus-private/nautilus-scalable-font.c88
-rw-r--r--libnautilus-private/nautilus-scalable-font.h7
-rw-r--r--libnautilus-private/nautilus-string-picker.c24
-rw-r--r--libnautilus-private/nautilus-string-picker.h34
-rw-r--r--libnautilus-private/nautilus-tabs.c4
-rw-r--r--src/nautilus-first-time-druid.c4
-rw-r--r--src/nautilus-sidebar-tabs.c4
-rw-r--r--test/Makefile.am2
-rw-r--r--test/test-nautilus-font-manager.c118
-rw-r--r--test/test-nautilus-font-picker.c80
-rw-r--r--test/test-nautilus-glyph-simple.c14
-rw-r--r--test/test-nautilus-label.c109
44 files changed, 2447 insertions, 1567 deletions
diff --git a/ChangeLog b/ChangeLog
index e8d393b27..79c1b67be 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,140 @@
+2001-03-02 Ramiro Estrugo <ramiro@eazel.com>
+
+ reviewed by: <delete if not using a buddy>
+
+ Bug 2673 - Need to hook up the new font picker to nautilus .
+
+ * configure.in:
+ Remove an old font setup hack that never really worked.
+
+ * data/fonts/urw/fonts.dir:
+ Rename the fonts to "Helvetica Default" in order not to clash with
+ system fonts.
+
+ * libnautilus-extensions/nautilus-font-manager.h:
+ * libnautilus-extensions/nautilus-font-manager.c:
+ (font_description_new): Add a font type parameter.
+ (font_lists_total_num_fonts): New function to count the total
+ number of scalable fonts detetected.
+ (font_description_table_add): Pass in the detected font lists to
+ do reality checks.
+ (font_get_font_type): New function.
+ (font_description_table_get_length),
+ (font_description_table_peek_nth),
+ (font_description_table_get_nth_file_name): Name the parameters
+ more consistently.
+ (font_description_table_for_each): Add font type parameter
+ (font_description_table_new): Rework to not require storing the
+ detected font list. We now use that only for the duration of the
+ constructor. Lost the install_font_lists dumbness.
+ (font_server_for_each_font_directory_internal): Use g_warning
+ instead of g_print.
+ (font_ignore_directory): New function to determine whether we
+ should ignore a directory - makes things much faster.
+ (font_manager_collect_font_tables): New function to handle all the
+ work of collecting font directories into tables.
+ (font_server_for_each_callback), (font_table_list_free),
+ (font_table_list_for_each), (free_font_tables),
+ (ensure_at_exit_handler), (ensure_fallback_font_table),
+ (ensure_user_font_table), (ensure_system_font_tables): Add 3
+ tables for fallback, system and users fonts. These are populated
+ as needed.
+ (nautilus_font_manager_for_each_font): Iterate the 3 font talbles.
+ (nautilus_font_manager_get_fallback_font) : New function to obtain
+ a fallback font quickly without having to check the system.
+ (call_chop_off_comments), (nautilus_self_check_font_manager):
+ Rework the checks to not create a temp directory. Unfortunately
+ they now only run for me.
+
+ * libnautilus-extensions/nautilus-font-picker.h:
+ * libnautilus-extensions/nautilus-font-picker.c:
+ (nautilus_font_picker_initialize_class),
+ (nautilus_font_picker_initialize), (nautilus_font_picker_destroy),
+ (font_entry_list_find), (font_picker_update),
+ (font_name_picker_changed_callback),
+ (style_picker_changed_callback), (ignore_font),
+ (font_manager_callback), (style_list_for_each_callback),
+ (font_entry_list_for_each_callback),
+ (nautilus_font_picker_get_selected_font),
+ (nautilus_font_picker_set_selected_font),
+ (nautilus_font_picker_set_title_label):
+ Use the new font manager.
+
+ * libnautilus-extensions/nautilus-global-preferences.h:
+ * libnautilus-extensions/nautilus-global-preferences.c:
+ (global_preferences_install_descriptions),
+ (global_preferences_install_defaults),
+ (global_preferences_create_dialog), (appearnace_pane_update),
+ (global_preferences_create_font_group),
+ (global_preferences_install_home_location_defaults),
+ (global_preferences_install_font_defaults):
+ Add a new preference for the smooth font.
+ Factor our the default font code to its own function. Setup the
+ font pickers items to be mutually exclusive according to the
+ smooth graphics mode preference value.
+
+ * libnautilus-extensions/nautilus-gtk-extensions.h:
+ * libnautilus-extensions/nautilus-gtk-extensions.c:
+ (nautilus_gtk_widget_set_shown):
+ New function to show or hide a widget in one go.
+
+ * libnautilus-extensions/nautilus-preferences-group.c:
+ (nautilus_preferences_group_update):
+ Dont show the widget if a controlling preference prevents it.
+
+ * libnautilus-extensions/nautilus-preferences-item.h:
+ * libnautilus-extensions/nautilus-preferences-item.c:
+ (preferences_item_update_smooth_font),
+ (preferences_smooth_font_changed_callback),
+ (preferences_item_create_smooth_font): Add support for a smooth
+ font picker.
+ (preferences_item_destroy), (preferences_item_construct),
+ (nautilus_preferences_item_set_control_preference),
+ (nautilus_preferences_item_set_control_action),
+ (nautilus_preferences_item_get_control_showing): Add support for
+ using a controlling preference which can force the widget to be
+ shown or hidden depending on its value.
+
+ * libnautilus-extensions/nautilus-preferences-pane.c:
+ (nautilus_preferences_pane_update):
+ Use new gtk extension to show or hide the widget in one go.
+
+ * libnautilus-extensions/nautilus-scalable-font.h:
+ * libnautilus-extensions/nautilus-scalable-font.c:
+ (font_family_string_map_new): Update fallback font name.
+ (nautilus_scalable_font_new_from_file_name): New function to
+ create a font directly from a font file name.
+ (nautilus_scalable_font_get_default_font): Update fallback font name.
+ (nautilus_scalable_font_get_default_bold_font): New function to
+ get a fallback bold font.
+ Remove some unsed functions. Remove the font setup hack, the font
+ manager takes care of that now.
+
+ * libnautilus-extensions/nautilus-string-picker.h:
+ * libnautilus-extensions/nautilus-string-picker.c:
+ (nautilus_string_picker_clear):
+ New function to clear the string picker.
+
+ * libnautilus-extensions/nautilus-tabs.c:
+ (nautilus_tabs_initialize):
+ Fix the hard coded font name.
+
+ * src/nautilus-first-time-druid.c: (new_title_label):
+ Fix the hard coded font name.
+
+ * src/nautilus-sidebar-tabs.c:
+ (nautilus_sidebar_tabs_load_theme_data):
+ Fix the hard coded font name.
+
+ * test/Makefile.am:
+ * test/test-nautilus-font-manager.c: (font_type_to_string),
+ (font_iterator_callback), (font_table_for_each_callback), (main):
+ * test/test-nautilus-font-picker.c: (font_picker_changed_callback),
+ (main):
+ * test/test-nautilus-glyph-simple.c: (main):
+ * test/test-nautilus-label.c: (main):
+ Update for new font picker and font manager changes.
+
2001-03-02 Darin Adler <darin@eazel.com>
reviewed by: Arik Devens <arik@eazel.com>
diff --git a/configure.in b/configure.in
index 74928dc92..c55a79c0c 100644
--- a/configure.in
+++ b/configure.in
@@ -147,12 +147,6 @@ dnl ====================================
dnl = End profiling support
dnl ====================================
-
-dnl Check for "RedHat-style" font setup
-AM_CONDITIONAL(TYPE1_FONT_DIR_EXISTS, test -d /usr/share/fonts/default/Type1)
-
-
-
dnl ====================================
dnl = Check for different mount systems
dnl ====================================
diff --git a/data/fonts/urw/fonts.dir b/data/fonts/urw/fonts.dir
index fbc57d8fd..bd923b5ff 100644
--- a/data/fonts/urw/fonts.dir
+++ b/data/fonts/urw/fonts.dir
@@ -1,5 +1,5 @@
4
-n019003l.pfb -URW-Helvetica-medium-r-normal--0-0-0-0-p-0-iso8859-1
-n019004l.pfb -URW-Helvetica-bold-r-normal--0-0-0-0-p-0-iso8859-1
-n019023l.pfb -URW-Helvetica-medium-o-normal--0-0-0-0-p-0-iso8859-1
-n019024l.pfb -URW-Helvetica-bold-o-normal--0-0-0-0-p-0-iso8859-1
+n019003l.pfb -URW-Helvetica Default-medium-r-normal--0-0-0-0-p-0-iso8859-1
+n019004l.pfb -URW-Helvetica Default-bold-r-normal--0-0-0-0-p-0-iso8859-1
+n019023l.pfb -URW-Helvetica Default-medium-o-normal--0-0-0-0-p-0-iso8859-1
+n019024l.pfb -URW-Helvetica Default-bold-o-normal--0-0-0-0-p-0-iso8859-1
diff --git a/libnautilus-extensions/nautilus-font-manager.c b/libnautilus-extensions/nautilus-font-manager.c
index 331f58190..7b2c64db4 100644
--- a/libnautilus-extensions/nautilus-font-manager.c
+++ b/libnautilus-extensions/nautilus-font-manager.c
@@ -19,16 +19,18 @@
write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.
- Authors: Ramiro Estrugo <ramiro@eazel.com>
+ Authors: Pavel Cisler <pavel@eazel.com>,
+ Ramiro Estrugo <ramiro@eazel.com>
*/
#include <config.h>
#include "nautilus-font-manager.h"
-#include "nautilus-string.h"
-#include "nautilus-string-list.h"
-#include "nautilus-lib-self-check-functions.h"
-#include "nautilus-file-utilities.h"
+#include "nautilus-file-utilities.h"
+#include "nautilus-glib-extensions.h"
+#include "nautilus-lib-self-check-functions.h"
+#include "nautilus-string-list.h"
+#include "nautilus-string.h"
#include <libgnome/gnome-util.h>
#include <ctype.h>
#include <stdio.h>
@@ -48,8 +50,21 @@
#define FONTS_ALIAS_FILE_NAME "fonts.alias"
#define FONTS_SCALE_FILE_NAME "fonts.scale"
+#define FONT_SERVER_CONFIG_FILE "/etc/X11/fs/config"
+#define FALLBACK_FONT_DIRECTORY (NAUTILUS_DATADIR "/fonts/urw")
+#define USER_FONT_DIRECTORY_NAME "fonts"
+
+#define NAUTILUS_FONT_UNDEFINED ((NautilusFontType) 0)
+
+/*
+ * FontDescription:
+ *
+ * A structure that describes a single font entry;
+ *
+ */
typedef struct {
char *file_name;
+ NautilusFontType font_type;
char *foundry;
char *family;
char *weight;
@@ -59,47 +74,56 @@ typedef struct {
char *char_set_encoding;
} FontDescription;
+/*
+ * FontDescriptionTable:
+ *
+ * A table of 0 or more font descriptions.
+ *
+ */
typedef struct {
char *directory;
char *fonts_dir_file;
char *fonts_alias_file;
char *fonts_scale_file;
GList *descriptions;
- GList *postscript_font_list;
- GList *true_type_font_list;
} FontDescriptionTable;
-static gboolean string_is_valid (const char *string);
-static char * file_as_string (const char *file_name);
-static gboolean directory_contains_file (const char *directory,
- const char *file_name);
-static FontDescription * font_description_new (const char *font_file_name,
- const char *xlfd_string);
-static void font_description_free (FontDescription *description);
-static void font_description_table_for_each (const FontDescriptionTable *description_table,
- NautilusFontManagerIterationCallback callback,
- gpointer callback_data);
-static char *font_description_get_file_name (const FontDescription *description);
-static char *font_description_get_foundry (const FontDescription *description);
-static char *font_description_get_family (const FontDescription *description);
-static char *font_description_get_weight (const FontDescription *description);
-static char *font_description_get_slant (const FontDescription *description);
-static char *font_description_get_set_width (const FontDescription *description);
-static char *font_description_get_char_set_registry (const FontDescription *description);
-static char *font_description_get_char_set_encoding (const FontDescription *description);
-static FontDescriptionTable * font_description_table_new (const char *font_directory);
-static void font_description_table_install_font_lists (FontDescriptionTable *table,
- GList *postscript_font_list,
- GList *true_type_font_list);
-static void font_description_table_add (FontDescriptionTable *description_table,
- const char *line);
-static guint font_description_table_get_length (const FontDescriptionTable *description_table);
-static const FontDescription * font_description_table_peek_nth (const FontDescriptionTable *description_table,
- guint n);
-static char * font_description_table_get_nth_file_name (const FontDescriptionTable *description_table,
- guint n);
-static void font_description_table_free (FontDescriptionTable *table);
-static void font_description_table_clear (FontDescriptionTable *table);
+static gboolean string_is_valid (const char *string);
+static char * file_as_string (const char *file_name);
+static gboolean directory_contains_file (const char *directory,
+ const char *file_name);
+static FontDescription * font_description_new (const char *font_file_name,
+ NautilusFontType font_type,
+ const char *xlfd_string);
+static void font_description_free (FontDescription *description);
+static void font_description_table_for_each (const FontDescriptionTable *description_table,
+ NautilusFontManagerCallback callback,
+ gpointer callback_data);
+static char *font_description_get_file_name (const FontDescription *description);
+static char *font_description_get_foundry (const FontDescription *description);
+static char *font_description_get_family (const FontDescription *description);
+static char *font_description_get_weight (const FontDescription *description);
+static char *font_description_get_slant (const FontDescription *description);
+static char *font_description_get_set_width (const FontDescription *description);
+static char *font_description_get_char_set_registry (const FontDescription *description);
+static char *font_description_get_char_set_encoding (const FontDescription *description);
+static FontDescriptionTable * font_description_table_new (const char *font_directory,
+ const GList *postscript_font_list,
+ const GList *true_type_font_list);
+static void font_description_table_add (FontDescriptionTable *description_table,
+ const char *line,
+ const GList *postscript_font_list,
+ const GList *true_type_font_list);
+static NautilusFontType font_get_font_type (const char *font_file_name,
+ const GList *postscript_font_list,
+ const GList *true_type_font_list);
+static guint font_description_table_get_length (const FontDescriptionTable *description_table);
+static const FontDescription * font_description_table_peek_nth (const FontDescriptionTable *description_table,
+ guint n);
+static char * font_description_table_get_nth_file_name (const FontDescriptionTable *table,
+ guint n);
+static void font_description_table_free (FontDescriptionTable *table);
+static void font_description_table_clear (FontDescriptionTable *table);
static gboolean
string_is_valid (const char *string)
@@ -150,6 +174,7 @@ file_as_string (const char *file_name)
static FontDescription *
font_description_new (const char *font_file_name,
+ NautilusFontType font_type,
const char *xlfd_string)
{
FontDescription *font_description = NULL;
@@ -157,12 +182,15 @@ font_description_new (const char *font_file_name,
g_return_val_if_fail (string_is_valid (font_file_name), NULL);
g_return_val_if_fail (string_is_valid (xlfd_string), NULL);
+ g_return_val_if_fail (font_type == NAUTILUS_FONT_POSTSCRIPT
+ || font_type == NAUTILUS_FONT_TRUE_TYPE, NULL);
tokenized_xlfd = nautilus_string_list_new_from_tokens (xlfd_string, "-", FALSE);
if (nautilus_string_list_get_length (tokenized_xlfd) == (XLFD_INDEX_MAX + 1)) {
font_description = g_new0 (FontDescription, 1);
- font_description->file_name = g_strdup (font_file_name);
+ font_description->file_name = g_strdup (font_file_name);
+ font_description->font_type = font_type;
font_description->foundry = nautilus_string_list_nth (tokenized_xlfd, XLFD_INDEX_FOUNDRY);
font_description->family = nautilus_string_list_nth (tokenized_xlfd, XLFD_INDEX_FAMILY);
font_description->weight = nautilus_string_list_nth (tokenized_xlfd, XLFD_INDEX_WEIGHT);
@@ -259,16 +287,29 @@ font_description_get_char_set_encoding (const FontDescription *description)
return g_strdup (description->char_set_encoding);
}
+static guint
+font_lists_total_num_fonts (const GList *postscript_font_list,
+ const GList *true_type_font_list)
+{
+ return g_list_length ((GList *) postscript_font_list)
+ + g_list_length ((GList *) true_type_font_list);
+}
+
static void
-font_description_table_add (FontDescriptionTable *description_table,
- const char *line)
+font_description_table_add (FontDescriptionTable *table,
+ const char *line,
+ const GList *postscript_font_list,
+ const GList *true_type_font_list)
{
char *font_file_name = NULL;
FontDescription *description;
char *xlfd_delimeter;
+ char *font_file_full_path;
+ NautilusFontType font_type;
- g_return_if_fail (description_table != NULL);
+ g_return_if_fail (table != NULL);
g_return_if_fail (string_is_valid (line));
+ g_return_if_fail (font_lists_total_num_fonts (postscript_font_list, true_type_font_list) > 0);
xlfd_delimeter = strstr (line, " ");
@@ -282,46 +323,81 @@ font_description_table_add (FontDescriptionTable *description_table,
while (isspace ((guchar) *xlfd_delimeter)) {
xlfd_delimeter++;
}
-
- description = font_description_new (font_file_name, xlfd_delimeter);
- if (description != NULL) {
- description_table->descriptions = g_list_append (description_table->descriptions,
- description);
+ font_file_full_path = nautilus_make_path (table->directory, font_file_name);
+ font_type = font_get_font_type (font_file_full_path,
+ postscript_font_list,
+ true_type_font_list);
+
+ if (font_type != NAUTILUS_FONT_UNDEFINED) {
+ description = font_description_new (font_file_full_path, font_type, xlfd_delimeter);
+ if (description != NULL) {
+ table->descriptions = g_list_append (table->descriptions, description);
+ }
}
+ g_free (font_file_full_path);
g_free (font_file_name);
}
+static NautilusFontType
+font_get_font_type (const char *font_file_name,
+ const GList *postscript_font_list,
+ const GList *true_type_font_list)
+{
+ const GList *node;
+
+ g_return_val_if_fail (string_is_valid (font_file_name), NAUTILUS_FONT_UNDEFINED);
+ g_return_val_if_fail (font_lists_total_num_fonts (postscript_font_list, true_type_font_list) > 0,
+ NAUTILUS_FONT_UNDEFINED);
+
+ node = postscript_font_list;
+ while (node != NULL) {
+ if (nautilus_istr_is_equal (node->data, font_file_name)) {
+ return NAUTILUS_FONT_POSTSCRIPT;
+ }
+ node = node->next;
+ }
+
+ node = true_type_font_list;
+ while (node != NULL) {
+ if (nautilus_istr_is_equal (node->data, font_file_name)) {
+ return NAUTILUS_FONT_TRUE_TYPE;
+ }
+ node = node->next;
+ }
+
+ return NAUTILUS_FONT_UNDEFINED;
+}
+
static guint
-font_description_table_get_length (const FontDescriptionTable *description_table)
+font_description_table_get_length (const FontDescriptionTable *table)
{
- g_return_val_if_fail (description_table != NULL, 0);
+ g_return_val_if_fail (table != NULL, 0);
- return g_list_length (description_table->descriptions);
+ return g_list_length (table->descriptions);
}
static const FontDescription *
-font_description_table_peek_nth (const FontDescriptionTable *description_table,
+font_description_table_peek_nth (const FontDescriptionTable *table,
guint n)
{
- g_return_val_if_fail (description_table != NULL, NULL);
- g_return_val_if_fail (n < font_description_table_get_length (description_table), NULL);
+ g_return_val_if_fail (table != NULL, NULL);
+ g_return_val_if_fail (n < font_description_table_get_length (table), NULL);
- return g_list_nth_data (description_table->descriptions, n);
+ return g_list_nth_data (table->descriptions, n);
}
static char *
-font_description_table_get_nth_file_name (const FontDescriptionTable *description_table,
- guint n)
+font_description_table_get_nth_file_name (const FontDescriptionTable *table,
+ guint n)
{
const FontDescription *description;
- g_return_val_if_fail (description_table != NULL, NULL);
- g_return_val_if_fail (n < font_description_table_get_length (description_table), NULL);
+ g_return_val_if_fail (table != NULL, NULL);
+ g_return_val_if_fail (n < font_description_table_get_length (table), NULL);
- description = font_description_table_peek_nth (description_table, n);
-
+ description = font_description_table_peek_nth (table, n);
return g_strdup (description->file_name);
}
@@ -364,22 +440,24 @@ font_description_table_clear (FontDescriptionTable *table)
}
static void
-font_description_table_for_each (const FontDescriptionTable *description_table,
- NautilusFontManagerIterationCallback callback,
+font_description_table_for_each (const FontDescriptionTable *table,
+ NautilusFontManagerCallback callback,
gpointer callback_data)
{
GList *node;
const FontDescription *description;
- g_return_if_fail (description_table != NULL);
+ g_return_if_fail (table != NULL);
g_return_if_fail (callback != NULL);
- node = description_table->descriptions;
+ node = table->descriptions;
while (node != NULL) {
description = node->data;
g_assert (node->data != NULL);
- (* callback) (description->foundry,
+ (* callback) (description->file_name,
+ description->font_type,
+ description->foundry,
description->family,
description->weight,
description->slant,
@@ -393,97 +471,83 @@ font_description_table_for_each (const FontDescriptionTable *description_table,
}
static FontDescriptionTable *
-table_new_from_contents (const char *contents)
+font_description_table_new (const char *font_directory,
+ const GList *postscript_font_list,
+ const GList *true_type_font_list)
{
- FontDescriptionTable *description_table;
+ FontDescriptionTable *table;
+ char *description_file;
+ char *description_contents;
NautilusStringList *tokenized_contents;
int i;
int count;
char *line;
- g_return_val_if_fail (string_is_valid (contents), NULL);
+ g_return_val_if_fail (string_is_valid (font_directory), NULL);
+ g_return_val_if_fail (g_file_test (font_directory, G_FILE_TEST_ISDIR), NULL);
+
+ description_file = nautilus_make_path (font_directory, FONTS_DIR_FILE_NAME);
+ description_contents = file_as_string (description_file);
+
+ if (description_contents == NULL) {
+ g_free (description_file);
+ return NULL;
+ }
- tokenized_contents = nautilus_string_list_new_from_tokens (contents, "\n", FALSE);
+ tokenized_contents = nautilus_string_list_new_from_tokens (description_contents, "\n", FALSE);
/* Make sure there is at least one description. Item 0 is the count */
if (nautilus_string_list_get_length (tokenized_contents) <= 1) {
+ g_free (description_file);
+ g_free (description_contents);
nautilus_string_list_free (tokenized_contents);
return NULL;
}
/* Find out how many font entries are described in this file */
if (!nautilus_string_list_nth_as_integer (tokenized_contents, 0, &count)) {
+ g_free (description_file);
+ g_free (description_contents);
nautilus_string_list_free (tokenized_contents);
return NULL;
}
- description_table = g_new0 (FontDescriptionTable, 1);
+ /* Create a new table */
+ table = g_new0 (FontDescriptionTable, 1);
+ /* Assign the directory and description file */
+ table->directory = g_strdup (font_directory);
+ table->fonts_dir_file = description_file;
+
+ /* Iterate throught the description file contents */
for (i = 0; i < count; i++) {
line = nautilus_string_list_nth (tokenized_contents, i + 1);
-
if (line != NULL) {
- font_description_table_add (description_table, line);
+ font_description_table_add (table,
+ line,
+ postscript_font_list,
+ true_type_font_list);
}
-
g_free (line);
}
-
nautilus_string_list_free (tokenized_contents);
- return description_table;
-}
-
-static FontDescriptionTable *
-font_description_table_new (const char *font_directory)
-{
- FontDescriptionTable *table;
- char *description_file;
- char *description_contents;
-
- g_return_val_if_fail (string_is_valid (font_directory), NULL);
- g_return_val_if_fail (g_file_test (font_directory, G_FILE_TEST_ISDIR), NULL);
-
- description_file = nautilus_make_path (font_directory, FONTS_DIR_FILE_NAME);
- description_contents = file_as_string (description_file);
+ /* Assign the alias file if found */
+ if (directory_contains_file (font_directory, FONTS_ALIAS_FILE_NAME)) {
+ table->fonts_alias_file = nautilus_make_path (font_directory, FONTS_ALIAS_FILE_NAME);
+ }
- if (description_contents == NULL) {
- g_free (description_file);
- return NULL;
+ /* Assign the alias scale if found */
+ if (directory_contains_file (font_directory, FONTS_SCALE_FILE_NAME)) {
+ table->fonts_scale_file = nautilus_make_path (font_directory, FONTS_SCALE_FILE_NAME);
}
- table = table_new_from_contents (description_contents);
+ g_free (description_contents);
- if (table != NULL) {
- table->fonts_dir_file = nautilus_make_path (font_directory, FONTS_DIR_FILE_NAME);
-
- /* Assign the alias file if found */
- if (directory_contains_file (font_directory, FONTS_ALIAS_FILE_NAME)) {
- table->fonts_alias_file = nautilus_make_path (font_directory, FONTS_ALIAS_FILE_NAME);
- }
-
- /* Assign the alias scale if found */
- if (directory_contains_file (font_directory, FONTS_SCALE_FILE_NAME)) {
- table->fonts_scale_file = nautilus_make_path (font_directory, FONTS_SCALE_FILE_NAME);
- }
- }
return table;
}
-static void
-font_description_table_install_font_lists (FontDescriptionTable *table,
- GList *postscript_font_list,
- GList *true_type_font_list)
-{
- g_return_if_fail (table != NULL);
- g_return_if_fail (table->postscript_font_list == NULL);
- g_return_if_fail (table->true_type_font_list == NULL);
-
- table->postscript_font_list = postscript_font_list;
- table->true_type_font_list = true_type_font_list;
-}
-
static GnomeVFSResult
collect_fonts_from_directory (const char *font_directory,
GList **postscript_font_list,
@@ -660,7 +724,7 @@ font_server_for_each_font_directory_internal (void (* callback) (const char *fon
fgets (buffer, READ_BUFFER_SIZE, file);
if (strlen (buffer) == 0) {
if (state != EXPECT_COMMA) {
- g_print ("unexpected file end\n");
+ g_warning ("unexpected file end.");
}
break;
}
@@ -684,7 +748,7 @@ font_server_for_each_font_directory_internal (void (* callback) (const char *fon
case EXPECT_ASSIGNMENT:
if (!token_matches(buffer, token_start, token_end, "=")) {
- g_print (" expected token \"=\" \n");
+ g_warning (" expected token \"=\" .");
return;
}
state = EXPECT_DIRECTORY;
@@ -692,7 +756,7 @@ font_server_for_each_font_directory_internal (void (* callback) (const char *fon
case EXPECT_DIRECTORY:
if (token_matches(buffer, token_start, token_end, ",")) {
- g_print (" expected directory name \n");
+ g_warning (" expected directory name.");
return;
}
/* found a directory, call an each function on it */
@@ -762,22 +826,50 @@ directory_contains_file (const char *directory,
return result;
}
-static void
-font_server_for_each_callback (const char *font_directory,
- gpointer callback_data)
+/* Iterating directories is slow cause of all the mim sniffing that
+ * has to happen on each potential scalalble font. By Ignoring
+ * directories known to be without scalable fonts, we make things
+ * much faster.
+ */
+static gboolean
+font_ignore_directory (const char *font_directory)
{
- FontDescriptionTable *table;
+ g_return_val_if_fail (string_is_valid (font_directory), TRUE);
- GList *postscript_font_list = NULL;
- GList *true_type_font_list = NULL;
+ if (nautilus_str_has_suffix (font_directory, "unscaled")) {
+ return TRUE;
+ }
- GList **collected_font_tables;
+ if (nautilus_str_has_suffix (font_directory, "100dpi")) {
+ return TRUE;
+ }
- g_return_if_fail (font_directory != NULL);
- g_return_if_fail (callback_data != NULL);
+ if (nautilus_str_has_suffix (font_directory, "75dpi")) {
+ return TRUE;
+ }
- collected_font_tables = callback_data;
+ if (nautilus_str_has_suffix (font_directory, "misc")) {
+ return TRUE;
+ }
+ return FALSE;
+}
+
+static void
+font_manager_collect_font_tables (const char *font_directory,
+ GList **collected_font_tables)
+{
+ GList *postscript_font_list = NULL;
+ GList *true_type_font_list = NULL;
+ FontDescriptionTable *table;
+
+ g_return_if_fail (string_is_valid (font_directory));
+ g_return_if_fail (collected_font_tables != NULL);
+
+ if (font_ignore_directory (font_directory)) {
+ return;
+ }
+
/* Collect postscript and true type font in this directory */
collect_fonts_from_directory (font_directory, &postscript_font_list, &true_type_font_list);
@@ -789,208 +881,263 @@ font_server_for_each_callback (const char *font_directory,
/* If no "fonts.dir" exists, then the user has a missing description file (broken setup) */
if (!directory_contains_file (font_directory, FONTS_DIR_FILE_NAME)) {
- g_free (postscript_font_list);
- g_free (true_type_font_list);
+ nautilus_g_list_free_deep (postscript_font_list);
+ nautilus_g_list_free_deep (true_type_font_list);
g_warning ("Direcotry '%s' contains scalable fonts but no '%s' description file.",
font_directory,
FONTS_DIR_FILE_NAME);
return;
}
- table = font_description_table_new (font_directory);
- g_assert (table != NULL);
-
- font_description_table_install_font_lists (table, postscript_font_list, true_type_font_list);
+ table = font_description_table_new (font_directory, postscript_font_list, true_type_font_list);
+ if (table == NULL) {
+ nautilus_g_list_free_deep (postscript_font_list);
+ nautilus_g_list_free_deep (true_type_font_list);
+ g_warning ("Error trying to process font directory '%s'.", font_directory);
+ return;
+ }
*collected_font_tables = g_list_prepend (*collected_font_tables, table);
+
+ nautilus_g_list_free_deep (postscript_font_list);
+ nautilus_g_list_free_deep (true_type_font_list);
}
-/* Public */
-void
-nautilus_font_manager_for_each_font (NautilusFontManagerIterationCallback callback,
- gpointer callback_data)
+static void
+font_server_for_each_callback (const char *font_directory,
+ gpointer callback_data)
{
- GList *collected_font_tables = NULL;
- GList *node;
- FontDescriptionTable *table;
+ g_return_if_fail (string_is_valid (font_directory));
+ g_return_if_fail (callback_data != NULL);
- g_return_if_fail (callback != NULL);
+ font_manager_collect_font_tables (font_directory, callback_data);
+}
- font_server_for_each_font_directory ("/etc/X11/fs/config",
- font_server_for_each_callback,
- &collected_font_tables);
-
- node = collected_font_tables;
- while (node) {
+static GList *fallback_font_table = NULL;
+static GList *user_font_table = NULL;
+static GList *system_font_table = NULL;
+
+static void
+font_table_list_free (GList *font_table_list)
+{
+ GList *node;
+
+ node = font_table_list;
+ while (node != NULL) {
g_assert (node->data != NULL);
- table = node->data;
-
- font_description_table_for_each (table, callback, callback_data);
- font_description_table_free (table);
-
+ font_description_table_free (node->data);
node = node->next;
}
+ g_list_free (font_table_list);
+}
+
+static void
+font_table_list_for_each (GList *font_table_list,
+ NautilusFontManagerCallback callback,
+ gpointer callback_data)
+{
+ GList *node;
- g_list_free (collected_font_tables);
+ g_return_if_fail (callback != NULL);
+
+ node = font_table_list;
+ while (node != NULL) {
+ g_assert (node->data != NULL);
+ font_description_table_for_each (node->data, callback, callback_data);
+ node = node->next;
+ }
}
+static void
+free_font_tables (void)
+{
+ font_table_list_free (fallback_font_table);
+ fallback_font_table = NULL;
+
+ font_table_list_free (user_font_table);
+ user_font_table = NULL;
-#if !defined (NAUTILUS_OMIT_SELF_CHECK)
+ font_table_list_free (system_font_table);
+ system_font_table = NULL;
+}
-/*
- * The check strategy here is to create a temporary directory
- * with a single fonts.dir inside it. We then use that to
- * exercise the font manager.
- */
-static const char *test_fonts_dir_content =
-"4\n"
-"n019003l.pfb -URW-Helvetica-medium-r-normal--0-0-0-0-p-0-iso8859-1\n"
-"n019004l.pfb -URW-Helvetica-bold-r-normal--0-0-0-0-p-0-iso8859-1\n"
-"n019023l.pfb -URW-Helvetica-medium-o-normal--0-0-0-0-p-0-iso8859-1\n"
-"n019024l.pfb -URW-Helvetica-bold-o-normal--0-0-0-0-p-0-iso8859-1\n"
-;
+static gboolean at_exit_handler_installed = FALSE;
-static char *
-call_chop_off_comments (const char *input)
+static void
+ensure_at_exit_handler (void)
{
- char *test_copy;
- test_copy = g_strdup (input);
- chop_off_comments (test_copy);
- return test_copy;
+ if (!at_exit_handler_installed) {
+ at_exit_handler_installed = TRUE;
+ g_atexit (free_font_tables);
+ }
}
-static gboolean
-write_temp_font_dot_dir_file (const char *temp_font_dir_file_name)
+static void
+ensure_fallback_font_table (void)
{
- FILE *stream;
- size_t num;
- size_t num_written;
+ /* Populate the fallback font table if needed */
+ if (fallback_font_table == NULL) {
+ font_manager_collect_font_tables (FALLBACK_FONT_DIRECTORY, &fallback_font_table);
+ }
- g_return_val_if_fail (string_is_valid (temp_font_dir_file_name), FALSE);
- g_return_val_if_fail (!g_file_exists (temp_font_dir_file_name), FALSE);
+ ensure_at_exit_handler ();
+}
- stream = fopen (temp_font_dir_file_name, "w");
- g_return_val_if_fail (stream != NULL, FALSE);
+static void
+ensure_user_font_table (void)
+{
+ char *user_directory;
+ char *user_font_dir;
+
+ /* Populate the user font table if needed */
+ if (user_font_table == NULL) {
+ user_directory = nautilus_get_user_directory ();
+ user_font_dir = nautilus_make_path (user_directory, USER_FONT_DIRECTORY_NAME);
+ if (g_file_test (user_font_dir, G_FILE_TEST_ISDIR)) {
+ font_manager_collect_font_tables (user_font_dir, &user_font_table);
+ }
+ g_free (user_directory);
+ g_free (user_font_dir);
+ }
- num = strlen (test_fonts_dir_content);
- num_written = fwrite (test_fonts_dir_content, sizeof (char), num, stream);
- fclose (stream);
+ ensure_at_exit_handler ();
+}
- g_return_val_if_fail (num == num_written, FALSE);
+static void
+ensure_system_font_tables (void)
+{
+ /* Populate the system font table if needed - using the font server's configuration */
+ if (system_font_table == NULL) {
+ if (g_file_exists (FONT_SERVER_CONFIG_FILE)) {
+ font_server_for_each_font_directory (FONT_SERVER_CONFIG_FILE,
+ font_server_for_each_callback,
+ &system_font_table);
+ }
+ }
- return TRUE;
+ ensure_at_exit_handler ();
}
-static char *
-get_unique_temp_directory (void)
+/* Public */
+void
+nautilus_font_manager_for_each_font (NautilusFontManagerCallback callback,
+ gpointer callback_data)
{
- char *temp_font_directory;
+ g_return_if_fail (callback != NULL);
- temp_font_directory = nautilus_unique_temporary_file_name ();
+ /* Ensure that all the font tables exist */
+ ensure_fallback_font_table ();
+ ensure_user_font_table ();
+ ensure_system_font_tables ();
- if (temp_font_directory == NULL) {
- return NULL;
- }
+ font_table_list_for_each (fallback_font_table, callback, callback_data);
+ font_table_list_for_each (user_font_table, callback, callback_data);
+ font_table_list_for_each (system_font_table, callback, callback_data);
+}
- if (g_file_test (temp_font_directory, G_FILE_TEST_ISDIR)) {
- g_free (temp_font_directory);
- return NULL;
- }
+char *
+nautilus_font_manager_get_fallback_font (void)
+{
+ const FontDescriptionTable *table;
- mkdir (temp_font_directory, 0755);
+ ensure_fallback_font_table ();
+ g_return_val_if_fail (g_list_length (fallback_font_table) > 0, NULL);
- if (!g_file_test (temp_font_directory, G_FILE_TEST_ISDIR)) {
- g_free (temp_font_directory);
- return NULL;
- }
+ table = g_list_nth_data (fallback_font_table, 0);
+ g_return_val_if_fail (table != NULL, NULL);
- return temp_font_directory;
+ return font_description_table_get_nth_file_name (table, 0);
}
+#if !defined (NAUTILUS_OMIT_SELF_CHECK)
+
+static char *
+call_chop_off_comments (const char *input)
+{
+ char *test_copy;
+ test_copy = g_strdup (input);
+ chop_off_comments (test_copy);
+ return test_copy;
+}
+
+#define TEST_FONT_DIR "/usr/share/fonts/default/Type1"
+
void
nautilus_self_check_font_manager (void)
{
FontDescriptionTable *table;
const FontDescription *description;
+ GList *font_table_list = NULL;
- char *temp_font_directory;
- char *temp_fonts_dot_dir_file;
- char *cleanup_command;
- gboolean temp_font_directory_ok;
-
- temp_font_directory = get_unique_temp_directory ();
- g_return_if_fail (string_is_valid (temp_font_directory));
+ /* chop_off_comments() */
+ NAUTILUS_CHECK_STRING_RESULT (call_chop_off_comments ("foo bar"), "foo bar");
+ NAUTILUS_CHECK_STRING_RESULT (call_chop_off_comments ("foo bar\n"), "foo bar\n");
+ NAUTILUS_CHECK_STRING_RESULT (call_chop_off_comments ("#foo bar"), "");
+ NAUTILUS_CHECK_STRING_RESULT (call_chop_off_comments ("foo bar#"), "foo bar");
+ NAUTILUS_CHECK_STRING_RESULT (call_chop_off_comments ("\\foo bar"), "\\foo bar");
+ NAUTILUS_CHECK_STRING_RESULT (call_chop_off_comments ("\\#foo bar"), "\\#foo bar");
+ NAUTILUS_CHECK_STRING_RESULT (call_chop_off_comments ("\\##foo bar"), "\\#");
- temp_fonts_dot_dir_file = nautilus_make_path (temp_font_directory, FONTS_DIR_FILE_NAME);
- temp_font_directory_ok = write_temp_font_dot_dir_file (temp_fonts_dot_dir_file);
- g_return_if_fail (temp_font_directory_ok == TRUE);
+ /* FIXME bugzilla.eazel.com xxxx:
+ * Whats so special about this bastard ?
+ */
+ if (!nautilus_str_is_equal (g_get_user_name (), "ramiro") || !g_file_exists (TEST_FONT_DIR)) {
+ return;
+ }
- cleanup_command = g_strdup_printf ("/bin/rm -rf %s", temp_font_directory);
+ font_manager_collect_font_tables ("/usr/share/fonts/default/Type1", &font_table_list);
+ g_return_if_fail (font_table_list != NULL);
- table = font_description_table_new (temp_font_directory);
+ g_return_if_fail (g_list_nth_data (font_table_list, 0) != NULL);
+ table = g_list_nth_data (font_table_list, 0);
- NAUTILUS_CHECK_INTEGER_RESULT (font_description_table_get_length (table), 4);
- NAUTILUS_CHECK_STRING_RESULT (font_description_table_get_nth_file_name (table, 0), "n019003l.pfb");
- NAUTILUS_CHECK_STRING_RESULT (font_description_table_get_nth_file_name (table, 1), "n019004l.pfb");
- NAUTILUS_CHECK_STRING_RESULT (font_description_table_get_nth_file_name (table, 2), "n019023l.pfb");
- NAUTILUS_CHECK_STRING_RESULT (font_description_table_get_nth_file_name (table, 3), "n019024l.pfb");
+ NAUTILUS_CHECK_INTEGER_RESULT (font_description_table_get_length (table), 35);
+ NAUTILUS_CHECK_STRING_RESULT (font_description_table_get_nth_file_name (table, 0), TEST_FONT_DIR "/a010013l.pfb");
+ NAUTILUS_CHECK_STRING_RESULT (font_description_table_get_nth_file_name (table, 1), TEST_FONT_DIR "/a010015l.pfb");
+ NAUTILUS_CHECK_STRING_RESULT (font_description_table_get_nth_file_name (table, 2), TEST_FONT_DIR "/a010033l.pfb");
+ NAUTILUS_CHECK_STRING_RESULT (font_description_table_get_nth_file_name (table, 3), TEST_FONT_DIR "/a010035l.pfb");
description = font_description_table_peek_nth (table, 0);
- NAUTILUS_CHECK_STRING_RESULT (font_description_get_file_name (description), "n019003l.pfb");
+ NAUTILUS_CHECK_STRING_RESULT (font_description_get_file_name (description), TEST_FONT_DIR "/a010013l.pfb");
NAUTILUS_CHECK_STRING_RESULT (font_description_get_foundry (description), "URW");
- NAUTILUS_CHECK_STRING_RESULT (font_description_get_family (description), "Helvetica");
- NAUTILUS_CHECK_STRING_RESULT (font_description_get_weight (description), "medium");
+ NAUTILUS_CHECK_STRING_RESULT (font_description_get_family (description), "Avantgarde");
+ NAUTILUS_CHECK_STRING_RESULT (font_description_get_weight (description), "book");
NAUTILUS_CHECK_STRING_RESULT (font_description_get_slant (description), "r");
NAUTILUS_CHECK_STRING_RESULT (font_description_get_set_width (description), "normal");
NAUTILUS_CHECK_STRING_RESULT (font_description_get_char_set_encoding (description), "1");
NAUTILUS_CHECK_STRING_RESULT (font_description_get_char_set_registry (description), "iso8859");
description = font_description_table_peek_nth (table, 1);
- NAUTILUS_CHECK_STRING_RESULT (font_description_get_file_name (description), "n019004l.pfb");
+ NAUTILUS_CHECK_STRING_RESULT (font_description_get_file_name (description), TEST_FONT_DIR "/a010015l.pfb");
NAUTILUS_CHECK_STRING_RESULT (font_description_get_foundry (description), "URW");
- NAUTILUS_CHECK_STRING_RESULT (font_description_get_family (description), "Helvetica");
- NAUTILUS_CHECK_STRING_RESULT (font_description_get_weight (description), "bold");
+ NAUTILUS_CHECK_STRING_RESULT (font_description_get_family (description), "Avantgarde");
+ NAUTILUS_CHECK_STRING_RESULT (font_description_get_weight (description), "demibold");
NAUTILUS_CHECK_STRING_RESULT (font_description_get_slant (description), "r");
NAUTILUS_CHECK_STRING_RESULT (font_description_get_set_width (description), "normal");
NAUTILUS_CHECK_STRING_RESULT (font_description_get_char_set_encoding (description), "1");
NAUTILUS_CHECK_STRING_RESULT (font_description_get_char_set_registry (description), "iso8859");
description = font_description_table_peek_nth (table, 2);
- NAUTILUS_CHECK_STRING_RESULT (font_description_get_file_name (description), "n019023l.pfb");
+ NAUTILUS_CHECK_STRING_RESULT (font_description_get_file_name (description), TEST_FONT_DIR "/a010033l.pfb");
NAUTILUS_CHECK_STRING_RESULT (font_description_get_foundry (description), "URW");
- NAUTILUS_CHECK_STRING_RESULT (font_description_get_family (description), "Helvetica");
- NAUTILUS_CHECK_STRING_RESULT (font_description_get_weight (description), "medium");
+ NAUTILUS_CHECK_STRING_RESULT (font_description_get_family (description), "Avantgarde");
+ NAUTILUS_CHECK_STRING_RESULT (font_description_get_weight (description), "book");
NAUTILUS_CHECK_STRING_RESULT (font_description_get_slant (description), "o");
NAUTILUS_CHECK_STRING_RESULT (font_description_get_set_width (description), "normal");
NAUTILUS_CHECK_STRING_RESULT (font_description_get_char_set_encoding (description), "1");
NAUTILUS_CHECK_STRING_RESULT (font_description_get_char_set_registry (description), "iso8859");
description = font_description_table_peek_nth (table, 3);
- NAUTILUS_CHECK_STRING_RESULT (font_description_get_file_name (description), "n019024l.pfb");
+ NAUTILUS_CHECK_STRING_RESULT (font_description_get_file_name (description), TEST_FONT_DIR "/a010035l.pfb");
NAUTILUS_CHECK_STRING_RESULT (font_description_get_foundry (description), "URW");
- NAUTILUS_CHECK_STRING_RESULT (font_description_get_family (description), "Helvetica");
- NAUTILUS_CHECK_STRING_RESULT (font_description_get_weight (description), "bold");
+ NAUTILUS_CHECK_STRING_RESULT (font_description_get_family (description), "Avantgarde");
+ NAUTILUS_CHECK_STRING_RESULT (font_description_get_weight (description), "demibold");
NAUTILUS_CHECK_STRING_RESULT (font_description_get_slant (description), "o");
NAUTILUS_CHECK_STRING_RESULT (font_description_get_set_width (description), "normal");
NAUTILUS_CHECK_STRING_RESULT (font_description_get_char_set_encoding (description), "1");
NAUTILUS_CHECK_STRING_RESULT (font_description_get_char_set_registry (description), "iso8859");
- font_description_table_free (table);
-
- /* chop_off_comments() */
- NAUTILUS_CHECK_STRING_RESULT (call_chop_off_comments ("foo bar"), "foo bar");
- NAUTILUS_CHECK_STRING_RESULT (call_chop_off_comments ("foo bar\n"), "foo bar\n");
- NAUTILUS_CHECK_STRING_RESULT (call_chop_off_comments ("#foo bar"), "");
- NAUTILUS_CHECK_STRING_RESULT (call_chop_off_comments ("foo bar#"), "foo bar");
- NAUTILUS_CHECK_STRING_RESULT (call_chop_off_comments ("\\foo bar"), "\\foo bar");
- NAUTILUS_CHECK_STRING_RESULT (call_chop_off_comments ("\\#foo bar"), "\\#foo bar");
- NAUTILUS_CHECK_STRING_RESULT (call_chop_off_comments ("\\##foo bar"), "\\#");
-
- system (cleanup_command);
-
- g_free (cleanup_command);
- g_free (temp_font_directory);
- g_free (temp_fonts_dot_dir_file);
+ font_table_list_free (font_table_list);
}
#endif /* !NAUTILUS_OMIT_SELF_CHECK */
diff --git a/libnautilus-extensions/nautilus-font-manager.h b/libnautilus-extensions/nautilus-font-manager.h
index 3204ce0fa..9c168ef5c 100644
--- a/libnautilus-extensions/nautilus-font-manager.h
+++ b/libnautilus-extensions/nautilus-font-manager.h
@@ -19,7 +19,8 @@
write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.
- Authors: Ramiro Estrugo <ramiro@eazel.com>
+ Authors: Pavel Cisler <pavel@eazel.com>,
+ Ramiro Estrugo <ramiro@eazel.com>
*/
#ifndef NAUTILUS_FONT_MANAGER_H
@@ -30,20 +31,28 @@
BEGIN_GNOME_DECLS
+typedef enum {
+ NAUTILUS_FONT_POSTSCRIPT = 1,
+ NAUTILUS_FONT_TRUE_TYPE
+} NautilusFontType;
+
/*
* A callback which can be invoked for each font available in the system.
*/
-typedef void (*NautilusFontManagerIterationCallback) (const char *foundry,
- const char *family,
- const char *weight,
- const char *slant,
- const char *set_width,
- const char *char_set_registry,
- const char *char_set_encoding,
- gpointer callback_data);
-
-void nautilus_font_manager_for_each_font (NautilusFontManagerIterationCallback callback,
- gpointer callback_data);
+typedef void (*NautilusFontManagerCallback) (const char *font_file_name,
+ NautilusFontType font_type,
+ const char *foundry,
+ const char *family,
+ const char *weight,
+ const char *slant,
+ const char *set_width,
+ const char *char_set_registry,
+ const char *char_set_encoding,
+ gpointer callback_data);
+
+void nautilus_font_manager_for_each_font (NautilusFontManagerCallback callback,
+ gpointer callback_data);
+char *nautilus_font_manager_get_fallback_font (void);
END_GNOME_DECLS
diff --git a/libnautilus-extensions/nautilus-font-picker.c b/libnautilus-extensions/nautilus-font-picker.c
index ffe2639d5..ef6264540 100644
--- a/libnautilus-extensions/nautilus-font-picker.c
+++ b/libnautilus-extensions/nautilus-font-picker.c
@@ -25,81 +25,109 @@
#include <config.h>
#include "nautilus-font-picker.h"
+
#include "nautilus-gtk-macros.h"
#include "nautilus-glib-extensions.h"
#include "nautilus-string-picker.h"
#include "nautilus-string.h"
+#include "nautilus-font-manager.h"
#include <gtk/gtklabel.h>
#include <gtk/gtkentry.h>
#include <gtk/gtksignal.h>
+#include <gtk/gtkhbox.h>
#include <libgnome/gnome-i18n.h>
+
+typedef struct {
+ char *name;
+ char *font_file_name;
+} FontStyle;
+
+typedef struct {
+ char *title;
+ char *foundry;
+ char *family;
+ char *name;
+ GList *style_list;
+} FontEntry;
+
+static const char *black_listed_fonts[] = {
+ "microsoft Webdings",
+ "microsoft Wingdings",
+ "monotype OCR",
+ "URW Zapf Dingbats",
+ "URW Symbol",
+ "xfree86 cursor"
+};
+
static const gint FONT_PICKER_SPACING = 10;
/* Signals */
typedef enum
{
- SELECTED_FONT_CHANGED,
+ CHANGED,
LAST_SIGNAL
} FontPickerSignals;
-struct _NautilusFontPickerDetail
+struct NautilusFontPickerDetails
{
- GtkWidget *family_picker;
- GtkWidget *weight_picker;
- GtkWidget *slant_picker;
- GtkWidget *set_width_picker;
-
- NautilusStringList *weight_list;
- NautilusStringList *slant_list;
- NautilusStringList *set_width_list;
+ NautilusStringPicker *font_name_picker;
+ NautilusStringPicker *style_picker;
+ GList *font_entry_list;
+ GtkWidget *title_label;
};
-/* NautilusFontPickerClass methods */
-static void nautilus_font_picker_initialize_class (NautilusFontPickerClass *klass);
-static void nautilus_font_picker_initialize (NautilusFontPicker *font_picker);
-
-
/* GtkObjectClass methods */
+static void nautilus_font_picker_initialize_class (NautilusFontPickerClass *font_picker_class);
+static void nautilus_font_picker_initialize (NautilusFontPicker *font_picker);
static void nautilus_font_picker_destroy (GtkObject *object);
-static void family_picker_changed_callback (GtkWidget *string_picker,
- gpointer user_data);
-static void weight_picker_changed_callback (GtkWidget *string_picker,
- gpointer user_data);
-static void slant_picker_changed_callback (GtkWidget *string_picker,
- gpointer user_data);
-static void set_width_picker_changed_callback (GtkWidget *string_picker,
- gpointer user_data);
-
-NAUTILUS_DEFINE_CLASS_BOILERPLATE (NautilusFontPicker, nautilus_font_picker, GTK_TYPE_HBOX)
+static void font_picker_update (NautilusFontPicker *font_picker);
+
+/* Callbacks */
+static void font_name_picker_changed_callback (GtkWidget *string_picker,
+ gpointer callback_data);
+static void style_picker_changed_callback (GtkWidget *string_picker,
+ gpointer callback_data);
+static void font_manager_callback (const char *font_file_name,
+ NautilusFontType font_type,
+ const char *foundry,
+ const char *family,
+ const char *weight,
+ const char *slant,
+ const char *set_width,
+ const char *char_set_registry,
+ const char *char_set_encoding,
+ gpointer callback_data);
+static void font_entry_list_for_each_callback (gpointer data,
+ gpointer callback_data);
+static void style_list_for_each_callback (gpointer data,
+ gpointer callback_data);
+
+NAUTILUS_DEFINE_CLASS_BOILERPLATE (NautilusFontPicker, nautilus_font_picker, GTK_TYPE_VBOX)
static guint font_picker_signals[LAST_SIGNAL] = { 0 };
-/*
- * NautilusFontPickerClass methods
- */
+/* GtkObjectClass methods */
static void
nautilus_font_picker_initialize_class (NautilusFontPickerClass *font_picker_class)
{
GtkObjectClass *object_class;
- GtkWidgetClass *widget_class;
object_class = GTK_OBJECT_CLASS (font_picker_class);
- widget_class = GTK_WIDGET_CLASS (font_picker_class);
/* GtkObjectClass */
object_class->destroy = nautilus_font_picker_destroy;
/* Signals */
- font_picker_signals[SELECTED_FONT_CHANGED] = gtk_signal_new ("selected_font_changed",
- GTK_RUN_LAST,
- object_class->type,
- 0,
- gtk_marshal_NONE__NONE,
- GTK_TYPE_NONE,
- 0);
+ font_picker_signals[CHANGED] = gtk_signal_new ("changed",
+ GTK_RUN_LAST,
+ object_class->type,
+ 0,
+ gtk_marshal_NONE__NONE,
+ GTK_TYPE_NONE,
+ 0);
gtk_object_class_add_signals (object_class, font_picker_signals, LAST_SIGNAL);
}
@@ -107,73 +135,55 @@ nautilus_font_picker_initialize_class (NautilusFontPickerClass *font_picker_clas
static void
nautilus_font_picker_initialize (NautilusFontPicker *font_picker)
{
- NautilusStringList *family_list;
-
- font_picker->detail = g_new (NautilusFontPickerDetail, 1);
-
- font_picker->detail->weight_list = NULL;
- font_picker->detail->slant_list = NULL;
- font_picker->detail->set_width_list = NULL;
+ GtkWidget *hbox;
+ font_picker->details = g_new0 (NautilusFontPickerDetails, 1);
gtk_box_set_homogeneous (GTK_BOX (font_picker), FALSE);
gtk_box_set_spacing (GTK_BOX (font_picker), FONT_PICKER_SPACING);
- font_picker->detail->family_picker = nautilus_string_picker_new ();
- font_picker->detail->weight_picker = nautilus_string_picker_new ();
- font_picker->detail->slant_picker = nautilus_string_picker_new ();
- font_picker->detail->set_width_picker = nautilus_string_picker_new ();
-
- gtk_box_pack_start (GTK_BOX (font_picker), font_picker->detail->family_picker, TRUE, TRUE, 0);
- gtk_box_pack_start (GTK_BOX (font_picker), font_picker->detail->weight_picker, TRUE, TRUE, 0);
- gtk_box_pack_start (GTK_BOX (font_picker), font_picker->detail->slant_picker, TRUE, TRUE, 0);
- gtk_box_pack_end (GTK_BOX (font_picker), font_picker->detail->set_width_picker, TRUE, TRUE, 0);
+ font_picker->details->title_label = gtk_label_new ("");
+ gtk_label_set_justify (GTK_LABEL (font_picker->details->title_label),
+ GTK_JUSTIFY_LEFT);
+ gtk_misc_set_alignment (GTK_MISC (font_picker->details->title_label), 0.0, 0.5);
- nautilus_caption_set_title_label (NAUTILUS_CAPTION (font_picker->detail->family_picker), _("Font"));
+ gtk_box_pack_start (GTK_BOX (font_picker), font_picker->details->title_label, TRUE, TRUE, 0);
- nautilus_caption_set_show_title (NAUTILUS_CAPTION (font_picker->detail->family_picker), FALSE);
- nautilus_caption_set_show_title (NAUTILUS_CAPTION (font_picker->detail->weight_picker), FALSE);
- nautilus_caption_set_show_title (NAUTILUS_CAPTION (font_picker->detail->slant_picker), FALSE);
- nautilus_caption_set_show_title (NAUTILUS_CAPTION (font_picker->detail->set_width_picker), FALSE);
+ hbox = gtk_hbox_new (FALSE, 0);
+ gtk_box_pack_start (GTK_BOX (font_picker), hbox, TRUE, TRUE, 0);
- family_list = nautilus_scalable_font_get_font_family_list ();
+ font_picker->details->font_name_picker = NAUTILUS_STRING_PICKER (nautilus_string_picker_new ());
+ font_picker->details->style_picker = NAUTILUS_STRING_PICKER (nautilus_string_picker_new ());
- nautilus_string_list_sort (family_list);
-
- /* FIXME bugzilla.eazel.com 2557:
- * Need to deal with possiblity of there being no fonts */
- g_assert (family_list != NULL);
+ gtk_box_pack_start (GTK_BOX (hbox), GTK_WIDGET (font_picker->details->font_name_picker), TRUE, TRUE, 0);
+ gtk_box_pack_start (GTK_BOX (hbox), GTK_WIDGET (font_picker->details->style_picker), TRUE, TRUE, 0);
- nautilus_string_picker_set_string_list (NAUTILUS_STRING_PICKER (font_picker->detail->family_picker),
- family_list);
-
- nautilus_string_list_free (family_list);
+ nautilus_caption_set_title_label (NAUTILUS_CAPTION (font_picker->details->font_name_picker), _("Font"));
+ nautilus_caption_set_show_title (NAUTILUS_CAPTION (font_picker->details->font_name_picker), FALSE);
+ nautilus_caption_set_show_title (NAUTILUS_CAPTION (font_picker->details->style_picker), FALSE);
- gtk_signal_connect (GTK_OBJECT (font_picker->detail->family_picker),
+ gtk_signal_connect (GTK_OBJECT (font_picker->details->font_name_picker),
"changed",
- GTK_SIGNAL_FUNC (family_picker_changed_callback),
+ GTK_SIGNAL_FUNC (font_name_picker_changed_callback),
font_picker);
- gtk_signal_connect (GTK_OBJECT (font_picker->detail->weight_picker),
+ gtk_signal_connect (GTK_OBJECT (font_picker->details->style_picker),
"changed",
- GTK_SIGNAL_FUNC (weight_picker_changed_callback),
+ GTK_SIGNAL_FUNC (style_picker_changed_callback),
font_picker);
- gtk_signal_connect (GTK_OBJECT (font_picker->detail->slant_picker),
- "changed",
- GTK_SIGNAL_FUNC (slant_picker_changed_callback),
- font_picker);
+ gtk_widget_show (GTK_WIDGET (font_picker->details->font_name_picker));
+ gtk_widget_show (GTK_WIDGET (font_picker->details->style_picker));
+ gtk_widget_show (font_picker->details->title_label);
+ gtk_widget_show (hbox);
- gtk_signal_connect (GTK_OBJECT (font_picker->detail->set_width_picker),
- "changed",
- GTK_SIGNAL_FUNC (set_width_picker_changed_callback),
- font_picker);
+ /* Populate the font table */
+ nautilus_font_manager_for_each_font (font_manager_callback, font_picker);
- gtk_widget_show (font_picker->detail->family_picker);
- gtk_widget_show (font_picker->detail->weight_picker);
- gtk_widget_show (font_picker->detail->slant_picker);
- gtk_widget_show (font_picker->detail->set_width_picker);
+ /* Populate the font name (foundry+family) picker */
+ g_list_foreach (font_picker->details->font_entry_list, font_entry_list_for_each_callback, font_picker);
- family_picker_changed_callback (font_picker->detail->family_picker, font_picker);
+ /* Update the font picker */
+ font_picker_update (font_picker);;
}
/* GtkObjectClass methods */
@@ -181,317 +191,279 @@ static void
nautilus_font_picker_destroy (GtkObject* object)
{
NautilusFontPicker * font_picker;
-
- g_return_if_fail (object != NULL);
+
g_return_if_fail (NAUTILUS_IS_FONT_PICKER (object));
font_picker = NAUTILUS_FONT_PICKER (object);
-
- nautilus_string_list_free (font_picker->detail->weight_list);
- nautilus_string_list_free (font_picker->detail->slant_list);
- nautilus_string_list_free (font_picker->detail->set_width_list);
- g_free (font_picker->detail);
+ g_free (font_picker->details);
/* Chain */
NAUTILUS_CALL_PARENT (GTK_OBJECT_CLASS, destroy, (object));
}
-static void
-font_picker_update_weight_picker (NautilusFontPicker *font_picker)
+static FontEntry *
+font_entry_list_find (GList *font_entry_list,
+ const char *font_name)
{
- NautilusStringList *unique_weight_list;
- char *family;
-
- g_return_if_fail (NAUTILUS_IS_FONT_PICKER (font_picker));
-
- family = nautilus_string_picker_get_selected_string (NAUTILUS_STRING_PICKER (font_picker->detail->family_picker));
-
- unique_weight_list = nautilus_string_list_new_from_string_list (font_picker->detail->weight_list, TRUE);
-
- nautilus_string_list_sort (unique_weight_list);
- nautilus_string_list_remove_duplicates (unique_weight_list);
-
- nautilus_string_picker_set_string_list (NAUTILUS_STRING_PICKER (font_picker->detail->weight_picker),
- unique_weight_list);
+ while (font_entry_list != NULL) {
+ FontEntry *entry;
+ g_assert (font_entry_list->data != NULL);
+ entry = font_entry_list->data;
+ if (nautilus_istr_is_equal (font_name, entry->name)) {
+ return entry;
+ }
+
+ font_entry_list = font_entry_list->next;
+ }
- nautilus_string_list_free (unique_weight_list);
-
- g_free (family);
+ return NULL;
}
static void
-font_picker_update_slant_picker (NautilusFontPicker *font_picker)
+font_picker_update (NautilusFontPicker *font_picker)
{
- NautilusStringList *unique_slant_list;
- char *current_family;
- char *current_weight;
- guint i;
+ char *selected_font;
+ const FontEntry *entry;
g_return_if_fail (NAUTILUS_IS_FONT_PICKER (font_picker));
- current_family = nautilus_string_picker_get_selected_string (NAUTILUS_STRING_PICKER (font_picker->detail->family_picker));
- current_weight = nautilus_string_picker_get_selected_string (NAUTILUS_STRING_PICKER (font_picker->detail->weight_picker));
-
- g_assert (nautilus_string_list_get_length (font_picker->detail->slant_list) ==
- nautilus_string_list_get_length (font_picker->detail->weight_list));
+ selected_font = nautilus_string_picker_get_selected_string (font_picker->details->font_name_picker);
- unique_slant_list = nautilus_string_list_new (TRUE);
+ entry = font_entry_list_find (font_picker->details->font_entry_list, selected_font);
+ g_return_if_fail (entry != NULL);
- for (i = 0; i < nautilus_string_list_get_length (font_picker->detail->slant_list); i++) {
- char *weight = nautilus_string_list_nth (font_picker->detail->weight_list, i);
- char *slant = nautilus_string_list_nth (font_picker->detail->slant_list, i);
+ nautilus_string_picker_clear (font_picker->details->style_picker);
+
+ g_list_foreach (entry->style_list, style_list_for_each_callback, font_picker);
+
+ g_free (selected_font);
+}
- if (nautilus_str_is_equal (current_weight, weight)) {
- nautilus_string_list_insert (unique_slant_list, slant);
- }
+static void
+font_name_picker_changed_callback (GtkWidget *string_picker,
+ gpointer callback_data)
+{
+ NautilusFontPicker *font_picker;
- g_free (weight);
- g_free (slant);
- }
+ g_return_if_fail (NAUTILUS_IS_FONT_PICKER (callback_data));
+ g_return_if_fail (NAUTILUS_IS_STRING_PICKER (string_picker));
- nautilus_string_list_sort (unique_slant_list);
- nautilus_string_list_remove_duplicates (unique_slant_list);
+ font_picker = NAUTILUS_FONT_PICKER (callback_data);
- nautilus_string_picker_set_string_list (NAUTILUS_STRING_PICKER (font_picker->detail->slant_picker),
- unique_slant_list);
-
- nautilus_string_list_free (unique_slant_list);
+ font_picker_update (font_picker);
- g_free (current_family);
- g_free (current_weight);
+ gtk_signal_emit (GTK_OBJECT (font_picker), font_picker_signals[CHANGED]);
}
static void
-font_picker_update_set_width_picker (NautilusFontPicker *font_picker)
+style_picker_changed_callback (GtkWidget *string_picker, gpointer callback_data)
{
- NautilusStringList *unique_set_width_list;
- char *current_family;
- char *current_weight;
- char *current_slant;
- guint i;
+ NautilusFontPicker *font_picker;
- g_return_if_fail (NAUTILUS_IS_FONT_PICKER (font_picker));
-
- current_family = nautilus_string_picker_get_selected_string (NAUTILUS_STRING_PICKER (font_picker->detail->family_picker));
- current_weight = nautilus_string_picker_get_selected_string (NAUTILUS_STRING_PICKER (font_picker->detail->weight_picker));
- current_slant = nautilus_string_picker_get_selected_string (NAUTILUS_STRING_PICKER (font_picker->detail->slant_picker));
-
- g_assert (nautilus_string_list_get_length (font_picker->detail->slant_list) ==
- nautilus_string_list_get_length (font_picker->detail->weight_list));
+ g_return_if_fail (NAUTILUS_IS_FONT_PICKER (callback_data));
+ g_return_if_fail (NAUTILUS_IS_STRING_PICKER (string_picker));
- g_assert (nautilus_string_list_get_length (font_picker->detail->slant_list) ==
- nautilus_string_list_get_length (font_picker->detail->set_width_list));
+ font_picker = NAUTILUS_FONT_PICKER (callback_data);
- unique_set_width_list = nautilus_string_list_new (TRUE);
+ gtk_signal_emit (GTK_OBJECT (font_picker), font_picker_signals[CHANGED]);
+}
+
+static gboolean
+ignore_font (const char *font_file_name,
+ const char *foundry,
+ const char *family,
+ const char *entry_name)
+{
+ guint i;
- for (i = 0; i < nautilus_string_list_get_length (font_picker->detail->set_width_list); i++) {
- char *weight = nautilus_string_list_nth (font_picker->detail->weight_list, i);
- char *slant = nautilus_string_list_nth (font_picker->detail->slant_list, i);
- char *set_width = nautilus_string_list_nth (font_picker->detail->set_width_list, i);
+ g_return_val_if_fail (font_file_name != NULL, TRUE);
+ g_return_val_if_fail (foundry != NULL, TRUE);
+ g_return_val_if_fail (family != NULL, TRUE);
+ g_return_val_if_fail (entry_name != NULL, TRUE);
- if (nautilus_str_is_equal (current_weight, weight)
- && nautilus_str_is_equal (current_slant, slant)) {
- nautilus_string_list_insert (unique_set_width_list, set_width);
+ for (i = 0; i < NAUTILUS_N_ELEMENTS (black_listed_fonts); i++) {
+ if (nautilus_istr_is_equal (entry_name, black_listed_fonts[i])) {
+ return TRUE;
}
-
- g_free (weight);
- g_free (slant);
- g_free (set_width);
}
-
- nautilus_string_list_sort (unique_set_width_list);
- nautilus_string_list_remove_duplicates (unique_set_width_list);
-
- nautilus_string_picker_set_string_list (NAUTILUS_STRING_PICKER (font_picker->detail->set_width_picker),
- unique_set_width_list);
-
- nautilus_string_list_free (unique_set_width_list);
- g_free (current_family);
- g_free (current_weight);
- g_free (current_slant);
+ return FALSE;
}
static void
-family_picker_changed_callback (GtkWidget *string_picker, gpointer user_data)
+font_manager_callback (const char *font_file_name,
+ NautilusFontType font_type,
+ const char *foundry,
+ const char *family,
+ const char *weight,
+ const char *slant,
+ const char *set_width,
+ const char *char_set_registry,
+ const char *char_set_encoding,
+ gpointer callback_data)
{
- NautilusFontPicker *font_picker;
- char *family;
- NautilusStringList *weight_list = NULL;
- NautilusStringList *slant_list = NULL;
- NautilusStringList *set_width_list = NULL;
+ NautilusFontPicker *font_picker;
+ char *entry_name;
+ FontEntry *entry;
+ FontStyle *style;
- g_return_if_fail (NAUTILUS_IS_FONT_PICKER (user_data));
- g_return_if_fail (NAUTILUS_IS_STRING_PICKER (string_picker));
+ g_return_if_fail (font_file_name != NULL);
+ g_return_if_fail (foundry != NULL);
+ g_return_if_fail (family != NULL);
+ g_return_if_fail (weight != NULL);
+ g_return_if_fail (slant != NULL);
+ g_return_if_fail (set_width != NULL);
+ g_return_if_fail (char_set_registry != NULL);
+ g_return_if_fail (char_set_encoding != NULL);
+ g_return_if_fail (NAUTILUS_IS_FONT_PICKER (callback_data));
- font_picker = NAUTILUS_FONT_PICKER (user_data);
+ font_picker = NAUTILUS_FONT_PICKER (callback_data);
- family = nautilus_string_picker_get_selected_string (NAUTILUS_STRING_PICKER (string_picker));
-
- if (nautilus_scalable_font_query_font (family, &weight_list, &slant_list, &set_width_list)) {
- nautilus_string_list_free (font_picker->detail->weight_list);
- nautilus_string_list_free (font_picker->detail->slant_list);
- nautilus_string_list_free (font_picker->detail->set_width_list);
-
- font_picker->detail->weight_list = weight_list;
- font_picker->detail->slant_list = slant_list;
- font_picker->detail->set_width_list = set_width_list;
-
- font_picker_update_weight_picker (font_picker);
- font_picker_update_slant_picker (font_picker);
- font_picker_update_set_width_picker (font_picker);
+ entry_name = g_strdup_printf ("%s %s", foundry, family);
- gtk_signal_emit (GTK_OBJECT (font_picker), font_picker_signals[SELECTED_FONT_CHANGED]);
- }
- else {
- g_warning ("Trying to set a bogus non existant font '%s'\n", family);
+ if (ignore_font (font_file_name, foundry, family, entry_name)) {
+ g_free (entry_name);
+ return;
}
- g_free (family);
-}
+ entry = font_entry_list_find (font_picker->details->font_entry_list, entry_name);
-static void
-weight_picker_changed_callback (GtkWidget *string_picker, gpointer user_data)
-{
- NautilusFontPicker *font_picker;
-
- g_return_if_fail (NAUTILUS_IS_FONT_PICKER (user_data));
- g_return_if_fail (NAUTILUS_IS_STRING_PICKER (string_picker));
-
- font_picker = NAUTILUS_FONT_PICKER (user_data);
+ if (entry == NULL) {
+ entry = g_new0 (FontEntry, 1);
+ entry->name = g_strdup (entry_name);
+ entry->foundry = g_strdup (foundry);
+ entry->family = g_strdup (family);
+ font_picker->details->font_entry_list = g_list_prepend (font_picker->details->font_entry_list, entry);
+ }
+ g_assert (entry != NULL);
+ g_assert (font_entry_list_find (font_picker->details->font_entry_list, entry_name) == entry);
+ g_free (entry_name);
+
+ style = g_new0 (FontStyle, 1);
+ style->name = g_strdup_printf ("%s %s %s", weight, slant, set_width);
+ style->font_file_name = g_strdup (font_file_name);
- gtk_signal_emit (GTK_OBJECT (font_picker), font_picker_signals[SELECTED_FONT_CHANGED]);
+ entry->style_list = g_list_append (entry->style_list, style);
}
static void
-slant_picker_changed_callback (GtkWidget *string_picker, gpointer user_data)
+style_list_for_each_callback (gpointer data,
+ gpointer callback_data)
{
- NautilusFontPicker *font_picker;
+ NautilusFontPicker *font_picker;
+ FontStyle *style;
- g_return_if_fail (NAUTILUS_IS_FONT_PICKER (user_data));
- g_return_if_fail (NAUTILUS_IS_STRING_PICKER (string_picker));
+ g_return_if_fail (data != NULL);
+ g_return_if_fail (NAUTILUS_IS_FONT_PICKER (callback_data));
- font_picker = NAUTILUS_FONT_PICKER (user_data);
+ style = data;
+ font_picker = NAUTILUS_FONT_PICKER (callback_data);
- gtk_signal_emit (GTK_OBJECT (font_picker), font_picker_signals[SELECTED_FONT_CHANGED]);
+ nautilus_string_picker_insert_string (font_picker->details->style_picker, style->name);
}
-
static void
-set_width_picker_changed_callback (GtkWidget *string_picker, gpointer user_data)
+font_entry_list_for_each_callback (gpointer data,
+ gpointer callback_data)
{
- NautilusFontPicker *font_picker;
+ NautilusFontPicker *font_picker;
+ FontEntry *entry;
- g_return_if_fail (NAUTILUS_IS_FONT_PICKER (user_data));
- g_return_if_fail (NAUTILUS_IS_STRING_PICKER (string_picker));
+ g_return_if_fail (data != NULL);
+ g_return_if_fail (NAUTILUS_IS_FONT_PICKER (callback_data));
- font_picker = NAUTILUS_FONT_PICKER (user_data);
+ font_picker = NAUTILUS_FONT_PICKER (callback_data);
- gtk_signal_emit (GTK_OBJECT (font_picker), font_picker_signals[SELECTED_FONT_CHANGED]);
+ entry = data;
+ nautilus_string_picker_insert_string (font_picker->details->font_name_picker,
+ entry->name);
}
-
-/*
- * NautilusFontPicker public methods
- */
+/* NautilusFontPicker public methods */
GtkWidget *
nautilus_font_picker_new (void)
{
return gtk_widget_new (nautilus_font_picker_get_type (), NULL);
}
-void
-nautilus_font_picker_set_selected_family (NautilusFontPicker *font_picker,
- const char *family)
+char *
+nautilus_font_picker_get_selected_font (const NautilusFontPicker *font_picker)
{
- g_return_if_fail (NAUTILUS_IS_FONT_PICKER (font_picker));
- g_return_if_fail (family != NULL);
+ char *result = NULL;
+ char *selected_font;
+ char *selected_style;
+ const FontEntry *entry;
+ GList *node;
- if (!nautilus_string_picker_contains (NAUTILUS_STRING_PICKER (font_picker->detail->family_picker), family)) {
- g_warning ("Trying to set a bogus family '%s'\n", family);
- return;
- }
+ g_return_val_if_fail (NAUTILUS_IS_FONT_PICKER (font_picker), NULL);
- nautilus_string_picker_set_selected_string (NAUTILUS_STRING_PICKER (font_picker->detail->family_picker),
- family);
-}
+ selected_font = nautilus_string_picker_get_selected_string (font_picker->details->font_name_picker);
+ g_return_val_if_fail (selected_font != NULL, NULL);
+
+ selected_style = nautilus_string_picker_get_selected_string (font_picker->details->style_picker);
+ g_return_val_if_fail (selected_style != NULL, NULL);
+
+ entry = font_entry_list_find (font_picker->details->font_entry_list, selected_font);
+ g_return_val_if_fail (entry != NULL, NULL);
-void
-nautilus_font_picker_set_selected_weight (NautilusFontPicker *font_picker,
- const char *weight)
-{
- g_return_if_fail (NAUTILUS_IS_FONT_PICKER (font_picker));
- g_return_if_fail (weight != NULL);
+ node = entry->style_list;
+ while (node != NULL && result == NULL) {
+ const FontStyle *style;
+ g_assert (node->data != NULL);
+ style = node->data;
- if (!nautilus_string_picker_contains (NAUTILUS_STRING_PICKER (font_picker->detail->weight_picker), weight)) {
- g_warning ("Trying to set a bogus weight '%s'\n", weight);
- return;
+ if (nautilus_istr_is_equal (style->name, selected_style)) {
+ result = g_strdup (style->font_file_name);
+ }
+ node = node->next;
}
-
- nautilus_string_picker_set_selected_string (NAUTILUS_STRING_PICKER (font_picker->detail->weight_picker),
- weight);
+
+ g_free (selected_font);
+ g_free (selected_style);
+
+ return result;
}
void
-nautilus_font_picker_set_selected_slant (NautilusFontPicker *font_picker,
- const char *slant)
+nautilus_font_picker_set_selected_font (NautilusFontPicker *font_picker,
+ const char *font_name)
{
- g_return_if_fail (NAUTILUS_IS_FONT_PICKER (font_picker));
- g_return_if_fail (slant != NULL);
+ const FontEntry *entry;
+ const FontStyle *style;
+ GList *font_list_node;
+ GList *style_list_node;
- if (!nautilus_string_picker_contains (NAUTILUS_STRING_PICKER (font_picker->detail->slant_picker), slant)) {
- g_warning ("Trying to set a bogus slant '%s'\n", slant);
- return;
- }
+ g_return_if_fail (NAUTILUS_IS_FONT_PICKER (font_picker));
- nautilus_string_picker_set_selected_string (NAUTILUS_STRING_PICKER (font_picker->detail->slant_picker),
- slant);
+ font_list_node = font_picker->details->font_entry_list;
+ while (font_list_node != NULL) {
+ g_assert (font_list_node->data != NULL);
+ entry = font_list_node->data;
+
+ style_list_node = entry->style_list;
+ while (style_list_node != NULL) {
+ g_assert (style_list_node->data != NULL);
+ style = style_list_node->data;
+
+ if (nautilus_istr_is_equal (style->font_file_name, font_name)) {
+ nautilus_string_picker_set_selected_string (font_picker->details->font_name_picker,
+ entry->name);
+ font_picker_update (font_picker);
+ gtk_signal_emit (GTK_OBJECT (font_picker), font_picker_signals[CHANGED]);
+ return;
+ }
+ style_list_node = style_list_node->next;
+ }
+
+ font_list_node = font_list_node->next;
+ }
}
void
-nautilus_font_picker_set_selected_set_width (NautilusFontPicker *font_picker,
- const char *set_width)
+nautilus_font_picker_set_title_label (NautilusFontPicker *font_picker,
+ const char *title_label)
{
g_return_if_fail (NAUTILUS_IS_FONT_PICKER (font_picker));
- g_return_if_fail (set_width != NULL);
-
- if (!nautilus_string_picker_contains (NAUTILUS_STRING_PICKER (font_picker->detail->set_width_picker), set_width)) {
- g_warning ("Trying to set a bogus set_width '%s'\n", set_width);
- return;
- }
-
- nautilus_string_picker_set_selected_string (NAUTILUS_STRING_PICKER (font_picker->detail->set_width_picker),
- set_width);
-}
-
-char *
-nautilus_font_picker_get_selected_family (const NautilusFontPicker *font_picker)
-{
- g_return_val_if_fail (NAUTILUS_IS_FONT_PICKER (font_picker), NULL);
-
- return nautilus_string_picker_get_selected_string (NAUTILUS_STRING_PICKER (font_picker->detail->family_picker));
-}
-
-char *
-nautilus_font_picker_get_selected_weight (const NautilusFontPicker *font_picker)
-{
- g_return_val_if_fail (NAUTILUS_IS_FONT_PICKER (font_picker), NULL);
-
- return nautilus_string_picker_get_selected_string (NAUTILUS_STRING_PICKER (font_picker->detail->weight_picker));
-}
-
-char *
-nautilus_font_picker_get_selected_slant (const NautilusFontPicker *font_picker)
-{
- g_return_val_if_fail (NAUTILUS_IS_FONT_PICKER (font_picker), NULL);
-
- return nautilus_string_picker_get_selected_string (NAUTILUS_STRING_PICKER (font_picker->detail->slant_picker));
-}
-
-char *
-nautilus_font_picker_get_selected_set_width (const NautilusFontPicker *font_picker)
-{
- g_return_val_if_fail (NAUTILUS_IS_FONT_PICKER (font_picker), NULL);
- return nautilus_string_picker_get_selected_string (NAUTILUS_STRING_PICKER (font_picker->detail->set_width_picker));
+ gtk_label_set_text (GTK_LABEL (font_picker->details->title_label), title_label);
}
diff --git a/libnautilus-extensions/nautilus-font-picker.h b/libnautilus-extensions/nautilus-font-picker.h
index 5bbbe1ff4..b4b80de59 100644
--- a/libnautilus-extensions/nautilus-font-picker.h
+++ b/libnautilus-extensions/nautilus-font-picker.h
@@ -25,7 +25,7 @@
#ifndef NAUTILUS_FONT_PICKER_H
#define NAUTILUS_FONT_PICKER_H
-#include <gtk/gtkhbox.h>
+#include <gtk/gtkvbox.h>
#include <libnautilus-extensions/nautilus-scalable-font.h>
BEGIN_GNOME_DECLS
@@ -35,42 +35,31 @@ BEGIN_GNOME_DECLS
#define NAUTILUS_FONT_PICKER_CLASS(klass) (GTK_CHECK_CLASS_CAST ((klass), NAUTILUS_TYPE_FONT_PICKER, NautilusFontPickerClass))
#define NAUTILUS_IS_FONT_PICKER(obj) (GTK_CHECK_TYPE ((obj), NAUTILUS_TYPE_FONT_PICKER))
-typedef struct _NautilusFontPicker NautilusFontPicker;
-typedef struct _NautilusFontPickerClass NautilusFontPickerClass;
-typedef struct _NautilusFontPickerDetail NautilusFontPickerDetail;
+typedef struct NautilusFontPicker NautilusFontPicker;
+typedef struct NautilusFontPickerClass NautilusFontPickerClass;
+typedef struct NautilusFontPickerDetails NautilusFontPickerDetails;
-struct _NautilusFontPicker
+struct NautilusFontPicker
{
/* Super Class */
- GtkHBox hbox;
+ GtkVBox vbox;
/* Private stuff */
- NautilusFontPickerDetail *detail;
+ NautilusFontPickerDetails *details;
};
-struct _NautilusFontPickerClass
+struct NautilusFontPickerClass
{
- GtkHBoxClass parent_class;
+ GtkVBoxClass parent_class;
};
-GtkType nautilus_font_picker_get_type (void);
-GtkWidget* nautilus_font_picker_new (void);
-void nautilus_font_picker_set_show_weights (NautilusFontPicker *font_picker);
-void nautilus_font_picker_set_show_slants (NautilusFontPicker *font_picker);
-void nautilus_font_picker_set_show_set_widths (NautilusFontPicker *font_picker);
-void nautilus_font_picker_set_selected_family (NautilusFontPicker *font_picker,
- const char *family);
-void nautilus_font_picker_set_selected_weight (NautilusFontPicker *font_picker,
- const char *weight);
-void nautilus_font_picker_set_selected_slant (NautilusFontPicker *font_picker,
- const char *slant);
-void nautilus_font_picker_set_selected_set_width (NautilusFontPicker *font_picker,
- const char *set_width);
-char * nautilus_font_picker_get_selected_family (const NautilusFontPicker *font_picker);
-char * nautilus_font_picker_get_selected_weight (const NautilusFontPicker *font_picker);
-char * nautilus_font_picker_get_selected_slant (const NautilusFontPicker *font_picker);
-char * nautilus_font_picker_get_selected_set_width (const NautilusFontPicker *font_picker);
-
+GtkType nautilus_font_picker_get_type (void);
+GtkWidget* nautilus_font_picker_new (void);
+char * nautilus_font_picker_get_selected_font (const NautilusFontPicker *font_picker);
+void nautilus_font_picker_set_selected_font (NautilusFontPicker *font_picker,
+ const char *font);
+void nautilus_font_picker_set_title_label (NautilusFontPicker *font_picker,
+ const char *title_label);
END_GNOME_DECLS
#endif /* NAUTILUS_FONT_PICKER_H */
diff --git a/libnautilus-extensions/nautilus-global-preferences.c b/libnautilus-extensions/nautilus-global-preferences.c
index aeee8d2eb..1ca75b872 100644
--- a/libnautilus-extensions/nautilus-global-preferences.c
+++ b/libnautilus-extensions/nautilus-global-preferences.c
@@ -34,6 +34,7 @@
#include "nautilus-string.h"
#include "nautilus-medusa-support.h"
#include "nautilus-view-identifier.h"
+#include "nautilus-font-manager.h"
#include <gconf/gconf.h>
#include <gconf/gconf-client.h>
#include <gtk/gtkbox.h>
@@ -65,11 +66,13 @@ static void global_preferences_install_speed_tradeoff_descriptions (const
const char *description);
static void global_preferences_install_home_location_defaults (void);
static void global_preferences_install_medusa_defaults (void);
+static void global_preferences_install_font_defaults (void);
static void global_preferences_install_descriptions (void);
static int compare_view_identifiers (gconstpointer a,
gconstpointer b);
static GtkWidget *global_preferences_create_dialog (void);
static GtkWidget *global_preferences_create_search_pane (NautilusPreferencesBox *preference_box);
+static GtkWidget *global_preferences_create_font_group (NautilusPreferencesPane *appearance_pane);
static GtkWidget *global_prefs_dialog = NULL;
@@ -153,6 +156,8 @@ global_preferences_install_descriptions (void)
nautilus_preferences_set_description (NAUTILUS_PREFERENCES_DIRECTORY_VIEW_FONT_FAMILY,
_("Use this font family to display file names:"));
+ nautilus_preferences_set_description (NAUTILUS_PREFERENCES_DIRECTORY_VIEW_SMOOTH_FONT,
+ _("Use this font family to display file names:"));
nautilus_preferences_set_description (NAUTILUS_PREFERENCES_START_WITH_TOOLBAR,
_("Display toolbar in new windows"));
@@ -262,10 +267,6 @@ global_preferences_install_defaults (void)
NAUTILUS_USER_LEVEL_INTERMEDIATE,
NAUTILUS_SPEED_TRADEOFF_ALWAYS);
- nautilus_preferences_default_set_string (NAUTILUS_PREFERENCES_DIRECTORY_VIEW_FONT_FAMILY,
- NAUTILUS_USER_LEVEL_NOVICE,
- _("helvetica"));
-
nautilus_preferences_default_set_integer (NAUTILUS_PREFERENCES_CLICK_POLICY,
NAUTILUS_USER_LEVEL_NOVICE,
NAUTILUS_CLICK_POLICY_DOUBLE);
@@ -374,6 +375,9 @@ global_preferences_install_defaults (void)
/* Home location */
global_preferences_install_home_location_defaults ();
+ /* Fonts */
+ global_preferences_install_font_defaults ();
+
/* Medusa */
global_preferences_install_medusa_defaults ();
}
@@ -530,12 +534,11 @@ global_preferences_create_dialog (void)
0,
NAUTILUS_PREFERENCES_SMOOTH_GRAPHICS_MODE,
NAUTILUS_PREFERENCE_ITEM_BOOLEAN);
-
- nautilus_preferences_pane_add_group (NAUTILUS_PREFERENCES_PANE (appearance_pane), _("Fonts"));
- nautilus_preferences_pane_add_item_to_nth_group (NAUTILUS_PREFERENCES_PANE (appearance_pane),
- 1,
- NAUTILUS_PREFERENCES_DIRECTORY_VIEW_FONT_FAMILY,
- NAUTILUS_PREFERENCE_ITEM_FONT_FAMILY);
+
+ /*
+ * Fonts
+ */
+ global_preferences_create_font_group (NAUTILUS_PREFERENCES_PANE (appearance_pane));
/*
@@ -816,6 +819,56 @@ global_preferences_create_search_pane (NautilusPreferencesBox *preference_box)
return search_pane;
}
+/*
+ * We have 2 font picker items, but we only show one depending on
+ * the value of the SMOOTH_GRAPHICS preference.
+ */
+static void
+appearnace_pane_update (gpointer callback_data)
+{
+ g_return_if_fail (NAUTILUS_IS_PREFERENCES_PANE (callback_data));
+
+ nautilus_preferences_pane_update (NAUTILUS_PREFERENCES_PANE (callback_data));
+}
+
+static GtkWidget *
+global_preferences_create_font_group (NautilusPreferencesPane *appearance_pane)
+{
+ GtkWidget *font_group;
+ GtkWidget *font_picker_smooth_item;
+ GtkWidget *font_picker_gdk_item;
+
+ font_group =
+ nautilus_preferences_pane_add_group (NAUTILUS_PREFERENCES_PANE (appearance_pane), _("Fonts"));
+
+ font_picker_gdk_item =
+ nautilus_preferences_pane_add_item_to_nth_group (NAUTILUS_PREFERENCES_PANE (appearance_pane),
+ 1,
+ NAUTILUS_PREFERENCES_DIRECTORY_VIEW_FONT_FAMILY,
+ NAUTILUS_PREFERENCE_ITEM_FONT_FAMILY);
+ nautilus_preferences_item_set_control_preference (NAUTILUS_PREFERENCES_ITEM (font_picker_gdk_item),
+ NAUTILUS_PREFERENCES_SMOOTH_GRAPHICS_MODE);
+ nautilus_preferences_item_set_control_action (NAUTILUS_PREFERENCES_ITEM (font_picker_gdk_item),
+ NAUTILUS_PREFERENCE_ITEM_HIDE);
+
+ font_picker_smooth_item =
+ nautilus_preferences_pane_add_item_to_nth_group (NAUTILUS_PREFERENCES_PANE (appearance_pane),
+ 1,
+ NAUTILUS_PREFERENCES_DIRECTORY_VIEW_SMOOTH_FONT,
+ NAUTILUS_PREFERENCE_ITEM_SMOOTH_FONT);
+
+ nautilus_preferences_item_set_control_preference (NAUTILUS_PREFERENCES_ITEM (font_picker_gdk_item),
+ NAUTILUS_PREFERENCES_SMOOTH_GRAPHICS_MODE);
+ nautilus_preferences_item_set_control_action (NAUTILUS_PREFERENCES_ITEM (font_picker_smooth_item),
+ NAUTILUS_PREFERENCE_ITEM_SHOW);
+
+ nautilus_preferences_add_callback (NAUTILUS_PREFERENCES_SMOOTH_GRAPHICS_MODE,
+ appearnace_pane_update,
+ appearance_pane);
+
+ return font_group;
+}
+
/* Make a query to find out what sidebar panels are available. */
static GList *
global_preferences_get_sidebar_panel_view_identifiers (void)
@@ -1051,6 +1104,24 @@ global_preferences_install_home_location_defaults (void)
}
static void
+global_preferences_install_font_defaults (void)
+{
+ char *fallback_smooth_font;
+
+ nautilus_preferences_default_set_string (NAUTILUS_PREFERENCES_DIRECTORY_VIEW_FONT_FAMILY,
+ NAUTILUS_USER_LEVEL_NOVICE,
+ _("helvetica"));
+
+ /* The default smooth font */
+ fallback_smooth_font = nautilus_font_manager_get_fallback_font ();
+
+ nautilus_preferences_default_set_string (NAUTILUS_PREFERENCES_DIRECTORY_VIEW_SMOOTH_FONT,
+ NAUTILUS_USER_LEVEL_NOVICE,
+ fallback_smooth_font);
+ g_free (fallback_smooth_font);
+}
+
+static void
global_preferences_use_fast_search_changed_callback (gpointer callback_data)
{
gboolean use_fast_search;
diff --git a/libnautilus-extensions/nautilus-global-preferences.h b/libnautilus-extensions/nautilus-global-preferences.h
index fc8ebe310..661dd680e 100644
--- a/libnautilus-extensions/nautilus-global-preferences.h
+++ b/libnautilus-extensions/nautilus-global-preferences.h
@@ -91,6 +91,7 @@ BEGIN_GNOME_DECLS
/* Directory view */
#define NAUTILUS_PREFERENCES_DIRECTORY_VIEW_FONT_FAMILY "directory-view/font_family"
+#define NAUTILUS_PREFERENCES_DIRECTORY_VIEW_SMOOTH_FONT "directory-view/smooth_font"
/* File Indexing */
#define NAUTILUS_PREFERENCES_SEARCH_BAR_TYPE "preferences/search_bar_type"
diff --git a/libnautilus-extensions/nautilus-gtk-extensions.c b/libnautilus-extensions/nautilus-gtk-extensions.c
index ff7a9c57a..93738e211 100644
--- a/libnautilus-extensions/nautilus-gtk-extensions.c
+++ b/libnautilus-extensions/nautilus-gtk-extensions.c
@@ -1185,6 +1185,25 @@ nautilus_gtk_widget_set_font (GtkWidget *widget, GdkFont *font)
}
/**
+ * nautilus_gtk_widget_set_shown
+ *
+ * Show or hide a widget.
+ * @widget: The widget.
+ * @shown: Boolean value indicating whether the widget should be shown or hidden.
+ **/
+void
+nautilus_gtk_widget_set_shown (GtkWidget *widget, gboolean shown)
+{
+ g_return_if_fail (GTK_IS_WIDGET (widget));
+
+ if (shown) {
+ gtk_widget_show (widget);
+ } else {
+ gtk_widget_hide (widget);
+ }
+}
+
+/**
* nautilus_gtk_widget_set_font_by_name
*
* Sets the font for a widget, managing the font and style objects.
diff --git a/libnautilus-extensions/nautilus-gtk-extensions.h b/libnautilus-extensions/nautilus-gtk-extensions.h
index a219dbb2f..fbc19cb39 100644
--- a/libnautilus-extensions/nautilus-gtk-extensions.h
+++ b/libnautilus-extensions/nautilus-gtk-extensions.h
@@ -86,6 +86,8 @@ void nautilus_gtk_object_list_free (GList
GList * nautilus_gtk_object_list_copy (GList *list);
/* GtkWidget */
+void nautilus_gtk_widget_set_shown (GtkWidget *widget,
+ gboolean shown);
gboolean nautilus_point_in_allocation (const GtkAllocation *allocation,
int x,
int y);
diff --git a/libnautilus-extensions/nautilus-preferences-group.c b/libnautilus-extensions/nautilus-preferences-group.c
index baa6a9bfe..bdf83865c 100644
--- a/libnautilus-extensions/nautilus-preferences-group.c
+++ b/libnautilus-extensions/nautilus-preferences-group.c
@@ -24,6 +24,7 @@
#include <config.h>
#include "nautilus-preferences-group.h"
+#include "nautilus-gtk-extensions.h"
#include <gnome.h>
#include <gtk/gtkradiobutton.h>
@@ -232,22 +233,26 @@ nautilus_preferences_group_update (NautilusPreferencesGroup *group)
{
GList *iterator;
NautilusPreferencesItem *preferences_item;
+ gboolean shown;
+ char *name = NULL;
g_return_if_fail (NAUTILUS_IS_PREFERENCES_GROUP (group));
-
+
for (iterator = group->details->items; iterator != NULL; iterator = iterator->next) {
- char *name;
-
preferences_item = NAUTILUS_PREFERENCES_ITEM (iterator->data);
+
name = nautilus_preferences_item_get_name (preferences_item);
+
nautilus_preferences_item_update_displayed_value (preferences_item);
if (nautilus_preferences_is_visible (name)) {
- gtk_widget_show (GTK_WIDGET (iterator->data));
+ shown = nautilus_preferences_item_get_control_showing (preferences_item);
} else {
- gtk_widget_hide (GTK_WIDGET (iterator->data));
+ shown = FALSE;
}
-
+
+ nautilus_gtk_widget_set_shown (GTK_WIDGET (iterator->data), shown);
+
g_free (name);
}
}
diff --git a/libnautilus-extensions/nautilus-preferences-item.c b/libnautilus-extensions/nautilus-preferences-item.c
index fad424973..20cdd7607 100644
--- a/libnautilus-extensions/nautilus-preferences-item.c
+++ b/libnautilus-extensions/nautilus-preferences-item.c
@@ -39,6 +39,7 @@
#include "nautilus-radio-button-group.h"
#include "nautilus-string-picker.h"
+#include "nautilus-font-picker.h"
#include "nautilus-text-caption.h"
#include "nautilus-global-preferences.h"
@@ -55,6 +56,8 @@ struct _NautilusPreferencesItemDetails
NautilusPreferencesItemType item_type;
GtkWidget *child;
guint change_signal_ID;
+ char *control_preference_name;
+ NautilusPreferencesItemControlAction control_action;
};
/* GtkObjectClass methods */
@@ -78,6 +81,8 @@ static void preferences_item_create_integer (NautilusPreference
const char *preference_name);
static void preferences_item_create_font_family (NautilusPreferencesItem *item,
const char *preference_name);
+static void preferences_item_create_smooth_font (NautilusPreferencesItem *item,
+ const char *preference_name);
static void preferences_item_update_text_settings_at_idle (NautilusPreferencesItem *preferences_item);
static void preferences_item_update_integer_settings_at_idle (NautilusPreferencesItem *preferences_item);
static void enum_radio_group_changed_callback (GtkWidget *button_group,
@@ -128,6 +133,7 @@ preferences_item_destroy (GtkObject *object)
item = NAUTILUS_PREFERENCES_ITEM (object);
g_free (item->details->preference_name);
+ g_free (item->details->control_preference_name);
g_free (item->details);
/* Chain destroy */
@@ -173,6 +179,10 @@ preferences_item_construct (NautilusPreferencesItem *item,
preferences_item_create_font_family (item, preference_name);
break;
+ case NAUTILUS_PREFERENCE_ITEM_SMOOTH_FONT:
+ preferences_item_create_smooth_font (item, preference_name);
+ break;
+
case NAUTILUS_PREFERENCE_ITEM_EDITABLE_STRING:
preferences_item_create_editable_string (item, preference_name);
break;
@@ -450,7 +460,7 @@ preferences_item_update_font_family (const NautilusPreferencesItem *item)
static void
preferences_item_create_font_family (NautilusPreferencesItem *item,
- const char *preference_name)
+ const char *preference_name)
{
char *description;
NautilusStringList *font_list;
@@ -483,6 +493,64 @@ preferences_item_create_font_family (NautilusPreferencesItem *item,
(gpointer) item);
}
+
+static void
+preferences_item_update_smooth_font (const NautilusPreferencesItem *item)
+{
+ char *current_value;
+
+ g_return_if_fail (NAUTILUS_IS_PREFERENCES_ITEM (item));
+ g_return_if_fail (item->details->item_type == NAUTILUS_PREFERENCE_ITEM_SMOOTH_FONT);
+
+ current_value = nautilus_preferences_get (item->details->preference_name);
+ g_assert (current_value != NULL);
+
+ nautilus_font_picker_set_selected_font (NAUTILUS_FONT_PICKER (item->details->child),
+ current_value);
+ g_free (current_value);
+}
+
+static void
+preferences_smooth_font_changed_callback (NautilusFontPicker *font_picker,
+ gpointer callback_data)
+{
+ NautilusPreferencesItem *item;
+ char *new_value;
+
+ g_return_if_fail (NAUTILUS_IS_FONT_PICKER (font_picker));
+ g_return_if_fail (NAUTILUS_IS_PREFERENCES_ITEM (callback_data));
+
+ item = NAUTILUS_PREFERENCES_ITEM (callback_data);
+ new_value = nautilus_font_picker_get_selected_font (NAUTILUS_FONT_PICKER (item->details->child));
+ g_assert (new_value != NULL);
+ nautilus_preferences_set (item->details->preference_name, new_value);
+ g_free (new_value);
+}
+
+static void
+preferences_item_create_smooth_font (NautilusPreferencesItem *item,
+ const char *preference_name)
+{
+ char *description = NULL;
+
+ g_return_if_fail (NAUTILUS_IS_PREFERENCES_ITEM (item));
+ g_return_if_fail (nautilus_strlen (preference_name) > 0);
+
+ description = nautilus_preferences_get_description (preference_name);
+ g_return_if_fail (description != NULL);
+
+ item->details->child = nautilus_font_picker_new ();
+ nautilus_font_picker_set_title_label (NAUTILUS_FONT_PICKER (item->details->child),
+ description);
+
+ g_free (description);
+
+ item->details->change_signal_ID = gtk_signal_connect (GTK_OBJECT (item->details->child),
+ "changed",
+ GTK_SIGNAL_FUNC (preferences_smooth_font_changed_callback),
+ item);
+}
+
/* NautilusPreferencesItem public methods */
GtkWidget *
nautilus_preferences_item_new (const char *preference_name,
@@ -629,6 +697,10 @@ nautilus_preferences_item_update_displayed_value (const NautilusPreferencesItem
preferences_item_update_font_family (item);
break;
+ case NAUTILUS_PREFERENCE_ITEM_SMOOTH_FONT:
+ preferences_item_update_smooth_font (item);
+ break;
+
case NAUTILUS_PREFERENCE_ITEM_EDITABLE_STRING:
preferences_item_update_editable_string (item);
break;
@@ -701,3 +773,57 @@ preferences_item_update_integer_settings_at_idle (NautilusPreferencesItem *prefe
integer_idle_handler = TRUE;
}
}
+
+void
+nautilus_preferences_item_set_control_preference (NautilusPreferencesItem *preferences_item,
+ const char *control_preference_name)
+{
+ g_return_if_fail (NAUTILUS_IS_PREFERENCES_ITEM (preferences_item));
+
+ if (nautilus_str_is_equal (preferences_item->details->control_preference_name,
+ control_preference_name)) {
+ return;
+ }
+
+ g_free (preferences_item->details->control_preference_name);
+ preferences_item->details->control_preference_name = g_strdup (control_preference_name);
+}
+
+void
+nautilus_preferences_item_set_control_action (NautilusPreferencesItem *preferences_item,
+ NautilusPreferencesItemControlAction control_action)
+{
+ g_return_if_fail (NAUTILUS_IS_PREFERENCES_ITEM (preferences_item));
+ g_return_if_fail (control_action >= NAUTILUS_PREFERENCE_ITEM_SHOW);
+ g_return_if_fail (control_action <= NAUTILUS_PREFERENCE_ITEM_HIDE);
+
+ if (preferences_item->details->control_action == control_action) {
+ return;
+ }
+
+ preferences_item->details->control_action = control_action;
+}
+
+gboolean
+nautilus_preferences_item_get_control_showing (const NautilusPreferencesItem *preferences_item)
+{
+ gboolean value;
+
+ g_return_val_if_fail (NAUTILUS_IS_PREFERENCES_ITEM (preferences_item), FALSE);
+
+ if (preferences_item->details->control_preference_name == NULL) {
+ return TRUE;
+ }
+
+ value = nautilus_preferences_get_boolean (preferences_item->details->control_preference_name);
+
+ if (preferences_item->details->control_action == NAUTILUS_PREFERENCE_ITEM_SHOW) {
+ return value;
+ }
+
+ if (preferences_item->details->control_action == NAUTILUS_PREFERENCE_ITEM_HIDE) {
+ return !value;
+ }
+
+ return !value;
+}
diff --git a/libnautilus-extensions/nautilus-preferences-item.h b/libnautilus-extensions/nautilus-preferences-item.h
index 11fba2436..56348b2ef 100644
--- a/libnautilus-extensions/nautilus-preferences-item.h
+++ b/libnautilus-extensions/nautilus-preferences-item.h
@@ -67,15 +67,27 @@ typedef enum
NAUTILUS_PREFERENCE_ITEM_ENUM,
NAUTILUS_PREFERENCE_ITEM_SHORT_ENUM,
NAUTILUS_PREFERENCE_ITEM_FONT_FAMILY,
+ NAUTILUS_PREFERENCE_ITEM_SMOOTH_FONT,
NAUTILUS_PREFERENCE_ITEM_EDITABLE_STRING,
NAUTILUS_PREFERENCE_ITEM_INTEGER
} NautilusPreferencesItemType;
+typedef enum
+{
+ NAUTILUS_PREFERENCE_ITEM_SHOW,
+ NAUTILUS_PREFERENCE_ITEM_HIDE
+} NautilusPreferencesItemControlAction;
+
GtkType nautilus_preferences_item_get_type (void);
-GtkWidget* nautilus_preferences_item_new (const char *preference_name,
- NautilusPreferencesItemType item_type);
-char * nautilus_preferences_item_get_name (const NautilusPreferencesItem *preferences_item);
-void nautilus_preferences_item_update_displayed_value (const NautilusPreferencesItem *preferences_item);
+GtkWidget* nautilus_preferences_item_new (const char *preference_name,
+ NautilusPreferencesItemType item_type);
+char * nautilus_preferences_item_get_name (const NautilusPreferencesItem *preferences_item);
+void nautilus_preferences_item_update_displayed_value (const NautilusPreferencesItem *preferences_item);
+void nautilus_preferences_item_set_control_preference (NautilusPreferencesItem *preferences_item,
+ const char *control_preference_name);
+void nautilus_preferences_item_set_control_action (NautilusPreferencesItem *preferences_item,
+ NautilusPreferencesItemControlAction control_action);
+gboolean nautilus_preferences_item_get_control_showing (const NautilusPreferencesItem *preferences_item);
END_GNOME_DECLS
diff --git a/libnautilus-extensions/nautilus-preferences-pane.c b/libnautilus-extensions/nautilus-preferences-pane.c
index f425e0194..3466661de 100644
--- a/libnautilus-extensions/nautilus-preferences-pane.c
+++ b/libnautilus-extensions/nautilus-preferences-pane.c
@@ -26,6 +26,7 @@
#include <config.h>
#include "nautilus-preferences-pane.h"
#include "nautilus-gtk-macros.h"
+#include "nautilus-gtk-extensions.h"
#include <gtk/gtkhbox.h>
@@ -184,14 +185,9 @@ nautilus_preferences_pane_update (NautilusPreferencesPane *preferences_pane)
for (iterator = preferences_pane->details->groups; iterator != NULL; iterator = iterator->next) {
NautilusPreferencesGroup *group = NAUTILUS_PREFERENCES_GROUP (iterator->data);
-
nautilus_preferences_group_update (group);
-
- if (nautilus_preferences_group_get_num_visible_items (group) == 0) {
- gtk_widget_hide (GTK_WIDGET (group));
- } else {
- gtk_widget_show (GTK_WIDGET (group));
- }
+ nautilus_gtk_widget_set_shown (GTK_WIDGET (group),
+ nautilus_preferences_group_get_num_visible_items (group) > 0);
}
}
diff --git a/libnautilus-extensions/nautilus-scalable-font.c b/libnautilus-extensions/nautilus-scalable-font.c
index c18167cfd..b1c4a516d 100644
--- a/libnautilus-extensions/nautilus-scalable-font.c
+++ b/libnautilus-extensions/nautilus-scalable-font.c
@@ -527,10 +527,10 @@ font_family_string_map_new (void)
* Of course, specifying the font by its exact name will continue to work.
*/
if (font_family_lookup (global_font_family_table, "nimbus sans l")) {
- nautilus_string_map_add (map, "nimbus sans l", "helvetica");
+ nautilus_string_map_add (map, "nimbus sans l", "helvetica default");
}
- else if (font_family_lookup (global_font_family_table, "helvetica")) {
- nautilus_string_map_add (map, "helvetica", "nimbus sans l");
+ else if (font_family_lookup (global_font_family_table, "helvetica default")) {
+ nautilus_string_map_add (map, "helvetica default", "nimbus sans l");
}
return map;
@@ -611,6 +611,34 @@ nautilus_scalable_font_new (const char *family,
return font;
}
+/**
+ * nautilus_scalable_font_new_from_file_name:
+ * @file_name: Postscript or TrueType font file name.
+ *
+ * Returns a font for the given font file name.
+ *
+ */
+NautilusScalableFont *
+nautilus_scalable_font_new_from_file_name (const char *file_name)
+{
+ NautilusScalableFont *font;
+
+ g_return_val_if_fail (nautilus_strlen (file_name) > 0, NULL);
+ g_return_val_if_fail (g_file_exists (file_name), NULL);
+
+ initialize_global_stuff_if_needed ();
+
+ font = NAUTILUS_SCALABLE_FONT (gtk_object_new (nautilus_scalable_font_get_type (), NULL));
+ gtk_object_ref (GTK_OBJECT (font));
+ gtk_object_sink (GTK_OBJECT (font));
+
+ font->detail->font_handle = rsvg_ft_intern (global_rsvg_ft_context, file_name);
+ font->detail->font_family_entry = NULL;
+ font->detail->font_entry = NULL;
+
+ return font;
+}
+
NautilusScalableFont *
nautilus_scalable_font_make_bold (NautilusScalableFont *font)
{
@@ -792,7 +820,7 @@ NautilusScalableFont *
nautilus_scalable_font_get_default_font (void)
{
if (global_default_font == NULL) {
- global_default_font = nautilus_scalable_font_new ("helvetica", NULL, NULL, NULL);
+ global_default_font = nautilus_scalable_font_new ("helvetica default", NULL, NULL, NULL);
g_assert (global_default_font != NULL);
g_atexit (default_font_at_exit_destructor);
}
@@ -802,6 +830,19 @@ nautilus_scalable_font_get_default_font (void)
return global_default_font;
}
+NautilusScalableFont *
+nautilus_scalable_font_get_default_bold_font (void)
+{
+ NautilusScalableFont *default_font;
+ NautilusScalableFont *default_bold_font;
+
+ default_font = nautilus_scalable_font_get_default_font ();
+ default_bold_font = nautilus_scalable_font_make_bold (default_font);
+ gtk_object_unref (GTK_OBJECT (default_font));
+
+ return default_bold_font;
+}
+
static void
font_family_table_for_each_append (gpointer key,
gpointer value,
@@ -924,14 +965,6 @@ nautilus_scalable_font_query_font (const char *family,
return TRUE;
}
-#if 0
-static const char * global_default_font_path[] =
-{
- "/usr/lib/X11/fonts/Type1",
- "/usr/share/fonts/default/Type1"
-};
-#endif
-
/* 'atexit' destructors for global stuff */
static void
destroy_global_rsvg_ft_context (void)
@@ -972,13 +1005,7 @@ initialize_global_stuff_if_needed (void)
if (!fonts_initialized) {
fonts_initialized = TRUE;
global_font_family_table = g_hash_table_new (g_str_hash, g_str_equal);
-
-#if TYPE1_FONT_DIR_EXISTS
- font_family_table_add_fonts (global_font_family_table, "/usr/share/fonts/default/Type1");
-#else
font_family_table_add_fonts (global_font_family_table, NAUTILUS_DATADIR "/fonts/urw");
-#endif
-
g_atexit (font_family_table_at_exit_destructor);
}
@@ -989,31 +1016,6 @@ initialize_global_stuff_if_needed (void)
}
}
-int
-nautilus_scalable_font_get_underline_height (const NautilusScalableFont *font,
- int font_size)
-{
- g_return_val_if_fail (NAUTILUS_IS_SCALABLE_FONT (font), 0);
- g_return_val_if_fail (font_size > 0, 0);
-
- /* FIXME bugzilla.eazel.com 2865: This underlining code should
- * take into account the baseline for the rendered string rather
- * that doing the '1' nonsense.
- */
- return 1;
-}
-
-int
-nautilus_scalable_font_get_baseline (const NautilusScalableFont *font,
- int font_size)
-{
- /* FIXME bugzilla.eazel.com 2865: This underlining code should
- * take into account the baseline for the rendered string rather
- * that doing the '-2' nonsense.
- */
- return -2;
-}
-
/* Private NautilusScalableFont things */
int
nautilus_scalable_font_get_rsvg_handle (const NautilusScalableFont *font)
diff --git a/libnautilus-extensions/nautilus-scalable-font.h b/libnautilus-extensions/nautilus-scalable-font.h
index 92d82e80b..40c860cc8 100644
--- a/libnautilus-extensions/nautilus-scalable-font.h
+++ b/libnautilus-extensions/nautilus-scalable-font.h
@@ -78,6 +78,7 @@ NautilusScalableFont *nautilus_scalable_font_new (const c
const char *weight,
const char *slant,
const char *set_width);
+NautilusScalableFont * nautilus_scalable_font_new_from_file_name (const char *file_name);
NautilusDimensions nautilus_scalable_font_measure_text (const NautilusScalableFont *font,
int font_size,
const char *text,
@@ -102,16 +103,14 @@ int nautilus_scalable_font_largest_fitting_font_size (const N
int minimum_acceptable_font_size,
int maximum_acceptable_font_size);
NautilusScalableFont *nautilus_scalable_font_get_default_font (void);
+NautilusScalableFont *nautilus_scalable_font_get_default_bold_font (void);
NautilusStringList * nautilus_scalable_font_get_font_family_list (void);
gboolean nautilus_scalable_font_query_font (const char *family,
NautilusStringList **weights,
NautilusStringList **slants,
NautilusStringList **set_widths);
NautilusScalableFont *nautilus_scalable_font_make_bold (NautilusScalableFont *font);
-int nautilus_scalable_font_get_underline_height (const NautilusScalableFont *font,
- int font_size);
-int nautilus_scalable_font_get_baseline (const NautilusScalableFont *font,
- int font_size);
+
END_GNOME_DECLS
#endif /* NAUTILUS_SCALABLE_FONT_H */
diff --git a/libnautilus-extensions/nautilus-string-picker.c b/libnautilus-extensions/nautilus-string-picker.c
index 34d1be9f3..370266393 100644
--- a/libnautilus-extensions/nautilus-string-picker.c
+++ b/libnautilus-extensions/nautilus-string-picker.c
@@ -362,3 +362,27 @@ nautilus_string_picker_get_index_for_string (const NautilusStringPicker *string_
return nautilus_string_list_get_index_for_string (string_picker->detail->string_list, string);
}
+
+/**
+ * nautilus_string_picker_clear:
+
+ * @string_picker: A NautilusStringPicker
+ *
+ * Remove all entries from the string picker.
+ */
+void
+nautilus_string_picker_clear (NautilusStringPicker *string_picker)
+{
+ NautilusStringList *empty_list;
+
+ g_return_if_fail (NAUTILUS_IS_STRING_PICKER (string_picker));
+
+ /* Already empty */
+ if (nautilus_string_list_get_length (string_picker->detail->string_list) == 0) {
+ return;
+ }
+
+ empty_list = nautilus_string_list_new (TRUE);
+ nautilus_string_picker_set_string_list (string_picker, empty_list);
+ nautilus_string_list_free (empty_list);
+}
diff --git a/libnautilus-extensions/nautilus-string-picker.h b/libnautilus-extensions/nautilus-string-picker.h
index ebfcb5b6a..9ce803b67 100644
--- a/libnautilus-extensions/nautilus-string-picker.h
+++ b/libnautilus-extensions/nautilus-string-picker.h
@@ -60,40 +60,42 @@ struct _NautilusStringPickerClass
NautilusCaptionClass parent_class;
};
-GtkType nautilus_string_picker_get_type (void);
-GtkWidget* nautilus_string_picker_new (void);
+GtkType nautilus_string_picker_get_type (void);
+GtkWidget* nautilus_string_picker_new (void);
/* Set the list of strings. */
-void nautilus_string_picker_set_string_list (NautilusStringPicker *string_picker,
- const NautilusStringList *string_list);
-
+void nautilus_string_picker_set_string_list (NautilusStringPicker *string_picker,
+ const NautilusStringList *string_list);
/* Access a copy of the list of strings. */
-NautilusStringList *nautilus_string_picker_get_string_list (const NautilusStringPicker *string_picker);
+NautilusStringList *nautilus_string_picker_get_string_list (const NautilusStringPicker *string_picker);
/* Get the selected string. Resulting string needs to be freed with g_free(). */
-char * nautilus_string_picker_get_selected_string (NautilusStringPicker *string_picker);
+char * nautilus_string_picker_get_selected_string (NautilusStringPicker *string_picker);
/* Set the selected string. The internal string list needs to contain the 'string'. */
-void nautilus_string_picker_set_selected_string (NautilusStringPicker *string_picker,
- const char *string);
+void nautilus_string_picker_set_selected_string (NautilusStringPicker *string_picker,
+ const char *string);
void nautilus_string_picker_set_selected_string_index (NautilusStringPicker *string_picker,
- guint index);
+ guint index);
/* Add a new string to the picker. */
-void nautilus_string_picker_insert_string (NautilusStringPicker *string_picker,
- const char *string);
+void nautilus_string_picker_insert_string (NautilusStringPicker *string_picker,
+ const char *string);
/* Does the string picker contain the given string ? */
-gboolean nautilus_string_picker_contains (const NautilusStringPicker *string_picker,
- const char *string);
+gboolean nautilus_string_picker_contains (const NautilusStringPicker *string_picker,
+ const char *string);
/* Return the index of the given string */
-int nautilus_string_picker_get_index_for_string (const NautilusStringPicker *string_picker,
- const char *string);
+int nautilus_string_picker_get_index_for_string (const NautilusStringPicker *string_picker,
+ const char *string);
+
+/* Remove all entries from the string picker. */
+void nautilus_string_picker_clear (NautilusStringPicker *string_picker);
END_GNOME_DECLS
diff --git a/libnautilus-extensions/nautilus-tabs.c b/libnautilus-extensions/nautilus-tabs.c
index 2fa4c7467..bc718847f 100644
--- a/libnautilus-extensions/nautilus-tabs.c
+++ b/libnautilus-extensions/nautilus-tabs.c
@@ -179,9 +179,9 @@ nautilus_tabs_initialize (NautilusTabs *tabs)
tabs->details->selected_tab = -1;
/* FIXME bugzilla.eazel.com 5456:
- * Hard coded font family and size.
+ * Hard coded font size.
*/
- tabs->details->tab_font = nautilus_scalable_font_new ("helvetica", "bold", NULL, NULL);
+ tabs->details->tab_font = nautilus_scalable_font_get_default_bold_font ();
tabs->details->font_size = 14;
gray_tab_directory_path = nautilus_theme_get_image_path ("gray_tab_pieces");
diff --git a/libnautilus-private/nautilus-font-manager.c b/libnautilus-private/nautilus-font-manager.c
index 331f58190..7b2c64db4 100644
--- a/libnautilus-private/nautilus-font-manager.c
+++ b/libnautilus-private/nautilus-font-manager.c
@@ -19,16 +19,18 @@
write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.
- Authors: Ramiro Estrugo <ramiro@eazel.com>
+ Authors: Pavel Cisler <pavel@eazel.com>,
+ Ramiro Estrugo <ramiro@eazel.com>
*/
#include <config.h>
#include "nautilus-font-manager.h"
-#include "nautilus-string.h"
-#include "nautilus-string-list.h"
-#include "nautilus-lib-self-check-functions.h"
-#include "nautilus-file-utilities.h"
+#include "nautilus-file-utilities.h"
+#include "nautilus-glib-extensions.h"
+#include "nautilus-lib-self-check-functions.h"
+#include "nautilus-string-list.h"
+#include "nautilus-string.h"
#include <libgnome/gnome-util.h>
#include <ctype.h>
#include <stdio.h>
@@ -48,8 +50,21 @@
#define FONTS_ALIAS_FILE_NAME "fonts.alias"
#define FONTS_SCALE_FILE_NAME "fonts.scale"
+#define FONT_SERVER_CONFIG_FILE "/etc/X11/fs/config"
+#define FALLBACK_FONT_DIRECTORY (NAUTILUS_DATADIR "/fonts/urw")
+#define USER_FONT_DIRECTORY_NAME "fonts"
+
+#define NAUTILUS_FONT_UNDEFINED ((NautilusFontType) 0)
+
+/*
+ * FontDescription:
+ *
+ * A structure that describes a single font entry;
+ *
+ */
typedef struct {
char *file_name;
+ NautilusFontType font_type;
char *foundry;
char *family;
char *weight;
@@ -59,47 +74,56 @@ typedef struct {
char *char_set_encoding;
} FontDescription;
+/*
+ * FontDescriptionTable:
+ *
+ * A table of 0 or more font descriptions.
+ *
+ */
typedef struct {
char *directory;
char *fonts_dir_file;
char *fonts_alias_file;
char *fonts_scale_file;
GList *descriptions;
- GList *postscript_font_list;
- GList *true_type_font_list;
} FontDescriptionTable;
-static gboolean string_is_valid (const char *string);
-static char * file_as_string (const char *file_name);
-static gboolean directory_contains_file (const char *directory,
- const char *file_name);
-static FontDescription * font_description_new (const char *font_file_name,
- const char *xlfd_string);
-static void font_description_free (FontDescription *description);
-static void font_description_table_for_each (const FontDescriptionTable *description_table,
- NautilusFontManagerIterationCallback callback,
- gpointer callback_data);
-static char *font_description_get_file_name (const FontDescription *description);
-static char *font_description_get_foundry (const FontDescription *description);
-static char *font_description_get_family (const FontDescription *description);
-static char *font_description_get_weight (const FontDescription *description);
-static char *font_description_get_slant (const FontDescription *description);
-static char *font_description_get_set_width (const FontDescription *description);
-static char *font_description_get_char_set_registry (const FontDescription *description);
-static char *font_description_get_char_set_encoding (const FontDescription *description);
-static FontDescriptionTable * font_description_table_new (const char *font_directory);
-static void font_description_table_install_font_lists (FontDescriptionTable *table,
- GList *postscript_font_list,
- GList *true_type_font_list);
-static void font_description_table_add (FontDescriptionTable *description_table,
- const char *line);
-static guint font_description_table_get_length (const FontDescriptionTable *description_table);
-static const FontDescription * font_description_table_peek_nth (const FontDescriptionTable *description_table,
- guint n);
-static char * font_description_table_get_nth_file_name (const FontDescriptionTable *description_table,
- guint n);
-static void font_description_table_free (FontDescriptionTable *table);
-static void font_description_table_clear (FontDescriptionTable *table);
+static gboolean string_is_valid (const char *string);
+static char * file_as_string (const char *file_name);
+static gboolean directory_contains_file (const char *directory,
+ const char *file_name);
+static FontDescription * font_description_new (const char *font_file_name,
+ NautilusFontType font_type,
+ const char *xlfd_string);
+static void font_description_free (FontDescription *description);
+static void font_description_table_for_each (const FontDescriptionTable *description_table,
+ NautilusFontManagerCallback callback,
+ gpointer callback_data);
+static char *font_description_get_file_name (const FontDescription *description);
+static char *font_description_get_foundry (const FontDescription *description);
+static char *font_description_get_family (const FontDescription *description);
+static char *font_description_get_weight (const FontDescription *description);
+static char *font_description_get_slant (const FontDescription *description);
+static char *font_description_get_set_width (const FontDescription *description);
+static char *font_description_get_char_set_registry (const FontDescription *description);
+static char *font_description_get_char_set_encoding (const FontDescription *description);
+static FontDescriptionTable * font_description_table_new (const char *font_directory,
+ const GList *postscript_font_list,
+ const GList *true_type_font_list);
+static void font_description_table_add (FontDescriptionTable *description_table,
+ const char *line,
+ const GList *postscript_font_list,
+ const GList *true_type_font_list);
+static NautilusFontType font_get_font_type (const char *font_file_name,
+ const GList *postscript_font_list,
+ const GList *true_type_font_list);
+static guint font_description_table_get_length (const FontDescriptionTable *description_table);
+static const FontDescription * font_description_table_peek_nth (const FontDescriptionTable *description_table,
+ guint n);
+static char * font_description_table_get_nth_file_name (const FontDescriptionTable *table,
+ guint n);
+static void font_description_table_free (FontDescriptionTable *table);
+static void font_description_table_clear (FontDescriptionTable *table);
static gboolean
string_is_valid (const char *string)
@@ -150,6 +174,7 @@ file_as_string (const char *file_name)
static FontDescription *
font_description_new (const char *font_file_name,
+ NautilusFontType font_type,
const char *xlfd_string)
{
FontDescription *font_description = NULL;
@@ -157,12 +182,15 @@ font_description_new (const char *font_file_name,
g_return_val_if_fail (string_is_valid (font_file_name), NULL);
g_return_val_if_fail (string_is_valid (xlfd_string), NULL);
+ g_return_val_if_fail (font_type == NAUTILUS_FONT_POSTSCRIPT
+ || font_type == NAUTILUS_FONT_TRUE_TYPE, NULL);
tokenized_xlfd = nautilus_string_list_new_from_tokens (xlfd_string, "-", FALSE);
if (nautilus_string_list_get_length (tokenized_xlfd) == (XLFD_INDEX_MAX + 1)) {
font_description = g_new0 (FontDescription, 1);
- font_description->file_name = g_strdup (font_file_name);
+ font_description->file_name = g_strdup (font_file_name);
+ font_description->font_type = font_type;
font_description->foundry = nautilus_string_list_nth (tokenized_xlfd, XLFD_INDEX_FOUNDRY);
font_description->family = nautilus_string_list_nth (tokenized_xlfd, XLFD_INDEX_FAMILY);
font_description->weight = nautilus_string_list_nth (tokenized_xlfd, XLFD_INDEX_WEIGHT);
@@ -259,16 +287,29 @@ font_description_get_char_set_encoding (const FontDescription *description)
return g_strdup (description->char_set_encoding);
}
+static guint
+font_lists_total_num_fonts (const GList *postscript_font_list,
+ const GList *true_type_font_list)
+{
+ return g_list_length ((GList *) postscript_font_list)
+ + g_list_length ((GList *) true_type_font_list);
+}
+
static void
-font_description_table_add (FontDescriptionTable *description_table,
- const char *line)
+font_description_table_add (FontDescriptionTable *table,
+ const char *line,
+ const GList *postscript_font_list,
+ const GList *true_type_font_list)
{
char *font_file_name = NULL;
FontDescription *description;
char *xlfd_delimeter;
+ char *font_file_full_path;
+ NautilusFontType font_type;
- g_return_if_fail (description_table != NULL);
+ g_return_if_fail (table != NULL);
g_return_if_fail (string_is_valid (line));
+ g_return_if_fail (font_lists_total_num_fonts (postscript_font_list, true_type_font_list) > 0);
xlfd_delimeter = strstr (line, " ");
@@ -282,46 +323,81 @@ font_description_table_add (FontDescriptionTable *description_table,
while (isspace ((guchar) *xlfd_delimeter)) {
xlfd_delimeter++;
}
-
- description = font_description_new (font_file_name, xlfd_delimeter);
- if (description != NULL) {
- description_table->descriptions = g_list_append (description_table->descriptions,
- description);
+ font_file_full_path = nautilus_make_path (table->directory, font_file_name);
+ font_type = font_get_font_type (font_file_full_path,
+ postscript_font_list,
+ true_type_font_list);
+
+ if (font_type != NAUTILUS_FONT_UNDEFINED) {
+ description = font_description_new (font_file_full_path, font_type, xlfd_delimeter);
+ if (description != NULL) {
+ table->descriptions = g_list_append (table->descriptions, description);
+ }
}
+ g_free (font_file_full_path);
g_free (font_file_name);
}
+static NautilusFontType
+font_get_font_type (const char *font_file_name,
+ const GList *postscript_font_list,
+ const GList *true_type_font_list)
+{
+ const GList *node;
+
+ g_return_val_if_fail (string_is_valid (font_file_name), NAUTILUS_FONT_UNDEFINED);
+ g_return_val_if_fail (font_lists_total_num_fonts (postscript_font_list, true_type_font_list) > 0,
+ NAUTILUS_FONT_UNDEFINED);
+
+ node = postscript_font_list;
+ while (node != NULL) {
+ if (nautilus_istr_is_equal (node->data, font_file_name)) {
+ return NAUTILUS_FONT_POSTSCRIPT;
+ }
+ node = node->next;
+ }
+
+ node = true_type_font_list;
+ while (node != NULL) {
+ if (nautilus_istr_is_equal (node->data, font_file_name)) {
+ return NAUTILUS_FONT_TRUE_TYPE;
+ }
+ node = node->next;
+ }
+
+ return NAUTILUS_FONT_UNDEFINED;
+}
+
static guint
-font_description_table_get_length (const FontDescriptionTable *description_table)
+font_description_table_get_length (const FontDescriptionTable *table)
{
- g_return_val_if_fail (description_table != NULL, 0);
+ g_return_val_if_fail (table != NULL, 0);
- return g_list_length (description_table->descriptions);
+ return g_list_length (table->descriptions);
}
static const FontDescription *
-font_description_table_peek_nth (const FontDescriptionTable *description_table,
+font_description_table_peek_nth (const FontDescriptionTable *table,
guint n)
{
- g_return_val_if_fail (description_table != NULL, NULL);
- g_return_val_if_fail (n < font_description_table_get_length (description_table), NULL);
+ g_return_val_if_fail (table != NULL, NULL);
+ g_return_val_if_fail (n < font_description_table_get_length (table), NULL);
- return g_list_nth_data (description_table->descriptions, n);
+ return g_list_nth_data (table->descriptions, n);
}
static char *
-font_description_table_get_nth_file_name (const FontDescriptionTable *description_table,
- guint n)
+font_description_table_get_nth_file_name (const FontDescriptionTable *table,
+ guint n)
{
const FontDescription *description;
- g_return_val_if_fail (description_table != NULL, NULL);
- g_return_val_if_fail (n < font_description_table_get_length (description_table), NULL);
+ g_return_val_if_fail (table != NULL, NULL);
+ g_return_val_if_fail (n < font_description_table_get_length (table), NULL);
- description = font_description_table_peek_nth (description_table, n);
-
+ description = font_description_table_peek_nth (table, n);
return g_strdup (description->file_name);
}
@@ -364,22 +440,24 @@ font_description_table_clear (FontDescriptionTable *table)
}
static void
-font_description_table_for_each (const FontDescriptionTable *description_table,
- NautilusFontManagerIterationCallback callback,
+font_description_table_for_each (const FontDescriptionTable *table,
+ NautilusFontManagerCallback callback,
gpointer callback_data)
{
GList *node;
const FontDescription *description;
- g_return_if_fail (description_table != NULL);
+ g_return_if_fail (table != NULL);
g_return_if_fail (callback != NULL);
- node = description_table->descriptions;
+ node = table->descriptions;
while (node != NULL) {
description = node->data;
g_assert (node->data != NULL);
- (* callback) (description->foundry,
+ (* callback) (description->file_name,
+ description->font_type,
+ description->foundry,
description->family,
description->weight,
description->slant,
@@ -393,97 +471,83 @@ font_description_table_for_each (const FontDescriptionTable *description_table,
}
static FontDescriptionTable *
-table_new_from_contents (const char *contents)
+font_description_table_new (const char *font_directory,
+ const GList *postscript_font_list,
+ const GList *true_type_font_list)
{
- FontDescriptionTable *description_table;
+ FontDescriptionTable *table;
+ char *description_file;
+ char *description_contents;
NautilusStringList *tokenized_contents;
int i;
int count;
char *line;
- g_return_val_if_fail (string_is_valid (contents), NULL);
+ g_return_val_if_fail (string_is_valid (font_directory), NULL);
+ g_return_val_if_fail (g_file_test (font_directory, G_FILE_TEST_ISDIR), NULL);
+
+ description_file = nautilus_make_path (font_directory, FONTS_DIR_FILE_NAME);
+ description_contents = file_as_string (description_file);
+
+ if (description_contents == NULL) {
+ g_free (description_file);
+ return NULL;
+ }
- tokenized_contents = nautilus_string_list_new_from_tokens (contents, "\n", FALSE);
+ tokenized_contents = nautilus_string_list_new_from_tokens (description_contents, "\n", FALSE);
/* Make sure there is at least one description. Item 0 is the count */
if (nautilus_string_list_get_length (tokenized_contents) <= 1) {
+ g_free (description_file);
+ g_free (description_contents);
nautilus_string_list_free (tokenized_contents);
return NULL;
}
/* Find out how many font entries are described in this file */
if (!nautilus_string_list_nth_as_integer (tokenized_contents, 0, &count)) {
+ g_free (description_file);
+ g_free (description_contents);
nautilus_string_list_free (tokenized_contents);
return NULL;
}
- description_table = g_new0 (FontDescriptionTable, 1);
+ /* Create a new table */
+ table = g_new0 (FontDescriptionTable, 1);
+ /* Assign the directory and description file */
+ table->directory = g_strdup (font_directory);
+ table->fonts_dir_file = description_file;
+
+ /* Iterate throught the description file contents */
for (i = 0; i < count; i++) {
line = nautilus_string_list_nth (tokenized_contents, i + 1);
-
if (line != NULL) {
- font_description_table_add (description_table, line);
+ font_description_table_add (table,
+ line,
+ postscript_font_list,
+ true_type_font_list);
}
-
g_free (line);
}
-
nautilus_string_list_free (tokenized_contents);
- return description_table;
-}
-
-static FontDescriptionTable *
-font_description_table_new (const char *font_directory)
-{
- FontDescriptionTable *table;
- char *description_file;
- char *description_contents;
-
- g_return_val_if_fail (string_is_valid (font_directory), NULL);
- g_return_val_if_fail (g_file_test (font_directory, G_FILE_TEST_ISDIR), NULL);
-
- description_file = nautilus_make_path (font_directory, FONTS_DIR_FILE_NAME);
- description_contents = file_as_string (description_file);
+ /* Assign the alias file if found */
+ if (directory_contains_file (font_directory, FONTS_ALIAS_FILE_NAME)) {
+ table->fonts_alias_file = nautilus_make_path (font_directory, FONTS_ALIAS_FILE_NAME);
+ }
- if (description_contents == NULL) {
- g_free (description_file);
- return NULL;
+ /* Assign the alias scale if found */
+ if (directory_contains_file (font_directory, FONTS_SCALE_FILE_NAME)) {
+ table->fonts_scale_file = nautilus_make_path (font_directory, FONTS_SCALE_FILE_NAME);
}
- table = table_new_from_contents (description_contents);
+ g_free (description_contents);
- if (table != NULL) {
- table->fonts_dir_file = nautilus_make_path (font_directory, FONTS_DIR_FILE_NAME);
-
- /* Assign the alias file if found */
- if (directory_contains_file (font_directory, FONTS_ALIAS_FILE_NAME)) {
- table->fonts_alias_file = nautilus_make_path (font_directory, FONTS_ALIAS_FILE_NAME);
- }
-
- /* Assign the alias scale if found */
- if (directory_contains_file (font_directory, FONTS_SCALE_FILE_NAME)) {
- table->fonts_scale_file = nautilus_make_path (font_directory, FONTS_SCALE_FILE_NAME);
- }
- }
return table;
}
-static void
-font_description_table_install_font_lists (FontDescriptionTable *table,
- GList *postscript_font_list,
- GList *true_type_font_list)
-{
- g_return_if_fail (table != NULL);
- g_return_if_fail (table->postscript_font_list == NULL);
- g_return_if_fail (table->true_type_font_list == NULL);
-
- table->postscript_font_list = postscript_font_list;
- table->true_type_font_list = true_type_font_list;
-}
-
static GnomeVFSResult
collect_fonts_from_directory (const char *font_directory,
GList **postscript_font_list,
@@ -660,7 +724,7 @@ font_server_for_each_font_directory_internal (void (* callback) (const char *fon
fgets (buffer, READ_BUFFER_SIZE, file);
if (strlen (buffer) == 0) {
if (state != EXPECT_COMMA) {
- g_print ("unexpected file end\n");
+ g_warning ("unexpected file end.");
}
break;
}
@@ -684,7 +748,7 @@ font_server_for_each_font_directory_internal (void (* callback) (const char *fon
case EXPECT_ASSIGNMENT:
if (!token_matches(buffer, token_start, token_end, "=")) {
- g_print (" expected token \"=\" \n");
+ g_warning (" expected token \"=\" .");
return;
}
state = EXPECT_DIRECTORY;
@@ -692,7 +756,7 @@ font_server_for_each_font_directory_internal (void (* callback) (const char *fon
case EXPECT_DIRECTORY:
if (token_matches(buffer, token_start, token_end, ",")) {
- g_print (" expected directory name \n");
+ g_warning (" expected directory name.");
return;
}
/* found a directory, call an each function on it */
@@ -762,22 +826,50 @@ directory_contains_file (const char *directory,
return result;
}
-static void
-font_server_for_each_callback (const char *font_directory,
- gpointer callback_data)
+/* Iterating directories is slow cause of all the mim sniffing that
+ * has to happen on each potential scalalble font. By Ignoring
+ * directories known to be without scalable fonts, we make things
+ * much faster.
+ */
+static gboolean
+font_ignore_directory (const char *font_directory)
{
- FontDescriptionTable *table;
+ g_return_val_if_fail (string_is_valid (font_directory), TRUE);
- GList *postscript_font_list = NULL;
- GList *true_type_font_list = NULL;
+ if (nautilus_str_has_suffix (font_directory, "unscaled")) {
+ return TRUE;
+ }
- GList **collected_font_tables;
+ if (nautilus_str_has_suffix (font_directory, "100dpi")) {
+ return TRUE;
+ }
- g_return_if_fail (font_directory != NULL);
- g_return_if_fail (callback_data != NULL);
+ if (nautilus_str_has_suffix (font_directory, "75dpi")) {
+ return TRUE;
+ }
- collected_font_tables = callback_data;
+ if (nautilus_str_has_suffix (font_directory, "misc")) {
+ return TRUE;
+ }
+ return FALSE;
+}
+
+static void
+font_manager_collect_font_tables (const char *font_directory,
+ GList **collected_font_tables)
+{
+ GList *postscript_font_list = NULL;
+ GList *true_type_font_list = NULL;
+ FontDescriptionTable *table;
+
+ g_return_if_fail (string_is_valid (font_directory));
+ g_return_if_fail (collected_font_tables != NULL);
+
+ if (font_ignore_directory (font_directory)) {
+ return;
+ }
+
/* Collect postscript and true type font in this directory */
collect_fonts_from_directory (font_directory, &postscript_font_list, &true_type_font_list);
@@ -789,208 +881,263 @@ font_server_for_each_callback (const char *font_directory,
/* If no "fonts.dir" exists, then the user has a missing description file (broken setup) */
if (!directory_contains_file (font_directory, FONTS_DIR_FILE_NAME)) {
- g_free (postscript_font_list);
- g_free (true_type_font_list);
+ nautilus_g_list_free_deep (postscript_font_list);
+ nautilus_g_list_free_deep (true_type_font_list);
g_warning ("Direcotry '%s' contains scalable fonts but no '%s' description file.",
font_directory,
FONTS_DIR_FILE_NAME);
return;
}
- table = font_description_table_new (font_directory);
- g_assert (table != NULL);
-
- font_description_table_install_font_lists (table, postscript_font_list, true_type_font_list);
+ table = font_description_table_new (font_directory, postscript_font_list, true_type_font_list);
+ if (table == NULL) {
+ nautilus_g_list_free_deep (postscript_font_list);
+ nautilus_g_list_free_deep (true_type_font_list);
+ g_warning ("Error trying to process font directory '%s'.", font_directory);
+ return;
+ }
*collected_font_tables = g_list_prepend (*collected_font_tables, table);
+
+ nautilus_g_list_free_deep (postscript_font_list);
+ nautilus_g_list_free_deep (true_type_font_list);
}
-/* Public */
-void
-nautilus_font_manager_for_each_font (NautilusFontManagerIterationCallback callback,
- gpointer callback_data)
+static void
+font_server_for_each_callback (const char *font_directory,
+ gpointer callback_data)
{
- GList *collected_font_tables = NULL;
- GList *node;
- FontDescriptionTable *table;
+ g_return_if_fail (string_is_valid (font_directory));
+ g_return_if_fail (callback_data != NULL);
- g_return_if_fail (callback != NULL);
+ font_manager_collect_font_tables (font_directory, callback_data);
+}
- font_server_for_each_font_directory ("/etc/X11/fs/config",
- font_server_for_each_callback,
- &collected_font_tables);
-
- node = collected_font_tables;
- while (node) {
+static GList *fallback_font_table = NULL;
+static GList *user_font_table = NULL;
+static GList *system_font_table = NULL;
+
+static void
+font_table_list_free (GList *font_table_list)
+{
+ GList *node;
+
+ node = font_table_list;
+ while (node != NULL) {
g_assert (node->data != NULL);
- table = node->data;
-
- font_description_table_for_each (table, callback, callback_data);
- font_description_table_free (table);
-
+ font_description_table_free (node->data);
node = node->next;
}
+ g_list_free (font_table_list);
+}
+
+static void
+font_table_list_for_each (GList *font_table_list,
+ NautilusFontManagerCallback callback,
+ gpointer callback_data)
+{
+ GList *node;
- g_list_free (collected_font_tables);
+ g_return_if_fail (callback != NULL);
+
+ node = font_table_list;
+ while (node != NULL) {
+ g_assert (node->data != NULL);
+ font_description_table_for_each (node->data, callback, callback_data);
+ node = node->next;
+ }
}
+static void
+free_font_tables (void)
+{
+ font_table_list_free (fallback_font_table);
+ fallback_font_table = NULL;
+
+ font_table_list_free (user_font_table);
+ user_font_table = NULL;
-#if !defined (NAUTILUS_OMIT_SELF_CHECK)
+ font_table_list_free (system_font_table);
+ system_font_table = NULL;
+}
-/*
- * The check strategy here is to create a temporary directory
- * with a single fonts.dir inside it. We then use that to
- * exercise the font manager.
- */
-static const char *test_fonts_dir_content =
-"4\n"
-"n019003l.pfb -URW-Helvetica-medium-r-normal--0-0-0-0-p-0-iso8859-1\n"
-"n019004l.pfb -URW-Helvetica-bold-r-normal--0-0-0-0-p-0-iso8859-1\n"
-"n019023l.pfb -URW-Helvetica-medium-o-normal--0-0-0-0-p-0-iso8859-1\n"
-"n019024l.pfb -URW-Helvetica-bold-o-normal--0-0-0-0-p-0-iso8859-1\n"
-;
+static gboolean at_exit_handler_installed = FALSE;
-static char *
-call_chop_off_comments (const char *input)
+static void
+ensure_at_exit_handler (void)
{
- char *test_copy;
- test_copy = g_strdup (input);
- chop_off_comments (test_copy);
- return test_copy;
+ if (!at_exit_handler_installed) {
+ at_exit_handler_installed = TRUE;
+ g_atexit (free_font_tables);
+ }
}
-static gboolean
-write_temp_font_dot_dir_file (const char *temp_font_dir_file_name)
+static void
+ensure_fallback_font_table (void)
{
- FILE *stream;
- size_t num;
- size_t num_written;
+ /* Populate the fallback font table if needed */
+ if (fallback_font_table == NULL) {
+ font_manager_collect_font_tables (FALLBACK_FONT_DIRECTORY, &fallback_font_table);
+ }
- g_return_val_if_fail (string_is_valid (temp_font_dir_file_name), FALSE);
- g_return_val_if_fail (!g_file_exists (temp_font_dir_file_name), FALSE);
+ ensure_at_exit_handler ();
+}
- stream = fopen (temp_font_dir_file_name, "w");
- g_return_val_if_fail (stream != NULL, FALSE);
+static void
+ensure_user_font_table (void)
+{
+ char *user_directory;
+ char *user_font_dir;
+
+ /* Populate the user font table if needed */
+ if (user_font_table == NULL) {
+ user_directory = nautilus_get_user_directory ();
+ user_font_dir = nautilus_make_path (user_directory, USER_FONT_DIRECTORY_NAME);
+ if (g_file_test (user_font_dir, G_FILE_TEST_ISDIR)) {
+ font_manager_collect_font_tables (user_font_dir, &user_font_table);
+ }
+ g_free (user_directory);
+ g_free (user_font_dir);
+ }
- num = strlen (test_fonts_dir_content);
- num_written = fwrite (test_fonts_dir_content, sizeof (char), num, stream);
- fclose (stream);
+ ensure_at_exit_handler ();
+}
- g_return_val_if_fail (num == num_written, FALSE);
+static void
+ensure_system_font_tables (void)
+{
+ /* Populate the system font table if needed - using the font server's configuration */
+ if (system_font_table == NULL) {
+ if (g_file_exists (FONT_SERVER_CONFIG_FILE)) {
+ font_server_for_each_font_directory (FONT_SERVER_CONFIG_FILE,
+ font_server_for_each_callback,
+ &system_font_table);
+ }
+ }
- return TRUE;
+ ensure_at_exit_handler ();
}
-static char *
-get_unique_temp_directory (void)
+/* Public */
+void
+nautilus_font_manager_for_each_font (NautilusFontManagerCallback callback,
+ gpointer callback_data)
{
- char *temp_font_directory;
+ g_return_if_fail (callback != NULL);
- temp_font_directory = nautilus_unique_temporary_file_name ();
+ /* Ensure that all the font tables exist */
+ ensure_fallback_font_table ();
+ ensure_user_font_table ();
+ ensure_system_font_tables ();
- if (temp_font_directory == NULL) {
- return NULL;
- }
+ font_table_list_for_each (fallback_font_table, callback, callback_data);
+ font_table_list_for_each (user_font_table, callback, callback_data);
+ font_table_list_for_each (system_font_table, callback, callback_data);
+}
- if (g_file_test (temp_font_directory, G_FILE_TEST_ISDIR)) {
- g_free (temp_font_directory);
- return NULL;
- }
+char *
+nautilus_font_manager_get_fallback_font (void)
+{
+ const FontDescriptionTable *table;
- mkdir (temp_font_directory, 0755);
+ ensure_fallback_font_table ();
+ g_return_val_if_fail (g_list_length (fallback_font_table) > 0, NULL);
- if (!g_file_test (temp_font_directory, G_FILE_TEST_ISDIR)) {
- g_free (temp_font_directory);
- return NULL;
- }
+ table = g_list_nth_data (fallback_font_table, 0);
+ g_return_val_if_fail (table != NULL, NULL);
- return temp_font_directory;
+ return font_description_table_get_nth_file_name (table, 0);
}
+#if !defined (NAUTILUS_OMIT_SELF_CHECK)
+
+static char *
+call_chop_off_comments (const char *input)
+{
+ char *test_copy;
+ test_copy = g_strdup (input);
+ chop_off_comments (test_copy);
+ return test_copy;
+}
+
+#define TEST_FONT_DIR "/usr/share/fonts/default/Type1"
+
void
nautilus_self_check_font_manager (void)
{
FontDescriptionTable *table;
const FontDescription *description;
+ GList *font_table_list = NULL;
- char *temp_font_directory;
- char *temp_fonts_dot_dir_file;
- char *cleanup_command;
- gboolean temp_font_directory_ok;
-
- temp_font_directory = get_unique_temp_directory ();
- g_return_if_fail (string_is_valid (temp_font_directory));
+ /* chop_off_comments() */
+ NAUTILUS_CHECK_STRING_RESULT (call_chop_off_comments ("foo bar"), "foo bar");
+ NAUTILUS_CHECK_STRING_RESULT (call_chop_off_comments ("foo bar\n"), "foo bar\n");
+ NAUTILUS_CHECK_STRING_RESULT (call_chop_off_comments ("#foo bar"), "");
+ NAUTILUS_CHECK_STRING_RESULT (call_chop_off_comments ("foo bar#"), "foo bar");
+ NAUTILUS_CHECK_STRING_RESULT (call_chop_off_comments ("\\foo bar"), "\\foo bar");
+ NAUTILUS_CHECK_STRING_RESULT (call_chop_off_comments ("\\#foo bar"), "\\#foo bar");
+ NAUTILUS_CHECK_STRING_RESULT (call_chop_off_comments ("\\##foo bar"), "\\#");
- temp_fonts_dot_dir_file = nautilus_make_path (temp_font_directory, FONTS_DIR_FILE_NAME);
- temp_font_directory_ok = write_temp_font_dot_dir_file (temp_fonts_dot_dir_file);
- g_return_if_fail (temp_font_directory_ok == TRUE);
+ /* FIXME bugzilla.eazel.com xxxx:
+ * Whats so special about this bastard ?
+ */
+ if (!nautilus_str_is_equal (g_get_user_name (), "ramiro") || !g_file_exists (TEST_FONT_DIR)) {
+ return;
+ }
- cleanup_command = g_strdup_printf ("/bin/rm -rf %s", temp_font_directory);
+ font_manager_collect_font_tables ("/usr/share/fonts/default/Type1", &font_table_list);
+ g_return_if_fail (font_table_list != NULL);
- table = font_description_table_new (temp_font_directory);
+ g_return_if_fail (g_list_nth_data (font_table_list, 0) != NULL);
+ table = g_list_nth_data (font_table_list, 0);
- NAUTILUS_CHECK_INTEGER_RESULT (font_description_table_get_length (table), 4);
- NAUTILUS_CHECK_STRING_RESULT (font_description_table_get_nth_file_name (table, 0), "n019003l.pfb");
- NAUTILUS_CHECK_STRING_RESULT (font_description_table_get_nth_file_name (table, 1), "n019004l.pfb");
- NAUTILUS_CHECK_STRING_RESULT (font_description_table_get_nth_file_name (table, 2), "n019023l.pfb");
- NAUTILUS_CHECK_STRING_RESULT (font_description_table_get_nth_file_name (table, 3), "n019024l.pfb");
+ NAUTILUS_CHECK_INTEGER_RESULT (font_description_table_get_length (table), 35);
+ NAUTILUS_CHECK_STRING_RESULT (font_description_table_get_nth_file_name (table, 0), TEST_FONT_DIR "/a010013l.pfb");
+ NAUTILUS_CHECK_STRING_RESULT (font_description_table_get_nth_file_name (table, 1), TEST_FONT_DIR "/a010015l.pfb");
+ NAUTILUS_CHECK_STRING_RESULT (font_description_table_get_nth_file_name (table, 2), TEST_FONT_DIR "/a010033l.pfb");
+ NAUTILUS_CHECK_STRING_RESULT (font_description_table_get_nth_file_name (table, 3), TEST_FONT_DIR "/a010035l.pfb");
description = font_description_table_peek_nth (table, 0);
- NAUTILUS_CHECK_STRING_RESULT (font_description_get_file_name (description), "n019003l.pfb");
+ NAUTILUS_CHECK_STRING_RESULT (font_description_get_file_name (description), TEST_FONT_DIR "/a010013l.pfb");
NAUTILUS_CHECK_STRING_RESULT (font_description_get_foundry (description), "URW");
- NAUTILUS_CHECK_STRING_RESULT (font_description_get_family (description), "Helvetica");
- NAUTILUS_CHECK_STRING_RESULT (font_description_get_weight (description), "medium");
+ NAUTILUS_CHECK_STRING_RESULT (font_description_get_family (description), "Avantgarde");
+ NAUTILUS_CHECK_STRING_RESULT (font_description_get_weight (description), "book");
NAUTILUS_CHECK_STRING_RESULT (font_description_get_slant (description), "r");
NAUTILUS_CHECK_STRING_RESULT (font_description_get_set_width (description), "normal");
NAUTILUS_CHECK_STRING_RESULT (font_description_get_char_set_encoding (description), "1");
NAUTILUS_CHECK_STRING_RESULT (font_description_get_char_set_registry (description), "iso8859");
description = font_description_table_peek_nth (table, 1);
- NAUTILUS_CHECK_STRING_RESULT (font_description_get_file_name (description), "n019004l.pfb");
+ NAUTILUS_CHECK_STRING_RESULT (font_description_get_file_name (description), TEST_FONT_DIR "/a010015l.pfb");
NAUTILUS_CHECK_STRING_RESULT (font_description_get_foundry (description), "URW");
- NAUTILUS_CHECK_STRING_RESULT (font_description_get_family (description), "Helvetica");
- NAUTILUS_CHECK_STRING_RESULT (font_description_get_weight (description), "bold");
+ NAUTILUS_CHECK_STRING_RESULT (font_description_get_family (description), "Avantgarde");
+ NAUTILUS_CHECK_STRING_RESULT (font_description_get_weight (description), "demibold");
NAUTILUS_CHECK_STRING_RESULT (font_description_get_slant (description), "r");
NAUTILUS_CHECK_STRING_RESULT (font_description_get_set_width (description), "normal");
NAUTILUS_CHECK_STRING_RESULT (font_description_get_char_set_encoding (description), "1");
NAUTILUS_CHECK_STRING_RESULT (font_description_get_char_set_registry (description), "iso8859");
description = font_description_table_peek_nth (table, 2);
- NAUTILUS_CHECK_STRING_RESULT (font_description_get_file_name (description), "n019023l.pfb");
+ NAUTILUS_CHECK_STRING_RESULT (font_description_get_file_name (description), TEST_FONT_DIR "/a010033l.pfb");
NAUTILUS_CHECK_STRING_RESULT (font_description_get_foundry (description), "URW");
- NAUTILUS_CHECK_STRING_RESULT (font_description_get_family (description), "Helvetica");
- NAUTILUS_CHECK_STRING_RESULT (font_description_get_weight (description), "medium");
+ NAUTILUS_CHECK_STRING_RESULT (font_description_get_family (description), "Avantgarde");
+ NAUTILUS_CHECK_STRING_RESULT (font_description_get_weight (description), "book");
NAUTILUS_CHECK_STRING_RESULT (font_description_get_slant (description), "o");
NAUTILUS_CHECK_STRING_RESULT (font_description_get_set_width (description), "normal");
NAUTILUS_CHECK_STRING_RESULT (font_description_get_char_set_encoding (description), "1");
NAUTILUS_CHECK_STRING_RESULT (font_description_get_char_set_registry (description), "iso8859");
description = font_description_table_peek_nth (table, 3);
- NAUTILUS_CHECK_STRING_RESULT (font_description_get_file_name (description), "n019024l.pfb");
+ NAUTILUS_CHECK_STRING_RESULT (font_description_get_file_name (description), TEST_FONT_DIR "/a010035l.pfb");
NAUTILUS_CHECK_STRING_RESULT (font_description_get_foundry (description), "URW");
- NAUTILUS_CHECK_STRING_RESULT (font_description_get_family (description), "Helvetica");
- NAUTILUS_CHECK_STRING_RESULT (font_description_get_weight (description), "bold");
+ NAUTILUS_CHECK_STRING_RESULT (font_description_get_family (description), "Avantgarde");
+ NAUTILUS_CHECK_STRING_RESULT (font_description_get_weight (description), "demibold");
NAUTILUS_CHECK_STRING_RESULT (font_description_get_slant (description), "o");
NAUTILUS_CHECK_STRING_RESULT (font_description_get_set_width (description), "normal");
NAUTILUS_CHECK_STRING_RESULT (font_description_get_char_set_encoding (description), "1");
NAUTILUS_CHECK_STRING_RESULT (font_description_get_char_set_registry (description), "iso8859");
- font_description_table_free (table);
-
- /* chop_off_comments() */
- NAUTILUS_CHECK_STRING_RESULT (call_chop_off_comments ("foo bar"), "foo bar");
- NAUTILUS_CHECK_STRING_RESULT (call_chop_off_comments ("foo bar\n"), "foo bar\n");
- NAUTILUS_CHECK_STRING_RESULT (call_chop_off_comments ("#foo bar"), "");
- NAUTILUS_CHECK_STRING_RESULT (call_chop_off_comments ("foo bar#"), "foo bar");
- NAUTILUS_CHECK_STRING_RESULT (call_chop_off_comments ("\\foo bar"), "\\foo bar");
- NAUTILUS_CHECK_STRING_RESULT (call_chop_off_comments ("\\#foo bar"), "\\#foo bar");
- NAUTILUS_CHECK_STRING_RESULT (call_chop_off_comments ("\\##foo bar"), "\\#");
-
- system (cleanup_command);
-
- g_free (cleanup_command);
- g_free (temp_font_directory);
- g_free (temp_fonts_dot_dir_file);
+ font_table_list_free (font_table_list);
}
#endif /* !NAUTILUS_OMIT_SELF_CHECK */
diff --git a/libnautilus-private/nautilus-font-manager.h b/libnautilus-private/nautilus-font-manager.h
index 3204ce0fa..9c168ef5c 100644
--- a/libnautilus-private/nautilus-font-manager.h
+++ b/libnautilus-private/nautilus-font-manager.h
@@ -19,7 +19,8 @@
write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.
- Authors: Ramiro Estrugo <ramiro@eazel.com>
+ Authors: Pavel Cisler <pavel@eazel.com>,
+ Ramiro Estrugo <ramiro@eazel.com>
*/
#ifndef NAUTILUS_FONT_MANAGER_H
@@ -30,20 +31,28 @@
BEGIN_GNOME_DECLS
+typedef enum {
+ NAUTILUS_FONT_POSTSCRIPT = 1,
+ NAUTILUS_FONT_TRUE_TYPE
+} NautilusFontType;
+
/*
* A callback which can be invoked for each font available in the system.
*/
-typedef void (*NautilusFontManagerIterationCallback) (const char *foundry,
- const char *family,
- const char *weight,
- const char *slant,
- const char *set_width,
- const char *char_set_registry,
- const char *char_set_encoding,
- gpointer callback_data);
-
-void nautilus_font_manager_for_each_font (NautilusFontManagerIterationCallback callback,
- gpointer callback_data);
+typedef void (*NautilusFontManagerCallback) (const char *font_file_name,
+ NautilusFontType font_type,
+ const char *foundry,
+ const char *family,
+ const char *weight,
+ const char *slant,
+ const char *set_width,
+ const char *char_set_registry,
+ const char *char_set_encoding,
+ gpointer callback_data);
+
+void nautilus_font_manager_for_each_font (NautilusFontManagerCallback callback,
+ gpointer callback_data);
+char *nautilus_font_manager_get_fallback_font (void);
END_GNOME_DECLS
diff --git a/libnautilus-private/nautilus-font-picker.c b/libnautilus-private/nautilus-font-picker.c
index ffe2639d5..ef6264540 100644
--- a/libnautilus-private/nautilus-font-picker.c
+++ b/libnautilus-private/nautilus-font-picker.c
@@ -25,81 +25,109 @@
#include <config.h>
#include "nautilus-font-picker.h"
+
#include "nautilus-gtk-macros.h"
#include "nautilus-glib-extensions.h"
#include "nautilus-string-picker.h"
#include "nautilus-string.h"
+#include "nautilus-font-manager.h"
#include <gtk/gtklabel.h>
#include <gtk/gtkentry.h>
#include <gtk/gtksignal.h>
+#include <gtk/gtkhbox.h>
#include <libgnome/gnome-i18n.h>
+
+typedef struct {
+ char *name;
+ char *font_file_name;
+} FontStyle;
+
+typedef struct {
+ char *title;
+ char *foundry;
+ char *family;
+ char *name;
+ GList *style_list;
+} FontEntry;
+
+static const char *black_listed_fonts[] = {
+ "microsoft Webdings",
+ "microsoft Wingdings",
+ "monotype OCR",
+ "URW Zapf Dingbats",
+ "URW Symbol",
+ "xfree86 cursor"
+};
+
static const gint FONT_PICKER_SPACING = 10;
/* Signals */
typedef enum
{
- SELECTED_FONT_CHANGED,
+ CHANGED,
LAST_SIGNAL
} FontPickerSignals;
-struct _NautilusFontPickerDetail
+struct NautilusFontPickerDetails
{
- GtkWidget *family_picker;
- GtkWidget *weight_picker;
- GtkWidget *slant_picker;
- GtkWidget *set_width_picker;
-
- NautilusStringList *weight_list;
- NautilusStringList *slant_list;
- NautilusStringList *set_width_list;
+ NautilusStringPicker *font_name_picker;
+ NautilusStringPicker *style_picker;
+ GList *font_entry_list;
+ GtkWidget *title_label;
};
-/* NautilusFontPickerClass methods */
-static void nautilus_font_picker_initialize_class (NautilusFontPickerClass *klass);
-static void nautilus_font_picker_initialize (NautilusFontPicker *font_picker);
-
-
/* GtkObjectClass methods */
+static void nautilus_font_picker_initialize_class (NautilusFontPickerClass *font_picker_class);
+static void nautilus_font_picker_initialize (NautilusFontPicker *font_picker);
static void nautilus_font_picker_destroy (GtkObject *object);
-static void family_picker_changed_callback (GtkWidget *string_picker,
- gpointer user_data);
-static void weight_picker_changed_callback (GtkWidget *string_picker,
- gpointer user_data);
-static void slant_picker_changed_callback (GtkWidget *string_picker,
- gpointer user_data);
-static void set_width_picker_changed_callback (GtkWidget *string_picker,
- gpointer user_data);
-
-NAUTILUS_DEFINE_CLASS_BOILERPLATE (NautilusFontPicker, nautilus_font_picker, GTK_TYPE_HBOX)
+static void font_picker_update (NautilusFontPicker *font_picker);
+
+/* Callbacks */
+static void font_name_picker_changed_callback (GtkWidget *string_picker,
+ gpointer callback_data);
+static void style_picker_changed_callback (GtkWidget *string_picker,
+ gpointer callback_data);
+static void font_manager_callback (const char *font_file_name,
+ NautilusFontType font_type,
+ const char *foundry,
+ const char *family,
+ const char *weight,
+ const char *slant,
+ const char *set_width,
+ const char *char_set_registry,
+ const char *char_set_encoding,
+ gpointer callback_data);
+static void font_entry_list_for_each_callback (gpointer data,
+ gpointer callback_data);
+static void style_list_for_each_callback (gpointer data,
+ gpointer callback_data);
+
+NAUTILUS_DEFINE_CLASS_BOILERPLATE (NautilusFontPicker, nautilus_font_picker, GTK_TYPE_VBOX)
static guint font_picker_signals[LAST_SIGNAL] = { 0 };
-/*
- * NautilusFontPickerClass methods
- */
+/* GtkObjectClass methods */
static void
nautilus_font_picker_initialize_class (NautilusFontPickerClass *font_picker_class)
{
GtkObjectClass *object_class;
- GtkWidgetClass *widget_class;
object_class = GTK_OBJECT_CLASS (font_picker_class);
- widget_class = GTK_WIDGET_CLASS (font_picker_class);
/* GtkObjectClass */
object_class->destroy = nautilus_font_picker_destroy;
/* Signals */
- font_picker_signals[SELECTED_FONT_CHANGED] = gtk_signal_new ("selected_font_changed",
- GTK_RUN_LAST,
- object_class->type,
- 0,
- gtk_marshal_NONE__NONE,
- GTK_TYPE_NONE,
- 0);
+ font_picker_signals[CHANGED] = gtk_signal_new ("changed",
+ GTK_RUN_LAST,
+ object_class->type,
+ 0,
+ gtk_marshal_NONE__NONE,
+ GTK_TYPE_NONE,
+ 0);
gtk_object_class_add_signals (object_class, font_picker_signals, LAST_SIGNAL);
}
@@ -107,73 +135,55 @@ nautilus_font_picker_initialize_class (NautilusFontPickerClass *font_picker_clas
static void
nautilus_font_picker_initialize (NautilusFontPicker *font_picker)
{
- NautilusStringList *family_list;
-
- font_picker->detail = g_new (NautilusFontPickerDetail, 1);
-
- font_picker->detail->weight_list = NULL;
- font_picker->detail->slant_list = NULL;
- font_picker->detail->set_width_list = NULL;
+ GtkWidget *hbox;
+ font_picker->details = g_new0 (NautilusFontPickerDetails, 1);
gtk_box_set_homogeneous (GTK_BOX (font_picker), FALSE);
gtk_box_set_spacing (GTK_BOX (font_picker), FONT_PICKER_SPACING);
- font_picker->detail->family_picker = nautilus_string_picker_new ();
- font_picker->detail->weight_picker = nautilus_string_picker_new ();
- font_picker->detail->slant_picker = nautilus_string_picker_new ();
- font_picker->detail->set_width_picker = nautilus_string_picker_new ();
-
- gtk_box_pack_start (GTK_BOX (font_picker), font_picker->detail->family_picker, TRUE, TRUE, 0);
- gtk_box_pack_start (GTK_BOX (font_picker), font_picker->detail->weight_picker, TRUE, TRUE, 0);
- gtk_box_pack_start (GTK_BOX (font_picker), font_picker->detail->slant_picker, TRUE, TRUE, 0);
- gtk_box_pack_end (GTK_BOX (font_picker), font_picker->detail->set_width_picker, TRUE, TRUE, 0);
+ font_picker->details->title_label = gtk_label_new ("");
+ gtk_label_set_justify (GTK_LABEL (font_picker->details->title_label),
+ GTK_JUSTIFY_LEFT);
+ gtk_misc_set_alignment (GTK_MISC (font_picker->details->title_label), 0.0, 0.5);
- nautilus_caption_set_title_label (NAUTILUS_CAPTION (font_picker->detail->family_picker), _("Font"));
+ gtk_box_pack_start (GTK_BOX (font_picker), font_picker->details->title_label, TRUE, TRUE, 0);
- nautilus_caption_set_show_title (NAUTILUS_CAPTION (font_picker->detail->family_picker), FALSE);
- nautilus_caption_set_show_title (NAUTILUS_CAPTION (font_picker->detail->weight_picker), FALSE);
- nautilus_caption_set_show_title (NAUTILUS_CAPTION (font_picker->detail->slant_picker), FALSE);
- nautilus_caption_set_show_title (NAUTILUS_CAPTION (font_picker->detail->set_width_picker), FALSE);
+ hbox = gtk_hbox_new (FALSE, 0);
+ gtk_box_pack_start (GTK_BOX (font_picker), hbox, TRUE, TRUE, 0);
- family_list = nautilus_scalable_font_get_font_family_list ();
+ font_picker->details->font_name_picker = NAUTILUS_STRING_PICKER (nautilus_string_picker_new ());
+ font_picker->details->style_picker = NAUTILUS_STRING_PICKER (nautilus_string_picker_new ());
- nautilus_string_list_sort (family_list);
-
- /* FIXME bugzilla.eazel.com 2557:
- * Need to deal with possiblity of there being no fonts */
- g_assert (family_list != NULL);
+ gtk_box_pack_start (GTK_BOX (hbox), GTK_WIDGET (font_picker->details->font_name_picker), TRUE, TRUE, 0);
+ gtk_box_pack_start (GTK_BOX (hbox), GTK_WIDGET (font_picker->details->style_picker), TRUE, TRUE, 0);
- nautilus_string_picker_set_string_list (NAUTILUS_STRING_PICKER (font_picker->detail->family_picker),
- family_list);
-
- nautilus_string_list_free (family_list);
+ nautilus_caption_set_title_label (NAUTILUS_CAPTION (font_picker->details->font_name_picker), _("Font"));
+ nautilus_caption_set_show_title (NAUTILUS_CAPTION (font_picker->details->font_name_picker), FALSE);
+ nautilus_caption_set_show_title (NAUTILUS_CAPTION (font_picker->details->style_picker), FALSE);
- gtk_signal_connect (GTK_OBJECT (font_picker->detail->family_picker),
+ gtk_signal_connect (GTK_OBJECT (font_picker->details->font_name_picker),
"changed",
- GTK_SIGNAL_FUNC (family_picker_changed_callback),
+ GTK_SIGNAL_FUNC (font_name_picker_changed_callback),
font_picker);
- gtk_signal_connect (GTK_OBJECT (font_picker->detail->weight_picker),
+ gtk_signal_connect (GTK_OBJECT (font_picker->details->style_picker),
"changed",
- GTK_SIGNAL_FUNC (weight_picker_changed_callback),
+ GTK_SIGNAL_FUNC (style_picker_changed_callback),
font_picker);
- gtk_signal_connect (GTK_OBJECT (font_picker->detail->slant_picker),
- "changed",
- GTK_SIGNAL_FUNC (slant_picker_changed_callback),
- font_picker);
+ gtk_widget_show (GTK_WIDGET (font_picker->details->font_name_picker));
+ gtk_widget_show (GTK_WIDGET (font_picker->details->style_picker));
+ gtk_widget_show (font_picker->details->title_label);
+ gtk_widget_show (hbox);
- gtk_signal_connect (GTK_OBJECT (font_picker->detail->set_width_picker),
- "changed",
- GTK_SIGNAL_FUNC (set_width_picker_changed_callback),
- font_picker);
+ /* Populate the font table */
+ nautilus_font_manager_for_each_font (font_manager_callback, font_picker);
- gtk_widget_show (font_picker->detail->family_picker);
- gtk_widget_show (font_picker->detail->weight_picker);
- gtk_widget_show (font_picker->detail->slant_picker);
- gtk_widget_show (font_picker->detail->set_width_picker);
+ /* Populate the font name (foundry+family) picker */
+ g_list_foreach (font_picker->details->font_entry_list, font_entry_list_for_each_callback, font_picker);
- family_picker_changed_callback (font_picker->detail->family_picker, font_picker);
+ /* Update the font picker */
+ font_picker_update (font_picker);;
}
/* GtkObjectClass methods */
@@ -181,317 +191,279 @@ static void
nautilus_font_picker_destroy (GtkObject* object)
{
NautilusFontPicker * font_picker;
-
- g_return_if_fail (object != NULL);
+
g_return_if_fail (NAUTILUS_IS_FONT_PICKER (object));
font_picker = NAUTILUS_FONT_PICKER (object);
-
- nautilus_string_list_free (font_picker->detail->weight_list);
- nautilus_string_list_free (font_picker->detail->slant_list);
- nautilus_string_list_free (font_picker->detail->set_width_list);
- g_free (font_picker->detail);
+ g_free (font_picker->details);
/* Chain */
NAUTILUS_CALL_PARENT (GTK_OBJECT_CLASS, destroy, (object));
}
-static void
-font_picker_update_weight_picker (NautilusFontPicker *font_picker)
+static FontEntry *
+font_entry_list_find (GList *font_entry_list,
+ const char *font_name)
{
- NautilusStringList *unique_weight_list;
- char *family;
-
- g_return_if_fail (NAUTILUS_IS_FONT_PICKER (font_picker));
-
- family = nautilus_string_picker_get_selected_string (NAUTILUS_STRING_PICKER (font_picker->detail->family_picker));
-
- unique_weight_list = nautilus_string_list_new_from_string_list (font_picker->detail->weight_list, TRUE);
-
- nautilus_string_list_sort (unique_weight_list);
- nautilus_string_list_remove_duplicates (unique_weight_list);
-
- nautilus_string_picker_set_string_list (NAUTILUS_STRING_PICKER (font_picker->detail->weight_picker),
- unique_weight_list);
+ while (font_entry_list != NULL) {
+ FontEntry *entry;
+ g_assert (font_entry_list->data != NULL);
+ entry = font_entry_list->data;
+ if (nautilus_istr_is_equal (font_name, entry->name)) {
+ return entry;
+ }
+
+ font_entry_list = font_entry_list->next;
+ }
- nautilus_string_list_free (unique_weight_list);
-
- g_free (family);
+ return NULL;
}
static void
-font_picker_update_slant_picker (NautilusFontPicker *font_picker)
+font_picker_update (NautilusFontPicker *font_picker)
{
- NautilusStringList *unique_slant_list;
- char *current_family;
- char *current_weight;
- guint i;
+ char *selected_font;
+ const FontEntry *entry;
g_return_if_fail (NAUTILUS_IS_FONT_PICKER (font_picker));
- current_family = nautilus_string_picker_get_selected_string (NAUTILUS_STRING_PICKER (font_picker->detail->family_picker));
- current_weight = nautilus_string_picker_get_selected_string (NAUTILUS_STRING_PICKER (font_picker->detail->weight_picker));
-
- g_assert (nautilus_string_list_get_length (font_picker->detail->slant_list) ==
- nautilus_string_list_get_length (font_picker->detail->weight_list));
+ selected_font = nautilus_string_picker_get_selected_string (font_picker->details->font_name_picker);
- unique_slant_list = nautilus_string_list_new (TRUE);
+ entry = font_entry_list_find (font_picker->details->font_entry_list, selected_font);
+ g_return_if_fail (entry != NULL);
- for (i = 0; i < nautilus_string_list_get_length (font_picker->detail->slant_list); i++) {
- char *weight = nautilus_string_list_nth (font_picker->detail->weight_list, i);
- char *slant = nautilus_string_list_nth (font_picker->detail->slant_list, i);
+ nautilus_string_picker_clear (font_picker->details->style_picker);
+
+ g_list_foreach (entry->style_list, style_list_for_each_callback, font_picker);
+
+ g_free (selected_font);
+}
- if (nautilus_str_is_equal (current_weight, weight)) {
- nautilus_string_list_insert (unique_slant_list, slant);
- }
+static void
+font_name_picker_changed_callback (GtkWidget *string_picker,
+ gpointer callback_data)
+{
+ NautilusFontPicker *font_picker;
- g_free (weight);
- g_free (slant);
- }
+ g_return_if_fail (NAUTILUS_IS_FONT_PICKER (callback_data));
+ g_return_if_fail (NAUTILUS_IS_STRING_PICKER (string_picker));
- nautilus_string_list_sort (unique_slant_list);
- nautilus_string_list_remove_duplicates (unique_slant_list);
+ font_picker = NAUTILUS_FONT_PICKER (callback_data);
- nautilus_string_picker_set_string_list (NAUTILUS_STRING_PICKER (font_picker->detail->slant_picker),
- unique_slant_list);
-
- nautilus_string_list_free (unique_slant_list);
+ font_picker_update (font_picker);
- g_free (current_family);
- g_free (current_weight);
+ gtk_signal_emit (GTK_OBJECT (font_picker), font_picker_signals[CHANGED]);
}
static void
-font_picker_update_set_width_picker (NautilusFontPicker *font_picker)
+style_picker_changed_callback (GtkWidget *string_picker, gpointer callback_data)
{
- NautilusStringList *unique_set_width_list;
- char *current_family;
- char *current_weight;
- char *current_slant;
- guint i;
+ NautilusFontPicker *font_picker;
- g_return_if_fail (NAUTILUS_IS_FONT_PICKER (font_picker));
-
- current_family = nautilus_string_picker_get_selected_string (NAUTILUS_STRING_PICKER (font_picker->detail->family_picker));
- current_weight = nautilus_string_picker_get_selected_string (NAUTILUS_STRING_PICKER (font_picker->detail->weight_picker));
- current_slant = nautilus_string_picker_get_selected_string (NAUTILUS_STRING_PICKER (font_picker->detail->slant_picker));
-
- g_assert (nautilus_string_list_get_length (font_picker->detail->slant_list) ==
- nautilus_string_list_get_length (font_picker->detail->weight_list));
+ g_return_if_fail (NAUTILUS_IS_FONT_PICKER (callback_data));
+ g_return_if_fail (NAUTILUS_IS_STRING_PICKER (string_picker));
- g_assert (nautilus_string_list_get_length (font_picker->detail->slant_list) ==
- nautilus_string_list_get_length (font_picker->detail->set_width_list));
+ font_picker = NAUTILUS_FONT_PICKER (callback_data);
- unique_set_width_list = nautilus_string_list_new (TRUE);
+ gtk_signal_emit (GTK_OBJECT (font_picker), font_picker_signals[CHANGED]);
+}
+
+static gboolean
+ignore_font (const char *font_file_name,
+ const char *foundry,
+ const char *family,
+ const char *entry_name)
+{
+ guint i;
- for (i = 0; i < nautilus_string_list_get_length (font_picker->detail->set_width_list); i++) {
- char *weight = nautilus_string_list_nth (font_picker->detail->weight_list, i);
- char *slant = nautilus_string_list_nth (font_picker->detail->slant_list, i);
- char *set_width = nautilus_string_list_nth (font_picker->detail->set_width_list, i);
+ g_return_val_if_fail (font_file_name != NULL, TRUE);
+ g_return_val_if_fail (foundry != NULL, TRUE);
+ g_return_val_if_fail (family != NULL, TRUE);
+ g_return_val_if_fail (entry_name != NULL, TRUE);
- if (nautilus_str_is_equal (current_weight, weight)
- && nautilus_str_is_equal (current_slant, slant)) {
- nautilus_string_list_insert (unique_set_width_list, set_width);
+ for (i = 0; i < NAUTILUS_N_ELEMENTS (black_listed_fonts); i++) {
+ if (nautilus_istr_is_equal (entry_name, black_listed_fonts[i])) {
+ return TRUE;
}
-
- g_free (weight);
- g_free (slant);
- g_free (set_width);
}
-
- nautilus_string_list_sort (unique_set_width_list);
- nautilus_string_list_remove_duplicates (unique_set_width_list);
-
- nautilus_string_picker_set_string_list (NAUTILUS_STRING_PICKER (font_picker->detail->set_width_picker),
- unique_set_width_list);
-
- nautilus_string_list_free (unique_set_width_list);
- g_free (current_family);
- g_free (current_weight);
- g_free (current_slant);
+ return FALSE;
}
static void
-family_picker_changed_callback (GtkWidget *string_picker, gpointer user_data)
+font_manager_callback (const char *font_file_name,
+ NautilusFontType font_type,
+ const char *foundry,
+ const char *family,
+ const char *weight,
+ const char *slant,
+ const char *set_width,
+ const char *char_set_registry,
+ const char *char_set_encoding,
+ gpointer callback_data)
{
- NautilusFontPicker *font_picker;
- char *family;
- NautilusStringList *weight_list = NULL;
- NautilusStringList *slant_list = NULL;
- NautilusStringList *set_width_list = NULL;
+ NautilusFontPicker *font_picker;
+ char *entry_name;
+ FontEntry *entry;
+ FontStyle *style;
- g_return_if_fail (NAUTILUS_IS_FONT_PICKER (user_data));
- g_return_if_fail (NAUTILUS_IS_STRING_PICKER (string_picker));
+ g_return_if_fail (font_file_name != NULL);
+ g_return_if_fail (foundry != NULL);
+ g_return_if_fail (family != NULL);
+ g_return_if_fail (weight != NULL);
+ g_return_if_fail (slant != NULL);
+ g_return_if_fail (set_width != NULL);
+ g_return_if_fail (char_set_registry != NULL);
+ g_return_if_fail (char_set_encoding != NULL);
+ g_return_if_fail (NAUTILUS_IS_FONT_PICKER (callback_data));
- font_picker = NAUTILUS_FONT_PICKER (user_data);
+ font_picker = NAUTILUS_FONT_PICKER (callback_data);
- family = nautilus_string_picker_get_selected_string (NAUTILUS_STRING_PICKER (string_picker));
-
- if (nautilus_scalable_font_query_font (family, &weight_list, &slant_list, &set_width_list)) {
- nautilus_string_list_free (font_picker->detail->weight_list);
- nautilus_string_list_free (font_picker->detail->slant_list);
- nautilus_string_list_free (font_picker->detail->set_width_list);
-
- font_picker->detail->weight_list = weight_list;
- font_picker->detail->slant_list = slant_list;
- font_picker->detail->set_width_list = set_width_list;
-
- font_picker_update_weight_picker (font_picker);
- font_picker_update_slant_picker (font_picker);
- font_picker_update_set_width_picker (font_picker);
+ entry_name = g_strdup_printf ("%s %s", foundry, family);
- gtk_signal_emit (GTK_OBJECT (font_picker), font_picker_signals[SELECTED_FONT_CHANGED]);
- }
- else {
- g_warning ("Trying to set a bogus non existant font '%s'\n", family);
+ if (ignore_font (font_file_name, foundry, family, entry_name)) {
+ g_free (entry_name);
+ return;
}
- g_free (family);
-}
+ entry = font_entry_list_find (font_picker->details->font_entry_list, entry_name);
-static void
-weight_picker_changed_callback (GtkWidget *string_picker, gpointer user_data)
-{
- NautilusFontPicker *font_picker;
-
- g_return_if_fail (NAUTILUS_IS_FONT_PICKER (user_data));
- g_return_if_fail (NAUTILUS_IS_STRING_PICKER (string_picker));
-
- font_picker = NAUTILUS_FONT_PICKER (user_data);
+ if (entry == NULL) {
+ entry = g_new0 (FontEntry, 1);
+ entry->name = g_strdup (entry_name);
+ entry->foundry = g_strdup (foundry);
+ entry->family = g_strdup (family);
+ font_picker->details->font_entry_list = g_list_prepend (font_picker->details->font_entry_list, entry);
+ }
+ g_assert (entry != NULL);
+ g_assert (font_entry_list_find (font_picker->details->font_entry_list, entry_name) == entry);
+ g_free (entry_name);
+
+ style = g_new0 (FontStyle, 1);
+ style->name = g_strdup_printf ("%s %s %s", weight, slant, set_width);
+ style->font_file_name = g_strdup (font_file_name);
- gtk_signal_emit (GTK_OBJECT (font_picker), font_picker_signals[SELECTED_FONT_CHANGED]);
+ entry->style_list = g_list_append (entry->style_list, style);
}
static void
-slant_picker_changed_callback (GtkWidget *string_picker, gpointer user_data)
+style_list_for_each_callback (gpointer data,
+ gpointer callback_data)
{
- NautilusFontPicker *font_picker;
+ NautilusFontPicker *font_picker;
+ FontStyle *style;
- g_return_if_fail (NAUTILUS_IS_FONT_PICKER (user_data));
- g_return_if_fail (NAUTILUS_IS_STRING_PICKER (string_picker));
+ g_return_if_fail (data != NULL);
+ g_return_if_fail (NAUTILUS_IS_FONT_PICKER (callback_data));
- font_picker = NAUTILUS_FONT_PICKER (user_data);
+ style = data;
+ font_picker = NAUTILUS_FONT_PICKER (callback_data);
- gtk_signal_emit (GTK_OBJECT (font_picker), font_picker_signals[SELECTED_FONT_CHANGED]);
+ nautilus_string_picker_insert_string (font_picker->details->style_picker, style->name);
}
-
static void
-set_width_picker_changed_callback (GtkWidget *string_picker, gpointer user_data)
+font_entry_list_for_each_callback (gpointer data,
+ gpointer callback_data)
{
- NautilusFontPicker *font_picker;
+ NautilusFontPicker *font_picker;
+ FontEntry *entry;
- g_return_if_fail (NAUTILUS_IS_FONT_PICKER (user_data));
- g_return_if_fail (NAUTILUS_IS_STRING_PICKER (string_picker));
+ g_return_if_fail (data != NULL);
+ g_return_if_fail (NAUTILUS_IS_FONT_PICKER (callback_data));
- font_picker = NAUTILUS_FONT_PICKER (user_data);
+ font_picker = NAUTILUS_FONT_PICKER (callback_data);
- gtk_signal_emit (GTK_OBJECT (font_picker), font_picker_signals[SELECTED_FONT_CHANGED]);
+ entry = data;
+ nautilus_string_picker_insert_string (font_picker->details->font_name_picker,
+ entry->name);
}
-
-/*
- * NautilusFontPicker public methods
- */
+/* NautilusFontPicker public methods */
GtkWidget *
nautilus_font_picker_new (void)
{
return gtk_widget_new (nautilus_font_picker_get_type (), NULL);
}
-void
-nautilus_font_picker_set_selected_family (NautilusFontPicker *font_picker,
- const char *family)
+char *
+nautilus_font_picker_get_selected_font (const NautilusFontPicker *font_picker)
{
- g_return_if_fail (NAUTILUS_IS_FONT_PICKER (font_picker));
- g_return_if_fail (family != NULL);
+ char *result = NULL;
+ char *selected_font;
+ char *selected_style;
+ const FontEntry *entry;
+ GList *node;
- if (!nautilus_string_picker_contains (NAUTILUS_STRING_PICKER (font_picker->detail->family_picker), family)) {
- g_warning ("Trying to set a bogus family '%s'\n", family);
- return;
- }
+ g_return_val_if_fail (NAUTILUS_IS_FONT_PICKER (font_picker), NULL);
- nautilus_string_picker_set_selected_string (NAUTILUS_STRING_PICKER (font_picker->detail->family_picker),
- family);
-}
+ selected_font = nautilus_string_picker_get_selected_string (font_picker->details->font_name_picker);
+ g_return_val_if_fail (selected_font != NULL, NULL);
+
+ selected_style = nautilus_string_picker_get_selected_string (font_picker->details->style_picker);
+ g_return_val_if_fail (selected_style != NULL, NULL);
+
+ entry = font_entry_list_find (font_picker->details->font_entry_list, selected_font);
+ g_return_val_if_fail (entry != NULL, NULL);
-void
-nautilus_font_picker_set_selected_weight (NautilusFontPicker *font_picker,
- const char *weight)
-{
- g_return_if_fail (NAUTILUS_IS_FONT_PICKER (font_picker));
- g_return_if_fail (weight != NULL);
+ node = entry->style_list;
+ while (node != NULL && result == NULL) {
+ const FontStyle *style;
+ g_assert (node->data != NULL);
+ style = node->data;
- if (!nautilus_string_picker_contains (NAUTILUS_STRING_PICKER (font_picker->detail->weight_picker), weight)) {
- g_warning ("Trying to set a bogus weight '%s'\n", weight);
- return;
+ if (nautilus_istr_is_equal (style->name, selected_style)) {
+ result = g_strdup (style->font_file_name);
+ }
+ node = node->next;
}
-
- nautilus_string_picker_set_selected_string (NAUTILUS_STRING_PICKER (font_picker->detail->weight_picker),
- weight);
+
+ g_free (selected_font);
+ g_free (selected_style);
+
+ return result;
}
void
-nautilus_font_picker_set_selected_slant (NautilusFontPicker *font_picker,
- const char *slant)
+nautilus_font_picker_set_selected_font (NautilusFontPicker *font_picker,
+ const char *font_name)
{
- g_return_if_fail (NAUTILUS_IS_FONT_PICKER (font_picker));
- g_return_if_fail (slant != NULL);
+ const FontEntry *entry;
+ const FontStyle *style;
+ GList *font_list_node;
+ GList *style_list_node;
- if (!nautilus_string_picker_contains (NAUTILUS_STRING_PICKER (font_picker->detail->slant_picker), slant)) {
- g_warning ("Trying to set a bogus slant '%s'\n", slant);
- return;
- }
+ g_return_if_fail (NAUTILUS_IS_FONT_PICKER (font_picker));
- nautilus_string_picker_set_selected_string (NAUTILUS_STRING_PICKER (font_picker->detail->slant_picker),
- slant);
+ font_list_node = font_picker->details->font_entry_list;
+ while (font_list_node != NULL) {
+ g_assert (font_list_node->data != NULL);
+ entry = font_list_node->data;
+
+ style_list_node = entry->style_list;
+ while (style_list_node != NULL) {
+ g_assert (style_list_node->data != NULL);
+ style = style_list_node->data;
+
+ if (nautilus_istr_is_equal (style->font_file_name, font_name)) {
+ nautilus_string_picker_set_selected_string (font_picker->details->font_name_picker,
+ entry->name);
+ font_picker_update (font_picker);
+ gtk_signal_emit (GTK_OBJECT (font_picker), font_picker_signals[CHANGED]);
+ return;
+ }
+ style_list_node = style_list_node->next;
+ }
+
+ font_list_node = font_list_node->next;
+ }
}
void
-nautilus_font_picker_set_selected_set_width (NautilusFontPicker *font_picker,
- const char *set_width)
+nautilus_font_picker_set_title_label (NautilusFontPicker *font_picker,
+ const char *title_label)
{
g_return_if_fail (NAUTILUS_IS_FONT_PICKER (font_picker));
- g_return_if_fail (set_width != NULL);
-
- if (!nautilus_string_picker_contains (NAUTILUS_STRING_PICKER (font_picker->detail->set_width_picker), set_width)) {
- g_warning ("Trying to set a bogus set_width '%s'\n", set_width);
- return;
- }
-
- nautilus_string_picker_set_selected_string (NAUTILUS_STRING_PICKER (font_picker->detail->set_width_picker),
- set_width);
-}
-
-char *
-nautilus_font_picker_get_selected_family (const NautilusFontPicker *font_picker)
-{
- g_return_val_if_fail (NAUTILUS_IS_FONT_PICKER (font_picker), NULL);
-
- return nautilus_string_picker_get_selected_string (NAUTILUS_STRING_PICKER (font_picker->detail->family_picker));
-}
-
-char *
-nautilus_font_picker_get_selected_weight (const NautilusFontPicker *font_picker)
-{
- g_return_val_if_fail (NAUTILUS_IS_FONT_PICKER (font_picker), NULL);
-
- return nautilus_string_picker_get_selected_string (NAUTILUS_STRING_PICKER (font_picker->detail->weight_picker));
-}
-
-char *
-nautilus_font_picker_get_selected_slant (const NautilusFontPicker *font_picker)
-{
- g_return_val_if_fail (NAUTILUS_IS_FONT_PICKER (font_picker), NULL);
-
- return nautilus_string_picker_get_selected_string (NAUTILUS_STRING_PICKER (font_picker->detail->slant_picker));
-}
-
-char *
-nautilus_font_picker_get_selected_set_width (const NautilusFontPicker *font_picker)
-{
- g_return_val_if_fail (NAUTILUS_IS_FONT_PICKER (font_picker), NULL);
- return nautilus_string_picker_get_selected_string (NAUTILUS_STRING_PICKER (font_picker->detail->set_width_picker));
+ gtk_label_set_text (GTK_LABEL (font_picker->details->title_label), title_label);
}
diff --git a/libnautilus-private/nautilus-font-picker.h b/libnautilus-private/nautilus-font-picker.h
index 5bbbe1ff4..b4b80de59 100644
--- a/libnautilus-private/nautilus-font-picker.h
+++ b/libnautilus-private/nautilus-font-picker.h
@@ -25,7 +25,7 @@
#ifndef NAUTILUS_FONT_PICKER_H
#define NAUTILUS_FONT_PICKER_H
-#include <gtk/gtkhbox.h>
+#include <gtk/gtkvbox.h>
#include <libnautilus-extensions/nautilus-scalable-font.h>
BEGIN_GNOME_DECLS
@@ -35,42 +35,31 @@ BEGIN_GNOME_DECLS
#define NAUTILUS_FONT_PICKER_CLASS(klass) (GTK_CHECK_CLASS_CAST ((klass), NAUTILUS_TYPE_FONT_PICKER, NautilusFontPickerClass))
#define NAUTILUS_IS_FONT_PICKER(obj) (GTK_CHECK_TYPE ((obj), NAUTILUS_TYPE_FONT_PICKER))
-typedef struct _NautilusFontPicker NautilusFontPicker;
-typedef struct _NautilusFontPickerClass NautilusFontPickerClass;
-typedef struct _NautilusFontPickerDetail NautilusFontPickerDetail;
+typedef struct NautilusFontPicker NautilusFontPicker;
+typedef struct NautilusFontPickerClass NautilusFontPickerClass;
+typedef struct NautilusFontPickerDetails NautilusFontPickerDetails;
-struct _NautilusFontPicker
+struct NautilusFontPicker
{
/* Super Class */
- GtkHBox hbox;
+ GtkVBox vbox;
/* Private stuff */
- NautilusFontPickerDetail *detail;
+ NautilusFontPickerDetails *details;
};
-struct _NautilusFontPickerClass
+struct NautilusFontPickerClass
{
- GtkHBoxClass parent_class;
+ GtkVBoxClass parent_class;
};
-GtkType nautilus_font_picker_get_type (void);
-GtkWidget* nautilus_font_picker_new (void);
-void nautilus_font_picker_set_show_weights (NautilusFontPicker *font_picker);
-void nautilus_font_picker_set_show_slants (NautilusFontPicker *font_picker);
-void nautilus_font_picker_set_show_set_widths (NautilusFontPicker *font_picker);
-void nautilus_font_picker_set_selected_family (NautilusFontPicker *font_picker,
- const char *family);
-void nautilus_font_picker_set_selected_weight (NautilusFontPicker *font_picker,
- const char *weight);
-void nautilus_font_picker_set_selected_slant (NautilusFontPicker *font_picker,
- const char *slant);
-void nautilus_font_picker_set_selected_set_width (NautilusFontPicker *font_picker,
- const char *set_width);
-char * nautilus_font_picker_get_selected_family (const NautilusFontPicker *font_picker);
-char * nautilus_font_picker_get_selected_weight (const NautilusFontPicker *font_picker);
-char * nautilus_font_picker_get_selected_slant (const NautilusFontPicker *font_picker);
-char * nautilus_font_picker_get_selected_set_width (const NautilusFontPicker *font_picker);
-
+GtkType nautilus_font_picker_get_type (void);
+GtkWidget* nautilus_font_picker_new (void);
+char * nautilus_font_picker_get_selected_font (const NautilusFontPicker *font_picker);
+void nautilus_font_picker_set_selected_font (NautilusFontPicker *font_picker,
+ const char *font);
+void nautilus_font_picker_set_title_label (NautilusFontPicker *font_picker,
+ const char *title_label);
END_GNOME_DECLS
#endif /* NAUTILUS_FONT_PICKER_H */
diff --git a/libnautilus-private/nautilus-global-preferences.c b/libnautilus-private/nautilus-global-preferences.c
index aeee8d2eb..1ca75b872 100644
--- a/libnautilus-private/nautilus-global-preferences.c
+++ b/libnautilus-private/nautilus-global-preferences.c
@@ -34,6 +34,7 @@
#include "nautilus-string.h"
#include "nautilus-medusa-support.h"
#include "nautilus-view-identifier.h"
+#include "nautilus-font-manager.h"
#include <gconf/gconf.h>
#include <gconf/gconf-client.h>
#include <gtk/gtkbox.h>
@@ -65,11 +66,13 @@ static void global_preferences_install_speed_tradeoff_descriptions (const
const char *description);
static void global_preferences_install_home_location_defaults (void);
static void global_preferences_install_medusa_defaults (void);
+static void global_preferences_install_font_defaults (void);
static void global_preferences_install_descriptions (void);
static int compare_view_identifiers (gconstpointer a,
gconstpointer b);
static GtkWidget *global_preferences_create_dialog (void);
static GtkWidget *global_preferences_create_search_pane (NautilusPreferencesBox *preference_box);
+static GtkWidget *global_preferences_create_font_group (NautilusPreferencesPane *appearance_pane);
static GtkWidget *global_prefs_dialog = NULL;
@@ -153,6 +156,8 @@ global_preferences_install_descriptions (void)
nautilus_preferences_set_description (NAUTILUS_PREFERENCES_DIRECTORY_VIEW_FONT_FAMILY,
_("Use this font family to display file names:"));
+ nautilus_preferences_set_description (NAUTILUS_PREFERENCES_DIRECTORY_VIEW_SMOOTH_FONT,
+ _("Use this font family to display file names:"));
nautilus_preferences_set_description (NAUTILUS_PREFERENCES_START_WITH_TOOLBAR,
_("Display toolbar in new windows"));
@@ -262,10 +267,6 @@ global_preferences_install_defaults (void)
NAUTILUS_USER_LEVEL_INTERMEDIATE,
NAUTILUS_SPEED_TRADEOFF_ALWAYS);
- nautilus_preferences_default_set_string (NAUTILUS_PREFERENCES_DIRECTORY_VIEW_FONT_FAMILY,
- NAUTILUS_USER_LEVEL_NOVICE,
- _("helvetica"));
-
nautilus_preferences_default_set_integer (NAUTILUS_PREFERENCES_CLICK_POLICY,
NAUTILUS_USER_LEVEL_NOVICE,
NAUTILUS_CLICK_POLICY_DOUBLE);
@@ -374,6 +375,9 @@ global_preferences_install_defaults (void)
/* Home location */
global_preferences_install_home_location_defaults ();
+ /* Fonts */
+ global_preferences_install_font_defaults ();
+
/* Medusa */
global_preferences_install_medusa_defaults ();
}
@@ -530,12 +534,11 @@ global_preferences_create_dialog (void)
0,
NAUTILUS_PREFERENCES_SMOOTH_GRAPHICS_MODE,
NAUTILUS_PREFERENCE_ITEM_BOOLEAN);
-
- nautilus_preferences_pane_add_group (NAUTILUS_PREFERENCES_PANE (appearance_pane), _("Fonts"));
- nautilus_preferences_pane_add_item_to_nth_group (NAUTILUS_PREFERENCES_PANE (appearance_pane),
- 1,
- NAUTILUS_PREFERENCES_DIRECTORY_VIEW_FONT_FAMILY,
- NAUTILUS_PREFERENCE_ITEM_FONT_FAMILY);
+
+ /*
+ * Fonts
+ */
+ global_preferences_create_font_group (NAUTILUS_PREFERENCES_PANE (appearance_pane));
/*
@@ -816,6 +819,56 @@ global_preferences_create_search_pane (NautilusPreferencesBox *preference_box)
return search_pane;
}
+/*
+ * We have 2 font picker items, but we only show one depending on
+ * the value of the SMOOTH_GRAPHICS preference.
+ */
+static void
+appearnace_pane_update (gpointer callback_data)
+{
+ g_return_if_fail (NAUTILUS_IS_PREFERENCES_PANE (callback_data));
+
+ nautilus_preferences_pane_update (NAUTILUS_PREFERENCES_PANE (callback_data));
+}
+
+static GtkWidget *
+global_preferences_create_font_group (NautilusPreferencesPane *appearance_pane)
+{
+ GtkWidget *font_group;
+ GtkWidget *font_picker_smooth_item;
+ GtkWidget *font_picker_gdk_item;
+
+ font_group =
+ nautilus_preferences_pane_add_group (NAUTILUS_PREFERENCES_PANE (appearance_pane), _("Fonts"));
+
+ font_picker_gdk_item =
+ nautilus_preferences_pane_add_item_to_nth_group (NAUTILUS_PREFERENCES_PANE (appearance_pane),
+ 1,
+ NAUTILUS_PREFERENCES_DIRECTORY_VIEW_FONT_FAMILY,
+ NAUTILUS_PREFERENCE_ITEM_FONT_FAMILY);
+ nautilus_preferences_item_set_control_preference (NAUTILUS_PREFERENCES_ITEM (font_picker_gdk_item),
+ NAUTILUS_PREFERENCES_SMOOTH_GRAPHICS_MODE);
+ nautilus_preferences_item_set_control_action (NAUTILUS_PREFERENCES_ITEM (font_picker_gdk_item),
+ NAUTILUS_PREFERENCE_ITEM_HIDE);
+
+ font_picker_smooth_item =
+ nautilus_preferences_pane_add_item_to_nth_group (NAUTILUS_PREFERENCES_PANE (appearance_pane),
+ 1,
+ NAUTILUS_PREFERENCES_DIRECTORY_VIEW_SMOOTH_FONT,
+ NAUTILUS_PREFERENCE_ITEM_SMOOTH_FONT);
+
+ nautilus_preferences_item_set_control_preference (NAUTILUS_PREFERENCES_ITEM (font_picker_gdk_item),
+ NAUTILUS_PREFERENCES_SMOOTH_GRAPHICS_MODE);
+ nautilus_preferences_item_set_control_action (NAUTILUS_PREFERENCES_ITEM (font_picker_smooth_item),
+ NAUTILUS_PREFERENCE_ITEM_SHOW);
+
+ nautilus_preferences_add_callback (NAUTILUS_PREFERENCES_SMOOTH_GRAPHICS_MODE,
+ appearnace_pane_update,
+ appearance_pane);
+
+ return font_group;
+}
+
/* Make a query to find out what sidebar panels are available. */
static GList *
global_preferences_get_sidebar_panel_view_identifiers (void)
@@ -1051,6 +1104,24 @@ global_preferences_install_home_location_defaults (void)
}
static void
+global_preferences_install_font_defaults (void)
+{
+ char *fallback_smooth_font;
+
+ nautilus_preferences_default_set_string (NAUTILUS_PREFERENCES_DIRECTORY_VIEW_FONT_FAMILY,
+ NAUTILUS_USER_LEVEL_NOVICE,
+ _("helvetica"));
+
+ /* The default smooth font */
+ fallback_smooth_font = nautilus_font_manager_get_fallback_font ();
+
+ nautilus_preferences_default_set_string (NAUTILUS_PREFERENCES_DIRECTORY_VIEW_SMOOTH_FONT,
+ NAUTILUS_USER_LEVEL_NOVICE,
+ fallback_smooth_font);
+ g_free (fallback_smooth_font);
+}
+
+static void
global_preferences_use_fast_search_changed_callback (gpointer callback_data)
{
gboolean use_fast_search;
diff --git a/libnautilus-private/nautilus-global-preferences.h b/libnautilus-private/nautilus-global-preferences.h
index fc8ebe310..661dd680e 100644
--- a/libnautilus-private/nautilus-global-preferences.h
+++ b/libnautilus-private/nautilus-global-preferences.h
@@ -91,6 +91,7 @@ BEGIN_GNOME_DECLS
/* Directory view */
#define NAUTILUS_PREFERENCES_DIRECTORY_VIEW_FONT_FAMILY "directory-view/font_family"
+#define NAUTILUS_PREFERENCES_DIRECTORY_VIEW_SMOOTH_FONT "directory-view/smooth_font"
/* File Indexing */
#define NAUTILUS_PREFERENCES_SEARCH_BAR_TYPE "preferences/search_bar_type"
diff --git a/libnautilus-private/nautilus-gtk-extensions.c b/libnautilus-private/nautilus-gtk-extensions.c
index ff7a9c57a..93738e211 100644
--- a/libnautilus-private/nautilus-gtk-extensions.c
+++ b/libnautilus-private/nautilus-gtk-extensions.c
@@ -1185,6 +1185,25 @@ nautilus_gtk_widget_set_font (GtkWidget *widget, GdkFont *font)
}
/**
+ * nautilus_gtk_widget_set_shown
+ *
+ * Show or hide a widget.
+ * @widget: The widget.
+ * @shown: Boolean value indicating whether the widget should be shown or hidden.
+ **/
+void
+nautilus_gtk_widget_set_shown (GtkWidget *widget, gboolean shown)
+{
+ g_return_if_fail (GTK_IS_WIDGET (widget));
+
+ if (shown) {
+ gtk_widget_show (widget);
+ } else {
+ gtk_widget_hide (widget);
+ }
+}
+
+/**
* nautilus_gtk_widget_set_font_by_name
*
* Sets the font for a widget, managing the font and style objects.
diff --git a/libnautilus-private/nautilus-gtk-extensions.h b/libnautilus-private/nautilus-gtk-extensions.h
index a219dbb2f..fbc19cb39 100644
--- a/libnautilus-private/nautilus-gtk-extensions.h
+++ b/libnautilus-private/nautilus-gtk-extensions.h
@@ -86,6 +86,8 @@ void nautilus_gtk_object_list_free (GList
GList * nautilus_gtk_object_list_copy (GList *list);
/* GtkWidget */
+void nautilus_gtk_widget_set_shown (GtkWidget *widget,
+ gboolean shown);
gboolean nautilus_point_in_allocation (const GtkAllocation *allocation,
int x,
int y);
diff --git a/libnautilus-private/nautilus-preferences-group.c b/libnautilus-private/nautilus-preferences-group.c
index baa6a9bfe..bdf83865c 100644
--- a/libnautilus-private/nautilus-preferences-group.c
+++ b/libnautilus-private/nautilus-preferences-group.c
@@ -24,6 +24,7 @@
#include <config.h>
#include "nautilus-preferences-group.h"
+#include "nautilus-gtk-extensions.h"
#include <gnome.h>
#include <gtk/gtkradiobutton.h>
@@ -232,22 +233,26 @@ nautilus_preferences_group_update (NautilusPreferencesGroup *group)
{
GList *iterator;
NautilusPreferencesItem *preferences_item;
+ gboolean shown;
+ char *name = NULL;
g_return_if_fail (NAUTILUS_IS_PREFERENCES_GROUP (group));
-
+
for (iterator = group->details->items; iterator != NULL; iterator = iterator->next) {
- char *name;
-
preferences_item = NAUTILUS_PREFERENCES_ITEM (iterator->data);
+
name = nautilus_preferences_item_get_name (preferences_item);
+
nautilus_preferences_item_update_displayed_value (preferences_item);
if (nautilus_preferences_is_visible (name)) {
- gtk_widget_show (GTK_WIDGET (iterator->data));
+ shown = nautilus_preferences_item_get_control_showing (preferences_item);
} else {
- gtk_widget_hide (GTK_WIDGET (iterator->data));
+ shown = FALSE;
}
-
+
+ nautilus_gtk_widget_set_shown (GTK_WIDGET (iterator->data), shown);
+
g_free (name);
}
}
diff --git a/libnautilus-private/nautilus-preferences-item.c b/libnautilus-private/nautilus-preferences-item.c
index fad424973..20cdd7607 100644
--- a/libnautilus-private/nautilus-preferences-item.c
+++ b/libnautilus-private/nautilus-preferences-item.c
@@ -39,6 +39,7 @@
#include "nautilus-radio-button-group.h"
#include "nautilus-string-picker.h"
+#include "nautilus-font-picker.h"
#include "nautilus-text-caption.h"
#include "nautilus-global-preferences.h"
@@ -55,6 +56,8 @@ struct _NautilusPreferencesItemDetails
NautilusPreferencesItemType item_type;
GtkWidget *child;
guint change_signal_ID;
+ char *control_preference_name;
+ NautilusPreferencesItemControlAction control_action;
};
/* GtkObjectClass methods */
@@ -78,6 +81,8 @@ static void preferences_item_create_integer (NautilusPreference
const char *preference_name);
static void preferences_item_create_font_family (NautilusPreferencesItem *item,
const char *preference_name);
+static void preferences_item_create_smooth_font (NautilusPreferencesItem *item,
+ const char *preference_name);
static void preferences_item_update_text_settings_at_idle (NautilusPreferencesItem *preferences_item);
static void preferences_item_update_integer_settings_at_idle (NautilusPreferencesItem *preferences_item);
static void enum_radio_group_changed_callback (GtkWidget *button_group,
@@ -128,6 +133,7 @@ preferences_item_destroy (GtkObject *object)
item = NAUTILUS_PREFERENCES_ITEM (object);
g_free (item->details->preference_name);
+ g_free (item->details->control_preference_name);
g_free (item->details);
/* Chain destroy */
@@ -173,6 +179,10 @@ preferences_item_construct (NautilusPreferencesItem *item,
preferences_item_create_font_family (item, preference_name);
break;
+ case NAUTILUS_PREFERENCE_ITEM_SMOOTH_FONT:
+ preferences_item_create_smooth_font (item, preference_name);
+ break;
+
case NAUTILUS_PREFERENCE_ITEM_EDITABLE_STRING:
preferences_item_create_editable_string (item, preference_name);
break;
@@ -450,7 +460,7 @@ preferences_item_update_font_family (const NautilusPreferencesItem *item)
static void
preferences_item_create_font_family (NautilusPreferencesItem *item,
- const char *preference_name)
+ const char *preference_name)
{
char *description;
NautilusStringList *font_list;
@@ -483,6 +493,64 @@ preferences_item_create_font_family (NautilusPreferencesItem *item,
(gpointer) item);
}
+
+static void
+preferences_item_update_smooth_font (const NautilusPreferencesItem *item)
+{
+ char *current_value;
+
+ g_return_if_fail (NAUTILUS_IS_PREFERENCES_ITEM (item));
+ g_return_if_fail (item->details->item_type == NAUTILUS_PREFERENCE_ITEM_SMOOTH_FONT);
+
+ current_value = nautilus_preferences_get (item->details->preference_name);
+ g_assert (current_value != NULL);
+
+ nautilus_font_picker_set_selected_font (NAUTILUS_FONT_PICKER (item->details->child),
+ current_value);
+ g_free (current_value);
+}
+
+static void
+preferences_smooth_font_changed_callback (NautilusFontPicker *font_picker,
+ gpointer callback_data)
+{
+ NautilusPreferencesItem *item;
+ char *new_value;
+
+ g_return_if_fail (NAUTILUS_IS_FONT_PICKER (font_picker));
+ g_return_if_fail (NAUTILUS_IS_PREFERENCES_ITEM (callback_data));
+
+ item = NAUTILUS_PREFERENCES_ITEM (callback_data);
+ new_value = nautilus_font_picker_get_selected_font (NAUTILUS_FONT_PICKER (item->details->child));
+ g_assert (new_value != NULL);
+ nautilus_preferences_set (item->details->preference_name, new_value);
+ g_free (new_value);
+}
+
+static void
+preferences_item_create_smooth_font (NautilusPreferencesItem *item,
+ const char *preference_name)
+{
+ char *description = NULL;
+
+ g_return_if_fail (NAUTILUS_IS_PREFERENCES_ITEM (item));
+ g_return_if_fail (nautilus_strlen (preference_name) > 0);
+
+ description = nautilus_preferences_get_description (preference_name);
+ g_return_if_fail (description != NULL);
+
+ item->details->child = nautilus_font_picker_new ();
+ nautilus_font_picker_set_title_label (NAUTILUS_FONT_PICKER (item->details->child),
+ description);
+
+ g_free (description);
+
+ item->details->change_signal_ID = gtk_signal_connect (GTK_OBJECT (item->details->child),
+ "changed",
+ GTK_SIGNAL_FUNC (preferences_smooth_font_changed_callback),
+ item);
+}
+
/* NautilusPreferencesItem public methods */
GtkWidget *
nautilus_preferences_item_new (const char *preference_name,
@@ -629,6 +697,10 @@ nautilus_preferences_item_update_displayed_value (const NautilusPreferencesItem
preferences_item_update_font_family (item);
break;
+ case NAUTILUS_PREFERENCE_ITEM_SMOOTH_FONT:
+ preferences_item_update_smooth_font (item);
+ break;
+
case NAUTILUS_PREFERENCE_ITEM_EDITABLE_STRING:
preferences_item_update_editable_string (item);
break;
@@ -701,3 +773,57 @@ preferences_item_update_integer_settings_at_idle (NautilusPreferencesItem *prefe
integer_idle_handler = TRUE;
}
}
+
+void
+nautilus_preferences_item_set_control_preference (NautilusPreferencesItem *preferences_item,
+ const char *control_preference_name)
+{
+ g_return_if_fail (NAUTILUS_IS_PREFERENCES_ITEM (preferences_item));
+
+ if (nautilus_str_is_equal (preferences_item->details->control_preference_name,
+ control_preference_name)) {
+ return;
+ }
+
+ g_free (preferences_item->details->control_preference_name);
+ preferences_item->details->control_preference_name = g_strdup (control_preference_name);
+}
+
+void
+nautilus_preferences_item_set_control_action (NautilusPreferencesItem *preferences_item,
+ NautilusPreferencesItemControlAction control_action)
+{
+ g_return_if_fail (NAUTILUS_IS_PREFERENCES_ITEM (preferences_item));
+ g_return_if_fail (control_action >= NAUTILUS_PREFERENCE_ITEM_SHOW);
+ g_return_if_fail (control_action <= NAUTILUS_PREFERENCE_ITEM_HIDE);
+
+ if (preferences_item->details->control_action == control_action) {
+ return;
+ }
+
+ preferences_item->details->control_action = control_action;
+}
+
+gboolean
+nautilus_preferences_item_get_control_showing (const NautilusPreferencesItem *preferences_item)
+{
+ gboolean value;
+
+ g_return_val_if_fail (NAUTILUS_IS_PREFERENCES_ITEM (preferences_item), FALSE);
+
+ if (preferences_item->details->control_preference_name == NULL) {
+ return TRUE;
+ }
+
+ value = nautilus_preferences_get_boolean (preferences_item->details->control_preference_name);
+
+ if (preferences_item->details->control_action == NAUTILUS_PREFERENCE_ITEM_SHOW) {
+ return value;
+ }
+
+ if (preferences_item->details->control_action == NAUTILUS_PREFERENCE_ITEM_HIDE) {
+ return !value;
+ }
+
+ return !value;
+}
diff --git a/libnautilus-private/nautilus-preferences-item.h b/libnautilus-private/nautilus-preferences-item.h
index 11fba2436..56348b2ef 100644
--- a/libnautilus-private/nautilus-preferences-item.h
+++ b/libnautilus-private/nautilus-preferences-item.h
@@ -67,15 +67,27 @@ typedef enum
NAUTILUS_PREFERENCE_ITEM_ENUM,
NAUTILUS_PREFERENCE_ITEM_SHORT_ENUM,
NAUTILUS_PREFERENCE_ITEM_FONT_FAMILY,
+ NAUTILUS_PREFERENCE_ITEM_SMOOTH_FONT,
NAUTILUS_PREFERENCE_ITEM_EDITABLE_STRING,
NAUTILUS_PREFERENCE_ITEM_INTEGER
} NautilusPreferencesItemType;
+typedef enum
+{
+ NAUTILUS_PREFERENCE_ITEM_SHOW,
+ NAUTILUS_PREFERENCE_ITEM_HIDE
+} NautilusPreferencesItemControlAction;
+
GtkType nautilus_preferences_item_get_type (void);
-GtkWidget* nautilus_preferences_item_new (const char *preference_name,
- NautilusPreferencesItemType item_type);
-char * nautilus_preferences_item_get_name (const NautilusPreferencesItem *preferences_item);
-void nautilus_preferences_item_update_displayed_value (const NautilusPreferencesItem *preferences_item);
+GtkWidget* nautilus_preferences_item_new (const char *preference_name,
+ NautilusPreferencesItemType item_type);
+char * nautilus_preferences_item_get_name (const NautilusPreferencesItem *preferences_item);
+void nautilus_preferences_item_update_displayed_value (const NautilusPreferencesItem *preferences_item);
+void nautilus_preferences_item_set_control_preference (NautilusPreferencesItem *preferences_item,
+ const char *control_preference_name);
+void nautilus_preferences_item_set_control_action (NautilusPreferencesItem *preferences_item,
+ NautilusPreferencesItemControlAction control_action);
+gboolean nautilus_preferences_item_get_control_showing (const NautilusPreferencesItem *preferences_item);
END_GNOME_DECLS
diff --git a/libnautilus-private/nautilus-preferences-pane.c b/libnautilus-private/nautilus-preferences-pane.c
index f425e0194..3466661de 100644
--- a/libnautilus-private/nautilus-preferences-pane.c
+++ b/libnautilus-private/nautilus-preferences-pane.c
@@ -26,6 +26,7 @@
#include <config.h>
#include "nautilus-preferences-pane.h"
#include "nautilus-gtk-macros.h"
+#include "nautilus-gtk-extensions.h"
#include <gtk/gtkhbox.h>
@@ -184,14 +185,9 @@ nautilus_preferences_pane_update (NautilusPreferencesPane *preferences_pane)
for (iterator = preferences_pane->details->groups; iterator != NULL; iterator = iterator->next) {
NautilusPreferencesGroup *group = NAUTILUS_PREFERENCES_GROUP (iterator->data);
-
nautilus_preferences_group_update (group);
-
- if (nautilus_preferences_group_get_num_visible_items (group) == 0) {
- gtk_widget_hide (GTK_WIDGET (group));
- } else {
- gtk_widget_show (GTK_WIDGET (group));
- }
+ nautilus_gtk_widget_set_shown (GTK_WIDGET (group),
+ nautilus_preferences_group_get_num_visible_items (group) > 0);
}
}
diff --git a/libnautilus-private/nautilus-scalable-font.c b/libnautilus-private/nautilus-scalable-font.c
index c18167cfd..b1c4a516d 100644
--- a/libnautilus-private/nautilus-scalable-font.c
+++ b/libnautilus-private/nautilus-scalable-font.c
@@ -527,10 +527,10 @@ font_family_string_map_new (void)
* Of course, specifying the font by its exact name will continue to work.
*/
if (font_family_lookup (global_font_family_table, "nimbus sans l")) {
- nautilus_string_map_add (map, "nimbus sans l", "helvetica");
+ nautilus_string_map_add (map, "nimbus sans l", "helvetica default");
}
- else if (font_family_lookup (global_font_family_table, "helvetica")) {
- nautilus_string_map_add (map, "helvetica", "nimbus sans l");
+ else if (font_family_lookup (global_font_family_table, "helvetica default")) {
+ nautilus_string_map_add (map, "helvetica default", "nimbus sans l");
}
return map;
@@ -611,6 +611,34 @@ nautilus_scalable_font_new (const char *family,
return font;
}
+/**
+ * nautilus_scalable_font_new_from_file_name:
+ * @file_name: Postscript or TrueType font file name.
+ *
+ * Returns a font for the given font file name.
+ *
+ */
+NautilusScalableFont *
+nautilus_scalable_font_new_from_file_name (const char *file_name)
+{
+ NautilusScalableFont *font;
+
+ g_return_val_if_fail (nautilus_strlen (file_name) > 0, NULL);
+ g_return_val_if_fail (g_file_exists (file_name), NULL);
+
+ initialize_global_stuff_if_needed ();
+
+ font = NAUTILUS_SCALABLE_FONT (gtk_object_new (nautilus_scalable_font_get_type (), NULL));
+ gtk_object_ref (GTK_OBJECT (font));
+ gtk_object_sink (GTK_OBJECT (font));
+
+ font->detail->font_handle = rsvg_ft_intern (global_rsvg_ft_context, file_name);
+ font->detail->font_family_entry = NULL;
+ font->detail->font_entry = NULL;
+
+ return font;
+}
+
NautilusScalableFont *
nautilus_scalable_font_make_bold (NautilusScalableFont *font)
{
@@ -792,7 +820,7 @@ NautilusScalableFont *
nautilus_scalable_font_get_default_font (void)
{
if (global_default_font == NULL) {
- global_default_font = nautilus_scalable_font_new ("helvetica", NULL, NULL, NULL);
+ global_default_font = nautilus_scalable_font_new ("helvetica default", NULL, NULL, NULL);
g_assert (global_default_font != NULL);
g_atexit (default_font_at_exit_destructor);
}
@@ -802,6 +830,19 @@ nautilus_scalable_font_get_default_font (void)
return global_default_font;
}
+NautilusScalableFont *
+nautilus_scalable_font_get_default_bold_font (void)
+{
+ NautilusScalableFont *default_font;
+ NautilusScalableFont *default_bold_font;
+
+ default_font = nautilus_scalable_font_get_default_font ();
+ default_bold_font = nautilus_scalable_font_make_bold (default_font);
+ gtk_object_unref (GTK_OBJECT (default_font));
+
+ return default_bold_font;
+}
+
static void
font_family_table_for_each_append (gpointer key,
gpointer value,
@@ -924,14 +965,6 @@ nautilus_scalable_font_query_font (const char *family,
return TRUE;
}
-#if 0
-static const char * global_default_font_path[] =
-{
- "/usr/lib/X11/fonts/Type1",
- "/usr/share/fonts/default/Type1"
-};
-#endif
-
/* 'atexit' destructors for global stuff */
static void
destroy_global_rsvg_ft_context (void)
@@ -972,13 +1005,7 @@ initialize_global_stuff_if_needed (void)
if (!fonts_initialized) {
fonts_initialized = TRUE;
global_font_family_table = g_hash_table_new (g_str_hash, g_str_equal);
-
-#if TYPE1_FONT_DIR_EXISTS
- font_family_table_add_fonts (global_font_family_table, "/usr/share/fonts/default/Type1");
-#else
font_family_table_add_fonts (global_font_family_table, NAUTILUS_DATADIR "/fonts/urw");
-#endif
-
g_atexit (font_family_table_at_exit_destructor);
}
@@ -989,31 +1016,6 @@ initialize_global_stuff_if_needed (void)
}
}
-int
-nautilus_scalable_font_get_underline_height (const NautilusScalableFont *font,
- int font_size)
-{
- g_return_val_if_fail (NAUTILUS_IS_SCALABLE_FONT (font), 0);
- g_return_val_if_fail (font_size > 0, 0);
-
- /* FIXME bugzilla.eazel.com 2865: This underlining code should
- * take into account the baseline for the rendered string rather
- * that doing the '1' nonsense.
- */
- return 1;
-}
-
-int
-nautilus_scalable_font_get_baseline (const NautilusScalableFont *font,
- int font_size)
-{
- /* FIXME bugzilla.eazel.com 2865: This underlining code should
- * take into account the baseline for the rendered string rather
- * that doing the '-2' nonsense.
- */
- return -2;
-}
-
/* Private NautilusScalableFont things */
int
nautilus_scalable_font_get_rsvg_handle (const NautilusScalableFont *font)
diff --git a/libnautilus-private/nautilus-scalable-font.h b/libnautilus-private/nautilus-scalable-font.h
index 92d82e80b..40c860cc8 100644
--- a/libnautilus-private/nautilus-scalable-font.h
+++ b/libnautilus-private/nautilus-scalable-font.h
@@ -78,6 +78,7 @@ NautilusScalableFont *nautilus_scalable_font_new (const c
const char *weight,
const char *slant,
const char *set_width);
+NautilusScalableFont * nautilus_scalable_font_new_from_file_name (const char *file_name);
NautilusDimensions nautilus_scalable_font_measure_text (const NautilusScalableFont *font,
int font_size,
const char *text,
@@ -102,16 +103,14 @@ int nautilus_scalable_font_largest_fitting_font_size (const N
int minimum_acceptable_font_size,
int maximum_acceptable_font_size);
NautilusScalableFont *nautilus_scalable_font_get_default_font (void);
+NautilusScalableFont *nautilus_scalable_font_get_default_bold_font (void);
NautilusStringList * nautilus_scalable_font_get_font_family_list (void);
gboolean nautilus_scalable_font_query_font (const char *family,
NautilusStringList **weights,
NautilusStringList **slants,
NautilusStringList **set_widths);
NautilusScalableFont *nautilus_scalable_font_make_bold (NautilusScalableFont *font);
-int nautilus_scalable_font_get_underline_height (const NautilusScalableFont *font,
- int font_size);
-int nautilus_scalable_font_get_baseline (const NautilusScalableFont *font,
- int font_size);
+
END_GNOME_DECLS
#endif /* NAUTILUS_SCALABLE_FONT_H */
diff --git a/libnautilus-private/nautilus-string-picker.c b/libnautilus-private/nautilus-string-picker.c
index 34d1be9f3..370266393 100644
--- a/libnautilus-private/nautilus-string-picker.c
+++ b/libnautilus-private/nautilus-string-picker.c
@@ -362,3 +362,27 @@ nautilus_string_picker_get_index_for_string (const NautilusStringPicker *string_
return nautilus_string_list_get_index_for_string (string_picker->detail->string_list, string);
}
+
+/**
+ * nautilus_string_picker_clear:
+
+ * @string_picker: A NautilusStringPicker
+ *
+ * Remove all entries from the string picker.
+ */
+void
+nautilus_string_picker_clear (NautilusStringPicker *string_picker)
+{
+ NautilusStringList *empty_list;
+
+ g_return_if_fail (NAUTILUS_IS_STRING_PICKER (string_picker));
+
+ /* Already empty */
+ if (nautilus_string_list_get_length (string_picker->detail->string_list) == 0) {
+ return;
+ }
+
+ empty_list = nautilus_string_list_new (TRUE);
+ nautilus_string_picker_set_string_list (string_picker, empty_list);
+ nautilus_string_list_free (empty_list);
+}
diff --git a/libnautilus-private/nautilus-string-picker.h b/libnautilus-private/nautilus-string-picker.h
index ebfcb5b6a..9ce803b67 100644
--- a/libnautilus-private/nautilus-string-picker.h
+++ b/libnautilus-private/nautilus-string-picker.h
@@ -60,40 +60,42 @@ struct _NautilusStringPickerClass
NautilusCaptionClass parent_class;
};
-GtkType nautilus_string_picker_get_type (void);
-GtkWidget* nautilus_string_picker_new (void);
+GtkType nautilus_string_picker_get_type (void);
+GtkWidget* nautilus_string_picker_new (void);
/* Set the list of strings. */
-void nautilus_string_picker_set_string_list (NautilusStringPicker *string_picker,
- const NautilusStringList *string_list);
-
+void nautilus_string_picker_set_string_list (NautilusStringPicker *string_picker,
+ const NautilusStringList *string_list);
/* Access a copy of the list of strings. */
-NautilusStringList *nautilus_string_picker_get_string_list (const NautilusStringPicker *string_picker);
+NautilusStringList *nautilus_string_picker_get_string_list (const NautilusStringPicker *string_picker);
/* Get the selected string. Resulting string needs to be freed with g_free(). */
-char * nautilus_string_picker_get_selected_string (NautilusStringPicker *string_picker);
+char * nautilus_string_picker_get_selected_string (NautilusStringPicker *string_picker);
/* Set the selected string. The internal string list needs to contain the 'string'. */
-void nautilus_string_picker_set_selected_string (NautilusStringPicker *string_picker,
- const char *string);
+void nautilus_string_picker_set_selected_string (NautilusStringPicker *string_picker,
+ const char *string);
void nautilus_string_picker_set_selected_string_index (NautilusStringPicker *string_picker,
- guint index);
+ guint index);
/* Add a new string to the picker. */
-void nautilus_string_picker_insert_string (NautilusStringPicker *string_picker,
- const char *string);
+void nautilus_string_picker_insert_string (NautilusStringPicker *string_picker,
+ const char *string);
/* Does the string picker contain the given string ? */
-gboolean nautilus_string_picker_contains (const NautilusStringPicker *string_picker,
- const char *string);
+gboolean nautilus_string_picker_contains (const NautilusStringPicker *string_picker,
+ const char *string);
/* Return the index of the given string */
-int nautilus_string_picker_get_index_for_string (const NautilusStringPicker *string_picker,
- const char *string);
+int nautilus_string_picker_get_index_for_string (const NautilusStringPicker *string_picker,
+ const char *string);
+
+/* Remove all entries from the string picker. */
+void nautilus_string_picker_clear (NautilusStringPicker *string_picker);
END_GNOME_DECLS
diff --git a/libnautilus-private/nautilus-tabs.c b/libnautilus-private/nautilus-tabs.c
index 2fa4c7467..bc718847f 100644
--- a/libnautilus-private/nautilus-tabs.c
+++ b/libnautilus-private/nautilus-tabs.c
@@ -179,9 +179,9 @@ nautilus_tabs_initialize (NautilusTabs *tabs)
tabs->details->selected_tab = -1;
/* FIXME bugzilla.eazel.com 5456:
- * Hard coded font family and size.
+ * Hard coded font size.
*/
- tabs->details->tab_font = nautilus_scalable_font_new ("helvetica", "bold", NULL, NULL);
+ tabs->details->tab_font = nautilus_scalable_font_get_default_bold_font ();
tabs->details->font_size = 14;
gray_tab_directory_path = nautilus_theme_get_image_path ("gray_tab_pieces");
diff --git a/src/nautilus-first-time-druid.c b/src/nautilus-first-time-druid.c
index 6e80af176..6a8b008bf 100644
--- a/src/nautilus-first-time-druid.c
+++ b/src/nautilus-first-time-druid.c
@@ -337,9 +337,7 @@ new_title_label (const char *text)
label = label_new_left_justified (text);
- /* Note to localizers: this font is used for title text in
- * the first time druid */
- font = nautilus_scalable_font_new (_("helvetica"), _("medium"), NULL, NULL);
+ font = nautilus_scalable_font_get_default_font ();
nautilus_label_set_is_smooth (NAUTILUS_LABEL (label), TRUE);
nautilus_label_set_smooth_font (NAUTILUS_LABEL (label), font);
nautilus_label_make_larger (NAUTILUS_LABEL (label), 10);
diff --git a/src/nautilus-sidebar-tabs.c b/src/nautilus-sidebar-tabs.c
index 63c85e8e8..cf33b3d89 100644
--- a/src/nautilus-sidebar-tabs.c
+++ b/src/nautilus-sidebar-tabs.c
@@ -229,11 +229,11 @@ nautilus_sidebar_tabs_load_theme_data (NautilusSidebarTabs *sidebar_tabs)
}
/* FIXME bugzilla.eazel.com 5456:
- * Hard coded font family and size.
+ * Hard coded font size.
*/
/* use the default font. In the future, it should fetch the font name and properties from the theme */
- sidebar_tabs->details->tab_font = nautilus_scalable_font_new ("helvetica", "bold", NULL, NULL);
+ sidebar_tabs->details->tab_font = nautilus_scalable_font_get_default_bold_font ();
sidebar_tabs->details->font_size = 12;
}
diff --git a/test/Makefile.am b/test/Makefile.am
index 9cd60bccd..fe4151519 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -69,7 +69,7 @@ test_nautilus_async_activation_SOURCES = test-nautilus-async-activation.c
test_nautilus_background_SOURCES = test-nautilus-background.c
test_nautilus_clickable_image_SOURCES = test-nautilus-clickable-image.c test.c
test_nautilus_font_SOURCES = test-nautilus-font.c test.c
-test_nautilus_font_picker_SOURCES = test-nautilus-font-picker.c
+test_nautilus_font_picker_SOURCES = test-nautilus-font-picker.c test.c
test_nautilus_font_simple_SOURCES = test-nautilus-font-simple.c test.c
test_nautilus_font_manager_SOURCES = test-nautilus-font-manager.c test.c
test_nautilus_glyph_SOURCES = test-nautilus-glyph.c test.c
diff --git a/test/test-nautilus-font-manager.c b/test/test-nautilus-font-manager.c
index 0b34bb3ce..468b6c487 100644
--- a/test/test-nautilus-font-manager.c
+++ b/test/test-nautilus-font-manager.c
@@ -5,8 +5,41 @@
#include <libnautilus-extensions/nautilus-font-manager.h>
+static const char *
+font_type_to_string (NautilusFontType font_type)
+{
+ if (font_type == NAUTILUS_FONT_POSTSCRIPT) {
+ return "postscript";
+ }
+
+ return "truetype";
+}
+
+// microsoft Webdings
+// microsoft Wingdings
+// monotype OCR
+// URW Zapf
+// xfree86 cursor
+
+typedef struct
+{
+ char *key;
+ char *font_file_name;
+} Style;
+
+typedef struct
+{
+ char *title;
+ char *foundry;
+ char *family;
+ char *key;
+ GList *style_list;
+} Entry;
+
static void
-font_iterator_callback (const char *foundry,
+font_iterator_callback (const char *font_file_name,
+ NautilusFontType font_type,
+ const char *foundry,
const char *family,
const char *weight,
const char *slant,
@@ -15,23 +48,88 @@ font_iterator_callback (const char *foundry,
const char *char_set_encoding,
gpointer callback_data)
{
+ char *key;
+ Entry *entry;
+ Style *style;
+
+ GHashTable *font_table;
+
+ g_return_if_fail (font_file_name != NULL);
+ g_return_if_fail (foundry != NULL);
+ g_return_if_fail (family != NULL);
+ g_return_if_fail (weight != NULL);
+ g_return_if_fail (slant != NULL);
+ g_return_if_fail (set_width != NULL);
+ g_return_if_fail (char_set_registry != NULL);
+ g_return_if_fail (char_set_encoding != NULL);
+ g_return_if_fail (callback_data != NULL);
+
+ font_table = callback_data;
+
+ key = g_strdup_printf ("%s %s", foundry, family);
+
+ entry = g_hash_table_lookup (font_table, key);
+
+ if (entry == NULL) {
+ entry = g_new0 (Entry, 1);
+ entry->key = g_strdup (key);
+ entry->foundry = g_strdup (foundry);
+ entry->family = g_strdup (family);
+
+ g_hash_table_insert (font_table, entry->key, entry);
+ }
+ g_assert (entry != NULL);
+ g_assert (g_hash_table_lookup (font_table, key) == entry);
+ g_free (key);
+
+ style = g_new0 (Style, 1);
+ style->key = g_strdup_printf ("%s %s %s", weight, slant, set_width);
+ style->font_file_name = g_strdup (font_file_name);
+
+ entry->style_list = g_list_append (entry->style_list, style);
+
+ if (1) {
+ g_print ("%s %s %s-%s-%s-%s-%s-%s-%s\n",
+ font_type_to_string (font_type),
+ font_file_name,
+ foundry,
+ family,
+ weight,
+ slant,
+ set_width,
+ char_set_registry,
+ char_set_encoding);
+ }
+}
+
+static void
+font_table_for_each_callback (gpointer key,
+ gpointer value,
+ gpointer callback_data)
+{
+ char *entry_key;
+
+ g_return_if_fail (key != NULL);
+ g_return_if_fail (value != NULL);
+ //g_return_if_fail (callback_data != NULL);
+
+ entry_key = key;
- g_print ("%s-%s-%s-%s-%s-%s-%s\n",
- foundry,
- family,
- weight,
- slant,
- set_width,
- char_set_registry,
- char_set_encoding);
+ if (0) g_print ("%s\n", entry_key);
}
int
main (int argc, char* argv[])
{
+ GHashTable *font_table = NULL;
+
test_init (&argc, &argv);
- nautilus_font_manager_for_each_font (font_iterator_callback, NULL);
+ font_table = g_hash_table_new (g_str_hash, g_str_equal);
+
+ nautilus_font_manager_for_each_font (font_iterator_callback, font_table);
+
+ g_hash_table_foreach (font_table, font_table_for_each_callback, NULL);
return test_quit (EXIT_SUCCESS);
}
diff --git a/test/test-nautilus-font-picker.c b/test/test-nautilus-font-picker.c
index 89f341c45..ef1566fa5 100644
--- a/test/test-nautilus-font-picker.c
+++ b/test/test-nautilus-font-picker.c
@@ -1,55 +1,75 @@
-#include <config.h>
+#include "test.h"
-#include <gtk/gtk.h>
-#include <libgnome/gnome-defs.h>
-#include <libgnomeui/gnome-init.h>
#include <libnautilus-extensions/nautilus-font-picker.h>
+#include <libnautilus-extensions/nautilus-font-manager.h>
static void
-font_picker_changed_callback (GtkWidget *font_picker, gpointer user_data)
+font_picker_changed_callback (NautilusFontPicker *font_picker,
+ gpointer callback_data)
{
- char *family;
- char *weight;
- char *slant;
- char *set_width;
+ NautilusScalableFont *font;
+ char *font_file_name;
g_return_if_fail (NAUTILUS_IS_FONT_PICKER (font_picker));
+ g_return_if_fail (NAUTILUS_IS_LABEL (callback_data));
- family = nautilus_font_picker_get_selected_family (NAUTILUS_FONT_PICKER (font_picker));
- weight = nautilus_font_picker_get_selected_weight (NAUTILUS_FONT_PICKER (font_picker));
- slant = nautilus_font_picker_get_selected_slant (NAUTILUS_FONT_PICKER (font_picker));
- set_width = nautilus_font_picker_get_selected_set_width (NAUTILUS_FONT_PICKER (font_picker));
+ font_file_name = nautilus_font_picker_get_selected_font (font_picker);
+ g_print ("font changed = %s\n", font_file_name);
- g_print ("%s (%s,%s,%s,%s)\n", __FUNCTION__, family, weight, slant, set_width);
+ font = nautilus_scalable_font_new_from_file_name (font_file_name);
+ nautilus_label_set_smooth_font (NAUTILUS_LABEL (callback_data), font);
+ gtk_object_unref (GTK_OBJECT (font));
- g_free (family);
- g_free (weight);
- g_free (slant);
- g_free (set_width);
+ g_free (font_file_name);
}
int
main (int argc, char * argv[])
{
- GtkWidget *window;
- GtkWidget *font_picker;
+ GtkWidget *window;
+ GtkWidget *vbox;
+ GtkWidget *font_picker;
+ GtkWidget *label;
- gnome_init ("foo", "bar", argc, argv);
-
- window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
+ NautilusScalableFont *font;
+
+ char *fallback_font;
+
+ test_init (&argc, &argv);
+
+ window = test_window_new ("Font Picker Test", 10);
+
+ vbox = gtk_vbox_new (FALSE, 0);
+ gtk_container_add (GTK_CONTAINER (window), vbox);
+
+ fallback_font = nautilus_font_manager_get_fallback_font ();
+ g_print ("fallback_font = %s\n", fallback_font);
font_picker = nautilus_font_picker_new ();
+
+ label = nautilus_label_new ("Something");
+ nautilus_label_set_is_smooth (NAUTILUS_LABEL (label), TRUE);
+ nautilus_label_make_larger (NAUTILUS_LABEL (label), 40);
+
+ font = nautilus_scalable_font_new_from_file_name ("/usr/share/fonts/default/truetype/times.ttf");
+
+ nautilus_label_set_smooth_font (NAUTILUS_LABEL (label), font);
- gtk_container_add (GTK_CONTAINER (window), font_picker);
+ gtk_object_unref (GTK_OBJECT (font));
gtk_signal_connect (GTK_OBJECT (font_picker),
- "selected_font_changed",
+ "changed",
GTK_SIGNAL_FUNC (font_picker_changed_callback),
- (gpointer) NULL);
+ label);
- gtk_widget_show (font_picker);
- gtk_widget_show (window);
- gtk_main ();
+ nautilus_font_picker_set_selected_font (NAUTILUS_FONT_PICKER (font_picker),
+ "/usr/share/fonts/ISO8859-2/Type1/gatsb___.pfb");
+
+ gtk_box_pack_start (GTK_BOX (vbox), font_picker, TRUE, TRUE, 0);
+ gtk_box_pack_start (GTK_BOX (vbox), label, TRUE, TRUE, 10);
+
+ gtk_widget_show_all (window);
- return 0;
+ gtk_main ();
+ return test_quit (EXIT_SUCCESS);
}
diff --git a/test/test-nautilus-glyph-simple.c b/test/test-nautilus-glyph-simple.c
index 8eaa06e9f..414450679 100644
--- a/test/test-nautilus-glyph-simple.c
+++ b/test/test-nautilus-glyph-simple.c
@@ -105,16 +105,10 @@ main (int argc, char* argv[])
{
NautilusScalableFont *font;
- int underline_height;
- int baseline;
ArtIRect glyph_rect;
ArtIRect underline_rect;
font = nautilus_scalable_font_get_default_font ();
- underline_height = nautilus_scalable_font_get_underline_height (font, underlined_font_size);
- baseline = nautilus_scalable_font_get_baseline (font, underlined_font_size);
- gtk_object_unref (GTK_OBJECT (font));
-
glyph_rect = nautilus_glyph_intersect (glyph, x, y, NULL);
if (0) nautilus_debug_pixbuf_draw_rectangle (pixbuf,
@@ -126,10 +120,7 @@ main (int argc, char* argv[])
0xFF0000,
NAUTILUS_OPACITY_FULLY_OPAQUE);
- underline_rect = glyph_rect;
-
- underline_rect.y1 -= ABS (baseline);
- underline_rect.y0 = underline_rect.y1 - underline_height;
+ nautilus_glyph_get_underline_rectangle (glyph, &underline_rect);
nautilus_debug_pixbuf_draw_rectangle (pixbuf,
TRUE,
@@ -139,9 +130,6 @@ main (int argc, char* argv[])
underline_rect.y1,
NAUTILUS_RGBA_COLOR_OPAQUE_BLUE,
NAUTILUS_OPACITY_FULLY_OPAQUE);
-
- g_print ("underline_height = %d\n", underline_height);
- g_print ("baseline = %d\n", baseline);
}
nautilus_glyph_free (glyph);
diff --git a/test/test-nautilus-label.c b/test/test-nautilus-label.c
index 2bbabd9c1..e6ad7afd6 100644
--- a/test/test-nautilus-label.c
+++ b/test/test-nautilus-label.c
@@ -199,56 +199,6 @@ alpha_background_color_value_changed_callback (GtkAdjustment *adjustment, gpoint
}
static void
-font_size_changed_callback (NautilusStringPicker *string_picker, gpointer client_data)
-{
- char *string;
- int size;
-
- g_return_if_fail (NAUTILUS_IS_STRING_PICKER (string_picker));
- g_return_if_fail (NAUTILUS_IS_LABEL (client_data));
-
- string = nautilus_string_picker_get_selected_string (string_picker);
-
- if (nautilus_eat_str_to_int (string, &size)) {
- nautilus_label_set_smooth_font_size (NAUTILUS_LABEL (client_data), (guint) size);
- }
-
- g_free (string);
-}
-
-static void
-font_changed_callback (NautilusFontPicker *font_picker, gpointer client_data)
-{
- NautilusScalableFont *font;
- char *family;
- char *weight;
- char *slant;
- char *set_width;
-
- g_return_if_fail (NAUTILUS_IS_FONT_PICKER (font_picker));
- g_return_if_fail (NAUTILUS_IS_LABEL (client_data));
-
- family = nautilus_font_picker_get_selected_family (NAUTILUS_FONT_PICKER (font_picker));
- weight = nautilus_font_picker_get_selected_weight (NAUTILUS_FONT_PICKER (font_picker));
- slant = nautilus_font_picker_get_selected_slant (NAUTILUS_FONT_PICKER (font_picker));
- set_width = nautilus_font_picker_get_selected_set_width (NAUTILUS_FONT_PICKER (font_picker));
-
- g_print ("%s (%s,%s,%s,%s)\n", __FUNCTION__, family, weight, slant, set_width);
-
- font = nautilus_scalable_font_new (family, weight, slant, set_width);
- g_assert (font != NULL);
-
- nautilus_label_set_smooth_font (NAUTILUS_LABEL (client_data), font);
-
- g_free (family);
- g_free (weight);
- g_free (slant);
- g_free (set_width);
-
- gtk_object_unref (GTK_OBJECT (font));
-}
-
-static void
text_caption_changed_callback (NautilusTextCaption *text_caption, gpointer client_data)
{
NautilusLabel *label;
@@ -400,53 +350,6 @@ create_color_picker_frame (const char *title,
}
static GtkWidget*
-create_font_picker_frame (const char *title,
- GtkSignalFunc changed_callback,
- GtkSignalFunc size_changed_callback,
- gpointer callback_data)
-{
- GtkWidget *frame;
- GtkWidget *hbox;
- GtkWidget *font_picker;
- GtkWidget *font_size_picker;
- NautilusStringList *font_size_list;
-
- g_return_val_if_fail (title != NULL, NULL);
- g_return_val_if_fail (changed_callback != NULL, NULL);
- g_return_val_if_fail (size_changed_callback != NULL, NULL);
-
- frame = gtk_frame_new (title);
-
- hbox = gtk_hbox_new (FALSE, 0);
- gtk_container_set_border_width (GTK_CONTAINER (hbox), 6);
-
- gtk_container_add (GTK_CONTAINER (frame), hbox);
-
- font_size_picker = nautilus_string_picker_new ();
- nautilus_caption_set_show_title (NAUTILUS_CAPTION (font_size_picker), FALSE);
- nautilus_caption_set_title_label (NAUTILUS_CAPTION (font_size_picker), "Size");
-
- gtk_signal_connect (GTK_OBJECT (font_size_picker), "changed", size_changed_callback, callback_data);
-
- font_size_list = nautilus_string_list_new_from_tokens ("5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,"
- "30,40,50,60,70,80,90,100,110,120,130,140,"
- "200,400,800", ",", TRUE);
-
- nautilus_string_picker_set_string_list (NAUTILUS_STRING_PICKER (font_size_picker), font_size_list);
- nautilus_string_list_free (font_size_list);
-
- font_picker = nautilus_font_picker_new ();
- gtk_signal_connect (GTK_OBJECT (font_picker), "selected_font_changed", changed_callback, callback_data);
-
- gtk_box_pack_start (GTK_BOX (hbox), font_picker, TRUE, TRUE, 0);
- gtk_box_pack_end (GTK_BOX (hbox), font_size_picker, FALSE, FALSE, 5);
-
- gtk_widget_show_all (hbox);
-
- return frame;
-}
-
-static GtkWidget*
create_text_caption_frame (const char *title,
GtkSignalFunc changed_callback,
gpointer callback_data)
@@ -732,12 +635,10 @@ main (int argc, char* argv[])
GtkWidget *bottom_box;
GtkWidget *tool_box1;
GtkWidget *tool_box2;
- GtkWidget *tool_box3;
GtkWidget *color_tool_box;
GtkWidget *label;
GtkWidget *label_color_picker_frame;
GtkWidget *background_color_picker_frame;
- GtkWidget *font_picker_frame;
GtkWidget *text_caption_frame;
GtkWidget *background_frame;
GtkWidget *justification_frame;
@@ -763,13 +664,11 @@ main (int argc, char* argv[])
tool_box1 = gtk_hbox_new (FALSE, 0);
tool_box2 = gtk_hbox_new (FALSE, 0);
- tool_box3 = gtk_hbox_new (FALSE, 0);
color_tool_box = gtk_hbox_new (FALSE, 0);
gtk_box_pack_start (GTK_BOX (bottom_box), tool_box1, TRUE, TRUE, 0);
gtk_box_pack_start (GTK_BOX (bottom_box), tool_box2, TRUE, TRUE, 0);
- gtk_box_pack_end (GTK_BOX (bottom_box), tool_box3, TRUE, TRUE, 10);
gtk_box_pack_start (GTK_BOX (main_box), label, TRUE, TRUE, 10);
gtk_box_pack_end (GTK_BOX (main_box), bottom_box, TRUE, TRUE, 10);
@@ -792,11 +691,6 @@ main (int argc, char* argv[])
label,
nautilus_label_get_text_color (NAUTILUS_LABEL (label)));
- font_picker_frame = create_font_picker_frame ("Font",
- font_changed_callback,
- font_size_changed_callback,
- label);
-
text_caption_frame = create_text_caption_frame ("Text",
text_caption_changed_callback,
label);
@@ -823,8 +717,7 @@ main (int argc, char* argv[])
gtk_box_pack_end (GTK_BOX (color_tool_box), background_color_picker_frame, FALSE, FALSE, 0);
gtk_box_pack_start (GTK_BOX (tool_box1), color_tool_box, FALSE, FALSE, 0);
- gtk_box_pack_start (GTK_BOX (tool_box2), font_picker_frame, FALSE, FALSE, 0);
- gtk_box_pack_start (GTK_BOX (tool_box3), text_caption_frame, TRUE, TRUE, 0);
+ gtk_box_pack_start (GTK_BOX (tool_box2), text_caption_frame, TRUE, TRUE, 0);
gtk_widget_show_all (window);