Mercurial > emacs
annotate src/xftfont.c @ 95471:6c85f5f5064c
(x_supports_face_attributes_p): Check face->font before
comparing the properties.
author | Kenichi Handa <handa@m17n.org> |
---|---|
date | Mon, 02 Jun 2008 01:49:35 +0000 |
parents | 089ad7a58f94 |
children | 3376493a3ad4 |
rev | line source |
---|---|
90400 | 1 /* xftfont.c -- XFT font driver. |
91556
0920231c95f2
Update copyright years and GPL version.
Glenn Morris <rgm@gnu.org>
parents:
91269
diff
changeset
|
2 Copyright (C) 2006, 2007, 2008 Free Software Foundation, Inc. |
0920231c95f2
Update copyright years and GPL version.
Glenn Morris <rgm@gnu.org>
parents:
91269
diff
changeset
|
3 Copyright (C) 2006, 2007, 2008 |
90400 | 4 National Institute of Advanced Industrial Science and Technology (AIST) |
5 Registration Number H13PRO009 | |
6 | |
7 This file is part of GNU Emacs. | |
8 | |
94963
8971ddf55736
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
94941
diff
changeset
|
9 GNU Emacs is free software: you can redistribute it and/or modify |
90400 | 10 it under the terms of the GNU General Public License as published by |
94963
8971ddf55736
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
94941
diff
changeset
|
11 the Free Software Foundation, either version 3 of the License, or |
8971ddf55736
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
94941
diff
changeset
|
12 (at your option) any later version. |
90400 | 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 | |
94963
8971ddf55736
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
94941
diff
changeset
|
20 along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */ |
90400 | 21 |
22 #include <config.h> | |
23 #include <stdio.h> | |
24 #include <X11/Xlib.h> | |
25 #include <X11/Xft/Xft.h> | |
26 | |
27 #include "lisp.h" | |
28 #include "dispextern.h" | |
29 #include "xterm.h" | |
30 #include "frame.h" | |
31 #include "blockinput.h" | |
32 #include "character.h" | |
33 #include "charset.h" | |
34 #include "fontset.h" | |
35 #include "font.h" | |
91143 | 36 #include "ftfont.h" |
90400 | 37 |
38 /* Xft font driver. */ | |
39 | |
40 static Lisp_Object Qxft; | |
41 | |
42 /* The actual structure for Xft font that can be casted to struct | |
43 font. */ | |
44 | |
45 struct xftfont_info | |
46 { | |
47 struct font font; | |
48 Display *display; | |
49 int screen; | |
50 XftFont *xftfont; | |
91143 | 51 #ifdef HAVE_LIBOTF |
52 int maybe_otf; /* Flag to tell if this may be OTF or not. */ | |
53 OTF *otf; | |
91163 | 54 #endif /* HAVE_LIBOTF */ |
90400 | 55 }; |
56 | |
57 /* Structure pointed by (struct face *)->extra */ | |
90559
fb5d3ac2d786
(xftfont_match): New function.
Kenichi Handa <handa@m17n.org>
parents:
90527
diff
changeset
|
58 |
90400 | 59 struct xftface_info |
60 { | |
90559
fb5d3ac2d786
(xftfont_match): New function.
Kenichi Handa <handa@m17n.org>
parents:
90527
diff
changeset
|
61 XftColor xft_fg; /* color for face->foreground */ |
fb5d3ac2d786
(xftfont_match): New function.
Kenichi Handa <handa@m17n.org>
parents:
90527
diff
changeset
|
62 XftColor xft_bg; /* color for face->background */ |
90400 | 63 }; |
64 | |
65 static void xftfont_get_colors P_ ((FRAME_PTR, struct face *, GC gc, | |
66 struct xftface_info *, | |
67 XftColor *fg, XftColor *bg)); | |
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 | |
135 | |
136 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
|
137 static Lisp_Object xftfont_match P_ ((Lisp_Object, Lisp_Object)); |
94941
8cbdb26068b4
(xftfont_list): Adjusted for the change of `list'
Kenichi Handa <handa@m17n.org>
parents:
92184
diff
changeset
|
138 static Lisp_Object xftfont_open P_ ((FRAME_PTR, Lisp_Object, int)); |
90400 | 139 static void xftfont_close P_ ((FRAME_PTR, struct font *)); |
140 static int xftfont_prepare_face P_ ((FRAME_PTR, struct face *)); | |
141 static void xftfont_done_face P_ ((FRAME_PTR, struct face *)); | |
142 static unsigned xftfont_encode_char P_ ((struct font *, int)); | |
143 static int xftfont_text_extents P_ ((struct font *, unsigned *, int, | |
144 struct font_metrics *)); | |
145 static int xftfont_draw P_ ((struct glyph_string *, int, int, int, int, int)); | |
146 | |
147 static int xftfont_anchor_point P_ ((struct font *, unsigned, int, | |
148 int *, int *)); | |
91110
82a42637237c
(struct xftface_info): Delete the member xft_draw.
Kenichi Handa <handa@m17n.org>
parents:
91027
diff
changeset
|
149 static int xftfont_end_for_frame P_ ((FRAME_PTR f)); |
90400 | 150 |
151 struct font_driver xftfont_driver; | |
152 | |
153 static Lisp_Object | |
154 xftfont_list (frame, spec) | |
155 Lisp_Object frame; | |
156 Lisp_Object spec; | |
157 { | |
94941
8cbdb26068b4
(xftfont_list): Adjusted for the change of `list'
Kenichi Handa <handa@m17n.org>
parents:
92184
diff
changeset
|
158 Lisp_Object list = ftfont_driver.list (frame, spec), tail; |
90400 | 159 |
94941
8cbdb26068b4
(xftfont_list): Adjusted for the change of `list'
Kenichi Handa <handa@m17n.org>
parents:
92184
diff
changeset
|
160 for (tail = list; CONSP (tail); tail = XCDR (tail)) |
8cbdb26068b4
(xftfont_list): Adjusted for the change of `list'
Kenichi Handa <handa@m17n.org>
parents:
92184
diff
changeset
|
161 ASET (XCAR (tail), FONT_TYPE_INDEX, Qxft); |
8cbdb26068b4
(xftfont_list): Adjusted for the change of `list'
Kenichi Handa <handa@m17n.org>
parents:
92184
diff
changeset
|
162 return list; |
90559
fb5d3ac2d786
(xftfont_match): New function.
Kenichi Handa <handa@m17n.org>
parents:
90527
diff
changeset
|
163 } |
90400 | 164 |
90559
fb5d3ac2d786
(xftfont_match): New function.
Kenichi Handa <handa@m17n.org>
parents:
90527
diff
changeset
|
165 static Lisp_Object |
fb5d3ac2d786
(xftfont_match): New function.
Kenichi Handa <handa@m17n.org>
parents:
90527
diff
changeset
|
166 xftfont_match (frame, spec) |
fb5d3ac2d786
(xftfont_match): New function.
Kenichi Handa <handa@m17n.org>
parents:
90527
diff
changeset
|
167 Lisp_Object frame; |
fb5d3ac2d786
(xftfont_match): New function.
Kenichi Handa <handa@m17n.org>
parents:
90527
diff
changeset
|
168 Lisp_Object spec; |
fb5d3ac2d786
(xftfont_match): New function.
Kenichi Handa <handa@m17n.org>
parents:
90527
diff
changeset
|
169 { |
fb5d3ac2d786
(xftfont_match): New function.
Kenichi Handa <handa@m17n.org>
parents:
90527
diff
changeset
|
170 Lisp_Object entity = ftfont_driver.match (frame, spec); |
fb5d3ac2d786
(xftfont_match): New function.
Kenichi Handa <handa@m17n.org>
parents:
90527
diff
changeset
|
171 |
94941
8cbdb26068b4
(xftfont_list): Adjusted for the change of `list'
Kenichi Handa <handa@m17n.org>
parents:
92184
diff
changeset
|
172 if (! NILP (entity)) |
90559
fb5d3ac2d786
(xftfont_match): New function.
Kenichi Handa <handa@m17n.org>
parents:
90527
diff
changeset
|
173 ASET (entity, FONT_TYPE_INDEX, Qxft); |
fb5d3ac2d786
(xftfont_match): New function.
Kenichi Handa <handa@m17n.org>
parents:
90527
diff
changeset
|
174 return entity; |
90400 | 175 } |
176 | |
90700
b165eceb829f
(ftfont_font_format): Extern declaration.
Kenichi Handa <handa@m17n.org>
parents:
90675
diff
changeset
|
177 extern Lisp_Object ftfont_font_format P_ ((FcPattern *)); |
b165eceb829f
(ftfont_font_format): Extern declaration.
Kenichi Handa <handa@m17n.org>
parents:
90675
diff
changeset
|
178 |
90400 | 179 static FcChar8 ascii_printable[95]; |
180 | |
94941
8cbdb26068b4
(xftfont_list): Adjusted for the change of `list'
Kenichi Handa <handa@m17n.org>
parents:
92184
diff
changeset
|
181 static Lisp_Object |
90400 | 182 xftfont_open (f, entity, pixel_size) |
183 FRAME_PTR f; | |
184 Lisp_Object entity; | |
185 int pixel_size; | |
186 { | |
187 Display *display = FRAME_X_DISPLAY (f); | |
95293
089ad7a58f94
(xftfont_open): Delete unused variable. If
Kenichi Handa <handa@m17n.org>
parents:
95102
diff
changeset
|
188 Lisp_Object val, filename, font_object; |
95102
a3868b9c34f4
(xftfont_open): Ajusted for the change of extra info
Kenichi Handa <handa@m17n.org>
parents:
94963
diff
changeset
|
189 FcPattern *pat = NULL; |
90460
86449661f321
(xftfont_open): Change coding style of error
Kenichi Handa <handa@m17n.org>
parents:
90442
diff
changeset
|
190 struct xftfont_info *xftfont_info = NULL; |
90400 | 191 struct font *font; |
192 double size = 0; | |
90460
86449661f321
(xftfont_open): Change coding style of error
Kenichi Handa <handa@m17n.org>
parents:
90442
diff
changeset
|
193 XftFont *xftfont = NULL; |
90400 | 194 int spacing; |
94941
8cbdb26068b4
(xftfont_list): Adjusted for the change of `list'
Kenichi Handa <handa@m17n.org>
parents:
92184
diff
changeset
|
195 char name[256]; |
8cbdb26068b4
(xftfont_list): Adjusted for the change of `list'
Kenichi Handa <handa@m17n.org>
parents:
92184
diff
changeset
|
196 int len, i; |
90959
3f83c9d3f96c
(xftfont_open): If one of font's ASCII glyph has
Kenichi Handa <handa@m17n.org>
parents:
90714
diff
changeset
|
197 XGlyphInfo extents; |
91226
040f2e332dc3
(struct xftfont_info): Delete the member ft_face.
Kenichi Handa <handa@m17n.org>
parents:
91163
diff
changeset
|
198 FT_Face ft_face; |
90400 | 199 |
94941
8cbdb26068b4
(xftfont_list): Adjusted for the change of `list'
Kenichi Handa <handa@m17n.org>
parents:
92184
diff
changeset
|
200 val = assq_no_quit (QCfont_entity, AREF (entity, FONT_EXTRA_INDEX)); |
95102
a3868b9c34f4
(xftfont_open): Ajusted for the change of extra info
Kenichi Handa <handa@m17n.org>
parents:
94963
diff
changeset
|
201 if (! CONSP (val)) |
94941
8cbdb26068b4
(xftfont_list): Adjusted for the change of `list'
Kenichi Handa <handa@m17n.org>
parents:
92184
diff
changeset
|
202 return Qnil; |
95102
a3868b9c34f4
(xftfont_open): Ajusted for the change of extra info
Kenichi Handa <handa@m17n.org>
parents:
94963
diff
changeset
|
203 val = XCDR (val); |
a3868b9c34f4
(xftfont_open): Ajusted for the change of extra info
Kenichi Handa <handa@m17n.org>
parents:
94963
diff
changeset
|
204 filename = XCAR (val); |
90400 | 205 size = XINT (AREF (entity, FONT_SIZE_INDEX)); |
206 if (size == 0) | |
207 size = pixel_size; | |
208 pat = FcPatternCreate (); | |
95102
a3868b9c34f4
(xftfont_open): Ajusted for the change of extra info
Kenichi Handa <handa@m17n.org>
parents:
94963
diff
changeset
|
209 FcPatternAddString (pat, FC_FILE, (FcChar8 *) SDATA (filename)); |
90400 | 210 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
|
211 /*FcPatternAddBool (pat, FC_ANTIALIAS, FcTrue);*/ |
90714
698001835583
(xftfont_open): Call FcConfigSubstitute.
Kenichi Handa <handa@m17n.org>
parents:
90712
diff
changeset
|
212 val = AREF (entity, FONT_FAMILY_INDEX); |
698001835583
(xftfont_open): Call FcConfigSubstitute.
Kenichi Handa <handa@m17n.org>
parents:
90712
diff
changeset
|
213 if (! NILP (val)) |
698001835583
(xftfont_open): Call FcConfigSubstitute.
Kenichi Handa <handa@m17n.org>
parents:
90712
diff
changeset
|
214 FcPatternAddString (pat, FC_FAMILY, (FcChar8 *) SDATA (SYMBOL_NAME (val))); |
698001835583
(xftfont_open): Call FcConfigSubstitute.
Kenichi Handa <handa@m17n.org>
parents:
90712
diff
changeset
|
215 FcConfigSubstitute (NULL, pat, FcMatchPattern); |
90442
d6abf2344438
(xftfont_open): Make the font name fontconfig's
Kenichi Handa <handa@m17n.org>
parents:
90427
diff
changeset
|
216 |
d6abf2344438
(xftfont_open): Make the font name fontconfig's
Kenichi Handa <handa@m17n.org>
parents:
90427
diff
changeset
|
217 BLOCK_INPUT; |
90589
697dcc1df88d
(xftfont_open): Call XftDefaultSubstitute before
Kenichi Handa <handa@m17n.org>
parents:
90559
diff
changeset
|
218 XftDefaultSubstitute (display, FRAME_X_SCREEN_NUMBER (f), pat); |
90400 | 219 xftfont = XftFontOpenPattern (display, pat); |
94941
8cbdb26068b4
(xftfont_list): Adjusted for the change of `list'
Kenichi Handa <handa@m17n.org>
parents:
92184
diff
changeset
|
220 UNBLOCK_INPUT; |
8cbdb26068b4
(xftfont_list): Adjusted for the change of `list'
Kenichi Handa <handa@m17n.org>
parents:
92184
diff
changeset
|
221 if (! xftfont) |
8cbdb26068b4
(xftfont_list): Adjusted for the change of `list'
Kenichi Handa <handa@m17n.org>
parents:
92184
diff
changeset
|
222 return Qnil; |
90400 | 223 /* We should not destroy PAT here because it is kept in XFTFONT and |
224 destroyed automatically when XFTFONT is closed. */ | |
94941
8cbdb26068b4
(xftfont_list): Adjusted for the change of `list'
Kenichi Handa <handa@m17n.org>
parents:
92184
diff
changeset
|
225 font_object = font_make_object (VECSIZE (struct xftfont_info)); |
8cbdb26068b4
(xftfont_list): Adjusted for the change of `list'
Kenichi Handa <handa@m17n.org>
parents:
92184
diff
changeset
|
226 ASET (font_object, FONT_TYPE_INDEX, Qxft); |
8cbdb26068b4
(xftfont_list): Adjusted for the change of `list'
Kenichi Handa <handa@m17n.org>
parents:
92184
diff
changeset
|
227 for (i = 1; i < FONT_ENTITY_MAX; i++) |
8cbdb26068b4
(xftfont_list): Adjusted for the change of `list'
Kenichi Handa <handa@m17n.org>
parents:
92184
diff
changeset
|
228 ASET (font_object, i, AREF (entity, i)); |
8cbdb26068b4
(xftfont_list): Adjusted for the change of `list'
Kenichi Handa <handa@m17n.org>
parents:
92184
diff
changeset
|
229 ASET (font_object, FONT_SIZE_INDEX, make_number (size)); |
8cbdb26068b4
(xftfont_list): Adjusted for the change of `list'
Kenichi Handa <handa@m17n.org>
parents:
92184
diff
changeset
|
230 len = font_unparse_xlfd (entity, size, name, 256); |
8cbdb26068b4
(xftfont_list): Adjusted for the change of `list'
Kenichi Handa <handa@m17n.org>
parents:
92184
diff
changeset
|
231 if (len > 0) |
8cbdb26068b4
(xftfont_list): Adjusted for the change of `list'
Kenichi Handa <handa@m17n.org>
parents:
92184
diff
changeset
|
232 ASET (font_object, FONT_NAME_INDEX, make_unibyte_string (name, len)); |
8cbdb26068b4
(xftfont_list): Adjusted for the change of `list'
Kenichi Handa <handa@m17n.org>
parents:
92184
diff
changeset
|
233 len = font_unparse_fcname (entity, size, name, 256); |
8cbdb26068b4
(xftfont_list): Adjusted for the change of `list'
Kenichi Handa <handa@m17n.org>
parents:
92184
diff
changeset
|
234 if (len > 0) |
8cbdb26068b4
(xftfont_list): Adjusted for the change of `list'
Kenichi Handa <handa@m17n.org>
parents:
92184
diff
changeset
|
235 ASET (font_object, FONT_FULLNAME_INDEX, make_unibyte_string (name, len)); |
8cbdb26068b4
(xftfont_list): Adjusted for the change of `list'
Kenichi Handa <handa@m17n.org>
parents:
92184
diff
changeset
|
236 else |
8cbdb26068b4
(xftfont_list): Adjusted for the change of `list'
Kenichi Handa <handa@m17n.org>
parents:
92184
diff
changeset
|
237 ASET (font_object, FONT_FULLNAME_INDEX, |
8cbdb26068b4
(xftfont_list): Adjusted for the change of `list'
Kenichi Handa <handa@m17n.org>
parents:
92184
diff
changeset
|
238 AREF (font_object, FONT_NAME_INDEX)); |
95102
a3868b9c34f4
(xftfont_open): Ajusted for the change of extra info
Kenichi Handa <handa@m17n.org>
parents:
94963
diff
changeset
|
239 ASET (font_object, FONT_FILE_INDEX, filename); |
a3868b9c34f4
(xftfont_open): Ajusted for the change of extra info
Kenichi Handa <handa@m17n.org>
parents:
94963
diff
changeset
|
240 ASET (font_object, FONT_FORMAT_INDEX, |
a3868b9c34f4
(xftfont_open): Ajusted for the change of extra info
Kenichi Handa <handa@m17n.org>
parents:
94963
diff
changeset
|
241 ftfont_font_format (xftfont->pattern)); |
94941
8cbdb26068b4
(xftfont_list): Adjusted for the change of `list'
Kenichi Handa <handa@m17n.org>
parents:
92184
diff
changeset
|
242 font = XFONT_OBJECT (font_object); |
8cbdb26068b4
(xftfont_list): Adjusted for the change of `list'
Kenichi Handa <handa@m17n.org>
parents:
92184
diff
changeset
|
243 font->pixel_size = pixel_size; |
8cbdb26068b4
(xftfont_list): Adjusted for the change of `list'
Kenichi Handa <handa@m17n.org>
parents:
92184
diff
changeset
|
244 font->driver = &xftfont_driver; |
8cbdb26068b4
(xftfont_list): Adjusted for the change of `list'
Kenichi Handa <handa@m17n.org>
parents:
92184
diff
changeset
|
245 font->encoding_charset = font->repertory_charset = -1; |
90400 | 246 |
94941
8cbdb26068b4
(xftfont_list): Adjusted for the change of `list'
Kenichi Handa <handa@m17n.org>
parents:
92184
diff
changeset
|
247 xftfont_info = (struct xftfont_info *) font; |
90400 | 248 xftfont_info->display = display; |
249 xftfont_info->screen = FRAME_X_SCREEN_NUMBER (f); | |
250 xftfont_info->xftfont = xftfont; | |
251 font->pixel_size = size; | |
252 font->driver = &xftfont_driver; | |
95102
a3868b9c34f4
(xftfont_open): Ajusted for the change of extra info
Kenichi Handa <handa@m17n.org>
parents:
94963
diff
changeset
|
253 if (INTEGERP (AREF (entity, FONT_SPACING_INDEX))) |
a3868b9c34f4
(xftfont_open): Ajusted for the change of extra info
Kenichi Handa <handa@m17n.org>
parents:
94963
diff
changeset
|
254 spacing = XINT (AREF (entity, FONT_SPACING_INDEX)); |
a3868b9c34f4
(xftfont_open): Ajusted for the change of extra info
Kenichi Handa <handa@m17n.org>
parents:
94963
diff
changeset
|
255 else |
90400 | 256 spacing = FC_PROPORTIONAL; |
90959
3f83c9d3f96c
(xftfont_open): If one of font's ASCII glyph has
Kenichi Handa <handa@m17n.org>
parents:
90714
diff
changeset
|
257 if (! ascii_printable[0]) |
3f83c9d3f96c
(xftfont_open): If one of font's ASCII glyph has
Kenichi Handa <handa@m17n.org>
parents:
90714
diff
changeset
|
258 { |
3f83c9d3f96c
(xftfont_open): If one of font's ASCII glyph has
Kenichi Handa <handa@m17n.org>
parents:
90714
diff
changeset
|
259 int i; |
3f83c9d3f96c
(xftfont_open): If one of font's ASCII glyph has
Kenichi Handa <handa@m17n.org>
parents:
90714
diff
changeset
|
260 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
|
261 ascii_printable[i] = ' ' + i; |
3f83c9d3f96c
(xftfont_open): If one of font's ASCII glyph has
Kenichi Handa <handa@m17n.org>
parents:
90714
diff
changeset
|
262 } |
94941
8cbdb26068b4
(xftfont_list): Adjusted for the change of `list'
Kenichi Handa <handa@m17n.org>
parents:
92184
diff
changeset
|
263 BLOCK_INPUT; |
90400 | 264 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
|
265 { |
94941
8cbdb26068b4
(xftfont_list): Adjusted for the change of `list'
Kenichi Handa <handa@m17n.org>
parents:
92184
diff
changeset
|
266 font->min_width = font->average_width = font->space_width |
90959
3f83c9d3f96c
(xftfont_open): If one of font's ASCII glyph has
Kenichi Handa <handa@m17n.org>
parents:
90714
diff
changeset
|
267 = xftfont->max_advance_width; |
3f83c9d3f96c
(xftfont_open): If one of font's ASCII glyph has
Kenichi Handa <handa@m17n.org>
parents:
90714
diff
changeset
|
268 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
|
269 } |
90400 | 270 else |
271 { | |
272 XftTextExtents8 (display, xftfont, ascii_printable, 1, &extents); | |
94941
8cbdb26068b4
(xftfont_list): Adjusted for the change of `list'
Kenichi Handa <handa@m17n.org>
parents:
92184
diff
changeset
|
273 font->space_width = extents.xOff; |
8cbdb26068b4
(xftfont_list): Adjusted for the change of `list'
Kenichi Handa <handa@m17n.org>
parents:
92184
diff
changeset
|
274 if (font->space_width <= 0) |
90400 | 275 /* dirty workaround */ |
94941
8cbdb26068b4
(xftfont_list): Adjusted for the change of `list'
Kenichi Handa <handa@m17n.org>
parents:
92184
diff
changeset
|
276 font->space_width = pixel_size; |
90400 | 277 XftTextExtents8 (display, xftfont, ascii_printable + 1, 94, &extents); |
94941
8cbdb26068b4
(xftfont_list): Adjusted for the change of `list'
Kenichi Handa <handa@m17n.org>
parents:
92184
diff
changeset
|
278 font->average_width = (font->space_width + extents.xOff) / 95; |
90400 | 279 } |
90442
d6abf2344438
(xftfont_open): Make the font name fontconfig's
Kenichi Handa <handa@m17n.org>
parents:
90427
diff
changeset
|
280 UNBLOCK_INPUT; |
90400 | 281 |
90959
3f83c9d3f96c
(xftfont_open): If one of font's ASCII glyph has
Kenichi Handa <handa@m17n.org>
parents:
90714
diff
changeset
|
282 font->ascent = xftfont->ascent; |
3f83c9d3f96c
(xftfont_open): If one of font's ASCII glyph has
Kenichi Handa <handa@m17n.org>
parents:
90714
diff
changeset
|
283 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
|
284 font->ascent = extents.y; |
3f83c9d3f96c
(xftfont_open): If one of font's ASCII glyph has
Kenichi Handa <handa@m17n.org>
parents:
90714
diff
changeset
|
285 font->descent = xftfont->descent; |
3f83c9d3f96c
(xftfont_open): If one of font's ASCII glyph has
Kenichi Handa <handa@m17n.org>
parents:
90714
diff
changeset
|
286 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
|
287 font->descent = extents.height - extents.y; |
94941
8cbdb26068b4
(xftfont_list): Adjusted for the change of `list'
Kenichi Handa <handa@m17n.org>
parents:
92184
diff
changeset
|
288 font->height = font->ascent + font->descent; |
8cbdb26068b4
(xftfont_list): Adjusted for the change of `list'
Kenichi Handa <handa@m17n.org>
parents:
92184
diff
changeset
|
289 |
8cbdb26068b4
(xftfont_list): Adjusted for the change of `list'
Kenichi Handa <handa@m17n.org>
parents:
92184
diff
changeset
|
290 ft_face = XftLockFace (xftfont); |
8cbdb26068b4
(xftfont_list): Adjusted for the change of `list'
Kenichi Handa <handa@m17n.org>
parents:
92184
diff
changeset
|
291 if (XINT (AREF (entity, FONT_SIZE_INDEX)) == 0) |
8cbdb26068b4
(xftfont_list): Adjusted for the change of `list'
Kenichi Handa <handa@m17n.org>
parents:
92184
diff
changeset
|
292 { |
8cbdb26068b4
(xftfont_list): Adjusted for the change of `list'
Kenichi Handa <handa@m17n.org>
parents:
92184
diff
changeset
|
293 int upEM = ft_face->units_per_EM; |
8cbdb26068b4
(xftfont_list): Adjusted for the change of `list'
Kenichi Handa <handa@m17n.org>
parents:
92184
diff
changeset
|
294 |
8cbdb26068b4
(xftfont_list): Adjusted for the change of `list'
Kenichi Handa <handa@m17n.org>
parents:
92184
diff
changeset
|
295 font->underline_position = -ft_face->underline_position * size / upEM; |
8cbdb26068b4
(xftfont_list): Adjusted for the change of `list'
Kenichi Handa <handa@m17n.org>
parents:
92184
diff
changeset
|
296 font->underline_thickness = -ft_face->underline_thickness * size / upEM; |
95293
089ad7a58f94
(xftfont_open): Delete unused variable. If
Kenichi Handa <handa@m17n.org>
parents:
95102
diff
changeset
|
297 if (font->underline_thickness > 2) |
089ad7a58f94
(xftfont_open): Delete unused variable. If
Kenichi Handa <handa@m17n.org>
parents:
95102
diff
changeset
|
298 font->underline_position -= font->underline_thickness / 2; |
94941
8cbdb26068b4
(xftfont_list): Adjusted for the change of `list'
Kenichi Handa <handa@m17n.org>
parents:
92184
diff
changeset
|
299 } |
8cbdb26068b4
(xftfont_list): Adjusted for the change of `list'
Kenichi Handa <handa@m17n.org>
parents:
92184
diff
changeset
|
300 else |
8cbdb26068b4
(xftfont_list): Adjusted for the change of `list'
Kenichi Handa <handa@m17n.org>
parents:
92184
diff
changeset
|
301 { |
8cbdb26068b4
(xftfont_list): Adjusted for the change of `list'
Kenichi Handa <handa@m17n.org>
parents:
92184
diff
changeset
|
302 font->underline_position = -1; |
8cbdb26068b4
(xftfont_list): Adjusted for the change of `list'
Kenichi Handa <handa@m17n.org>
parents:
92184
diff
changeset
|
303 font->underline_thickness = 0; |
8cbdb26068b4
(xftfont_list): Adjusted for the change of `list'
Kenichi Handa <handa@m17n.org>
parents:
92184
diff
changeset
|
304 } |
8cbdb26068b4
(xftfont_list): Adjusted for the change of `list'
Kenichi Handa <handa@m17n.org>
parents:
92184
diff
changeset
|
305 #ifdef HAVE_LIBOTF |
8cbdb26068b4
(xftfont_list): Adjusted for the change of `list'
Kenichi Handa <handa@m17n.org>
parents:
92184
diff
changeset
|
306 xftfont_info->maybe_otf = ft_face->face_flags & FT_FACE_FLAG_SFNT; |
8cbdb26068b4
(xftfont_list): Adjusted for the change of `list'
Kenichi Handa <handa@m17n.org>
parents:
92184
diff
changeset
|
307 xftfont_info->otf = NULL; |
8cbdb26068b4
(xftfont_list): Adjusted for the change of `list'
Kenichi Handa <handa@m17n.org>
parents:
92184
diff
changeset
|
308 #endif /* HAVE_LIBOTF */ |
8cbdb26068b4
(xftfont_list): Adjusted for the change of `list'
Kenichi Handa <handa@m17n.org>
parents:
92184
diff
changeset
|
309 XftUnlockFace (xftfont); |
90959
3f83c9d3f96c
(xftfont_open): If one of font's ASCII glyph has
Kenichi Handa <handa@m17n.org>
parents:
90714
diff
changeset
|
310 |
90400 | 311 /* Unfortunately Xft doesn't provide a way to get minimum char |
312 width. So, we use space_width instead. */ | |
94941
8cbdb26068b4
(xftfont_list): Adjusted for the change of `list'
Kenichi Handa <handa@m17n.org>
parents:
92184
diff
changeset
|
313 font->min_width = font->space_width; |
90400 | 314 |
94941
8cbdb26068b4
(xftfont_list): Adjusted for the change of `list'
Kenichi Handa <handa@m17n.org>
parents:
92184
diff
changeset
|
315 font->baseline_offset = 0; |
8cbdb26068b4
(xftfont_list): Adjusted for the change of `list'
Kenichi Handa <handa@m17n.org>
parents:
92184
diff
changeset
|
316 font->relative_compose = 0; |
8cbdb26068b4
(xftfont_list): Adjusted for the change of `list'
Kenichi Handa <handa@m17n.org>
parents:
92184
diff
changeset
|
317 font->default_ascent = 0; |
8cbdb26068b4
(xftfont_list): Adjusted for the change of `list'
Kenichi Handa <handa@m17n.org>
parents:
92184
diff
changeset
|
318 font->vertical_centering = 0; |
90400 | 319 |
94941
8cbdb26068b4
(xftfont_list): Adjusted for the change of `list'
Kenichi Handa <handa@m17n.org>
parents:
92184
diff
changeset
|
320 return font_object; |
90400 | 321 } |
322 | |
323 static void | |
324 xftfont_close (f, font) | |
325 FRAME_PTR f; | |
326 struct font *font; | |
327 { | |
328 struct xftfont_info *xftfont_info = (struct xftfont_info *) font; | |
329 | |
91143 | 330 #ifdef HAVE_LIBOTF |
331 if (xftfont_info->otf) | |
332 OTF_close (xftfont_info->otf); | |
333 #endif | |
94941
8cbdb26068b4
(xftfont_list): Adjusted for the change of `list'
Kenichi Handa <handa@m17n.org>
parents:
92184
diff
changeset
|
334 BLOCK_INPUT; |
90400 | 335 XftFontClose (xftfont_info->display, xftfont_info->xftfont); |
94941
8cbdb26068b4
(xftfont_list): Adjusted for the change of `list'
Kenichi Handa <handa@m17n.org>
parents:
92184
diff
changeset
|
336 UNBLOCK_INPUT; |
90400 | 337 } |
338 | |
339 static int | |
340 xftfont_prepare_face (f, face) | |
341 FRAME_PTR f; | |
342 struct face *face; | |
343 { | |
90489
78a820ef12db
(xftfont_prepare_face): Make non-ascii face share
Kenichi Handa <handa@m17n.org>
parents:
90473
diff
changeset
|
344 struct xftface_info *xftface_info; |
90400 | 345 |
90499
32b8f672da38
(xftfont_prepare_face): Cancel previous change.
Kenichi Handa <handa@m17n.org>
parents:
90489
diff
changeset
|
346 #if 0 |
32b8f672da38
(xftfont_prepare_face): Cancel previous change.
Kenichi Handa <handa@m17n.org>
parents:
90489
diff
changeset
|
347 /* 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
|
348 if (face != face->ascii_face) |
78a820ef12db
(xftfont_prepare_face): Make non-ascii face share
Kenichi Handa <handa@m17n.org>
parents:
90473
diff
changeset
|
349 { |
78a820ef12db
(xftfont_prepare_face): Make non-ascii face share
Kenichi Handa <handa@m17n.org>
parents:
90473
diff
changeset
|
350 face->extra = face->ascii_face->extra; |
78a820ef12db
(xftfont_prepare_face): Make non-ascii face share
Kenichi Handa <handa@m17n.org>
parents:
90473
diff
changeset
|
351 return 0; |
78a820ef12db
(xftfont_prepare_face): Make non-ascii face share
Kenichi Handa <handa@m17n.org>
parents:
90473
diff
changeset
|
352 } |
90499
32b8f672da38
(xftfont_prepare_face): Cancel previous change.
Kenichi Handa <handa@m17n.org>
parents:
90489
diff
changeset
|
353 #endif |
90489
78a820ef12db
(xftfont_prepare_face): Make non-ascii face share
Kenichi Handa <handa@m17n.org>
parents:
90473
diff
changeset
|
354 |
78a820ef12db
(xftfont_prepare_face): Make non-ascii face share
Kenichi Handa <handa@m17n.org>
parents:
90473
diff
changeset
|
355 xftface_info = malloc (sizeof (struct xftface_info)); |
90400 | 356 if (! xftface_info) |
357 return -1; | |
358 xftfont_get_colors (f, face, face->gc, NULL, | |
359 &xftface_info->xft_fg, &xftface_info->xft_bg); | |
360 face->extra = xftface_info; | |
361 return 0; | |
362 } | |
363 | |
364 static void | |
365 xftfont_done_face (f, face) | |
366 FRAME_PTR f; | |
367 struct face *face; | |
368 { | |
90489
78a820ef12db
(xftfont_prepare_face): Make non-ascii face share
Kenichi Handa <handa@m17n.org>
parents:
90473
diff
changeset
|
369 struct xftface_info *xftface_info; |
78a820ef12db
(xftfont_prepare_face): Make non-ascii face share
Kenichi Handa <handa@m17n.org>
parents:
90473
diff
changeset
|
370 |
90499
32b8f672da38
(xftfont_prepare_face): Cancel previous change.
Kenichi Handa <handa@m17n.org>
parents:
90489
diff
changeset
|
371 #if 0 |
32b8f672da38
(xftfont_prepare_face): Cancel previous change.
Kenichi Handa <handa@m17n.org>
parents:
90489
diff
changeset
|
372 /* 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
|
373 if (face != face->ascii_face |
78a820ef12db
(xftfont_prepare_face): Make non-ascii face share
Kenichi Handa <handa@m17n.org>
parents:
90473
diff
changeset
|
374 || ! face->extra) |
78a820ef12db
(xftfont_prepare_face): Make non-ascii face share
Kenichi Handa <handa@m17n.org>
parents:
90473
diff
changeset
|
375 return; |
90499
32b8f672da38
(xftfont_prepare_face): Cancel previous change.
Kenichi Handa <handa@m17n.org>
parents:
90489
diff
changeset
|
376 #endif |
90400 | 377 |
90489
78a820ef12db
(xftfont_prepare_face): Make non-ascii face share
Kenichi Handa <handa@m17n.org>
parents:
90473
diff
changeset
|
378 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
|
379 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
|
380 { |
63b888896eba
* xftfont.c (xftfont_done_face): Call XftDrawDestroy only if xftface_info
Jan Djärv <jan.h.d@swipnet.se>
parents:
90511
diff
changeset
|
381 free (xftface_info); |
91110
82a42637237c
(struct xftface_info): Delete the member xft_draw.
Kenichi Handa <handa@m17n.org>
parents:
91027
diff
changeset
|
382 face->extra = NULL; |
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
|
383 } |
90400 | 384 } |
385 | |
386 static unsigned | |
387 xftfont_encode_char (font, c) | |
388 struct font *font; | |
389 int c; | |
390 { | |
391 struct xftfont_info *xftfont_info = (struct xftfont_info *) font; | |
392 unsigned code = XftCharIndex (xftfont_info->display, xftfont_info->xftfont, | |
393 (FcChar32) c); | |
394 | |
91269
421d7c7d296a
(xftfont_encode_char): Use the macro FONT_INVALID_CODE.
Kenichi Handa <handa@m17n.org>
parents:
91243
diff
changeset
|
395 return (code ? code : FONT_INVALID_CODE); |
90400 | 396 } |
397 | |
398 static int | |
399 xftfont_text_extents (font, code, nglyphs, metrics) | |
400 struct font *font; | |
401 unsigned *code; | |
402 int nglyphs; | |
403 struct font_metrics *metrics; | |
404 { | |
405 struct xftfont_info *xftfont_info = (struct xftfont_info *) font; | |
406 XGlyphInfo extents; | |
407 | |
408 BLOCK_INPUT; | |
409 XftGlyphExtents (xftfont_info->display, xftfont_info->xftfont, code, nglyphs, | |
410 &extents); | |
411 UNBLOCK_INPUT; | |
412 if (metrics) | |
413 { | |
414 metrics->lbearing = - extents.x; | |
415 metrics->rbearing = - extents.x + extents.width; | |
416 metrics->width = extents.xOff; | |
417 metrics->ascent = extents.y; | |
90616
68d59ef20174
(xftfont_text_extents): Fix calculation of descent
Kenichi Handa <handa@m17n.org>
parents:
90589
diff
changeset
|
418 metrics->descent = extents.height - extents.y; |
90400 | 419 } |
420 return extents.xOff; | |
421 } | |
422 | |
91110
82a42637237c
(struct xftface_info): Delete the member xft_draw.
Kenichi Handa <handa@m17n.org>
parents:
91027
diff
changeset
|
423 static XftDraw * |
82a42637237c
(struct xftface_info): Delete the member xft_draw.
Kenichi Handa <handa@m17n.org>
parents:
91027
diff
changeset
|
424 xftfont_get_xft_draw (f) |
82a42637237c
(struct xftface_info): Delete the member xft_draw.
Kenichi Handa <handa@m17n.org>
parents:
91027
diff
changeset
|
425 FRAME_PTR f; |
82a42637237c
(struct xftface_info): Delete the member xft_draw.
Kenichi Handa <handa@m17n.org>
parents:
91027
diff
changeset
|
426 { |
82a42637237c
(struct xftface_info): Delete the member xft_draw.
Kenichi Handa <handa@m17n.org>
parents:
91027
diff
changeset
|
427 XftDraw *xft_draw = font_get_frame_data (f, &xftfont_driver);; |
82a42637237c
(struct xftface_info): Delete the member xft_draw.
Kenichi Handa <handa@m17n.org>
parents:
91027
diff
changeset
|
428 |
82a42637237c
(struct xftface_info): Delete the member xft_draw.
Kenichi Handa <handa@m17n.org>
parents:
91027
diff
changeset
|
429 if (! xft_draw) |
82a42637237c
(struct xftface_info): Delete the member xft_draw.
Kenichi Handa <handa@m17n.org>
parents:
91027
diff
changeset
|
430 { |
82a42637237c
(struct xftface_info): Delete the member xft_draw.
Kenichi Handa <handa@m17n.org>
parents:
91027
diff
changeset
|
431 BLOCK_INPUT; |
82a42637237c
(struct xftface_info): Delete the member xft_draw.
Kenichi Handa <handa@m17n.org>
parents:
91027
diff
changeset
|
432 xft_draw= XftDrawCreate (FRAME_X_DISPLAY (f), |
82a42637237c
(struct xftface_info): Delete the member xft_draw.
Kenichi Handa <handa@m17n.org>
parents:
91027
diff
changeset
|
433 FRAME_X_WINDOW (f), |
82a42637237c
(struct xftface_info): Delete the member xft_draw.
Kenichi Handa <handa@m17n.org>
parents:
91027
diff
changeset
|
434 FRAME_X_VISUAL (f), |
82a42637237c
(struct xftface_info): Delete the member xft_draw.
Kenichi Handa <handa@m17n.org>
parents:
91027
diff
changeset
|
435 FRAME_X_COLORMAP (f)); |
82a42637237c
(struct xftface_info): Delete the member xft_draw.
Kenichi Handa <handa@m17n.org>
parents:
91027
diff
changeset
|
436 UNBLOCK_INPUT; |
82a42637237c
(struct xftface_info): Delete the member xft_draw.
Kenichi Handa <handa@m17n.org>
parents:
91027
diff
changeset
|
437 if (! xft_draw) |
82a42637237c
(struct xftface_info): Delete the member xft_draw.
Kenichi Handa <handa@m17n.org>
parents:
91027
diff
changeset
|
438 abort (); |
82a42637237c
(struct xftface_info): Delete the member xft_draw.
Kenichi Handa <handa@m17n.org>
parents:
91027
diff
changeset
|
439 font_put_frame_data (f, &xftfont_driver, xft_draw); |
82a42637237c
(struct xftface_info): Delete the member xft_draw.
Kenichi Handa <handa@m17n.org>
parents:
91027
diff
changeset
|
440 } |
82a42637237c
(struct xftface_info): Delete the member xft_draw.
Kenichi Handa <handa@m17n.org>
parents:
91027
diff
changeset
|
441 return xft_draw; |
82a42637237c
(struct xftface_info): Delete the member xft_draw.
Kenichi Handa <handa@m17n.org>
parents:
91027
diff
changeset
|
442 } |
82a42637237c
(struct xftface_info): Delete the member xft_draw.
Kenichi Handa <handa@m17n.org>
parents:
91027
diff
changeset
|
443 |
90400 | 444 static int |
445 xftfont_draw (s, from, to, x, y, with_background) | |
446 struct glyph_string *s; | |
447 int from, to, x, y, with_background; | |
448 { | |
449 FRAME_PTR f = s->f; | |
450 struct face *face = s->face; | |
94941
8cbdb26068b4
(xftfont_list): Adjusted for the change of `list'
Kenichi Handa <handa@m17n.org>
parents:
92184
diff
changeset
|
451 struct xftfont_info *xftfont_info = (struct xftfont_info *) s->font; |
91011
7239c19e55e9
(xftfont_draw): If s->font_info != s->face->font_info,
Kenichi Handa <handa@m17n.org>
parents:
90959
diff
changeset
|
452 struct xftface_info *xftface_info = NULL; |
91110
82a42637237c
(struct xftface_info): Delete the member xft_draw.
Kenichi Handa <handa@m17n.org>
parents:
91027
diff
changeset
|
453 XftDraw *xft_draw = xftfont_get_xft_draw (f); |
90400 | 454 FT_UInt *code; |
455 XftColor fg, bg; | |
456 int len = to - from; | |
457 int i; | |
458 | |
94941
8cbdb26068b4
(xftfont_list): Adjusted for the change of `list'
Kenichi Handa <handa@m17n.org>
parents:
92184
diff
changeset
|
459 if (s->font == face->font) |
91110
82a42637237c
(struct xftface_info): Delete the member xft_draw.
Kenichi Handa <handa@m17n.org>
parents:
91027
diff
changeset
|
460 xftface_info = (struct xftface_info *) face->extra; |
90400 | 461 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
|
462 &fg, with_background ? &bg : NULL); |
90400 | 463 BLOCK_INPUT; |
91027
04b81a720da9
(xftfont_draw): Adjusted for the change of struct
Kenichi Handa <handa@m17n.org>
parents:
91011
diff
changeset
|
464 if (s->num_clips > 0) |
04b81a720da9
(xftfont_draw): Adjusted for the change of struct
Kenichi Handa <handa@m17n.org>
parents:
91011
diff
changeset
|
465 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
|
466 else |
04b81a720da9
(xftfont_draw): Adjusted for the change of struct
Kenichi Handa <handa@m17n.org>
parents:
91011
diff
changeset
|
467 XftDrawSetClip (xft_draw, NULL); |
04b81a720da9
(xftfont_draw): Adjusted for the change of struct
Kenichi Handa <handa@m17n.org>
parents:
91011
diff
changeset
|
468 |
90400 | 469 if (with_background) |
94941
8cbdb26068b4
(xftfont_list): Adjusted for the change of `list'
Kenichi Handa <handa@m17n.org>
parents:
92184
diff
changeset
|
470 XftDrawRect (xft_draw, &bg, |
8cbdb26068b4
(xftfont_list): Adjusted for the change of `list'
Kenichi Handa <handa@m17n.org>
parents:
92184
diff
changeset
|
471 x, y - face->font->ascent, s->width, face->font->height); |
90400 | 472 code = alloca (sizeof (FT_UInt) * len); |
473 for (i = 0; i < len; i++) | |
474 code[i] = ((XCHAR2B_BYTE1 (s->char2b + from + i) << 8) | |
475 | XCHAR2B_BYTE2 (s->char2b + from + i)); | |
476 | |
92184
6218afb021ac
(xftfont_draw): Pay attention to s->padding_p.
Kenichi Handa <handa@m17n.org>
parents:
91907
diff
changeset
|
477 if (s->padding_p) |
6218afb021ac
(xftfont_draw): Pay attention to s->padding_p.
Kenichi Handa <handa@m17n.org>
parents:
91907
diff
changeset
|
478 for (i = 0; i < len; i++) |
6218afb021ac
(xftfont_draw): Pay attention to s->padding_p.
Kenichi Handa <handa@m17n.org>
parents:
91907
diff
changeset
|
479 XftDrawGlyphs (xft_draw, &fg, xftfont_info->xftfont, |
6218afb021ac
(xftfont_draw): Pay attention to s->padding_p.
Kenichi Handa <handa@m17n.org>
parents:
91907
diff
changeset
|
480 x + i, y, code + i, 1); |
6218afb021ac
(xftfont_draw): Pay attention to s->padding_p.
Kenichi Handa <handa@m17n.org>
parents:
91907
diff
changeset
|
481 else |
6218afb021ac
(xftfont_draw): Pay attention to s->padding_p.
Kenichi Handa <handa@m17n.org>
parents:
91907
diff
changeset
|
482 XftDrawGlyphs (xft_draw, &fg, xftfont_info->xftfont, |
6218afb021ac
(xftfont_draw): Pay attention to s->padding_p.
Kenichi Handa <handa@m17n.org>
parents:
91907
diff
changeset
|
483 x, y, code, len); |
90400 | 484 UNBLOCK_INPUT; |
485 | |
486 return len; | |
487 } | |
488 | |
489 static int | |
490 xftfont_anchor_point (font, code, index, x, y) | |
491 struct font *font; | |
492 unsigned code; | |
493 int index; | |
494 int *x, *y; | |
495 { | |
496 struct xftfont_info *xftfont_info = (struct xftfont_info *) font; | |
91226
040f2e332dc3
(struct xftfont_info): Delete the member ft_face.
Kenichi Handa <handa@m17n.org>
parents:
91163
diff
changeset
|
497 FT_Face ft_face = XftLockFace (xftfont_info->xftfont); |
040f2e332dc3
(struct xftfont_info): Delete the member ft_face.
Kenichi Handa <handa@m17n.org>
parents:
91163
diff
changeset
|
498 int result; |
90400 | 499 |
500 if (FT_Load_Glyph (ft_face, code, FT_LOAD_DEFAULT) != 0) | |
91226
040f2e332dc3
(struct xftfont_info): Delete the member ft_face.
Kenichi Handa <handa@m17n.org>
parents:
91163
diff
changeset
|
501 result = -1; |
040f2e332dc3
(struct xftfont_info): Delete the member ft_face.
Kenichi Handa <handa@m17n.org>
parents:
91163
diff
changeset
|
502 else if (ft_face->glyph->format != FT_GLYPH_FORMAT_OUTLINE) |
040f2e332dc3
(struct xftfont_info): Delete the member ft_face.
Kenichi Handa <handa@m17n.org>
parents:
91163
diff
changeset
|
503 result = -1; |
040f2e332dc3
(struct xftfont_info): Delete the member ft_face.
Kenichi Handa <handa@m17n.org>
parents:
91163
diff
changeset
|
504 else if (index >= ft_face->glyph->outline.n_points) |
040f2e332dc3
(struct xftfont_info): Delete the member ft_face.
Kenichi Handa <handa@m17n.org>
parents:
91163
diff
changeset
|
505 result = -1; |
040f2e332dc3
(struct xftfont_info): Delete the member ft_face.
Kenichi Handa <handa@m17n.org>
parents:
91163
diff
changeset
|
506 else |
040f2e332dc3
(struct xftfont_info): Delete the member ft_face.
Kenichi Handa <handa@m17n.org>
parents:
91163
diff
changeset
|
507 { |
040f2e332dc3
(struct xftfont_info): Delete the member ft_face.
Kenichi Handa <handa@m17n.org>
parents:
91163
diff
changeset
|
508 *x = ft_face->glyph->outline.points[index].x; |
040f2e332dc3
(struct xftfont_info): Delete the member ft_face.
Kenichi Handa <handa@m17n.org>
parents:
91163
diff
changeset
|
509 *y = ft_face->glyph->outline.points[index].y; |
040f2e332dc3
(struct xftfont_info): Delete the member ft_face.
Kenichi Handa <handa@m17n.org>
parents:
91163
diff
changeset
|
510 } |
040f2e332dc3
(struct xftfont_info): Delete the member ft_face.
Kenichi Handa <handa@m17n.org>
parents:
91163
diff
changeset
|
511 XftUnlockFace (xftfont_info->xftfont); |
040f2e332dc3
(struct xftfont_info): Delete the member ft_face.
Kenichi Handa <handa@m17n.org>
parents:
91163
diff
changeset
|
512 return result; |
90400 | 513 } |
514 | |
91110
82a42637237c
(struct xftface_info): Delete the member xft_draw.
Kenichi Handa <handa@m17n.org>
parents:
91027
diff
changeset
|
515 static int |
82a42637237c
(struct xftface_info): Delete the member xft_draw.
Kenichi Handa <handa@m17n.org>
parents:
91027
diff
changeset
|
516 xftfont_end_for_frame (f) |
82a42637237c
(struct xftface_info): Delete the member xft_draw.
Kenichi Handa <handa@m17n.org>
parents:
91027
diff
changeset
|
517 FRAME_PTR f; |
82a42637237c
(struct xftface_info): Delete the member xft_draw.
Kenichi Handa <handa@m17n.org>
parents:
91027
diff
changeset
|
518 { |
82a42637237c
(struct xftface_info): Delete the member xft_draw.
Kenichi Handa <handa@m17n.org>
parents:
91027
diff
changeset
|
519 XftDraw *xft_draw = font_get_frame_data (f, &xftfont_driver); |
82a42637237c
(struct xftface_info): Delete the member xft_draw.
Kenichi Handa <handa@m17n.org>
parents:
91027
diff
changeset
|
520 |
82a42637237c
(struct xftface_info): Delete the member xft_draw.
Kenichi Handa <handa@m17n.org>
parents:
91027
diff
changeset
|
521 if (xft_draw) |
82a42637237c
(struct xftface_info): Delete the member xft_draw.
Kenichi Handa <handa@m17n.org>
parents:
91027
diff
changeset
|
522 { |
82a42637237c
(struct xftface_info): Delete the member xft_draw.
Kenichi Handa <handa@m17n.org>
parents:
91027
diff
changeset
|
523 BLOCK_INPUT; |
82a42637237c
(struct xftface_info): Delete the member xft_draw.
Kenichi Handa <handa@m17n.org>
parents:
91027
diff
changeset
|
524 XftDrawDestroy (xft_draw); |
82a42637237c
(struct xftface_info): Delete the member xft_draw.
Kenichi Handa <handa@m17n.org>
parents:
91027
diff
changeset
|
525 UNBLOCK_INPUT; |
82a42637237c
(struct xftface_info): Delete the member xft_draw.
Kenichi Handa <handa@m17n.org>
parents:
91027
diff
changeset
|
526 font_put_frame_data (f, &xftfont_driver, NULL); |
82a42637237c
(struct xftface_info): Delete the member xft_draw.
Kenichi Handa <handa@m17n.org>
parents:
91027
diff
changeset
|
527 } |
82a42637237c
(struct xftface_info): Delete the member xft_draw.
Kenichi Handa <handa@m17n.org>
parents:
91027
diff
changeset
|
528 return 0; |
82a42637237c
(struct xftface_info): Delete the member xft_draw.
Kenichi Handa <handa@m17n.org>
parents:
91027
diff
changeset
|
529 } |
90400 | 530 |
91143 | 531 #ifdef HAVE_LIBOTF |
532 #ifdef HAVE_M17N_FLT | |
533 static Lisp_Object | |
534 xftfont_shape (lgstring) | |
535 Lisp_Object lgstring; | |
536 { | |
537 struct font *font; | |
538 struct xftfont_info *xftfont_info; | |
94941
8cbdb26068b4
(xftfont_list): Adjusted for the change of `list'
Kenichi Handa <handa@m17n.org>
parents:
92184
diff
changeset
|
539 Lisp_Object result; |
91226
040f2e332dc3
(struct xftfont_info): Delete the member ft_face.
Kenichi Handa <handa@m17n.org>
parents:
91163
diff
changeset
|
540 FT_Face ft_face; |
91143 | 541 |
542 CHECK_FONT_GET_OBJECT (LGSTRING_FONT (lgstring), font); | |
543 xftfont_info = (struct xftfont_info *) font; | |
544 if (! xftfont_info->maybe_otf) | |
545 return Qnil; | |
91226
040f2e332dc3
(struct xftfont_info): Delete the member ft_face.
Kenichi Handa <handa@m17n.org>
parents:
91163
diff
changeset
|
546 ft_face = XftLockFace (xftfont_info->xftfont); |
91143 | 547 if (! xftfont_info->otf) |
548 { | |
91226
040f2e332dc3
(struct xftfont_info): Delete the member ft_face.
Kenichi Handa <handa@m17n.org>
parents:
91163
diff
changeset
|
549 OTF *otf = OTF_open_ft_face (ft_face); |
91143 | 550 |
551 if (! otf || OTF_get_table (otf, "head") < 0) | |
552 { | |
553 if (otf) | |
554 OTF_close (otf); | |
555 xftfont_info->maybe_otf = 0; | |
91226
040f2e332dc3
(struct xftfont_info): Delete the member ft_face.
Kenichi Handa <handa@m17n.org>
parents:
91163
diff
changeset
|
556 XftUnlockFace (xftfont_info->xftfont); |
94941
8cbdb26068b4
(xftfont_list): Adjusted for the change of `list'
Kenichi Handa <handa@m17n.org>
parents:
92184
diff
changeset
|
557 return Qnil; |
91143 | 558 } |
559 xftfont_info->otf = otf; | |
560 } | |
561 | |
91226
040f2e332dc3
(struct xftfont_info): Delete the member ft_face.
Kenichi Handa <handa@m17n.org>
parents:
91163
diff
changeset
|
562 result = ftfont_shape_by_flt (lgstring, font, ft_face, xftfont_info->otf); |
040f2e332dc3
(struct xftfont_info): Delete the member ft_face.
Kenichi Handa <handa@m17n.org>
parents:
91163
diff
changeset
|
563 XftUnlockFace (xftfont_info->xftfont); |
040f2e332dc3
(struct xftfont_info): Delete the member ft_face.
Kenichi Handa <handa@m17n.org>
parents:
91163
diff
changeset
|
564 return result; |
91143 | 565 } |
566 #endif /* HAVE_M17N_FLT */ | |
567 #endif /* HAVE_LIBOTF */ | |
568 | |
90400 | 569 void |
570 syms_of_xftfont () | |
571 { | |
572 DEFSYM (Qxft, "xft"); | |
573 | |
574 xftfont_driver = ftfont_driver; | |
575 xftfont_driver.type = Qxft; | |
576 xftfont_driver.get_cache = xfont_driver.get_cache; | |
577 xftfont_driver.list = xftfont_list; | |
90559
fb5d3ac2d786
(xftfont_match): New function.
Kenichi Handa <handa@m17n.org>
parents:
90527
diff
changeset
|
578 xftfont_driver.match = xftfont_match; |
90400 | 579 xftfont_driver.open = xftfont_open; |
580 xftfont_driver.close = xftfont_close; | |
581 xftfont_driver.prepare_face = xftfont_prepare_face; | |
582 xftfont_driver.done_face = xftfont_done_face; | |
583 xftfont_driver.encode_char = xftfont_encode_char; | |
584 xftfont_driver.text_extents = xftfont_text_extents; | |
585 xftfont_driver.draw = xftfont_draw; | |
586 xftfont_driver.anchor_point = xftfont_anchor_point; | |
91110
82a42637237c
(struct xftface_info): Delete the member xft_draw.
Kenichi Handa <handa@m17n.org>
parents:
91027
diff
changeset
|
587 xftfont_driver.end_for_frame = xftfont_end_for_frame; |
91143 | 588 #ifdef HAVE_LIBOTF |
589 #ifdef HAVE_M17N_FLT | |
590 xftfont_driver.shape = xftfont_shape; | |
591 #endif /* HAVE_M17N_FLT */ | |
592 #endif /* HAVE_LIBOTF */ | |
90400 | 593 |
594 register_font_driver (&xftfont_driver, NULL); | |
595 } | |
90427 | 596 |
597 /* arch-tag: 64ec61bf-7c8e-4fe6-b953-c6a85d5e1605 | |
598 (do not change this comment) */ |