annotate src/xfont.c @ 90400:80fff33f74f5

New file.
author Kenichi Handa <handa@m17n.org>
date Tue, 06 Jun 2006 03:47:13 +0000
parents
children 5976e428d68e
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
90400
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1 /* xfont.c -- X core font driver.
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2 Copyright (C) 2006 Free Software Foundation, Inc.
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
3 Copyright (C) 2006
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
4 National Institute of Advanced Industrial Science and Technology (AIST)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
5 Registration Number H13PRO009
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
6
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
7 This file is part of GNU Emacs.
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
8
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
9 GNU Emacs is free software; you can redistribute it and/or modify
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
10 it under the terms of the GNU General Public License as published by
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
11 the Free Software Foundation; either version 2, or (at your option)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
12 any later version.
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
13
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
14 GNU Emacs is distributed in the hope that it will be useful,
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
17 GNU General Public License for more details.
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
18
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
19 You should have received a copy of the GNU General Public License
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
20 along with GNU Emacs; see the file COPYING. If not, write to
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
21 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
22 Boston, MA 02110-1301, USA. */
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
23
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
24 #include <config.h>
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
25 #include <stdio.h>
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
26 #include <X11/Xlib.h>
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
27
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
28 #include "lisp.h"
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
29 #include "dispextern.h"
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
30 #include "xterm.h"
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
31 #include "frame.h"
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
32 #include "blockinput.h"
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
33 #include "character.h"
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
34 #include "charset.h"
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
35 #include "fontset.h"
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
36 #include "font.h"
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
37
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
38
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
39 /* X core font driver. */
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
40
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
41 Lisp_Object Qx;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
42
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
43 /* Alist of font registry symbol and the corresponding charsets
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
44 information. The information is retrieved from
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
45 Vfont_encoding_alist on demand.
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
46
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
47 Eash element has the form:
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
48 (REGISTRY . (ENCODING-CHARSET-ID . REPERTORY-CHARSET-ID))
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
49 or
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
50 (REGISTRY . nil)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
51
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
52 In the former form, ENCODING-CHARSET-ID is an ID of a charset that
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
53 encodes a character code to a glyph code of a font, and
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
54 REPERTORY-CHARSET-ID is an ID of a charset that tells if a
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
55 character is supported by a font.
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
56
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
57 The latter form means that the information for REGISTRY couldn't be
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
58 retrieved. */
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
59 static Lisp_Object x_font_charset_alist;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
60
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
61 /* Prototypes of support functions. */
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
62 extern void x_clear_errors P_ ((Display *));
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
63
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
64 static char *xfont_query_font P_ ((Display *, char *, Lisp_Object));
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
65 static XCharStruct *xfont_get_pcm P_ ((XFontStruct *, XChar2b *));
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
66 static int xfont_registry_charsets P_ ((Lisp_Object, struct charset **,
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
67 struct charset **));
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
68
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
69 static char *
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
70 xfont_query_font (display, name, spec)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
71 Display *display;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
72 char *name;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
73 Lisp_Object spec;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
74 {
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
75 XFontStruct *font;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
76
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
77 BLOCK_INPUT;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
78 x_catch_errors (display);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
79 font = XLoadQueryFont (display, name);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
80 name = NULL;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
81 if (x_had_errors_p (display))
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
82 {
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
83 /* This error is perhaps due to insufficient memory on X
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
84 server. Let's just ignore it. */
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
85 x_clear_errors (display);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
86 }
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
87 else if (font)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
88 {
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
89 unsigned long value;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
90
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
91 if (XGetFontProperty (font, XA_FONT, &value))
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
92 {
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
93 char *n = (char *) XGetAtomName (display, (Atom) value);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
94
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
95 if (font_parse_xlfd (n, spec, 0) >= 0)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
96 name = n;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
97 else
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
98 XFree (n);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
99 }
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
100 XFreeFont (display, font);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
101 }
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
102 x_uncatch_errors ();
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
103 UNBLOCK_INPUT;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
104
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
105 return name;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
106 }
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
107
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
108
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
109 /* Get metrics of character CHAR2B in XFONT. Value is null if CHAR2B
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
110 is not contained in the font. */
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
111
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
112 static XCharStruct *
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
113 xfont_get_pcm (xfont, char2b)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
114 XFontStruct *xfont;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
115 XChar2b *char2b;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
116 {
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
117 /* The result metric information. */
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
118 XCharStruct *pcm = NULL;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
119
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
120 xassert (xfont && char2b);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
121
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
122 if (xfont->per_char != NULL)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
123 {
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
124 if (xfont->min_byte1 == 0 && xfont->max_byte1 == 0)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
125 {
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
126 /* min_char_or_byte2 specifies the linear character index
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
127 corresponding to the first element of the per_char array,
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
128 max_char_or_byte2 is the index of the last character. A
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
129 character with non-zero CHAR2B->byte1 is not in the font.
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
130 A character with byte2 less than min_char_or_byte2 or
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
131 greater max_char_or_byte2 is not in the font. */
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
132 if (char2b->byte1 == 0
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
133 && char2b->byte2 >= xfont->min_char_or_byte2
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
134 && char2b->byte2 <= xfont->max_char_or_byte2)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
135 pcm = xfont->per_char + char2b->byte2 - xfont->min_char_or_byte2;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
136 }
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
137 else
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
138 {
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
139 /* If either min_byte1 or max_byte1 are nonzero, both
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
140 min_char_or_byte2 and max_char_or_byte2 are less than
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
141 256, and the 2-byte character index values corresponding
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
142 to the per_char array element N (counting from 0) are:
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
143
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
144 byte1 = N/D + min_byte1
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
145 byte2 = N\D + min_char_or_byte2
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
146
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
147 where:
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
148
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
149 D = max_char_or_byte2 - min_char_or_byte2 + 1
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
150 / = integer division
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
151 \ = integer modulus */
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
152 if (char2b->byte1 >= xfont->min_byte1
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
153 && char2b->byte1 <= xfont->max_byte1
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
154 && char2b->byte2 >= xfont->min_char_or_byte2
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
155 && char2b->byte2 <= xfont->max_char_or_byte2)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
156 pcm = (xfont->per_char
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
157 + ((xfont->max_char_or_byte2 - xfont->min_char_or_byte2 + 1)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
158 * (char2b->byte1 - xfont->min_byte1))
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
159 + (char2b->byte2 - xfont->min_char_or_byte2));
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
160 }
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
161 }
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
162 else
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
163 {
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
164 /* If the per_char pointer is null, all glyphs between the first
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
165 and last character indexes inclusive have the same
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
166 information, as given by both min_bounds and max_bounds. */
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
167 if (char2b->byte2 >= xfont->min_char_or_byte2
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
168 && char2b->byte2 <= xfont->max_char_or_byte2)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
169 pcm = &xfont->max_bounds;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
170 }
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
171
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
172 return ((pcm == NULL
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
173 || (pcm->width == 0 && (pcm->rbearing - pcm->lbearing) == 0))
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
174 ? NULL : pcm);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
175 }
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
176
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
177 extern Lisp_Object find_font_encoding P_ ((Lisp_Object));
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
178
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
179 /* Return encoding charset and repertory charset for REGISTRY in
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
180 ENCODING and REPERTORY correspondingly. If correct information for
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
181 REGISTRY is available, return 0. Otherwise return -1. */
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
182
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
183 static int
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
184 xfont_registry_charsets (registry, encoding, repertory)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
185 Lisp_Object registry;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
186 struct charset **encoding, **repertory;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
187 {
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
188 Lisp_Object val;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
189 int encoding_id, repertory_id;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
190
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
191 val = assq_no_quit (registry, x_font_charset_alist);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
192 if (! NILP (val))
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
193 {
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
194 val = XCDR (val);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
195 if (NILP (val))
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
196 return -1;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
197 encoding_id = XINT (XCAR (val));
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
198 repertory_id = XINT (XCDR (val));
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
199 }
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
200 else
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
201 {
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
202 val = find_font_encoding (SYMBOL_NAME (registry));
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
203 if (SYMBOLP (val) && CHARSETP (val))
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
204 {
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
205 encoding_id = repertory_id = XINT (CHARSET_SYMBOL_ID (val));
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
206 }
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
207 else if (CONSP (val))
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
208 {
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
209 if (! CHARSETP (XCAR (val)))
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
210 goto invalid_entry;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
211 encoding_id = XINT (CHARSET_SYMBOL_ID (XCAR (val)));
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
212 if (NILP (XCDR (val)))
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
213 repertory_id = -1;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
214 else
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
215 {
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
216 if (! CHARSETP (XCDR (val)))
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
217 goto invalid_entry;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
218 repertory_id = XINT (CHARSET_SYMBOL_ID (XCDR (val)));
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
219 }
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
220 }
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
221 else
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
222 goto invalid_entry;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
223 val = Fcons (make_number (encoding_id), make_number (repertory_id));
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
224 x_font_charset_alist
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
225 = nconc2 (x_font_charset_alist, Fcons (Fcons (registry, val), Qnil));
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
226 }
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
227
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
228 if (encoding)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
229 *encoding = CHARSET_FROM_ID (encoding_id);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
230 if (repertory)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
231 *repertory = repertory_id >= 0 ? CHARSET_FROM_ID (repertory_id) : NULL;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
232 return 0;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
233
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
234 invalid_entry:
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
235 x_font_charset_alist
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
236 = nconc2 (x_font_charset_alist, Fcons (Fcons (registry, Qnil), Qnil));
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
237 return -1;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
238 }
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
239
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
240 static Lisp_Object xfont_get_cache P_ ((Lisp_Object));
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
241 static int xfont_parse_name P_ ((FRAME_PTR, char *, Lisp_Object));
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
242 static Lisp_Object xfont_list P_ ((Lisp_Object, Lisp_Object));
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
243 static Lisp_Object xfont_list_family P_ ((Lisp_Object));
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
244 static struct font *xfont_open P_ ((FRAME_PTR, Lisp_Object, int));
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
245 static void xfont_close P_ ((FRAME_PTR, struct font *));
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
246 static int xfont_prepare_face P_ ((FRAME_PTR, struct face *));
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
247 #if 0
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
248 static void xfont_done_face P_ ((FRAME_PTR, struct face *));
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
249 #endif
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
250 static int xfont_has_char P_ ((Lisp_Object, int));
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
251 static unsigned xfont_encode_char P_ ((struct font *, int));
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
252 static int xfont_text_extents P_ ((struct font *, unsigned *, int,
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
253 struct font_metrics *));
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
254 static int xfont_draw P_ ((struct glyph_string *, int, int, int, int, int));
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
255
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
256 struct font_driver xfont_driver =
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
257 {
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
258 (Lisp_Object) NULL, /* Qx */
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
259 xfont_get_cache,
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
260 xfont_parse_name,
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
261 xfont_list,
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
262 xfont_list_family,
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
263 NULL,
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
264 xfont_open,
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
265 xfont_close,
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
266 xfont_prepare_face,
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
267 NULL /*xfont_done_face*/,
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
268 xfont_has_char,
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
269 xfont_encode_char,
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
270 xfont_text_extents,
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
271 xfont_draw,
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
272 };
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
273
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
274 extern Lisp_Object QCname;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
275
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
276 static Lisp_Object
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
277 xfont_get_cache (frame)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
278 Lisp_Object frame;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
279 {
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
280 Display_Info *dpyinfo = FRAME_X_DISPLAY_INFO (XFRAME (frame));
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
281
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
282 return (dpyinfo->name_list_element);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
283 }
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
284
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
285 static int
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
286 xfont_parse_name (f, name, spec)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
287 FRAME_PTR f;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
288 char *name;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
289 Lisp_Object spec;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
290 {
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
291 if (font_parse_xlfd (name, spec, 0) >= 0)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
292 return 0;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
293 name = xfont_query_font (FRAME_X_DISPLAY (f), name, spec);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
294 if (name)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
295 {
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
296 XFree (name);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
297 return 0;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
298 }
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
299 return -1;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
300 }
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
301
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
302 extern Lisp_Object Vface_alternative_font_registry_alist;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
303
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
304 static Lisp_Object
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
305 xfont_list (frame, spec)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
306 Lisp_Object frame, spec;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
307 {
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
308 FRAME_PTR f = XFRAME (frame);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
309 Display_Info *dpyinfo = FRAME_X_DISPLAY_INFO (f);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
310 Lisp_Object *vec, val, extra, font_name, entity;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
311 char name[256], **names;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
312 int i, idx, limit, num_fonts;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
313 int error_occurred = 0;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
314 USE_SAFE_ALLOCA;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
315
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
316 extra = AREF (spec, FONT_EXTRA_INDEX);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
317 font_name = Qnil;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
318 if (CONSP (extra))
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
319 {
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
320 val = Fassq (QCotf, extra);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
321 if (! NILP (val))
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
322 return null_vector;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
323 val = Fassq (QCname, extra);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
324 if (CONSP (val))
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
325 font_name = XCDR (val);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
326 }
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
327
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
328 if (! STRINGP (font_name)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
329 && font_unparse_xlfd (spec, 0, name, 256) < 0)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
330 return null_vector;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
331
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
332 BLOCK_INPUT;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
333 x_catch_errors (dpyinfo->display);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
334
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
335 if (STRINGP (font_name))
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
336 {
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
337 XFontStruct *font = XLoadQueryFont (dpyinfo->display,
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
338 (char *) SDATA (font_name));
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
339 unsigned long value;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
340
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
341 num_fonts = 0;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
342 if (x_had_errors_p (dpyinfo->display))
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
343 {
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
344 /* This error is perhaps due to insufficient memory on X
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
345 server. Let's just ignore it. */
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
346 font = NULL;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
347 error_occurred = 1;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
348 x_clear_errors (dpyinfo->display);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
349 }
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
350 if (font)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
351 {
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
352 if (XGetFontProperty (font, XA_FONT, &value))
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
353 {
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
354 char *n = (char *) XGetAtomName (dpyinfo->display, (Atom) value);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
355 int len = strlen (n);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
356 char *tmp;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
357
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
358 /* If DXPC (a Differential X Protocol Compressor)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
359 Ver.3.7 is running, XGetAtomName will return null
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
360 string. We must avoid such a name. */
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
361 if (len > 0)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
362 {
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
363 num_fonts = 1;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
364 names = (char **) alloca (sizeof (char *));
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
365 /* Some systems only allow alloca assigned to a
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
366 simple var. */
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
367 tmp = (char *) alloca (len + 1); names[0] = tmp;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
368 bcopy (n, names[0], len + 1);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
369 }
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
370 XFree (n);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
371 }
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
372 XFreeFont (dpyinfo->display, font);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
373 }
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
374 }
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
375 else
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
376 {
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
377 Lisp_Object registry = AREF (spec, FONT_REGISTRY_INDEX);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
378 Lisp_Object alter = Qnil;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
379 char *r = NULL;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
380
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
381 if (! NILP (registry))
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
382 alter = Fassoc_string (SYMBOL_NAME (registry),
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
383 Vface_alternative_font_registry_alist);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
384 while (1)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
385 {
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
386 for (limit = 512, num_fonts = 0; ; limit *= 2)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
387 {
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
388 names = XListFonts (dpyinfo->display, name, limit, &num_fonts);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
389 if (x_had_errors_p (dpyinfo->display))
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
390 {
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
391 /* This error is perhaps due to insufficient memory
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
392 on X server. Let's just ignore it. */
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
393 x_clear_errors (dpyinfo->display);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
394 error_occurred = 1;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
395 num_fonts = 0;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
396 break;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
397 }
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
398 if (num_fonts < limit)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
399 break;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
400 XFreeFontNames (names);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
401 }
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
402 if (num_fonts > 0
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
403 || NILP (alter))
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
404 break;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
405
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
406 /* Setup for trying alternatives. */
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
407 if (! r
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
408 && ! (r = strstr (name, (char *) SDATA (SYMBOL_NAME (registry)))))
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
409 abort ();
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
410 while (1)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
411 {
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
412 registry = Qnil;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
413 alter = XCDR (alter);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
414 if (NILP (alter))
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
415 break;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
416 registry = XCAR (alter);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
417 if ((r - name) + SBYTES (registry) < 255)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
418 break;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
419 }
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
420 if (NILP (registry))
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
421 break;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
422 bcopy (SDATA (registry), r, SBYTES (registry));
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
423 }
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
424 }
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
425
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
426 x_uncatch_errors ();
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
427 UNBLOCK_INPUT;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
428
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
429 if (error_occurred)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
430 return Qnil;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
431 if (num_fonts == 0)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
432 return null_vector;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
433
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
434 entity = Fmake_vector (make_number (FONT_ENTITY_MAX), Qnil);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
435 ASET (entity, FONT_TYPE_INDEX, Qx);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
436 ASET (entity, FONT_FRAME_INDEX, frame);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
437
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
438 SAFE_ALLOCA_LISP (vec, num_fonts);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
439 for (i = idx = 0; i < num_fonts; i++)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
440 {
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
441 if (font_parse_xlfd (names[i], entity, 0) > 0)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
442 vec[idx++] = Fcopy_sequence (entity);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
443 }
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
444 if (! STRINGP (font_name))
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
445 {
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
446 BLOCK_INPUT;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
447 XFreeFontNames (names);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
448 UNBLOCK_INPUT;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
449 }
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
450 val = Fvector (idx, vec);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
451 SAFE_FREE ();
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
452
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
453 return val;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
454 }
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
455
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
456 static int
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
457 memq_no_quit (elt, list)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
458 Lisp_Object elt, list;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
459 {
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
460 while (CONSP (list) && ! EQ (XCAR (list), elt))
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
461 list = XCDR (list);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
462 return (CONSP (list));
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
463 }
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
464
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
465 static Lisp_Object
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
466 xfont_list_family (frame)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
467 {
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
468 FRAME_PTR f = XFRAME (frame);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
469 Display_Info *dpyinfo = FRAME_X_DISPLAY_INFO (f);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
470 char **names;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
471 int num_fonts, i;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
472 Lisp_Object list;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
473 char *last_family;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
474 int last_len;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
475
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
476 BLOCK_INPUT;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
477 x_catch_errors (dpyinfo->display);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
478 names = XListFonts (dpyinfo->display, "-*-*-*-*-*-*-*-*-*-*-*-*-*-*",
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
479 0x8000, &num_fonts);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
480 if (x_had_errors_p (dpyinfo->display))
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
481 {
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
482 /* This error is perhaps due to insufficient memory on X server.
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
483 Let's just ignore it. */
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
484 x_clear_errors (dpyinfo->display);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
485 num_fonts = 0;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
486 }
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
487
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
488 list = Qnil;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
489 for (i = 0, last_len = 0; i < num_fonts; i++)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
490 {
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
491 char *p0 = names[i], *p1;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
492 Lisp_Object family;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
493
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
494 p0++; /* skip the leading '-' */
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
495 while (*p0 && *p0 != '-') p0++; /* skip foundry */
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
496 if (! *p0)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
497 continue;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
498 p1 = ++p0;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
499 while (*p1 && *p1 != '-') p1++; /* find the end of family */
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
500 if (! *p1 || p1 == p0)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
501 continue;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
502 if (last_len == p1 - p0
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
503 && bcmp (last_family, p0, last_len) == 0)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
504 continue;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
505 last_len = p1 - p0;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
506 last_family = p0;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
507 family = intern_downcase (p0, last_len);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
508 if (! memq_no_quit (family, list))
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
509 list = Fcons (family, list);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
510 }
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
511
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
512 XFreeFontNames (names);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
513 x_uncatch_errors ();
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
514 UNBLOCK_INPUT;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
515
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
516 return list;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
517 }
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
518
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
519 static struct font *
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
520 xfont_open (f, entity, pixel_size)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
521 FRAME_PTR f;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
522 Lisp_Object entity;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
523 int pixel_size;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
524 {
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
525 Display_Info *dpyinfo = FRAME_X_DISPLAY_INFO (f);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
526 Display *display = dpyinfo->display;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
527 char name[256];
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
528 int len;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
529 unsigned long value;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
530 Lisp_Object registry;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
531 struct charset *encoding, *repertory;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
532 struct font *font;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
533 XFontStruct *xfont;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
534
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
535 /* At first, check if we know how to encode characters for this
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
536 font. */
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
537 registry = AREF (entity, FONT_REGISTRY_INDEX);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
538 if (xfont_registry_charsets (registry, &encoding, &repertory) < 0)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
539 return NULL;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
540
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
541 if (XINT (AREF (entity, FONT_SIZE_INDEX)) != 0)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
542 pixel_size = XINT (AREF (entity, FONT_SIZE_INDEX));
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
543 len = font_unparse_xlfd (entity, pixel_size, name, 256);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
544 if (len <= 0)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
545 return NULL;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
546
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
547 BLOCK_INPUT;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
548 x_catch_errors (display);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
549 xfont = XLoadQueryFont (display, name);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
550 if (x_had_errors_p (display))
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
551 {
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
552 /* This error is perhaps due to insufficient memory on X server.
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
553 Let's just ignore it. */
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
554 x_clear_errors (display);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
555 xfont = NULL;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
556 }
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
557 x_uncatch_errors ();
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
558 UNBLOCK_INPUT;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
559
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
560 if (! xfont)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
561 return NULL;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
562 font = malloc (sizeof (struct font));
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
563 font->font.font = xfont;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
564 font->entity = entity;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
565 font->pixel_size = pixel_size;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
566 font->driver = &xfont_driver;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
567 font->font.name = malloc (len + 1);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
568 if (! font->font.name)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
569 {
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
570 XFreeFont (display, xfont);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
571 free (font);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
572 return NULL;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
573 }
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
574 bcopy (name, font->font.name, len + 1);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
575 font->font.charset = encoding->id;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
576 font->encoding_charset = encoding->id;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
577 font->repertory_charet = repertory ? repertory->id : -1;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
578 font->ascent = xfont->ascent;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
579 font->descent = xfont->descent;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
580
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
581 if (xfont->min_bounds.width == xfont->max_bounds.width)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
582 {
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
583 /* Fixed width font. */
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
584 font->font.average_width = font->font.space_width
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
585 = xfont->min_bounds.width;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
586 }
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
587 else
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
588 {
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
589 XChar2b char2b;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
590 XCharStruct *pcm;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
591
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
592 char2b.byte1 = 0x00, char2b.byte2 = 0x20;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
593 pcm = xfont_get_pcm (xfont, &char2b);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
594 if (pcm)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
595 font->font.space_width = pcm->width;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
596 else
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
597 font->font.space_width = xfont->max_bounds.width;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
598
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
599 font->font.average_width
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
600 = (XGetFontProperty (xfont, dpyinfo->Xatom_AVERAGE_WIDTH, &value)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
601 ? (long) value / 10 : 0);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
602 if (font->font.average_width < 0)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
603 font->font.average_width = - font->font.average_width;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
604 if (font->font.average_width == 0)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
605 {
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
606 if (pcm)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
607 {
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
608 int width = pcm->width;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
609 for (char2b.byte2 = 33; char2b.byte2 <= 126; char2b.byte2++)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
610 if ((pcm = xfont_get_pcm (xfont, &char2b)) != NULL)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
611 width += pcm->width;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
612 font->font.average_width = width / 95;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
613 }
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
614 else
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
615 font->font.average_width = xfont->max_bounds.width;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
616 }
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
617 }
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
618 font->min_width = xfont->min_bounds.width;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
619 if (font->min_width <= 0)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
620 font->min_width = font->font.space_width;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
621
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
622 BLOCK_INPUT;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
623 /* Try to get the full name of FONT. Put it in FULL_NAME. */
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
624 if (XGetFontProperty (xfont, XA_FONT, &value))
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
625 {
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
626 char *full_name = NULL, *p0, *p;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
627 int dashes = 0;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
628
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
629 p0 = p = (char *) XGetAtomName (FRAME_X_DISPLAY (f), (Atom) value);;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
630 /* Count the number of dashes in the "full name".
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
631 If it is too few, this isn't really the font's full name,
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
632 so don't use it.
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
633 In X11R4, the fonts did not come with their canonical names
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
634 stored in them. */
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
635 while (*p)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
636 {
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
637 if (*p == '-')
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
638 dashes++;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
639 p++;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
640 }
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
641
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
642 if (dashes >= 13)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
643 {
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
644 full_name = (char *) malloc (p - p0 + 1);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
645 if (full_name)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
646 bcopy (p0, full_name, p - p0 + 1);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
647 }
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
648 XFree (p0);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
649
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
650 if (full_name)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
651 font->font.full_name = full_name;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
652 else
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
653 font->font.full_name = font->font.name;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
654 }
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
655 font->file_name = NULL;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
656
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
657 font->font.size = xfont->max_bounds.width;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
658 font->font.height = xfont->ascent + xfont->descent;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
659 font->font.baseline_offset
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
660 = (XGetFontProperty (xfont, dpyinfo->Xatom_MULE_BASELINE_OFFSET, &value)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
661 ? (long) value : 0);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
662 font->font.relative_compose
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
663 = (XGetFontProperty (xfont, dpyinfo->Xatom_MULE_RELATIVE_COMPOSE, &value)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
664 ? (long) value : 0);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
665 font->font.default_ascent
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
666 = (XGetFontProperty (xfont, dpyinfo->Xatom_MULE_DEFAULT_ASCENT, &value)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
667 ? (long) value : 0);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
668 font->font.vertical_centering
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
669 = (STRINGP (Vvertical_centering_font_regexp)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
670 && (fast_c_string_match_ignore_case
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
671 (Vvertical_centering_font_regexp, font->font.full_name) >= 0));
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
672
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
673 UNBLOCK_INPUT;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
674
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
675 dpyinfo->n_fonts++;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
676
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
677 /* Set global flag fonts_changed_p to non-zero if the font loaded
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
678 has a character with a smaller width than any other character
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
679 before, or if the font loaded has a smaller height than any other
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
680 font loaded before. If this happens, it will make a glyph matrix
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
681 reallocation necessary. */
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
682 if (dpyinfo->n_fonts == 1)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
683 {
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
684 dpyinfo->smallest_font_height = font->font.height;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
685 dpyinfo->smallest_char_width = font->min_width;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
686 fonts_changed_p = 1;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
687 }
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
688 else
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
689 {
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
690 if (dpyinfo->smallest_font_height > font->font.height)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
691 dpyinfo->smallest_font_height = font->font.height, fonts_changed_p |= 1;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
692 if (dpyinfo->smallest_char_width > font->min_width)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
693 dpyinfo->smallest_char_width = font->min_width, fonts_changed_p |= 1;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
694 }
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
695
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
696 return font;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
697 }
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
698
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
699 static void
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
700 xfont_close (f, font)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
701 FRAME_PTR f;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
702 struct font *font;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
703 {
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
704 BLOCK_INPUT;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
705 XFreeFont (FRAME_X_DISPLAY (f), font->font.font);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
706 UNBLOCK_INPUT;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
707
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
708 if (font->font.name != font->font.full_name)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
709 free (font->font.full_name);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
710 free (font->font.name);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
711 free (font);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
712 FRAME_X_DISPLAY_INFO (f)->n_fonts--;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
713 }
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
714
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
715 static int
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
716 xfont_prepare_face (f, face)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
717 FRAME_PTR f;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
718 struct face *face;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
719 {
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
720 BLOCK_INPUT;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
721 XSetFont (FRAME_X_DISPLAY (f), face->gc, face->font->fid);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
722 UNBLOCK_INPUT;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
723
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
724 return 0;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
725 }
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
726
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
727 #if 0
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
728 static void
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
729 xfont_done_face (f, face)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
730 FRAME_PTR f;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
731 struct face *face;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
732 {
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
733 if (face->extra)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
734 {
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
735 BLOCK_INPUT;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
736 XFreeGC (FRAME_X_DISPLAY (f), (GC) face->extra);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
737 UNBLOCK_INPUT;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
738 face->extra = NULL;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
739 }
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
740 }
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
741 #endif /* 0 */
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
742
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
743 static int
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
744 xfont_has_char (entity, c)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
745 Lisp_Object entity;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
746 int c;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
747 {
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
748 Lisp_Object registry = AREF (entity, FONT_REGISTRY_INDEX);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
749 struct charset *repertory;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
750
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
751 if (xfont_registry_charsets (registry, NULL, &repertory) < 0)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
752 return -1;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
753 if (! repertory)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
754 return -1;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
755 return (ENCODE_CHAR (repertory, c) != CHARSET_INVALID_CODE (repertory));
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
756 }
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
757
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
758 static unsigned
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
759 xfont_encode_char (font, c)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
760 struct font *font;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
761 int c;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
762 {
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
763 struct charset *charset;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
764 unsigned code;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
765 XChar2b char2b;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
766
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
767 charset = CHARSET_FROM_ID (font->encoding_charset);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
768 code = ENCODE_CHAR (charset, c);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
769 if (code == CHARSET_INVALID_CODE (charset))
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
770 return 0xFFFFFFFF;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
771 if (font->repertory_charet >= 0)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
772 {
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
773 charset = CHARSET_FROM_ID (font->repertory_charet);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
774 return (ENCODE_CHAR (charset, c) != CHARSET_INVALID_CODE (charset)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
775 ? code : 0xFFFFFFFF);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
776 }
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
777 char2b.byte1 = code >> 16;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
778 char2b.byte2 = code & 0xFFFF;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
779 return (xfont_get_pcm (font->font.font, &char2b) ? code : 0xFFFFFFFF);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
780 }
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
781
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
782 static int
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
783 xfont_text_extents (font, code, nglyphs, metrics)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
784 struct font *font;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
785 unsigned *code;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
786 int nglyphs;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
787 struct font_metrics *metrics;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
788 {
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
789 int width = 0;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
790 int i, x;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
791
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
792 if (metrics)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
793 bzero (metrics, sizeof (struct font_metrics));
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
794 for (i = 0, x = 0; i < nglyphs; i++)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
795 {
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
796 XChar2b char2b;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
797 static XCharStruct *pcm;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
798
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
799 if (code[i] >= 0x10000)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
800 continue;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
801 char2b.byte1 = code[i] >> 8, char2b.byte2 = code[i] & 0xFF;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
802 pcm = xfont_get_pcm (font->font.font, &char2b);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
803 if (! pcm)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
804 continue;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
805 if (metrics->lbearing > width + pcm->lbearing)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
806 metrics->lbearing = width + pcm->lbearing;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
807 if (metrics->rbearing < width + pcm->rbearing)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
808 metrics->rbearing = width + pcm->rbearing;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
809 if (metrics->ascent < pcm->ascent)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
810 metrics->ascent = pcm->ascent;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
811 if (metrics->descent < pcm->descent)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
812 metrics->descent = pcm->descent;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
813 width += pcm->width;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
814 }
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
815 if (metrics)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
816 metrics->width = width;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
817 return width;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
818 }
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
819
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
820 static int
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
821 xfont_draw (s, from, to, x, y, with_background)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
822 struct glyph_string *s;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
823 int from, to, x, y, with_background;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
824 {
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
825 XFontStruct *xfont = s->face->font;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
826 int len = to - from;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
827
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
828 if (xfont->min_byte1 == 0 && xfont->max_byte1 == 0)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
829 {
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
830 char *str;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
831 int i;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
832 USE_SAFE_ALLOCA;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
833
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
834 SAFE_ALLOCA (str, char *, len);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
835 for (i = 0; i < len ; i++)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
836 str[i] = XCHAR2B_BYTE2 (s->char2b + from + i);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
837 if (with_background > 0)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
838 XDrawImageString (FRAME_X_DISPLAY (s->f), FRAME_X_WINDOW (s->f),
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
839 s->gc, x, y, str, len);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
840 else
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
841 XDrawString (FRAME_X_DISPLAY (s->f), FRAME_X_WINDOW (s->f),
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
842 s->gc, x, y, str, len);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
843 SAFE_FREE ();
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
844 return s->nchars;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
845 }
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
846
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
847 if (with_background > 0)
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
848 XDrawImageString16 (FRAME_X_DISPLAY (s->f), FRAME_X_WINDOW (s->f),
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
849 s->gc, x, y, s->char2b + from, len);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
850 else
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
851 XDrawString16 (FRAME_X_DISPLAY (s->f), FRAME_X_WINDOW (s->f),
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
852 s->gc, x, y, s->char2b + from, len);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
853
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
854 return len;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
855 }
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
856
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
857
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
858
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
859 void
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
860 syms_of_xfont ()
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
861 {
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
862 staticpro (&x_font_charset_alist);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
863 x_font_charset_alist = Qnil;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
864
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
865 DEFSYM (Qx, "x");
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
866 xfont_driver.type = Qx;
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
867 register_font_driver (&xfont_driver, NULL);
80fff33f74f5 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
868 }