Instead of having the normal-weight and bold fonts set separately,

generate the name of the boldface font from the Roman font; if the two
fonts don't have the same widths, the display will look weird when a
field is selected, and it's a bit of a pain for the user to have to
select *two* fonts.

On UNIX/X, default to
"-*-fixed-medium-r-semicondensed-*-*-120-*-*-*-*-*-" rather than to
"-*-lucidatypewriter-medium-r-normal-*-*-120-*-*-*-*-iso8859-1" - some
Linux distributions appear to lack the Lucida typewriter font.

Add a "gui.font_name" preference to the preferences file, specifying the
normal-weight font to use.  Have it settable from the "GUI" tab in the
Preferences dialog box - the "Font..." button, when clicked, pops up a
font selection dialog box.

If we either can't open the selected font or the boldfaced version of
the font, default to "6x13" and "6x13bold" as fallbacks - the former
will probably be "fixed", and the latter would be "fixedbold" if X
actually created such an alias, but it doesn't so we use "6x13bold"
instead.

svn path=/trunk/; revision=2304
This commit is contained in:
Guy Harris 2000-08-20 07:53:45 +00:00
parent 2962655ac5
commit e697eb8e9f
7 changed files with 265 additions and 40 deletions

View File

@ -1,7 +1,7 @@
/* capture.c
* Routines for packet capture windows
*
* $Id: capture.c,v 1.120 2000/08/19 18:20:56 deniel Exp $
* $Id: capture.c,v 1.121 2000/08/20 07:53:29 guy Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@zing.org>
@ -275,7 +275,7 @@ do_capture(char *capfile_name)
execlp(ethereal_path, CHILD_NAME, "-i", cfile.iface,
"-w", cfile.save_file, "-W", save_file_fd,
"-c", scount, "-s", ssnap,
"-m", medium_font, "-b", bold_font,
"-m", prefs.gui_font_name,
(cfile.cfilter == NULL)? 0 : "-f",
(cfile.cfilter == NULL)? 0 : cfile.cfilter,
(const char *)NULL);

View File

@ -1,7 +1,7 @@
/* globals.h
* Global defines, etc.
*
* $Id: globals.h,v 1.20 2000/08/11 13:34:29 deniel Exp $
* $Id: globals.h,v 1.21 2000/08/20 07:53:30 guy Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@zing.org>
@ -68,8 +68,6 @@ extern capture_file cfile;
extern guint main_ctx, file_ctx;
extern gchar comp_info_str[256];
extern gchar *ethereal_path;
extern gchar *medium_font;
extern gchar *bold_font;
extern gchar *last_open_dir;
extern gboolean auto_scroll_live;
extern int g_resolving_actif;

View File

@ -1,7 +1,7 @@
/* gui_prefs.c
* Dialog box for GUI preferences
*
* $Id: gui_prefs.c,v 1.5 2000/08/11 13:33:02 deniel Exp $
* $Id: gui_prefs.c,v 1.6 2000/08/20 07:53:43 guy Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@zing.org>
@ -33,18 +33,27 @@
#include "gui_prefs.h"
#include "gtkglobals.h"
#include "prefs_dlg.h"
#include "ui_util.h"
#include "dlg_utils.h"
static void scrollbar_menu_item_cb(GtkWidget *w, gpointer data);
static void plist_sel_browse_cb(GtkWidget *w, gpointer data);
static void ptree_sel_browse_cb(GtkWidget *w, gpointer data);
static void ptree_line_style_cb(GtkWidget *w, gpointer data);
static void ptree_expander_style_cb(GtkWidget *w, gpointer data);
static void font_browse_cb(GtkWidget *w, gpointer data);
static void font_browse_ok_cb(GtkWidget *w, GtkFontSelectionDialog *fs);
static void font_browse_destroy(GtkWidget *win, gpointer data);
static gboolean temp_gui_scrollbar_on_right;
static gboolean temp_gui_plist_sel_browse;
static gboolean temp_gui_ptree_sel_browse;
static gint temp_gui_ptree_line_style;
static gint temp_gui_ptree_expander_style;
static gchar *temp_gui_font_name;
#define E_FONT_DIALOG_PTR_KEY "font_dialog_ptr"
#define E_FONT_CALLER_PTR_KEY "font_caller_ptr"
GtkWidget*
gui_prefs_show(void)
@ -52,20 +61,21 @@ gui_prefs_show(void)
GtkWidget *main_tb, *main_vb, *label;
GtkWidget *menu_item_false, *menu_item_true,
*menu_item_0, *menu_item_1, *menu_item_2, *menu_item_3,
*scrollbar_menu, *scrollbar_option_menu;
*scrollbar_menu, *scrollbar_option_menu, *font_bt;
temp_gui_scrollbar_on_right = prefs.gui_scrollbar_on_right;
temp_gui_plist_sel_browse = prefs.gui_plist_sel_browse;
temp_gui_ptree_sel_browse = prefs.gui_ptree_sel_browse;
temp_gui_ptree_line_style = prefs.gui_ptree_line_style;
temp_gui_ptree_expander_style = prefs.gui_ptree_expander_style;
temp_gui_font_name = g_strdup(prefs.gui_font_name);
/* Main vertical box */
main_vb = gtk_vbox_new(FALSE, 5);
gtk_container_border_width( GTK_CONTAINER(main_vb), 5 );
/* Main table */
main_tb = gtk_table_new(5, 2, FALSE);
main_tb = gtk_table_new(6, 2, FALSE);
gtk_box_pack_start( GTK_BOX(main_vb), main_tb, FALSE, FALSE, 0 );
gtk_table_set_row_spacings( GTK_TABLE(main_tb), 10 );
gtk_table_set_col_spacings( GTK_TABLE(main_tb), 15 );
@ -222,6 +232,12 @@ gui_prefs_show(void)
gtk_table_attach_defaults( GTK_TABLE(main_tb), scrollbar_option_menu,
1, 2, 4, 5 );
/* "Font..." button - click to open a font selection dialog box. */
font_bt = gtk_button_new_with_label("Font...");
gtk_signal_connect(GTK_OBJECT(font_bt), "clicked",
GTK_SIGNAL_FUNC(font_browse_cb), NULL);
gtk_table_attach_defaults( GTK_TABLE(main_tb), font_bt, 1, 2, 5, 6 );
/* Show 'em what we got */
gtk_widget_show_all(main_vb);
@ -274,6 +290,119 @@ ptree_expander_style_cb(GtkWidget *w, gpointer data)
set_ptree_expander_style_all(value);
}
/* XXX - need a way to set this on the fly, so that a font change takes
effect immediately, rather than requiring the user to exit and restart
Ethereal. */
/* Create a font dialog for browsing. */
static void
font_browse_cb(GtkWidget *w, gpointer data)
{
GtkWidget *caller = gtk_widget_get_toplevel(w);
GtkWidget *font_browse_w;
static gchar *fixedwidths[] = { "c", "m", NULL };
/* Has a font dialog box already been opened for that top-level
widget? */
font_browse_w = gtk_object_get_data(GTK_OBJECT(caller),
E_FONT_DIALOG_PTR_KEY);
if (font_browse_w != NULL) {
/* Yes. Just re-activate that dialog box. */
reactivate_window(font_browse_w);
return;
}
/* Now create a new dialog. */
font_browse_w = gtk_font_selection_dialog_new("Ethereal: Select Font");
gtk_window_set_transient_for(GTK_WINDOW(font_browse_w),
GTK_WINDOW(top_level));
/* Call a handler when we're destroyed, so we can inform
our caller, if any, that we've been destroyed. */
gtk_signal_connect(GTK_OBJECT(font_browse_w), "destroy",
GTK_SIGNAL_FUNC(font_browse_destroy), NULL);
/* Set its filter to show only fixed_width fonts. */
gtk_font_selection_dialog_set_filter(
GTK_FONT_SELECTION_DIALOG(font_browse_w),
GTK_FONT_FILTER_BASE, /* user can't change the filter */
GTK_FONT_ALL, /* bitmap or scalable are fine */
NULL, /* all foundries are OK */
NULL, /* all weights are OK (XXX - normal only?) */
NULL, /* all slants are OK (XXX - Roman only?) */
NULL, /* all setwidths are OK */
fixedwidths, /* ONLY fixed-width fonts */
NULL); /* all charsets are OK (XXX - ISO 8859/1 only?) */
/* Set the font to the current font.
XXX - this doesn't seem to work right. */
gtk_font_selection_dialog_set_font_name(
GTK_FONT_SELECTION_DIALOG(font_browse_w), prefs.gui_font_name);
/* Set the E_FONT_CALLER_PTR_KEY for the new dialog to point to
our caller. */
gtk_object_set_data(GTK_OBJECT(font_browse_w), E_FONT_CALLER_PTR_KEY,
caller);
/* Set the E_FONT_DIALOG_PTR_KEY for the caller to point to us */
gtk_object_set_data(GTK_OBJECT(caller), E_FONT_DIALOG_PTR_KEY,
font_browse_w);
/* Connect the ok_button to font_browse_ok_cb function and pass along a
pointer to the font selection box widget */
gtk_signal_connect(
GTK_OBJECT(GTK_FONT_SELECTION_DIALOG(font_browse_w)->ok_button),
"clicked", (GtkSignalFunc)font_browse_ok_cb, font_browse_w);
/* Connect the cancel_button to destroy the widget */
gtk_signal_connect_object(
GTK_OBJECT(GTK_FONT_SELECTION_DIALOG(font_browse_w)->cancel_button),
"clicked", (GtkSignalFunc)gtk_widget_destroy,
GTK_OBJECT(font_browse_w));
/* Catch the "key_press_event" signal in the window, so that we can
catch the ESC key being pressed and act as if the "Cancel" button
had been selected. */
dlg_set_cancel(font_browse_w,
GTK_FONT_SELECTION_DIALOG(font_browse_w)->cancel_button);
gtk_widget_show(font_browse_w);
}
static void
font_browse_ok_cb(GtkWidget *w, GtkFontSelectionDialog *fs)
{
if (temp_gui_font_name != NULL)
g_free(temp_gui_font_name);
temp_gui_font_name =
g_strdup(gtk_font_selection_dialog_get_font_name(
GTK_FONT_SELECTION_DIALOG(fs)));
gtk_widget_hide(GTK_WIDGET(fs));
gtk_widget_destroy(GTK_WIDGET(fs));
}
static void
font_browse_destroy(GtkWidget *win, gpointer data)
{
GtkWidget *caller;
/* Get the widget that requested that we be popped up, if any.
(It should arrange to destroy us if it's destroyed, so
that we don't get a pointer to a non-existent window here.) */
caller = gtk_object_get_data(GTK_OBJECT(win), E_FONT_CALLER_PTR_KEY);
if (caller != NULL) {
/* Tell it we no longer exist. */
gtk_object_set_data(GTK_OBJECT(caller), E_FONT_DIALOG_PTR_KEY,
NULL);
}
/* Now nuke this window. */
gtk_grab_remove(GTK_WIDGET(win));
gtk_widget_destroy(GTK_WIDGET(win));
}
void
gui_prefs_ok(GtkWidget *w)
@ -283,6 +412,9 @@ gui_prefs_ok(GtkWidget *w)
prefs.gui_ptree_sel_browse = temp_gui_ptree_sel_browse;
prefs.gui_ptree_line_style = temp_gui_ptree_line_style;
prefs.gui_ptree_expander_style = temp_gui_ptree_expander_style;
if (prefs.gui_font_name != NULL)
g_free(prefs.gui_font_name);
prefs.gui_font_name = g_strdup(temp_gui_font_name);
gui_prefs_delete(w);
}
@ -303,6 +435,9 @@ gui_prefs_cancel(GtkWidget *w)
temp_gui_ptree_sel_browse = prefs.gui_ptree_sel_browse;
temp_gui_ptree_line_style = prefs.gui_ptree_line_style;
temp_gui_ptree_expander_style = prefs.gui_ptree_expander_style;
if (temp_gui_font_name != NULL)
g_free(temp_gui_font_name);
temp_gui_font_name = g_strdup(prefs.gui_font_name);
set_scrollbar_placement_all(prefs.gui_scrollbar_on_right);
set_plist_sel_browse(prefs.gui_plist_sel_browse);
@ -316,4 +451,20 @@ gui_prefs_cancel(GtkWidget *w)
void
gui_prefs_delete(GtkWidget *w)
{
GtkWidget *caller = gtk_widget_get_toplevel(w);
GtkWidget *fs;
/* Is there a font selection dialog associated with this
Preferences dialog? */
fs = gtk_object_get_data(GTK_OBJECT(caller), E_FONT_DIALOG_PTR_KEY);
if (fs != NULL) {
/* Yes. Destroy it. */
gtk_widget_destroy(fs);
}
if (temp_gui_font_name != NULL) {
g_free(temp_gui_font_name);
temp_gui_font_name = NULL;
}
}

