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