Mercurial > emacs
annotate src/xftfont.c @ 91052:72adb6e72b67
Move unicode-specific changelog entries to lisp/ChangeLog.unicode
Revision: emacs@sv.gnu.org/emacs--unicode--0--patch-267
author | Miles Bader <miles@gnu.org> |
---|---|
date | Mon, 15 Oct 2007 04:54:31 +0000 |
parents | 04b81a720da9 |
children | 82a42637237c |
rev | line source |
---|---|
90400 | 1 /* xftfont.c -- XFT font driver. |
2 Copyright (C) 2006 Free Software Foundation, Inc. | |
3 Copyright (C) 2006 | |
4 National Institute of Advanced Industrial Science and Technology (AIST) | |
5 Registration Number H13PRO009 | |
6 | |
7 This file is part of GNU Emacs. | |
8 | |
9 GNU Emacs is free software; you can redistribute it and/or modify | |
10 it under the terms of the GNU General Public License as published by | |
11 the Free Software Foundation; either version 2, or (at your option) | |
12 any later version. | |
13 | |
14 GNU Emacs is distributed in the hope that it will be useful, | |
15 but WITHOUT ANY WARRANTY; without even the implied warranty of | |
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
17 GNU General Public License for more details. | |
18 | |
19 You should have received a copy of the GNU General Public License | |
20 along with GNU Emacs; see the file COPYING. If not, write to | |
21 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | |
22 Boston, MA 02110-1301, USA. */ | |
23 | |
24 #include <config.h> | |
25 #include <stdio.h> | |
26 #include <X11/Xlib.h> | |
27 #include <X11/Xft/Xft.h> | |
28 | |
29 #include "lisp.h" | |
30 #include "dispextern.h" | |
31 #include "xterm.h" | |
32 #include "frame.h" | |
33 #include "blockinput.h" | |
34 #include "character.h" | |
35 #include "charset.h" | |
36 #include "fontset.h" | |
37 #include "font.h" | |
38 | |
39 /* Xft font driver. */ | |
40 | |
41 static Lisp_Object Qxft; | |
42 | |
43 /* The actual structure for Xft font that can be casted to struct | |
44 font. */ | |
45 | |
46 struct xftfont_info | |
47 { | |
48 struct font font; | |
49 Display *display; | |
50 int screen; | |
51 XftFont *xftfont; | |
90559
fb5d3ac2d786
(xftfont_match): New function.
Kenichi Handa <handa@m17n.org>
parents:
90527
diff
changeset
|
52 FT_Face ft_face; /* set to XftLockFace (xftfont) */ |
90400 | 53 }; |
54 | |
55 /* Structure pointed by (struct face *)->extra */ | |
90559
fb5d3ac2d786
(xftfont_match): New function.
Kenichi Handa <handa@m17n.org>
parents:
90527
diff
changeset
|
56 |
90400 | 57 struct xftface_info |
58 { | |
90559
fb5d3ac2d786
(xftfont_match): New function.
Kenichi Handa <handa@m17n.org>
parents:
90527
diff
changeset
|
59 XftColor xft_fg; /* color for face->foreground */ |
fb5d3ac2d786
(xftfont_match): New function.
Kenichi Handa <handa@m17n.org>
parents:
90527
diff
changeset
|
60 XftColor xft_bg; /* color for face->background */ |
90400 | 61 XftDraw *xft_draw; |
62 }; | |
63 | |
64 static void xftfont_get_colors P_ ((FRAME_PTR, struct face *, GC gc, | |
65 struct xftface_info *, | |
66 XftColor *fg, XftColor *bg)); | |
67 static Font xftfont_default_fid P_ ((FRAME_PTR)); | |
68 | |
69 | |
90559
fb5d3ac2d786
(xftfont_match): New function.
Kenichi Handa <handa@m17n.org>
parents:
90527
diff
changeset
|
70 /* Setup foreground and background colors of GC into FG and BG. If |
fb5d3ac2d786
(xftfont_match): New function.
Kenichi Handa <handa@m17n.org>
parents:
90527
diff
changeset
|
71 XFTFACE_INFO is not NULL, reuse the colors in it if possible. BG |
fb5d3ac2d786
(xftfont_match): New function.
Kenichi Handa <handa@m17n.org>
parents:
90527
diff
changeset
|
72 may be NULL. */ |
fb5d3ac2d786
(xftfont_match): New function.
Kenichi Handa <handa@m17n.org>
parents:
90527
diff
changeset
|
73 |
90400 | 74 static void |
75 xftfont_get_colors (f, face, gc, xftface_info, fg, bg) | |
76 FRAME_PTR f; | |
77 struct face *face; | |
78 GC gc; | |
79 struct xftface_info *xftface_info; | |
80 XftColor *fg, *bg; | |
81 { | |
82 if (xftface_info && face->gc == gc) | |
83 { | |
84 *fg = xftface_info->xft_fg; | |
85 if (bg) | |
86 *bg = xftface_info->xft_bg; | |
87 } | |
88 else | |
89 { | |
90 XGCValues xgcv; | |
91 int fg_done = 0, bg_done = 0; | |
92 | |
93 BLOCK_INPUT; | |
94 XGetGCValues (FRAME_X_DISPLAY (f), gc, | |
95 GCForeground | GCBackground, &xgcv); | |
96 if (xftface_info) | |
97 { | |
98 if (xgcv.foreground == face->foreground) | |
99 *fg = xftface_info->xft_fg, fg_done = 1; | |
100 else if (xgcv.foreground == face->background) | |
101 *fg = xftface_info->xft_bg, fg_done = 1; | |
102 if (! bg) | |
103 bg_done = 1; | |
104 else if (xgcv.background == face->background) | |
105 *bg = xftface_info->xft_bg, bg_done = 1; | |
106 else if (xgcv.background == face->foreground) | |
107 *bg = xftface_info->xft_fg, bg_done = 1; | |
108 } | |
109 | |
110 if (fg_done + bg_done < 2) | |
111 { | |
112 XColor colors[2]; | |
113 | |
114 colors[0].pixel = fg->pixel = xgcv.foreground; | |
115 if (bg) | |
116 colors[1].pixel = bg->pixel = xgcv.background; | |
117 XQueryColors (FRAME_X_DISPLAY (f), FRAME_X_COLORMAP (f), colors, | |
118 bg ? 2 : 1); | |
119 fg->color.alpha = 0xFFFF; | |
120 fg->color.red = colors[0].red; | |
121 fg->color.green = colors[0].green; | |
122 fg->color.blue = colors[0].blue; | |
123 if (bg) | |
124 { | |
125 bg->color.alpha = 0xFFFF; | |
126 bg->color.red = colors[1].red; | |
127 bg->color.green = colors[1].green; | |
128 bg->color.blue = colors[1].blue; | |
129 } | |
130 } | |
131 UNBLOCK_INPUT; | |
132 } | |
133 } | |
134 | |
90559
fb5d3ac2d786
(xftfont_match): New function.
Kenichi Handa <handa@m17n.org>
parents:
90527
diff
changeset
|
135 /* Return the default Font ID on frame F. The Returned Font ID is |
fb5d3ac2d786
(xftfont_match): New function.
Kenichi Handa <handa@m17n.org>
parents:
90527
diff
changeset
|
136 stored in the GC of the frame F, but the font is never used. So, |
fb5d3ac2d786
(xftfont_match): New function.
Kenichi Handa <handa@m17n.org>
parents:
90527
diff
changeset
|
137 any ID is ok as long as it is valid. */ |
90400 | 138 |
139 static Font | |
140 xftfont_default_fid (f) | |
141 FRAME_PTR f; | |
142 { | |
143 static int fid_known; | |
144 static Font fid; | |
145 | |
146 if (! fid_known) | |
147 { | |
148 fid = XLoadFont (FRAME_X_DISPLAY (f), "fixed"); | |
149 if (! fid) | |
150 { | |
151 fid = XLoadFont (FRAME_X_DISPLAY (f), "*"); | |
152 if (! fid) | |
153 abort (); | |
154 } | |
90426
e9ed7d437c21
(xftfont_default_fid): Set fid_known to 1.
Kenichi Handa <handa@m17n.org>
parents:
90400
diff
changeset
|
155 fid_known = 1; |
90400 | 156 } |
157 return fid; | |
158 } | |
159 | |
160 | |
161 static Lisp_Object xftfont_list P_ ((Lisp_Object, Lisp_Object)); | |
90559
fb5d3ac2d786
(xftfont_match): New function.
Kenichi Handa <handa@m17n.org>
parents:
90527
diff
changeset
|
162 static Lisp_Object xftfont_match P_ ((Lisp_Object, Lisp_Object)); |
90400 | 163 static struct font *xftfont_open P_ ((FRAME_PTR, Lisp_Object, int)); |
164 static void xftfont_close P_ ((FRAME_PTR, struct font *)); | |
165 static int xftfont_prepare_face P_ ((FRAME_PTR, struct face *)); | |
166 static void xftfont_done_face P_ ((FRAME_PTR, struct face *)); | |
167 static unsigned xftfont_encode_char P_ ((struct font *, int)); | |
168 static int xftfont_text_extents P_ ((struct font *, unsigned *, int, | |
169 struct font_metrics *)); | |
170 static int xftfont_draw P_ ((struct glyph_string *, int, int, int, int, int)); | |
171 | |
172 static int xftfont_anchor_point P_ ((struct font *, unsigned, int, | |
173 int *, int *)); | |
174 | |
175 struct font_driver xftfont_driver; | |
176 | |
177 static Lisp_Object | |
178 xftfont_list (frame, spec) | |
179 Lisp_Object frame; | |
180 Lisp_Object spec; | |
181 { | |
182 Lisp_Object val = ftfont_driver.list (frame, spec); | |
90559
fb5d3ac2d786
(xftfont_match): New function.
Kenichi Handa <handa@m17n.org>
parents:
90527
diff
changeset
|
183 int i; |
90400 | 184 |
185 if (! NILP (val)) | |
90559
fb5d3ac2d786
(xftfont_match): New function.
Kenichi Handa <handa@m17n.org>
parents:
90527
diff
changeset
|
186 for (i = 0; i < ASIZE (val); i++) |
fb5d3ac2d786
(xftfont_match): New function.
Kenichi Handa <handa@m17n.org>
parents:
90527
diff
changeset
|
187 ASET (AREF (val, i), FONT_TYPE_INDEX, Qxft); |
fb5d3ac2d786
(xftfont_match): New function.
Kenichi Handa <handa@m17n.org>
parents:
90527
diff
changeset
|
188 return val; |
fb5d3ac2d786
(xftfont_match): New function.
Kenichi Handa <handa@m17n.org>
parents:
90527
diff
changeset
|
189 } |
90400 | 190 |
90559
fb5d3ac2d786
(xftfont_match): New function.
Kenichi Handa <handa@m17n.org>
parents:
90527
diff
changeset
|
191 static Lisp_Object |
fb5d3ac2d786
(xftfont_match): New function.
Kenichi Handa <handa@m17n.org>
parents:
90527
diff
changeset
|
192 xftfont_match (frame, spec) |
fb5d3ac2d786
(xftfont_match): New function.
Kenichi Handa <handa@m17n.org>
parents:
90527
diff
changeset
|
193 Lisp_Object frame; |
fb5d3ac2d786
(xftfont_match): New function.
Kenichi Handa <handa@m17n.org>
parents:
90527
diff
changeset
|
194 Lisp_Object spec; |
fb5d3ac2d786
(xftfont_match): New function.
Kenichi Handa <handa@m17n.org>
parents:
90527
diff
changeset
|
195 { |
fb5d3ac2d786
(xftfont_match): New function.
Kenichi Handa <handa@m17n.org>
parents:
90527
diff
changeset
|
196 Lisp_Object entity = ftfont_driver.match (frame, spec); |
fb5d3ac2d786
(xftfont_match): New function.
Kenichi Handa <handa@m17n.org>
parents:
90527
diff
changeset
|
197 |
fb5d3ac2d786
(xftfont_match): New function.
Kenichi Handa <handa@m17n.org>
parents:
90527
diff
changeset
|
198 if (VECTORP (entity)) |
fb5d3ac2d786
(xftfont_match): New function.
Kenichi Handa <handa@m17n.org>
parents:
90527
diff
changeset
|
199 ASET (entity, FONT_TYPE_INDEX, Qxft); |
fb5d3ac2d786
(xftfont_match): New function.
Kenichi Handa <handa@m17n.org>
parents:
90527
diff
changeset
|
200 return entity; |
90400 | 201 } |
202 | |
90700
b165eceb829f
(ftfont_font_format): Extern declaration.
Kenichi Handa <handa@m17n.org>
parents:
90675
diff
changeset
|
203 extern Lisp_Object ftfont_font_format P_ ((FcPattern *)); |
b165eceb829f
(ftfont_font_format): Extern declaration.
Kenichi Handa <handa@m17n.org>
parents:
90675
diff
changeset
|
204 |
90400 | 205 static FcChar8 ascii_printable[95]; |
206 | |
207 static struct font * | |
208 xftfont_open (f, entity, pixel_size) | |
209 FRAME_PTR f; | |
210 Lisp_Object entity; | |
211 int pixel_size; | |
212 { | |
213 Display_Info *dpyinfo = FRAME_X_DISPLAY_INFO (f); | |
214 Display *display = FRAME_X_DISPLAY (f); | |
215 Lisp_Object val; | |
90460
86449661f321
(xftfont_open): Change coding style of error
Kenichi Handa <handa@m17n.org>
parents:
90442
diff
changeset
|
216 FcPattern *pattern, *pat = NULL; |
86449661f321
(xftfont_open): Change coding style of error
Kenichi Handa <handa@m17n.org>
parents:
90442
diff
changeset
|
217 FcChar8 *file; |
86449661f321
(xftfont_open): Change coding style of error
Kenichi Handa <handa@m17n.org>
parents:
90442
diff
changeset
|
218 struct xftfont_info *xftfont_info = NULL; |
86449661f321
(xftfont_open): Change coding style of error
Kenichi Handa <handa@m17n.org>
parents:
90442
diff
changeset
|
219 XFontStruct *xfont = NULL; |
90400 | 220 struct font *font; |
221 double size = 0; | |
90460
86449661f321
(xftfont_open): Change coding style of error
Kenichi Handa <handa@m17n.org>
parents:
90442
diff
changeset
|
222 XftFont *xftfont = NULL; |
90400 | 223 int spacing; |
90460
86449661f321
(xftfont_open): Change coding style of error
Kenichi Handa <handa@m17n.org>
parents:
90442
diff
changeset
|
224 char *name; |
90442
d6abf2344438
(xftfont_open): Make the font name fontconfig's
Kenichi Handa <handa@m17n.org>
parents:
90427
diff
changeset
|
225 int len; |
90959
3f83c9d3f96c
(xftfont_open): If one of font's ASCII glyph has
Kenichi Handa <handa@m17n.org>
parents:
90714
diff
changeset
|
226 XGlyphInfo extents; |
90400 | 227 |
228 val = AREF (entity, FONT_EXTRA_INDEX); | |
229 if (XTYPE (val) != Lisp_Misc | |
230 || XMISCTYPE (val) != Lisp_Misc_Save_Value) | |
231 return NULL; | |
232 pattern = XSAVE_VALUE (val)->pointer; | |
233 if (FcPatternGetString (pattern, FC_FILE, 0, &file) != FcResultMatch) | |
234 return NULL; | |
235 | |
236 size = XINT (AREF (entity, FONT_SIZE_INDEX)); | |
237 if (size == 0) | |
238 size = pixel_size; | |
90442
d6abf2344438
(xftfont_open): Make the font name fontconfig's
Kenichi Handa <handa@m17n.org>
parents:
90427
diff
changeset
|
239 |
90400 | 240 pat = FcPatternCreate (); |
241 FcPatternAddString (pat, FC_FILE, file); | |
242 FcPatternAddDouble (pat, FC_PIXEL_SIZE, pixel_size); | |
90712
8594053c8fec
(xftfont_open): Don't enable antialias explicitly.
Kenichi Handa <handa@m17n.org>
parents:
90700
diff
changeset
|
243 /*FcPatternAddBool (pat, FC_ANTIALIAS, FcTrue);*/ |
90714
698001835583
(xftfont_open): Call FcConfigSubstitute.
Kenichi Handa <handa@m17n.org>
parents:
90712
diff
changeset
|
244 val = AREF (entity, FONT_FAMILY_INDEX); |
698001835583
(xftfont_open): Call FcConfigSubstitute.
Kenichi Handa <handa@m17n.org>
parents:
90712
diff
changeset
|
245 if (! NILP (val)) |
698001835583
(xftfont_open): Call FcConfigSubstitute.
Kenichi Handa <handa@m17n.org>
parents:
90712
diff
changeset
|
246 FcPatternAddString (pat, FC_FAMILY, (FcChar8 *) SDATA (SYMBOL_NAME (val))); |
698001835583
(xftfont_open): Call FcConfigSubstitute.
Kenichi Handa <handa@m17n.org>
parents:
90712
diff
changeset
|
247 FcConfigSubstitute (NULL, pat, FcMatchPattern); |
90442
d6abf2344438
(xftfont_open): Make the font name fontconfig's
Kenichi Handa <handa@m17n.org>
parents:
90427
diff
changeset
|
248 |
d6abf2344438
(xftfont_open): Make the font name fontconfig's
Kenichi Handa <handa@m17n.org>
parents:
90427
diff
changeset
|
249 BLOCK_INPUT; |
90589
697dcc1df88d
(xftfont_open): Call XftDefaultSubstitute before
Kenichi Handa <handa@m17n.org>
parents:
90559
diff
changeset
|
250 XftDefaultSubstitute (display, FRAME_X_SCREEN_NUMBER (f), pat); |
90400 | 251 xftfont = XftFontOpenPattern (display, pat); |
252 /* We should not destroy PAT here because it is kept in XFTFONT and | |
253 destroyed automatically when XFTFONT is closed. */ | |
254 if (! xftfont) | |
90460
86449661f321
(xftfont_open): Change coding style of error
Kenichi Handa <handa@m17n.org>
parents:
90442
diff
changeset
|
255 goto err; |
90400 | 256 |
257 xftfont_info = malloc (sizeof (struct xftfont_info)); | |
258 if (! xftfont_info) | |
90460
86449661f321
(xftfont_open): Change coding style of error
Kenichi Handa <handa@m17n.org>
parents:
90442
diff
changeset
|
259 goto err; |
90400 | 260 xfont = malloc (sizeof (XFontStruct)); |
90460
86449661f321
(xftfont_open): Change coding style of error
Kenichi Handa <handa@m17n.org>
parents:
90442
diff
changeset
|
261 if (! xfont) |
86449661f321
(xftfont_open): Change coding style of error
Kenichi Handa <handa@m17n.org>
parents:
90442
diff
changeset
|
262 goto err; |
90400 | 263 xftfont_info->display = display; |
264 xftfont_info->screen = FRAME_X_SCREEN_NUMBER (f); | |
265 xftfont_info->xftfont = xftfont; | |
266 xftfont_info->ft_face = XftLockFace (xftfont); | |
267 | |
268 font = (struct font *) xftfont_info; | |
90675
dfe6bfcd570f
(xftfont_open): Set font->format.
Kenichi Handa <handa@m17n.org>
parents:
90616
diff
changeset
|
269 font->format = ftfont_font_format (xftfont->pattern); |
90400 | 270 font->entity = entity; |
271 font->pixel_size = size; | |
272 font->driver = &xftfont_driver; | |
90473
9c75458ea910
(xftfont_open): For generating a name, start from
Kenichi Handa <handa@m17n.org>
parents:
90460
diff
changeset
|
273 len = 96; |
90460
86449661f321
(xftfont_open): Change coding style of error
Kenichi Handa <handa@m17n.org>
parents:
90442
diff
changeset
|
274 name = malloc (len); |
86449661f321
(xftfont_open): Change coding style of error
Kenichi Handa <handa@m17n.org>
parents:
90442
diff
changeset
|
275 while (name && font_unparse_fcname (entity, pixel_size, name, len) < 0) |
86449661f321
(xftfont_open): Change coding style of error
Kenichi Handa <handa@m17n.org>
parents:
90442
diff
changeset
|
276 { |
86449661f321
(xftfont_open): Change coding style of error
Kenichi Handa <handa@m17n.org>
parents:
90442
diff
changeset
|
277 char *new = realloc (name, len += 32); |
86449661f321
(xftfont_open): Change coding style of error
Kenichi Handa <handa@m17n.org>
parents:
90442
diff
changeset
|
278 |
86449661f321
(xftfont_open): Change coding style of error
Kenichi Handa <handa@m17n.org>
parents:
90442
diff
changeset
|
279 if (! new) |
86449661f321
(xftfont_open): Change coding style of error
Kenichi Handa <handa@m17n.org>
parents:
90442
diff
changeset
|
280 free (name); |
86449661f321
(xftfont_open): Change coding style of error
Kenichi Handa <handa@m17n.org>
parents:
90442
diff
changeset
|
281 name = new; |
86449661f321
(xftfont_open): Change coding style of error
Kenichi Handa <handa@m17n.org>
parents:
90442
diff
changeset
|
282 } |
86449661f321
(xftfont_open): Change coding style of error
Kenichi Handa <handa@m17n.org>
parents:
90442
diff
changeset
|
283 if (! name) |
86449661f321
(xftfont_open): Change coding style of error
Kenichi Handa <handa@m17n.org>
parents:
90442
diff
changeset
|
284 goto err; |
86449661f321
(xftfont_open): Change coding style of error
Kenichi Handa <handa@m17n.org>
parents:
90442
diff
changeset
|
285 font->font.full_name = font->font.name = name; |
90400 | 286 font->file_name = (char *) file; |
287 font->font.size = xftfont->max_advance_width; | |
90511
2cd8e24f656a
(xftfont_open): Set charset related members to -1.
Kenichi Handa <handa@m17n.org>
parents:
90499
diff
changeset
|
288 font->font.charset = font->encoding_charset = font->repertory_charset = -1; |
90400 | 289 |
290 if (FcPatternGetInteger (xftfont->pattern, FC_SPACING, 0, &spacing) | |
291 != FcResultMatch) | |
292 spacing = FC_PROPORTIONAL; | |
90959
3f83c9d3f96c
(xftfont_open): If one of font's ASCII glyph has
Kenichi Handa <handa@m17n.org>
parents:
90714
diff
changeset
|
293 if (! ascii_printable[0]) |
3f83c9d3f96c
(xftfont_open): If one of font's ASCII glyph has
Kenichi Handa <handa@m17n.org>
parents:
90714
diff
changeset
|
294 { |
3f83c9d3f96c
(xftfont_open): If one of font's ASCII glyph has
Kenichi Handa <handa@m17n.org>
parents:
90714
diff
changeset
|
295 int i; |
3f83c9d3f96c
(xftfont_open): If one of font's ASCII glyph has
Kenichi Handa <handa@m17n.org>
parents:
90714
diff
changeset
|
296 for (i = 0; i < 95; i++) |
3f83c9d3f96c
(xftfont_open): If one of font's ASCII glyph has
Kenichi Handa <handa@m17n.org>
parents:
90714
diff
changeset
|
297 ascii_printable[i] = ' ' + i; |
3f83c9d3f96c
(xftfont_open): If one of font's ASCII glyph has
Kenichi Handa <handa@m17n.org>
parents:
90714
diff
changeset
|
298 } |
90400 | 299 if (spacing != FC_PROPORTIONAL) |
90959
3f83c9d3f96c
(xftfont_open): If one of font's ASCII glyph has
Kenichi Handa <handa@m17n.org>
parents:
90714
diff
changeset
|
300 { |
3f83c9d3f96c
(xftfont_open): If one of font's ASCII glyph has
Kenichi Handa <handa@m17n.org>
parents:
90714
diff
changeset
|
301 font->font.average_width = font->font.space_width |
3f83c9d3f96c
(xftfont_open): If one of font's ASCII glyph has
Kenichi Handa <handa@m17n.org>
parents:
90714
diff
changeset
|
302 = xftfont->max_advance_width; |
3f83c9d3f96c
(xftfont_open): If one of font's ASCII glyph has
Kenichi Handa <handa@m17n.org>
parents:
90714
diff
changeset
|
303 XftTextExtents8 (display, xftfont, ascii_printable + 1, 94, &extents); |
3f83c9d3f96c
(xftfont_open): If one of font's ASCII glyph has
Kenichi Handa <handa@m17n.org>
parents:
90714
diff
changeset
|
304 } |
90400 | 305 else |
306 { | |
307 XftTextExtents8 (display, xftfont, ascii_printable, 1, &extents); | |
308 font->font.space_width = extents.xOff; | |
309 if (font->font.space_width <= 0) | |
310 /* dirty workaround */ | |
311 font->font.space_width = pixel_size; | |
312 XftTextExtents8 (display, xftfont, ascii_printable + 1, 94, &extents); | |
313 font->font.average_width = (font->font.space_width + extents.xOff) / 95; | |
314 } | |
90442
d6abf2344438
(xftfont_open): Make the font name fontconfig's
Kenichi Handa <handa@m17n.org>
parents:
90427
diff
changeset
|
315 UNBLOCK_INPUT; |
90400 | 316 |
90959
3f83c9d3f96c
(xftfont_open): If one of font's ASCII glyph has
Kenichi Handa <handa@m17n.org>
parents:
90714
diff
changeset
|
317 font->ascent = xftfont->ascent; |
3f83c9d3f96c
(xftfont_open): If one of font's ASCII glyph has
Kenichi Handa <handa@m17n.org>
parents:
90714
diff
changeset
|
318 if (font->ascent < extents.y) |
3f83c9d3f96c
(xftfont_open): If one of font's ASCII glyph has
Kenichi Handa <handa@m17n.org>
parents:
90714
diff
changeset
|
319 font->ascent = extents.y; |
3f83c9d3f96c
(xftfont_open): If one of font's ASCII glyph has
Kenichi Handa <handa@m17n.org>
parents:
90714
diff
changeset
|
320 font->descent = xftfont->descent; |
3f83c9d3f96c
(xftfont_open): If one of font's ASCII glyph has
Kenichi Handa <handa@m17n.org>
parents:
90714
diff
changeset
|
321 if (font->descent < extents.height - extents.y) |
3f83c9d3f96c
(xftfont_open): If one of font's ASCII glyph has
Kenichi Handa <handa@m17n.org>
parents:
90714
diff
changeset
|
322 font->descent = extents.height - extents.y; |
3f83c9d3f96c
(xftfont_open): If one of font's ASCII glyph has
Kenichi Handa <handa@m17n.org>
parents:
90714
diff
changeset
|
323 font->font.height = font->ascent + font->descent; |
3f83c9d3f96c
(xftfont_open): If one of font's ASCII glyph has
Kenichi Handa <handa@m17n.org>
parents:
90714
diff
changeset
|
324 |
90400 | 325 /* Unfortunately Xft doesn't provide a way to get minimum char |
326 width. So, we use space_width instead. */ | |
327 font->min_width = font->font.space_width; | |
328 | |
329 font->font.baseline_offset = 0; | |
330 font->font.relative_compose = 0; | |
331 font->font.default_ascent = 0; | |
332 font->font.vertical_centering = 0; | |
333 | |
334 /* Setup pseudo XFontStruct */ | |
335 xfont->fid = xftfont_default_fid (f); | |
90959
3f83c9d3f96c
(xftfont_open): If one of font's ASCII glyph has
Kenichi Handa <handa@m17n.org>
parents:
90714
diff
changeset
|
336 xfont->ascent = font->ascent; |
3f83c9d3f96c
(xftfont_open): If one of font's ASCII glyph has
Kenichi Handa <handa@m17n.org>
parents:
90714
diff
changeset
|
337 xfont->descent = font->descent; |
3f83c9d3f96c
(xftfont_open): If one of font's ASCII glyph has
Kenichi Handa <handa@m17n.org>
parents:
90714
diff
changeset
|
338 xfont->max_bounds.descent = font->descent; |
90400 | 339 xfont->max_bounds.width = xftfont->max_advance_width; |
340 xfont->min_bounds.width = font->font.space_width; | |
341 font->font.font = xfont; | |
342 | |
343 dpyinfo->n_fonts++; | |
344 | |
345 /* Set global flag fonts_changed_p to non-zero if the font loaded | |
346 has a character with a smaller width than any other character | |
347 before, or if the font loaded has a smaller height than any other | |
348 font loaded before. If this happens, it will make a glyph matrix | |
349 reallocation necessary. */ | |
350 if (dpyinfo->n_fonts == 1) | |
351 { | |
352 dpyinfo->smallest_font_height = font->font.height; | |
353 dpyinfo->smallest_char_width = font->min_width; | |
354 fonts_changed_p = 1; | |
355 } | |
356 else | |
357 { | |
358 if (dpyinfo->smallest_font_height > font->font.height) | |
359 dpyinfo->smallest_font_height = font->font.height, | |
360 fonts_changed_p |= 1; | |
361 if (dpyinfo->smallest_char_width > font->min_width) | |
362 dpyinfo->smallest_char_width = font->min_width, | |
363 fonts_changed_p |= 1; | |
364 } | |
365 | |
366 return font; | |
90460
86449661f321
(xftfont_open): Change coding style of error
Kenichi Handa <handa@m17n.org>
parents:
90442
diff
changeset
|
367 |
86449661f321
(xftfont_open): Change coding style of error
Kenichi Handa <handa@m17n.org>
parents:
90442
diff
changeset
|
368 err: |
86449661f321
(xftfont_open): Change coding style of error
Kenichi Handa <handa@m17n.org>
parents:
90442
diff
changeset
|
369 if (xftfont) XftFontClose (display, xftfont); |
86449661f321
(xftfont_open): Change coding style of error
Kenichi Handa <handa@m17n.org>
parents:
90442
diff
changeset
|
370 UNBLOCK_INPUT; |
86449661f321
(xftfont_open): Change coding style of error
Kenichi Handa <handa@m17n.org>
parents:
90442
diff
changeset
|
371 if (xftfont_info) free (xftfont_info); |
86449661f321
(xftfont_open): Change coding style of error
Kenichi Handa <handa@m17n.org>
parents:
90442
diff
changeset
|
372 if (xfont) free (xfont); |
86449661f321
(xftfont_open): Change coding style of error
Kenichi Handa <handa@m17n.org>
parents:
90442
diff
changeset
|
373 return NULL; |
90400 | 374 } |
375 | |
376 static void | |
377 xftfont_close (f, font) | |
378 FRAME_PTR f; | |
379 struct font *font; | |
380 { | |
381 struct xftfont_info *xftfont_info = (struct xftfont_info *) font; | |
382 | |
383 XftUnlockFace (xftfont_info->xftfont); | |
384 XftFontClose (xftfont_info->display, xftfont_info->xftfont); | |
90442
d6abf2344438
(xftfont_open): Make the font name fontconfig's
Kenichi Handa <handa@m17n.org>
parents:
90427
diff
changeset
|
385 if (font->font.name) |
d6abf2344438
(xftfont_open): Make the font name fontconfig's
Kenichi Handa <handa@m17n.org>
parents:
90427
diff
changeset
|
386 free (font->font.name); |
90400 | 387 free (font); |
388 FRAME_X_DISPLAY_INFO (f)->n_fonts--; | |
389 } | |
390 | |
391 static int | |
392 xftfont_prepare_face (f, face) | |
393 FRAME_PTR f; | |
394 struct face *face; | |
395 { | |
90489
78a820ef12db
(xftfont_prepare_face): Make non-ascii face share
Kenichi Handa <handa@m17n.org>
parents:
90473
diff
changeset
|
396 struct xftface_info *xftface_info; |
90400 | 397 |
90499
32b8f672da38
(xftfont_prepare_face): Cancel previous change.
Kenichi Handa <handa@m17n.org>
parents:
90489
diff
changeset
|
398 #if 0 |
32b8f672da38
(xftfont_prepare_face): Cancel previous change.
Kenichi Handa <handa@m17n.org>
parents:
90489
diff
changeset
|
399 /* This doesn't work if face->ascii_face doesn't use an Xft font. */ |
90489
78a820ef12db
(xftfont_prepare_face): Make non-ascii face share
Kenichi Handa <handa@m17n.org>
parents:
90473
diff
changeset
|
400 if (face != face->ascii_face) |
78a820ef12db
(xftfont_prepare_face): Make non-ascii face share
Kenichi Handa <handa@m17n.org>
parents:
90473
diff
changeset
|
401 { |
78a820ef12db
(xftfont_prepare_face): Make non-ascii face share
Kenichi Handa <handa@m17n.org>
parents:
90473
diff
changeset
|
402 face->extra = face->ascii_face->extra; |
78a820ef12db
(xftfont_prepare_face): Make non-ascii face share
Kenichi Handa <handa@m17n.org>
parents:
90473
diff
changeset
|
403 return 0; |
78a820ef12db
(xftfont_prepare_face): Make non-ascii face share
Kenichi Handa <handa@m17n.org>
parents:
90473
diff
changeset
|
404 } |
90499
32b8f672da38
(xftfont_prepare_face): Cancel previous change.
Kenichi Handa <handa@m17n.org>
parents:
90489
diff
changeset
|
405 #endif |
90489
78a820ef12db
(xftfont_prepare_face): Make non-ascii face share
Kenichi Handa <handa@m17n.org>
parents:
90473
diff
changeset
|
406 |
78a820ef12db
(xftfont_prepare_face): Make non-ascii face share
Kenichi Handa <handa@m17n.org>
parents:
90473
diff
changeset
|
407 xftface_info = malloc (sizeof (struct xftface_info)); |
90400 | 408 if (! xftface_info) |
409 return -1; | |
410 | |
411 BLOCK_INPUT; | |
412 xftface_info->xft_draw = XftDrawCreate (FRAME_X_DISPLAY (f), | |
413 FRAME_X_WINDOW (f), | |
414 FRAME_X_VISUAL (f), | |
415 FRAME_X_COLORMAP (f)); | |
416 xftfont_get_colors (f, face, face->gc, NULL, | |
417 &xftface_info->xft_fg, &xftface_info->xft_bg); | |
418 UNBLOCK_INPUT; | |
419 | |
420 face->extra = xftface_info; | |
421 return 0; | |
422 } | |
423 | |
424 static void | |
425 xftfont_done_face (f, face) | |
426 FRAME_PTR f; | |
427 struct face *face; | |
428 { | |
90489
78a820ef12db
(xftfont_prepare_face): Make non-ascii face share
Kenichi Handa <handa@m17n.org>
parents:
90473
diff
changeset
|
429 struct xftface_info *xftface_info; |
78a820ef12db
(xftfont_prepare_face): Make non-ascii face share
Kenichi Handa <handa@m17n.org>
parents:
90473
diff
changeset
|
430 |
90499
32b8f672da38
(xftfont_prepare_face): Cancel previous change.
Kenichi Handa <handa@m17n.org>
parents:
90489
diff
changeset
|
431 #if 0 |
32b8f672da38
(xftfont_prepare_face): Cancel previous change.
Kenichi Handa <handa@m17n.org>
parents:
90489
diff
changeset
|
432 /* This doesn't work if face->ascii_face doesn't use an Xft font. */ |
90489
78a820ef12db
(xftfont_prepare_face): Make non-ascii face share
Kenichi Handa <handa@m17n.org>
parents:
90473
diff
changeset
|
433 if (face != face->ascii_face |
78a820ef12db
(xftfont_prepare_face): Make non-ascii face share
Kenichi Handa <handa@m17n.org>
parents:
90473
diff
changeset
|
434 || ! face->extra) |
78a820ef12db
(xftfont_prepare_face): Make non-ascii face share
Kenichi Handa <handa@m17n.org>
parents:
90473
diff
changeset
|
435 return; |
90499
32b8f672da38
(xftfont_prepare_face): Cancel previous change.
Kenichi Handa <handa@m17n.org>
parents:
90489
diff
changeset
|
436 #endif |
90400 | 437 |
90489
78a820ef12db
(xftfont_prepare_face): Make non-ascii face share
Kenichi Handa <handa@m17n.org>
parents:
90473
diff
changeset
|
438 xftface_info = (struct xftface_info *) face->extra; |
90527
63b888896eba
* xftfont.c (xftfont_done_face): Call XftDrawDestroy only if xftface_info
Jan Djärv <jan.h.d@swipnet.se>
parents:
90511
diff
changeset
|
439 if (xftface_info) |
63b888896eba
* xftfont.c (xftfont_done_face): Call XftDrawDestroy only if xftface_info
Jan Djärv <jan.h.d@swipnet.se>
parents:
90511
diff
changeset
|
440 { |
63b888896eba
* xftfont.c (xftfont_done_face): Call XftDrawDestroy only if xftface_info
Jan Djärv <jan.h.d@swipnet.se>
parents:
90511
diff
changeset
|
441 BLOCK_INPUT; |
63b888896eba
* xftfont.c (xftfont_done_face): Call XftDrawDestroy only if xftface_info
Jan Djärv <jan.h.d@swipnet.se>
parents:
90511
diff
changeset
|
442 XftDrawDestroy (xftface_info->xft_draw); |
63b888896eba
* xftfont.c (xftfont_done_face): Call XftDrawDestroy only if xftface_info
Jan Djärv <jan.h.d@swipnet.se>
parents:
90511
diff
changeset
|
443 UNBLOCK_INPUT; |
63b888896eba
* xftfont.c (xftfont_done_face): Call XftDrawDestroy only if xftface_info
Jan Djärv <jan.h.d@swipnet.se>
parents:
90511
diff
changeset
|
444 free (xftface_info); |
63b888896eba
* xftfont.c (xftfont_done_face): Call XftDrawDestroy only if xftface_info
Jan Djärv <jan.h.d@swipnet.se>
parents:
90511
diff
changeset
|
445 } |
90489
78a820ef12db
(xftfont_prepare_face): Make non-ascii face share
Kenichi Handa <handa@m17n.org>
parents:
90473
diff
changeset
|
446 face->extra = NULL; |
90400 | 447 } |
448 | |
449 static unsigned | |
450 xftfont_encode_char (font, c) | |
451 struct font *font; | |
452 int c; | |
453 { | |
454 struct xftfont_info *xftfont_info = (struct xftfont_info *) font; | |
455 unsigned code = XftCharIndex (xftfont_info->display, xftfont_info->xftfont, | |
456 (FcChar32) c); | |
457 | |
458 return (code ? code : 0xFFFFFFFF); | |
459 } | |
460 | |
461 static int | |
462 xftfont_text_extents (font, code, nglyphs, metrics) | |
463 struct font *font; | |
464 unsigned *code; | |
465 int nglyphs; | |
466 struct font_metrics *metrics; | |
467 { | |
468 struct xftfont_info *xftfont_info = (struct xftfont_info *) font; | |
469 XGlyphInfo extents; | |
470 | |
471 BLOCK_INPUT; | |
472 XftGlyphExtents (xftfont_info->display, xftfont_info->xftfont, code, nglyphs, | |
473 &extents); | |
474 UNBLOCK_INPUT; | |
475 if (metrics) | |
476 { | |
477 metrics->lbearing = - extents.x; | |
478 metrics->rbearing = - extents.x + extents.width; | |
479 metrics->width = extents.xOff; | |
480 metrics->ascent = extents.y; | |
90616
68d59ef20174
(xftfont_text_extents): Fix calculation of descent
Kenichi Handa <handa@m17n.org>
parents:
90589
diff
changeset
|
481 metrics->descent = extents.height - extents.y; |
90400 | 482 } |
483 return extents.xOff; | |
484 } | |
485 | |
486 static int | |
487 xftfont_draw (s, from, to, x, y, with_background) | |
488 struct glyph_string *s; | |
489 int from, to, x, y, with_background; | |
490 { | |
491 FRAME_PTR f = s->f; | |
492 struct face *face = s->face; | |
91011
7239c19e55e9
(xftfont_draw): If s->font_info != s->face->font_info,
Kenichi Handa <handa@m17n.org>
parents:
90959
diff
changeset
|
493 struct xftfont_info *xftfont_info = (struct xftfont_info *) s->font_info; |
7239c19e55e9
(xftfont_draw): If s->font_info != s->face->font_info,
Kenichi Handa <handa@m17n.org>
parents:
90959
diff
changeset
|
494 struct xftface_info *xftface_info = NULL; |
7239c19e55e9
(xftfont_draw): If s->font_info != s->face->font_info,
Kenichi Handa <handa@m17n.org>
parents:
90959
diff
changeset
|
495 XftDraw *xft_draw = NULL; |
90400 | 496 FT_UInt *code; |
497 XftColor fg, bg; | |
498 XRectangle r; | |
499 int len = to - from; | |
500 int i; | |
501 | |
91011
7239c19e55e9
(xftfont_draw): If s->font_info != s->face->font_info,
Kenichi Handa <handa@m17n.org>
parents:
90959
diff
changeset
|
502 if (s->font_info == face->font_info) |
7239c19e55e9
(xftfont_draw): If s->font_info != s->face->font_info,
Kenichi Handa <handa@m17n.org>
parents:
90959
diff
changeset
|
503 { |
7239c19e55e9
(xftfont_draw): If s->font_info != s->face->font_info,
Kenichi Handa <handa@m17n.org>
parents:
90959
diff
changeset
|
504 xftface_info = (struct xftface_info *) face->extra; |
7239c19e55e9
(xftfont_draw): If s->font_info != s->face->font_info,
Kenichi Handa <handa@m17n.org>
parents:
90959
diff
changeset
|
505 xft_draw = xftface_info->xft_draw; |
7239c19e55e9
(xftfont_draw): If s->font_info != s->face->font_info,
Kenichi Handa <handa@m17n.org>
parents:
90959
diff
changeset
|
506 } |
90400 | 507 xftfont_get_colors (f, face, s->gc, xftface_info, |
90426
e9ed7d437c21
(xftfont_default_fid): Set fid_known to 1.
Kenichi Handa <handa@m17n.org>
parents:
90400
diff
changeset
|
508 &fg, with_background ? &bg : NULL); |
90400 | 509 BLOCK_INPUT; |
91011
7239c19e55e9
(xftfont_draw): If s->font_info != s->face->font_info,
Kenichi Handa <handa@m17n.org>
parents:
90959
diff
changeset
|
510 if (! xft_draw) |
7239c19e55e9
(xftfont_draw): If s->font_info != s->face->font_info,
Kenichi Handa <handa@m17n.org>
parents:
90959
diff
changeset
|
511 xft_draw = XftDrawCreate (FRAME_X_DISPLAY (f), |
7239c19e55e9
(xftfont_draw): If s->font_info != s->face->font_info,
Kenichi Handa <handa@m17n.org>
parents:
90959
diff
changeset
|
512 FRAME_X_WINDOW (f), |
7239c19e55e9
(xftfont_draw): If s->font_info != s->face->font_info,
Kenichi Handa <handa@m17n.org>
parents:
90959
diff
changeset
|
513 FRAME_X_VISUAL (f), |
7239c19e55e9
(xftfont_draw): If s->font_info != s->face->font_info,
Kenichi Handa <handa@m17n.org>
parents:
90959
diff
changeset
|
514 FRAME_X_COLORMAP (f)); |
91027
04b81a720da9
(xftfont_draw): Adjusted for the change of struct
Kenichi Handa <handa@m17n.org>
parents:
91011
diff
changeset
|
515 if (s->num_clips > 0) |
04b81a720da9
(xftfont_draw): Adjusted for the change of struct
Kenichi Handa <handa@m17n.org>
parents:
91011
diff
changeset
|
516 XftDrawSetClipRectangles (xft_draw, 0, 0, s->clip, s->num_clips); |
04b81a720da9
(xftfont_draw): Adjusted for the change of struct
Kenichi Handa <handa@m17n.org>
parents:
91011
diff
changeset
|
517 else |
04b81a720da9
(xftfont_draw): Adjusted for the change of struct
Kenichi Handa <handa@m17n.org>
parents:
91011
diff
changeset
|
518 XftDrawSetClip (xft_draw, NULL); |
04b81a720da9
(xftfont_draw): Adjusted for the change of struct
Kenichi Handa <handa@m17n.org>
parents:
91011
diff
changeset
|
519 |
90400 | 520 if (with_background) |
521 { | |
522 struct font *font = (struct font *) face->font_info; | |
523 | |
91011
7239c19e55e9
(xftfont_draw): If s->font_info != s->face->font_info,
Kenichi Handa <handa@m17n.org>
parents:
90959
diff
changeset
|
524 XftDrawRect (xft_draw, &bg, |
90400 | 525 x, y - face->font->ascent, s->width, font->font.height); |
526 } | |
527 code = alloca (sizeof (FT_UInt) * len); | |
528 for (i = 0; i < len; i++) | |
529 code[i] = ((XCHAR2B_BYTE1 (s->char2b + from + i) << 8) | |
530 | XCHAR2B_BYTE2 (s->char2b + from + i)); | |
531 | |
91011
7239c19e55e9
(xftfont_draw): If s->font_info != s->face->font_info,
Kenichi Handa <handa@m17n.org>
parents:
90959
diff
changeset
|
532 XftDrawGlyphs (xft_draw, &fg, xftfont_info->xftfont, |
90400 | 533 x, y, code, len); |
91011
7239c19e55e9
(xftfont_draw): If s->font_info != s->face->font_info,
Kenichi Handa <handa@m17n.org>
parents:
90959
diff
changeset
|
534 if (s->font_info != face->font_info) |
7239c19e55e9
(xftfont_draw): If s->font_info != s->face->font_info,
Kenichi Handa <handa@m17n.org>
parents:
90959
diff
changeset
|
535 XftDrawDestroy (xft_draw); |
90400 | 536 UNBLOCK_INPUT; |
537 | |
538 return len; | |
539 } | |
540 | |
541 static int | |
542 xftfont_anchor_point (font, code, index, x, y) | |
543 struct font *font; | |
544 unsigned code; | |
545 int index; | |
546 int *x, *y; | |
547 { | |
548 struct xftfont_info *xftfont_info = (struct xftfont_info *) font; | |
549 FT_Face ft_face = xftfont_info->ft_face; | |
550 | |
551 if (FT_Load_Glyph (ft_face, code, FT_LOAD_DEFAULT) != 0) | |
552 return -1; | |
553 if (ft_face->glyph->format != FT_GLYPH_FORMAT_OUTLINE) | |
554 return -1; | |
555 if (index >= ft_face->glyph->outline.n_points) | |
556 return -1; | |
557 *x = ft_face->glyph->outline.points[index].x; | |
558 *y = ft_face->glyph->outline.points[index].y; | |
559 return 0; | |
560 } | |
561 | |
562 | |
563 void | |
564 syms_of_xftfont () | |
565 { | |
566 DEFSYM (Qxft, "xft"); | |
567 | |
568 xftfont_driver = ftfont_driver; | |
569 xftfont_driver.type = Qxft; | |
570 xftfont_driver.get_cache = xfont_driver.get_cache; | |
571 xftfont_driver.list = xftfont_list; | |
90559
fb5d3ac2d786
(xftfont_match): New function.
Kenichi Handa <handa@m17n.org>
parents:
90527
diff
changeset
|
572 xftfont_driver.match = xftfont_match; |
90400 | 573 xftfont_driver.open = xftfont_open; |
574 xftfont_driver.close = xftfont_close; | |
575 xftfont_driver.prepare_face = xftfont_prepare_face; | |
576 xftfont_driver.done_face = xftfont_done_face; | |
577 xftfont_driver.encode_char = xftfont_encode_char; | |
578 xftfont_driver.text_extents = xftfont_text_extents; | |
579 xftfont_driver.draw = xftfont_draw; | |
580 xftfont_driver.anchor_point = xftfont_anchor_point; | |
581 | |
582 register_font_driver (&xftfont_driver, NULL); | |
583 } | |
90427 | 584 |
585 /* arch-tag: 64ec61bf-7c8e-4fe6-b953-c6a85d5e1605 | |
586 (do not change this comment) */ |