View File

@ -1,6 +1,6 @@
/* main.c
*
* $Id: main.c,v 1.136 2000/08/17 07:56:37 guy Exp $
* $Id: main.c,v 1.137 2000/08/20 07:53:43 guy Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@zing.org>
@ -126,8 +126,6 @@ GdkFont *m_r_font, *m_b_font;
guint main_ctx, file_ctx;
gchar comp_info_str[256];
gchar *ethereal_path = NULL;
gchar *medium_font = MONO_MEDIUM_FONT;
gchar *bold_font = MONO_BOLD_FONT;
gchar *last_open_dir = NULL;
ts_type timestamp_type = RELATIVE;
@ -138,6 +136,7 @@ GtkStyle *item_style;
field_info *finfo_selected = NULL;
static char* hfinfo_numeric_format(header_field_info *hfinfo);
static char *boldify(const char *font_name);
static void create_main_window(gint, gint, gint, e_prefs*);
/* About Ethereal window */
@ -791,6 +790,7 @@ main(int argc, char *argv[])
dfilter *rfcode = NULL;
gboolean rfilter_parse_failed = FALSE;
e_prefs *prefs;
char *bold_font_name;
ethereal_path = argv[0];
@ -915,11 +915,8 @@ main(int argc, char *argv[])
);
/* Now get our args */
while ((opt = getopt(argc, argv, "b:B:c:Df:hi:km:no:P:Qr:R:Ss:t:T:w:W:vZ:")) != EOF) {
while ((opt = getopt(argc, argv, "B:c:Df:hi:km:no:P:Qr:R:Ss:t:T:w:W:vZ:")) != EOF) {
switch (opt) {
case 'b': /* Bold font */
bold_font = g_strdup(optarg);
break;
case 'B': /* Byte view pane height */
bv_size = atoi(optarg);
break;
@ -964,8 +961,10 @@ main(int argc, char *argv[])
arg_error = TRUE;
#endif
break;
case 'm': /* Medium font */
medium_font = g_strdup(optarg);
case 'm': /* Fixed-width font for the display */
if (prefs->gui_font_name != NULL)
g_free(prefs->gui_font_name);
prefs->gui_font_name = g_strdup(optarg);
break;
case 'n': /* No name resolution */
g_resolving_actif = 0;
@ -1152,14 +1151,31 @@ main(int argc, char *argv[])
sprintf(rc_file, "%s/%s", get_home_dir(), RC_FILE);
gtk_rc_parse(rc_file);
if ((m_r_font = gdk_font_load(medium_font)) == NULL) {
fprintf(stderr, "ethereal: Error font %s not found (use -m option)\n", medium_font);
exit(1);
}
if ((m_b_font = gdk_font_load(bold_font)) == NULL) {
fprintf(stderr, "ethereal: Error font %s not found (use -b option)\n", bold_font);
exit(1);
/* Try to load the regular and boldface fixed-width fonts */
bold_font_name = boldify(prefs->gui_font_name);
m_r_font = gdk_font_load(prefs->gui_font_name);
m_b_font = gdk_font_load(bold_font_name);
if (m_r_font == NULL || m_b_font == NULL) {
/* XXX - pop this up as a dialog box? */
if (m_r_font == NULL)
fprintf(stderr, "ethereal: Warning: font %s not found - defaulting to 6x13 and 6x13bold\n",
prefs->gui_font_name);
else
gdk_font_unref(m_r_font);
if (m_b_font == NULL)
fprintf(stderr, "ethereal: Warning: font %s not found - defaulting to 6x13 and 6x13bold\n",
bold_font_name);
else
gdk_font_unref(m_b_font);
g_free(bold_font_name);
if ((m_r_font = gdk_font_load("6x13")) == NULL) {
fprintf(stderr, "ethereal: Error: font 6x13 not found\n");
exit(1);
}
if ((m_b_font = gdk_font_load("6x13bold")) == NULL) {
fprintf(stderr, "ethereal: Error: font 6x13 not found\n");
exit(1);
}
}
create_main_window(pl_size, tv_size, bv_size, prefs);
@ -1306,6 +1322,59 @@ WinMain (struct HINSTANCE__ *hInstance,
#endif
/* Given a font name, construct the name of the next heavier version of
that font. */
#define XLFD_WEIGHT 3 /* index of the "weight" field */
/* Map from a given weight to the appropriate weight for the "bold"
version of a font.
XXX - the XLFD says these strings shouldn't be used for font matching;
can we get the weight, as a number, from GDK, and ask GDK to find us
a font just like the given font, but with the appropriate higher
weight? */
static const struct {
char *light;
char *heavier;
} weight_map[] = {
{ "ultralight", "light" },
{ "extralight", "semilight" },
{ "light", "medium" },
{ "semilight", "semibold" },
{ "medium", "bold" },
{ "semibold", "extrabold" },
{ "bold", "ultrabold" }
};
#define N_WEIGHTS (sizeof weight_map / sizeof weight_map[0])
static char *
boldify(const char *font_name)
{
char *bold_font_name;
gchar **xlfd_tokens;
int i;
/* Is this an XLFD font? If it begins with "-", yes, otherwise no. */
if (font_name[0] == '-') {
xlfd_tokens = g_strsplit(font_name, "-", XLFD_WEIGHT+1);
for (i = 0; i < N_WEIGHTS; i++) {
if (strcmp(xlfd_tokens[XLFD_WEIGHT],
weight_map[i].light) == 0) {
g_free(xlfd_tokens[XLFD_WEIGHT]);
xlfd_tokens[XLFD_WEIGHT] =
g_strdup(weight_map[i].heavier);
break;
}
}
bold_font_name = g_strjoinv("-", xlfd_tokens);
g_strfreev(xlfd_tokens);
} else {
/* Append "bold" to the name of the font. */
bold_font_name = g_strconcat(font_name, "bold", NULL);
}
return bold_font_name;
}
static void
create_main_window (gint pl_size, gint tv_size, gint bv_size, e_prefs *prefs)
{

View File

@ -1,7 +1,7 @@
/* main.h
* Global defines, etc.
*
* $Id: main.h,v 1.16 2000/08/11 13:32:58 deniel Exp $
* $Id: main.h,v 1.17 2000/08/20 07:53:45 guy Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@zing.org>
@ -32,13 +32,6 @@
#include "globals.h"
#ifdef WIN32
#define MONO_MEDIUM_FONT "-*-lucida console-medium-*-*-*-*-100-*-*-*-*-*-*"
#define MONO_BOLD_FONT "-*-lucida console-bold-*-*-*-*-100-*-*-*-*-*-*"
#else
#define MONO_MEDIUM_FONT "-*-lucidatypewriter-medium-r-normal-*-*-120-*-*-*-*-iso8859-1"
#define MONO_BOLD_FONT "-*-lucidatypewriter-bold-r-normal-*-*-120-*-*-*-*-iso8859-1"
#endif
#define RC_FILE PF_DIR "/gtkrc"
#define DEF_WIDTH 750
#define DEF_HEIGHT 550

15
prefs.c
View File

@ -1,7 +1,7 @@
/* prefs.c
* Routines for handling preferences
*
* $Id: prefs.c,v 1.36 2000/08/15 20:53:30 deniel Exp $
* $Id: prefs.c,v 1.37 2000/08/20 07:53:31 guy Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@zing.org>
@ -515,6 +515,11 @@ read_prefs(int *gpf_errno_return, char **gpf_path_return,
prefs.gui_ptree_sel_browse = FALSE;
prefs.gui_ptree_line_style = 0;
prefs.gui_ptree_expander_style = 1;
#ifdef WIN32
prefs.gui_font_name = g_strdup("-*-lucida console-medium-r-*-*-*-100-*-*-*-*-*-*");
#else
prefs.gui_font_name = g_strdup("-*-fixed-medium-r-semicondensed-*-*-120-*-*-*-*-*-");
#endif
}
/* Read the global preferences file, if it exists. */
@ -727,6 +732,7 @@ prefs_set_pref(char *prefarg)
#define PRS_GUI_PTREE_SEL_BROWSE "gui.protocol_tree_sel_browse"
#define PRS_GUI_PTREE_LINE_STYLE "gui.protocol_tree_line_style"
#define PRS_GUI_PTREE_EXPANDER_STYLE "gui.protocol_tree_expander_style"
#define PRS_GUI_FONT_NAME "gui.font_name"
#define RED_COMPONENT(x) ((((x) >> 16) & 0xff) * 65535 / 255)
#define GREEN_COMPONENT(x) ((((x) >> 8) & 0xff) * 65535 / 255)
@ -846,6 +852,10 @@ set_pref(gchar *pref_name, gchar *value)
} else if (strcmp(pref_name, PRS_GUI_PTREE_EXPANDER_STYLE) == 0) {
prefs.gui_ptree_expander_style =
find_index_from_string_array(value, gui_ptree_expander_style_text, 1);
} else if (strcmp(pref_name, PRS_GUI_FONT_NAME) == 0) {
if (prefs.gui_font_name != NULL)
g_free(prefs.gui_font_name);
prefs.gui_font_name = g_strdup(value);
} else {
/* To which module does this preference belong? */
dotp = strchr(pref_name, '.');
@ -1091,6 +1101,9 @@ write_prefs(char **pf_path_return)
fprintf(pf, PRS_GUI_PTREE_EXPANDER_STYLE ": %s\n",
gui_ptree_expander_style_text[prefs.gui_ptree_expander_style]);
fprintf(pf, "\n# Font name for packet list, protocol tree, and hex dump panes.\n");
fprintf(pf, PRS_GUI_FONT_NAME ": %s\n", prefs.gui_font_name);
g_list_foreach(modules, write_module_prefs, pf);
fclose(pf);

13
prefs.h
View File

@ -1,7 +1,7 @@
/* prefs.h
* Definitions for preference handling routines
*
* $Id: prefs.h,v 1.20 2000/08/17 21:02:10 deniel Exp $
* $Id: prefs.h,v 1.21 2000/08/20 07:53:31 guy Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@zing.org>
@ -41,11 +41,12 @@ typedef struct _e_prefs {
GList *col_list;
gint num_cols;
GdkColor st_client_fg, st_client_bg, st_server_fg, st_server_bg;
gboolean gui_scrollbar_on_right;
gboolean gui_plist_sel_browse;
gboolean gui_ptree_sel_browse;
gint gui_ptree_line_style;
gint gui_ptree_expander_style;
gboolean gui_scrollbar_on_right;
gboolean gui_plist_sel_browse;
gboolean gui_ptree_sel_browse;
gint gui_ptree_line_style;
gint gui_ptree_expander_style;
gchar *gui_font_name;
} e_prefs;
extern e_prefs prefs;