52d317c4655f264d88326aaa709b143f0d05964d
[obnox/wireshark/wip.git] / gtk / font_utils.c
1 /* font_utils.c
2  * Utilities to use for font manipulation
3  *
4  * $Id$
5  *
6  * Ethereal - Network traffic analyzer
7  * By Gerald Combs <gerald@ethereal.com>
8  * Copyright 1998 Gerald Combs
9  *
10  * This program is free software; you can redistribute it and/or
11  * modify it under the terms of the GNU General Public License
12  * as published by the Free Software Foundation; either version 2
13  * of the License, or (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program; if not, write to the Free Software
22  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
23  */
24
25 #ifdef HAVE_CONFIG_H
26 # include "config.h"
27 #endif
28
29 #include <gtk/gtk.h>
30 #include <string.h>
31 #include <stdlib.h>
32 #include <stdio.h>
33
34 #include <epan/packet.h>
35
36 #ifdef _WIN32
37 #include <windows.h>
38 #endif
39
40 #include "recent.h"
41 #include <epan/prefs.h>
42
43 #include "gtkglobals.h"
44
45 #include "compat_macros.h"
46 #include "font_utils.h"
47 #include "simple_dialog.h"
48
49 #include "packet_list.h"
50 #include "proto_draw.h"
51 #include "follow_dlg.h"
52
53
54 /* XXX - use capture.h instead */
55 /*#include "capture.h"*/
56 extern gboolean capture_child;  
57
58
59
60 #if GTK_MAJOR_VERSION < 2
61 guint        m_font_height, m_font_width;
62 #endif
63 FONT_TYPE *m_r_font, *m_b_font;
64
65
66 /* Get the regular user font.
67  *
68  * @return the regular user font
69  */
70 FONT_TYPE *user_font_get_regular(void)
71 {
72     return m_r_font;
73 }
74
75 /* Get the bold user font.
76  *
77  * @return the bold user font
78  */
79 FONT_TYPE *user_font_get_bold(void)
80 {
81     return m_b_font;
82 }
83
84 #if GTK_MAJOR_VERSION < 2
85 /* Get the regular user font height.
86  *
87  * @return the regular user font height
88  */
89 guint user_font_get_regular_height(void)
90 {
91     return m_font_height;
92 }
93
94 /* Get the regular user font width.
95  *
96  * @return the regular user font width
97  */
98 guint user_font_get_regular_width(void)
99 {
100     return m_font_width;
101 }
102 #endif
103
104
105 static void
106 set_fonts(FONT_TYPE *regular, FONT_TYPE *bold)
107 {
108         /* Yes, assert. The code that loads the font should check
109          * for NULL and provide its own error message. */
110         g_assert(m_r_font && m_b_font);
111         m_r_font = regular;
112         m_b_font = bold;
113
114 #if GTK_MAJOR_VERSION < 2
115         m_font_height = m_r_font->ascent + m_r_font->descent;
116         m_font_width = gdk_string_width(m_r_font, "0");
117 #endif
118 }
119
120 void
121 view_zoom_in_cb(GtkWidget *w _U_, gpointer d _U_)
122 {
123     gint save_gui_zoom_level;
124
125     save_gui_zoom_level = recent.gui_zoom_level;
126     recent.gui_zoom_level++;
127     switch (user_font_apply()) {
128
129     case FA_SUCCESS:
130         break;
131
132     case FA_FONT_NOT_RESIZEABLE:
133         /* "font_apply()" popped up an alert box. */
134         recent.gui_zoom_level = save_gui_zoom_level;    /* undo zoom */
135         break;
136
137     case FA_FONT_NOT_AVAILABLE:
138         /* We assume this means that the specified size isn't available. */
139         simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK,
140             "Your current font isn't available in the next larger size.\n");
141         recent.gui_zoom_level = save_gui_zoom_level;    /* undo zoom */
142         break;
143     }
144 }
145
146 void
147 view_zoom_out_cb(GtkWidget *w _U_, gpointer d _U_)
148 {
149     gint save_gui_zoom_level;
150
151     save_gui_zoom_level = recent.gui_zoom_level;
152     recent.gui_zoom_level--;
153     switch (user_font_apply()) {
154
155     case FA_SUCCESS:
156         break;
157
158     case FA_FONT_NOT_RESIZEABLE:
159         /* "font_apply()" popped up an alert box. */
160         recent.gui_zoom_level = save_gui_zoom_level;    /* undo zoom */
161         break;
162
163     case FA_FONT_NOT_AVAILABLE:
164         /* We assume this means that the specified size isn't available. */
165         simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK,
166             "Your current font isn't available in the next smaller size.\n");
167         recent.gui_zoom_level = save_gui_zoom_level;    /* undo zoom */
168         break;
169     }
170 }
171
172 void
173 view_zoom_100_cb(GtkWidget *w _U_, gpointer d _U_)
174 {
175     gint save_gui_zoom_level;
176
177     save_gui_zoom_level = recent.gui_zoom_level;
178     recent.gui_zoom_level = 0;
179     switch (user_font_apply()) {
180
181     case FA_SUCCESS:
182         break;
183
184     case FA_FONT_NOT_RESIZEABLE:
185         /* "font_apply()" popped up an alert box. */
186         recent.gui_zoom_level = save_gui_zoom_level;    /* undo zoom */
187         break;
188
189     case FA_FONT_NOT_AVAILABLE:
190         /* We assume this means that the specified size isn't available.
191            XXX - this "shouldn't happen". */
192         simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK,
193             "Your current font couldn't be reloaded at the size you selected.\n");
194         recent.gui_zoom_level = save_gui_zoom_level;    /* undo zoom */
195         break;
196     }
197 }
198
199
200 #if GTK_MAJOR_VERSION < 2
201 /* Given a font name, construct the name of the next heavier version of
202    that font. */
203
204 #define XLFD_WEIGHT     3       /* index of the "weight" field */
205
206 /* Map from a given weight to the appropriate weight for the "bold"
207    version of a font.
208    XXX - the XLFD says these strings shouldn't be used for font matching;
209    can we get the weight, as a number, from GDK, and ask GDK to find us
210    a font just like the given font, but with the appropriate higher
211    weight? */
212 static const struct {
213         char    *light;
214         char    *heavier;
215 } weight_map[] = {
216         { "ultralight", "light" },
217         { "extralight", "semilight" },
218         { "light",      "medium" },
219         { "semilight",  "semibold" },
220         { "medium",     "bold" },
221         { "normal",     "bold" },
222         { "semibold",   "extrabold" },
223         { "bold",       "ultrabold" }
224 };
225 #define N_WEIGHTS       (sizeof weight_map / sizeof weight_map[0])
226
227 /* Try to convert a font name to it's bold version.
228  *
229  * @param the font to convert
230  * @return the bold font
231  */
232 static char *
233 user_font_boldify(const char *font_name)
234 {
235         char *bold_font_name;
236         gchar **xlfd_tokens;
237         unsigned int i;
238
239         /* Is this an XLFD font?  If it begins with "-", yes, otherwise no. */
240         if (font_name[0] == '-') {
241                 xlfd_tokens = g_strsplit(font_name, "-", XLFD_WEIGHT+1);
242
243                 /*
244                  * Make sure we *have* a weight (this might not be a valid
245                  * XLFD font name).
246                  */
247                 for (i = 0; i < XLFD_WEIGHT+1; i++) {
248                         if (xlfd_tokens[i] == NULL) {
249                                 /*
250                                  * We don't, so treat this as a non-XLFD
251                                  * font name.
252                                  */
253                                 goto not_xlfd;
254                         }
255                 }
256                 for (i = 0; i < N_WEIGHTS; i++) {
257                         if (strcmp(xlfd_tokens[XLFD_WEIGHT],
258                             weight_map[i].light) == 0) {
259                                 g_free(xlfd_tokens[XLFD_WEIGHT]);
260                                 xlfd_tokens[XLFD_WEIGHT] =
261                                     g_strdup(weight_map[i].heavier);
262                                 break;
263                         }
264                 }
265                 bold_font_name = g_strjoinv("-", xlfd_tokens);
266                 g_strfreev(xlfd_tokens);
267                 return bold_font_name;
268         }
269
270 not_xlfd:
271         /*
272          * This isn't an XLFD font name; just append "bold" to the name
273          * of the font.
274          */
275         bold_font_name = g_strconcat(font_name, "bold", NULL);
276         return bold_font_name;
277 }
278 #endif
279
280
281 gboolean
282 user_font_test(gchar *font_name)
283 {
284 #if GTK_MAJOR_VERSION < 2
285         gchar   *bold_font_name;
286 #endif
287         FONT_TYPE *new_r_font, *new_b_font;
288
289 #if GTK_MAJOR_VERSION < 2
290         /* Get the name that the boldface version of that font would have. */
291         bold_font_name = user_font_boldify(font_name);
292
293         /* Now load those fonts, just to make sure we can. */
294         new_r_font = gdk_font_load(font_name);
295 #else
296         new_r_font = pango_font_description_from_string(font_name);
297 #endif
298         if (new_r_font == NULL) {
299                 /* Oops, that font didn't work.
300                    Tell the user, but don't tear down the font selection
301                    dialog, so that they can try again. */
302                 simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK,
303                    "The font you selected can't be loaded.");
304
305 #if GTK_MAJOR_VERSION < 2
306                 g_free(bold_font_name);
307 #endif
308                 return FALSE;
309         }
310
311 #if GTK_MAJOR_VERSION < 2
312         new_b_font = gdk_font_load(bold_font_name);
313 #else
314         new_b_font = pango_font_description_copy(new_r_font);
315         pango_font_description_set_weight(new_b_font, PANGO_WEIGHT_BOLD);
316 #endif
317         if (new_b_font == NULL) {
318                 /* Oops, that font didn't work.
319                    Tell the user, but don't tear down the font selection
320                    dialog, so that they can try again. */
321                 simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK,
322                    "The font you selected doesn't have a boldface version.");
323
324 #if GTK_MAJOR_VERSION < 2
325                 g_free(bold_font_name);
326                 gdk_font_unref(new_r_font);
327 #else
328                 pango_font_description_free(new_r_font);
329 #endif
330                 return FALSE;
331         }
332
333         return TRUE;
334 }
335
336
337
338 /* Given a font name, construct the name of a version of that font with
339    the current zoom factor applied. */
340 static char *
341 font_zoom(char *gui_font_name)
342 {
343     char *new_font_name;
344     char *font_name_dup;
345     char *font_name_p;
346     long font_point_size_l;
347 #if GTK_MAJOR_VERSION < 2
348     int minus_chars;
349     char *font_foundry;
350     char *font_family;
351     char *font_weight;
352     char *font_slant;
353     char *font_set_width;
354     char *font_add_style;
355     char *font_pixel_size;
356     char *font_point_size;
357     char *font_res_x;
358     char *font_res_y;
359     char *font_spacing;
360     char *font_aver_width;
361     char *font_charset_reg;
362     char *font_charset_encoding;
363 #endif
364
365     if (recent.gui_zoom_level == 0) {
366         /* There is no zoom factor - just return the name, so that if
367            this is GTK+ 1.2[.x] and the font name isn't an XLFD font
368            name, we don't fail. */
369         return g_strdup(gui_font_name);
370     }
371
372     font_name_dup = g_strdup(gui_font_name);
373     font_name_p = font_name_dup;
374
375 #if GTK_MAJOR_VERSION >= 2
376     /* find the start of the font_size string */
377     font_name_p = strrchr(font_name_dup, ' ');
378     *font_name_p = '\0';
379     font_name_p++;
380
381     /* calculate the new font size */
382     font_point_size_l = strtol(font_name_p, NULL, 10);
383     font_point_size_l += recent.gui_zoom_level;
384
385     /* build a new font name */
386     new_font_name = g_strdup_printf("%s %ld", font_name_dup, font_point_size_l);
387 #else
388     minus_chars = 0;
389     /* replace all '-' chars by NUL and count them */
390     while ((font_name_p = strchr(font_name_p, '-')) != NULL) {
391         *font_name_p = '\0';
392         font_name_p++;
393         minus_chars++;
394     }
395
396     if (minus_chars != 14) {
397         /*
398          * Not a valid XLFD font name.
399          * XXX - can we try scaling it by looking for a size at the end
400          * and tweaking that?  Unfortunately, some fonts have numbers
401          * at the end that aren't, as far as I know, sizes, e.g. "nil2".
402          */
403         return NULL;
404     }
405
406     /* first element (font name registry) empty */
407     font_name_p = font_name_dup;
408     font_name_p += strlen(font_name_p);
409     font_name_p++;
410
411     /* get pointers to all font name elements */
412     font_foundry = font_name_p;
413     font_name_p += strlen(font_name_p);
414     font_name_p++;
415
416     font_family = font_name_p;
417     font_name_p += strlen(font_name_p);
418     font_name_p++;
419
420     font_weight = font_name_p;
421     font_name_p += strlen(font_name_p);
422     font_name_p++;
423
424     font_slant = font_name_p;
425     font_name_p += strlen(font_name_p);
426     font_name_p++;
427
428     font_set_width = font_name_p;
429     font_name_p += strlen(font_name_p);
430     font_name_p++;
431
432     font_add_style = font_name_p;
433     font_name_p += strlen(font_name_p);
434     font_name_p++;
435
436     font_pixel_size = font_name_p;
437     font_name_p += strlen(font_name_p);
438     font_name_p++;
439
440     font_point_size = font_name_p;
441     font_name_p += strlen(font_name_p);
442     font_name_p++;
443
444     font_res_x = font_name_p;
445     font_name_p += strlen(font_name_p);
446     font_name_p++;
447
448     font_res_y = font_name_p;
449     font_name_p += strlen(font_name_p);
450     font_name_p++;
451
452     font_spacing = font_name_p;
453     font_name_p += strlen(font_name_p);
454     font_name_p++;
455
456     font_aver_width = font_name_p;
457     font_name_p += strlen(font_name_p);
458     font_name_p++;
459
460     font_charset_reg = font_name_p;
461     font_name_p += strlen(font_name_p);
462     font_name_p++;
463
464     font_charset_encoding = font_name_p;
465     font_name_p += strlen(font_name_p);
466     font_name_p++;
467
468     /* calculate the new font size */
469     font_point_size_l = strtol(font_point_size, NULL, 10);
470     font_point_size_l += recent.gui_zoom_level*10;
471     if (font_point_size_l <= 0)
472         font_point_size_l = 10;
473
474     /* build a new font name */
475     new_font_name = g_strdup_printf("-%s-%s-%s-%s-%s-%s-%s-%ld-%s-%s-%s-%s-%s-%s", 
476         font_foundry, font_family, font_weight, font_slant, font_set_width, 
477         font_add_style, font_pixel_size, font_point_size_l, font_res_x,
478         font_res_y, font_spacing, font_aver_width, font_charset_reg,
479         font_charset_encoding);
480 #endif
481
482     g_free(font_name_dup);
483
484     return new_font_name;
485 }
486
487 fa_ret_t
488 user_font_apply(void) {
489     char *gui_font_name;
490 #if GTK_MAJOR_VERSION < 2
491     char *bold_font_name;
492 #endif
493     FONT_TYPE *new_r_font, *new_b_font;
494     FONT_TYPE *old_r_font = NULL, *old_b_font = NULL;
495
496     /* convert font name to reflect the zoom level */
497     gui_font_name = font_zoom(prefs.PREFS_GUI_FONT_NAME);
498     if (gui_font_name == NULL) {
499         /*
500          * This means the font name isn't an XLFD font name.
501          * We just report that for now as a font not available in
502          * multiple sizes.
503          */
504         simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK,
505             "Your current font isn't available in any other sizes.\n");
506         return FA_FONT_NOT_RESIZEABLE;
507     }
508
509     /* load normal and bold font */
510 #if GTK_MAJOR_VERSION < 2
511     new_r_font = gdk_font_load(gui_font_name);
512     bold_font_name = user_font_boldify(gui_font_name);
513     new_b_font = gdk_font_load(bold_font_name);
514 #else
515     new_r_font = pango_font_description_from_string(gui_font_name);
516     new_b_font = pango_font_description_copy(new_r_font);
517     pango_font_description_set_weight(new_b_font, PANGO_WEIGHT_BOLD);
518 #endif
519
520     if (new_r_font == NULL || new_b_font == NULL) {
521         /* We're no longer using the new fonts; unreference them. */
522 #if GTK_MAJOR_VERSION < 2
523         if (new_r_font != NULL)
524             gdk_font_unref(new_r_font);
525         if (new_b_font != NULL)
526             gdk_font_unref(new_b_font);
527 #else
528         if (new_r_font != NULL)
529             pango_font_description_free(new_r_font);
530         if (new_b_font != NULL)
531             pango_font_description_free(new_b_font);
532 #endif
533         g_free(gui_font_name);
534
535         /* We let our caller pop up a dialog box, as the error message
536            depends on the context (did they zoom in or out, or did they
537            do something else? */
538         return FA_FONT_NOT_AVAILABLE;
539     }
540
541     /* the font(s) seem to be ok */
542     set_plist_font(new_r_font);
543     set_ptree_font_all(new_r_font);
544     old_r_font = m_r_font;
545     old_b_font = m_b_font;
546     set_fonts(new_r_font, new_b_font);
547 #if GTK_MAJOR_VERSION < 2
548     g_free(bold_font_name);
549 #endif
550
551     /* Redraw the hex dump windows. */
552     redraw_hex_dump_all();
553
554     /* Redraw the "Follow TCP Stream" windows. */
555     follow_redraw_all();
556
557     /* We're no longer using the old fonts; unreference them. */
558 #if GTK_MAJOR_VERSION < 2
559     if (old_r_font != NULL)
560         gdk_font_unref(old_r_font);
561     if (old_b_font != NULL)
562         gdk_font_unref(old_b_font);
563 #else
564     if (old_r_font != NULL)
565         pango_font_description_free(old_r_font);
566     if (old_b_font != NULL)
567         pango_font_description_free(old_b_font);
568 #endif
569     g_free(gui_font_name);
570
571     return FA_SUCCESS;
572 }
573
574
575 #ifdef _WIN32
576
577 #define NAME_BUFFER_LEN 32
578
579 #if GTK_MAJOR_VERSION < 2
580
581
582 /* The setting of the MS default font for system stuff (menus, dialogs, ...),
583  * coming from: Allin Cottrell, http://www.ecn.wfu.edu/~cottrell/gtk_win32,
584  * Thank you very much for this! */
585 static int get_windows_font_gtk1(char *fontspec, int fontspec_len)
586 {
587     HDC h_dc;
588     HGDIOBJ h_font;
589     TEXTMETRIC tm;
590     char name[NAME_BUFFER_LEN];
591     int len, pix_height;
592
593     h_dc = CreateDC("DISPLAY", NULL, NULL, NULL);
594     if (h_dc == NULL) return 1;
595     h_font = GetStockObject(DEFAULT_GUI_FONT);
596     if (h_font == NULL || !SelectObject(h_dc, h_font)) {
597         DeleteDC(h_dc);
598         return 1;
599     }
600     len = GetTextFace(h_dc, NAME_BUFFER_LEN, name);
601     if (len <= 0) {
602         DeleteDC(h_dc);
603         return 1;
604     }
605     if (!GetTextMetrics(h_dc, &tm)) {
606         DeleteDC(h_dc);
607         return 1;
608     }
609     pix_height = tm.tmHeight;
610     DeleteDC(h_dc);
611     g_snprintf(fontspec, fontspec_len, "-*-%s-*-*-*-*-%i-*-*-*-p-*-iso8859-1", name,
612             pix_height);
613     return 0;
614 }
615
616 void app_font_gtk1_init(GtkWidget *top_level_w)
617 {
618     GtkStyle *style;
619     char winfont[80];
620  
621     style = gtk_widget_get_style(top_level_w);
622     if (get_windows_font_gtk1(winfont, sizeof(winfont)) == 0)
623         style->font = gdk_font_load(winfont);
624     if (style->font) gtk_widget_set_style(top_level_w, style);
625 }
626
627
628 #else /* GTK_MAJOR_VERSION */
629 static char appfontname[128] = "tahoma 8";
630
631 static void
632 set_app_font_gtk2(const char *fontname)
633 {
634     GtkSettings *settings;
635
636     if (fontname != NULL && *fontname == 0) return;
637
638     settings = gtk_settings_get_default();
639
640     if (fontname == NULL) {
641         g_object_set(G_OBJECT(settings), "gtk-font-name", appfontname, NULL);
642     } else {
643         GtkWidget *w;
644         PangoFontDescription *pfd;
645         PangoContext *pc;
646         PangoFont *pfont;
647
648         w = gtk_label_new(NULL);
649         pfd = pango_font_description_from_string(fontname);
650         pc = gtk_widget_get_pango_context(w);
651         pfont = pango_context_load_font(pc, pfd);
652
653         if (pfont != NULL) {
654             strcpy(appfontname, fontname);
655             g_object_set(G_OBJECT(settings), "gtk-font-name", appfontname, NULL);
656         }
657
658         gtk_widget_destroy(w);
659         pango_font_description_free(pfd);
660     }
661 }
662
663 static char *default_windows_menu_fontspec_gtk2(void)
664 {
665     gchar *fontspec = NULL;
666     NONCLIENTMETRICS ncm;
667
668     memset(&ncm, 0, sizeof ncm);
669     ncm.cbSize = sizeof ncm;
670
671     if (SystemParametersInfo(SPI_GETNONCLIENTMETRICS, ncm.cbSize, &ncm, 0)) {
672         HDC screen = GetDC(0);
673         double y_scale = 72.0 / GetDeviceCaps(screen, LOGPIXELSY);
674         int point_size = (int) (ncm.lfMenuFont.lfHeight * y_scale);
675
676         if (point_size < 0) point_size = -point_size;
677         fontspec = g_strdup_printf("%s %d", ncm.lfMenuFont.lfFaceName,
678                                    point_size);
679         ReleaseDC(0, screen);
680     }
681
682     return fontspec;
683 }
684
685 static void try_to_get_windows_font_gtk2(void)
686 {
687     gchar *fontspec;
688
689     fontspec = default_windows_menu_fontspec_gtk2();
690
691     if (fontspec != NULL) {
692         int match = 0;
693         PangoFontDescription *pfd;
694         PangoFont *pfont;
695         PangoContext *pc;
696         GtkWidget *w;
697
698         pfd = pango_font_description_from_string(fontspec);
699
700         w = gtk_label_new(NULL);
701         pc = gtk_widget_get_pango_context(w);
702         pfont = pango_context_load_font(pc, pfd);
703         match = (pfont != NULL);
704
705         pango_font_description_free(pfd);
706         g_object_unref(G_OBJECT(pc));
707         gtk_widget_destroy(w);
708
709         if (match) set_app_font_gtk2(fontspec);
710         g_free(fontspec);
711     }
712 }
713 #endif /* GTK_MAJOR_VERSION */
714
715 #endif /* _WIN32 */
716
717
718 void font_init(void)
719 {
720 #if GTK_MAJOR_VERSION < 2
721   gchar *bold_font_name;
722 #endif
723
724 #ifdef _WIN32
725 #if GTK_MAJOR_VERSION >= 2
726   /* try to load the application font for GTK2 */
727   try_to_get_windows_font_gtk2();
728 #endif
729 #endif
730     
731   /* Try to load the regular and boldface fixed-width fonts */
732 #if GTK_MAJOR_VERSION < 2
733   bold_font_name = user_font_boldify(prefs.gui_font_name1);
734   m_r_font = gdk_font_load(prefs.gui_font_name1);
735   m_b_font = gdk_font_load(bold_font_name);
736   if (m_r_font == NULL || m_b_font == NULL) {
737     /* XXX - pop this up as a dialog box? no */
738     if (m_r_font == NULL) {
739 #ifdef HAVE_LIBPCAP
740       if (!capture_child)
741 #endif
742         fprintf(stderr, "ethereal: Warning: font %s not found - defaulting to 6x13 and 6x13bold\n",
743                 prefs.gui_font_name1);
744     } else {
745       gdk_font_unref(m_r_font);
746     }
747     if (m_b_font == NULL) {
748 #ifdef HAVE_LIBPCAP
749       if (!capture_child)
750 #endif
751         fprintf(stderr, "ethereal: Warning: font %s not found - defaulting to 6x13 and 6x13bold\n",
752                 bold_font_name);
753     } else {
754       gdk_font_unref(m_b_font);
755     }
756     g_free(bold_font_name);
757     if ((m_r_font = gdk_font_load("6x13")) == NULL) {
758       fprintf(stderr, "ethereal: Error: font 6x13 not found\n");
759       exit(1);
760     }
761     if ((m_b_font = gdk_font_load("6x13bold")) == NULL) {
762       fprintf(stderr, "ethereal: Error: font 6x13bold not found\n");
763       exit(1);
764     }
765     g_free(prefs.gui_font_name1);
766     prefs.gui_font_name1 = g_strdup("6x13");
767   }
768 #else /* GTK_MAJOR_VERSION */
769   m_r_font = pango_font_description_from_string(prefs.gui_font_name2);
770   m_b_font = pango_font_description_copy(m_r_font);
771   pango_font_description_set_weight(m_b_font, PANGO_WEIGHT_BOLD);
772   if (m_r_font == NULL || m_b_font == NULL) {
773     /* XXX - pop this up as a dialog box? no */
774     if (m_r_font == NULL) {
775 #ifdef HAVE_LIBPCAP
776       if (!capture_child)
777 #endif
778         fprintf(stderr, "ethereal: Warning: font %s not found - defaulting to Monospace 9\n",
779                 prefs.gui_font_name2);
780     } else {
781       pango_font_description_free(m_r_font);
782     }
783     if (m_b_font == NULL) {
784 #ifdef HAVE_LIBPCAP
785       if (!capture_child)
786 #endif
787         fprintf(stderr, "ethereal: Warning: bold font %s not found - defaulting"
788                         " to Monospace 9\n", prefs.gui_font_name2);
789     } else {
790       pango_font_description_free(m_b_font);
791     }
792     if ((m_r_font = pango_font_description_from_string("Monospace 9")) == NULL)
793     {
794       fprintf(stderr, "ethereal: Error: font Monospace 9 not found\n");
795       exit(1);
796     }
797     if ((m_b_font = pango_font_description_copy(m_r_font)) == NULL) {
798       fprintf(stderr, "ethereal: Error: font Monospace 9 bold not found\n");
799       exit(1);
800     }
801     g_free(prefs.gui_font_name2);
802     pango_font_description_set_weight(m_b_font, PANGO_WEIGHT_BOLD);
803     prefs.gui_font_name2 = g_strdup("Monospace 9");
804   }
805 #endif /* GTK_MAJOR_VERSION */
806
807   /* Call this for the side-effects that set_fonts() produces */
808   set_fonts(m_r_font, m_b_font);
809 }