annotate lwlib/lwlib-fonts.c @ 3140:160945bb6c26

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