3094
+ − 1 /* Font handling code for X and Xft.
+ − 2
+ − 3 Copyright (C) 2003 Eric Knauel
+ − 4 Copyright (C) 2004 Free Software Foundation, Inc.
+ − 5
+ − 6 Author: Stephen J. Turnbull <stephen@xemacs.org>
+ − 7 Created: 24 Jul 2004 by Stephen J. Turnbull
+ − 8
+ − 9 This file is part of XEmacs.
+ − 10
+ − 11 XEmacs is free software; you can redistribute it and/or modify it
+ − 12 under the terms of the GNU General Public License as published by the
+ − 13 Free Software Foundation; either version 2, or (at your option) any
+ − 14 later version.
+ − 15
+ − 16 XEmacs is distributed in the hope that it will be useful, but WITHOUT
+ − 17 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ − 18 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ − 19 for more details.
+ − 20
+ − 21 You should have received a copy of the GNU General Public License
+ − 22 along with XEmacs; see the file COPYING. If not, write to
+ − 23 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ − 24 Boston, MA 02111-1307, USA. */
+ − 25
+ − 26 /* Synched up with: Not in GNU Emacs. */
+ − 27
+ − 28 #include <config.h>
+ − 29 #include <stdio.h>
+ − 30 #include <stdlib.h>
+ − 31 #include "lwlib-fonts.h"
+ − 32
+ − 33 #if 0
+ − 34 /* these are all from ../src; if we need them move the code */
+ − 35 #include "lisp.h"
+ − 36 #include "device.h"
+ − 37 #include "device-impl.h"
+ − 38 #include "console-x-impl.h"
3360
+ − 39 #ifdef HAVE_FONTCONFIG
3354
+ − 40 #include "font-mgr.h"
3094
+ − 41 #endif
3360
+ − 42 #endif
3094
+ − 43
+ − 44 /*
+ − 45 * code for handling Xft
+ − 46 */
+ − 47
+ − 48 #ifdef USE_XFT
+ − 49
+ − 50 /* helper function to correctly open Xft/core fonts by name
+ − 51 #### Can't we use FcParseName here?
+ − 52 #### Is this done so often that the logic needs to be hard-coded in C?
+ − 53
+ − 54 Daniel Pittman sez: Older code tried to enforce that an XLFD font was
+ − 55 not scaled, while this version just doesn't care. I think that is a
+ − 56 better behavior, since if someone really wants a scaled font we should
+ − 57 oblige them.
+ − 58
+ − 59 Stephen sez: This whole function was ill-conceived, and I'm not sure it
+ − 60 succeeds at any of the things it attempts to do. First, we should be
+ − 61 using fontconfig directly. I'm not sure what Xft (or fontconfig) will
+ − 62 try to do if passed an XLFD. As for scaled fonts, both options are
+ − 63 equally bad. The problem is that the X server will often scale bitmap
+ − 64 fonts willy-nilly; it's worth trying to avoid that, but I can't say
+ − 65 whether that's worth overriding somebody who knows what they're doing.
+ − 66 In any case, I think we should find out what Xft (fontconfig?) is able
+ − 67 and willing to do with XLFDs, and probably move the logic to LISP.
+ − 68 */
+ − 69 XftFont *
+ − 70 xft_open_font_by_name (Display *dpy, char *name)
+ − 71 {
+ − 72 XftFont *res = NULL;
+ − 73
+ − 74 /* if (!NILP (Fxft_xlfd_font_name_p (make_string (name, strlen (name))))) */
+ − 75 /* #### this is bogus but ... */
+ − 76 int count = 0;
+ − 77 char *pos = name;
+ − 78 /* extra parens shut up gcc */
+ − 79 while ((pos = index (pos, '-')))
+ − 80 {
+ − 81 count++;
+ − 82 pos++;
+ − 83 }
+ − 84
+ − 85 /* #### hard-coding DefaultScreen is evil! */
+ − 86 if (count == 14 /* fully-qualified XLFD */
+ − 87 || (count < 14 /* heuristic for wildcarded XLFD */
+ − 88 && count >= 5
+ − 89 && index (name, '*')))
+ − 90 res = XftFontOpenXlfd (dpy, DefaultScreen (dpy), name);
+ − 91 else
+ − 92 res = XftFontOpenName (dpy, DefaultScreen (dpy), name);
+ − 93
+ − 94 /* Try for a generic monospace font
+ − 95 #### Why? Menus don't need to line up in columns! */
+ − 96 if (!res)
+ − 97 res = XftFontOpenName (dpy, DefaultScreen (dpy), "monospace");
+ − 98 /* Try for anything we can get */
+ − 99 if (!res)
+ − 100 res = XftFontOpenName (dpy, DefaultScreen (dpy), "");
+ − 101
+ − 102 if (!res)
+ − 103 {
+ − 104 /* #### This is Just So Wrong ... ! */
+ − 105 /* sorry folks ... */
+ − 106 fprintf (stderr,
+ − 107 "Unable to find any usable XFT font, even the defaults!\n");
+ − 108 abort ();
+ − 109 return 0;
+ − 110 }
+ − 111
+ − 112 return res;
+ − 113 }
+ − 114
+ − 115 #endif /* USE_XFT */
+ − 116
+ − 117 /* End of lwlib-fonts.c */