diff options
author | Ramiro Estrugo <ramiro@eazel.com> | 2001-03-03 03:49:25 +0000 |
---|---|---|
committer | Ramiro Estrugo <ramiro@src.gnome.org> | 2001-03-03 03:49:25 +0000 |
commit | a5eedddc21e6f257f21ed4bb29bcc8fbd507084e (patch) | |
tree | 1c7c0b29aab0f4602b321cf0d486635aebdcb792 /test | |
parent | 8eb6d4160dbdb21cb149ae6ddbdc9b5daa64ee52 (diff) | |
download | nautilus-a5eedddc21e6f257f21ed4bb29bcc8fbd507084e.tar.gz |
reviewed by: <delete if not using a buddy>
2001-03-02 Ramiro Estrugo <ramiro@eazel.com>
reviewed by: <delete if not using a buddy>
Bug 2673 - Need to hook up the new font picker to nautilus .
* configure.in:
Remove an old font setup hack that never really worked.
* data/fonts/urw/fonts.dir:
Rename the fonts to "Helvetica Default" in order not to clash with
system fonts.
* libnautilus-extensions/nautilus-font-manager.h:
* libnautilus-extensions/nautilus-font-manager.c:
(font_description_new): Add a font type parameter.
(font_lists_total_num_fonts): New function to count the total
number of scalable fonts detetected.
(font_description_table_add): Pass in the detected font lists to
do reality checks.
(font_get_font_type): New function.
(font_description_table_get_length),
(font_description_table_peek_nth),
(font_description_table_get_nth_file_name): Name the parameters
more consistently.
(font_description_table_for_each): Add font type parameter
(font_description_table_new): Rework to not require storing the
detected font list. We now use that only for the duration of the
constructor. Lost the install_font_lists dumbness.
(font_server_for_each_font_directory_internal): Use g_warning
instead of g_print.
(font_ignore_directory): New function to determine whether we
should ignore a directory - makes things much faster.
(font_manager_collect_font_tables): New function to handle all the
work of collecting font directories into tables.
(font_server_for_each_callback), (font_table_list_free),
(font_table_list_for_each), (free_font_tables),
(ensure_at_exit_handler), (ensure_fallback_font_table),
(ensure_user_font_table), (ensure_system_font_tables): Add 3
tables for fallback, system and users fonts. These are populated
as needed.
(nautilus_font_manager_for_each_font): Iterate the 3 font talbles.
(nautilus_font_manager_get_fallback_font) : New function to obtain
a fallback font quickly without having to check the system.
(call_chop_off_comments), (nautilus_self_check_font_manager):
Rework the checks to not create a temp directory. Unfortunately
they now only run for me.
* libnautilus-extensions/nautilus-font-picker.h:
* libnautilus-extensions/nautilus-font-picker.c:
(nautilus_font_picker_initialize_class),
(nautilus_font_picker_initialize), (nautilus_font_picker_destroy),
(font_entry_list_find), (font_picker_update),
(font_name_picker_changed_callback),
(style_picker_changed_callback), (ignore_font),
(font_manager_callback), (style_list_for_each_callback),
(font_entry_list_for_each_callback),
(nautilus_font_picker_get_selected_font),
(nautilus_font_picker_set_selected_font),
(nautilus_font_picker_set_title_label):
Use the new font manager.
* libnautilus-extensions/nautilus-global-preferences.h:
* libnautilus-extensions/nautilus-global-preferences.c:
(global_preferences_install_descriptions),
(global_preferences_install_defaults),
(global_preferences_create_dialog), (appearnace_pane_update),
(global_preferences_create_font_group),
(global_preferences_install_home_location_defaults),
(global_preferences_install_font_defaults):
Add a new preference for the smooth font.
Factor our the default font code to its own function. Setup the
font pickers items to be mutually exclusive according to the
smooth graphics mode preference value.
* libnautilus-extensions/nautilus-gtk-extensions.h:
* libnautilus-extensions/nautilus-gtk-extensions.c:
(nautilus_gtk_widget_set_shown):
New function to show or hide a widget in one go.
* libnautilus-extensions/nautilus-preferences-group.c:
(nautilus_preferences_group_update):
Dont show the widget if a controlling preference prevents it.
* libnautilus-extensions/nautilus-preferences-item.h:
* libnautilus-extensions/nautilus-preferences-item.c:
(preferences_item_update_smooth_font),
(preferences_smooth_font_changed_callback),
(preferences_item_create_smooth_font): Add support for a smooth
font picker.
(preferences_item_destroy), (preferences_item_construct),
(nautilus_preferences_item_set_control_preference),
(nautilus_preferences_item_set_control_action),
(nautilus_preferences_item_get_control_showing): Add support for
using a controlling preference which can force the widget to be
shown or hidden depending on its value.
* libnautilus-extensions/nautilus-preferences-pane.c:
(nautilus_preferences_pane_update):
Use new gtk extension to show or hide the widget in one go.
* libnautilus-extensions/nautilus-scalable-font.h:
* libnautilus-extensions/nautilus-scalable-font.c:
(font_family_string_map_new): Update fallback font name.
(nautilus_scalable_font_new_from_file_name): New function to
create a font directly from a font file name.
(nautilus_scalable_font_get_default_font): Update fallback font name.
(nautilus_scalable_font_get_default_bold_font): New function to
get a fallback bold font.
Remove some unsed functions. Remove the font setup hack, the font
manager takes care of that now.
* libnautilus-extensions/nautilus-string-picker.h:
* libnautilus-extensions/nautilus-string-picker.c:
(nautilus_string_picker_clear):
New function to clear the string picker.
* libnautilus-extensions/nautilus-tabs.c:
(nautilus_tabs_initialize):
Fix the hard coded font name.
* src/nautilus-first-time-druid.c: (new_title_label):
Fix the hard coded font name.
* src/nautilus-sidebar-tabs.c:
(nautilus_sidebar_tabs_load_theme_data):
Fix the hard coded font name.
* test/Makefile.am:
* test/test-nautilus-font-manager.c: (font_type_to_string),
(font_iterator_callback), (font_table_for_each_callback), (main):
* test/test-nautilus-font-picker.c: (font_picker_changed_callback),
(main):
* test/test-nautilus-glyph-simple.c: (main):
* test/test-nautilus-label.c: (main):
Update for new font picker and font manager changes.
Diffstat (limited to 'test')
-rw-r--r-- | test/Makefile.am | 2 | ||||
-rw-r--r-- | test/test-nautilus-font-manager.c | 118 | ||||
-rw-r--r-- | test/test-nautilus-font-picker.c | 80 | ||||
-rw-r--r-- | test/test-nautilus-glyph-simple.c | 14 | ||||
-rw-r--r-- | test/test-nautilus-label.c | 109 |
5 files changed, 161 insertions, 162 deletions
diff --git a/test/Makefile.am b/test/Makefile.am index 9cd60bccd..fe4151519 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -69,7 +69,7 @@ test_nautilus_async_activation_SOURCES = test-nautilus-async-activation.c test_nautilus_background_SOURCES = test-nautilus-background.c test_nautilus_clickable_image_SOURCES = test-nautilus-clickable-image.c test.c test_nautilus_font_SOURCES = test-nautilus-font.c test.c -test_nautilus_font_picker_SOURCES = test-nautilus-font-picker.c +test_nautilus_font_picker_SOURCES = test-nautilus-font-picker.c test.c test_nautilus_font_simple_SOURCES = test-nautilus-font-simple.c test.c test_nautilus_font_manager_SOURCES = test-nautilus-font-manager.c test.c test_nautilus_glyph_SOURCES = test-nautilus-glyph.c test.c diff --git a/test/test-nautilus-font-manager.c b/test/test-nautilus-font-manager.c index 0b34bb3ce..468b6c487 100644 --- a/test/test-nautilus-font-manager.c +++ b/test/test-nautilus-font-manager.c @@ -5,8 +5,41 @@ #include <libnautilus-extensions/nautilus-font-manager.h> +static const char * +font_type_to_string (NautilusFontType font_type) +{ + if (font_type == NAUTILUS_FONT_POSTSCRIPT) { + return "postscript"; + } + + return "truetype"; +} + +// microsoft Webdings +// microsoft Wingdings +// monotype OCR +// URW Zapf +// xfree86 cursor + +typedef struct +{ + char *key; + char *font_file_name; +} Style; + +typedef struct +{ + char *title; + char *foundry; + char *family; + char *key; + GList *style_list; +} Entry; + static void -font_iterator_callback (const char *foundry, +font_iterator_callback (const char *font_file_name, + NautilusFontType font_type, + const char *foundry, const char *family, const char *weight, const char *slant, @@ -15,23 +48,88 @@ font_iterator_callback (const char *foundry, const char *char_set_encoding, gpointer callback_data) { + char *key; + Entry *entry; + Style *style; + + GHashTable *font_table; + + g_return_if_fail (font_file_name != NULL); + g_return_if_fail (foundry != NULL); + g_return_if_fail (family != NULL); + g_return_if_fail (weight != NULL); + g_return_if_fail (slant != NULL); + g_return_if_fail (set_width != NULL); + g_return_if_fail (char_set_registry != NULL); + g_return_if_fail (char_set_encoding != NULL); + g_return_if_fail (callback_data != NULL); + + font_table = callback_data; + + key = g_strdup_printf ("%s %s", foundry, family); + + entry = g_hash_table_lookup (font_table, key); + + if (entry == NULL) { + entry = g_new0 (Entry, 1); + entry->key = g_strdup (key); + entry->foundry = g_strdup (foundry); + entry->family = g_strdup (family); + + g_hash_table_insert (font_table, entry->key, entry); + } + g_assert (entry != NULL); + g_assert (g_hash_table_lookup (font_table, key) == entry); + g_free (key); + + style = g_new0 (Style, 1); + style->key = g_strdup_printf ("%s %s %s", weight, slant, set_width); + style->font_file_name = g_strdup (font_file_name); + + entry->style_list = g_list_append (entry->style_list, style); + + if (1) { + g_print ("%s %s %s-%s-%s-%s-%s-%s-%s\n", + font_type_to_string (font_type), + font_file_name, + foundry, + family, + weight, + slant, + set_width, + char_set_registry, + char_set_encoding); + } +} + +static void +font_table_for_each_callback (gpointer key, + gpointer value, + gpointer callback_data) +{ + char *entry_key; + + g_return_if_fail (key != NULL); + g_return_if_fail (value != NULL); + //g_return_if_fail (callback_data != NULL); + + entry_key = key; - g_print ("%s-%s-%s-%s-%s-%s-%s\n", - foundry, - family, - weight, - slant, - set_width, - char_set_registry, - char_set_encoding); + if (0) g_print ("%s\n", entry_key); } int main (int argc, char* argv[]) { + GHashTable *font_table = NULL; + test_init (&argc, &argv); - nautilus_font_manager_for_each_font (font_iterator_callback, NULL); + font_table = g_hash_table_new (g_str_hash, g_str_equal); + + nautilus_font_manager_for_each_font (font_iterator_callback, font_table); + + g_hash_table_foreach (font_table, font_table_for_each_callback, NULL); return test_quit (EXIT_SUCCESS); } diff --git a/test/test-nautilus-font-picker.c b/test/test-nautilus-font-picker.c index 89f341c45..ef1566fa5 100644 --- a/test/test-nautilus-font-picker.c +++ b/test/test-nautilus-font-picker.c @@ -1,55 +1,75 @@ -#include <config.h> +#include "test.h" -#include <gtk/gtk.h> -#include <libgnome/gnome-defs.h> -#include <libgnomeui/gnome-init.h> #include <libnautilus-extensions/nautilus-font-picker.h> +#include <libnautilus-extensions/nautilus-font-manager.h> static void -font_picker_changed_callback (GtkWidget *font_picker, gpointer user_data) +font_picker_changed_callback (NautilusFontPicker *font_picker, + gpointer callback_data) { - char *family; - char *weight; - char *slant; - char *set_width; + NautilusScalableFont *font; + char *font_file_name; g_return_if_fail (NAUTILUS_IS_FONT_PICKER (font_picker)); + g_return_if_fail (NAUTILUS_IS_LABEL (callback_data)); - family = nautilus_font_picker_get_selected_family (NAUTILUS_FONT_PICKER (font_picker)); - weight = nautilus_font_picker_get_selected_weight (NAUTILUS_FONT_PICKER (font_picker)); - slant = nautilus_font_picker_get_selected_slant (NAUTILUS_FONT_PICKER (font_picker)); - set_width = nautilus_font_picker_get_selected_set_width (NAUTILUS_FONT_PICKER (font_picker)); + font_file_name = nautilus_font_picker_get_selected_font (font_picker); + g_print ("font changed = %s\n", font_file_name); - g_print ("%s (%s,%s,%s,%s)\n", __FUNCTION__, family, weight, slant, set_width); + font = nautilus_scalable_font_new_from_file_name (font_file_name); + nautilus_label_set_smooth_font (NAUTILUS_LABEL (callback_data), font); + gtk_object_unref (GTK_OBJECT (font)); - g_free (family); - g_free (weight); - g_free (slant); - g_free (set_width); + g_free (font_file_name); } int main (int argc, char * argv[]) { - GtkWidget *window; - GtkWidget *font_picker; + GtkWidget *window; + GtkWidget *vbox; + GtkWidget *font_picker; + GtkWidget *label; - gnome_init ("foo", "bar", argc, argv); - - window = gtk_window_new (GTK_WINDOW_TOPLEVEL); + NautilusScalableFont *font; + + char *fallback_font; + + test_init (&argc, &argv); + + window = test_window_new ("Font Picker Test", 10); + + vbox = gtk_vbox_new (FALSE, 0); + gtk_container_add (GTK_CONTAINER (window), vbox); + + fallback_font = nautilus_font_manager_get_fallback_font (); + g_print ("fallback_font = %s\n", fallback_font); font_picker = nautilus_font_picker_new (); + + label = nautilus_label_new ("Something"); + nautilus_label_set_is_smooth (NAUTILUS_LABEL (label), TRUE); + nautilus_label_make_larger (NAUTILUS_LABEL (label), 40); + + font = nautilus_scalable_font_new_from_file_name ("/usr/share/fonts/default/truetype/times.ttf"); + + nautilus_label_set_smooth_font (NAUTILUS_LABEL (label), font); - gtk_container_add (GTK_CONTAINER (window), font_picker); + gtk_object_unref (GTK_OBJECT (font)); gtk_signal_connect (GTK_OBJECT (font_picker), - "selected_font_changed", + "changed", GTK_SIGNAL_FUNC (font_picker_changed_callback), - (gpointer) NULL); + label); - gtk_widget_show (font_picker); - gtk_widget_show (window); - gtk_main (); + nautilus_font_picker_set_selected_font (NAUTILUS_FONT_PICKER (font_picker), + "/usr/share/fonts/ISO8859-2/Type1/gatsb___.pfb"); + + gtk_box_pack_start (GTK_BOX (vbox), font_picker, TRUE, TRUE, 0); + gtk_box_pack_start (GTK_BOX (vbox), label, TRUE, TRUE, 10); + + gtk_widget_show_all (window); - return 0; + gtk_main (); + return test_quit (EXIT_SUCCESS); } diff --git a/test/test-nautilus-glyph-simple.c b/test/test-nautilus-glyph-simple.c index 8eaa06e9f..414450679 100644 --- a/test/test-nautilus-glyph-simple.c +++ b/test/test-nautilus-glyph-simple.c @@ -105,16 +105,10 @@ main (int argc, char* argv[]) { NautilusScalableFont *font; - int underline_height; - int baseline; ArtIRect glyph_rect; ArtIRect underline_rect; font = nautilus_scalable_font_get_default_font (); - underline_height = nautilus_scalable_font_get_underline_height (font, underlined_font_size); - baseline = nautilus_scalable_font_get_baseline (font, underlined_font_size); - gtk_object_unref (GTK_OBJECT (font)); - glyph_rect = nautilus_glyph_intersect (glyph, x, y, NULL); if (0) nautilus_debug_pixbuf_draw_rectangle (pixbuf, @@ -126,10 +120,7 @@ main (int argc, char* argv[]) 0xFF0000, NAUTILUS_OPACITY_FULLY_OPAQUE); - underline_rect = glyph_rect; - - underline_rect.y1 -= ABS (baseline); - underline_rect.y0 = underline_rect.y1 - underline_height; + nautilus_glyph_get_underline_rectangle (glyph, &underline_rect); nautilus_debug_pixbuf_draw_rectangle (pixbuf, TRUE, @@ -139,9 +130,6 @@ main (int argc, char* argv[]) underline_rect.y1, NAUTILUS_RGBA_COLOR_OPAQUE_BLUE, NAUTILUS_OPACITY_FULLY_OPAQUE); - - g_print ("underline_height = %d\n", underline_height); - g_print ("baseline = %d\n", baseline); } nautilus_glyph_free (glyph); diff --git a/test/test-nautilus-label.c b/test/test-nautilus-label.c index 2bbabd9c1..e6ad7afd6 100644 --- a/test/test-nautilus-label.c +++ b/test/test-nautilus-label.c @@ -199,56 +199,6 @@ alpha_background_color_value_changed_callback (GtkAdjustment *adjustment, gpoint } static void -font_size_changed_callback (NautilusStringPicker *string_picker, gpointer client_data) -{ - char *string; - int size; - - g_return_if_fail (NAUTILUS_IS_STRING_PICKER (string_picker)); - g_return_if_fail (NAUTILUS_IS_LABEL (client_data)); - - string = nautilus_string_picker_get_selected_string (string_picker); - - if (nautilus_eat_str_to_int (string, &size)) { - nautilus_label_set_smooth_font_size (NAUTILUS_LABEL (client_data), (guint) size); - } - - g_free (string); -} - -static void -font_changed_callback (NautilusFontPicker *font_picker, gpointer client_data) -{ - NautilusScalableFont *font; - char *family; - char *weight; - char *slant; - char *set_width; - - g_return_if_fail (NAUTILUS_IS_FONT_PICKER (font_picker)); - g_return_if_fail (NAUTILUS_IS_LABEL (client_data)); - - family = nautilus_font_picker_get_selected_family (NAUTILUS_FONT_PICKER (font_picker)); - weight = nautilus_font_picker_get_selected_weight (NAUTILUS_FONT_PICKER (font_picker)); - slant = nautilus_font_picker_get_selected_slant (NAUTILUS_FONT_PICKER (font_picker)); - set_width = nautilus_font_picker_get_selected_set_width (NAUTILUS_FONT_PICKER (font_picker)); - - g_print ("%s (%s,%s,%s,%s)\n", __FUNCTION__, family, weight, slant, set_width); - - font = nautilus_scalable_font_new (family, weight, slant, set_width); - g_assert (font != NULL); - - nautilus_label_set_smooth_font (NAUTILUS_LABEL (client_data), font); - - g_free (family); - g_free (weight); - g_free (slant); - g_free (set_width); - - gtk_object_unref (GTK_OBJECT (font)); -} - -static void text_caption_changed_callback (NautilusTextCaption *text_caption, gpointer client_data) { NautilusLabel *label; @@ -400,53 +350,6 @@ create_color_picker_frame (const char *title, } static GtkWidget* -create_font_picker_frame (const char *title, - GtkSignalFunc changed_callback, - GtkSignalFunc size_changed_callback, - gpointer callback_data) -{ - GtkWidget *frame; - GtkWidget *hbox; - GtkWidget *font_picker; - GtkWidget *font_size_picker; - NautilusStringList *font_size_list; - - g_return_val_if_fail (title != NULL, NULL); - g_return_val_if_fail (changed_callback != NULL, NULL); - g_return_val_if_fail (size_changed_callback != NULL, NULL); - - frame = gtk_frame_new (title); - - hbox = gtk_hbox_new (FALSE, 0); - gtk_container_set_border_width (GTK_CONTAINER (hbox), 6); - - gtk_container_add (GTK_CONTAINER (frame), hbox); - - font_size_picker = nautilus_string_picker_new (); - nautilus_caption_set_show_title (NAUTILUS_CAPTION (font_size_picker), FALSE); - nautilus_caption_set_title_label (NAUTILUS_CAPTION (font_size_picker), "Size"); - - gtk_signal_connect (GTK_OBJECT (font_size_picker), "changed", size_changed_callback, callback_data); - - font_size_list = nautilus_string_list_new_from_tokens ("5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20," - "30,40,50,60,70,80,90,100,110,120,130,140," - "200,400,800", ",", TRUE); - - nautilus_string_picker_set_string_list (NAUTILUS_STRING_PICKER (font_size_picker), font_size_list); - nautilus_string_list_free (font_size_list); - - font_picker = nautilus_font_picker_new (); - gtk_signal_connect (GTK_OBJECT (font_picker), "selected_font_changed", changed_callback, callback_data); - - gtk_box_pack_start (GTK_BOX (hbox), font_picker, TRUE, TRUE, 0); - gtk_box_pack_end (GTK_BOX (hbox), font_size_picker, FALSE, FALSE, 5); - - gtk_widget_show_all (hbox); - - return frame; -} - -static GtkWidget* create_text_caption_frame (const char *title, GtkSignalFunc changed_callback, gpointer callback_data) @@ -732,12 +635,10 @@ main (int argc, char* argv[]) GtkWidget *bottom_box; GtkWidget *tool_box1; GtkWidget *tool_box2; - GtkWidget *tool_box3; GtkWidget *color_tool_box; GtkWidget *label; GtkWidget *label_color_picker_frame; GtkWidget *background_color_picker_frame; - GtkWidget *font_picker_frame; GtkWidget *text_caption_frame; GtkWidget *background_frame; GtkWidget *justification_frame; @@ -763,13 +664,11 @@ main (int argc, char* argv[]) tool_box1 = gtk_hbox_new (FALSE, 0); tool_box2 = gtk_hbox_new (FALSE, 0); - tool_box3 = gtk_hbox_new (FALSE, 0); color_tool_box = gtk_hbox_new (FALSE, 0); gtk_box_pack_start (GTK_BOX (bottom_box), tool_box1, TRUE, TRUE, 0); gtk_box_pack_start (GTK_BOX (bottom_box), tool_box2, TRUE, TRUE, 0); - gtk_box_pack_end (GTK_BOX (bottom_box), tool_box3, TRUE, TRUE, 10); gtk_box_pack_start (GTK_BOX (main_box), label, TRUE, TRUE, 10); gtk_box_pack_end (GTK_BOX (main_box), bottom_box, TRUE, TRUE, 10); @@ -792,11 +691,6 @@ main (int argc, char* argv[]) label, nautilus_label_get_text_color (NAUTILUS_LABEL (label))); - font_picker_frame = create_font_picker_frame ("Font", - font_changed_callback, - font_size_changed_callback, - label); - text_caption_frame = create_text_caption_frame ("Text", text_caption_changed_callback, label); @@ -823,8 +717,7 @@ main (int argc, char* argv[]) gtk_box_pack_end (GTK_BOX (color_tool_box), background_color_picker_frame, FALSE, FALSE, 0); gtk_box_pack_start (GTK_BOX (tool_box1), color_tool_box, FALSE, FALSE, 0); - gtk_box_pack_start (GTK_BOX (tool_box2), font_picker_frame, FALSE, FALSE, 0); - gtk_box_pack_start (GTK_BOX (tool_box3), text_caption_frame, TRUE, TRUE, 0); + gtk_box_pack_start (GTK_BOX (tool_box2), text_caption_frame, TRUE, TRUE, 0); gtk_widget_show_all (window); |