summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRamiro Estrugo <ramiro@src.gnome.org>2001-03-05 08:15:06 +0000
committerRamiro Estrugo <ramiro@src.gnome.org>2001-03-05 08:15:06 +0000
commit24faaf921909492b4921efa64e8be1606a0d8324 (patch)
treea3ba475da2c7e716d4596f529363dc84560f9062
parent9723f62b3cf838898150308b49aae16f1e5b53ff (diff)
downloadnautilus-24faaf921909492b4921efa64e8be1606a0d8324.tar.gz
reviewed by: Pavel Cisler <pavel@eazel.com>
Maciej Stachowiak <mjs@eazel.com> Bugs: 6368 - Multibyte font handling in non smooth mode. 2673 - Need to hook up the new font picker to nautilus 1274 - Add support for picking a custom font * components/history/Makefile.am: * components/history/nautilus-history-view.c: (main): Initialize gettext for the history component so it can display localized strings. * components/notes/nautilus-notes.c: (make_notes_view): Set the notes widget font from preferences so it can be properly localized. * components/text/nautilus-text-view.c: (nautilus_text_view_set_font): Use the localized font name to make this work in locales other than the default. * libnautilus-extensions/Makefile.am: Add a macro for finding data on the source tree for the situation when 'make install' has not be run. * libnautilus-extensions/nautilus-font-factory.c: (nautilus_font_factory_get_font_by_family): Workaround the problem that fully qualified localized fonts were being processed incorrectly. We simply leave them alone now. (nautilus_font_factory_get_font_from_preferences): Use the localized font string to make this work on more locales. * libnautilus-extensions/nautilus-font-manager.h: * libnautilus-extensions/nautilus-font-manager.c: (font_description_table_find): New function to find a description in a table. (font_description_table_for_each): Change the return value to a boolean to indicate whether to stop the iteration or not. Switch the order of an assert and assigned. (collect_fonts_from_directory): Use macros for the mime type strings. (font_ignore_directory): Add more directories to ignore. (font_manager_collect_font_tables): Change prepend to append to get fonts in a better order (fallback and user fonts first) , (font_table_list_find), (free_font_tables), (ensure_global_font_table), (nautilus_font_manager_for_each_font): Use just one global table for all fonts instead of 3. (nautilus_font_manager_get_default_font): Compute the default dynamically to take user choices into account. Make it work on non installed nautilus builds. (nautilus_font_manager_get_default_bold_font): Same as above for a bold font. (nautilus_font_manager_file_is_scalable_font): New function to check that a file is really a scalable font: (font_list_find_bold_callback), (nautilus_font_manager_get_bold), (nautilus_font_manager_weight_is_bold): New functions to find a bold font in the global tables. (nautilus_self_check_font_manager): Make it work on not installed nautilus builds and remove the hack where checks would on run for the "ramiro" user. * libnautilus-extensions/nautilus-font-picker.c: (nautilus_font_picker_initialize), (font_list_find), (font_picker_update_styles), (font_picker_populate), (font_picker_font_changed_callback), (font_picker_style_changed_callback), (font_find_style), (ignore_font), (font_make_name), (font_make_style), (global_font_list_free), (font_list_count_families), (global_font_list_get), (global_font_list_populate_callback), (nautilus_font_picker_get_selected_font), (nautilus_font_picker_set_selected_font): Make the font list global and not per widget instance. Use better labels for the font styles. Use better labels for font names (foundry and family vs just family depending on how many families of the same font are found) * libnautilus-extensions/nautilus-global-preferences.h: * libnautilus-extensions/nautilus-global-preferences.c: (global_preferences_install_font_defaults): Add new smooth font preference for the icon container. (nautilus_global_preferences_get_smooth_font): New function to safely get a smooth font out of preferences. * libnautilus-extensions/nautilus-icon-container.c: (nautilus_icon_container_initialize): Use the localized version of the font strings and add a FIXME for the problem of checking these in many disparate places in nautilus. * libnautilus-extensions/nautilus-program-chooser.c: (program_file_pair_get_program_name_for_display): Use the localized version of the application name strings. * libnautilus-extensions/nautilus-scalable-font.h: * libnautilus-extensions/nautilus-scalable-font.c: (nautilus_scalable_font_initialize_class), (nautilus_scalable_font_initialize), (nautilus_scalable_font_destroy), (nautilus_scalable_font_new), (nautilus_scalable_font_make_bold), (nautilus_scalable_font_get_default_font), (nautilus_scalable_font_get_default_bold_font), (free_global_font_handle_table), (initialize_global_stuff_if_needed), (nautilus_scalable_font_get_rsvg_handle): Simplify this class a lot by using the font manager. No longer need to manage font lookup and queries. * libnautilus-extensions/nautilus-smooth-text-layout-cache.c: (nautilus_self_check_smooth_text_layout_cache): Fix a comment. Dont hardcode the font family. Use the default font. Remove the #ifdef hacker for "before make install fonts broken" problem which is now fixed. * src/file-manager/fm-directory-view.h: * src/file-manager/fm-directory-view.c: (directory_view_smooth_font_changed_callback), (fm_directory_view_initialize), (fm_directory_view_destroy): Add method for responding to changes in the smooth font for AA mode of the icon container. * src/file-manager/fm-icon-view.c: (fm_icon_view_smooth_font_changed), (fm_icon_view_initialize_class), (fm_icon_view_update_icon_container_smooth_font), (create_icon_container): Add support for responding to change in the smooth font. Update the icon container's smooth font on such changes. * src/nautilus-about.c: (nautilus_about_draw_info): Change the offset of the "Nautilus" title which broken when jsh make glyphs render properly taking the baseline into account. * src/nautilus-sidebar-title.c: (update_font): Use the localized font name. * src/nautilus-sidebar.c: (nautilus_sidebar_add_panel), (nautilus_sidebar_remove_panel): Use the localized sidebar tabs descriptions. * src/nautilus-window.c: (create_view_as_menu_item): Use the localized "View as" labels. * test/test-nautilus-font-manager.c: (font_iterator_callback): * test/test-nautilus-font-picker.c: (update_font), (font_changed_update_label_callback), (font_changed_update_file_name_callback), (use_defalt_font_callback), (use_defalt_bold_font_callback), (use_defalt_font_update_picker_callback), (use_defalt_bold_font_update_picker_callback), (main): * test/test.c: (test_quit): Updates for changes in font manager and font picker.
-rw-r--r--ChangeLog156
-rw-r--r--components/history/Makefile.am11
-rw-r--r--components/history/nautilus-history-view.c7
-rw-r--r--components/notes/nautilus-notes.c9
-rw-r--r--components/text/nautilus-text-view.c4
-rw-r--r--libnautilus-extensions/Makefile.am1
-rw-r--r--libnautilus-extensions/nautilus-font-factory.c24
-rw-r--r--libnautilus-extensions/nautilus-font-manager.c397
-rw-r--r--libnautilus-extensions/nautilus-font-manager.h33
-rw-r--r--libnautilus-extensions/nautilus-font-picker.c548
-rw-r--r--libnautilus-extensions/nautilus-global-preferences.c33
-rw-r--r--libnautilus-extensions/nautilus-global-preferences.h11
-rw-r--r--libnautilus-extensions/nautilus-icon-container.c16
-rw-r--r--libnautilus-extensions/nautilus-program-chooser.c4
-rw-r--r--libnautilus-extensions/nautilus-scalable-font.c806
-rw-r--r--libnautilus-extensions/nautilus-scalable-font.h27
-rw-r--r--libnautilus-extensions/nautilus-smooth-text-layout-cache.c18
-rw-r--r--libnautilus-private/Makefile.am1
-rw-r--r--libnautilus-private/nautilus-font-factory.c24
-rw-r--r--libnautilus-private/nautilus-font-manager.c397
-rw-r--r--libnautilus-private/nautilus-font-manager.h33
-rw-r--r--libnautilus-private/nautilus-font-picker.c548
-rw-r--r--libnautilus-private/nautilus-global-preferences.c33
-rw-r--r--libnautilus-private/nautilus-global-preferences.h11
-rw-r--r--libnautilus-private/nautilus-icon-container.c16
-rw-r--r--libnautilus-private/nautilus-program-chooser.c4
-rw-r--r--libnautilus-private/nautilus-scalable-font.c806
-rw-r--r--libnautilus-private/nautilus-scalable-font.h27
-rw-r--r--libnautilus-private/nautilus-smooth-text-layout-cache.c18
-rw-r--r--src/file-manager/fm-directory-view.c20
-rw-r--r--src/file-manager/fm-directory-view.h1
-rw-r--r--src/file-manager/fm-icon-view.c90
-rw-r--r--src/nautilus-about.c2
-rw-r--r--src/nautilus-information-panel.c4
-rw-r--r--src/nautilus-navigation-window.c2
-rw-r--r--src/nautilus-object-window.c2
-rw-r--r--src/nautilus-sidebar-title.c3
-rw-r--r--src/nautilus-sidebar.c4
-rw-r--r--src/nautilus-spatial-window.c2
-rw-r--r--src/nautilus-window.c2
-rw-r--r--test/test-nautilus-font-manager.c22
-rw-r--r--test/test-nautilus-font-picker.c179
-rw-r--r--test/test.c2
43 files changed, 2142 insertions, 2216 deletions
diff --git a/ChangeLog b/ChangeLog
index eb9622471..41fc0af75 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,159 @@
+2001-03-05 Ramiro Estrugo <ramiro@eazel.com>
+
+ reviewed by: Pavel Cisler <pavel@eazel.com>
+ Maciej Stachowiak <mjs@eazel.com>
+
+ Bugs:
+
+ 6368 - Multibyte font handling in non smooth mode.
+ 2673 - Need to hook up the new font picker to nautilus
+ 1274 - Add support for picking a custom font
+
+ * components/history/Makefile.am:
+ * components/history/nautilus-history-view.c: (main):
+ Initialize gettext for the history component so it can display
+ localized strings.
+
+ * components/notes/nautilus-notes.c: (make_notes_view):
+ Set the notes widget font from preferences so it can be properly
+ localized.
+
+ * components/text/nautilus-text-view.c:
+ (nautilus_text_view_set_font):
+ Use the localized font name to make this work in locales other
+ than the default.
+
+ * libnautilus-extensions/Makefile.am:
+ Add a macro for finding data on the source tree for the situation
+ when 'make install' has not be run.
+
+ * libnautilus-extensions/nautilus-font-factory.c:
+ (nautilus_font_factory_get_font_by_family): Workaround the problem
+ that fully qualified localized fonts were being processed
+ incorrectly. We simply leave them alone now.
+ (nautilus_font_factory_get_font_from_preferences): Use the
+ localized font string to make this work on more locales.
+
+ * libnautilus-extensions/nautilus-font-manager.h:
+ * libnautilus-extensions/nautilus-font-manager.c:
+ (font_description_table_find): New function to find a description
+ in a table.
+ (font_description_table_for_each): Change the return value to a
+ boolean to indicate whether to stop the iteration or not. Switch
+ the order of an assert and assigned.
+ (collect_fonts_from_directory): Use macros for the mime type
+ strings.
+ (font_ignore_directory): Add more directories to ignore.
+ (font_manager_collect_font_tables): Change prepend to append to
+ get fonts in a better order (fallback and user fonts first)
+ , (font_table_list_find),
+ (free_font_tables), (ensure_global_font_table),
+ (nautilus_font_manager_for_each_font): Use just one global table
+ for all fonts instead of 3.
+ (nautilus_font_manager_get_default_font): Compute the default
+ dynamically to take user choices into account. Make it work on
+ non installed nautilus builds.
+ (nautilus_font_manager_get_default_bold_font): Same as above for a
+ bold font.
+ (nautilus_font_manager_file_is_scalable_font): New function to
+ check that a file is really a scalable font:
+ (font_list_find_bold_callback), (nautilus_font_manager_get_bold),
+ (nautilus_font_manager_weight_is_bold): New functions to find a
+ bold font in the global tables.
+ (nautilus_self_check_font_manager): Make it work on not installed
+ nautilus builds and remove the hack where checks would on run for
+ the "ramiro" user.
+
+ * libnautilus-extensions/nautilus-font-picker.c:
+ (nautilus_font_picker_initialize), (font_list_find),
+ (font_picker_update_styles), (font_picker_populate),
+ (font_picker_font_changed_callback),
+ (font_picker_style_changed_callback), (font_find_style),
+ (ignore_font), (font_make_name), (font_make_style),
+ (global_font_list_free), (font_list_count_families),
+ (global_font_list_get), (global_font_list_populate_callback),
+ (nautilus_font_picker_get_selected_font),
+ (nautilus_font_picker_set_selected_font):
+ Make the font list global and not per widget instance. Use better
+ labels for the font styles. Use better labels for font names
+ (foundry and family vs just family depending on how many families
+ of the same font are found)
+
+ * libnautilus-extensions/nautilus-global-preferences.h:
+ * libnautilus-extensions/nautilus-global-preferences.c:
+ (global_preferences_install_font_defaults): Add new smooth font
+ preference for the icon container.
+ (nautilus_global_preferences_get_smooth_font): New function to
+ safely get a smooth font out of preferences.
+
+ * libnautilus-extensions/nautilus-icon-container.c:
+ (nautilus_icon_container_initialize): Use the localized version of
+ the font strings and add a FIXME for the problem of checking these
+ in many disparate places in nautilus.
+
+ * libnautilus-extensions/nautilus-program-chooser.c:
+ (program_file_pair_get_program_name_for_display): Use the
+ localized version of the application name strings.
+
+ * libnautilus-extensions/nautilus-scalable-font.h:
+ * libnautilus-extensions/nautilus-scalable-font.c:
+ (nautilus_scalable_font_initialize_class),
+ (nautilus_scalable_font_initialize),
+ (nautilus_scalable_font_destroy), (nautilus_scalable_font_new),
+ (nautilus_scalable_font_make_bold),
+ (nautilus_scalable_font_get_default_font),
+ (nautilus_scalable_font_get_default_bold_font),
+ (free_global_font_handle_table),
+ (initialize_global_stuff_if_needed),
+ (nautilus_scalable_font_get_rsvg_handle):
+ Simplify this class a lot by using the font manager. No longer
+ need to manage font lookup and queries.
+
+ * libnautilus-extensions/nautilus-smooth-text-layout-cache.c:
+ (nautilus_self_check_smooth_text_layout_cache): Fix a comment.
+ Dont hardcode the font family. Use the default font. Remove the
+ #ifdef hacker for "before make install fonts broken" problem which
+ is now fixed.
+
+ * src/file-manager/fm-directory-view.h:
+ * src/file-manager/fm-directory-view.c:
+ (directory_view_smooth_font_changed_callback),
+ (fm_directory_view_initialize), (fm_directory_view_destroy):
+ Add method for responding to changes in the smooth font for AA
+ mode of the icon container.
+
+ * src/file-manager/fm-icon-view.c:
+ (fm_icon_view_smooth_font_changed),
+ (fm_icon_view_initialize_class),
+ (fm_icon_view_update_icon_container_smooth_font),
+ (create_icon_container):
+ Add support for responding to change in the smooth font. Update
+ the icon container's smooth font on such changes.
+
+ * src/nautilus-about.c: (nautilus_about_draw_info):
+ Change the offset of the "Nautilus" title which broken when jsh
+ make glyphs render properly taking the baseline into account.
+
+ * src/nautilus-sidebar-title.c: (update_font):
+ Use the localized font name.
+
+ * src/nautilus-sidebar.c: (nautilus_sidebar_add_panel),
+ (nautilus_sidebar_remove_panel):
+ Use the localized sidebar tabs descriptions.
+
+ * src/nautilus-window.c: (create_view_as_menu_item):
+ Use the localized "View as" labels.
+
+ * test/test-nautilus-font-manager.c: (font_iterator_callback):
+ * test/test-nautilus-font-picker.c: (update_font),
+ (font_changed_update_label_callback),
+ (font_changed_update_file_name_callback),
+ (use_defalt_font_callback), (use_defalt_bold_font_callback),
+ (use_defalt_font_update_picker_callback),
+ (use_defalt_bold_font_update_picker_callback), (main):
+ * test/test.c: (test_quit):
+ Updates for changes in font manager and font picker.
+
2001-03-05 Dan Mueth <dan@eazel.com>
reviewed by: Ramiro Estrugo <ramiro@eazel.com>
diff --git a/components/history/Makefile.am b/components/history/Makefile.am
index 6de881019..6f9f061b8 100644
--- a/components/history/Makefile.am
+++ b/components/history/Makefile.am
@@ -2,8 +2,15 @@ NULL =
bin_PROGRAMS=nautilus-history-view
-INCLUDES=-I$(top_srcdir) -I$(top_builddir) $(GNOMEUI_CFLAGS) $(GCONF_CFLAGS) \
- $(BONOBO_CFLAGS) $(VFS_CFLAGS)
+INCLUDES=\
+ -I$(top_srcdir) \
+ -I$(top_builddir) \
+ -DGNOMELOCALEDIR=\""$(datadir)/locale"\" \
+ $(GNOMEUI_CFLAGS) \
+ $(GCONF_CFLAGS) \
+ $(BONOBO_CFLAGS) \
+ $(VFS_CFLAGS) \
+ $(NULL)
LDADD=\
$(top_builddir)/libnautilus/libnautilus.la \
diff --git a/components/history/nautilus-history-view.c b/components/history/nautilus-history-view.c
index 4a38df0ed..97967e443 100644
--- a/components/history/nautilus-history-view.c
+++ b/components/history/nautilus-history-view.c
@@ -30,6 +30,7 @@
#include <bonobo/bonobo-ui-util.h>
#include <gtk/gtkclist.h>
#include <gtk/gtkscrolledwindow.h>
+#include <gnome.h>
#include <libnautilus-extensions/nautilus-bookmark.h>
#include <libnautilus-extensions/nautilus-gdk-pixbuf-extensions.h>
#include <libnautilus-extensions/nautilus-gtk-macros.h>
@@ -293,6 +294,12 @@ nautilus_history_view_destroy (GtkObject *object)
int
main (int argc, char *argv[])
{
+/* Initialize gettext support */
+#ifdef ENABLE_NLS
+ bindtextdomain (PACKAGE, GNOMELOCALEDIR);
+ textdomain (PACKAGE);
+#endif
+
return nautilus_view_standard_main ("nautilus_history-view", VERSION,
argc, argv,
"OAFIID:nautilus_history_view_factory:912d6634-d18f-40b6-bb83-bdfe16f1d15e",
diff --git a/components/notes/nautilus-notes.c b/components/notes/nautilus-notes.c
index 501706c47..06564113b 100644
--- a/components/notes/nautilus-notes.c
+++ b/components/notes/nautilus-notes.c
@@ -37,6 +37,9 @@
#include <libnautilus-extensions/nautilus-file.h>
#include <libnautilus-extensions/nautilus-file-attributes.h>
#include <libnautilus-extensions/nautilus-metadata.h>
+#include <libnautilus-extensions/nautilus-font-factory.h>
+#include <libnautilus-extensions/nautilus-gtk-extensions.h>
+
/* FIXME bugzilla.eazel.com 4436:
* Undo not working in notes-view.
*/
@@ -182,6 +185,7 @@ make_notes_view (BonoboGenericFactory *Factory, const char *goad_id, gpointer cl
GtkWidget *vbox;
Notes *notes;
NautilusBackground *background;
+ GdkFont *font;
g_return_val_if_fail (strcmp (goad_id, "OAFIID:nautilus_notes_view:7f04c3cb-df79-4b9a-a577-38b19ccd4185") == 0, NULL);
notes = g_new0 (Notes, 1);
@@ -192,6 +196,11 @@ make_notes_view (BonoboGenericFactory *Factory, const char *goad_id, gpointer cl
/* create the text container */
notes->note_text_field = gtk_text_new (NULL, NULL);
+
+ font = nautilus_font_factory_get_font_by_family (_("helvetica"), 14);
+ nautilus_gtk_widget_set_font (notes->note_text_field, font);
+ gdk_font_unref (font);
+
gtk_text_set_editable (GTK_TEXT (notes->note_text_field), TRUE);
gtk_box_pack_start (GTK_BOX (vbox), notes->note_text_field, TRUE, TRUE, 0);
background = nautilus_get_widget_background (notes->note_text_field);
diff --git a/components/text/nautilus-text-view.c b/components/text/nautilus-text-view.c
index e5c10cf6a..03605bda7 100644
--- a/components/text/nautilus-text-view.c
+++ b/components/text/nautilus-text-view.c
@@ -507,12 +507,12 @@ handle_service_menu_item (BonoboUIComponent *ui, gpointer user_data, const char
static void
nautilus_text_view_set_font (NautilusTextView *text_view, const char *font_family)
{
- if (nautilus_strcmp (text_view->details->font_name, font_family) == 0) {
+ if (nautilus_strcmp (text_view->details->font_name, _(font_family)) == 0) {
return;
}
g_free (text_view->details->font_name);
- text_view->details->font_name = g_strdup (font_family);
+ text_view->details->font_name = g_strdup (_(font_family));
nautilus_text_view_update_font (text_view);
}
diff --git a/libnautilus-extensions/Makefile.am b/libnautilus-extensions/Makefile.am
index 9b8f4f36e..220b0b636 100644
--- a/libnautilus-extensions/Makefile.am
+++ b/libnautilus-extensions/Makefile.am
@@ -21,6 +21,7 @@ INCLUDES = \
-D_REENTRANT \
-DDATADIR=\""$(datadir)"\" \
-DNAUTILUS_DATADIR=\""$(datadir)/nautilus"\" \
+ -DSOURCE_DATADIR=\""$(top_srcdir)/data"\" \
$(NULL)
dependency_static_libs = \
diff --git a/libnautilus-extensions/nautilus-font-factory.c b/libnautilus-extensions/nautilus-font-factory.c
index 2715ae16d..042b4be30 100644
--- a/libnautilus-extensions/nautilus-font-factory.c
+++ b/libnautilus-extensions/nautilus-font-factory.c
@@ -223,13 +223,21 @@ nautilus_font_factory_get_font_by_family (const char *family,
factory = nautilus_get_current_font_factory ();
while (*iter) {
- font_name = nautilus_gdk_font_xlfd_string_new ("*",
- *iter,
- "medium",
- "r",
- "normal",
- "*",
- size_in_pixels);
+ /* FIXME bugzilla.eazel.com xxxx:
+ * Its a hack that we check for "-" prefixes in font names.
+ * We do this in order not to break transalted font families.
+ */
+ if (!nautilus_str_has_prefix (*iter, "-")) {
+ font_name = nautilus_gdk_font_xlfd_string_new ("*",
+ *iter,
+ "medium",
+ "r",
+ "normal",
+ "*",
+ size_in_pixels);
+ } else {
+ font_name = g_strdup (*iter);
+ }
g_free (*iter);
*iter = font_name;
@@ -262,7 +270,7 @@ nautilus_font_factory_get_font_from_preferences (guint size_in_pixels)
family = nautilus_preferences_get (NAUTILUS_PREFERENCES_DIRECTORY_VIEW_FONT_FAMILY);
- font = nautilus_font_factory_get_font_by_family (family, size_in_pixels);
+ font = nautilus_font_factory_get_font_by_family (_(family), size_in_pixels);
g_free (family);
diff --git a/libnautilus-extensions/nautilus-font-manager.c b/libnautilus-extensions/nautilus-font-manager.c
index fc4ac731e..e2f982121 100644
--- a/libnautilus-extensions/nautilus-font-manager.c
+++ b/libnautilus-extensions/nautilus-font-manager.c
@@ -51,11 +51,14 @@
#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 DEFAULT_FONT_DIRECTORY NAUTILUS_DATADIR "/fonts/urw"
#define USER_FONT_DIRECTORY_NAME "fonts"
#define NAUTILUS_FONT_UNDEFINED ((NautilusFontType) 0)
+#define POSTSCRIPT_FONT_MIME_TYPE "application/x-font-type1"
+#define TRUE_TYPE_FONT_MIME_TYPE "application/x-font-ttf"
+
/*
* FontDescription:
*
@@ -96,7 +99,7 @@ static FontDescription * font_description_new (const c
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,
+static gboolean font_description_table_for_each (const FontDescriptionTable *description_table,
NautilusFontManagerCallback callback,
gpointer callback_data);
static char *font_description_get_file_name (const FontDescription *description);
@@ -124,6 +127,8 @@ static char * font_description_table_get_nth_file_name (const F
guint n);
static void font_description_table_free (FontDescriptionTable *table);
static void font_description_table_clear (FontDescriptionTable *table);
+static const FontDescription * font_description_table_find (const FontDescriptionTable *description_table,
+ const char *file_name);
static gboolean
string_is_valid (const char *string)
@@ -439,35 +444,60 @@ font_description_table_clear (FontDescriptionTable *table)
table->fonts_scale_file = NULL;
}
-static void
+static const FontDescription *
+font_description_table_find (const FontDescriptionTable *table,
+ const char *file_name)
+{
+ GList *node;
+ const FontDescription *description;
+
+ g_return_val_if_fail (table != NULL, NULL);
+ g_return_val_if_fail (nautilus_strlen (file_name) > 0, NULL);
+
+ for (node = table->descriptions; node != NULL; node = node->next) {
+ g_assert (node->data != NULL);
+ description = node->data;
+
+ if (nautilus_str_is_equal (file_name, description->file_name)) {
+ return description;
+ }
+ }
+
+ return NULL;
+}
+
+static gboolean
font_description_table_for_each (const FontDescriptionTable *table,
NautilusFontManagerCallback callback,
gpointer callback_data)
{
GList *node;
const FontDescription *description;
+ gboolean cont = TRUE;
- g_return_if_fail (table != NULL);
- g_return_if_fail (callback != NULL);
+ g_return_val_if_fail (table != NULL, TRUE);
+ g_return_val_if_fail (callback != NULL, TRUE);
node = table->descriptions;
while (node != NULL) {
- description = node->data;
g_assert (node->data != NULL);
-
- (* callback) (description->file_name,
- description->font_type,
- description->foundry,
- description->family,
- description->weight,
- description->slant,
- description->set_width,
- description->char_set_registry,
- description->char_set_encoding,
- callback_data);
+ description = node->data;
- node = node->next;
+ cont = (* callback) (description->file_name,
+ description->font_type,
+ description->foundry,
+ description->family,
+ description->weight,
+ description->slant,
+ description->set_width,
+ description->char_set_registry,
+ description->char_set_encoding,
+ callback_data);
+
+ node = cont ? node->next : NULL;
}
+
+ return cont;
}
static FontDescriptionTable *
@@ -563,28 +593,30 @@ collect_fonts_from_directory (const char *font_directory,
g_return_val_if_fail (true_type_font_list != NULL, GNOME_VFS_ERROR_BAD_PARAMETERS);
directory_uri = g_strconcat ("file://", font_directory, NULL);
-
+
*postscript_font_list = NULL;
*true_type_font_list = NULL;
result = gnome_vfs_directory_open (&directory,
- directory_uri, GNOME_VFS_FILE_INFO_GET_MIME_TYPE, NULL);
+ directory_uri,
+ GNOME_VFS_FILE_INFO_GET_MIME_TYPE,
+ NULL);
g_free (directory_uri);
if (result != GNOME_VFS_OK) {
return result;
}
-
+
while (TRUE) {
info = gnome_vfs_file_info_new ();
result = gnome_vfs_directory_read_next (directory, info);
if (result == GNOME_VFS_OK) {
- if (strcasecmp (info->mime_type, "application/x-font-type1") == 0) {
+ if (strcasecmp (info->mime_type, POSTSCRIPT_FONT_MIME_TYPE) == 0) {
*postscript_font_list = g_list_prepend (*postscript_font_list,
g_strconcat (font_directory,
"/", info->name, NULL));
- } else if (strcasecmp (info->mime_type, "application/x-font-ttf") == 0) {
+ } else if (strcasecmp (info->mime_type, TRUE_TYPE_FONT_MIME_TYPE) == 0) {
*true_type_font_list = g_list_prepend (*true_type_font_list,
g_strconcat (font_directory,
"/", info->name, NULL));
@@ -826,30 +858,31 @@ directory_contains_file (const char *directory,
return result;
}
-/* Iterating directories is slow cause of all the mim sniffing that
+/* Iterating directories is slow cause of all the mime sniffing that
* has to happen on each potential scalalble font. By Ignoring
- * directories known to be without scalable fonts, we make things
- * much faster.
+ * directories that arent interesting, we make things much faster.
*/
static gboolean
font_ignore_directory (const char *font_directory)
{
- g_return_val_if_fail (string_is_valid (font_directory), TRUE);
-
- if (nautilus_str_has_suffix (font_directory, "unscaled")) {
- return TRUE;
- }
-
- if (nautilus_str_has_suffix (font_directory, "100dpi")) {
- return TRUE;
- }
+ guint i;
+
+ static const char *ignored_font_dir_suffices[] = {
+ "unscaled",
+ "100dpi",
+ "75dpi",
+ "misc",
+ "abisource/fonts",
+ "fonts/Speedo",
+ "fonts/cyrillic"
+ };
- if (nautilus_str_has_suffix (font_directory, "75dpi")) {
- return TRUE;
- }
+ g_return_val_if_fail (string_is_valid (font_directory), TRUE);
- if (nautilus_str_has_suffix (font_directory, "misc")) {
- return TRUE;
+ for (i = 0; i < NAUTILUS_N_ELEMENTS (ignored_font_dir_suffices); i++) {
+ if (nautilus_str_has_suffix (font_directory, ignored_font_dir_suffices[i])) {
+ return TRUE;
+ }
}
return FALSE;
@@ -857,7 +890,7 @@ font_ignore_directory (const char *font_directory)
static void
font_manager_collect_font_tables (const char *font_directory,
- GList **collected_font_tables)
+ GList **collected_font_tables)
{
GList *postscript_font_list = NULL;
GList *true_type_font_list = NULL;
@@ -897,7 +930,7 @@ font_manager_collect_font_tables (const char *font_directory,
return;
}
- *collected_font_tables = g_list_prepend (*collected_font_tables, table);
+ *collected_font_tables = g_list_append (*collected_font_tables, table);
nautilus_g_list_free_deep (postscript_font_list);
nautilus_g_list_free_deep (true_type_font_list);
@@ -913,9 +946,7 @@ font_server_for_each_callback (const char *font_directory,
font_manager_collect_font_tables (font_directory, callback_data);
}
-static GList *fallback_font_table = NULL;
-static GList *user_font_table = NULL;
-static GList *system_font_table = NULL;
+static GList *global_font_table = NULL;
static void
font_table_list_free (GList *font_table_list)
@@ -931,126 +962,247 @@ font_table_list_free (GList *font_table_list)
g_list_free (font_table_list);
}
-static void
-font_table_list_for_each (GList *font_table_list,
- NautilusFontManagerCallback callback,
- gpointer callback_data)
+static const FontDescription *
+font_table_list_find (const GList *font_table_list,
+ const char *file_name)
{
- GList *node;
+ const GList *node;
+ const FontDescription *description;
- g_return_if_fail (callback != NULL);
+ g_return_val_if_fail (file_name != NULL, NULL);
- node = font_table_list;
- while (node != NULL) {
+ for (node = font_table_list; node != NULL; node = node->next) {
g_assert (node->data != NULL);
- font_description_table_for_each (node->data, callback, callback_data);
- node = node->next;
+ description = font_description_table_find (node->data, file_name);
+ if (description != NULL) {
+ return description;
+ }
}
+
+ return NULL;
}
static void
free_font_tables (void)
{
- font_table_list_free (fallback_font_table);
- fallback_font_table = NULL;
+ font_table_list_free (global_font_table);
+ global_font_table = NULL;
+}
- font_table_list_free (user_font_table);
- user_font_table = NULL;
+static void
+ensure_global_font_table (void)
+{
+ char *user_directory;
+ char *user_font_dir;
- font_table_list_free (system_font_table);
- system_font_table = NULL;
+ if (global_font_table != NULL) {
+ return;
+ }
+
+ /* Populate the default font table if needed */
+ font_manager_collect_font_tables (DEFAULT_FONT_DIRECTORY, &global_font_table);
+
+ /* Populate the user font table if needed */
+ 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, &global_font_table);
+ }
+ g_free (user_directory);
+ g_free (user_font_dir);
+
+ /* Populate the system font table if needed - using the font server's configuration */
+ if (g_file_exists (FONT_SERVER_CONFIG_FILE)) {
+ font_server_for_each_font_directory (FONT_SERVER_CONFIG_FILE,
+ font_server_for_each_callback,
+ &global_font_table);
+ }
+
+ g_atexit (free_font_tables);
}
-static gboolean at_exit_handler_installed = FALSE;
+/* Public */
-static void
-ensure_at_exit_handler (void)
+/**
+ * nautilus_font_manager_for_each_font:
+ * @callback: A callback to be called for each scalable font in the system.
+ * @callback_data: User's data.
+ *
+ * Iterate all the scalable fonts available in the system. The available
+ * fonts are the sum of:
+ *
+ * 1) Fallback fonts installed by Nautilus
+ * 2) User fonts found in ~/.nautilus/fonts
+ * 3) Fonts listed in the font servers config file (/etc/X11/fs/config)
+ *
+ */
+void
+nautilus_font_manager_for_each_font (NautilusFontManagerCallback callback,
+ gpointer callback_data)
{
- if (!at_exit_handler_installed) {
- at_exit_handler_installed = TRUE;
- g_atexit (free_font_tables);
+ GList *node;
+ gboolean cont = TRUE;
+
+ g_return_if_fail (callback != NULL);
+
+ /* Ensure that all the font tables exist */
+ ensure_global_font_table ();
+
+ for (node = global_font_table; node != NULL && cont; node = node->next) {
+ g_assert (node->data != NULL);
+ cont = font_description_table_for_each (node->data, callback, callback_data);
}
}
-static void
-ensure_fallback_font_table (void)
+char *
+nautilus_font_manager_get_default_font (void)
{
- /* Populate the fallback font table if needed */
- if (fallback_font_table == NULL) {
- font_manager_collect_font_tables (FALLBACK_FONT_DIRECTORY, &fallback_font_table);
+ guint i;
+
+ static const char *default_fonts[] = {
+ DEFAULT_FONT_DIRECTORY "/n019003l.pfb",
+ SOURCE_DATADIR "/fonts/urw/n019003l.pfb",
+ "/usr/share/fonts/default/Type1/n019003l.pfb",
+ "/usr/X11R6/lib/X11/fonts/Type1/lcdxsr.pfa"
+ };
+
+ for (i = 0; i < NAUTILUS_N_ELEMENTS (default_fonts); i++) {
+ if (g_file_exists (default_fonts[i])) {
+ return g_strdup (default_fonts[i]);
+ }
}
- ensure_at_exit_handler ();
+ return NULL;
}
-static void
-ensure_user_font_table (void)
+char *
+nautilus_font_manager_get_default_bold_font (void)
{
- char *user_directory;
- char *user_font_dir;
+ guint i;
- /* 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);
+ static const char *default_bold_fonts[] = {
+ DEFAULT_FONT_DIRECTORY "/n019004l.pfb",
+ SOURCE_DATADIR "/fonts/urw/n019004l.pfb",
+ };
+
+ for (i = 0; i < NAUTILUS_N_ELEMENTS (default_bold_fonts); i++) {
+ if (g_file_exists (default_bold_fonts[i])) {
+ return g_strdup (default_bold_fonts[i]);
}
- g_free (user_directory);
- g_free (user_font_dir);
}
- ensure_at_exit_handler ();
+ return NULL;
}
-static void
-ensure_system_font_tables (void)
+gboolean
+nautilus_font_manager_file_is_scalable_font (const char *file_name)
{
- /* 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);
- }
+ gboolean is_scalable_font = FALSE;
+ char *uri;
+ GnomeVFSFileInfo *info;
+ GnomeVFSResult result;
+
+ g_return_val_if_fail (nautilus_strlen (file_name) > 0, FALSE);
+
+ uri = g_strconcat ("file://", file_name, NULL);
+
+ info = gnome_vfs_file_info_new ();
+ result = gnome_vfs_get_file_info (uri, info, GNOME_VFS_FILE_INFO_GET_MIME_TYPE);
+
+ if (result == GNOME_VFS_OK) {
+ is_scalable_font =
+ nautilus_istr_is_equal (info->mime_type, POSTSCRIPT_FONT_MIME_TYPE)
+ || nautilus_istr_is_equal (info->mime_type, TRUE_TYPE_FONT_MIME_TYPE);
}
- ensure_at_exit_handler ();
+ gnome_vfs_file_info_unref (info);
+ g_free (uri);
+
+ return is_scalable_font;
}
-/* Public */
-void
-nautilus_font_manager_for_each_font (NautilusFontManagerCallback callback,
- gpointer callback_data)
+typedef struct
{
- g_return_if_fail (callback != NULL);
+ const FontDescription *description;
+ char *found_file_name;
+} FindData;
- /* Ensure that all the font tables exist */
- ensure_fallback_font_table ();
- ensure_user_font_table ();
- ensure_system_font_tables ();
+static gboolean
+font_list_find_bold_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)
+{
+ FindData *data;
+
+ g_return_val_if_fail (font_file_name != NULL, FALSE);
+ g_return_val_if_fail (foundry != NULL, FALSE);
+ g_return_val_if_fail (family != NULL, FALSE);
+ g_return_val_if_fail (weight != NULL, FALSE);
+ g_return_val_if_fail (slant != NULL, FALSE);
+ g_return_val_if_fail (set_width != NULL, FALSE);
+ g_return_val_if_fail (char_set_registry != NULL, FALSE);
+ g_return_val_if_fail (char_set_encoding != NULL, FALSE);
+ g_return_val_if_fail (callback_data != NULL, FALSE);
+
+ data = callback_data;
+
+ g_return_val_if_fail (data->description != NULL, FALSE);
+ g_return_val_if_fail (data->found_file_name == NULL, FALSE);
+
+ if (nautilus_istr_is_equal (data->description->foundry, foundry)
+ && nautilus_istr_is_equal (data->description->family, family)
+ && nautilus_istr_is_equal (data->description->slant, slant)
+ && nautilus_istr_is_equal (data->description->set_width, set_width)
+ && nautilus_istr_is_equal (data->description->char_set_registry, char_set_registry)
+ && nautilus_istr_is_equal (data->description->char_set_encoding, char_set_encoding)
+ && nautilus_font_manager_weight_is_bold (weight)) {
+ data->found_file_name = g_strdup (font_file_name);
+ }
- 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);
+ return (data->found_file_name == NULL);
}
char *
-nautilus_font_manager_get_fallback_font (void)
+nautilus_font_manager_get_bold (const char *plain_font)
{
-#if 0
- const FontDescriptionTable *table;
+ FindData data;
- ensure_fallback_font_table ();
- g_return_val_if_fail (g_list_length (fallback_font_table) > 0, NULL);
+ g_return_val_if_fail (nautilus_strlen (plain_font) > 0, NULL);
+ g_return_val_if_fail (nautilus_font_manager_file_is_scalable_font (plain_font), NULL);
- table = g_list_nth_data (fallback_font_table, 0);
- g_return_val_if_fail (table != NULL, NULL);
+ ensure_global_font_table ();
- return font_description_table_get_nth_file_name (table, 0);
-#else
- return g_strdup ("/usr/share/fonts/default/Type1/n019003l.pfb");
-#endif
+ data.description = font_table_list_find (global_font_table, plain_font);
+
+ if (data.description == NULL) {
+ return g_strdup (plain_font);
+ }
+
+ data.found_file_name = NULL;
+ nautilus_font_manager_for_each_font (font_list_find_bold_callback, &data);
+
+ if (data.found_file_name != NULL) {
+ return data.found_file_name;
+ }
+
+ return g_strdup (plain_font);
+}
+
+gboolean
+nautilus_font_manager_weight_is_bold (const char *weight)
+{
+ g_return_val_if_fail (weight != NULL, FALSE);
+
+ return (nautilus_istr_is_equal (weight, "bold")
+ || nautilus_istr_is_equal (weight, "demibold")
+ || nautilus_istr_is_equal (weight, "black"));
}
#if !defined (NAUTILUS_OMIT_SELF_CHECK)
@@ -1082,14 +1234,11 @@ nautilus_self_check_font_manager (void)
NAUTILUS_CHECK_STRING_RESULT (call_chop_off_comments ("\\#foo bar"), "\\#foo bar");
NAUTILUS_CHECK_STRING_RESULT (call_chop_off_comments ("\\##foo bar"), "\\#");
- /* 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)) {
+ if (!g_file_exists (TEST_FONT_DIR)) {
return;
}
- font_manager_collect_font_tables ("/usr/share/fonts/default/Type1", &font_table_list);
+ font_manager_collect_font_tables (TEST_FONT_DIR, &font_table_list);
g_return_if_fail (font_table_list != NULL);
g_return_if_fail (g_list_nth_data (font_table_list, 0) != NULL);
diff --git a/libnautilus-extensions/nautilus-font-manager.h b/libnautilus-extensions/nautilus-font-manager.h
index 9c168ef5c..ce8213bc5 100644
--- a/libnautilus-extensions/nautilus-font-manager.h
+++ b/libnautilus-extensions/nautilus-font-manager.h
@@ -39,20 +39,25 @@ typedef enum {
/*
* A callback which can be invoked for each font available in the system.
*/
-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);
+typedef gboolean (*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_default_font (void);
+char * nautilus_font_manager_get_default_bold_font (void);
+gboolean nautilus_font_manager_file_is_scalable_font (const char *file_name);
+char * nautilus_font_manager_get_bold (const char *plain_font);
+char * nautilus_font_manager_get_italic (const char *plain_font);
+gboolean nautilus_font_manager_weight_is_bold (const char *weight);
END_GNOME_DECLS
diff --git a/libnautilus-extensions/nautilus-font-picker.c b/libnautilus-extensions/nautilus-font-picker.c
index ef6264540..bf520ea4a 100644
--- a/libnautilus-extensions/nautilus-font-picker.c
+++ b/libnautilus-extensions/nautilus-font-picker.c
@@ -32,6 +32,8 @@
#include "nautilus-string.h"
#include "nautilus-font-manager.h"
+#include <libgnome/gnome-i18n.h>
+
#include <gtk/gtklabel.h>
#include <gtk/gtkentry.h>
#include <gtk/gtksignal.h>
@@ -43,27 +45,83 @@
typedef struct {
char *name;
char *font_file_name;
-} FontStyle;
+} FontStyleEntry;
typedef struct {
- char *title;
- char *foundry;
- char *family;
char *name;
+ char *family;
+ char *name_for_display;
GList *style_list;
} FontEntry;
-static const char *black_listed_fonts[] = {
- "microsoft Webdings",
- "microsoft Wingdings",
- "monotype OCR",
- "URW Zapf Dingbats",
- "URW Symbol",
- "xfree86 cursor"
+/* These font families are black listed, because they
+ * arent useful at all to display "normal" text - at
+ * least in the context of Nautilus.
+ */
+static const char *black_listed_font_families[] = {
+ "Webdings",
+ "Wingdings",
+ "OCR",
+ "Zapf Dingbats",
+ "Symbol",
+ "cursor",
+
+ "mincho",
+ "gothic"
+};
+
+static const char *black_listed_font_foundries[] = {
+ "greek",
+ "grinet",
+ /* Abisource fonts are black listed because they
+ * appear to simply be copies of the URW fonts,
+ * and listing them would waste valuable font picker
+ * space for no purpose.
+ */
+ "Abisource"
+};
+
+typedef struct
+{
+ const char *name;
+ const char *mapped;
+} StyleMap;
+
+static const char *normal_style = N_("Normal");
+static const char *unknown_style = N_("Unknown");
+
+static const StyleMap font_weight_map[] = {
+ { "", NULL },
+ { "medium", NULL },
+ { "regular", NULL },
+ { "bold", N_("Bold") },
+ { "book", N_("Book") },
+ { "black", N_("Black") },
+ { "demibold", N_("Demibold") },
+ { "light", N_("Light") }
+};
+
+static const StyleMap font_slant_map[] = {
+ { "", NULL },
+ { "r", NULL },
+ { "i", N_("Italic"), },
+ { "o", N_("Oblique"), },
+ { "ri", N_("Reverse Italic"), },
+ { "ro", N_("Reverse Oblique"), },
+ { "ot", N_("Other"), }
+};
+
+static const StyleMap font_set_width_map[] = {
+ { "", NULL },
+ { "normal", NULL },
+ { "condensed", N_("Condensed"), },
+ { "semicondensed", N_("Semicondensed"), }
};
static const gint FONT_PICKER_SPACING = 10;
+static GList *global_font_list = NULL;
+
/* Signals */
typedef enum
{
@@ -75,35 +133,37 @@ struct NautilusFontPickerDetails
{
NautilusStringPicker *font_name_picker;
NautilusStringPicker *style_picker;
- GList *font_entry_list;
GtkWidget *title_label;
};
/* 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 font_picker_update (NautilusFontPicker *font_picker);
+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);
+
+/* Private methods */
+static void font_picker_update_styles (NautilusFontPicker *font_picker);
+static void font_picker_populate (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);
+static void font_picker_font_changed_callback (GtkWidget *string_picker,
+ gpointer callback_data);
+static void font_picker_style_changed_callback (GtkWidget *string_picker,
+ gpointer callback_data);
+
+/* Global font list */
+static const GList *global_font_list_get (void);
+static void global_font_list_free (void);
+static gboolean global_font_list_populate_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);
NAUTILUS_DEFINE_CLASS_BOILERPLATE (NautilusFontPicker, nautilus_font_picker, GTK_TYPE_VBOX)
@@ -163,12 +223,12 @@ nautilus_font_picker_initialize (NautilusFontPicker *font_picker)
gtk_signal_connect (GTK_OBJECT (font_picker->details->font_name_picker),
"changed",
- GTK_SIGNAL_FUNC (font_name_picker_changed_callback),
+ GTK_SIGNAL_FUNC (font_picker_font_changed_callback),
font_picker);
gtk_signal_connect (GTK_OBJECT (font_picker->details->style_picker),
"changed",
- GTK_SIGNAL_FUNC (style_picker_changed_callback),
+ GTK_SIGNAL_FUNC (font_picker_style_changed_callback),
font_picker);
gtk_widget_show (GTK_WIDGET (font_picker->details->font_name_picker));
@@ -176,14 +236,7 @@ nautilus_font_picker_initialize (NautilusFontPicker *font_picker)
gtk_widget_show (font_picker->details->title_label);
gtk_widget_show (hbox);
- /* Populate the font table */
- nautilus_font_manager_for_each_font (font_manager_callback, font_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);
-
- /* Update the font picker */
- font_picker_update (font_picker);;
+ font_picker_populate (font_picker);
}
/* GtkObjectClass methods */
@@ -203,45 +256,95 @@ nautilus_font_picker_destroy (GtkObject* object)
}
static FontEntry *
-font_entry_list_find (GList *font_entry_list,
- const char *font_name)
+font_list_find (const GList *font_list,
+ const char *font_name)
{
- while (font_entry_list != NULL) {
- FontEntry *entry;
- g_assert (font_entry_list->data != NULL);
- entry = font_entry_list->data;
+ const GList *node;
+ FontEntry *entry;
+
+ /* First check the foundry qualified font names */
+ for (node = font_list; node != NULL; node = node->next) {
+ g_assert (node->data != NULL);
+ entry = node->data;
+
if (nautilus_istr_is_equal (font_name, entry->name)) {
return entry;
}
-
- font_entry_list = font_entry_list->next;
}
-
+
+ /* First check the foundry qualified font names */
+ for (node = font_list; node != NULL; node = node->next) {
+ g_assert (node->data != NULL);
+ entry = node->data;
+
+ if (nautilus_istr_is_equal (font_name, entry->family)) {
+ return entry;
+ }
+ }
+
return NULL;
}
static void
-font_picker_update (NautilusFontPicker *font_picker)
+font_picker_update_styles (NautilusFontPicker *font_picker)
{
+ const GList *font_list;
char *selected_font;
- const FontEntry *entry;
-
+ const FontEntry *font_entry;
+ const FontStyleEntry *style_entry;
+ const GList *node;
+
g_return_if_fail (NAUTILUS_IS_FONT_PICKER (font_picker));
selected_font = nautilus_string_picker_get_selected_string (font_picker->details->font_name_picker);
- entry = font_entry_list_find (font_picker->details->font_entry_list, selected_font);
- g_return_if_fail (entry != NULL);
+ font_list = global_font_list_get ();
+ g_assert (font_list != NULL);
+
+ font_entry = font_list_find (font_list, selected_font);
+ g_return_if_fail (font_entry != NULL);
nautilus_string_picker_clear (font_picker->details->style_picker);
-
- g_list_foreach (entry->style_list, style_list_for_each_callback, font_picker);
-
+
+ for (node = font_entry->style_list; node != NULL; node = node->next) {
+ g_assert (node->data != NULL);
+ style_entry = node->data;
+ nautilus_string_picker_insert_string (font_picker->details->style_picker,
+ style_entry->name);
+ }
+
g_free (selected_font);
}
static void
-font_name_picker_changed_callback (GtkWidget *string_picker,
+font_picker_populate (NautilusFontPicker *font_picker)
+{
+ const GList *font_list;
+ const GList *node;
+ const FontEntry *font_entry;
+
+ g_return_if_fail (NAUTILUS_IS_FONT_PICKER (font_picker));
+
+ font_list = global_font_list_get ();
+ g_assert (font_list != NULL);
+
+ nautilus_string_picker_clear (font_picker->details->font_name_picker);
+
+ for (node = font_list; node != NULL; node = node->next) {
+ g_assert (node->data != NULL);
+ font_entry = node->data;
+
+ nautilus_string_picker_insert_string (font_picker->details->font_name_picker,
+ font_entry->name_for_display);
+ }
+
+ /* Update the styles picker */
+ font_picker_update_styles (font_picker);;
+}
+
+/* Callbacks */
+static void
+font_picker_font_changed_callback (GtkWidget *string_picker,
gpointer callback_data)
{
NautilusFontPicker *font_picker;
@@ -251,16 +354,16 @@ font_name_picker_changed_callback (GtkWidget *string_picker,
font_picker = NAUTILUS_FONT_PICKER (callback_data);
- font_picker_update (font_picker);
+ font_picker_update_styles (font_picker);
gtk_signal_emit (GTK_OBJECT (font_picker), font_picker_signals[CHANGED]);
}
static void
-style_picker_changed_callback (GtkWidget *string_picker, gpointer callback_data)
+font_picker_style_changed_callback (GtkWidget *string_picker, gpointer callback_data)
{
- NautilusFontPicker *font_picker;
-
+ NautilusFontPicker *font_picker;
+
g_return_if_fail (NAUTILUS_IS_FONT_PICKER (callback_data));
g_return_if_fail (NAUTILUS_IS_STRING_PICKER (string_picker));
@@ -269,21 +372,43 @@ style_picker_changed_callback (GtkWidget *string_picker, gpointer callback_data)
gtk_signal_emit (GTK_OBJECT (font_picker), font_picker_signals[CHANGED]);
}
+static const char *
+font_find_style (const StyleMap *style_map,
+ guint num_styles,
+ const char *style)
+{
+ guint i;
+
+ g_return_val_if_fail (style_map != NULL, NULL);
+ g_return_val_if_fail (num_styles > 0, NULL);
+ g_return_val_if_fail (style != NULL, NULL);
+
+ for (i = 0; i < num_styles; i++) {
+ if (nautilus_istr_is_equal (style, style_map[i].name)) {
+ return _(style_map[i].mapped);
+ }
+ }
+
+ return NULL;
+}
+
static gboolean
-ignore_font (const char *font_file_name,
- const char *foundry,
- const char *family,
- const char *entry_name)
+ignore_font (const char *foundry,
+ const char *family)
{
guint 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);
- for (i = 0; i < NAUTILUS_N_ELEMENTS (black_listed_fonts); i++) {
- if (nautilus_istr_is_equal (entry_name, black_listed_fonts[i])) {
+ for (i = 0; i < NAUTILUS_N_ELEMENTS (black_listed_font_families); i++) {
+ if (nautilus_istr_is_equal (family, black_listed_font_families[i])) {
+ return TRUE;
+ }
+ }
+
+ for (i = 0; i < NAUTILUS_N_ELEMENTS (black_listed_font_foundries); i++) {
+ if (nautilus_istr_is_equal (foundry, black_listed_font_foundries[i])) {
return TRUE;
}
}
@@ -291,92 +416,215 @@ ignore_font (const char *font_file_name,
return FALSE;
}
-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 char *
+font_make_name (const char *foundry,
+ const char *family)
{
- NautilusFontPicker *font_picker;
- char *entry_name;
- FontEntry *entry;
- FontStyle *style;
-
- 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));
+ g_return_val_if_fail (foundry != NULL, NULL);
+ g_return_val_if_fail (family != NULL, NULL);
+
+ return g_strdup_printf ("%s %s", foundry, family);
+}
- font_picker = NAUTILUS_FONT_PICKER (callback_data);
+static char *
+font_make_style (const char *weight,
+ const char *slant,
+ const char *set_width,
+ const char *char_set_registry,
+ const char *char_set_encoding)
+{
+ const char *mapped_weight;
+ const char *mapped_slant;
+ const char *mapped_set_width;
+
+ g_return_val_if_fail (weight != NULL, NULL);
+ g_return_val_if_fail (slant != NULL, NULL);
+ g_return_val_if_fail (set_width != NULL, NULL);
+ g_return_val_if_fail (char_set_registry != NULL, NULL);
+ g_return_val_if_fail (char_set_encoding != NULL, NULL);
+
+ mapped_weight = font_find_style (font_weight_map,
+ NAUTILUS_N_ELEMENTS (font_weight_map),
+ weight);
+
+ mapped_slant = font_find_style (font_slant_map,
+ NAUTILUS_N_ELEMENTS (font_slant_map),
+ slant);
+
+ mapped_set_width = font_find_style (font_set_width_map,
+ NAUTILUS_N_ELEMENTS (font_set_width_map),
+ set_width);
+
+ if (mapped_weight != NULL) {
+ /* "abnormal" weight */
+ if (mapped_slant == NULL && mapped_set_width == NULL) {
+ return g_strdup (mapped_weight);
+ } else if (mapped_slant != NULL && mapped_set_width != NULL) {
+ return g_strdup_printf ("%s %s %s", mapped_weight, mapped_slant, mapped_set_width);
+ } else if (mapped_slant != NULL) {
+ return g_strdup_printf ("%s %s", mapped_weight, mapped_slant);
+ }
- entry_name = g_strdup_printf ("%s %s", foundry, family);
+ return g_strdup_printf ("%s %s", mapped_weight, mapped_set_width);
+ } else {
+ /* normal weight */
+ if (mapped_slant == NULL && mapped_set_width == NULL) {
+ return g_strdup (_(normal_style));
+ } else if (mapped_slant != NULL && mapped_set_width != NULL) {
+ return g_strdup_printf ("%s %s", mapped_slant, mapped_set_width);
+ } else if (mapped_slant != NULL) {
+ return g_strdup_printf ("%s", mapped_slant);
+ }
+
+ return g_strdup_printf ("%s", mapped_set_width);
+ }
+
+ return g_strdup (_(unknown_style));
+}
- if (ignore_font (font_file_name, foundry, family, entry_name)) {
- g_free (entry_name);
+/* Global font list */
+static void
+global_font_list_free (void)
+{
+ GList *font_node;
+ FontEntry *font_entry;
+ GList *style_node;
+ FontStyleEntry *style_entry;
+
+ if (global_font_list == NULL) {
return;
}
- entry = font_entry_list_find (font_picker->details->font_entry_list, entry_name);
+ for (font_node = global_font_list; font_node != NULL; font_node = font_node->next) {
+ g_assert (font_node->data != NULL);
+ font_entry = font_node->data;
+
+ g_free (font_entry->name);
+ g_free (font_entry->family);
+ g_free (font_entry->name_for_display);
+
+ for (style_node = font_entry->style_list; style_node != NULL; style_node = style_node->next) {
+ g_assert (style_node->data != NULL);
+ style_entry = style_node->data;
+ g_free (style_entry->name);
+ g_free (style_entry->font_file_name);
+ g_free (style_entry);
+ }
+ g_list_free (font_entry->style_list);
- 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_free (font_entry);
}
- g_assert (entry != NULL);
- g_assert (font_entry_list_find (font_picker->details->font_entry_list, entry_name) == entry);
- g_free (entry_name);
+
+ global_font_list = NULL;
+}
+
+static guint
+font_list_count_families (const GList *font_list,
+ const char *family)
+{
+ guint count = 0;
+ const GList *node;
+ const FontEntry *entry;
+
+ g_return_val_if_fail (font_list != NULL, 0);
+ g_return_val_if_fail (family != NULL, 0);
- 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);
+ for (node = font_list; node != NULL; node = node->next) {
+ g_assert (node->data != NULL);
+ entry = node->data;
- entry->style_list = g_list_append (entry->style_list, style);
+ if (nautilus_istr_is_equal (family, entry->family)) {
+ count++;
+ }
+ }
+
+ return count;
}
-static void
-style_list_for_each_callback (gpointer data,
- gpointer callback_data)
+static const GList *
+global_font_list_get (void)
{
- NautilusFontPicker *font_picker;
- FontStyle *style;
+ guint family_count = 0;
+ GList *node;
+ FontEntry *entry;
- g_return_if_fail (data != NULL);
- g_return_if_fail (NAUTILUS_IS_FONT_PICKER (callback_data));
+ if (global_font_list != NULL) {
+ return global_font_list;
+ }
- style = data;
- font_picker = NAUTILUS_FONT_PICKER (callback_data);
+ nautilus_font_manager_for_each_font (global_font_list_populate_callback, &global_font_list);
+ g_assert (global_font_list != NULL);
+
+ for (node = global_font_list; node != NULL; node = node->next) {
+ g_assert (node->data != NULL);
+ entry = node->data;
+
+ g_assert (entry->name_for_display == NULL);
+
+ family_count = font_list_count_families (global_font_list, entry->family);
+ g_assert (family_count > 0);
+
+ entry->name_for_display = (family_count > 1) ? g_strdup (entry->name) : g_strdup (entry->family);
+ }
- nautilus_string_picker_insert_string (font_picker->details->style_picker, style->name);
+ g_atexit (global_font_list_free);
+
+ return global_font_list;
}
-static void
-font_entry_list_for_each_callback (gpointer data,
- gpointer callback_data)
+
+static gboolean
+global_font_list_populate_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;
+ GList **font_list;
+ char *entry_name;
FontEntry *entry;
+ FontStyleEntry *style;
+
+ g_return_val_if_fail (font_file_name != NULL, FALSE);
+ g_return_val_if_fail (foundry != NULL, FALSE);
+ g_return_val_if_fail (family != NULL, FALSE);
+ g_return_val_if_fail (weight != NULL, FALSE);
+ g_return_val_if_fail (slant != NULL, FALSE);
+ g_return_val_if_fail (set_width != NULL, FALSE);
+ g_return_val_if_fail (char_set_registry != NULL, FALSE);
+ g_return_val_if_fail (char_set_encoding != NULL, FALSE);
+ g_return_val_if_fail (callback_data != NULL, FALSE);
+
+ font_list = callback_data;
+
+ if (ignore_font (foundry, family)) {
+ return TRUE;
+ }
- g_return_if_fail (data != NULL);
- g_return_if_fail (NAUTILUS_IS_FONT_PICKER (callback_data));
+ entry_name = font_make_name (foundry, family);
+ entry = font_list_find (*font_list, entry_name);
- font_picker = NAUTILUS_FONT_PICKER (callback_data);
+ if (entry == NULL) {
+ entry = g_new0 (FontEntry, 1);
+ entry->name = g_strdup (entry_name);
+ entry->family = g_strdup (family);
+ *font_list = g_list_append (*font_list, entry);
+ }
+ g_assert (entry != NULL);
+ g_assert (font_list_find (*font_list, entry_name) == entry);
+ g_free (entry_name);
- entry = data;
- nautilus_string_picker_insert_string (font_picker->details->font_name_picker,
- entry->name);
+ style = g_new0 (FontStyleEntry, 1);
+ style->name = font_make_style (weight, slant, set_width, char_set_registry, char_set_encoding);
+ style->font_file_name = g_strdup (font_file_name);
+
+ entry->style_list = g_list_append (entry->style_list, style);
+
+ return TRUE;
}
/* NautilusFontPicker public methods */
@@ -389,13 +637,17 @@ nautilus_font_picker_new (void)
char *
nautilus_font_picker_get_selected_font (const NautilusFontPicker *font_picker)
{
+ const GList *font_list;
char *result = NULL;
char *selected_font;
char *selected_style;
const FontEntry *entry;
- GList *node;
+ const GList *node;
g_return_val_if_fail (NAUTILUS_IS_FONT_PICKER (font_picker), NULL);
+
+ font_list = global_font_list_get ();
+ g_assert (font_list != NULL);
selected_font = nautilus_string_picker_get_selected_string (font_picker->details->font_name_picker);
g_return_val_if_fail (selected_font != NULL, NULL);
@@ -403,12 +655,12 @@ nautilus_font_picker_get_selected_font (const NautilusFontPicker *font_picker)
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);
+ entry = font_list_find (font_list, selected_font);
g_return_val_if_fail (entry != NULL, NULL);
node = entry->style_list;
while (node != NULL && result == NULL) {
- const FontStyle *style;
+ const FontStyleEntry *style;
g_assert (node->data != NULL);
style = node->data;
@@ -428,14 +680,18 @@ void
nautilus_font_picker_set_selected_font (NautilusFontPicker *font_picker,
const char *font_name)
{
+ const GList *font_list;
const FontEntry *entry;
- const FontStyle *style;
- GList *font_list_node;
- GList *style_list_node;
+ const FontStyleEntry *style;
+ const GList *font_list_node;
+ const GList *style_list_node;
g_return_if_fail (NAUTILUS_IS_FONT_PICKER (font_picker));
+
+ font_list = global_font_list_get ();
+ g_assert (font_list != NULL);
- font_list_node = font_picker->details->font_entry_list;
+ font_list_node = font_list;
while (font_list_node != NULL) {
g_assert (font_list_node->data != NULL);
entry = font_list_node->data;
@@ -447,8 +703,8 @@ nautilus_font_picker_set_selected_font (NautilusFontPicker *font_picker,
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);
+ entry->name_for_display);
+ font_picker_update_styles (font_picker);
gtk_signal_emit (GTK_OBJECT (font_picker), font_picker_signals[CHANGED]);
return;
}
diff --git a/libnautilus-extensions/nautilus-global-preferences.c b/libnautilus-extensions/nautilus-global-preferences.c
index 1ca75b872..18e7f89b0 100644
--- a/libnautilus-extensions/nautilus-global-preferences.c
+++ b/libnautilus-extensions/nautilus-global-preferences.c
@@ -26,19 +26,21 @@
#include "nautilus-global-preferences.h"
#include "nautilus-file-utilities.h"
+#include "nautilus-font-manager.h"
#include "nautilus-glib-extensions.h"
#include "nautilus-gtk-extensions.h"
+#include "nautilus-medusa-support.h"
#include "nautilus-preferences-dialog.h"
#include "nautilus-preferences-group.h"
#include "nautilus-preferences-item.h"
+#include "nautilus-scalable-font.h"
#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>
#include <libgnome/gnome-i18n.h>
+#include <libgnome/gnome-util.h>
#include <liboaf/liboaf.h>
#include <libgnomevfs/gnome-vfs-utils.h>
@@ -1106,19 +1108,19 @@ global_preferences_install_home_location_defaults (void)
static void
global_preferences_install_font_defaults (void)
{
- char *fallback_smooth_font;
+ char *default_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 ();
+ default_smooth_font = nautilus_font_manager_get_default_font ();
nautilus_preferences_default_set_string (NAUTILUS_PREFERENCES_DIRECTORY_VIEW_SMOOTH_FONT,
NAUTILUS_USER_LEVEL_NOVICE,
- fallback_smooth_font);
- g_free (fallback_smooth_font);
+ default_smooth_font);
+ g_free (default_smooth_font);
}
static void
@@ -1209,6 +1211,25 @@ nautilus_global_preferences_set_dialog_title (const char *title)
gtk_window_set_title (GTK_WINDOW (dialog), title);
}
+NautilusScalableFont *
+nautilus_global_preferences_get_smooth_font (void)
+{
+ NautilusScalableFont *scalable_font;
+ char *font_file_name;
+
+ font_file_name = nautilus_preferences_get (NAUTILUS_PREFERENCES_DIRECTORY_VIEW_SMOOTH_FONT);
+
+ scalable_font =
+ (font_file_name && g_file_exists (font_file_name)) ?
+ nautilus_scalable_font_new (font_file_name) :
+ nautilus_scalable_font_get_default_font ();
+ g_free (font_file_name);
+
+ g_assert (NAUTILUS_IS_SCALABLE_FONT (scalable_font));
+
+ return scalable_font;
+}
+
void
nautilus_global_preferences_initialize (void)
{
diff --git a/libnautilus-extensions/nautilus-global-preferences.h b/libnautilus-extensions/nautilus-global-preferences.h
index 661dd680e..2416de3b7 100644
--- a/libnautilus-extensions/nautilus-global-preferences.h
+++ b/libnautilus-extensions/nautilus-global-preferences.h
@@ -136,13 +136,14 @@ typedef enum
/* Gnome session management */
#define NAUTILUS_PREFERENCES_ADD_TO_SESSION "preferences/add_to_session"
-void nautilus_global_preferences_initialize (void);
-void nautilus_global_preferences_show_dialog (void);
-void nautilus_global_preferences_hide_dialog (void);
-void nautilus_global_preferences_set_dialog_title (const char *title);
+void nautilus_global_preferences_initialize (void);
+void nautilus_global_preferences_show_dialog (void);
+void nautilus_global_preferences_hide_dialog (void);
+void nautilus_global_preferences_set_dialog_title (const char *title);
/* Sidebar */
-GList *nautilus_global_preferences_get_enabled_sidebar_panel_view_identifiers (void);
+GList * nautilus_global_preferences_get_enabled_sidebar_panel_view_identifiers (void);
+struct NautilusScalableFont *nautilus_global_preferences_get_smooth_font (void);
END_GNOME_DECLS
diff --git a/libnautilus-extensions/nautilus-icon-container.c b/libnautilus-extensions/nautilus-icon-container.c
index 0f69b7f5b..367d39988 100644
--- a/libnautilus-extensions/nautilus-icon-container.c
+++ b/libnautilus-extensions/nautilus-icon-container.c
@@ -47,6 +47,7 @@
#include <gtk/gtksignal.h>
#include <gtk/gtklayout.h>
#include <libgnomeui/gnome-canvas-rect-ellipse.h>
+#include <libgnome/gnome-i18n.h>
#include <libnautilus/nautilus-clipboard.h>
#include <math.h>
#include <stdio.h>
@@ -3315,13 +3316,14 @@ nautilus_icon_container_initialize (NautilusIconContainer *container)
/* font table - this isn't exactly proportional, but it looks better than computed */
/* FIXME bugzilla.eazel.com 5093: Font name is hard-coded here. */
/* FIXME bugzilla.eazel.com 5101: Font size is hard-coded here. */
- details->label_font[NAUTILUS_ZOOM_LEVEL_SMALLEST] = nautilus_font_factory_get_font_by_family ("helvetica", 8);
- details->label_font[NAUTILUS_ZOOM_LEVEL_SMALLER] = nautilus_font_factory_get_font_by_family ("helvetica", 8);
- details->label_font[NAUTILUS_ZOOM_LEVEL_SMALL] = nautilus_font_factory_get_font_by_family ("helvetica", 10);
- details->label_font[NAUTILUS_ZOOM_LEVEL_STANDARD] = nautilus_font_factory_get_font_by_family ("helvetica", 12);
- details->label_font[NAUTILUS_ZOOM_LEVEL_LARGE] = nautilus_font_factory_get_font_by_family ("helvetica", 14);
- details->label_font[NAUTILUS_ZOOM_LEVEL_LARGER] = nautilus_font_factory_get_font_by_family ("helvetica", 18);
- details->label_font[NAUTILUS_ZOOM_LEVEL_LARGEST] = nautilus_font_factory_get_font_by_family ("helvetica", 18);
+ /* FIXME bugzilla.eazel.com xxxx: Fonts marked for localization in disparate places. */
+ details->label_font[NAUTILUS_ZOOM_LEVEL_SMALLEST] = nautilus_font_factory_get_font_by_family (_("helvetica"), 8);
+ details->label_font[NAUTILUS_ZOOM_LEVEL_SMALLER] = nautilus_font_factory_get_font_by_family (_("helvetica"), 8);
+ details->label_font[NAUTILUS_ZOOM_LEVEL_SMALL] = nautilus_font_factory_get_font_by_family (_("helvetica"), 10);
+ details->label_font[NAUTILUS_ZOOM_LEVEL_STANDARD] = nautilus_font_factory_get_font_by_family (_("helvetica"), 12);
+ details->label_font[NAUTILUS_ZOOM_LEVEL_LARGE] = nautilus_font_factory_get_font_by_family (_("helvetica"), 14);
+ details->label_font[NAUTILUS_ZOOM_LEVEL_LARGER] = nautilus_font_factory_get_font_by_family (_("helvetica"), 18);
+ details->label_font[NAUTILUS_ZOOM_LEVEL_LARGEST] = nautilus_font_factory_get_font_by_family (_("helvetica"), 18);
details->smooth_label_font = nautilus_scalable_font_get_default_font ();
diff --git a/libnautilus-extensions/nautilus-program-chooser.c b/libnautilus-extensions/nautilus-program-chooser.c
index 7183d82a2..35e69efe0 100644
--- a/libnautilus-extensions/nautilus-program-chooser.c
+++ b/libnautilus-extensions/nautilus-program-chooser.c
@@ -193,10 +193,10 @@ program_file_pair_get_program_name_for_display (ProgramFilePair *pair)
|| pair->view_identifier != NULL);
if (pair->action_type == GNOME_VFS_MIME_ACTION_TYPE_COMPONENT) {
- return g_strdup (pair->view_identifier->view_as_label);
+ return g_strdup (_(pair->view_identifier->view_as_label));
}
- return g_strdup (pair->application->name);
+ return g_strdup (_(pair->application->name));
}
static char *
diff --git a/libnautilus-extensions/nautilus-scalable-font.c b/libnautilus-extensions/nautilus-scalable-font.c
index b1c4a516d..4e9a92e3a 100644
--- a/libnautilus-extensions/nautilus-scalable-font.c
+++ b/libnautilus-extensions/nautilus-scalable-font.c
@@ -25,63 +25,33 @@
#include <config.h>
#include "nautilus-scalable-font-private.h"
-#include "nautilus-gtk-macros.h"
-#include "nautilus-gdk-extensions.h"
-#include "nautilus-gdk-pixbuf-extensions.h"
#include "nautilus-background.h"
-#include "nautilus-string.h"
-#include "nautilus-file-utilities.h"
-#include "nautilus-glib-extensions.h"
-#include "nautilus-string-map.h"
-#include "nautilus-lib-self-check-functions.h"
+#include "nautilus-font-manager.h"
+#include "nautilus-gdk-pixbuf-extensions.h"
#include "nautilus-glyph.h"
-
+#include "nautilus-gtk-macros.h"
+#include "nautilus-lib-self-check-functions.h"
+#include "nautilus-global-preferences.h"
+#include "nautilus-string.h"
#include <librsvg/rsvg-ft.h>
-
-#include <stdio.h>
#include <libgnome/gnome-util.h>
-#include <ctype.h>
-
-/* FontEntry */
-typedef struct {
- char *weight;
- char *slant;
- char *set_width;
- RsvgFTFontHandle font_handle;
- char *path;
-} FontEntry;
-
-/* FontFamilyEntry */
-typedef struct {
- char *family;
- GList *fonts;
-} FontFamilyEntry;
/* Detail member struct */
-struct _NautilusScalableFontDetail
+struct NautilusScalableFontDetails
{
RsvgFTFontHandle font_handle;
- const FontFamilyEntry *font_family_entry;
- const FontEntry *font_entry;
+ char *font_file_name;
};
/* Global things */
-static GHashTable *global_font_family_table = NULL;
static RsvgFTCtx *global_rsvg_ft_context = NULL;
-static NautilusScalableFont *global_default_font = NULL;
-static NautilusStringMap *global_family_string_map = NULL;
+static GHashTable *global_font_handle_table = NULL;
/* GtkObjectClass methods */
-static void nautilus_scalable_font_initialize_class (NautilusScalableFontClass *font_class);
-static void nautilus_scalable_font_initialize (NautilusScalableFont *font);
-static void nautilus_scalable_font_destroy (GtkObject *object);
-static void initialize_global_stuff_if_needed (void);
-
-
-/* 'atexit' destructors for global stuff */
-static void default_font_at_exit_destructor (void);
-static void font_family_table_at_exit_destructor (void);
-static void font_family_string_map_at_exit_destructor (void);
+static void nautilus_scalable_font_initialize_class (NautilusScalableFontClass *font_class);
+static void nautilus_scalable_font_initialize (NautilusScalableFont *font);
+static void nautilus_scalable_font_destroy (GtkObject *object);
+static void initialize_global_stuff_if_needed (void);
NAUTILUS_DEFINE_CLASS_BOILERPLATE (NautilusScalableFont, nautilus_scalable_font, GTK_TYPE_OBJECT)
@@ -89,7 +59,7 @@ NAUTILUS_DEFINE_CLASS_BOILERPLATE (NautilusScalableFont, nautilus_scalable_font,
static void
nautilus_scalable_font_initialize_class (NautilusScalableFontClass *font_class)
{
- GtkObjectClass *object_class = GTK_OBJECT_CLASS (font_class);
+ GtkObjectClass *object_class = GTK_OBJECT_CLASS (font_class);
initialize_global_stuff_if_needed ();
@@ -100,9 +70,9 @@ nautilus_scalable_font_initialize_class (NautilusScalableFontClass *font_class)
void
nautilus_scalable_font_initialize (NautilusScalableFont *font)
{
- font->detail = g_new0 (NautilusScalableFontDetail, 1);
+ font->details = g_new0 (NautilusScalableFontDetails, 1);
- font->detail->font_handle = NAUTILUS_SCALABLE_FONT_UNDEFINED_HANDLE;
+ font->details->font_handle = NAUTILUS_SCALABLE_FONT_UNDEFINED_HANDLE;
}
/* GtkObjectClass methods */
@@ -116,515 +86,30 @@ nautilus_scalable_font_destroy (GtkObject *object)
font = NAUTILUS_SCALABLE_FONT (object);
- g_free (font->detail);
-
+ g_free (font->details->font_file_name);
+ g_free (font->details);
+
/* Chain destroy */
NAUTILUS_CALL_PARENT (GTK_OBJECT_CLASS, destroy, (object));
}
-static char *
-file_as_string (const char *file_name)
-{
- struct stat stat_info;
- FILE *stream;
- char *result;
- size_t num_read;
-
- g_return_val_if_fail (file_name != NULL, NULL);
- g_return_val_if_fail (g_file_exists (file_name), NULL);
-
- if (stat (file_name, &stat_info) != 0) {
- return NULL;
- }
-
- if (stat_info.st_size == 0) {
- return NULL;
- }
-
- stream = fopen (file_name, "r");
-
- if (!stream) {
- return NULL;
- }
-
- result = g_malloc (sizeof (char) * stat_info.st_size + 1);
-
- num_read = fread (result, sizeof (char), stat_info.st_size, stream);
-
- fclose (stream);
-
- if ((ssize_t)num_read != stat_info.st_size) {
- g_free (result);
- return NULL;
- }
-
- result[stat_info.st_size] = '\0';
-
- return result;
-}
-
-static gboolean
-parse_font_description_file (const char *directory,
- NautilusStringList **font_pfb_list_out,
- NautilusStringList **font_xfld_list_out)
-{
- char *fonts_dir_path;
- char *fonts_dir_content;
- NautilusStringList *tokenized_list;
- int i;
- int count;
-
- g_return_val_if_fail (directory != NULL, FALSE);
- g_return_val_if_fail (g_file_exists (directory), FALSE);
- g_return_val_if_fail (font_pfb_list_out != NULL, FALSE);
- g_return_val_if_fail (font_xfld_list_out != NULL, FALSE);
-
- *font_pfb_list_out = NULL;
- *font_xfld_list_out = NULL;
-
- fonts_dir_path = g_strdup_printf ("%s/%s", directory, "fonts.dir");
- fonts_dir_content = file_as_string (fonts_dir_path);
- g_free (fonts_dir_path);
-
- if (fonts_dir_content == NULL) {
- return FALSE;
- }
-
- tokenized_list = nautilus_string_list_new_from_tokens (fonts_dir_content, "\n", FALSE);
- g_free (fonts_dir_content);
-
- if (tokenized_list == NULL) {
- return FALSE;
- }
-
- if (nautilus_string_list_get_length (tokenized_list) <= 1) {
- nautilus_string_list_free (tokenized_list);
- return FALSE;
- }
-
- if (!nautilus_eat_str_to_int (nautilus_string_list_nth (tokenized_list, 0), &count)) {
- return FALSE;
- }
-
- *font_pfb_list_out = nautilus_string_list_new (FALSE);
- *font_xfld_list_out = nautilus_string_list_new (FALSE);
-
- for (i = 0; i < count; i++) {
- char *line = nautilus_string_list_nth (tokenized_list, i + 1);
-
- if (line != NULL) {
- char *delimeter;
-
- /* Look for the delimiting space */
- delimeter = strstr (line, " ");
- if (delimeter != NULL) {
-
- char *font_pfb;
- char *font_pfb_path;
- int pfb_length;
-
- pfb_length = delimeter - line;
- font_pfb = g_malloc (sizeof (char) * pfb_length + 1);
- strncpy (font_pfb, line, pfb_length);
- font_pfb[pfb_length] = '\0';
-
- font_pfb_path = g_strdup_printf ("%s/%s", directory, font_pfb);
-
- /* Make sure the pfb file exists */
- if (g_file_exists (font_pfb_path)) {
- while (isspace (*delimeter)) {
- delimeter++;
- }
-
- nautilus_string_list_insert (*font_pfb_list_out, font_pfb_path);
- nautilus_string_list_insert (*font_xfld_list_out, delimeter);
- }
-
- g_free (font_pfb);
- g_free (font_pfb_path);
- }
-
- g_free (line);
- }
- }
-
- nautilus_string_list_free (tokenized_list);
-
- return TRUE;
-}
-
-/*
- * FontEntry things
- */
-static FontEntry*
-font_entry_new (const char *weight,
- const char *slant,
- const char *set_width,
- const char *path)
-{
- FontEntry *entry;
-
- g_return_val_if_fail (weight != NULL, NULL);
- g_return_val_if_fail (slant != NULL, NULL);
- g_return_val_if_fail (set_width != NULL, NULL);
- g_return_val_if_fail (path != NULL, NULL);
-
- entry = g_new (FontEntry, 1);
-
- entry->weight = g_strdup (weight);
- entry->slant = g_strdup (slant);
- entry->set_width = g_strdup (set_width);
- entry->path = g_strdup (path);
- entry->font_handle = NAUTILUS_SCALABLE_FONT_UNDEFINED_HANDLE;
-
- return entry;
-}
-
-static void
-font_entry_free (FontEntry* entry)
-{
- g_return_if_fail (entry != NULL);
-
- g_free (entry->weight);
- g_free (entry->slant);
- g_free (entry->set_width);
- g_free (entry->path);
-
- /* These fonts arent refcounted because they are catched internally by librsvg */
- entry->font_handle = NAUTILUS_SCALABLE_FONT_UNDEFINED_HANDLE;
-
- g_free (entry);
-}
-
-/*
- * FontFamilyEntry things
- */
-static FontFamilyEntry*
-font_family_new (const char *family)
-{
- FontFamilyEntry *entry;
-
- g_return_val_if_fail (family != NULL, NULL);
-
- entry = g_new (FontFamilyEntry, 1);
-
- entry->family = g_strdup (family);
- g_strdown (entry->family);
- entry->fonts = NULL;
-
- return entry;
-}
-
-static void
-free_font_entry (gpointer data, gpointer user_data)
-{
- font_entry_free ((FontEntry*) data);
-}
-
-static void
-font_family_free (FontFamilyEntry* entry)
-{
- g_return_if_fail (entry != NULL);
-
- g_free (entry->family);
-
- nautilus_g_list_free_deep_custom (entry->fonts, free_font_entry, NULL);
- entry->fonts = NULL;
-
- g_free (entry);
-}
-
-static void
-font_family_insert_font (FontFamilyEntry *family_entry, FontEntry *font_entry)
-{
- g_return_if_fail (family_entry != NULL);
- g_return_if_fail (font_entry != NULL);
-
- family_entry->fonts = g_list_append (family_entry->fonts, (gpointer) font_entry);
-}
-
-#define EQUAL 0
-#define NOT_EQUAL 1
-
-static gint
-font_compare (gconstpointer a,
- gconstpointer b)
-{
- FontEntry *font_entry_a = (FontEntry *) a;
- FontEntry *font_entry_b = (FontEntry *) b;
-
- g_return_val_if_fail (font_entry_a != NULL, NOT_EQUAL);
- g_return_val_if_fail (font_entry_b != NULL, NOT_EQUAL);
-
- g_return_val_if_fail (font_entry_a->weight != NULL, NOT_EQUAL);
- g_return_val_if_fail (font_entry_a->slant != NULL, NOT_EQUAL);
- g_return_val_if_fail (font_entry_a->set_width != NULL, NOT_EQUAL);
- g_return_val_if_fail (font_entry_b->weight != NULL, NOT_EQUAL);
- g_return_val_if_fail (font_entry_b->slant != NULL, NOT_EQUAL);
- g_return_val_if_fail (font_entry_b->set_width != NULL, NOT_EQUAL);
-
- return (nautilus_str_is_equal (font_entry_a->weight, font_entry_b->weight)
- && nautilus_str_is_equal (font_entry_a->slant, font_entry_b->slant)
- && nautilus_str_is_equal (font_entry_a->set_width, font_entry_b->set_width)) ? EQUAL : NOT_EQUAL;
-}
-
-static FontEntry*
-font_family_find_font (const FontFamilyEntry *family_entry,
- const char *weight,
- const char *slant,
- const char *set_width)
-{
- FontEntry fake_font_entry;
-
- GList *node;
-
- g_return_val_if_fail (family_entry != NULL, NULL);
- g_return_val_if_fail (weight != NULL, NULL);
- g_return_val_if_fail (slant != NULL, NULL);
- g_return_val_if_fail (set_width != NULL, NULL);
-
- fake_font_entry.weight = (char *) weight;
- fake_font_entry.slant = (char *) slant;
- fake_font_entry.set_width = (char *) set_width;
-
- node = g_list_find_custom (family_entry->fonts, &fake_font_entry, font_compare);
-
- return node ? node->data : NULL;
-}
-
-static FontFamilyEntry *
-font_family_lookup (GHashTable *font_family_table,
- const char *family)
-{
- gpointer value;
-
- g_return_val_if_fail (font_family_table != NULL, NULL);
- g_return_val_if_fail (family != NULL, NULL);
-
- value = g_hash_table_lookup (font_family_table, (gconstpointer) family);
-
- return (FontFamilyEntry *) value;
-}
-
-static FontFamilyEntry *
-font_family_lookup_with_insertion (GHashTable *font_family_table,
- const char *family)
-{
- FontFamilyEntry *entry;
-
- g_return_val_if_fail (font_family_table != NULL, NULL);
- g_return_val_if_fail (family != NULL, NULL);
-
- entry = g_hash_table_lookup (font_family_table, (gconstpointer) family);
-
- if (entry == NULL) {
-
- entry = font_family_new (family);
-
- g_hash_table_insert (font_family_table, entry->family, entry);
- }
-
- return entry;
-}
-
-static void
-font_family_table_add_fonts (GHashTable *font_family_table,
- const char *font_path)
-{
- NautilusStringList *font_pfb_list = NULL;
- NautilusStringList *font_xfld_list = NULL;
- guint i;
-
- g_return_if_fail (font_family_table != NULL);
- g_return_if_fail (font_path != NULL);
-
- if (!g_file_exists (font_path)) {
- return;
- }
-
- if (!parse_font_description_file (font_path, &font_pfb_list, &font_xfld_list)) {
- return;
- }
-
- if (nautilus_string_list_get_length (font_pfb_list) != nautilus_string_list_get_length (font_xfld_list)) {
- nautilus_string_list_free (font_pfb_list);
- nautilus_string_list_free (font_xfld_list);
- return;
- }
-
- for (i = 0; i < nautilus_string_list_get_length (font_pfb_list); i++) {
- NautilusStringList *tokenized_xfld;
- char *path;
- char *xfld;
- char *foundry;
- char *family;
- char *weight;
- char *slant;
- char *set_width;
- FontFamilyEntry *family_entry;
- FontEntry *font_entry;
-
- path = nautilus_string_list_nth (font_pfb_list, i);
- g_assert (path != NULL);
-
- xfld = nautilus_string_list_nth (font_xfld_list, i);
- g_assert (xfld != NULL);
-
- tokenized_xfld = nautilus_string_list_new_from_tokens (xfld, "-", FALSE);
-
- foundry = nautilus_string_list_nth (tokenized_xfld, 1);
- family = nautilus_string_list_nth (tokenized_xfld, 2);
- g_strdown (family);
- weight = nautilus_string_list_nth (tokenized_xfld, 3);
- slant = nautilus_string_list_nth (tokenized_xfld, 4);
- set_width = nautilus_string_list_nth (tokenized_xfld, 5);
-
- family_entry = font_family_lookup_with_insertion (font_family_table, family);
- g_assert (family_entry != NULL);
-
- font_entry = font_family_find_font (family_entry, weight, slant, set_width);
-
- if (font_entry != NULL) {
- g_warning ("Dude, the font '%s-%s-%s-%s' already exists", family, weight, slant, set_width);
- }
- else {
- font_entry = font_entry_new (weight, slant, set_width, path);
-
- font_family_insert_font (family_entry, font_entry);
- }
-
- nautilus_string_list_free (tokenized_xfld);
- g_free (foundry);
- g_free (family);
- g_free (weight);
- g_free (slant);
- g_free (set_width);
-
- g_free (path);
- g_free (xfld);
- }
-
- nautilus_string_list_free (font_pfb_list);
- nautilus_string_list_free (font_xfld_list);
-}
-
-static NautilusStringMap *
-font_family_string_map_new (void)
-{
- NautilusStringMap *map;
-
- map = nautilus_string_map_new (FALSE);
-
- /*
- * The idea behind the family map here is that users of NautilusScalableFont
- * dont need to know what the exact name of the font is.
- *
- * For example, old urw fonts use the name 'helvetica', but newer ones use
- * 'numbus sans l'
- *
- * So, we a map for 'helvetica' to 'nimbus sans l' if needed.
- *
- * 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 default");
- }
- else if (font_family_lookup (global_font_family_table, "helvetica default")) {
- nautilus_string_map_add (map, "helvetica default", "nimbus sans l");
- }
-
- return map;
-}
-
/* Public NautilusScalableFont methods */
/**
* nautilus_scalable_font_new:
- * @family: The desired font family.
- * @weight: The desired font weight.
- * @slant: The desired font slant.
- * @set_width: The desired font set_width.
- *
- * Returns a font for the desired components. Returns NULL if the font
- * does not exist.
- *
- */
-NautilusScalableFont *
-nautilus_scalable_font_new (const char *family,
- const char *weight,
- const char *slant,
- const char *set_width)
-{
- /* const char *foundry = "URW"; */
- FontFamilyEntry *font_family_entry;
- FontEntry *font_entry;
- NautilusScalableFont *font;
-
- initialize_global_stuff_if_needed ();
-
- font_family_entry = font_family_lookup (global_font_family_table, family);
-
- /* If the family entry was not found, try a mapped family name */
- if (font_family_entry == NULL) {
- char *mapped_family;
-
- mapped_family = nautilus_string_map_lookup (global_family_string_map, family);
-
- if (mapped_family != NULL) {
- font_family_entry = font_family_lookup (global_font_family_table, mapped_family);
- g_free (mapped_family);
- }
- }
-
- if (font_family_entry == NULL) {
- return NULL;
- }
-
- weight = weight ? weight : "medium";
- slant = slant ? slant : "r";
- set_width = set_width ? set_width : "normal";
-
- font_entry = font_family_find_font (font_family_entry, weight, slant, set_width);
-
- if (font_entry == NULL) {
- return NULL;
- }
-
- /* 'Intern' the rsvg font handle if needed */
- if (font_entry->font_handle == NAUTILUS_SCALABLE_FONT_UNDEFINED_HANDLE) {
- font_entry->font_handle = rsvg_ft_intern (global_rsvg_ft_context, font_entry->path);
- }
-
-#if 0
- g_print ("%s (%s, %s, %s %s) handle = %d, path = %s\n" ,
- __FUNCTION__, family, weight, slant, set_width, font_entry->font_handle, font_entry->path);
-#endif
-
- 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 = font_entry->font_handle;
- font->detail->font_family_entry = font_family_entry;
- font->detail->font_entry = font_entry;
-
- 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)
+nautilus_scalable_font_new (const char *file_name)
{
NautilusScalableFont *font;
+ RsvgFTFontHandle font_handle = -1;
g_return_val_if_fail (nautilus_strlen (file_name) > 0, NULL);
- g_return_val_if_fail (g_file_exists (file_name), NULL);
+ g_return_val_if_fail (nautilus_font_manager_file_is_scalable_font (file_name), NULL);
initialize_global_stuff_if_needed ();
@@ -632,9 +117,20 @@ nautilus_scalable_font_new_from_file_name (const char *file_name)
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;
+ font->details->font_file_name = g_strdup (file_name);
+
+ if (!g_hash_table_lookup_extended (global_font_handle_table,
+ font->details->font_file_name,
+ NULL,
+ (gpointer *) &font_handle)) {
+ font_handle = rsvg_ft_intern (global_rsvg_ft_context, font->details->font_file_name);
+ g_hash_table_insert (global_font_handle_table,
+ font->details->font_file_name,
+ GINT_TO_POINTER (font_handle));
+ }
+ g_assert (font_handle >= 0);
+
+ font->details->font_handle = font_handle;
return font;
}
@@ -642,32 +138,14 @@ nautilus_scalable_font_new_from_file_name (const char *file_name)
NautilusScalableFont *
nautilus_scalable_font_make_bold (NautilusScalableFont *font)
{
- NautilusScalableFont *bold_font = NULL;
+ char *bold_font_file_name;
+ NautilusScalableFont *bold_font;
g_return_val_if_fail (NAUTILUS_IS_SCALABLE_FONT (font), NULL);
- /* FIXME bugzilla.eazel.com xxxx:
- * To be 100% correc we need to query for the weights.
- * It just so happens that the limited number of Type1
- * font we have dealt with all have a "bold" weight.
- */
-
- /* If the font is already bold, then do nothing */
- if (nautilus_str_is_equal (font->detail->font_entry->weight, "bold")) {
- gtk_object_ref (GTK_OBJECT (font));
- return font;
- }
-
- bold_font = nautilus_scalable_font_new (font->detail->font_family_entry->family,
- "bold",
- font->detail->font_entry->slant,
- font->detail->font_entry->set_width);
-
- /* If the bold font does not exist, then return the source font */
- if (bold_font == NULL) {
- gtk_object_ref (GTK_OBJECT (font));
- bold_font = font;
- }
+ bold_font_file_name = nautilus_font_manager_get_bold (font->details->font_file_name);
+ bold_font = nautilus_scalable_font_new (bold_font_file_name);
+ g_free (bold_font_file_name);
return bold_font;
}
@@ -819,153 +297,50 @@ nautilus_scalable_font_largest_fitting_font_size (const NautilusScalableFont *fo
NautilusScalableFont *
nautilus_scalable_font_get_default_font (void)
{
- if (global_default_font == 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);
- }
+ char *default_font_file_name;
+ NautilusScalableFont *default_font;
- gtk_object_ref (GTK_OBJECT (global_default_font));
+ /* FIXME bugzilla.eazel.com xxxx:
+ * Its evil that we have to peek preferences here to
+ * find the default smooth font, but so it goes.
+ */
+ default_font_file_name = nautilus_preferences_get (NAUTILUS_PREFERENCES_DIRECTORY_VIEW_SMOOTH_FONT);
+ if (!g_file_exists (default_font_file_name)) {
+ g_free (default_font_file_name);
+ default_font_file_name = nautilus_font_manager_get_default_font ();
+ }
- return global_default_font;
+ g_assert (default_font_file_name != NULL);
+ default_font = nautilus_scalable_font_new (default_font_file_name);
+ g_free (default_font_file_name);
+ g_assert (NAUTILUS_IS_SCALABLE_FONT (default_font));
+ return default_font;
}
NautilusScalableFont *
nautilus_scalable_font_get_default_bold_font (void)
{
- NautilusScalableFont *default_font;
+ char *default_bold_font_file_name;
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,
- gpointer user_data)
-{
- NautilusStringList *list = (NautilusStringList *) user_data;
- FontFamilyEntry *family_entry = (FontFamilyEntry *) value;
-
- g_assert (family_entry != NULL);
- g_assert (!nautilus_string_list_contains (list, family_entry->family));
-
- nautilus_string_list_insert (list, family_entry->family);
-}
-
-static void
-font_family_table_for_each_free (gpointer key,
- gpointer value,
- gpointer user_data)
-{
- FontFamilyEntry *family_entry = (FontFamilyEntry *) value;
- g_assert (family_entry != NULL);
-
- font_family_free (family_entry);
-}
-
-static NautilusStringList *
-font_family_table_get_family_list (GHashTable *font_family_table)
-{
- NautilusStringList *list;
-
- g_return_val_if_fail (font_family_table != NULL, NULL);
-
- list = nautilus_string_list_new (FALSE);
-
- g_hash_table_foreach (font_family_table, font_family_table_for_each_append, list);
-
- return list;
-}
-
-NautilusStringList *
-nautilus_scalable_font_get_font_family_list (void)
-{
- initialize_global_stuff_if_needed ();
-
- return font_family_table_get_family_list (global_font_family_table);
-}
-
-static void
-font_family_table_free (GHashTable *font_family_table)
-{
- g_assert (font_family_table != NULL);
-
- g_hash_table_foreach (font_family_table, font_family_table_for_each_free, NULL);
-
- g_hash_table_destroy (font_family_table);
-}
-
-gboolean
-nautilus_scalable_font_query_font (const char *family,
- NautilusStringList **weights_out,
- NautilusStringList **slants_out,
- NautilusStringList **set_widths_out)
-{
- FontFamilyEntry *family_entry;
- GList *iterator;
-
- g_return_val_if_fail (family != NULL, FALSE);
-
- if (weights_out != NULL) {
- *weights_out = NULL;
- }
-
- if (slants_out != NULL) {
- *slants_out = NULL;
- }
-
- if (set_widths_out != NULL) {
- *set_widths_out = NULL;
- }
-
- family_entry = font_family_lookup (global_font_family_table, family);
-
- if (family_entry == NULL) {
- return FALSE;
- }
-
- if (weights_out == NULL && slants_out == NULL && set_widths_out == NULL) {
- return TRUE;
- }
-
- if (weights_out != NULL) {
- *weights_out = nautilus_string_list_new (FALSE);
- }
-
- if (slants_out != NULL) {
- *slants_out = nautilus_string_list_new (FALSE);
- }
-
- if (set_widths_out != NULL) {
- *set_widths_out = nautilus_string_list_new (FALSE);
- }
-
- for (iterator = family_entry->fonts; iterator != NULL; iterator = iterator->next) {
- FontEntry *font_entry = (FontEntry *) iterator->data;
- g_assert (font_entry != NULL);
-
- if (weights_out != NULL) {
- nautilus_string_list_insert (*weights_out, font_entry->weight);
- }
-
- if (slants_out != NULL) {
- nautilus_string_list_insert (*slants_out, font_entry->slant);
- }
-
- if (set_widths_out != NULL) {
- nautilus_string_list_insert (*set_widths_out, font_entry->set_width);
- }
+ /* FIXME bugzilla.eazel.com xxxx:
+ * Its evil that we have to peek preferences here to
+ * find the default smooth font, but so it goes.
+ */
+ default_bold_font_file_name = nautilus_preferences_get ("directory-view/smooth_font");
+ if (!g_file_exists (default_bold_font_file_name)) {
+ g_free (default_bold_font_file_name);
+ default_bold_font_file_name = nautilus_font_manager_get_default_bold_font ();
}
- return TRUE;
+ g_assert (default_bold_font_file_name != NULL);
+ default_bold_font = nautilus_scalable_font_new (default_bold_font_file_name);
+ g_free (default_bold_font_file_name);
+ g_assert (NAUTILUS_IS_SCALABLE_FONT (default_bold_font));
+ return default_bold_font;
}
-/* 'atexit' destructors for global stuff */
+/* 'atexit' destructor for rsvg context */
static void
destroy_global_rsvg_ft_context (void)
{
@@ -973,46 +348,27 @@ destroy_global_rsvg_ft_context (void)
}
static void
-default_font_at_exit_destructor (void)
-{
- gtk_object_unref (GTK_OBJECT (global_default_font));
-}
-
-static void
-font_family_table_at_exit_destructor (void)
+free_global_font_handle_table (void)
{
- font_family_table_free (global_font_family_table);
-}
+ if (global_font_handle_table != NULL) {
+ g_hash_table_destroy (global_font_handle_table);
+ }
-static void
-font_family_string_map_at_exit_destructor (void)
-{
- nautilus_string_map_free (global_family_string_map);
+ global_font_handle_table = NULL;
}
static void
initialize_global_stuff_if_needed (void)
{
- static gboolean fonts_initialized = FALSE;
-
/* Initialize the rsvg font context shared by all fonts */
if (global_rsvg_ft_context == NULL) {
global_rsvg_ft_context = rsvg_ft_ctx_new ();
g_atexit (destroy_global_rsvg_ft_context);
}
- /* Initialize the global font table */
- if (!fonts_initialized) {
- fonts_initialized = TRUE;
- global_font_family_table = g_hash_table_new (g_str_hash, g_str_equal);
- font_family_table_add_fonts (global_font_family_table, NAUTILUS_DATADIR "/fonts/urw");
- g_atexit (font_family_table_at_exit_destructor);
- }
-
- if (global_family_string_map == NULL) {
- global_family_string_map = font_family_string_map_new ();
-
- g_atexit (font_family_string_map_at_exit_destructor);
+ if (global_font_handle_table == NULL) {
+ global_font_handle_table = g_hash_table_new (g_str_hash, g_str_equal);
+ g_atexit (free_global_font_handle_table);
}
}
@@ -1022,7 +378,7 @@ nautilus_scalable_font_get_rsvg_handle (const NautilusScalableFont *font)
{
g_return_val_if_fail (NAUTILUS_IS_SCALABLE_FONT (font), NAUTILUS_SCALABLE_FONT_UNDEFINED_HANDLE);
- return font->detail->font_handle;
+ return font->details->font_handle;
}
struct _RsvgFTCtx *
diff --git a/libnautilus-extensions/nautilus-scalable-font.h b/libnautilus-extensions/nautilus-scalable-font.h
index 40c860cc8..c8add6e4b 100644
--- a/libnautilus-extensions/nautilus-scalable-font.h
+++ b/libnautilus-extensions/nautilus-scalable-font.h
@@ -55,30 +55,26 @@ BEGIN_GNOME_DECLS
#define NAUTILUS_IS_SCALABLE_FONT(obj) (GTK_CHECK_TYPE ((obj), NAUTILUS_TYPE_SCALABLE_FONT))
#define NAUTILUS_IS_SCALABLE_FONT_CLASS(klass) (GTK_CHECK_CLASS_TYPE ((klass), NAUTILUS_TYPE_SCALABLE_FONT))
-typedef struct _NautilusScalableFont NautilusScalableFont;
-typedef struct _NautilusScalableFontClass NautilusScalableFontClass;
-typedef struct _NautilusScalableFontDetail NautilusScalableFontDetail;
+typedef struct NautilusScalableFont NautilusScalableFont;
+typedef struct NautilusScalableFontClass NautilusScalableFontClass;
+typedef struct NautilusScalableFontDetails NautilusScalableFontDetails;
-struct _NautilusScalableFont
+struct NautilusScalableFont
{
/* Superclass */
- GtkObject object;
+ GtkObject object;
/* Private things */
- NautilusScalableFontDetail *detail;
+ NautilusScalableFontDetails *details;
};
-struct _NautilusScalableFontClass
+struct NautilusScalableFontClass
{
- GtkObjectClass parent_class;
+ GtkObjectClass parent_class;
};
GtkType nautilus_scalable_font_get_type (void);
-NautilusScalableFont *nautilus_scalable_font_new (const char *family,
- const char *weight,
- const char *slant,
- const char *set_width);
-NautilusScalableFont * nautilus_scalable_font_new_from_file_name (const char *file_name);
+NautilusScalableFont * nautilus_scalable_font_new (const char *file_name);
NautilusDimensions nautilus_scalable_font_measure_text (const NautilusScalableFont *font,
int font_size,
const char *text,
@@ -104,11 +100,6 @@ int nautilus_scalable_font_largest_fitting_font_size (const N
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);
END_GNOME_DECLS
diff --git a/libnautilus-extensions/nautilus-smooth-text-layout-cache.c b/libnautilus-extensions/nautilus-smooth-text-layout-cache.c
index 041ff34e0..c2d2b6a02 100644
--- a/libnautilus-extensions/nautilus-smooth-text-layout-cache.c
+++ b/libnautilus-extensions/nautilus-smooth-text-layout-cache.c
@@ -288,7 +288,7 @@ cache_trim (NautilusSmoothTextLayoutCache *cache)
* @cache: The layout cache being queried
* @text: The string to be rendered
* @text_length: The number of bytes to draw
- * @font: The desired smooth font family.
+ * @font: The desired smooth font.
* @font_size: The pixel size of the font
* @wrap:
* @line_spacing:
@@ -445,11 +445,6 @@ nautilus_smooth_text_layout_cache_destroy (GtkObject *object)
#include <stdlib.h>
#include <stdio.h>
-/* Have to disable the tests by default for now - NautilusScalableFont
- * can't handle loading fonts before `make install' has happened :-(
- */
-#ifdef FIXED_LOADING_FONTS_BEFORE_MAKE_INSTALL
-
static NautilusSmoothTextLayoutCache *test_cache;
static NautilusScalableFont *test_font;
@@ -567,7 +562,6 @@ struct test_case {
#define MIN_LINES 1
#define MAX_LINES 10
-#define FONT_FAMILY "helvetica"
#define MIN_FONT_SIZE 8
#define MAX_FONT_SIZE 48
@@ -730,7 +724,7 @@ nautilus_self_check_smooth_text_layout_cache (void)
int i, index;
test_cache = nautilus_smooth_text_layout_cache_new ();
- test_font = nautilus_scalable_font_new (FONT_FAMILY, NULL, NULL, NULL);
+ test_font = nautilus_scalable_font_get_default_font ();
/* initialize the random number generator to a known state */
srandom (1);
@@ -764,12 +758,4 @@ nautilus_self_check_smooth_text_layout_cache (void)
gtk_object_destroy (GTK_OBJECT (test_cache));
}
-#else /* FIXED_LOADING_FONTS_BEFORE_MAKE_INSTALL */
-
-void
-nautilus_self_check_smooth_text_layout_cache (void)
-{
-}
-
-#endif /* FIXED_LOADING_FONTS_BEFORE_MAKE_INSTALL */
#endif /* NAUTILUS_OMIT_SELF_CHECK */
diff --git a/libnautilus-private/Makefile.am b/libnautilus-private/Makefile.am
index 9b8f4f36e..220b0b636 100644
--- a/libnautilus-private/Makefile.am
+++ b/libnautilus-private/Makefile.am
@@ -21,6 +21,7 @@ INCLUDES = \
-D_REENTRANT \
-DDATADIR=\""$(datadir)"\" \
-DNAUTILUS_DATADIR=\""$(datadir)/nautilus"\" \
+ -DSOURCE_DATADIR=\""$(top_srcdir)/data"\" \
$(NULL)
dependency_static_libs = \
diff --git a/libnautilus-private/nautilus-font-factory.c b/libnautilus-private/nautilus-font-factory.c
index 2715ae16d..042b4be30 100644
--- a/libnautilus-private/nautilus-font-factory.c
+++ b/libnautilus-private/nautilus-font-factory.c
@@ -223,13 +223,21 @@ nautilus_font_factory_get_font_by_family (const char *family,
factory = nautilus_get_current_font_factory ();
while (*iter) {
- font_name = nautilus_gdk_font_xlfd_string_new ("*",
- *iter,
- "medium",
- "r",
- "normal",
- "*",
- size_in_pixels);
+ /* FIXME bugzilla.eazel.com xxxx:
+ * Its a hack that we check for "-" prefixes in font names.
+ * We do this in order not to break transalted font families.
+ */
+ if (!nautilus_str_has_prefix (*iter, "-")) {
+ font_name = nautilus_gdk_font_xlfd_string_new ("*",
+ *iter,
+ "medium",
+ "r",
+ "normal",
+ "*",
+ size_in_pixels);
+ } else {
+ font_name = g_strdup (*iter);
+ }
g_free (*iter);
*iter = font_name;
@@ -262,7 +270,7 @@ nautilus_font_factory_get_font_from_preferences (guint size_in_pixels)
family = nautilus_preferences_get (NAUTILUS_PREFERENCES_DIRECTORY_VIEW_FONT_FAMILY);
- font = nautilus_font_factory_get_font_by_family (family, size_in_pixels);
+ font = nautilus_font_factory_get_font_by_family (_(family), size_in_pixels);
g_free (family);
diff --git a/libnautilus-private/nautilus-font-manager.c b/libnautilus-private/nautilus-font-manager.c
index fc4ac731e..e2f982121 100644
--- a/libnautilus-private/nautilus-font-manager.c
+++ b/libnautilus-private/nautilus-font-manager.c
@@ -51,11 +51,14 @@
#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 DEFAULT_FONT_DIRECTORY NAUTILUS_DATADIR "/fonts/urw"
#define USER_FONT_DIRECTORY_NAME "fonts"
#define NAUTILUS_FONT_UNDEFINED ((NautilusFontType) 0)
+#define POSTSCRIPT_FONT_MIME_TYPE "application/x-font-type1"
+#define TRUE_TYPE_FONT_MIME_TYPE "application/x-font-ttf"
+
/*
* FontDescription:
*
@@ -96,7 +99,7 @@ static FontDescription * font_description_new (const c
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,
+static gboolean font_description_table_for_each (const FontDescriptionTable *description_table,
NautilusFontManagerCallback callback,
gpointer callback_data);
static char *font_description_get_file_name (const FontDescription *description);
@@ -124,6 +127,8 @@ static char * font_description_table_get_nth_file_name (const F
guint n);
static void font_description_table_free (FontDescriptionTable *table);
static void font_description_table_clear (FontDescriptionTable *table);
+static const FontDescription * font_description_table_find (const FontDescriptionTable *description_table,
+ const char *file_name);
static gboolean
string_is_valid (const char *string)
@@ -439,35 +444,60 @@ font_description_table_clear (FontDescriptionTable *table)
table->fonts_scale_file = NULL;
}
-static void
+static const FontDescription *
+font_description_table_find (const FontDescriptionTable *table,
+ const char *file_name)
+{
+ GList *node;
+ const FontDescription *description;
+
+ g_return_val_if_fail (table != NULL, NULL);
+ g_return_val_if_fail (nautilus_strlen (file_name) > 0, NULL);
+
+ for (node = table->descriptions; node != NULL; node = node->next) {
+ g_assert (node->data != NULL);
+ description = node->data;
+
+ if (nautilus_str_is_equal (file_name, description->file_name)) {
+ return description;
+ }
+ }
+
+ return NULL;
+}
+
+static gboolean
font_description_table_for_each (const FontDescriptionTable *table,
NautilusFontManagerCallback callback,
gpointer callback_data)
{
GList *node;
const FontDescription *description;
+ gboolean cont = TRUE;
- g_return_if_fail (table != NULL);
- g_return_if_fail (callback != NULL);
+ g_return_val_if_fail (table != NULL, TRUE);
+ g_return_val_if_fail (callback != NULL, TRUE);
node = table->descriptions;
while (node != NULL) {
- description = node->data;
g_assert (node->data != NULL);
-
- (* callback) (description->file_name,
- description->font_type,
- description->foundry,
- description->family,
- description->weight,
- description->slant,
- description->set_width,
- description->char_set_registry,
- description->char_set_encoding,
- callback_data);
+ description = node->data;
- node = node->next;
+ cont = (* callback) (description->file_name,
+ description->font_type,
+ description->foundry,
+ description->family,
+ description->weight,
+ description->slant,
+ description->set_width,
+ description->char_set_registry,
+ description->char_set_encoding,
+ callback_data);
+
+ node = cont ? node->next : NULL;
}
+
+ return cont;
}
static FontDescriptionTable *
@@ -563,28 +593,30 @@ collect_fonts_from_directory (const char *font_directory,
g_return_val_if_fail (true_type_font_list != NULL, GNOME_VFS_ERROR_BAD_PARAMETERS);
directory_uri = g_strconcat ("file://", font_directory, NULL);
-
+
*postscript_font_list = NULL;
*true_type_font_list = NULL;
result = gnome_vfs_directory_open (&directory,
- directory_uri, GNOME_VFS_FILE_INFO_GET_MIME_TYPE, NULL);
+ directory_uri,
+ GNOME_VFS_FILE_INFO_GET_MIME_TYPE,
+ NULL);
g_free (directory_uri);
if (result != GNOME_VFS_OK) {
return result;
}
-
+
while (TRUE) {
info = gnome_vfs_file_info_new ();
result = gnome_vfs_directory_read_next (directory, info);
if (result == GNOME_VFS_OK) {
- if (strcasecmp (info->mime_type, "application/x-font-type1") == 0) {
+ if (strcasecmp (info->mime_type, POSTSCRIPT_FONT_MIME_TYPE) == 0) {
*postscript_font_list = g_list_prepend (*postscript_font_list,
g_strconcat (font_directory,
"/", info->name, NULL));
- } else if (strcasecmp (info->mime_type, "application/x-font-ttf") == 0) {
+ } else if (strcasecmp (info->mime_type, TRUE_TYPE_FONT_MIME_TYPE) == 0) {
*true_type_font_list = g_list_prepend (*true_type_font_list,
g_strconcat (font_directory,
"/", info->name, NULL));
@@ -826,30 +858,31 @@ directory_contains_file (const char *directory,
return result;
}
-/* Iterating directories is slow cause of all the mim sniffing that
+/* Iterating directories is slow cause of all the mime sniffing that
* has to happen on each potential scalalble font. By Ignoring
- * directories known to be without scalable fonts, we make things
- * much faster.
+ * directories that arent interesting, we make things much faster.
*/
static gboolean
font_ignore_directory (const char *font_directory)
{
- g_return_val_if_fail (string_is_valid (font_directory), TRUE);
-
- if (nautilus_str_has_suffix (font_directory, "unscaled")) {
- return TRUE;
- }
-
- if (nautilus_str_has_suffix (font_directory, "100dpi")) {
- return TRUE;
- }
+ guint i;
+
+ static const char *ignored_font_dir_suffices[] = {
+ "unscaled",
+ "100dpi",
+ "75dpi",
+ "misc",
+ "abisource/fonts",
+ "fonts/Speedo",
+ "fonts/cyrillic"
+ };
- if (nautilus_str_has_suffix (font_directory, "75dpi")) {
- return TRUE;
- }
+ g_return_val_if_fail (string_is_valid (font_directory), TRUE);
- if (nautilus_str_has_suffix (font_directory, "misc")) {
- return TRUE;
+ for (i = 0; i < NAUTILUS_N_ELEMENTS (ignored_font_dir_suffices); i++) {
+ if (nautilus_str_has_suffix (font_directory, ignored_font_dir_suffices[i])) {
+ return TRUE;
+ }
}
return FALSE;
@@ -857,7 +890,7 @@ font_ignore_directory (const char *font_directory)
static void
font_manager_collect_font_tables (const char *font_directory,
- GList **collected_font_tables)
+ GList **collected_font_tables)
{
GList *postscript_font_list = NULL;
GList *true_type_font_list = NULL;
@@ -897,7 +930,7 @@ font_manager_collect_font_tables (const char *font_directory,
return;
}
- *collected_font_tables = g_list_prepend (*collected_font_tables, table);
+ *collected_font_tables = g_list_append (*collected_font_tables, table);
nautilus_g_list_free_deep (postscript_font_list);
nautilus_g_list_free_deep (true_type_font_list);
@@ -913,9 +946,7 @@ font_server_for_each_callback (const char *font_directory,
font_manager_collect_font_tables (font_directory, callback_data);
}
-static GList *fallback_font_table = NULL;
-static GList *user_font_table = NULL;
-static GList *system_font_table = NULL;
+static GList *global_font_table = NULL;
static void
font_table_list_free (GList *font_table_list)
@@ -931,126 +962,247 @@ font_table_list_free (GList *font_table_list)
g_list_free (font_table_list);
}
-static void
-font_table_list_for_each (GList *font_table_list,
- NautilusFontManagerCallback callback,
- gpointer callback_data)
+static const FontDescription *
+font_table_list_find (const GList *font_table_list,
+ const char *file_name)
{
- GList *node;
+ const GList *node;
+ const FontDescription *description;
- g_return_if_fail (callback != NULL);
+ g_return_val_if_fail (file_name != NULL, NULL);
- node = font_table_list;
- while (node != NULL) {
+ for (node = font_table_list; node != NULL; node = node->next) {
g_assert (node->data != NULL);
- font_description_table_for_each (node->data, callback, callback_data);
- node = node->next;
+ description = font_description_table_find (node->data, file_name);
+ if (description != NULL) {
+ return description;
+ }
}
+
+ return NULL;
}
static void
free_font_tables (void)
{
- font_table_list_free (fallback_font_table);
- fallback_font_table = NULL;
+ font_table_list_free (global_font_table);
+ global_font_table = NULL;
+}
- font_table_list_free (user_font_table);
- user_font_table = NULL;
+static void
+ensure_global_font_table (void)
+{
+ char *user_directory;
+ char *user_font_dir;
- font_table_list_free (system_font_table);
- system_font_table = NULL;
+ if (global_font_table != NULL) {
+ return;
+ }
+
+ /* Populate the default font table if needed */
+ font_manager_collect_font_tables (DEFAULT_FONT_DIRECTORY, &global_font_table);
+
+ /* Populate the user font table if needed */
+ 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, &global_font_table);
+ }
+ g_free (user_directory);
+ g_free (user_font_dir);
+
+ /* Populate the system font table if needed - using the font server's configuration */
+ if (g_file_exists (FONT_SERVER_CONFIG_FILE)) {
+ font_server_for_each_font_directory (FONT_SERVER_CONFIG_FILE,
+ font_server_for_each_callback,
+ &global_font_table);
+ }
+
+ g_atexit (free_font_tables);
}
-static gboolean at_exit_handler_installed = FALSE;
+/* Public */
-static void
-ensure_at_exit_handler (void)
+/**
+ * nautilus_font_manager_for_each_font:
+ * @callback: A callback to be called for each scalable font in the system.
+ * @callback_data: User's data.
+ *
+ * Iterate all the scalable fonts available in the system. The available
+ * fonts are the sum of:
+ *
+ * 1) Fallback fonts installed by Nautilus
+ * 2) User fonts found in ~/.nautilus/fonts
+ * 3) Fonts listed in the font servers config file (/etc/X11/fs/config)
+ *
+ */
+void
+nautilus_font_manager_for_each_font (NautilusFontManagerCallback callback,
+ gpointer callback_data)
{
- if (!at_exit_handler_installed) {
- at_exit_handler_installed = TRUE;
- g_atexit (free_font_tables);
+ GList *node;
+ gboolean cont = TRUE;
+
+ g_return_if_fail (callback != NULL);
+
+ /* Ensure that all the font tables exist */
+ ensure_global_font_table ();
+
+ for (node = global_font_table; node != NULL && cont; node = node->next) {
+ g_assert (node->data != NULL);
+ cont = font_description_table_for_each (node->data, callback, callback_data);
}
}
-static void
-ensure_fallback_font_table (void)
+char *
+nautilus_font_manager_get_default_font (void)
{
- /* Populate the fallback font table if needed */
- if (fallback_font_table == NULL) {
- font_manager_collect_font_tables (FALLBACK_FONT_DIRECTORY, &fallback_font_table);
+ guint i;
+
+ static const char *default_fonts[] = {
+ DEFAULT_FONT_DIRECTORY "/n019003l.pfb",
+ SOURCE_DATADIR "/fonts/urw/n019003l.pfb",
+ "/usr/share/fonts/default/Type1/n019003l.pfb",
+ "/usr/X11R6/lib/X11/fonts/Type1/lcdxsr.pfa"
+ };
+
+ for (i = 0; i < NAUTILUS_N_ELEMENTS (default_fonts); i++) {
+ if (g_file_exists (default_fonts[i])) {
+ return g_strdup (default_fonts[i]);
+ }
}
- ensure_at_exit_handler ();
+ return NULL;
}
-static void
-ensure_user_font_table (void)
+char *
+nautilus_font_manager_get_default_bold_font (void)
{
- char *user_directory;
- char *user_font_dir;
+ guint i;
- /* 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);
+ static const char *default_bold_fonts[] = {
+ DEFAULT_FONT_DIRECTORY "/n019004l.pfb",
+ SOURCE_DATADIR "/fonts/urw/n019004l.pfb",
+ };
+
+ for (i = 0; i < NAUTILUS_N_ELEMENTS (default_bold_fonts); i++) {
+ if (g_file_exists (default_bold_fonts[i])) {
+ return g_strdup (default_bold_fonts[i]);
}
- g_free (user_directory);
- g_free (user_font_dir);
}
- ensure_at_exit_handler ();
+ return NULL;
}
-static void
-ensure_system_font_tables (void)
+gboolean
+nautilus_font_manager_file_is_scalable_font (const char *file_name)
{
- /* 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);
- }
+ gboolean is_scalable_font = FALSE;
+ char *uri;
+ GnomeVFSFileInfo *info;
+ GnomeVFSResult result;
+
+ g_return_val_if_fail (nautilus_strlen (file_name) > 0, FALSE);
+
+ uri = g_strconcat ("file://", file_name, NULL);
+
+ info = gnome_vfs_file_info_new ();
+ result = gnome_vfs_get_file_info (uri, info, GNOME_VFS_FILE_INFO_GET_MIME_TYPE);
+
+ if (result == GNOME_VFS_OK) {
+ is_scalable_font =
+ nautilus_istr_is_equal (info->mime_type, POSTSCRIPT_FONT_MIME_TYPE)
+ || nautilus_istr_is_equal (info->mime_type, TRUE_TYPE_FONT_MIME_TYPE);
}
- ensure_at_exit_handler ();
+ gnome_vfs_file_info_unref (info);
+ g_free (uri);
+
+ return is_scalable_font;
}
-/* Public */
-void
-nautilus_font_manager_for_each_font (NautilusFontManagerCallback callback,
- gpointer callback_data)
+typedef struct
{
- g_return_if_fail (callback != NULL);
+ const FontDescription *description;
+ char *found_file_name;
+} FindData;
- /* Ensure that all the font tables exist */
- ensure_fallback_font_table ();
- ensure_user_font_table ();
- ensure_system_font_tables ();
+static gboolean
+font_list_find_bold_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)
+{
+ FindData *data;
+
+ g_return_val_if_fail (font_file_name != NULL, FALSE);
+ g_return_val_if_fail (foundry != NULL, FALSE);
+ g_return_val_if_fail (family != NULL, FALSE);
+ g_return_val_if_fail (weight != NULL, FALSE);
+ g_return_val_if_fail (slant != NULL, FALSE);
+ g_return_val_if_fail (set_width != NULL, FALSE);
+ g_return_val_if_fail (char_set_registry != NULL, FALSE);
+ g_return_val_if_fail (char_set_encoding != NULL, FALSE);
+ g_return_val_if_fail (callback_data != NULL, FALSE);
+
+ data = callback_data;
+
+ g_return_val_if_fail (data->description != NULL, FALSE);
+ g_return_val_if_fail (data->found_file_name == NULL, FALSE);
+
+ if (nautilus_istr_is_equal (data->description->foundry, foundry)
+ && nautilus_istr_is_equal (data->description->family, family)
+ && nautilus_istr_is_equal (data->description->slant, slant)
+ && nautilus_istr_is_equal (data->description->set_width, set_width)
+ && nautilus_istr_is_equal (data->description->char_set_registry, char_set_registry)
+ && nautilus_istr_is_equal (data->description->char_set_encoding, char_set_encoding)
+ && nautilus_font_manager_weight_is_bold (weight)) {
+ data->found_file_name = g_strdup (font_file_name);
+ }
- 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);
+ return (data->found_file_name == NULL);
}
char *
-nautilus_font_manager_get_fallback_font (void)
+nautilus_font_manager_get_bold (const char *plain_font)
{
-#if 0
- const FontDescriptionTable *table;
+ FindData data;
- ensure_fallback_font_table ();
- g_return_val_if_fail (g_list_length (fallback_font_table) > 0, NULL);
+ g_return_val_if_fail (nautilus_strlen (plain_font) > 0, NULL);
+ g_return_val_if_fail (nautilus_font_manager_file_is_scalable_font (plain_font), NULL);
- table = g_list_nth_data (fallback_font_table, 0);
- g_return_val_if_fail (table != NULL, NULL);
+ ensure_global_font_table ();
- return font_description_table_get_nth_file_name (table, 0);
-#else
- return g_strdup ("/usr/share/fonts/default/Type1/n019003l.pfb");
-#endif
+ data.description = font_table_list_find (global_font_table, plain_font);
+
+ if (data.description == NULL) {
+ return g_strdup (plain_font);
+ }
+
+ data.found_file_name = NULL;
+ nautilus_font_manager_for_each_font (font_list_find_bold_callback, &data);
+
+ if (data.found_file_name != NULL) {
+ return data.found_file_name;
+ }
+
+ return g_strdup (plain_font);
+}
+
+gboolean
+nautilus_font_manager_weight_is_bold (const char *weight)
+{
+ g_return_val_if_fail (weight != NULL, FALSE);
+
+ return (nautilus_istr_is_equal (weight, "bold")
+ || nautilus_istr_is_equal (weight, "demibold")
+ || nautilus_istr_is_equal (weight, "black"));
}
#if !defined (NAUTILUS_OMIT_SELF_CHECK)
@@ -1082,14 +1234,11 @@ nautilus_self_check_font_manager (void)
NAUTILUS_CHECK_STRING_RESULT (call_chop_off_comments ("\\#foo bar"), "\\#foo bar");
NAUTILUS_CHECK_STRING_RESULT (call_chop_off_comments ("\\##foo bar"), "\\#");
- /* 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)) {
+ if (!g_file_exists (TEST_FONT_DIR)) {
return;
}
- font_manager_collect_font_tables ("/usr/share/fonts/default/Type1", &font_table_list);
+ font_manager_collect_font_tables (TEST_FONT_DIR, &font_table_list);
g_return_if_fail (font_table_list != NULL);
g_return_if_fail (g_list_nth_data (font_table_list, 0) != NULL);
diff --git a/libnautilus-private/nautilus-font-manager.h b/libnautilus-private/nautilus-font-manager.h
index 9c168ef5c..ce8213bc5 100644
--- a/libnautilus-private/nautilus-font-manager.h
+++ b/libnautilus-private/nautilus-font-manager.h
@@ -39,20 +39,25 @@ typedef enum {
/*
* A callback which can be invoked for each font available in the system.
*/
-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);
+typedef gboolean (*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_default_font (void);
+char * nautilus_font_manager_get_default_bold_font (void);
+gboolean nautilus_font_manager_file_is_scalable_font (const char *file_name);
+char * nautilus_font_manager_get_bold (const char *plain_font);
+char * nautilus_font_manager_get_italic (const char *plain_font);
+gboolean nautilus_font_manager_weight_is_bold (const char *weight);
END_GNOME_DECLS
diff --git a/libnautilus-private/nautilus-font-picker.c b/libnautilus-private/nautilus-font-picker.c
index ef6264540..bf520ea4a 100644
--- a/libnautilus-private/nautilus-font-picker.c
+++ b/libnautilus-private/nautilus-font-picker.c
@@ -32,6 +32,8 @@
#include "nautilus-string.h"
#include "nautilus-font-manager.h"
+#include <libgnome/gnome-i18n.h>
+
#include <gtk/gtklabel.h>
#include <gtk/gtkentry.h>
#include <gtk/gtksignal.h>
@@ -43,27 +45,83 @@
typedef struct {
char *name;
char *font_file_name;
-} FontStyle;
+} FontStyleEntry;
typedef struct {
- char *title;
- char *foundry;
- char *family;
char *name;
+ char *family;
+ char *name_for_display;
GList *style_list;
} FontEntry;
-static const char *black_listed_fonts[] = {
- "microsoft Webdings",
- "microsoft Wingdings",
- "monotype OCR",
- "URW Zapf Dingbats",
- "URW Symbol",
- "xfree86 cursor"
+/* These font families are black listed, because they
+ * arent useful at all to display "normal" text - at
+ * least in the context of Nautilus.
+ */
+static const char *black_listed_font_families[] = {
+ "Webdings",
+ "Wingdings",
+ "OCR",
+ "Zapf Dingbats",
+ "Symbol",
+ "cursor",
+
+ "mincho",
+ "gothic"
+};
+
+static const char *black_listed_font_foundries[] = {
+ "greek",
+ "grinet",
+ /* Abisource fonts are black listed because they
+ * appear to simply be copies of the URW fonts,
+ * and listing them would waste valuable font picker
+ * space for no purpose.
+ */
+ "Abisource"
+};
+
+typedef struct
+{
+ const char *name;
+ const char *mapped;
+} StyleMap;
+
+static const char *normal_style = N_("Normal");
+static const char *unknown_style = N_("Unknown");
+
+static const StyleMap font_weight_map[] = {
+ { "", NULL },
+ { "medium", NULL },
+ { "regular", NULL },
+ { "bold", N_("Bold") },
+ { "book", N_("Book") },
+ { "black", N_("Black") },
+ { "demibold", N_("Demibold") },
+ { "light", N_("Light") }
+};
+
+static const StyleMap font_slant_map[] = {
+ { "", NULL },
+ { "r", NULL },
+ { "i", N_("Italic"), },
+ { "o", N_("Oblique"), },
+ { "ri", N_("Reverse Italic"), },
+ { "ro", N_("Reverse Oblique"), },
+ { "ot", N_("Other"), }
+};
+
+static const StyleMap font_set_width_map[] = {
+ { "", NULL },
+ { "normal", NULL },
+ { "condensed", N_("Condensed"), },
+ { "semicondensed", N_("Semicondensed"), }
};
static const gint FONT_PICKER_SPACING = 10;
+static GList *global_font_list = NULL;
+
/* Signals */
typedef enum
{
@@ -75,35 +133,37 @@ struct NautilusFontPickerDetails
{
NautilusStringPicker *font_name_picker;
NautilusStringPicker *style_picker;
- GList *font_entry_list;
GtkWidget *title_label;
};
/* 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 font_picker_update (NautilusFontPicker *font_picker);
+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);
+
+/* Private methods */
+static void font_picker_update_styles (NautilusFontPicker *font_picker);
+static void font_picker_populate (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);
+static void font_picker_font_changed_callback (GtkWidget *string_picker,
+ gpointer callback_data);
+static void font_picker_style_changed_callback (GtkWidget *string_picker,
+ gpointer callback_data);
+
+/* Global font list */
+static const GList *global_font_list_get (void);
+static void global_font_list_free (void);
+static gboolean global_font_list_populate_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);
NAUTILUS_DEFINE_CLASS_BOILERPLATE (NautilusFontPicker, nautilus_font_picker, GTK_TYPE_VBOX)
@@ -163,12 +223,12 @@ nautilus_font_picker_initialize (NautilusFontPicker *font_picker)
gtk_signal_connect (GTK_OBJECT (font_picker->details->font_name_picker),
"changed",
- GTK_SIGNAL_FUNC (font_name_picker_changed_callback),
+ GTK_SIGNAL_FUNC (font_picker_font_changed_callback),
font_picker);
gtk_signal_connect (GTK_OBJECT (font_picker->details->style_picker),
"changed",
- GTK_SIGNAL_FUNC (style_picker_changed_callback),
+ GTK_SIGNAL_FUNC (font_picker_style_changed_callback),
font_picker);
gtk_widget_show (GTK_WIDGET (font_picker->details->font_name_picker));
@@ -176,14 +236,7 @@ nautilus_font_picker_initialize (NautilusFontPicker *font_picker)
gtk_widget_show (font_picker->details->title_label);
gtk_widget_show (hbox);
- /* Populate the font table */
- nautilus_font_manager_for_each_font (font_manager_callback, font_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);
-
- /* Update the font picker */
- font_picker_update (font_picker);;
+ font_picker_populate (font_picker);
}
/* GtkObjectClass methods */
@@ -203,45 +256,95 @@ nautilus_font_picker_destroy (GtkObject* object)
}
static FontEntry *
-font_entry_list_find (GList *font_entry_list,
- const char *font_name)
+font_list_find (const GList *font_list,
+ const char *font_name)
{
- while (font_entry_list != NULL) {
- FontEntry *entry;
- g_assert (font_entry_list->data != NULL);
- entry = font_entry_list->data;
+ const GList *node;
+ FontEntry *entry;
+
+ /* First check the foundry qualified font names */
+ for (node = font_list; node != NULL; node = node->next) {
+ g_assert (node->data != NULL);
+ entry = node->data;
+
if (nautilus_istr_is_equal (font_name, entry->name)) {
return entry;
}
-
- font_entry_list = font_entry_list->next;
}
-
+
+ /* First check the foundry qualified font names */
+ for (node = font_list; node != NULL; node = node->next) {
+ g_assert (node->data != NULL);
+ entry = node->data;
+
+ if (nautilus_istr_is_equal (font_name, entry->family)) {
+ return entry;
+ }
+ }
+
return NULL;
}
static void
-font_picker_update (NautilusFontPicker *font_picker)
+font_picker_update_styles (NautilusFontPicker *font_picker)
{
+ const GList *font_list;
char *selected_font;
- const FontEntry *entry;
-
+ const FontEntry *font_entry;
+ const FontStyleEntry *style_entry;
+ const GList *node;
+
g_return_if_fail (NAUTILUS_IS_FONT_PICKER (font_picker));
selected_font = nautilus_string_picker_get_selected_string (font_picker->details->font_name_picker);
- entry = font_entry_list_find (font_picker->details->font_entry_list, selected_font);
- g_return_if_fail (entry != NULL);
+ font_list = global_font_list_get ();
+ g_assert (font_list != NULL);
+
+ font_entry = font_list_find (font_list, selected_font);
+ g_return_if_fail (font_entry != NULL);
nautilus_string_picker_clear (font_picker->details->style_picker);
-
- g_list_foreach (entry->style_list, style_list_for_each_callback, font_picker);
-
+
+ for (node = font_entry->style_list; node != NULL; node = node->next) {
+ g_assert (node->data != NULL);
+ style_entry = node->data;
+ nautilus_string_picker_insert_string (font_picker->details->style_picker,
+ style_entry->name);
+ }
+
g_free (selected_font);
}
static void
-font_name_picker_changed_callback (GtkWidget *string_picker,
+font_picker_populate (NautilusFontPicker *font_picker)
+{
+ const GList *font_list;
+ const GList *node;
+ const FontEntry *font_entry;
+
+ g_return_if_fail (NAUTILUS_IS_FONT_PICKER (font_picker));
+
+ font_list = global_font_list_get ();
+ g_assert (font_list != NULL);
+
+ nautilus_string_picker_clear (font_picker->details->font_name_picker);
+
+ for (node = font_list; node != NULL; node = node->next) {
+ g_assert (node->data != NULL);
+ font_entry = node->data;
+
+ nautilus_string_picker_insert_string (font_picker->details->font_name_picker,
+ font_entry->name_for_display);
+ }
+
+ /* Update the styles picker */
+ font_picker_update_styles (font_picker);;
+}
+
+/* Callbacks */
+static void
+font_picker_font_changed_callback (GtkWidget *string_picker,
gpointer callback_data)
{
NautilusFontPicker *font_picker;
@@ -251,16 +354,16 @@ font_name_picker_changed_callback (GtkWidget *string_picker,
font_picker = NAUTILUS_FONT_PICKER (callback_data);
- font_picker_update (font_picker);
+ font_picker_update_styles (font_picker);
gtk_signal_emit (GTK_OBJECT (font_picker), font_picker_signals[CHANGED]);
}
static void
-style_picker_changed_callback (GtkWidget *string_picker, gpointer callback_data)
+font_picker_style_changed_callback (GtkWidget *string_picker, gpointer callback_data)
{
- NautilusFontPicker *font_picker;
-
+ NautilusFontPicker *font_picker;
+
g_return_if_fail (NAUTILUS_IS_FONT_PICKER (callback_data));
g_return_if_fail (NAUTILUS_IS_STRING_PICKER (string_picker));
@@ -269,21 +372,43 @@ style_picker_changed_callback (GtkWidget *string_picker, gpointer callback_data)
gtk_signal_emit (GTK_OBJECT (font_picker), font_picker_signals[CHANGED]);
}
+static const char *
+font_find_style (const StyleMap *style_map,
+ guint num_styles,
+ const char *style)
+{
+ guint i;
+
+ g_return_val_if_fail (style_map != NULL, NULL);
+ g_return_val_if_fail (num_styles > 0, NULL);
+ g_return_val_if_fail (style != NULL, NULL);
+
+ for (i = 0; i < num_styles; i++) {
+ if (nautilus_istr_is_equal (style, style_map[i].name)) {
+ return _(style_map[i].mapped);
+ }
+ }
+
+ return NULL;
+}
+
static gboolean
-ignore_font (const char *font_file_name,
- const char *foundry,
- const char *family,
- const char *entry_name)
+ignore_font (const char *foundry,
+ const char *family)
{
guint 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);
- for (i = 0; i < NAUTILUS_N_ELEMENTS (black_listed_fonts); i++) {
- if (nautilus_istr_is_equal (entry_name, black_listed_fonts[i])) {
+ for (i = 0; i < NAUTILUS_N_ELEMENTS (black_listed_font_families); i++) {
+ if (nautilus_istr_is_equal (family, black_listed_font_families[i])) {
+ return TRUE;
+ }
+ }
+
+ for (i = 0; i < NAUTILUS_N_ELEMENTS (black_listed_font_foundries); i++) {
+ if (nautilus_istr_is_equal (foundry, black_listed_font_foundries[i])) {
return TRUE;
}
}
@@ -291,92 +416,215 @@ ignore_font (const char *font_file_name,
return FALSE;
}
-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 char *
+font_make_name (const char *foundry,
+ const char *family)
{
- NautilusFontPicker *font_picker;
- char *entry_name;
- FontEntry *entry;
- FontStyle *style;
-
- 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));
+ g_return_val_if_fail (foundry != NULL, NULL);
+ g_return_val_if_fail (family != NULL, NULL);
+
+ return g_strdup_printf ("%s %s", foundry, family);
+}
- font_picker = NAUTILUS_FONT_PICKER (callback_data);
+static char *
+font_make_style (const char *weight,
+ const char *slant,
+ const char *set_width,
+ const char *char_set_registry,
+ const char *char_set_encoding)
+{
+ const char *mapped_weight;
+ const char *mapped_slant;
+ const char *mapped_set_width;
+
+ g_return_val_if_fail (weight != NULL, NULL);
+ g_return_val_if_fail (slant != NULL, NULL);
+ g_return_val_if_fail (set_width != NULL, NULL);
+ g_return_val_if_fail (char_set_registry != NULL, NULL);
+ g_return_val_if_fail (char_set_encoding != NULL, NULL);
+
+ mapped_weight = font_find_style (font_weight_map,
+ NAUTILUS_N_ELEMENTS (font_weight_map),
+ weight);
+
+ mapped_slant = font_find_style (font_slant_map,
+ NAUTILUS_N_ELEMENTS (font_slant_map),
+ slant);
+
+ mapped_set_width = font_find_style (font_set_width_map,
+ NAUTILUS_N_ELEMENTS (font_set_width_map),
+ set_width);
+
+ if (mapped_weight != NULL) {
+ /* "abnormal" weight */
+ if (mapped_slant == NULL && mapped_set_width == NULL) {
+ return g_strdup (mapped_weight);
+ } else if (mapped_slant != NULL && mapped_set_width != NULL) {
+ return g_strdup_printf ("%s %s %s", mapped_weight, mapped_slant, mapped_set_width);
+ } else if (mapped_slant != NULL) {
+ return g_strdup_printf ("%s %s", mapped_weight, mapped_slant);
+ }
- entry_name = g_strdup_printf ("%s %s", foundry, family);
+ return g_strdup_printf ("%s %s", mapped_weight, mapped_set_width);
+ } else {
+ /* normal weight */
+ if (mapped_slant == NULL && mapped_set_width == NULL) {
+ return g_strdup (_(normal_style));
+ } else if (mapped_slant != NULL && mapped_set_width != NULL) {
+ return g_strdup_printf ("%s %s", mapped_slant, mapped_set_width);
+ } else if (mapped_slant != NULL) {
+ return g_strdup_printf ("%s", mapped_slant);
+ }
+
+ return g_strdup_printf ("%s", mapped_set_width);
+ }
+
+ return g_strdup (_(unknown_style));
+}
- if (ignore_font (font_file_name, foundry, family, entry_name)) {
- g_free (entry_name);
+/* Global font list */
+static void
+global_font_list_free (void)
+{
+ GList *font_node;
+ FontEntry *font_entry;
+ GList *style_node;
+ FontStyleEntry *style_entry;
+
+ if (global_font_list == NULL) {
return;
}
- entry = font_entry_list_find (font_picker->details->font_entry_list, entry_name);
+ for (font_node = global_font_list; font_node != NULL; font_node = font_node->next) {
+ g_assert (font_node->data != NULL);
+ font_entry = font_node->data;
+
+ g_free (font_entry->name);
+ g_free (font_entry->family);
+ g_free (font_entry->name_for_display);
+
+ for (style_node = font_entry->style_list; style_node != NULL; style_node = style_node->next) {
+ g_assert (style_node->data != NULL);
+ style_entry = style_node->data;
+ g_free (style_entry->name);
+ g_free (style_entry->font_file_name);
+ g_free (style_entry);
+ }
+ g_list_free (font_entry->style_list);
- 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_free (font_entry);
}
- g_assert (entry != NULL);
- g_assert (font_entry_list_find (font_picker->details->font_entry_list, entry_name) == entry);
- g_free (entry_name);
+
+ global_font_list = NULL;
+}
+
+static guint
+font_list_count_families (const GList *font_list,
+ const char *family)
+{
+ guint count = 0;
+ const GList *node;
+ const FontEntry *entry;
+
+ g_return_val_if_fail (font_list != NULL, 0);
+ g_return_val_if_fail (family != NULL, 0);
- 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);
+ for (node = font_list; node != NULL; node = node->next) {
+ g_assert (node->data != NULL);
+ entry = node->data;
- entry->style_list = g_list_append (entry->style_list, style);
+ if (nautilus_istr_is_equal (family, entry->family)) {
+ count++;
+ }
+ }
+
+ return count;
}
-static void
-style_list_for_each_callback (gpointer data,
- gpointer callback_data)
+static const GList *
+global_font_list_get (void)
{
- NautilusFontPicker *font_picker;
- FontStyle *style;
+ guint family_count = 0;
+ GList *node;
+ FontEntry *entry;
- g_return_if_fail (data != NULL);
- g_return_if_fail (NAUTILUS_IS_FONT_PICKER (callback_data));
+ if (global_font_list != NULL) {
+ return global_font_list;
+ }
- style = data;
- font_picker = NAUTILUS_FONT_PICKER (callback_data);
+ nautilus_font_manager_for_each_font (global_font_list_populate_callback, &global_font_list);
+ g_assert (global_font_list != NULL);
+
+ for (node = global_font_list; node != NULL; node = node->next) {
+ g_assert (node->data != NULL);
+ entry = node->data;
+
+ g_assert (entry->name_for_display == NULL);
+
+ family_count = font_list_count_families (global_font_list, entry->family);
+ g_assert (family_count > 0);
+
+ entry->name_for_display = (family_count > 1) ? g_strdup (entry->name) : g_strdup (entry->family);
+ }
- nautilus_string_picker_insert_string (font_picker->details->style_picker, style->name);
+ g_atexit (global_font_list_free);
+
+ return global_font_list;
}
-static void
-font_entry_list_for_each_callback (gpointer data,
- gpointer callback_data)
+
+static gboolean
+global_font_list_populate_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;
+ GList **font_list;
+ char *entry_name;
FontEntry *entry;
+ FontStyleEntry *style;
+
+ g_return_val_if_fail (font_file_name != NULL, FALSE);
+ g_return_val_if_fail (foundry != NULL, FALSE);
+ g_return_val_if_fail (family != NULL, FALSE);
+ g_return_val_if_fail (weight != NULL, FALSE);
+ g_return_val_if_fail (slant != NULL, FALSE);
+ g_return_val_if_fail (set_width != NULL, FALSE);
+ g_return_val_if_fail (char_set_registry != NULL, FALSE);
+ g_return_val_if_fail (char_set_encoding != NULL, FALSE);
+ g_return_val_if_fail (callback_data != NULL, FALSE);
+
+ font_list = callback_data;
+
+ if (ignore_font (foundry, family)) {
+ return TRUE;
+ }
- g_return_if_fail (data != NULL);
- g_return_if_fail (NAUTILUS_IS_FONT_PICKER (callback_data));
+ entry_name = font_make_name (foundry, family);
+ entry = font_list_find (*font_list, entry_name);
- font_picker = NAUTILUS_FONT_PICKER (callback_data);
+ if (entry == NULL) {
+ entry = g_new0 (FontEntry, 1);
+ entry->name = g_strdup (entry_name);
+ entry->family = g_strdup (family);
+ *font_list = g_list_append (*font_list, entry);
+ }
+ g_assert (entry != NULL);
+ g_assert (font_list_find (*font_list, entry_name) == entry);
+ g_free (entry_name);
- entry = data;
- nautilus_string_picker_insert_string (font_picker->details->font_name_picker,
- entry->name);
+ style = g_new0 (FontStyleEntry, 1);
+ style->name = font_make_style (weight, slant, set_width, char_set_registry, char_set_encoding);
+ style->font_file_name = g_strdup (font_file_name);
+
+ entry->style_list = g_list_append (entry->style_list, style);
+
+ return TRUE;
}
/* NautilusFontPicker public methods */
@@ -389,13 +637,17 @@ nautilus_font_picker_new (void)
char *
nautilus_font_picker_get_selected_font (const NautilusFontPicker *font_picker)
{
+ const GList *font_list;
char *result = NULL;
char *selected_font;
char *selected_style;
const FontEntry *entry;
- GList *node;
+ const GList *node;
g_return_val_if_fail (NAUTILUS_IS_FONT_PICKER (font_picker), NULL);
+
+ font_list = global_font_list_get ();
+ g_assert (font_list != NULL);
selected_font = nautilus_string_picker_get_selected_string (font_picker->details->font_name_picker);
g_return_val_if_fail (selected_font != NULL, NULL);
@@ -403,12 +655,12 @@ nautilus_font_picker_get_selected_font (const NautilusFontPicker *font_picker)
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);
+ entry = font_list_find (font_list, selected_font);
g_return_val_if_fail (entry != NULL, NULL);
node = entry->style_list;
while (node != NULL && result == NULL) {
- const FontStyle *style;
+ const FontStyleEntry *style;
g_assert (node->data != NULL);
style = node->data;
@@ -428,14 +680,18 @@ void
nautilus_font_picker_set_selected_font (NautilusFontPicker *font_picker,
const char *font_name)
{
+ const GList *font_list;
const FontEntry *entry;
- const FontStyle *style;
- GList *font_list_node;
- GList *style_list_node;
+ const FontStyleEntry *style;
+ const GList *font_list_node;
+ const GList *style_list_node;
g_return_if_fail (NAUTILUS_IS_FONT_PICKER (font_picker));
+
+ font_list = global_font_list_get ();
+ g_assert (font_list != NULL);
- font_list_node = font_picker->details->font_entry_list;
+ font_list_node = font_list;
while (font_list_node != NULL) {
g_assert (font_list_node->data != NULL);
entry = font_list_node->data;
@@ -447,8 +703,8 @@ nautilus_font_picker_set_selected_font (NautilusFontPicker *font_picker,
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);
+ entry->name_for_display);
+ font_picker_update_styles (font_picker);
gtk_signal_emit (GTK_OBJECT (font_picker), font_picker_signals[CHANGED]);
return;
}
diff --git a/libnautilus-private/nautilus-global-preferences.c b/libnautilus-private/nautilus-global-preferences.c
index 1ca75b872..18e7f89b0 100644
--- a/libnautilus-private/nautilus-global-preferences.c
+++ b/libnautilus-private/nautilus-global-preferences.c
@@ -26,19 +26,21 @@
#include "nautilus-global-preferences.h"
#include "nautilus-file-utilities.h"
+#include "nautilus-font-manager.h"
#include "nautilus-glib-extensions.h"
#include "nautilus-gtk-extensions.h"
+#include "nautilus-medusa-support.h"
#include "nautilus-preferences-dialog.h"
#include "nautilus-preferences-group.h"
#include "nautilus-preferences-item.h"
+#include "nautilus-scalable-font.h"
#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>
#include <libgnome/gnome-i18n.h>
+#include <libgnome/gnome-util.h>
#include <liboaf/liboaf.h>
#include <libgnomevfs/gnome-vfs-utils.h>
@@ -1106,19 +1108,19 @@ global_preferences_install_home_location_defaults (void)
static void
global_preferences_install_font_defaults (void)
{
- char *fallback_smooth_font;
+ char *default_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 ();
+ default_smooth_font = nautilus_font_manager_get_default_font ();
nautilus_preferences_default_set_string (NAUTILUS_PREFERENCES_DIRECTORY_VIEW_SMOOTH_FONT,
NAUTILUS_USER_LEVEL_NOVICE,
- fallback_smooth_font);
- g_free (fallback_smooth_font);
+ default_smooth_font);
+ g_free (default_smooth_font);
}
static void
@@ -1209,6 +1211,25 @@ nautilus_global_preferences_set_dialog_title (const char *title)
gtk_window_set_title (GTK_WINDOW (dialog), title);
}
+NautilusScalableFont *
+nautilus_global_preferences_get_smooth_font (void)
+{
+ NautilusScalableFont *scalable_font;
+ char *font_file_name;
+
+ font_file_name = nautilus_preferences_get (NAUTILUS_PREFERENCES_DIRECTORY_VIEW_SMOOTH_FONT);
+
+ scalable_font =
+ (font_file_name && g_file_exists (font_file_name)) ?
+ nautilus_scalable_font_new (font_file_name) :
+ nautilus_scalable_font_get_default_font ();
+ g_free (font_file_name);
+
+ g_assert (NAUTILUS_IS_SCALABLE_FONT (scalable_font));
+
+ return scalable_font;
+}
+
void
nautilus_global_preferences_initialize (void)
{
diff --git a/libnautilus-private/nautilus-global-preferences.h b/libnautilus-private/nautilus-global-preferences.h
index 661dd680e..2416de3b7 100644
--- a/libnautilus-private/nautilus-global-preferences.h
+++ b/libnautilus-private/nautilus-global-preferences.h
@@ -136,13 +136,14 @@ typedef enum
/* Gnome session management */
#define NAUTILUS_PREFERENCES_ADD_TO_SESSION "preferences/add_to_session"
-void nautilus_global_preferences_initialize (void);
-void nautilus_global_preferences_show_dialog (void);
-void nautilus_global_preferences_hide_dialog (void);
-void nautilus_global_preferences_set_dialog_title (const char *title);
+void nautilus_global_preferences_initialize (void);
+void nautilus_global_preferences_show_dialog (void);
+void nautilus_global_preferences_hide_dialog (void);
+void nautilus_global_preferences_set_dialog_title (const char *title);
/* Sidebar */
-GList *nautilus_global_preferences_get_enabled_sidebar_panel_view_identifiers (void);
+GList * nautilus_global_preferences_get_enabled_sidebar_panel_view_identifiers (void);
+struct NautilusScalableFont *nautilus_global_preferences_get_smooth_font (void);
END_GNOME_DECLS
diff --git a/libnautilus-private/nautilus-icon-container.c b/libnautilus-private/nautilus-icon-container.c
index 0f69b7f5b..367d39988 100644
--- a/libnautilus-private/nautilus-icon-container.c
+++ b/libnautilus-private/nautilus-icon-container.c
@@ -47,6 +47,7 @@
#include <gtk/gtksignal.h>
#include <gtk/gtklayout.h>
#include <libgnomeui/gnome-canvas-rect-ellipse.h>
+#include <libgnome/gnome-i18n.h>
#include <libnautilus/nautilus-clipboard.h>
#include <math.h>
#include <stdio.h>
@@ -3315,13 +3316,14 @@ nautilus_icon_container_initialize (NautilusIconContainer *container)
/* font table - this isn't exactly proportional, but it looks better than computed */
/* FIXME bugzilla.eazel.com 5093: Font name is hard-coded here. */
/* FIXME bugzilla.eazel.com 5101: Font size is hard-coded here. */
- details->label_font[NAUTILUS_ZOOM_LEVEL_SMALLEST] = nautilus_font_factory_get_font_by_family ("helvetica", 8);
- details->label_font[NAUTILUS_ZOOM_LEVEL_SMALLER] = nautilus_font_factory_get_font_by_family ("helvetica", 8);
- details->label_font[NAUTILUS_ZOOM_LEVEL_SMALL] = nautilus_font_factory_get_font_by_family ("helvetica", 10);
- details->label_font[NAUTILUS_ZOOM_LEVEL_STANDARD] = nautilus_font_factory_get_font_by_family ("helvetica", 12);
- details->label_font[NAUTILUS_ZOOM_LEVEL_LARGE] = nautilus_font_factory_get_font_by_family ("helvetica", 14);
- details->label_font[NAUTILUS_ZOOM_LEVEL_LARGER] = nautilus_font_factory_get_font_by_family ("helvetica", 18);
- details->label_font[NAUTILUS_ZOOM_LEVEL_LARGEST] = nautilus_font_factory_get_font_by_family ("helvetica", 18);
+ /* FIXME bugzilla.eazel.com xxxx: Fonts marked for localization in disparate places. */
+ details->label_font[NAUTILUS_ZOOM_LEVEL_SMALLEST] = nautilus_font_factory_get_font_by_family (_("helvetica"), 8);
+ details->label_font[NAUTILUS_ZOOM_LEVEL_SMALLER] = nautilus_font_factory_get_font_by_family (_("helvetica"), 8);
+ details->label_font[NAUTILUS_ZOOM_LEVEL_SMALL] = nautilus_font_factory_get_font_by_family (_("helvetica"), 10);
+ details->label_font[NAUTILUS_ZOOM_LEVEL_STANDARD] = nautilus_font_factory_get_font_by_family (_("helvetica"), 12);
+ details->label_font[NAUTILUS_ZOOM_LEVEL_LARGE] = nautilus_font_factory_get_font_by_family (_("helvetica"), 14);
+ details->label_font[NAUTILUS_ZOOM_LEVEL_LARGER] = nautilus_font_factory_get_font_by_family (_("helvetica"), 18);
+ details->label_font[NAUTILUS_ZOOM_LEVEL_LARGEST] = nautilus_font_factory_get_font_by_family (_("helvetica"), 18);
details->smooth_label_font = nautilus_scalable_font_get_default_font ();
diff --git a/libnautilus-private/nautilus-program-chooser.c b/libnautilus-private/nautilus-program-chooser.c
index 7183d82a2..35e69efe0 100644
--- a/libnautilus-private/nautilus-program-chooser.c
+++ b/libnautilus-private/nautilus-program-chooser.c
@@ -193,10 +193,10 @@ program_file_pair_get_program_name_for_display (ProgramFilePair *pair)
|| pair->view_identifier != NULL);
if (pair->action_type == GNOME_VFS_MIME_ACTION_TYPE_COMPONENT) {
- return g_strdup (pair->view_identifier->view_as_label);
+ return g_strdup (_(pair->view_identifier->view_as_label));
}
- return g_strdup (pair->application->name);
+ return g_strdup (_(pair->application->name));
}
static char *
diff --git a/libnautilus-private/nautilus-scalable-font.c b/libnautilus-private/nautilus-scalable-font.c
index b1c4a516d..4e9a92e3a 100644
--- a/libnautilus-private/nautilus-scalable-font.c
+++ b/libnautilus-private/nautilus-scalable-font.c
@@ -25,63 +25,33 @@
#include <config.h>
#include "nautilus-scalable-font-private.h"
-#include "nautilus-gtk-macros.h"
-#include "nautilus-gdk-extensions.h"
-#include "nautilus-gdk-pixbuf-extensions.h"
#include "nautilus-background.h"
-#include "nautilus-string.h"
-#include "nautilus-file-utilities.h"
-#include "nautilus-glib-extensions.h"
-#include "nautilus-string-map.h"
-#include "nautilus-lib-self-check-functions.h"
+#include "nautilus-font-manager.h"
+#include "nautilus-gdk-pixbuf-extensions.h"
#include "nautilus-glyph.h"
-
+#include "nautilus-gtk-macros.h"
+#include "nautilus-lib-self-check-functions.h"
+#include "nautilus-global-preferences.h"
+#include "nautilus-string.h"
#include <librsvg/rsvg-ft.h>
-
-#include <stdio.h>
#include <libgnome/gnome-util.h>
-#include <ctype.h>
-
-/* FontEntry */
-typedef struct {
- char *weight;
- char *slant;
- char *set_width;
- RsvgFTFontHandle font_handle;
- char *path;
-} FontEntry;
-
-/* FontFamilyEntry */
-typedef struct {
- char *family;
- GList *fonts;
-} FontFamilyEntry;
/* Detail member struct */
-struct _NautilusScalableFontDetail
+struct NautilusScalableFontDetails
{
RsvgFTFontHandle font_handle;
- const FontFamilyEntry *font_family_entry;
- const FontEntry *font_entry;
+ char *font_file_name;
};
/* Global things */
-static GHashTable *global_font_family_table = NULL;
static RsvgFTCtx *global_rsvg_ft_context = NULL;
-static NautilusScalableFont *global_default_font = NULL;
-static NautilusStringMap *global_family_string_map = NULL;
+static GHashTable *global_font_handle_table = NULL;
/* GtkObjectClass methods */
-static void nautilus_scalable_font_initialize_class (NautilusScalableFontClass *font_class);
-static void nautilus_scalable_font_initialize (NautilusScalableFont *font);
-static void nautilus_scalable_font_destroy (GtkObject *object);
-static void initialize_global_stuff_if_needed (void);
-
-
-/* 'atexit' destructors for global stuff */
-static void default_font_at_exit_destructor (void);
-static void font_family_table_at_exit_destructor (void);
-static void font_family_string_map_at_exit_destructor (void);
+static void nautilus_scalable_font_initialize_class (NautilusScalableFontClass *font_class);
+static void nautilus_scalable_font_initialize (NautilusScalableFont *font);
+static void nautilus_scalable_font_destroy (GtkObject *object);
+static void initialize_global_stuff_if_needed (void);
NAUTILUS_DEFINE_CLASS_BOILERPLATE (NautilusScalableFont, nautilus_scalable_font, GTK_TYPE_OBJECT)
@@ -89,7 +59,7 @@ NAUTILUS_DEFINE_CLASS_BOILERPLATE (NautilusScalableFont, nautilus_scalable_font,
static void
nautilus_scalable_font_initialize_class (NautilusScalableFontClass *font_class)
{
- GtkObjectClass *object_class = GTK_OBJECT_CLASS (font_class);
+ GtkObjectClass *object_class = GTK_OBJECT_CLASS (font_class);
initialize_global_stuff_if_needed ();
@@ -100,9 +70,9 @@ nautilus_scalable_font_initialize_class (NautilusScalableFontClass *font_class)
void
nautilus_scalable_font_initialize (NautilusScalableFont *font)
{
- font->detail = g_new0 (NautilusScalableFontDetail, 1);
+ font->details = g_new0 (NautilusScalableFontDetails, 1);
- font->detail->font_handle = NAUTILUS_SCALABLE_FONT_UNDEFINED_HANDLE;
+ font->details->font_handle = NAUTILUS_SCALABLE_FONT_UNDEFINED_HANDLE;
}
/* GtkObjectClass methods */
@@ -116,515 +86,30 @@ nautilus_scalable_font_destroy (GtkObject *object)
font = NAUTILUS_SCALABLE_FONT (object);
- g_free (font->detail);
-
+ g_free (font->details->font_file_name);
+ g_free (font->details);
+
/* Chain destroy */
NAUTILUS_CALL_PARENT (GTK_OBJECT_CLASS, destroy, (object));
}
-static char *
-file_as_string (const char *file_name)
-{
- struct stat stat_info;
- FILE *stream;
- char *result;
- size_t num_read;
-
- g_return_val_if_fail (file_name != NULL, NULL);
- g_return_val_if_fail (g_file_exists (file_name), NULL);
-
- if (stat (file_name, &stat_info) != 0) {
- return NULL;
- }
-
- if (stat_info.st_size == 0) {
- return NULL;
- }
-
- stream = fopen (file_name, "r");
-
- if (!stream) {
- return NULL;
- }
-
- result = g_malloc (sizeof (char) * stat_info.st_size + 1);
-
- num_read = fread (result, sizeof (char), stat_info.st_size, stream);
-
- fclose (stream);
-
- if ((ssize_t)num_read != stat_info.st_size) {
- g_free (result);
- return NULL;
- }
-
- result[stat_info.st_size] = '\0';
-
- return result;
-}
-
-static gboolean
-parse_font_description_file (const char *directory,
- NautilusStringList **font_pfb_list_out,
- NautilusStringList **font_xfld_list_out)
-{
- char *fonts_dir_path;
- char *fonts_dir_content;
- NautilusStringList *tokenized_list;
- int i;
- int count;
-
- g_return_val_if_fail (directory != NULL, FALSE);
- g_return_val_if_fail (g_file_exists (directory), FALSE);
- g_return_val_if_fail (font_pfb_list_out != NULL, FALSE);
- g_return_val_if_fail (font_xfld_list_out != NULL, FALSE);
-
- *font_pfb_list_out = NULL;
- *font_xfld_list_out = NULL;
-
- fonts_dir_path = g_strdup_printf ("%s/%s", directory, "fonts.dir");
- fonts_dir_content = file_as_string (fonts_dir_path);
- g_free (fonts_dir_path);
-
- if (fonts_dir_content == NULL) {
- return FALSE;
- }
-
- tokenized_list = nautilus_string_list_new_from_tokens (fonts_dir_content, "\n", FALSE);
- g_free (fonts_dir_content);
-
- if (tokenized_list == NULL) {
- return FALSE;
- }
-
- if (nautilus_string_list_get_length (tokenized_list) <= 1) {
- nautilus_string_list_free (tokenized_list);
- return FALSE;
- }
-
- if (!nautilus_eat_str_to_int (nautilus_string_list_nth (tokenized_list, 0), &count)) {
- return FALSE;
- }
-
- *font_pfb_list_out = nautilus_string_list_new (FALSE);
- *font_xfld_list_out = nautilus_string_list_new (FALSE);
-
- for (i = 0; i < count; i++) {
- char *line = nautilus_string_list_nth (tokenized_list, i + 1);
-
- if (line != NULL) {
- char *delimeter;
-
- /* Look for the delimiting space */
- delimeter = strstr (line, " ");
- if (delimeter != NULL) {
-
- char *font_pfb;
- char *font_pfb_path;
- int pfb_length;
-
- pfb_length = delimeter - line;
- font_pfb = g_malloc (sizeof (char) * pfb_length + 1);
- strncpy (font_pfb, line, pfb_length);
- font_pfb[pfb_length] = '\0';
-
- font_pfb_path = g_strdup_printf ("%s/%s", directory, font_pfb);
-
- /* Make sure the pfb file exists */
- if (g_file_exists (font_pfb_path)) {
- while (isspace (*delimeter)) {
- delimeter++;
- }
-
- nautilus_string_list_insert (*font_pfb_list_out, font_pfb_path);
- nautilus_string_list_insert (*font_xfld_list_out, delimeter);
- }
-
- g_free (font_pfb);
- g_free (font_pfb_path);
- }
-
- g_free (line);
- }
- }
-
- nautilus_string_list_free (tokenized_list);
-
- return TRUE;
-}
-
-/*
- * FontEntry things
- */
-static FontEntry*
-font_entry_new (const char *weight,
- const char *slant,
- const char *set_width,
- const char *path)
-{
- FontEntry *entry;
-
- g_return_val_if_fail (weight != NULL, NULL);
- g_return_val_if_fail (slant != NULL, NULL);
- g_return_val_if_fail (set_width != NULL, NULL);
- g_return_val_if_fail (path != NULL, NULL);
-
- entry = g_new (FontEntry, 1);
-
- entry->weight = g_strdup (weight);
- entry->slant = g_strdup (slant);
- entry->set_width = g_strdup (set_width);
- entry->path = g_strdup (path);
- entry->font_handle = NAUTILUS_SCALABLE_FONT_UNDEFINED_HANDLE;
-
- return entry;
-}
-
-static void
-font_entry_free (FontEntry* entry)
-{
- g_return_if_fail (entry != NULL);
-
- g_free (entry->weight);
- g_free (entry->slant);
- g_free (entry->set_width);
- g_free (entry->path);
-
- /* These fonts arent refcounted because they are catched internally by librsvg */
- entry->font_handle = NAUTILUS_SCALABLE_FONT_UNDEFINED_HANDLE;
-
- g_free (entry);
-}
-
-/*
- * FontFamilyEntry things
- */
-static FontFamilyEntry*
-font_family_new (const char *family)
-{
- FontFamilyEntry *entry;
-
- g_return_val_if_fail (family != NULL, NULL);
-
- entry = g_new (FontFamilyEntry, 1);
-
- entry->family = g_strdup (family);
- g_strdown (entry->family);
- entry->fonts = NULL;
-
- return entry;
-}
-
-static void
-free_font_entry (gpointer data, gpointer user_data)
-{
- font_entry_free ((FontEntry*) data);
-}
-
-static void
-font_family_free (FontFamilyEntry* entry)
-{
- g_return_if_fail (entry != NULL);
-
- g_free (entry->family);
-
- nautilus_g_list_free_deep_custom (entry->fonts, free_font_entry, NULL);
- entry->fonts = NULL;
-
- g_free (entry);
-}
-
-static void
-font_family_insert_font (FontFamilyEntry *family_entry, FontEntry *font_entry)
-{
- g_return_if_fail (family_entry != NULL);
- g_return_if_fail (font_entry != NULL);
-
- family_entry->fonts = g_list_append (family_entry->fonts, (gpointer) font_entry);
-}
-
-#define EQUAL 0
-#define NOT_EQUAL 1
-
-static gint
-font_compare (gconstpointer a,
- gconstpointer b)
-{
- FontEntry *font_entry_a = (FontEntry *) a;
- FontEntry *font_entry_b = (FontEntry *) b;
-
- g_return_val_if_fail (font_entry_a != NULL, NOT_EQUAL);
- g_return_val_if_fail (font_entry_b != NULL, NOT_EQUAL);
-
- g_return_val_if_fail (font_entry_a->weight != NULL, NOT_EQUAL);
- g_return_val_if_fail (font_entry_a->slant != NULL, NOT_EQUAL);
- g_return_val_if_fail (font_entry_a->set_width != NULL, NOT_EQUAL);
- g_return_val_if_fail (font_entry_b->weight != NULL, NOT_EQUAL);
- g_return_val_if_fail (font_entry_b->slant != NULL, NOT_EQUAL);
- g_return_val_if_fail (font_entry_b->set_width != NULL, NOT_EQUAL);
-
- return (nautilus_str_is_equal (font_entry_a->weight, font_entry_b->weight)
- && nautilus_str_is_equal (font_entry_a->slant, font_entry_b->slant)
- && nautilus_str_is_equal (font_entry_a->set_width, font_entry_b->set_width)) ? EQUAL : NOT_EQUAL;
-}
-
-static FontEntry*
-font_family_find_font (const FontFamilyEntry *family_entry,
- const char *weight,
- const char *slant,
- const char *set_width)
-{
- FontEntry fake_font_entry;
-
- GList *node;
-
- g_return_val_if_fail (family_entry != NULL, NULL);
- g_return_val_if_fail (weight != NULL, NULL);
- g_return_val_if_fail (slant != NULL, NULL);
- g_return_val_if_fail (set_width != NULL, NULL);
-
- fake_font_entry.weight = (char *) weight;
- fake_font_entry.slant = (char *) slant;
- fake_font_entry.set_width = (char *) set_width;
-
- node = g_list_find_custom (family_entry->fonts, &fake_font_entry, font_compare);
-
- return node ? node->data : NULL;
-}
-
-static FontFamilyEntry *
-font_family_lookup (GHashTable *font_family_table,
- const char *family)
-{
- gpointer value;
-
- g_return_val_if_fail (font_family_table != NULL, NULL);
- g_return_val_if_fail (family != NULL, NULL);
-
- value = g_hash_table_lookup (font_family_table, (gconstpointer) family);
-
- return (FontFamilyEntry *) value;
-}
-
-static FontFamilyEntry *
-font_family_lookup_with_insertion (GHashTable *font_family_table,
- const char *family)
-{
- FontFamilyEntry *entry;
-
- g_return_val_if_fail (font_family_table != NULL, NULL);
- g_return_val_if_fail (family != NULL, NULL);
-
- entry = g_hash_table_lookup (font_family_table, (gconstpointer) family);
-
- if (entry == NULL) {
-
- entry = font_family_new (family);
-
- g_hash_table_insert (font_family_table, entry->family, entry);
- }
-
- return entry;
-}
-
-static void
-font_family_table_add_fonts (GHashTable *font_family_table,
- const char *font_path)
-{
- NautilusStringList *font_pfb_list = NULL;
- NautilusStringList *font_xfld_list = NULL;
- guint i;
-
- g_return_if_fail (font_family_table != NULL);
- g_return_if_fail (font_path != NULL);
-
- if (!g_file_exists (font_path)) {
- return;
- }
-
- if (!parse_font_description_file (font_path, &font_pfb_list, &font_xfld_list)) {
- return;
- }
-
- if (nautilus_string_list_get_length (font_pfb_list) != nautilus_string_list_get_length (font_xfld_list)) {
- nautilus_string_list_free (font_pfb_list);
- nautilus_string_list_free (font_xfld_list);
- return;
- }
-
- for (i = 0; i < nautilus_string_list_get_length (font_pfb_list); i++) {
- NautilusStringList *tokenized_xfld;
- char *path;
- char *xfld;
- char *foundry;
- char *family;
- char *weight;
- char *slant;
- char *set_width;
- FontFamilyEntry *family_entry;
- FontEntry *font_entry;
-
- path = nautilus_string_list_nth (font_pfb_list, i);
- g_assert (path != NULL);
-
- xfld = nautilus_string_list_nth (font_xfld_list, i);
- g_assert (xfld != NULL);
-
- tokenized_xfld = nautilus_string_list_new_from_tokens (xfld, "-", FALSE);
-
- foundry = nautilus_string_list_nth (tokenized_xfld, 1);
- family = nautilus_string_list_nth (tokenized_xfld, 2);
- g_strdown (family);
- weight = nautilus_string_list_nth (tokenized_xfld, 3);
- slant = nautilus_string_list_nth (tokenized_xfld, 4);
- set_width = nautilus_string_list_nth (tokenized_xfld, 5);
-
- family_entry = font_family_lookup_with_insertion (font_family_table, family);
- g_assert (family_entry != NULL);
-
- font_entry = font_family_find_font (family_entry, weight, slant, set_width);
-
- if (font_entry != NULL) {
- g_warning ("Dude, the font '%s-%s-%s-%s' already exists", family, weight, slant, set_width);
- }
- else {
- font_entry = font_entry_new (weight, slant, set_width, path);
-
- font_family_insert_font (family_entry, font_entry);
- }
-
- nautilus_string_list_free (tokenized_xfld);
- g_free (foundry);
- g_free (family);
- g_free (weight);
- g_free (slant);
- g_free (set_width);
-
- g_free (path);
- g_free (xfld);
- }
-
- nautilus_string_list_free (font_pfb_list);
- nautilus_string_list_free (font_xfld_list);
-}
-
-static NautilusStringMap *
-font_family_string_map_new (void)
-{
- NautilusStringMap *map;
-
- map = nautilus_string_map_new (FALSE);
-
- /*
- * The idea behind the family map here is that users of NautilusScalableFont
- * dont need to know what the exact name of the font is.
- *
- * For example, old urw fonts use the name 'helvetica', but newer ones use
- * 'numbus sans l'
- *
- * So, we a map for 'helvetica' to 'nimbus sans l' if needed.
- *
- * 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 default");
- }
- else if (font_family_lookup (global_font_family_table, "helvetica default")) {
- nautilus_string_map_add (map, "helvetica default", "nimbus sans l");
- }
-
- return map;
-}
-
/* Public NautilusScalableFont methods */
/**
* nautilus_scalable_font_new:
- * @family: The desired font family.
- * @weight: The desired font weight.
- * @slant: The desired font slant.
- * @set_width: The desired font set_width.
- *
- * Returns a font for the desired components. Returns NULL if the font
- * does not exist.
- *
- */
-NautilusScalableFont *
-nautilus_scalable_font_new (const char *family,
- const char *weight,
- const char *slant,
- const char *set_width)
-{
- /* const char *foundry = "URW"; */
- FontFamilyEntry *font_family_entry;
- FontEntry *font_entry;
- NautilusScalableFont *font;
-
- initialize_global_stuff_if_needed ();
-
- font_family_entry = font_family_lookup (global_font_family_table, family);
-
- /* If the family entry was not found, try a mapped family name */
- if (font_family_entry == NULL) {
- char *mapped_family;
-
- mapped_family = nautilus_string_map_lookup (global_family_string_map, family);
-
- if (mapped_family != NULL) {
- font_family_entry = font_family_lookup (global_font_family_table, mapped_family);
- g_free (mapped_family);
- }
- }
-
- if (font_family_entry == NULL) {
- return NULL;
- }
-
- weight = weight ? weight : "medium";
- slant = slant ? slant : "r";
- set_width = set_width ? set_width : "normal";
-
- font_entry = font_family_find_font (font_family_entry, weight, slant, set_width);
-
- if (font_entry == NULL) {
- return NULL;
- }
-
- /* 'Intern' the rsvg font handle if needed */
- if (font_entry->font_handle == NAUTILUS_SCALABLE_FONT_UNDEFINED_HANDLE) {
- font_entry->font_handle = rsvg_ft_intern (global_rsvg_ft_context, font_entry->path);
- }
-
-#if 0
- g_print ("%s (%s, %s, %s %s) handle = %d, path = %s\n" ,
- __FUNCTION__, family, weight, slant, set_width, font_entry->font_handle, font_entry->path);
-#endif
-
- 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 = font_entry->font_handle;
- font->detail->font_family_entry = font_family_entry;
- font->detail->font_entry = font_entry;
-
- 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)
+nautilus_scalable_font_new (const char *file_name)
{
NautilusScalableFont *font;
+ RsvgFTFontHandle font_handle = -1;
g_return_val_if_fail (nautilus_strlen (file_name) > 0, NULL);
- g_return_val_if_fail (g_file_exists (file_name), NULL);
+ g_return_val_if_fail (nautilus_font_manager_file_is_scalable_font (file_name), NULL);
initialize_global_stuff_if_needed ();
@@ -632,9 +117,20 @@ nautilus_scalable_font_new_from_file_name (const char *file_name)
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;
+ font->details->font_file_name = g_strdup (file_name);
+
+ if (!g_hash_table_lookup_extended (global_font_handle_table,
+ font->details->font_file_name,
+ NULL,
+ (gpointer *) &font_handle)) {
+ font_handle = rsvg_ft_intern (global_rsvg_ft_context, font->details->font_file_name);
+ g_hash_table_insert (global_font_handle_table,
+ font->details->font_file_name,
+ GINT_TO_POINTER (font_handle));
+ }
+ g_assert (font_handle >= 0);
+
+ font->details->font_handle = font_handle;
return font;
}
@@ -642,32 +138,14 @@ nautilus_scalable_font_new_from_file_name (const char *file_name)
NautilusScalableFont *
nautilus_scalable_font_make_bold (NautilusScalableFont *font)
{
- NautilusScalableFont *bold_font = NULL;
+ char *bold_font_file_name;
+ NautilusScalableFont *bold_font;
g_return_val_if_fail (NAUTILUS_IS_SCALABLE_FONT (font), NULL);
- /* FIXME bugzilla.eazel.com xxxx:
- * To be 100% correc we need to query for the weights.
- * It just so happens that the limited number of Type1
- * font we have dealt with all have a "bold" weight.
- */
-
- /* If the font is already bold, then do nothing */
- if (nautilus_str_is_equal (font->detail->font_entry->weight, "bold")) {
- gtk_object_ref (GTK_OBJECT (font));
- return font;
- }
-
- bold_font = nautilus_scalable_font_new (font->detail->font_family_entry->family,
- "bold",
- font->detail->font_entry->slant,
- font->detail->font_entry->set_width);
-
- /* If the bold font does not exist, then return the source font */
- if (bold_font == NULL) {
- gtk_object_ref (GTK_OBJECT (font));
- bold_font = font;
- }
+ bold_font_file_name = nautilus_font_manager_get_bold (font->details->font_file_name);
+ bold_font = nautilus_scalable_font_new (bold_font_file_name);
+ g_free (bold_font_file_name);
return bold_font;
}
@@ -819,153 +297,50 @@ nautilus_scalable_font_largest_fitting_font_size (const NautilusScalableFont *fo
NautilusScalableFont *
nautilus_scalable_font_get_default_font (void)
{
- if (global_default_font == 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);
- }
+ char *default_font_file_name;
+ NautilusScalableFont *default_font;
- gtk_object_ref (GTK_OBJECT (global_default_font));
+ /* FIXME bugzilla.eazel.com xxxx:
+ * Its evil that we have to peek preferences here to
+ * find the default smooth font, but so it goes.
+ */
+ default_font_file_name = nautilus_preferences_get (NAUTILUS_PREFERENCES_DIRECTORY_VIEW_SMOOTH_FONT);
+ if (!g_file_exists (default_font_file_name)) {
+ g_free (default_font_file_name);
+ default_font_file_name = nautilus_font_manager_get_default_font ();
+ }
- return global_default_font;
+ g_assert (default_font_file_name != NULL);
+ default_font = nautilus_scalable_font_new (default_font_file_name);
+ g_free (default_font_file_name);
+ g_assert (NAUTILUS_IS_SCALABLE_FONT (default_font));
+ return default_font;
}
NautilusScalableFont *
nautilus_scalable_font_get_default_bold_font (void)
{
- NautilusScalableFont *default_font;
+ char *default_bold_font_file_name;
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,
- gpointer user_data)
-{
- NautilusStringList *list = (NautilusStringList *) user_data;
- FontFamilyEntry *family_entry = (FontFamilyEntry *) value;
-
- g_assert (family_entry != NULL);
- g_assert (!nautilus_string_list_contains (list, family_entry->family));
-
- nautilus_string_list_insert (list, family_entry->family);
-}
-
-static void
-font_family_table_for_each_free (gpointer key,
- gpointer value,
- gpointer user_data)
-{
- FontFamilyEntry *family_entry = (FontFamilyEntry *) value;
- g_assert (family_entry != NULL);
-
- font_family_free (family_entry);
-}
-
-static NautilusStringList *
-font_family_table_get_family_list (GHashTable *font_family_table)
-{
- NautilusStringList *list;
-
- g_return_val_if_fail (font_family_table != NULL, NULL);
-
- list = nautilus_string_list_new (FALSE);
-
- g_hash_table_foreach (font_family_table, font_family_table_for_each_append, list);
-
- return list;
-}
-
-NautilusStringList *
-nautilus_scalable_font_get_font_family_list (void)
-{
- initialize_global_stuff_if_needed ();
-
- return font_family_table_get_family_list (global_font_family_table);
-}
-
-static void
-font_family_table_free (GHashTable *font_family_table)
-{
- g_assert (font_family_table != NULL);
-
- g_hash_table_foreach (font_family_table, font_family_table_for_each_free, NULL);
-
- g_hash_table_destroy (font_family_table);
-}
-
-gboolean
-nautilus_scalable_font_query_font (const char *family,
- NautilusStringList **weights_out,
- NautilusStringList **slants_out,
- NautilusStringList **set_widths_out)
-{
- FontFamilyEntry *family_entry;
- GList *iterator;
-
- g_return_val_if_fail (family != NULL, FALSE);
-
- if (weights_out != NULL) {
- *weights_out = NULL;
- }
-
- if (slants_out != NULL) {
- *slants_out = NULL;
- }
-
- if (set_widths_out != NULL) {
- *set_widths_out = NULL;
- }
-
- family_entry = font_family_lookup (global_font_family_table, family);
-
- if (family_entry == NULL) {
- return FALSE;
- }
-
- if (weights_out == NULL && slants_out == NULL && set_widths_out == NULL) {
- return TRUE;
- }
-
- if (weights_out != NULL) {
- *weights_out = nautilus_string_list_new (FALSE);
- }
-
- if (slants_out != NULL) {
- *slants_out = nautilus_string_list_new (FALSE);
- }
-
- if (set_widths_out != NULL) {
- *set_widths_out = nautilus_string_list_new (FALSE);
- }
-
- for (iterator = family_entry->fonts; iterator != NULL; iterator = iterator->next) {
- FontEntry *font_entry = (FontEntry *) iterator->data;
- g_assert (font_entry != NULL);
-
- if (weights_out != NULL) {
- nautilus_string_list_insert (*weights_out, font_entry->weight);
- }
-
- if (slants_out != NULL) {
- nautilus_string_list_insert (*slants_out, font_entry->slant);
- }
-
- if (set_widths_out != NULL) {
- nautilus_string_list_insert (*set_widths_out, font_entry->set_width);
- }
+ /* FIXME bugzilla.eazel.com xxxx:
+ * Its evil that we have to peek preferences here to
+ * find the default smooth font, but so it goes.
+ */
+ default_bold_font_file_name = nautilus_preferences_get ("directory-view/smooth_font");
+ if (!g_file_exists (default_bold_font_file_name)) {
+ g_free (default_bold_font_file_name);
+ default_bold_font_file_name = nautilus_font_manager_get_default_bold_font ();
}
- return TRUE;
+ g_assert (default_bold_font_file_name != NULL);
+ default_bold_font = nautilus_scalable_font_new (default_bold_font_file_name);
+ g_free (default_bold_font_file_name);
+ g_assert (NAUTILUS_IS_SCALABLE_FONT (default_bold_font));
+ return default_bold_font;
}
-/* 'atexit' destructors for global stuff */
+/* 'atexit' destructor for rsvg context */
static void
destroy_global_rsvg_ft_context (void)
{
@@ -973,46 +348,27 @@ destroy_global_rsvg_ft_context (void)
}
static void
-default_font_at_exit_destructor (void)
-{
- gtk_object_unref (GTK_OBJECT (global_default_font));
-}
-
-static void
-font_family_table_at_exit_destructor (void)
+free_global_font_handle_table (void)
{
- font_family_table_free (global_font_family_table);
-}
+ if (global_font_handle_table != NULL) {
+ g_hash_table_destroy (global_font_handle_table);
+ }
-static void
-font_family_string_map_at_exit_destructor (void)
-{
- nautilus_string_map_free (global_family_string_map);
+ global_font_handle_table = NULL;
}
static void
initialize_global_stuff_if_needed (void)
{
- static gboolean fonts_initialized = FALSE;
-
/* Initialize the rsvg font context shared by all fonts */
if (global_rsvg_ft_context == NULL) {
global_rsvg_ft_context = rsvg_ft_ctx_new ();
g_atexit (destroy_global_rsvg_ft_context);
}
- /* Initialize the global font table */
- if (!fonts_initialized) {
- fonts_initialized = TRUE;
- global_font_family_table = g_hash_table_new (g_str_hash, g_str_equal);
- font_family_table_add_fonts (global_font_family_table, NAUTILUS_DATADIR "/fonts/urw");
- g_atexit (font_family_table_at_exit_destructor);
- }
-
- if (global_family_string_map == NULL) {
- global_family_string_map = font_family_string_map_new ();
-
- g_atexit (font_family_string_map_at_exit_destructor);
+ if (global_font_handle_table == NULL) {
+ global_font_handle_table = g_hash_table_new (g_str_hash, g_str_equal);
+ g_atexit (free_global_font_handle_table);
}
}
@@ -1022,7 +378,7 @@ nautilus_scalable_font_get_rsvg_handle (const NautilusScalableFont *font)
{
g_return_val_if_fail (NAUTILUS_IS_SCALABLE_FONT (font), NAUTILUS_SCALABLE_FONT_UNDEFINED_HANDLE);
- return font->detail->font_handle;
+ return font->details->font_handle;
}
struct _RsvgFTCtx *
diff --git a/libnautilus-private/nautilus-scalable-font.h b/libnautilus-private/nautilus-scalable-font.h
index 40c860cc8..c8add6e4b 100644
--- a/libnautilus-private/nautilus-scalable-font.h
+++ b/libnautilus-private/nautilus-scalable-font.h
@@ -55,30 +55,26 @@ BEGIN_GNOME_DECLS
#define NAUTILUS_IS_SCALABLE_FONT(obj) (GTK_CHECK_TYPE ((obj), NAUTILUS_TYPE_SCALABLE_FONT))
#define NAUTILUS_IS_SCALABLE_FONT_CLASS(klass) (GTK_CHECK_CLASS_TYPE ((klass), NAUTILUS_TYPE_SCALABLE_FONT))
-typedef struct _NautilusScalableFont NautilusScalableFont;
-typedef struct _NautilusScalableFontClass NautilusScalableFontClass;
-typedef struct _NautilusScalableFontDetail NautilusScalableFontDetail;
+typedef struct NautilusScalableFont NautilusScalableFont;
+typedef struct NautilusScalableFontClass NautilusScalableFontClass;
+typedef struct NautilusScalableFontDetails NautilusScalableFontDetails;
-struct _NautilusScalableFont
+struct NautilusScalableFont
{
/* Superclass */
- GtkObject object;
+ GtkObject object;
/* Private things */
- NautilusScalableFontDetail *detail;
+ NautilusScalableFontDetails *details;
};
-struct _NautilusScalableFontClass
+struct NautilusScalableFontClass
{
- GtkObjectClass parent_class;
+ GtkObjectClass parent_class;
};
GtkType nautilus_scalable_font_get_type (void);
-NautilusScalableFont *nautilus_scalable_font_new (const char *family,
- const char *weight,
- const char *slant,
- const char *set_width);
-NautilusScalableFont * nautilus_scalable_font_new_from_file_name (const char *file_name);
+NautilusScalableFont * nautilus_scalable_font_new (const char *file_name);
NautilusDimensions nautilus_scalable_font_measure_text (const NautilusScalableFont *font,
int font_size,
const char *text,
@@ -104,11 +100,6 @@ int nautilus_scalable_font_largest_fitting_font_size (const N
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);
END_GNOME_DECLS
diff --git a/libnautilus-private/nautilus-smooth-text-layout-cache.c b/libnautilus-private/nautilus-smooth-text-layout-cache.c
index 041ff34e0..c2d2b6a02 100644
--- a/libnautilus-private/nautilus-smooth-text-layout-cache.c
+++ b/libnautilus-private/nautilus-smooth-text-layout-cache.c
@@ -288,7 +288,7 @@ cache_trim (NautilusSmoothTextLayoutCache *cache)
* @cache: The layout cache being queried
* @text: The string to be rendered
* @text_length: The number of bytes to draw
- * @font: The desired smooth font family.
+ * @font: The desired smooth font.
* @font_size: The pixel size of the font
* @wrap:
* @line_spacing:
@@ -445,11 +445,6 @@ nautilus_smooth_text_layout_cache_destroy (GtkObject *object)
#include <stdlib.h>
#include <stdio.h>
-/* Have to disable the tests by default for now - NautilusScalableFont
- * can't handle loading fonts before `make install' has happened :-(
- */
-#ifdef FIXED_LOADING_FONTS_BEFORE_MAKE_INSTALL
-
static NautilusSmoothTextLayoutCache *test_cache;
static NautilusScalableFont *test_font;
@@ -567,7 +562,6 @@ struct test_case {
#define MIN_LINES 1
#define MAX_LINES 10
-#define FONT_FAMILY "helvetica"
#define MIN_FONT_SIZE 8
#define MAX_FONT_SIZE 48
@@ -730,7 +724,7 @@ nautilus_self_check_smooth_text_layout_cache (void)
int i, index;
test_cache = nautilus_smooth_text_layout_cache_new ();
- test_font = nautilus_scalable_font_new (FONT_FAMILY, NULL, NULL, NULL);
+ test_font = nautilus_scalable_font_get_default_font ();
/* initialize the random number generator to a known state */
srandom (1);
@@ -764,12 +758,4 @@ nautilus_self_check_smooth_text_layout_cache (void)
gtk_object_destroy (GTK_OBJECT (test_cache));
}
-#else /* FIXED_LOADING_FONTS_BEFORE_MAKE_INSTALL */
-
-void
-nautilus_self_check_smooth_text_layout_cache (void)
-{
-}
-
-#endif /* FIXED_LOADING_FONTS_BEFORE_MAKE_INSTALL */
#endif /* NAUTILUS_OMIT_SELF_CHECK */
diff --git a/src/file-manager/fm-directory-view.c b/src/file-manager/fm-directory-view.c
index 7bfd11401..27711c305 100644
--- a/src/file-manager/fm-directory-view.c
+++ b/src/file-manager/fm-directory-view.c
@@ -927,6 +927,18 @@ directory_view_font_family_changed_callback (gpointer callback_data)
}
static void
+directory_view_smooth_font_changed_callback (gpointer callback_data)
+{
+ FMDirectoryView *view;
+
+ view = FM_DIRECTORY_VIEW (callback_data);
+
+ NAUTILUS_CALL_METHOD
+ (FM_DIRECTORY_VIEW_CLASS, view,
+ smooth_font_changed, (view));
+}
+
+static void
click_policy_changed_callback (gpointer callback_data)
{
FMDirectoryView *view;
@@ -1055,6 +1067,11 @@ fm_directory_view_initialize (FMDirectoryView *view)
directory_view_font_family_changed_callback,
view);
+ /* Keep track of changes in the smooth font */
+ nautilus_preferences_add_callback (NAUTILUS_PREFERENCES_DIRECTORY_VIEW_SMOOTH_FONT,
+ directory_view_smooth_font_changed_callback,
+ view);
+
/* Keep track of changes in clicking policy */
nautilus_preferences_add_callback (NAUTILUS_PREFERENCES_CLICK_POLICY,
click_policy_changed_callback,
@@ -1119,6 +1136,9 @@ fm_directory_view_destroy (GtkObject *object)
nautilus_preferences_remove_callback (NAUTILUS_PREFERENCES_DIRECTORY_VIEW_FONT_FAMILY,
directory_view_font_family_changed_callback,
view);
+ nautilus_preferences_remove_callback (NAUTILUS_PREFERENCES_DIRECTORY_VIEW_SMOOTH_FONT,
+ directory_view_smooth_font_changed_callback,
+ view);
nautilus_preferences_remove_callback (NAUTILUS_PREFERENCES_CLICK_POLICY,
click_policy_changed_callback,
view);
diff --git a/src/file-manager/fm-directory-view.h b/src/file-manager/fm-directory-view.h
index 83fdf457f..2ef4f6d50 100644
--- a/src/file-manager/fm-directory-view.h
+++ b/src/file-manager/fm-directory-view.h
@@ -284,6 +284,7 @@ struct FMDirectoryViewClass {
void (* embedded_text_policy_changed)(FMDirectoryView *view);
void (* image_display_policy_changed)(FMDirectoryView *view);
void (* font_family_changed) (FMDirectoryView *view);
+ void (* smooth_font_changed) (FMDirectoryView *view);
void (* click_policy_changed) (FMDirectoryView *view);
void (* smooth_graphics_mode_changed)(FMDirectoryView *view);
};
diff --git a/src/file-manager/fm-icon-view.c b/src/file-manager/fm-icon-view.c
index 51ba35d44..e6f48aeb9 100644
--- a/src/file-manager/fm-icon-view.c
+++ b/src/file-manager/fm-icon-view.c
@@ -110,36 +110,37 @@ typedef enum {
} MenuItemType;
/* forward declarations */
-static void create_icon_container (FMIconView *icon_view);
-static void fm_icon_view_initialize (FMIconView *icon_view);
-static void fm_icon_view_initialize_class (FMIconViewClass *klass);
-static gboolean fm_icon_view_is_empty (FMDirectoryView *view);
-static void fm_icon_view_set_directory_sort_by (FMIconView *icon_view,
- NautilusFile *file,
- const char *sort_by);
-static void fm_icon_view_set_zoom_level (FMIconView *view,
- NautilusZoomLevel new_level,
- gboolean always_set_level);
-gboolean fm_icon_view_supports_auto_layout (FMIconView *view);
-static void fm_icon_view_update_icon_container_fonts (FMIconView *icon_view);
-static void fm_icon_view_update_click_mode (FMIconView *icon_view);
-static void fm_icon_view_update_smooth_graphics_mode (FMIconView *icon_view);
-static gboolean fm_icon_view_using_tighter_layout (FMIconView *icon_view);
-static gboolean fm_icon_view_get_directory_tighter_layout (FMIconView *icon_view,
- NautilusFile *file);
-static void fm_icon_view_set_directory_tighter_layout (FMIconView *icon_view,
- NautilusFile *file,
- gboolean tighter_layout);
-static gboolean real_supports_auto_layout (FMIconView *view);
-static const SortCriterion *get_sort_criterion_by_id (const char *id);
-static void set_sort_criterion_by_id (FMIconView *icon_view,
- const char *id);
-static gboolean set_sort_reversed (FMIconView *icon_view,
- gboolean new_value);
-static void switch_to_manual_layout (FMIconView *view);
-static void preview_sound (NautilusFile *file,
- gboolean start_flag);
-static void update_layout_menus (FMIconView *view);
+static void create_icon_container (FMIconView *icon_view);
+static void fm_icon_view_initialize (FMIconView *icon_view);
+static void fm_icon_view_initialize_class (FMIconViewClass *klass);
+static gboolean fm_icon_view_is_empty (FMDirectoryView *view);
+static void fm_icon_view_set_directory_sort_by (FMIconView *icon_view,
+ NautilusFile *file,
+ const char *sort_by);
+static void fm_icon_view_set_zoom_level (FMIconView *view,
+ NautilusZoomLevel new_level,
+ gboolean always_set_level);
+gboolean fm_icon_view_supports_auto_layout (FMIconView *view);
+static void fm_icon_view_update_icon_container_fonts (FMIconView *icon_view);
+static void fm_icon_view_update_icon_container_smooth_font (FMIconView *icon_view);
+static void fm_icon_view_update_click_mode (FMIconView *icon_view);
+static void fm_icon_view_update_smooth_graphics_mode (FMIconView *icon_view);
+static gboolean fm_icon_view_using_tighter_layout (FMIconView *icon_view);
+static gboolean fm_icon_view_get_directory_tighter_layout (FMIconView *icon_view,
+ NautilusFile *file);
+static void fm_icon_view_set_directory_tighter_layout (FMIconView *icon_view,
+ NautilusFile *file,
+ gboolean tighter_layout);
+static gboolean real_supports_auto_layout (FMIconView *view);
+static const SortCriterion *get_sort_criterion_by_id (const char *id);
+static void set_sort_criterion_by_id (FMIconView *icon_view,
+ const char *id);
+static gboolean set_sort_reversed (FMIconView *icon_view,
+ gboolean new_value);
+static void switch_to_manual_layout (FMIconView *view);
+static void preview_sound (NautilusFile *file,
+ gboolean start_flag);
+static void update_layout_menus (FMIconView *view);
NAUTILUS_DEFINE_CLASS_BOILERPLATE (FMIconView,
fm_icon_view,
@@ -1832,6 +1833,14 @@ fm_icon_view_font_family_changed (FMDirectoryView *directory_view)
}
static void
+fm_icon_view_smooth_font_changed (FMDirectoryView *directory_view)
+{
+ g_assert (FM_IS_ICON_VIEW (directory_view));
+
+ fm_icon_view_update_icon_container_smooth_font (FM_ICON_VIEW (directory_view));
+}
+
+static void
fm_icon_view_click_policy_changed (FMDirectoryView *directory_view)
{
g_assert (FM_IS_ICON_VIEW (directory_view));
@@ -1884,6 +1893,7 @@ fm_icon_view_initialize_class (FMIconViewClass *klass)
fm_directory_view_class->embedded_text_policy_changed = fm_icon_view_embedded_text_policy_changed;
fm_directory_view_class->image_display_policy_changed = fm_icon_view_image_display_policy_changed;
fm_directory_view_class->font_family_changed = fm_icon_view_font_family_changed;
+ fm_directory_view_class->smooth_font_changed = fm_icon_view_smooth_font_changed;
fm_directory_view_class->click_policy_changed = fm_icon_view_click_policy_changed;
fm_directory_view_class->smooth_graphics_mode_changed = fm_icon_view_smooth_graphics_mode_changed;
@@ -1966,6 +1976,25 @@ fm_icon_view_update_icon_container_fonts (FMIconView *icon_view)
}
static void
+fm_icon_view_update_icon_container_smooth_font (FMIconView *icon_view)
+{
+ NautilusIconContainer *icon_container;
+ NautilusScalableFont *scalable_font;
+
+ icon_container = get_icon_container (icon_view);
+ g_assert (icon_container != NULL);
+
+ scalable_font = nautilus_global_preferences_get_smooth_font ();
+ g_assert (NAUTILUS_IS_SCALABLE_FONT (scalable_font));
+
+ nautilus_icon_container_set_smooth_label_font (icon_container,
+ scalable_font);
+ gtk_object_unref (GTK_OBJECT (scalable_font));
+
+ nautilus_icon_container_request_update_all (icon_container);
+}
+
+static void
fm_icon_view_update_click_mode (FMIconView *icon_view)
{
NautilusIconContainer *icon_container;
@@ -2103,6 +2132,7 @@ create_icon_container (FMIconView *icon_view)
GTK_WIDGET (icon_container));
fm_icon_view_update_icon_container_fonts (icon_view);
+ fm_icon_view_update_icon_container_smooth_font (icon_view);
fm_icon_view_update_click_mode (icon_view);
fm_icon_view_update_smooth_graphics_mode (icon_view);
diff --git a/src/nautilus-about.c b/src/nautilus-about.c
index c57f8ae68..4d7706af7 100644
--- a/src/nautilus-about.c
+++ b/src/nautilus-about.c
@@ -351,7 +351,7 @@ nautilus_about_draw_info (NautilusAbout *about,
/* draw the name and version */
display_str = g_strdup_printf ("%s %s", title, version);
- draw_aa_string (bold_font, pixbuf, 24, 12, 10, white, black, display_str, 1);
+ draw_aa_string (bold_font, pixbuf, 24, 12, 5, white, black, display_str, 1);
g_free (display_str);
/* draw the copyright notice */
diff --git a/src/nautilus-information-panel.c b/src/nautilus-information-panel.c
index 124eae872..595fe5e02 100644
--- a/src/nautilus-information-panel.c
+++ b/src/nautilus-information-panel.c
@@ -840,7 +840,7 @@ nautilus_sidebar_add_panel (NautilusSidebar *sidebar, NautilusViewFrame *panel)
/* tell the index tabs about it */
nautilus_sidebar_tabs_add_view (sidebar->details->sidebar_tabs,
- description, GTK_WIDGET (panel), page_num);
+ _(description), GTK_WIDGET (panel), page_num);
g_free (description);
@@ -867,7 +867,7 @@ nautilus_sidebar_remove_panel (NautilusSidebar *sidebar,
}
/* Remove the tab associated with this panel */
- nautilus_sidebar_tabs_remove_view (sidebar->details->sidebar_tabs, description);
+ nautilus_sidebar_tabs_remove_view (sidebar->details->sidebar_tabs, _(description));
if (page_num <= sidebar->details->selected_index) {
sidebar->details->selected_index -= 1;
}
diff --git a/src/nautilus-navigation-window.c b/src/nautilus-navigation-window.c
index 867597884..b49fd156b 100644
--- a/src/nautilus-navigation-window.c
+++ b/src/nautilus-navigation-window.c
@@ -1073,7 +1073,7 @@ create_view_as_menu_item (NautilusWindow *window, NautilusViewIdentifier *identi
GtkWidget *menu_item;
char *menu_label;
- menu_label = g_strdup (identifier->view_as_label);
+ menu_label = g_strdup (_(identifier->view_as_label));
menu_item = gtk_menu_item_new_with_label (menu_label);
g_free (menu_label);
diff --git a/src/nautilus-object-window.c b/src/nautilus-object-window.c
index 867597884..b49fd156b 100644
--- a/src/nautilus-object-window.c
+++ b/src/nautilus-object-window.c
@@ -1073,7 +1073,7 @@ create_view_as_menu_item (NautilusWindow *window, NautilusViewIdentifier *identi
GtkWidget *menu_item;
char *menu_label;
- menu_label = g_strdup (identifier->view_as_label);
+ menu_label = g_strdup (_(identifier->view_as_label));
menu_item = gtk_menu_item_new_with_label (menu_label);
g_free (menu_label);
diff --git a/src/nautilus-sidebar-title.c b/src/nautilus-sidebar-title.c
index 7ebcbab0f..e3d5db9ff 100644
--- a/src/nautilus-sidebar-title.c
+++ b/src/nautilus-sidebar-title.c
@@ -36,6 +36,7 @@
#include <gtk/gtklabel.h>
#include <gtk/gtkpixmap.h>
#include <gtk/gtksignal.h>
+#include <libgnome/gnome-i18n.h>
#include <libgnomevfs/gnome-vfs-types.h>
#include <libgnomevfs/gnome-vfs-uri.h>
#include <libnautilus-extensions/nautilus-background.h>
@@ -453,7 +454,7 @@ update_font (NautilusSidebarTitle *sidebar_title)
/* FIXME bugzilla.eazel.com 1103: Hard coded font family. */
/* Update the regular font */
- template_font = nautilus_font_factory_get_font_by_family ("helvetica", maximum_acceptable_font_size);
+ template_font = nautilus_font_factory_get_font_by_family (_("helvetica"), maximum_acceptable_font_size);
g_assert (template_font != NULL);
bold_template_font = nautilus_gdk_font_get_bold (template_font);
diff --git a/src/nautilus-sidebar.c b/src/nautilus-sidebar.c
index 124eae872..595fe5e02 100644
--- a/src/nautilus-sidebar.c
+++ b/src/nautilus-sidebar.c
@@ -840,7 +840,7 @@ nautilus_sidebar_add_panel (NautilusSidebar *sidebar, NautilusViewFrame *panel)
/* tell the index tabs about it */
nautilus_sidebar_tabs_add_view (sidebar->details->sidebar_tabs,
- description, GTK_WIDGET (panel), page_num);
+ _(description), GTK_WIDGET (panel), page_num);
g_free (description);
@@ -867,7 +867,7 @@ nautilus_sidebar_remove_panel (NautilusSidebar *sidebar,
}
/* Remove the tab associated with this panel */
- nautilus_sidebar_tabs_remove_view (sidebar->details->sidebar_tabs, description);
+ nautilus_sidebar_tabs_remove_view (sidebar->details->sidebar_tabs, _(description));
if (page_num <= sidebar->details->selected_index) {
sidebar->details->selected_index -= 1;
}
diff --git a/src/nautilus-spatial-window.c b/src/nautilus-spatial-window.c
index 867597884..b49fd156b 100644
--- a/src/nautilus-spatial-window.c
+++ b/src/nautilus-spatial-window.c
@@ -1073,7 +1073,7 @@ create_view_as_menu_item (NautilusWindow *window, NautilusViewIdentifier *identi
GtkWidget *menu_item;
char *menu_label;
- menu_label = g_strdup (identifier->view_as_label);
+ menu_label = g_strdup (_(identifier->view_as_label));
menu_item = gtk_menu_item_new_with_label (menu_label);
g_free (menu_label);
diff --git a/src/nautilus-window.c b/src/nautilus-window.c
index 867597884..b49fd156b 100644
--- a/src/nautilus-window.c
+++ b/src/nautilus-window.c
@@ -1073,7 +1073,7 @@ create_view_as_menu_item (NautilusWindow *window, NautilusViewIdentifier *identi
GtkWidget *menu_item;
char *menu_label;
- menu_label = g_strdup (identifier->view_as_label);
+ menu_label = g_strdup (_(identifier->view_as_label));
menu_item = gtk_menu_item_new_with_label (menu_label);
g_free (menu_label);
diff --git a/test/test-nautilus-font-manager.c b/test/test-nautilus-font-manager.c
index 468b6c487..7b237a544 100644
--- a/test/test-nautilus-font-manager.c
+++ b/test/test-nautilus-font-manager.c
@@ -36,7 +36,7 @@ typedef struct
GList *style_list;
} Entry;
-static void
+static gboolean
font_iterator_callback (const char *font_file_name,
NautilusFontType font_type,
const char *foundry,
@@ -54,15 +54,15 @@ font_iterator_callback (const char *font_file_name,
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);
+ g_return_val_if_fail (font_file_name != NULL, FALSE);
+ g_return_val_if_fail (foundry != NULL, FALSE);
+ g_return_val_if_fail (family != NULL, FALSE);
+ g_return_val_if_fail (weight != NULL, FALSE);
+ g_return_val_if_fail (slant != NULL, FALSE);
+ g_return_val_if_fail (set_width != NULL, FALSE);
+ g_return_val_if_fail (char_set_registry != NULL, FALSE);
+ g_return_val_if_fail (char_set_encoding != NULL, FALSE);
+ g_return_val_if_fail (callback_data != NULL, FALSE);
font_table = callback_data;
@@ -100,6 +100,8 @@ font_iterator_callback (const char *font_file_name,
char_set_registry,
char_set_encoding);
}
+
+ return TRUE;
}
static void
diff --git a/test/test-nautilus-font-picker.c b/test/test-nautilus-font-picker.c
index ef1566fa5..81e7ed72c 100644
--- a/test/test-nautilus-font-picker.c
+++ b/test/test-nautilus-font-picker.c
@@ -2,27 +2,110 @@
#include <libnautilus-extensions/nautilus-font-picker.h>
#include <libnautilus-extensions/nautilus-font-manager.h>
+#include <libnautilus-extensions/nautilus-global-preferences.h>
static void
-font_picker_changed_callback (NautilusFontPicker *font_picker,
- gpointer callback_data)
+update_font (NautilusLabel *label,
+ const char *font_file_name)
{
NautilusScalableFont *font;
+
+ g_return_if_fail (NAUTILUS_IS_LABEL (label));
+ g_return_if_fail (font_file_name != NULL);
+
+ font = nautilus_scalable_font_new (font_file_name);
+ nautilus_label_set_smooth_font (NAUTILUS_LABEL (label), font);
+ gtk_object_unref (GTK_OBJECT (font));
+
+ nautilus_preferences_set (NAUTILUS_PREFERENCES_DIRECTORY_VIEW_SMOOTH_FONT, font_file_name);
+}
+
+static void
+font_changed_update_label_callback (NautilusFontPicker *font_picker,
+ gpointer callback_data)
+{
char *font_file_name;
g_return_if_fail (NAUTILUS_IS_FONT_PICKER (font_picker));
g_return_if_fail (NAUTILUS_IS_LABEL (callback_data));
font_file_name = nautilus_font_picker_get_selected_font (font_picker);
- g_print ("font changed = %s\n", font_file_name);
+ update_font (NAUTILUS_LABEL (callback_data), font_file_name);
+ g_free (font_file_name);
+}
- 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));
+static void
+font_changed_update_file_name_callback (NautilusFontPicker *font_picker,
+ gpointer callback_data)
+{
+ char *font_file_name;
+ g_return_if_fail (NAUTILUS_IS_FONT_PICKER (font_picker));
+ g_return_if_fail (NAUTILUS_IS_TEXT_CAPTION (callback_data));
+
+ font_file_name = nautilus_font_picker_get_selected_font (font_picker);
+ nautilus_text_caption_set_text (NAUTILUS_TEXT_CAPTION (callback_data), font_file_name);
g_free (font_file_name);
}
+static void
+use_defalt_font_callback (GtkWidget *button,
+ gpointer callback_data)
+{
+ char *default_font;
+
+ g_return_if_fail (GTK_IS_BUTTON (button));
+ g_return_if_fail (NAUTILUS_IS_LABEL (callback_data));
+
+ default_font = nautilus_font_manager_get_default_font ();
+ update_font (NAUTILUS_LABEL (callback_data), default_font);
+ g_free (default_font);
+}
+
+static void
+use_defalt_bold_font_callback (GtkWidget *button,
+ gpointer callback_data)
+{
+ char *default_bold_font;
+
+ g_return_if_fail (GTK_IS_BUTTON (button));
+ g_return_if_fail (NAUTILUS_IS_LABEL (callback_data));
+
+ default_bold_font = nautilus_font_manager_get_default_bold_font ();
+ update_font (NAUTILUS_LABEL (callback_data), default_bold_font);
+ g_free (default_bold_font);
+}
+
+static void
+use_defalt_font_update_picker_callback (GtkWidget *button,
+ gpointer callback_data)
+{
+ char *default_font;
+
+ g_return_if_fail (GTK_IS_BUTTON (button));
+ g_return_if_fail (NAUTILUS_IS_FONT_PICKER (callback_data));
+
+ default_font = nautilus_font_manager_get_default_font ();
+ nautilus_font_picker_set_selected_font (NAUTILUS_FONT_PICKER (callback_data),
+ default_font);
+ g_free (default_font);
+}
+
+static void
+use_defalt_bold_font_update_picker_callback (GtkWidget *button,
+ gpointer callback_data)
+{
+ char *default_bold_font;
+
+ g_return_if_fail (GTK_IS_BUTTON (button));
+ g_return_if_fail (NAUTILUS_IS_FONT_PICKER (callback_data));
+
+ default_bold_font = nautilus_font_manager_get_default_bold_font ();
+ nautilus_font_picker_set_selected_font (NAUTILUS_FONT_PICKER (callback_data),
+ default_bold_font);
+ g_free (default_bold_font);
+}
+
int
main (int argc, char * argv[])
{
@@ -30,10 +113,17 @@ main (int argc, char * argv[])
GtkWidget *vbox;
GtkWidget *font_picker;
GtkWidget *label;
-
+ GtkWidget *file_name_caption;
+ GtkWidget *default_font_caption;
+ GtkWidget *default_bold_font_caption;
NautilusScalableFont *font;
-
- char *fallback_font;
+ GtkWidget *use_defailt_button;
+ GtkWidget *use_defailt_bold_button;
+ GtkWidget *default_hbox;
+ GtkWidget *default_bold_hbox;
+ char *current_font;
+ char *default_font;
+ char *default_bold_font;
test_init (&argc, &argv);
@@ -42,31 +132,82 @@ main (int argc, char * argv[])
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);
+ default_font = nautilus_font_manager_get_default_font ();
+ default_bold_font = nautilus_font_manager_get_default_bold_font ();
font_picker = nautilus_font_picker_new ();
- label = nautilus_label_new ("Something");
+ current_font = nautilus_preferences_get (NAUTILUS_PREFERENCES_DIRECTORY_VIEW_SMOOTH_FONT);
+ nautilus_font_picker_set_selected_font (NAUTILUS_FONT_PICKER (font_picker),
+ current_font);
+
+ label = nautilus_label_new ("Something\nハードウェア");
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");
-
+ font = nautilus_scalable_font_new (current_font);
nautilus_label_set_smooth_font (NAUTILUS_LABEL (label), font);
-
gtk_object_unref (GTK_OBJECT (font));
-
+
gtk_signal_connect (GTK_OBJECT (font_picker),
"changed",
- GTK_SIGNAL_FUNC (font_picker_changed_callback),
+ GTK_SIGNAL_FUNC (font_changed_update_label_callback),
label);
- nautilus_font_picker_set_selected_font (NAUTILUS_FONT_PICKER (font_picker),
- "/usr/share/fonts/ISO8859-2/Type1/gatsb___.pfb");
+ file_name_caption = nautilus_text_caption_new ();
+ nautilus_caption_set_title_label (NAUTILUS_CAPTION (file_name_caption),
+ "Current Font");
+ nautilus_text_caption_set_text (NAUTILUS_TEXT_CAPTION (file_name_caption), current_font);
+
+ gtk_signal_connect (GTK_OBJECT (font_picker),
+ "changed",
+ GTK_SIGNAL_FUNC (font_changed_update_file_name_callback),
+ file_name_caption);
+
+ default_hbox = gtk_hbox_new (FALSE, 0);
+ default_font_caption = nautilus_text_caption_new ();
+ nautilus_caption_set_title_label (NAUTILUS_CAPTION (default_font_caption),
+ "Default Font");
+ nautilus_text_caption_set_text (NAUTILUS_TEXT_CAPTION (default_font_caption), default_font);
+ use_defailt_button = gtk_button_new_with_label ("Use");
+ gtk_signal_connect (GTK_OBJECT (use_defailt_button),
+ "clicked",
+ GTK_SIGNAL_FUNC (use_defalt_font_callback),
+ label);
+ gtk_signal_connect (GTK_OBJECT (use_defailt_button),
+ "clicked",
+ GTK_SIGNAL_FUNC (use_defalt_font_update_picker_callback),
+ font_picker);
+ gtk_box_pack_start (GTK_BOX (default_hbox), default_font_caption, TRUE, TRUE, 0);
+ gtk_box_pack_start (GTK_BOX (default_hbox), use_defailt_button, FALSE, FALSE, 0);
+
+
+ default_bold_hbox = gtk_hbox_new (FALSE, 0);
+ default_bold_font_caption = nautilus_text_caption_new ();
+ nautilus_caption_set_title_label (NAUTILUS_CAPTION (default_bold_font_caption),
+ "Default Bold Font");
+ nautilus_text_caption_set_text (NAUTILUS_TEXT_CAPTION (default_bold_font_caption), default_bold_font);
+ use_defailt_bold_button = gtk_button_new_with_label ("Use");
+ gtk_signal_connect (GTK_OBJECT (use_defailt_bold_button),
+ "clicked",
+ GTK_SIGNAL_FUNC (use_defalt_bold_font_callback),
+ label);
+ gtk_signal_connect (GTK_OBJECT (use_defailt_bold_button),
+ "clicked",
+ GTK_SIGNAL_FUNC (use_defalt_bold_font_update_picker_callback),
+ font_picker);
+ gtk_box_pack_start (GTK_BOX (default_bold_hbox), default_bold_font_caption, TRUE, TRUE, 0);
+ gtk_box_pack_start (GTK_BOX (default_bold_hbox), use_defailt_bold_button, FALSE, FALSE, 0);
+
gtk_box_pack_start (GTK_BOX (vbox), font_picker, TRUE, TRUE, 0);
gtk_box_pack_start (GTK_BOX (vbox), label, TRUE, TRUE, 10);
+ gtk_box_pack_start (GTK_BOX (vbox), file_name_caption, TRUE, TRUE, 10);
+ gtk_box_pack_start (GTK_BOX (vbox), default_hbox, TRUE, TRUE, 10);
+ gtk_box_pack_start (GTK_BOX (vbox), default_bold_hbox, TRUE, TRUE, 10);
+
+ g_free (current_font);
+ g_free (default_font);
gtk_widget_show_all (window);
diff --git a/test/test.c b/test/test.c
index d596b87ab..103beec95 100644
--- a/test/test.c
+++ b/test/test.c
@@ -30,7 +30,7 @@ test_init (int *argc,
int
test_quit (int exit_code)
{
- gnome_vfs_shutdown ();
+ //gnome_vfs_shutdown ();
if (gtk_main_level () > 0) {
gtk_main_quit ();