diff options
author | ulfl <ulfl@f5534014-38df-0310-8fa8-9805f1628bb7> | 2004-06-17 16:35:26 +0000 |
---|---|---|
committer | ulfl <ulfl@f5534014-38df-0310-8fa8-9805f1628bb7> | 2004-06-17 16:35:26 +0000 |
commit | df9dcea54a59355ac6190fbf21dfdf2b2c9a171a (patch) | |
tree | f5502b917117b0ab16cad12e3d40031a29811b18 /gtk | |
parent | 8a9b0e536c61913306b889de87a5f54afadaff05 (diff) |
move font related stuff to new file font_utils.c/.h
do some font related renaming/code cleanup
git-svn-id: http://anonsvn.wireshark.org/wireshark/trunk@11166 f5534014-38df-0310-8fa8-9805f1628bb7
Diffstat (limited to 'gtk')
-rw-r--r-- | gtk/Makefile.am | 3 | ||||
-rw-r--r-- | gtk/Makefile.common | 5 | ||||
-rw-r--r-- | gtk/compat_macros.h | 8 | ||||
-rw-r--r-- | gtk/follow_dlg.c | 8 | ||||
-rw-r--r-- | gtk/font_utils.c | 807 | ||||
-rw-r--r-- | gtk/font_utils.h | 100 | ||||
-rw-r--r-- | gtk/gtkglobals.h | 20 | ||||
-rw-r--r-- | gtk/gui_prefs.c | 64 | ||||
-rw-r--r-- | gtk/main.c | 677 | ||||
-rw-r--r-- | gtk/main.h | 23 | ||||
-rw-r--r-- | gtk/packet_list.c | 13 | ||||
-rw-r--r-- | gtk/packet_list.h | 12 | ||||
-rw-r--r-- | gtk/proto_draw.c | 63 | ||||
-rw-r--r-- | gtk/supported_protos_dlg.c | 19 | ||||
-rw-r--r-- | gtk/tcp_graph.c | 8 | ||||
-rw-r--r-- | gtk/text_page.c | 9 |
16 files changed, 1001 insertions, 838 deletions
diff --git a/gtk/Makefile.am b/gtk/Makefile.am index 8917174b9f..96225e31da 100644 --- a/gtk/Makefile.am +++ b/gtk/Makefile.am @@ -1,7 +1,7 @@ # Makefile.am # Automake file for the GTK interface routines for Ethereal # -# $Id: Makefile.am,v 1.102 2004/06/09 19:20:46 gerald Exp $ +# $Id: Makefile.am,v 1.103 2004/06/17 16:35:25 ulfl Exp $ # # Ethereal - Network traffic analyzer # By Gerald Combs <gerald@ethereal.com> @@ -52,6 +52,7 @@ noinst_HEADERS = \ filter_prefs.h \ find_dlg.h \ follow_dlg.h \ + font_utils.h \ goto_dlg.h \ gsm_map_stat.h \ gtkglobals.h \ diff --git a/gtk/Makefile.common b/gtk/Makefile.common index 0b6874b5a7..2ec414bc38 100644 --- a/gtk/Makefile.common +++ b/gtk/Makefile.common @@ -3,7 +3,7 @@ # a) common to both files and # b) portable between both files # -# $Id: Makefile.common,v 1.14 2004/06/05 09:57:10 ulfl Exp $ +# $Id: Makefile.common,v 1.15 2004/06/17 16:35:25 ulfl Exp $ # # Ethereal - Network traffic analyzer # By Gerald Combs <gerald@ethereal.com> @@ -26,7 +26,7 @@ # # ethclist.obj is not in here because it is currently gtk+-1.2-only -# code, while the DLL for GTK+ on Windows is gtk+-1.3. +# code, while the DLL for GTK+ on Windows is gtk+-1.3 or gtk+-2.x. # ETHEREAL_GTK_SRC = \ about_dlg.c \ @@ -48,6 +48,7 @@ ETHEREAL_GTK_SRC = \ filter_prefs.c \ find_dlg.c \ follow_dlg.c \ + font_utils.c \ goto_dlg.c \ gtk_stat_util.c \ gui_prefs.c \ diff --git a/gtk/compat_macros.h b/gtk/compat_macros.h index e6a4717629..e871a388c3 100644 --- a/gtk/compat_macros.h +++ b/gtk/compat_macros.h @@ -1,7 +1,7 @@ /* compat_macros.h * GTK-related Global defines, etc. * - * $Id: compat_macros.h,v 1.19 2004/06/05 10:27:38 ulfl Exp $ + * $Id: compat_macros.h,v 1.20 2004/06/17 16:35:23 ulfl Exp $ * * Ethereal - Network traffic analyzer * By Gerald Combs <gerald@ethereal.com> @@ -242,6 +242,10 @@ dlg_toggle_button_new_with_label_with_mnemonic(label_text, accel_group) /** tag(s) end for first row of simple_dialog (and others). */ #define PRIMARY_TEXT_END "" +#define FONT_TYPE GdkFont + +/*************************************************************************/ + #else /* GTK_MAJOR_VERSION >= 2 */ #define SIGNAL_CONNECT(widget, name, callback, arg) \ @@ -325,6 +329,8 @@ gtk_toggle_button_new_with_mnemonic(label_text) #define PRIMARY_TEXT_START "<span weight=\"bold\" size=\"larger\">" #define PRIMARY_TEXT_END "</span>" +#define FONT_TYPE PangoFontDescription + #endif /* GTK_MAJOR_VERSION */ #endif /* __COMPAT_MACROS_H__ */ diff --git a/gtk/follow_dlg.c b/gtk/follow_dlg.c index 531e52412e..1480e2c078 100644 --- a/gtk/follow_dlg.c +++ b/gtk/follow_dlg.c @@ -1,6 +1,6 @@ /* follow_dlg.c * - * $Id: follow_dlg.c,v 1.65 2004/06/01 17:33:36 ulfl Exp $ + * $Id: follow_dlg.c,v 1.66 2004/06/17 16:35:24 ulfl Exp $ * * Ethereal - Network traffic analyzer * By Gerald Combs <gerald@ethereal.com> @@ -48,7 +48,6 @@ #include "dlg_utils.h" #include "keys.h" #include "globals.h" -#include "gtkglobals.h" #include "main.h" #include "alert_box.h" #include "simple_dialog.h" @@ -63,6 +62,7 @@ #include "ipproto.h" #include "tap_menu.h" #include "print_mswin.h" +#include "font_utils.h" /* Show Stream */ typedef enum { @@ -924,12 +924,12 @@ follow_add_to_gtk_text(char *buffer, int nchars, gboolean is_server, color_t_to_gdkcolor(&bg, &prefs.st_client_bg); } #if GTK_MAJOR_VERSION < 2 - gtk_text_insert(GTK_TEXT(text), m_r_font, &fg, &bg, buffer, nchars); + gtk_text_insert(GTK_TEXT(text), user_font_get_regular(), &fg, &bg, buffer, nchars); #else gtk_text_buffer_get_end_iter(buf, &iter); tag = gtk_text_buffer_create_tag(buf, NULL, "foreground-gdk", &fg, "background-gdk", &bg, "font-desc", - m_r_font, NULL); + user_font_get_regular(), NULL); convbuf = g_locale_to_utf8(buffer, nchars, NULL, &outbytes, NULL); gtk_text_buffer_insert_with_tags(buf, &iter, convbuf, outbytes, tag, NULL); diff --git a/gtk/font_utils.c b/gtk/font_utils.c new file mode 100644 index 0000000000..0242644585 --- /dev/null +++ b/gtk/font_utils.c @@ -0,0 +1,807 @@ +/* font_utils.c + * Utilities to use for font manipulation + * + * $Id: font_utils.c,v 1.1 2004/06/17 16:35:24 ulfl Exp $ + * + * Ethereal - Network traffic analyzer + * By Gerald Combs <gerald@ethereal.com> + * Copyright 1998 Gerald Combs + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include <gtk/gtk.h> +#include <string.h> +#include <stdlib.h> +#include <stdio.h> + +#ifdef WIN32 +#include <windows.h> +#endif + +#include "recent.h" +#include "prefs.h" + +#include "gtkglobals.h" + +#include "compat_macros.h" +#include "font_utils.h" +#include "simple_dialog.h" + +#include "packet_list.h" +#include "proto_draw.h" +#include "follow_dlg.h" + + +/* XXX - use capture.h instead */ +/*#include "capture.h"*/ +extern gboolean capture_child; + + + +#if GTK_MAJOR_VERSION < 2 +guint m_font_height, m_font_width; +#endif +FONT_TYPE *m_r_font, *m_b_font; + + +/* Get the regular user font. + * + * @return the regular user font + */ +FONT_TYPE *user_font_get_regular(void) +{ + return m_r_font; +} + +/* Get the bold user font. + * + * @return the bold user font + */ +FONT_TYPE *user_font_get_bold(void) +{ + return m_b_font; +} + +#if GTK_MAJOR_VERSION < 2 +/* Get the regular user font height. + * + * @return the regular user font height + */ +guint user_font_get_regular_height(void) +{ + return m_font_height; +} + +/* Get the regular user font width. + * + * @return the regular user font width + */ +guint user_font_get_regular_width(void) +{ + return m_font_width; +} +#endif + + +static void +set_fonts(FONT_TYPE *regular, FONT_TYPE *bold) +{ + /* Yes, assert. The code that loads the font should check + * for NULL and provide its own error message. */ + g_assert(m_r_font && m_b_font); + m_r_font = regular; + m_b_font = bold; + +#if GTK_MAJOR_VERSION < 2 + m_font_height = m_r_font->ascent + m_r_font->descent; + m_font_width = gdk_string_width(m_r_font, "0"); +#endif +} + +void +view_zoom_in_cb(GtkWidget *w _U_, gpointer d _U_) +{ + gint save_gui_zoom_level; + + save_gui_zoom_level = recent.gui_zoom_level; + recent.gui_zoom_level++; + switch (user_font_apply()) { + + case FA_SUCCESS: + break; + + case FA_FONT_NOT_RESIZEABLE: + /* "font_apply()" popped up an alert box. */ + recent.gui_zoom_level = save_gui_zoom_level; /* undo zoom */ + break; + + case FA_FONT_NOT_AVAILABLE: + /* We assume this means that the specified size isn't available. */ + simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, + "Your current font isn't available in the next larger size.\n"); + recent.gui_zoom_level = save_gui_zoom_level; /* undo zoom */ + break; + } +} + +void +view_zoom_out_cb(GtkWidget *w _U_, gpointer d _U_) +{ + gint save_gui_zoom_level; + + save_gui_zoom_level = recent.gui_zoom_level; + recent.gui_zoom_level--; + switch (user_font_apply()) { + + case FA_SUCCESS: + break; + + case FA_FONT_NOT_RESIZEABLE: + /* "font_apply()" popped up an alert box. */ + recent.gui_zoom_level = save_gui_zoom_level; /* undo zoom */ + break; + + case FA_FONT_NOT_AVAILABLE: + /* We assume this means that the specified size isn't available. */ + simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, + "Your current font isn't available in the next smaller size.\n"); + recent.gui_zoom_level = save_gui_zoom_level; /* undo zoom */ + break; + } +} + +void +view_zoom_100_cb(GtkWidget *w _U_, gpointer d _U_) +{ + gint save_gui_zoom_level; + + save_gui_zoom_level = recent.gui_zoom_level; + recent.gui_zoom_level = 0; + switch (user_font_apply()) { + + case FA_SUCCESS: + break; + + case FA_FONT_NOT_RESIZEABLE: + /* "font_apply()" popped up an alert box. */ + recent.gui_zoom_level = save_gui_zoom_level; /* undo zoom */ + break; + + case FA_FONT_NOT_AVAILABLE: + /* We assume this means that the specified size isn't available. + XXX - this "shouldn't happen". */ + simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, + "Your current font couldn't be reloaded at the size you selected.\n"); + recent.gui_zoom_level = save_gui_zoom_level; /* undo zoom */ + break; + } +} + + +#if GTK_MAJOR_VERSION < 2 +/* 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" }, + { "normal", "bold" }, + { "semibold", "extrabold" }, + { "bold", "ultrabold" } +}; +#define N_WEIGHTS (sizeof weight_map / sizeof weight_map[0]) + +/* Try to convert a font name to it's bold version. + * + * @param the font to convert + * @return the bold font + */ +static char * +user_font_boldify(const char *font_name) +{ + char *bold_font_name; + gchar **xlfd_tokens; + unsigned 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); + + /* + * Make sure we *have* a weight (this might not be a valid + * XLFD font name). + */ + for (i = 0; i < XLFD_WEIGHT+1; i++) { + if (xlfd_tokens[i] == NULL) { + /* + * We don't, so treat this as a non-XLFD + * font name. + */ + goto not_xlfd; + } + } + 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); + return bold_font_name; + } + +not_xlfd: + /* + * This isn't an XLFD font name; just append "bold" to the name + * of the font. + */ + bold_font_name = g_strconcat(font_name, "bold", NULL); + return bold_font_name; +} +#endif + + +gboolean +user_font_test(gchar *font_name) +{ +#if GTK_MAJOR_VERSION < 2 + gchar *bold_font_name; +#endif + FONT_TYPE *new_r_font, *new_b_font; + +#if GTK_MAJOR_VERSION < 2 + /* Get the name that the boldface version of that font would have. */ + bold_font_name = user_font_boldify(font_name); + + /* Now load those fonts, just to make sure we can. */ + new_r_font = gdk_font_load(font_name); +#else + new_r_font = pango_font_description_from_string(font_name); +#endif + if (new_r_font == NULL) { + /* Oops, that font didn't work. + Tell the user, but don't tear down the font selection + dialog, so that they can try again. */ + simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, + "The font you selected cannot be loaded."); + +#if GTK_MAJOR_VERSION < 2 + g_free(bold_font_name); +#endif + return FALSE; + } + +#if GTK_MAJOR_VERSION < 2 + new_b_font = gdk_font_load(bold_font_name); +#else + new_b_font = pango_font_description_copy(new_r_font); + pango_font_description_set_weight(new_b_font, PANGO_WEIGHT_BOLD); +#endif + if (new_b_font == NULL) { + /* Oops, that font didn't work. + Tell the user, but don't tear down the font selection + dialog, so that they can try again. */ + simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, + "The font you selected doesn't have a boldface version."); + +#if GTK_MAJOR_VERSION < 2 + g_free(bold_font_name); + gdk_font_unref(new_r_font); +#else + pango_font_description_free(new_r_font); +#endif + return FALSE; + } + + return TRUE; +} + + + +/* Given a font name, construct the name of a version of that font with + the current zoom factor applied. */ +static char * +font_zoom(char *gui_font_name) +{ + char *new_font_name; + char *font_name_dup; + char *font_name_p; + long font_point_size_l; +#if GTK_MAJOR_VERSION < 2 + int minus_chars; + char *font_foundry; + char *font_family; + char *font_weight; + char *font_slant; + char *font_set_width; + char *font_add_style; + char *font_pixel_size; + char *font_point_size; + char *font_res_x; + char *font_res_y; + char *font_spacing; + char *font_aver_width; + char *font_charset_reg; + char *font_charset_encoding; +#endif + + if (recent.gui_zoom_level == 0) { + /* There is no zoom factor - just return the name, so that if + this is GTK+ 1.2[.x] and the font name isn't an XLFD font + name, we don't fail. */ + return g_strdup(gui_font_name); + } + + font_name_dup = g_strdup(gui_font_name); + font_name_p = font_name_dup; + +#if GTK_MAJOR_VERSION >= 2 + /* find the start of the font_size string */ + font_name_p = strrchr(font_name_dup, ' '); + *font_name_p = '\0'; + font_name_p++; + + /* calculate the new font size */ + font_point_size_l = strtol(font_name_p, NULL, 10); + font_point_size_l += recent.gui_zoom_level; + + /* build a new font name */ + new_font_name = g_strdup_printf("%s %ld", font_name_dup, font_point_size_l); +#else + minus_chars = 0; + /* replace all '-' chars by NUL and count them */ + while ((font_name_p = strchr(font_name_p, '-')) != NULL) { + *font_name_p = '\0'; + font_name_p++; + minus_chars++; + } + + if (minus_chars != 14) { + /* + * Not a valid XLFD font name. + * XXX - can we try scaling it by looking for a size at the end + * and tweaking that? Unfortunately, some fonts have numbers + * at the end that aren't, as far as I know, sizes, e.g. "nil2". + */ + return NULL; + } + + /* first element (font name registry) empty */ + font_name_p = font_name_dup; + font_name_p += strlen(font_name_p); + font_name_p++; + + /* get pointers to all font name elements */ + font_foundry = font_name_p; + font_name_p += strlen(font_name_p); + font_name_p++; + + font_family = font_name_p; + font_name_p += strlen(font_name_p); + font_name_p++; + + font_weight = font_name_p; + font_name_p += strlen(font_name_p); + font_name_p++; + + font_slant = font_name_p; + font_name_p += strlen(font_name_p); + font_name_p++; + + font_set_width = font_name_p; + font_name_p += strlen(font_name_p); + font_name_p++; + + font_add_style = font_name_p; + font_name_p += strlen(font_name_p); + font_name_p++; + + font_pixel_size = font_name_p; + font_name_p += strlen(font_name_p); + font_name_p++; + + font_point_size = font_name_p; + font_name_p += strlen(font_name_p); + font_name_p++; + + font_res_x = font_name_p; + font_name_p += strlen(font_name_p); + font_name_p++; + + font_res_y = font_name_p; + font_name_p += strlen(font_name_p); + font_name_p++; + + font_spacing = font_name_p; + font_name_p += strlen(font_name_p); + font_name_p++; + + font_aver_width = font_name_p; + font_name_p += strlen(font_name_p); + font_name_p++; + + font_charset_reg = font_name_p; + font_name_p += strlen(font_name_p); + font_name_p++; + + font_charset_encoding = font_name_p; + font_name_p += strlen(font_name_p); + font_name_p++; + + /* calculate the new font size */ + font_point_size_l = strtol(font_point_size, NULL, 10); + font_point_size_l += recent.gui_zoom_level*10; + if (font_point_size_l <= 0) + font_point_size_l = 10; + + /* build a new font name */ + new_font_name = g_strdup_printf("-%s-%s-%s-%s-%s-%s-%s-%ld-%s-%s-%s-%s-%s-%s", + font_foundry, font_family, font_weight, font_slant, font_set_width, + font_add_style, font_pixel_size, font_point_size_l, font_res_x, + font_res_y, font_spacing, font_aver_width, font_charset_reg, + font_charset_encoding); +#endif + + g_free(font_name_dup); + + return new_font_name; +} + +fa_ret_t +user_font_apply(void) { + char *gui_font_name; +#if GTK_MAJOR_VERSION < 2 + char *bold_font_name; +#endif + FONT_TYPE *new_r_font, *new_b_font; + FONT_TYPE *old_r_font = NULL, *old_b_font = NULL; + + /* convert font name to reflect the zoom level */ + gui_font_name = font_zoom(prefs.PREFS_GUI_FONT_NAME); + if (gui_font_name == NULL) { + /* + * This means the font name isn't an XLFD font name. + * We just report that for now as a font not available in + * multiple sizes. + */ + simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, + "Your current font isn't available in any other sizes.\n"); + return FA_FONT_NOT_RESIZEABLE; + } + + /* load normal and bold font */ +#if GTK_MAJOR_VERSION < 2 + new_r_font = gdk_font_load(gui_font_name); + bold_font_name = user_font_boldify(gui_font_name); + new_b_font = gdk_font_load(bold_font_name); +#else + new_r_font = pango_font_description_from_string(gui_font_name); + new_b_font = pango_font_description_copy(new_r_font); + pango_font_description_set_weight(new_b_font, PANGO_WEIGHT_BOLD); +#endif + + if (new_r_font == NULL || new_b_font == NULL) { + /* We're no longer using the new fonts; unreference them. */ +#if GTK_MAJOR_VERSION < 2 + if (new_r_font != NULL) + gdk_font_unref(new_r_font); + if (new_b_font != NULL) + gdk_font_unref(new_b_font); +#else + if (new_r_font != NULL) + pango_font_description_free(new_r_font); + if (new_b_font != NULL) + pango_font_description_free(new_b_font); +#endif + g_free(gui_font_name); + + /* We let our caller pop up a dialog box, as the error message + depends on the context (did they zoom in or out, or did they + do something else? */ + return FA_FONT_NOT_AVAILABLE; + } + + /* the font(s) seem to be ok */ + set_plist_font(new_r_font); + set_ptree_font_all(new_r_font); + old_r_font = m_r_font; + old_b_font = m_b_font; + set_fonts(new_r_font, new_b_font); +#if GTK_MAJOR_VERSION < 2 + g_free(bold_font_name); +#endif + + /* Redraw the hex dump windows. */ + redraw_hex_dump_all(); + + /* Redraw the "Follow TCP Stream" windows. */ + follow_redraw_all(); + + /* We're no longer using the old fonts; unreference them. */ +#if GTK_MAJOR_VERSION < 2 + if (old_r_font != NULL) + gdk_font_unref(old_r_font); + if (old_b_font != NULL) + gdk_font_unref(old_b_font); +#else + if (old_r_font != NULL) + pango_font_description_free(old_r_font); + if (old_b_font != NULL) + pango_font_description_free(old_b_font); +#endif + g_free(gui_font_name); + + return FA_SUCCESS; +} + + +#ifdef WIN32 + +#define NAME_BUFFER_LEN 32 + +#if GTK_MAJOR_VERSION < 2 + + +/* The setting of the MS default font for system stuff (menus, dialogs, ...), + * coming from: Allin Cottrell, http://www.ecn.wfu.edu/~cottrell/gtk_win32, + * Thank you very much for this! */ +static int get_windows_font_gtk1(char *fontspec, int fontspec_len) +{ + HDC h_dc; + HGDIOBJ h_font; + TEXTMETRIC tm; + char name[NAME_BUFFER_LEN]; + int len, pix_height; + + h_dc = CreateDC("DISPLAY", NULL, NULL, NULL); + if (h_dc == NULL) return 1; + h_font = GetStockObject(DEFAULT_GUI_FONT); + if (h_font == NULL || !SelectObject(h_dc, h_font)) { + DeleteDC(h_dc); + return 1; + } + len = GetTextFace(h_dc, NAME_BUFFER_LEN, name); + if (len <= 0) { + DeleteDC(h_dc); + return 1; + } + if (!GetTextMetrics(h_dc, &tm)) { + DeleteDC(h_dc); + return 1; + } + pix_height = tm.tmHeight; + DeleteDC(h_dc); + g_snprintf(fontspec, fontspec_len, "-*-%s-*-*-*-*-%i-*-*-*-p-*-iso8859-1", name, + pix_height); + return 0; +} + +void app_font_gtk1_init(GtkWidget *top_level_w) +{ + GtkStyle *style; + char winfont[80]; + + style = gtk_widget_get_style(top_level_w); + if (get_windows_font_gtk1(winfont, sizeof(winfont)) == 0) + style->font = gdk_font_load(winfont); + if (style->font) gtk_widget_set_style(top_level_w, style); +} + + +#else /* GTK_MAJOR_VERSION */ +static char appfontname[128] = "tahoma 8"; + +static void +set_app_font_gtk2(const char *fontname) +{ + GtkSettings *settings; + + if (fontname != NULL && *fontname == 0) return; + + settings = gtk_settings_get_default(); + + if (fontname == NULL) { + g_object_set(G_OBJECT(settings), "gtk-font-name", appfontname, NULL); + } else { + GtkWidget *w; + PangoFontDescription *pfd; + PangoContext *pc; + PangoFont *pfont; + + w = gtk_label_new(NULL); + pfd = pango_font_description_from_string(fontname); + pc = gtk_widget_get_pango_context(w); + pfont = pango_context_load_font(pc, pfd); + + if (pfont != NULL) { + strcpy(appfontname, fontname); + g_object_set(G_OBJECT(settings), "gtk-font-name", appfontname, NULL); + } + + gtk_widget_destroy(w); + pango_font_description_free(pfd); + } +} + +static char *default_windows_menu_fontspec_gtk2(void) +{ + gchar *fontspec = NULL; + NONCLIENTMETRICS ncm; + + memset(&ncm, 0, sizeof ncm); + ncm.cbSize = sizeof ncm; + + if (SystemParametersInfo(SPI_GETNONCLIENTMETRICS, ncm.cbSize, &ncm, 0)) { + HDC screen = GetDC(0); + double y_scale = 72.0 / GetDeviceCaps(screen, LOGPIXELSY); + int point_size = (int) (ncm.lfMenuFont.lfHeight * y_scale); + + if (point_size < 0) point_size = -point_size; + fontspec = g_strdup_printf("%s %d", ncm.lfMenuFont.lfFaceName, + point_size); + ReleaseDC(0, screen); + } + + return fontspec; +} + +static void try_to_get_windows_font_gtk2(void) +{ + gchar *fontspec; + + fontspec = default_windows_menu_fontspec_gtk2(); + + if (fontspec != NULL) { + int match = 0; + PangoFontDescription *pfd; + PangoFont *pfont; + PangoContext *pc; + GtkWidget *w; + + pfd = pango_font_description_from_string(fontspec); + + w = gtk_label_new(NULL); + pc = gtk_widget_get_pango_context(w); + pfont = pango_context_load_font(pc, pfd); + match = (pfont != NULL); + + pango_font_description_free(pfd); + g_object_unref(G_OBJECT(pc)); + gtk_widget_destroy(w); + + if (match) set_app_font_gtk2(fontspec); + g_free(fontspec); + } +} +#endif /* GTK_MAJOR_VERSION */ + +#endif /* WIN32 */ + + +void font_init(void) +{ +#if GTK_MAJOR_VERSION < 2 + gchar *bold_font_name; +#endif + +#ifdef WIN32 +#if GTK_MAJOR_VERSION >= 2 + /* try to load the application font for GTK2 */ + try_to_get_windows_font_gtk2(); +#endif +#endif + + /* Try to load the regular and boldface fixed-width fonts */ +#if GTK_MAJOR_VERSION < 2 + bold_font_name = user_font_boldify(prefs.gui_font_name1); + m_r_font = gdk_font_load(prefs.gui_font_name1); + 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? no */ + if (m_r_font == NULL) { +#ifdef HAVE_LIBPCAP + if (!capture_child) +#endif + fprintf(stderr, "ethereal: Warning: font %s not found - defaulting to 6x13 and 6x13bold\n", + prefs.gui_font_name1); + } else { + gdk_font_unref(m_r_font); + } + if (m_b_font == NULL) { +#ifdef HAVE_LIBPCAP + if (!capture_child) +#endif + 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 6x13bold not found\n"); + exit(1); + } + g_free(prefs.gui_font_name1); + prefs.gui_font_name1 = g_strdup("6x13"); + } +#else /* GTK_MAJOR_VERSION */ + m_r_font = pango_font_description_from_string(prefs.gui_font_name2); + m_b_font = pango_font_description_copy(m_r_font); + pango_font_description_set_weight(m_b_font, PANGO_WEIGHT_BOLD); + if (m_r_font == NULL || m_b_font == NULL) { + /* XXX - pop this up as a dialog box? no */ + if (m_r_font == NULL) { +#ifdef HAVE_LIBPCAP + if (!capture_child) +#endif + fprintf(stderr, "ethereal: Warning: font %s not found - defaulting to Monospace 9\n", + prefs.gui_font_name2); + } else { + pango_font_description_free(m_r_font); + } + if (m_b_font == NULL) { +#ifdef HAVE_LIBPCAP + if (!capture_child) +#endif + fprintf(stderr, "ethereal: Warning: bold font %s not found - defaulting" + " to Monospace 9\n", prefs.gui_font_name2); + } else { + pango_font_description_free(m_b_font); + } + if ((m_r_font = pango_font_description_from_string("Monospace 9")) == NULL) + { + fprintf(stderr, "ethereal: Error: font Monospace 9 not found\n"); + exit(1); + } + if ((m_b_font = pango_font_description_copy(m_r_font)) == NULL) { + fprintf(stderr, "ethereal: Error: font Monospace 9 bold not found\n"); + exit(1); + } + g_free(prefs.gui_font_name2); + pango_font_description_set_weight(m_b_font, PANGO_WEIGHT_BOLD); + prefs.gui_font_name2 = g_strdup("Monospace 9"); + } +#endif /* GTK_MAJOR_VERSION */ + + /* Call this for the side-effects that set_fonts() produces */ + set_fonts(m_r_font, m_b_font); +} diff --git a/gtk/font_utils.h b/gtk/font_utils.h new file mode 100644 index 0000000000..e8a3b5faa7 --- /dev/null +++ b/gtk/font_utils.h @@ -0,0 +1,100 @@ +/* font_utils.h + * Declarations of utilities to use for font manipulation + * + * $Id: font_utils.h,v 1.1 2004/06/17 16:35:24 ulfl Exp $ + * + * Ethereal - Network traffic analyzer + * By Gerald Combs <gerald@ethereal.com> + * Copyright 1998 Gerald Combs + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + + +/** @file + * Utilities for font manipulation. + * + * There are two different fonts used: + * - the application font for menu's, dialog's and such + * - the user font for the packet panes + * + * The user font is also available in regular (m_r_font) and bold (m_b_font) versions, + * see gtkglobals.h. + */ + +#ifndef __FONT_UTILS_H__ +#define __FONT_UTILS_H__ + +/** Init the application and user fonts at program start. */ +extern void font_init(void); + +/** Return value from font_apply() */ +typedef enum { + FA_SUCCESS, /**< function succeeded */ + FA_FONT_NOT_RESIZEABLE, /**< the choosen font isn't resizable */ + FA_FONT_NOT_AVAILABLE /**< the choosen font isn't available */ +} fa_ret_t; + +/** Applies a new user font, corresponding to the preferences font name and recent zoom level. + * Will also redraw the screen. + * + * @return if the new font could be set or not + */ +extern fa_ret_t user_font_apply(void); + +#ifdef WIN32 +#if GTK_MAJOR_VERSION < 2 +/** Init the application font (GTK1 only). + * + * @param top_level_w the top level window + */ +extern void app_font_gtk1_init(GtkWidget *top_level_w); +#endif +#endif + +/** Test, if the given font name is available. + * + * @param font_name the font to test + * @return TRUE, if this font is available + */ +extern gboolean user_font_test(gchar *font_name); + +/** Get the regular user font. + * + * @return the regular user font + */ +extern FONT_TYPE *user_font_get_regular(void); + +/** Get the bold user font. + * + * @return the bold user font + */ +extern FONT_TYPE *user_font_get_bold(void); + +#if GTK_MAJOR_VERSION < 2 +/** Get the regular user font height. + * + * @return the regular user font height + */ +extern guint user_font_get_regular_height(void); + +/** Get the regular user font width. + * + * @return the regular user font width + */ +extern guint user_font_get_regular_width(void); +#endif + +#endif diff --git a/gtk/gtkglobals.h b/gtk/gtkglobals.h index d2e428afe0..31fd095a11 100644 --- a/gtk/gtkglobals.h +++ b/gtk/gtkglobals.h @@ -1,7 +1,7 @@ /* gtkglobals.h * GTK-related Global defines, etc. * - * $Id: gtkglobals.h,v 1.29 2004/06/05 12:12:13 ulfl Exp $ + * $Id: gtkglobals.h,v 1.30 2004/06/17 16:35:24 ulfl Exp $ * * Ethereal - Network traffic analyzer * By Gerald Combs <gerald@ethereal.com> @@ -54,24 +54,6 @@ extern GtkWidget *byte_nb_ptr; /** The filter text entry in the filter toolbar. */ extern GtkWidget *main_display_filter_widget; -#if GTK_MAJOR_VERSION < 2 -/** Normal font. */ -extern GdkFont *m_r_font; -/** Bold font. */ -extern GdkFont *m_b_font; -/** Font height. */ -extern guint m_font_height; -/** Font width. */ -extern guint m_font_width; -/** Widget style (font, color, ...). */ -extern GtkStyle *item_style; -#else -/** Normal font. */ -extern PangoFontDescription *m_r_font; -/** Bold font. */ -extern PangoFontDescription *m_b_font; -#endif - #if GTK_MAJOR_VERSION >= 2 || GTK_MINOR_VERSION >= 3 /** * XXX - "isprint()" can return "true" for non-ASCII characters, but diff --git a/gtk/gui_prefs.c b/gtk/gui_prefs.c index 59050de105..dce7e0b19b 100644 --- a/gtk/gui_prefs.c +++ b/gtk/gui_prefs.c @@ -1,7 +1,7 @@ /* gui_prefs.c * Dialog box for GUI preferences * - * $Id: gui_prefs.c,v 1.71 2004/05/27 16:50:15 ulfl Exp $ + * $Id: gui_prefs.c,v 1.72 2004/06/17 16:35:24 ulfl Exp $ * * Ethereal - Network traffic analyzer * By Gerald Combs <gerald@ethereal.com> @@ -46,6 +46,7 @@ #include "compat_macros.h" #include "toolbar.h" #include "recent.h" +#include "font_utils.h" static gint fetch_enum_value(gpointer control, const enum_val_t *enumvals); static gint fileopen_dir_changed_cb(GtkWidget *myentry _U_, GdkEvent *event, gpointer parent_w); @@ -333,12 +334,6 @@ static gboolean font_fetch(void) { gchar *font_name; -#if GTK_MAJOR_VERSION < 2 - gchar *bold_font_name; - GdkFont *new_r_font, *new_b_font; -#else - PangoFontDescription *new_r_font, *new_b_font; -#endif font_name = g_strdup(gtk_font_selection_get_font_name( GTK_FONT_SELECTION(font_browse_w))); @@ -351,53 +346,12 @@ font_fetch(void) return FALSE; } -#if GTK_MAJOR_VERSION < 2 - /* Get the name that the boldface version of that font would have. */ - bold_font_name = font_boldify(font_name); - - /* Now load those fonts, just to make sure we can. */ - new_r_font = gdk_font_load(font_name); -#else - new_r_font = pango_font_description_from_string(font_name); -#endif - if (new_r_font == NULL) { - /* Oops, that font didn't work. - Tell the user, but don't tear down the font selection - dialog, so that they can try again. */ - simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, - "The font you selected cannot be loaded."); - - g_free(font_name); -#if GTK_MAJOR_VERSION < 2 - g_free(bold_font_name); -#endif - return FALSE; - } - -#if GTK_MAJOR_VERSION < 2 - new_b_font = gdk_font_load(bold_font_name); -#else - new_b_font = pango_font_description_copy(new_r_font); - pango_font_description_set_weight(new_b_font, PANGO_WEIGHT_BOLD); -#endif - if (new_b_font == NULL) { - /* Oops, that font didn't work. - Tell the user, but don't tear down the font selection - dialog, so that they can try again. */ - simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, - "The font you selected doesn't have a boldface version."); - - g_free(font_name); -#if GTK_MAJOR_VERSION < 2 - g_free(bold_font_name); - gdk_font_unref(new_r_font); -#else - pango_font_description_free(new_r_font); -#endif - return FALSE; - } + if(user_font_test(font_name)) { + new_font_name = font_name; + return TRUE; + } - new_font_name = font_name; + g_free(font_name); return TRUE; } @@ -485,13 +439,13 @@ gui_prefs_apply(GtkWidget *w _U_) if (font_changed) { /* This redraws the hex dump windows. */ - switch (font_apply()) { + switch (user_font_apply()) { case FA_SUCCESS: break; case FA_FONT_NOT_RESIZEABLE: - /* "font_apply()" popped up an alert box. */ + /* "user_font_apply()" popped up an alert box. */ /* turn off zooming - font can't be resized */ recent.gui_zoom_level = 0; break; diff --git a/gtk/main.c b/gtk/main.c index 2e6dcfb3e5..6cf3a548ed 100644 --- a/gtk/main.c +++ b/gtk/main.c @@ -1,6 +1,6 @@ /* main.c * - * $Id: main.c,v 1.441 2004/06/12 07:47:14 guy Exp $ + * $Id: main.c,v 1.442 2004/06/17 16:35:25 ulfl Exp $ * * Ethereal - Network traffic analyzer * By Gerald Combs <gerald@ethereal.com> @@ -130,6 +130,7 @@ #include "packet_list.h" #include "recent.h" #include "follow_dlg.h" +#include "font_utils.h" /* @@ -153,22 +154,12 @@ static GtkWidget *status_pane; static GtkWidget *menubar, *main_vbox, *main_tb, *pkt_scrollw, *stat_hbox, *filter_tb; static GtkWidget *info_bar; static GtkWidget *packets_bar = NULL; -#if GTK_MAJOR_VERSION < 2 -GdkFont *m_r_font, *m_b_font; -guint m_font_height, m_font_width; -#else -PangoFontDescription *m_r_font, *m_b_font; -#endif static guint main_ctx, file_ctx, help_ctx; static guint packets_ctx; static gchar *packets_str = NULL; GString *comp_info_str, *runtime_info_str; gchar *ethereal_path = NULL; -#if GTK_MAJOR_VERSION < 2 -GtkStyle *item_style; -#endif - #ifdef WIN32 static gboolean has_console; /* TRUE if app has console */ /*static void create_console(void);*/ @@ -184,120 +175,10 @@ static gboolean list_link_layer_types; static void create_main_window(gint, gint, gint, e_prefs*); static void file_quit_answered_cb(gpointer dialog _U_, gint btn, gpointer data _U_); static void main_save_window_geometry(GtkWidget *widget); -#ifdef WIN32 -#if GTK_MAJOR_VERSION >= 2 -static void try_to_get_windows_font_gtk2 (void); -#endif -#endif #define E_DFILTER_CM_KEY "display_filter_combo" #define E_DFILTER_FL_KEY "display_filter_list" -#if GTK_MAJOR_VERSION < 2 -void set_fonts(GdkFont *regular, GdkFont *bold); -#else -void set_fonts(PangoFontDescription *regular, PangoFontDescription *bold); -#endif - - -#if GTK_MAJOR_VERSION < 2 -void -set_fonts(GdkFont *regular, GdkFont *bold) -#else -void -set_fonts(PangoFontDescription *regular, PangoFontDescription *bold) -#endif -{ - /* Yes, assert. The code that loads the font should check - * for NULL and provide its own error message. */ - g_assert(m_r_font && m_b_font); - m_r_font = regular; - m_b_font = bold; - -#if GTK_MAJOR_VERSION < 2 - m_font_height = m_r_font->ascent + m_r_font->descent; - m_font_width = gdk_string_width(m_r_font, "0"); -#endif -} - -void -view_zoom_in_cb(GtkWidget *w _U_, gpointer d _U_) -{ - gint save_gui_zoom_level; - - save_gui_zoom_level = recent.gui_zoom_level; - recent.gui_zoom_level++; - switch (font_apply()) { - - case FA_SUCCESS: - break; - - case FA_FONT_NOT_RESIZEABLE: - /* "font_apply()" popped up an alert box. */ - recent.gui_zoom_level = save_gui_zoom_level; /* undo zoom */ - break; - - case FA_FONT_NOT_AVAILABLE: - /* We assume this means that the specified size isn't available. */ - simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, - "Your current font isn't available in the next larger size.\n"); - recent.gui_zoom_level = save_gui_zoom_level; /* undo zoom */ - break; - } -} - -void -view_zoom_out_cb(GtkWidget *w _U_, gpointer d _U_) -{ - gint save_gui_zoom_level; - - save_gui_zoom_level = recent.gui_zoom_level; - recent.gui_zoom_level--; - switch (font_apply()) { - - case FA_SUCCESS: - break; - - case FA_FONT_NOT_RESIZEABLE: - /* "font_apply()" popped up an alert box. */ - recent.gui_zoom_level = save_gui_zoom_level; /* undo zoom */ - break; - - case FA_FONT_NOT_AVAILABLE: - /* We assume this means that the specified size isn't available. */ - simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, - "Your current font isn't available in the next smaller size.\n"); - recent.gui_zoom_level = save_gui_zoom_level; /* undo zoom */ - break; - } -} - -void -view_zoom_100_cb(GtkWidget *w _U_, gpointer d _U_) -{ - gint save_gui_zoom_level; - - save_gui_zoom_level = recent.gui_zoom_level; - recent.gui_zoom_level = 0; - switch (font_apply()) { - - case FA_SUCCESS: - break; - - case FA_FONT_NOT_RESIZEABLE: - /* "font_apply()" popped up an alert box. */ - recent.gui_zoom_level = save_gui_zoom_level; /* undo zoom */ - break; - - case FA_FONT_NOT_AVAILABLE: - /* We assume this means that the specified size isn't available. - XXX - this "shouldn't happen". */ - simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, - "Your current font couldn't be reloaded at the size you selected.\n"); - recent.gui_zoom_level = save_gui_zoom_level; /* undo zoom */ - break; - } -} /* Match selected byte pattern */ @@ -1563,9 +1444,6 @@ main(int argc, char *argv[]) gboolean rfilter_parse_failed = FALSE; e_prefs *prefs; char badopt; -#if GTK_MAJOR_VERSION < 2 - char *bold_font_name; -#endif ethereal_tap_list *tli = NULL; gchar *tap_opt = NULL; @@ -2342,95 +2220,13 @@ main(int argc, char *argv[]) #endif #endif -#ifdef WIN32 -#if GTK_MAJOR_VERSION >= 2 - try_to_get_windows_font_gtk2(); -#endif -#endif - /* read in rc file from global and personal configuration paths. */ + /* XXX - is this a good idea? */ gtk_rc_parse(RC_FILE); rc_file = get_persconffile_path(RC_FILE, FALSE); gtk_rc_parse(rc_file); - /* Try to load the regular and boldface fixed-width fonts */ -#if GTK_MAJOR_VERSION < 2 - bold_font_name = font_boldify(prefs->gui_font_name1); - m_r_font = gdk_font_load(prefs->gui_font_name1); - 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? no */ - if (m_r_font == NULL) { -#ifdef HAVE_LIBPCAP - if (!capture_child) -#endif - fprintf(stderr, "ethereal: Warning: font %s not found - defaulting to 6x13 and 6x13bold\n", - prefs->gui_font_name1); - } else { - gdk_font_unref(m_r_font); - } - if (m_b_font == NULL) { -#ifdef HAVE_LIBPCAP - if (!capture_child) -#endif - 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 6x13bold not found\n"); - exit(1); - } - g_free(prefs->gui_font_name1); - prefs->gui_font_name1 = g_strdup("6x13"); - } -#else /* GTK_MAJOR_VERSION */ - m_r_font = pango_font_description_from_string(prefs->gui_font_name2); - m_b_font = pango_font_description_copy(m_r_font); - pango_font_description_set_weight(m_b_font, PANGO_WEIGHT_BOLD); - if (m_r_font == NULL || m_b_font == NULL) { - /* XXX - pop this up as a dialog box? no */ - if (m_r_font == NULL) { -#ifdef HAVE_LIBPCAP - if (!capture_child) -#endif - fprintf(stderr, "ethereal: Warning: font %s not found - defaulting to Monospace 9\n", - prefs->gui_font_name2); - } else { - pango_font_description_free(m_r_font); - } - if (m_b_font == NULL) { -#ifdef HAVE_LIBPCAP - if (!capture_child) -#endif - fprintf(stderr, "ethereal: Warning: bold font %s not found - defaulting" - " to Monospace 9\n", prefs->gui_font_name2); - } else { - pango_font_description_free(m_b_font); - } - if ((m_r_font = pango_font_description_from_string("Monospace 9")) == NULL) - { - fprintf(stderr, "ethereal: Error: font Monospace 9 not found\n"); - exit(1); - } - if ((m_b_font = pango_font_description_copy(m_r_font)) == NULL) { - fprintf(stderr, "ethereal: Error: font Monospace 9 bold not found\n"); - exit(1); - } - g_free(prefs->gui_font_name2); - pango_font_description_set_weight(m_b_font, PANGO_WEIGHT_BOLD); - prefs->gui_font_name2 = g_strdup("Monospace 9"); - } -#endif /* GTK_MAJOR_VERSION */ - - /* Call this for the side-effects that set_fonts() produces */ - set_fonts(m_r_font, m_b_font); + font_init(); #ifdef HAVE_LIBPCAP /* Is this a "child" ethereal, which is only supposed to pop up a @@ -2445,7 +2241,7 @@ main(int argc, char *argv[]) /* Read the recent file, as we have the gui now ready for it. */ read_recent(&rf_path, &rf_open_errno); - /* rearrange all the widgets */ + /* rearrange all the widgets as we now have the recent settings for this */ main_widgets_rearrange(); /* Fill in column titles. This must be done after the top level window @@ -2456,11 +2252,11 @@ main(int argc, char *argv[]) menu_recent_read_finished(); - switch (font_apply()) { + switch (user_font_apply()) { case FA_SUCCESS: break; case FA_FONT_NOT_RESIZEABLE: - /* "font_apply()" popped up an alert box. */ + /* "user_font_apply()" popped up an alert box. */ /* turn off zooming - font can't be resized */ case FA_FONT_NOT_AVAILABLE: /* XXX - did we successfully load the un-zoomed version earlier? @@ -2711,457 +2507,6 @@ console_log_handler(const char *log_domain, GLogLevelFlags log_level, } #endif -#if GTK_MAJOR_VERSION < 2 -/* 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" }, - { "normal", "bold" }, - { "semibold", "extrabold" }, - { "bold", "ultrabold" } -}; -#define N_WEIGHTS (sizeof weight_map / sizeof weight_map[0]) - -char * -font_boldify(const char *font_name) -{ - char *bold_font_name; - gchar **xlfd_tokens; - unsigned 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); - - /* - * Make sure we *have* a weight (this might not be a valid - * XLFD font name). - */ - for (i = 0; i < XLFD_WEIGHT+1; i++) { - if (xlfd_tokens[i] == NULL) { - /* - * We don't, so treat this as a non-XLFD - * font name. - */ - goto not_xlfd; - } - } - 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); - return bold_font_name; - } - -not_xlfd: - /* - * This isn't an XLFD font name; just append "bold" to the name - * of the font. - */ - bold_font_name = g_strconcat(font_name, "bold", NULL); - return bold_font_name; -} -#endif - -/* Given a font name, construct the name of a version of that font with - the current zoom factor applied. */ -static char * -font_zoom(char *gui_font_name) -{ - char *new_font_name; - char *font_name_dup; - char *font_name_p; - long font_point_size_l; -#if GTK_MAJOR_VERSION < 2 - int minus_chars; - char *font_foundry; - char *font_family; - char *font_weight; - char *font_slant; - char *font_set_width; - char *font_add_style; - char *font_pixel_size; - char *font_point_size; - char *font_res_x; - char *font_res_y; - char *font_spacing; - char *font_aver_width; - char *font_charset_reg; - char *font_charset_encoding; -#endif - - if (recent.gui_zoom_level == 0) { - /* There is no zoom factor - just return the name, so that if - this is GTK+ 1.2[.x] and the font name isn't an XLFD font - name, we don't fail. */ - return g_strdup(gui_font_name); - } - - font_name_dup = g_strdup(gui_font_name); - font_name_p = font_name_dup; - -#if GTK_MAJOR_VERSION >= 2 - /* find the start of the font_size string */ - font_name_p = strrchr(font_name_dup, ' '); - *font_name_p = '\0'; - font_name_p++; - - /* calculate the new font size */ - font_point_size_l = strtol(font_name_p, NULL, 10); - font_point_size_l += recent.gui_zoom_level; - - /* build a new font name */ - new_font_name = g_strdup_printf("%s %ld", font_name_dup, font_point_size_l); -#else - minus_chars = 0; - /* replace all '-' chars by NUL and count them */ - while ((font_name_p = strchr(font_name_p, '-')) != NULL) { - *font_name_p = '\0'; - font_name_p++; - minus_chars++; - } - - if (minus_chars != 14) { - /* - * Not a valid XLFD font name. - * XXX - can we try scaling it by looking for a size at the end - * and tweaking that? Unfortunately, some fonts have numbers - * at the end that aren't, as far as I know, sizes, e.g. "nil2". - */ - return NULL; - } - - /* first element (font name registry) empty */ - font_name_p = font_name_dup; - font_name_p += strlen(font_name_p); - font_name_p++; - - /* get pointers to all font name elements */ - font_foundry = font_name_p; - font_name_p += strlen(font_name_p); - font_name_p++; - - font_family = font_name_p; - font_name_p += strlen(font_name_p); - font_name_p++; - - font_weight = font_name_p; - font_name_p += strlen(font_name_p); - font_name_p++; - - font_slant = font_name_p; - font_name_p += strlen(font_name_p); - font_name_p++; - - font_set_width = font_name_p; - font_name_p += strlen(font_name_p); - font_name_p++; - - font_add_style = font_name_p; - font_name_p += strlen(font_name_p); - font_name_p++; - - font_pixel_size = font_name_p; - font_name_p += strlen(font_name_p); - font_name_p++; - - font_point_size = font_name_p; - font_name_p += strlen(font_name_p); - font_name_p++; - - font_res_x = font_name_p; - font_name_p += strlen(font_name_p); - font_name_p++; - - font_res_y = font_name_p; - font_name_p += strlen(font_name_p); - font_name_p++; - - font_spacing = font_name_p; - font_name_p += strlen(font_name_p); - font_name_p++; - - font_aver_width = font_name_p; - font_name_p += strlen(font_name_p); - font_name_p++; - - font_charset_reg = font_name_p; - font_name_p += strlen(font_name_p); - font_name_p++; - - font_charset_encoding = font_name_p; - font_name_p += strlen(font_name_p); - font_name_p++; - - /* calculate the new font size */ - font_point_size_l = strtol(font_point_size, NULL, 10); - font_point_size_l += recent.gui_zoom_level*10; - if (font_point_size_l <= 0) - font_point_size_l = 10; - - /* build a new font name */ - new_font_name = g_strdup_printf("-%s-%s-%s-%s-%s-%s-%s-%ld-%s-%s-%s-%s-%s-%s", - font_foundry, font_family, font_weight, font_slant, font_set_width, - font_add_style, font_pixel_size, font_point_size_l, font_res_x, - font_res_y, font_spacing, font_aver_width, font_charset_reg, - font_charset_encoding); -#endif - - g_free(font_name_dup); - - return new_font_name; -} - -fa_ret_t -font_apply(void) { - char *gui_font_name; -#if GTK_MAJOR_VERSION < 2 - GdkFont *new_r_font, *new_b_font; - char *bold_font_name; - GdkFont *old_r_font = NULL, *old_b_font = NULL; -#else - PangoFontDescription *new_r_font, *new_b_font; - PangoFontDescription *old_r_font = NULL, *old_b_font = NULL; -#endif - - /* convert font name to reflect the zoom level */ - gui_font_name = font_zoom(prefs.PREFS_GUI_FONT_NAME); - if (gui_font_name == NULL) { - /* - * This means the font name isn't an XLFD font name. - * We just report that for now as a font not available in - * multiple sizes. - */ - simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, - "Your current font isn't available in any other sizes.\n"); - return FA_FONT_NOT_RESIZEABLE; - } - -#if GTK_MAJOR_VERSION < 2 - new_r_font = gdk_font_load(gui_font_name); - bold_font_name = font_boldify(gui_font_name); - new_b_font = gdk_font_load(bold_font_name); -#else - new_r_font = pango_font_description_from_string(gui_font_name); - new_b_font = pango_font_description_copy(new_r_font); - pango_font_description_set_weight(new_b_font, PANGO_WEIGHT_BOLD); -#endif - if (new_r_font == NULL || new_b_font == NULL) { - /* We're no longer using the new fonts; unreference them. */ -#if GTK_MAJOR_VERSION < 2 - if (new_r_font != NULL) - gdk_font_unref(new_r_font); - if (new_b_font != NULL) - gdk_font_unref(new_b_font); -#else - if (new_r_font != NULL) - pango_font_description_free(new_r_font); - if (new_b_font != NULL) - pango_font_description_free(new_b_font); -#endif - g_free(gui_font_name); - - /* We let our caller pop up a dialog box, as the error message - depends on the context (did they zoom in or out, or did they - do something else? */ - return FA_FONT_NOT_AVAILABLE; - } - - /* the font(s) seem to be ok */ - set_plist_font(new_r_font); - set_ptree_font_all(new_r_font); - old_r_font = m_r_font; - old_b_font = m_b_font; - set_fonts(new_r_font, new_b_font); -#if GTK_MAJOR_VERSION < 2 - g_free(bold_font_name); -#endif - - /* Redraw the hex dump windows. */ - redraw_hex_dump_all(); - - /* Redraw the "Follow TCP Stream" windows. */ - follow_redraw_all(); - - /* We're no longer using the old fonts; unreference them. */ -#if GTK_MAJOR_VERSION < 2 - if (old_r_font != NULL) - gdk_font_unref(old_r_font); - if (old_b_font != NULL) - gdk_font_unref(old_b_font); -#else - if (old_r_font != NULL) - pango_font_description_free(old_r_font); - if (old_b_font != NULL) - pango_font_description_free(old_b_font); -#endif - g_free(gui_font_name); - return FA_SUCCESS; -} - - -#ifdef WIN32 - -#define NAME_BUFFER_LEN 32 - -#if GTK_MAJOR_VERSION < 2 - - -/* The setting of the MS default font for system stuff (menus, dialogs, ...), - * coming from: Allin Cottrell, http://www.ecn.wfu.edu/~cottrell/gtk_win32, - * Thank you very much for this! */ -int get_windows_font_gtk1(char *fontspec, int fontspec_len) -{ - HDC h_dc; - HGDIOBJ h_font; - TEXTMETRIC tm; - char name[NAME_BUFFER_LEN]; - int len, pix_height; - - h_dc = CreateDC("DISPLAY", NULL, NULL, NULL); - if (h_dc == NULL) return 1; - h_font = GetStockObject(DEFAULT_GUI_FONT); - if (h_font == NULL || !SelectObject(h_dc, h_font)) { - DeleteDC(h_dc); - return 1; - } - len = GetTextFace(h_dc, NAME_BUFFER_LEN, name); - if (len <= 0) { - DeleteDC(h_dc); - return 1; - } - if (!GetTextMetrics(h_dc, &tm)) { - DeleteDC(h_dc); - return 1; - } - pix_height = tm.tmHeight; - DeleteDC(h_dc); - g_snprintf(fontspec, fontspec_len, "-*-%s-*-*-*-*-%i-*-*-*-p-*-iso8859-1", name, - pix_height); - return 0; -} - -void set_app_font_gtk1(GtkWidget *top_level_w) -{ - GtkStyle *style; - char winfont[80]; - - style = gtk_widget_get_style(top_level); - if (get_windows_font_gtk1(winfont, sizeof(winfont)) == 0) - style->font = gdk_font_load(winfont); - if (style->font) gtk_widget_set_style(top_level, style); -} - -#else /* GTK_MAJOR_VERSION */ -static char appfontname[128] = "tahoma 8"; - -void set_app_font_gtk2(const char *fontname) -{ - GtkSettings *settings; - - if (fontname != NULL && *fontname == 0) return; - - settings = gtk_settings_get_default(); - - if (fontname == NULL) { - g_object_set(G_OBJECT(settings), "gtk-font-name", appfontname, NULL); - } else { - GtkWidget *w; - PangoFontDescription *pfd; - PangoContext *pc; - PangoFont *pfont; - - w = gtk_label_new(NULL); - pfd = pango_font_description_from_string(fontname); - pc = gtk_widget_get_pango_context(w); - pfont = pango_context_load_font(pc, pfd); - - if (pfont != NULL) { - strcpy(appfontname, fontname); - g_object_set(G_OBJECT(settings), "gtk-font-name", appfontname, NULL); - } - - gtk_widget_destroy(w); - pango_font_description_free(pfd); - } -} - -char *default_windows_menu_fontspec_gtk2(void) -{ - gchar *fontspec = NULL; - NONCLIENTMETRICS ncm; - - memset(&ncm, 0, sizeof ncm); - ncm.cbSize = sizeof ncm; - - if (SystemParametersInfo(SPI_GETNONCLIENTMETRICS, ncm.cbSize, &ncm, 0)) { - HDC screen = GetDC(0); - double y_scale = 72.0 / GetDeviceCaps(screen, LOGPIXELSY); - int point_size = (int) (ncm.lfMenuFont.lfHeight * y_scale); - - if (point_size < 0) point_size = -point_size; - fontspec = g_strdup_printf("%s %d", ncm.lfMenuFont.lfFaceName, - point_size); - ReleaseDC(0, screen); - } - - return fontspec; -} - -static void try_to_get_windows_font_gtk2(void) -{ - gchar *fontspec; - - fontspec = default_windows_menu_fontspec_gtk2(); - - if (fontspec != NULL) { - int match = 0; - PangoFontDescription *pfd; - PangoFont *pfont; - PangoContext *pc; - GtkWidget *w; - - pfd = pango_font_description_from_string(fontspec); - - w = gtk_label_new(NULL); - pc = gtk_widget_get_pango_context(w); - pfont = pango_context_load_font(pc, pfd); - match = (pfont != NULL); - - pango_font_description_free(pfd); - g_object_unref(G_OBJECT(pc)); - gtk_widget_destroy(w); - - if (match) set_app_font_gtk2(fontspec); - g_free(fontspec); - } -} -#endif /* GTK_MAJOR_VERSION */ - -#endif /* WIN32 */ GtkWidget *info_bar_new(void) { @@ -3482,7 +2827,8 @@ create_main_window (gint pl_size, gint tv_size, gint bv_size, e_prefs *prefs) #ifdef WIN32 #if GTK_MAJOR_VERSION < 2 - set_app_font_gtk1(top_level); + /* has to be done, after top_level window is created */ + app_font_gtk1_init(top_level); #endif #endif @@ -3517,11 +2863,6 @@ create_main_window (gint pl_size, gint tv_size, gint bv_size, e_prefs *prefs) gtk_widget_show(pkt_scrollw); /* Tree view */ -#if GTK_MAJOR_VERSION < 2 - item_style = gtk_style_new(); - gdk_font_unref(item_style->font); - item_style->font = m_r_font; -#endif tv_scrollw = main_tree_view_new(prefs, &tree_view); WIDGET_SET_SIZE(tv_scrollw, -1, tv_size); gtk_widget_show(tv_scrollw); diff --git a/gtk/main.h b/gtk/main.h index 26ee1e48ef..f54509bf35 100644 --- a/gtk/main.h +++ b/gtk/main.h @@ -1,7 +1,7 @@ /* main.h * Global defines, etc. * - * $Id: main.h,v 1.51 2004/06/04 17:16:57 ulfl Exp $ + * $Id: main.h,v 1.52 2004/06/17 16:35:25 ulfl Exp $ * * Ethereal - Network traffic analyzer * By Gerald Combs <gerald@ethereal.com> @@ -250,25 +250,4 @@ extern void packets_bar_update(void); extern void create_console(void); #endif -/** Return value from font_apply() */ -typedef enum { - FA_SUCCESS, /**< function succeeded */ - FA_FONT_NOT_RESIZEABLE, /**< the choosen font isn't resizable */ - FA_FONT_NOT_AVAILABLE /**< the choosen font isn't available */ -} fa_ret_t; - -/** Applies a new font. Will also redraw the screen. - * - * @return if the new font could be set or not - */ -extern fa_ret_t font_apply(void); -#if GTK_MAJOR_VERSION < 2 -/* Try to convert a font name to it's bold version. - * - * @param the font to convert - * @return the bold font - */ -char *font_boldify(const char *font_name); -#endif - #endif /* __MAIN_H__ */ diff --git a/gtk/packet_list.c b/gtk/packet_list.c index 16eee2fc95..b6e4549cb8 100644 --- a/gtk/packet_list.c +++ b/gtk/packet_list.c @@ -1,7 +1,7 @@ /* packet_list.c * packet list related functions 2002 Olivier Abad * - * $Id: packet_list.c,v 1.20 2004/06/05 10:27:38 ulfl Exp $ + * $Id: packet_list.c,v 1.21 2004/06/17 16:35:25 ulfl Exp $ * * Ethereal - Network traffic analyzer * By Gerald Combs <gerald@ethereal.com> @@ -45,6 +45,8 @@ #include "file_dlg.h" #include "packet_list.h" #include "keys.h" +#include "font_utils.h" + #include <epan/timestamp.h> #include "image/clist_ascend.xpm" @@ -443,13 +445,8 @@ set_plist_sel_browse(gboolean val) } /* Set the font of the packet list window. */ -#if GTK_MAJOR_VERSION < 2 void -set_plist_font(GdkFont *font) -#else -void -set_plist_font(PangoFontDescription *font) -#endif +set_plist_font(FONT_TYPE *font) { int i; gint col_width; @@ -504,7 +501,7 @@ packet_list_new(e_prefs *prefs) gtk_container_add(GTK_CONTAINER(pkt_scrollw), packet_list); set_plist_sel_browse(prefs->gui_plist_sel_browse); - set_plist_font(m_r_font); + set_plist_font(user_font_get_regular()); gtk_widget_set_name(packet_list, "packet list"); SIGNAL_CONNECT(packet_list, "select-row", packet_list_select_cb, NULL); SIGNAL_CONNECT(packet_list, "unselect-row", packet_list_unselect_cb, NULL); diff --git a/gtk/packet_list.h b/gtk/packet_list.h index fed62a8c08..1b4fe0cd44 100644 --- a/gtk/packet_list.h +++ b/gtk/packet_list.h @@ -1,7 +1,7 @@ /* packet_list.h * Declarations of GTK+-specific routines for managing the packet list. * - * $Id: packet_list.h,v 1.4 2004/06/04 17:16:58 ulfl Exp $ + * $Id: packet_list.h,v 1.5 2004/06/17 16:35:25 ulfl Exp $ * * Ethereal - Network traffic analyzer * By Gerald Combs <gerald@ethereal.com> @@ -79,19 +79,11 @@ extern void update_marked_frames(void); extern gboolean packet_list_get_event_row_column(GtkWidget *widget, GdkEventButton *event_button, gint *row, gint *column); -#if GTK_MAJOR_VERSION < 2 /** Set the font of the packet list. * * @param font the new font */ -extern void set_plist_font(GdkFont *font); -#else -/** Set the font of the packet list. - * - * @param font the new font - */ -extern void set_plist_font(PangoFontDescription *font); -#endif +extern void set_plist_font(FONT_TYPE *font); /** Set the selection mode of the packet list window. * diff --git a/gtk/proto_draw.c b/gtk/proto_draw.c index 1562565724..5a628d747b 100644 --- a/gtk/proto_draw.c +++ b/gtk/proto_draw.c @@ -1,7 +1,7 @@ /* proto_draw.c * Routines for GTK+ packet display * - * $Id: proto_draw.c,v 1.104 2004/06/01 17:33:37 ulfl Exp $ + * $Id: proto_draw.c,v 1.105 2004/06/17 16:35:25 ulfl Exp $ * * Ethereal - Network traffic analyzer * By Gerald Combs <gerald@ethereal.com> @@ -68,6 +68,7 @@ #include "alert_box.h" #include "simple_dialog.h" #include "progress_dlg.h" +#include "font_utils.h" /* Win32 needs the O_BINARY flag for open() */ @@ -86,6 +87,11 @@ #define E_BYTE_VIEW_END_KEY "byte_view_end" #define E_BYTE_VIEW_ENCODE_KEY "byte_view_encode" + +#if GTK_MAJOR_VERSION < 2 +GtkStyle *item_style = NULL; +#endif + /* gtk_tree_view_expand_to_path doesn't exist in gtk+ v2.0 so we must include it * when building with this version (taken from gtk+ v2.2.4) */ #if GTK_MAJOR_VERSION >= 2 && GTK_MINOR_VERSION == 0 @@ -492,8 +498,8 @@ byte_view_select(GtkWidget *widget, GdkEventButton *event) * which text column/row the user selected. This could be off * if the bold version of the font is bigger than the * regular version of the font. */ - column = (int) ((bv->hadj->value + event->x) / m_font_width); - row = (int) ((bv->vadj->value + event->y) / m_font_height); + column = (int) ((bv->hadj->value + event->x) / user_font_get_regular_width()); + row = (int) ((bv->vadj->value + event->y) / user_font_get_regular_height()); #else /* get the row/column selected */ gtk_text_view_window_to_buffer_coords(bv, @@ -715,13 +721,13 @@ add_byte_tab(GtkWidget *byte_nb, const char *name, tvbuff_t *tvb, gtk_text_view_set_cursor_visible(GTK_TEXT_VIEW(byte_view), FALSE); buf = gtk_text_view_get_buffer(GTK_TEXT_VIEW(byte_view)); style = gtk_widget_get_style(GTK_WIDGET(byte_view)); - gtk_text_buffer_create_tag(buf, "plain", "font-desc", m_r_font, NULL); + gtk_text_buffer_create_tag(buf, "plain", "font-desc", user_font_get_regular(), NULL); gtk_text_buffer_create_tag(buf, "reverse", - "font-desc", m_r_font, + "font-desc", user_font_get_regular(), "foreground-gdk", &style->text[GTK_STATE_SELECTED], "background-gdk", &style->base[GTK_STATE_SELECTED], NULL); - gtk_text_buffer_create_tag(buf, "bold", "font-desc", m_b_font, NULL); + gtk_text_buffer_create_tag(buf, "bold", "font-desc", user_font_get_bold(), NULL); #endif OBJECT_SET_DATA(byte_view, E_BYTE_VIEW_TVBUFF_KEY, tvb); gtk_container_add(GTK_CONTAINER(byte_scrollw), byte_view); @@ -1078,7 +1084,7 @@ packet_hex_print_common(GtkTextView *bv, const guint8 *pd, int len, int bstart, /* Display with inverse video ? */ #if GTK_MAJOR_VERSION < 2 if (prefs.gui_hex_dump_highlight_style) { - gtk_text_insert(bv, m_r_font, &BLACK, &WHITE, line, -1); + gtk_text_insert(bv, user_font_get_regular(), &BLACK, &WHITE, line, -1); /* Do we start in reverse? */ reverse = i >= bstart && i < bend; fg = reverse ? &WHITE : &BLACK; @@ -1098,7 +1104,7 @@ packet_hex_print_common(GtkTextView *bv, const guint8 *pd, int len, int bstart, newreverse = i >= bstart && i < bend; /* Have we gone from reverse to plain? */ if (reverse && (reverse != newreverse)) { - gtk_text_insert(bv, m_r_font, fg, bg, line, cur); + gtk_text_insert(bv, user_font_get_regular(), fg, bg, line, cur); fg = &BLACK; bg = &WHITE; cur = 0; @@ -1113,7 +1119,7 @@ packet_hex_print_common(GtkTextView *bv, const guint8 *pd, int len, int bstart, } /* Have we gone from plain to reversed? */ if (!reverse && (reverse != newreverse)) { - gtk_text_insert(bv, m_r_font, fg, bg, line, cur); + gtk_text_insert(bv, user_font_get_regular(), fg, bg, line, cur); fg = &WHITE; bg = &BLACK; cur = 0; @@ -1121,11 +1127,11 @@ packet_hex_print_common(GtkTextView *bv, const guint8 *pd, int len, int bstart, reverse = newreverse; } /* Print remaining part of line */ - gtk_text_insert(bv, m_r_font, fg, bg, line, cur); + gtk_text_insert(bv, user_font_get_regular(), fg, bg, line, cur); cur = 0; /* Print some space at the end of the line */ line[cur++] = ' '; line[cur++] = ' '; line[cur++] = ' '; - gtk_text_insert(bv, m_r_font, &BLACK, &WHITE, line, cur); + gtk_text_insert(bv, user_font_get_regular(), &BLACK, &WHITE, line, cur); cur = 0; /* Print the ASCII bit */ @@ -1153,7 +1159,7 @@ packet_hex_print_common(GtkTextView *bv, const guint8 *pd, int len, int bstart, newreverse = i >= bstart && i < bend; /* Have we gone from reverse to plain? */ if (reverse && (reverse != newreverse)) { - gtk_text_insert(bv, m_r_font, fg, bg, line, cur); + gtk_text_insert(bv, user_font_get_regular(), fg, bg, line, cur); fg = &BLACK; bg = &WHITE; cur = 0; @@ -1166,7 +1172,7 @@ packet_hex_print_common(GtkTextView *bv, const guint8 *pd, int len, int bstart, } /* Have we gone from plain to reversed? */ if (!reverse && (reverse != newreverse)) { - gtk_text_insert(bv, m_r_font, fg, bg, line, cur); + gtk_text_insert(bv, user_font_get_regular(), fg, bg, line, cur); fg = &WHITE; bg = &BLACK; cur = 0; @@ -1174,16 +1180,16 @@ packet_hex_print_common(GtkTextView *bv, const guint8 *pd, int len, int bstart, reverse = newreverse; } /* Print remaining part of line */ - gtk_text_insert(bv, m_r_font, fg, bg, line, cur); + gtk_text_insert(bv, user_font_get_regular(), fg, bg, line, cur); cur = 0; line[cur++] = '\n'; line[cur] = '\0'; - gtk_text_insert(bv, m_r_font, &BLACK, &WHITE, line, -1); + gtk_text_insert(bv, user_font_get_regular(), &BLACK, &WHITE, line, -1); } else { - gtk_text_insert(bv, m_r_font, NULL, NULL, line, -1); + gtk_text_insert(bv, user_font_get_regular(), NULL, NULL, line, -1); /* Do we start in bold? */ - cur_font = (i >= bstart && i < bend) ? m_b_font : m_r_font; + cur_font = (i >= bstart && i < bend) ? user_font_get_bold() : user_font_get_regular(); j = i; k = i + BYTE_VIEW_WIDTH; cur = 0; @@ -1200,7 +1206,7 @@ packet_hex_print_common(GtkTextView *bv, const guint8 *pd, int len, int bstart, /* insert a space every BYTE_VIEW_SEP bytes */ if( ( i % BYTE_VIEW_SEP ) == 0 ) line[cur++] = ' '; /* Did we cross a bold/plain boundary? */ - new_font = (i >= bstart && i < bend) ? m_b_font : m_r_font; + new_font = (i >= bstart && i < bend) ? user_font_get_bold() : user_font_get_regular(); if (cur_font != new_font) { gtk_text_insert(bv, cur_font, NULL, NULL, line, cur); cur_font = new_font; @@ -1213,7 +1219,7 @@ packet_hex_print_common(GtkTextView *bv, const guint8 *pd, int len, int bstart, cur = 0; i = j; /* Print the ASCII bit */ - cur_font = (i >= bstart && i < bend) ? m_b_font : m_r_font; + cur_font = (i >= bstart && i < bend) ? user_font_get_bold() : user_font_get_regular(); while (i < k) { if (i < len) { if (encoding == CHAR_ASCII) { @@ -1233,7 +1239,7 @@ packet_hex_print_common(GtkTextView *bv, const guint8 *pd, int len, int bstart, /* insert a space every BYTE_VIEW_SEP bytes */ if( ( i % BYTE_VIEW_SEP ) == 0 ) line[cur++] = ' '; /* Did we cross a bold/plain boundary? */ - new_font = (i >= bstart && i < bend) ? m_b_font : m_r_font; + new_font = (i >= bstart && i < bend) ? user_font_get_bold() : user_font_get_regular(); if (cur_font != new_font) { gtk_text_insert(bv, cur_font, NULL, NULL, line, cur); cur_font = new_font; @@ -1372,7 +1378,7 @@ packet_hex_print_common(GtkTextView *bv, const guint8 *pd, int len, int bstart, float scrollval; linenum = bstart / BYTE_VIEW_WIDTH; - scrollval = MIN(linenum * m_font_height, + scrollval = MIN(linenum * user_font_get_regular_height(), bv->vadj->upper - bv->vadj->page_size); gtk_adjustment_set_value(bv->vadj, scrollval); @@ -1528,13 +1534,8 @@ set_ptree_font_cb(gpointer data, gpointer user_data) } #endif -#if GTK_MAJOR_VERSION < 2 void -set_ptree_font_all(GdkFont *font) -#else -void -set_ptree_font_all(PangoFontDescription *font) -#endif +set_ptree_font_all(FONT_TYPE *font) { #if GTK_MAJOR_VERSION < 2 GtkStyle *style; @@ -1650,9 +1651,15 @@ main_tree_view_new(e_prefs *prefs, GtkWidget **tree_view_p) gtk_container_add( GTK_CONTAINER(tv_scrollw), tree_view ); set_ptree_sel_browse(tree_view, prefs->gui_ptree_sel_browse); #if GTK_MAJOR_VERSION < 2 + if(item_style == NULL) { + item_style = gtk_style_new(); + gdk_font_unref(item_style->font); + item_style->font = user_font_get_regular(); + } + gtk_widget_set_style(tree_view, item_style); #else - gtk_widget_modify_font(tree_view, m_r_font); + gtk_widget_modify_font(tree_view, user_font_get_regular()); #endif remember_ptree_widget(tree_view); diff --git a/gtk/supported_protos_dlg.c b/gtk/supported_protos_dlg.c index 04ad9d270b..29991eaffd 100644 --- a/gtk/supported_protos_dlg.c +++ b/gtk/supported_protos_dlg.c @@ -2,7 +2,7 @@ * * Laurent Deniel <laurent.deniel@free.fr> * - * $Id: supported_protos_dlg.c,v 1.11 2004/05/23 23:24:06 ulfl Exp $ + * $Id: supported_protos_dlg.c,v 1.12 2004/06/17 16:35:25 ulfl Exp $ * * Ethereal - Network traffic analyzer * By Gerald Combs <gerald@ethereal.com> @@ -37,6 +37,7 @@ #include "ui_util.h" #include "compat_macros.h" #include "dlg_utils.h" +#include "font_utils.h" @@ -247,13 +248,13 @@ static void supported_destroy_cb(GtkWidget *w _U_, gpointer data _U_) static void insert_text(GtkWidget *w, const char *buffer, int nchars) { #if GTK_MAJOR_VERSION < 2 - gtk_text_insert(GTK_TEXT(w), m_r_font, NULL, NULL, buffer, nchars); + gtk_text_insert(GTK_TEXT(w), user_font_get_regular(), NULL, NULL, buffer, nchars); #else GtkTextBuffer *buf= gtk_text_view_get_buffer(GTK_TEXT_VIEW(w)); GtkTextIter iter; gtk_text_buffer_get_end_iter(buf, &iter); - gtk_widget_modify_font(w, m_r_font); + gtk_widget_modify_font(w, user_font_get_regular()); if (!g_utf8_validate(buffer, -1, NULL)) printf("Invalid utf8 encoding: %s\n", buffer); gtk_text_buffer_insert(buf, &iter, buffer, nchars); @@ -318,7 +319,7 @@ static void set_supported_text(GtkWidget *w, supported_type_t type) len = g_snprintf(buffer, BUFF_LEN, proto_supported, count); #if GTK_MAJOR_VERSION < 2 maxlen2 = len; - width = gdk_string_width(m_r_font, buffer); + width = gdk_string_width(user_font_get_regular(), buffer); insert_text(w, buffer, maxlen2); #else insert_text(w, buffer, len); @@ -340,7 +341,7 @@ static void set_supported_text(GtkWidget *w, supported_type_t type) #if GTK_MAJOR_VERSION < 2 if (len > maxlen2) { maxlen2 = len; - if ((len = gdk_string_width(m_r_font, buffer)) > width) + if ((len = gdk_string_width(user_font_get_regular(), buffer)) > width) width = len; } insert_text(w, buffer, strlen(buffer)); @@ -351,7 +352,7 @@ static void set_supported_text(GtkWidget *w, supported_type_t type) } #if GTK_MAJOR_VERSION < 2 - height = (3 + nb_lines) * m_font_height; + height = (3 + nb_lines) * user_font_get_regular_height(); WIDGET_SET_SIZE(w, 20 + width, 20 + height); #endif break; @@ -381,7 +382,7 @@ static void set_supported_text(GtkWidget *w, supported_type_t type) #if GTK_MAJOR_VERSION < 2 maxlen3 = strlen(dfilter_supported); - width = gdk_string_width(m_r_font, dfilter_supported); + width = gdk_string_width(user_font_get_regular(), dfilter_supported); insert_text(w, dfilter_supported, maxlen3); #else insert_text(w, dfilter_supported, strlen(dfilter_supported)); @@ -424,7 +425,7 @@ static void set_supported_text(GtkWidget *w, supported_type_t type) #if GTK_MAJOR_VERSION < 2 if (len > maxlen3) { maxlen3 = len; - if ((len = gdk_string_width(m_r_font, buffer)) > width) + if ((len = gdk_string_width(user_font_get_regular(), buffer)) > width) width = len; } insert_text(w, buffer, strlen(buffer)); @@ -438,7 +439,7 @@ static void set_supported_text(GtkWidget *w, supported_type_t type) insert_text(w, buffer, len); #if GTK_MAJOR_VERSION < 2 - height = (5 + nb_lines) * m_font_height; + height = (5 + nb_lines) * user_font_get_regular_height(); WIDGET_SET_SIZE(w, 20 + width, 20 + height); #endif break; diff --git a/gtk/tcp_graph.c b/gtk/tcp_graph.c index a957562ee5..fc893ecf8f 100644 --- a/gtk/tcp_graph.c +++ b/gtk/tcp_graph.c @@ -3,7 +3,7 @@ * By Pavel Mores <pvl@uh.cz> * Win32 port: rwh@unifiedtech.com * - * $Id: tcp_graph.c,v 1.63 2004/06/10 10:09:58 guy Exp $ + * $Id: tcp_graph.c,v 1.64 2004/06/17 16:35:25 ulfl Exp $ * * Ethereal - Network traffic analyzer * By Gerald Combs <gerald@ethereal.com> @@ -320,11 +320,7 @@ struct graph { GtkWidget *drawing_area; GtkWidget *text; /* text widget for seg list - probably * temporary */ -#if GTK_MAJOR_VERSION < 2 - GdkFont *font; /* font used for annotations etc. */ -#else - PangoFontDescription *font; /* font used for annotations etc. */ -#endif + FONT_TYPE *font; /* font used for annotations etc. */ GdkGC *fg_gc; GdkGC *bg_gc; GdkPixmap *title_pixmap; diff --git a/gtk/text_page.c b/gtk/text_page.c index 4b1be49c9c..cdc7b433c5 100644 --- a/gtk/text_page.c +++ b/gtk/text_page.c @@ -1,6 +1,6 @@ /* text_page.c * - * $Id: text_page.c,v 1.2 2004/06/07 19:49:37 guy Exp $ + * $Id: text_page.c,v 1.3 2004/06/17 16:35:26 ulfl Exp $ * * Ulf Lamping * @@ -34,11 +34,10 @@ #include "epan/filesystem.h" #include "text_page.h" -#include "gtkglobals.h" #include "ui_util.h" #include "compat_macros.h" #include "simple_dialog.h" - +#include "font_utils.h" #define TEXT_KEY "txt_key" @@ -103,13 +102,13 @@ static void text_page_insert(GtkWidget *page, const char *buffer, int nchars) GtkWidget *txt = OBJECT_GET_DATA(page, TEXT_KEY); #if GTK_MAJOR_VERSION < 2 - gtk_text_insert(GTK_TEXT(txt), m_r_font, NULL, NULL, buffer, nchars); + gtk_text_insert(GTK_TEXT(txt), user_font_get_regular(), NULL, NULL, buffer, nchars); #else GtkTextBuffer *buf= gtk_text_view_get_buffer(GTK_TEXT_VIEW(txt)); GtkTextIter iter; gtk_text_buffer_get_end_iter(buf, &iter); - gtk_widget_modify_font(GTK_WIDGET(txt), m_r_font); + gtk_widget_modify_font(GTK_WIDGET(txt), user_font_get_regular()); if (!g_utf8_validate(buffer, -1, NULL)) printf("Invalid utf8 encoding: %s\n", buffer); gtk_text_buffer_insert(buf, &iter, buffer, nchars); |