Mercurial > emacs
annotate src/xftfont.c @ 94954:81ec00f72dc6
(setup-default-fontset): For kana, han,
hangul, and cjk-misc, move an entry with font-spec at the end.
(generate-fontset-menu): Exclue fontset-auto* from the list.
| author | Kenichi Handa <handa@m17n.org> |
|---|---|
| date | Wed, 14 May 2008 01:55:46 +0000 |
| parents | 8cbdb26068b4 |
| children | 8971ddf55736 |
| 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 | |
| 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 | |
|
91556
0920231c95f2
Update copyright years and GPL version.
Glenn Morris <rgm@gnu.org>
parents:
91269
diff
changeset
|
11 the Free Software Foundation; either version 3, or (at your option) |
| 90400 | 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" | |
| 91143 | 38 #include "ftfont.h" |
| 90400 | 39 |
| 40 /* Xft font driver. */ | |
| 41 | |
| 42 static Lisp_Object Qxft; | |
| 43 | |
| 44 /* The actual structure for Xft font that can be casted to struct | |
| 45 font. */ | |
| 46 | |
| 47 struct xftfont_info | |
| 48 { | |
| 49 struct font font; | |
| 50 Display *display; | |
| 51 int screen; | |
| 52 XftFont *xftfont; | |
| 91143 | 53 #ifdef HAVE_LIBOTF |
| 54 int maybe_otf; /* Flag to tell if this may be OTF or not. */ | |
| 55 OTF *otf; | |
| 91163 | 56 #endif /* HAVE_LIBOTF */ |
| 90400 | 57 }; |
| 58 | |
| 59 /* Structure pointed by (struct face *)->extra */ | |
|
90559
fb5d3ac2d786
(xftfont_match): New function.
Kenichi Handa <handa@m17n.org>
parents:
90527
diff
changeset
|
60 |
| 90400 | 61 struct xftface_info |
| 62 { | |
|
90559
fb5d3ac2d786
(xftfont_match): New function.
Kenichi Handa <handa@m17n.org>
parents:
90527
diff
changeset
|
63 XftColor xft_fg; /* color for face->foreground */ |
|
fb5d3ac2d786
(xftfont_match): New function.
Kenichi Handa <handa@m17n.org>
parents:
90527
diff
changeset
|
64 XftColor xft_bg; /* color for face->background */ |
| 90400 | 65 }; |
| 66 | |
| 67 static void xftfont_get_colors P_ ((FRAME_PTR, struct face *, GC gc, | |
| 68 struct xftface_info *, | |
| 69 XftColor *fg, XftColor *bg)); | |
| 70 | |
| 71 | |
|
90559
fb5d3ac2d786
(xftfont_match): New function.
Kenichi Handa <handa@m17n.org>
parents:
90527
diff
changeset
|
72 /* 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
|
73 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
|
74 may be NULL. */ |
|
fb5d3ac2d786
(xftfont_match): New function.
Kenichi Handa <handa@m17n.org>
parents:
90527
diff
changeset
|
75 |
| 90400 | 76 static void |
| 77 xftfont_get_colors (f, face, gc, xftface_info, fg, bg) | |
| 78 FRAME_PTR f; | |
| 79 struct face *face; | |
| 80 GC gc; | |
| 81 struct xftface_info *xftface_info; | |
| 82 XftColor *fg, *bg; | |
| 83 { | |
| 84 if (xftface_info && face->gc == gc) | |
| 85 { | |
| 86 *fg = xftface_info->xft_fg; | |
| 87 if (bg) | |
| 88 *bg = xftface_info->xft_bg; | |
| 89 } | |
| 90 else | |
| 91 { | |
| 92 XGCValues xgcv; | |
| 93 int fg_done = 0, bg_done = 0; | |
| 94 | |
| 95 BLOCK_INPUT; | |
| 96 XGetGCValues (FRAME_X_DISPLAY (f), gc, | |
| 97 GCForeground | GCBackground, &xgcv); | |
| 98 if (xftface_info) | |
| 99 { | |
| 100 if (xgcv.foreground == face->foreground) | |
| 101 *fg = xftface_info->xft_fg, fg_done = 1; | |
| 102 else if (xgcv.foreground == face->background) | |
| 103 *fg = xftface_info->xft_bg, fg_done = 1; | |
| 104 if (! bg) | |
| 105 bg_done = 1; | |
| 106 else if (xgcv.background == face->background) | |
| 107 *bg = xftface_info->xft_bg, bg_done = 1; | |
| 108 else if (xgcv.background == face->foreground) | |
| 109 *bg = xftface_info->xft_fg, bg_done = 1; | |
| 110 } | |
| 111 | |
| 112 if (fg_done + bg_done < 2) | |
| 113 { | |
| 114 XColor colors[2]; | |
| 115 | |
| 116 colors[0].pixel = fg->pixel = xgcv.foreground; | |
| 117 if (bg) | |
| 118 colors[1].pixel = bg->pixel = xgcv.background; | |
| 119 XQueryColors (FRAME_X_DISPLAY (f), FRAME_X_COLORMAP (f), colors, | |
| 120 bg ? 2 : 1); | |
| 121 fg->color.alpha = 0xFFFF; | |
| 122 fg->color.red = colors[0].red; | |
| 123 fg->color.green = colors[0].green; | |
| 124 fg->color.blue = colors[0].blue; | |
| 125 if (bg) | |
| 126 { | |
| 127 bg->color.alpha = 0xFFFF; | |
| 128 bg->color.red = colors[1].red; | |
| 129 bg->color.green = colors[1].green; | |
| 130 bg->color.blue = colors[1].blue; | |
| 131 } | |
| 132 } | |
| 133 UNBLOCK_INPUT; | |
| 134 } | |
| 135 } | |
| 136 | |
| 137 | |
| 138 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
|
139 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
|
140 static Lisp_Object xftfont_open P_ ((FRAME_PTR, Lisp_Object, int)); |
| 90400 | 141 static void xftfont_close P_ ((FRAME_PTR, struct font *)); |
| 142 static int xftfont_prepare_face P_ ((FRAME_PTR, struct face *)); | |
| 143 static void xftfont_done_face P_ ((FRAME_PTR, struct face *)); | |
| 144 static unsigned xftfont_encode_char P_ ((struct font *, int)); | |
| 145 static int xftfont_text_extents P_ ((struct font *, unsigned *, int, | |
| 146 struct font_metrics *)); | |
| 147 static int xftfont_draw P_ ((struct glyph_string *, int, int, int, int, int)); | |
| 148 | |
| 149 static int xftfont_anchor_point P_ ((struct font *, unsigned, int, | |
| 150 int *, int *)); | |
|
91110
82a42637237c
(struct xftface_info): Delete the member xft_draw.
Kenichi Handa <handa@m17n.org>
parents:
91027
diff
changeset
|
151 static int xftfont_end_for_frame P_ ((FRAME_PTR f)); |
| 90400 | 152 |
| 153 struct font_driver xftfont_driver; | |
| 154 | |
| 155 static Lisp_Object | |
| 156 xftfont_list (frame, spec) | |
| 157 Lisp_Object frame; | |
| 158 Lisp_Object spec; | |
| 159 { | |
|
94941
8cbdb26068b4
(xftfont_list): Adjusted for the change of `list'
Kenichi Handa <handa@m17n.org>
parents:
92184
diff
changeset
|
160 Lisp_Object list = ftfont_driver.list (frame, spec), tail; |
|
90559
fb5d3ac2d786
(xftfont_match): New function.
Kenichi Handa <handa@m17n.org>
parents:
90527
diff
changeset
|
161 int i; |
| 90400 | 162 |
|
94941
8cbdb26068b4
(xftfont_list): Adjusted for the change of `list'
Kenichi Handa <handa@m17n.org>
parents:
92184
diff
changeset
|
163 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
|
164 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
|
165 return list; |
|
90559
fb5d3ac2d786
(xftfont_match): New function.
Kenichi Handa <handa@m17n.org>
parents:
90527
diff
changeset
|
166 } |
| 90400 | 167 |
|
90559
fb5d3ac2d786
(xftfont_match): New function.
Kenichi Handa <handa@m17n.org>
parents:
90527
diff
changeset
|
168 static Lisp_Object |
|
fb5d3ac2d786
(xftfont_match): New function.
Kenichi Handa <handa@m17n.org>
parents:
90527
diff
changeset
|
169 xftfont_match (frame, spec) |
|
fb5d3ac2d786
(xftfont_match): New function.
Kenichi Handa <handa@m17n.org>
parents:
90527
diff
changeset
|
170 Lisp_Object frame; |
|
fb5d3ac2d786
(xftfont_match): New function.
Kenichi Handa <handa@m17n.org>
parents:
90527
diff
changeset
|
171 Lisp_Object spec; |
|
fb5d3ac2d786
(xftfont_match): New function.
Kenichi Handa <handa@m17n.org>
parents:
90527
diff
changeset
|
172 { |
|
fb5d3ac2d786
(xftfont_match): New function.
Kenichi Handa <handa@m17n.org>
parents:
90527
diff
changeset
|
173 Lisp_Object entity = ftfont_driver.match (frame, spec); |
|
fb5d3ac2d786
(xftfont_match): New function.
Kenichi Handa <handa@m17n.org>
parents:
90527
diff
changeset
|
174 |
|
94941
8cbdb26068b4
(xftfont_list): Adjusted for the change of `list'
Kenichi Handa <handa@m17n.org>
parents:
92184
diff
changeset
|
175 if (! NILP (entity)) |
|
90559
fb5d3ac2d786
(xftfont_match): New function.
Kenichi Handa <handa@m17n.org>
parents:
90527
diff
changeset
|
176 ASET (entity, FONT_TYPE_INDEX, Qxft); |
|
fb5d3ac2d786
(xftfont_match): New function.
Kenichi Handa <handa@m17n.org>
parents:
90527
diff
changeset
|
177 return entity; |
| 90400 | 178 } |
| 179 | |
|
90700
b165eceb829f
(ftfont_font_format): Extern declaration.
Kenichi Handa <handa@m17n.org>
parents:
90675
diff
changeset
|
180 extern Lisp_Object ftfont_font_format P_ ((FcPattern *)); |
|
b165eceb829f
(ftfont_font_format): Extern declaration.
Kenichi Handa <handa@m17n.org>
parents:
90675
diff
changeset
|
181 |
| 90400 | 182 static FcChar8 ascii_printable[95]; |
| 183 | |
|
94941
8cbdb26068b4
(xftfont_list): Adjusted for the change of `list'
Kenichi Handa <handa@m17n.org>
parents:
92184
diff
changeset
|
184 static Lisp_Object |
| 90400 | 185 xftfont_open (f, entity, pixel_size) |
| 186 FRAME_PTR f; | |
| 187 Lisp_Object entity; | |
| 188 int pixel_size; | |
| 189 { | |
| 190 Display_Info *dpyinfo = FRAME_X_DISPLAY_INFO (f); | |
| 191 Display *display = FRAME_X_DISPLAY (f); | |
|
94941
8cbdb26068b4
(xftfont_list): Adjusted for the change of `list'
Kenichi Handa <handa@m17n.org>
parents:
92184
diff
changeset
|
192 Lisp_Object val, font_object; |
|
90460
86449661f321
(xftfont_open): Change coding style of error
Kenichi Handa <handa@m17n.org>
parents:
90442
diff
changeset
|
193 FcPattern *pattern, *pat = NULL; |
|
86449661f321
(xftfont_open): Change coding style of error
Kenichi Handa <handa@m17n.org>
parents:
90442
diff
changeset
|
194 FcChar8 *file; |
|
86449661f321
(xftfont_open): Change coding style of error
Kenichi Handa <handa@m17n.org>
parents:
90442
diff
changeset
|
195 struct xftfont_info *xftfont_info = NULL; |
|
86449661f321
(xftfont_open): Change coding style of error
Kenichi Handa <handa@m17n.org>
parents:
90442
diff
changeset
|
196 XFontStruct *xfont = NULL; |
| 90400 | 197 struct font *font; |
| 198 double size = 0; | |
|
90460
86449661f321
(xftfont_open): Change coding style of error
Kenichi Handa <handa@m17n.org>
parents:
90442
diff
changeset
|
199 XftFont *xftfont = NULL; |
| 90400 | 200 int spacing; |
|
94941
8cbdb26068b4
(xftfont_list): Adjusted for the change of `list'
Kenichi Handa <handa@m17n.org>
parents:
92184
diff
changeset
|
201 char name[256]; |
|
8cbdb26068b4
(xftfont_list): Adjusted for the change of `list'
Kenichi Handa <handa@m17n.org>
parents:
92184
diff
changeset
|
202 int len, i; |
|
90959
3f83c9d3f96c
(xftfont_open): If one of font's ASCII glyph has
Kenichi Handa <handa@m17n.org>
parents:
90714
diff
changeset
|
203 XGlyphInfo extents; |
|
91226
040f2e332dc3
(struct xftfont_info): Delete the member ft_face.
Kenichi Handa <handa@m17n.org>
parents:
91163
diff
changeset
|
204 FT_Face ft_face; |
| 90400 | 205 |
|
94941
8cbdb26068b4
(xftfont_list): Adjusted for the change of `list'
Kenichi Handa <handa@m17n.org>
parents:
92184
diff
changeset
|
206 val = assq_no_quit (QCfont_entity, AREF (entity, FONT_EXTRA_INDEX)); |
|
8cbdb26068b4
(xftfont_list): Adjusted for the change of `list'
Kenichi Handa <handa@m17n.org>
parents:
92184
diff
changeset
|
207 if (! CONSP (val) |
|
8cbdb26068b4
(xftfont_list): Adjusted for the change of `list'
Kenichi Handa <handa@m17n.org>
parents:
92184
diff
changeset
|
208 || XTYPE (XCDR (val)) != Lisp_Misc |
|
8cbdb26068b4
(xftfont_list): Adjusted for the change of `list'
Kenichi Handa <handa@m17n.org>
parents:
92184
diff
changeset
|
209 || XMISCTYPE (XCDR (val)) != Lisp_Misc_Save_Value) |
|
8cbdb26068b4
(xftfont_list): Adjusted for the change of `list'
Kenichi Handa <handa@m17n.org>
parents:
92184
diff
changeset
|
210 return Qnil; |
|
8cbdb26068b4
(xftfont_list): Adjusted for the change of `list'
Kenichi Handa <handa@m17n.org>
parents:
92184
diff
changeset
|
211 pattern = XSAVE_VALUE (XCDR (val))->pointer; |
| 90400 | 212 if (FcPatternGetString (pattern, FC_FILE, 0, &file) != FcResultMatch) |
|
94941
8cbdb26068b4
(xftfont_list): Adjusted for the change of `list'
Kenichi Handa <handa@m17n.org>
parents:
92184
diff
changeset
|
213 return Qnil; |
| 90400 | 214 |
| 215 size = XINT (AREF (entity, FONT_SIZE_INDEX)); | |
| 216 if (size == 0) | |
| 217 size = pixel_size; | |
|
90442
d6abf2344438
(xftfont_open): Make the font name fontconfig's
Kenichi Handa <handa@m17n.org>
parents:
90427
diff
changeset
|
218 |
| 90400 | 219 pat = FcPatternCreate (); |
| 220 FcPatternAddString (pat, FC_FILE, file); | |
| 221 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
|
222 /*FcPatternAddBool (pat, FC_ANTIALIAS, FcTrue);*/ |
|
90714
698001835583
(xftfont_open): Call FcConfigSubstitute.
Kenichi Handa <handa@m17n.org>
parents:
90712
diff
changeset
|
223 val = AREF (entity, FONT_FAMILY_INDEX); |
|
698001835583
(xftfont_open): Call FcConfigSubstitute.
Kenichi Handa <handa@m17n.org>
parents:
90712
diff
changeset
|
224 if (! NILP (val)) |
|
698001835583
(xftfont_open): Call FcConfigSubstitute.
Kenichi Handa <handa@m17n.org>
parents:
90712
diff
changeset
|
225 FcPatternAddString (pat, FC_FAMILY, (FcChar8 *) SDATA (SYMBOL_NAME (val))); |
|
698001835583
(xftfont_open): Call FcConfigSubstitute.
Kenichi Handa <handa@m17n.org>
parents:
90712
diff
changeset
|
226 FcConfigSubstitute (NULL, pat, FcMatchPattern); |
|
90442
d6abf2344438
(xftfont_open): Make the font name fontconfig's
Kenichi Handa <handa@m17n.org>
parents:
90427
diff
changeset
|
227 |
|
d6abf2344438
(xftfont_open): Make the font name fontconfig's
Kenichi Handa <handa@m17n.org>
parents:
90427
diff
changeset
|
228 BLOCK_INPUT; |
|
90589
697dcc1df88d
(xftfont_open): Call XftDefaultSubstitute before
Kenichi Handa <handa@m17n.org>
parents:
90559
diff
changeset
|
229 XftDefaultSubstitute (display, FRAME_X_SCREEN_NUMBER (f), pat); |
| 90400 | 230 xftfont = XftFontOpenPattern (display, pat); |
|
94941
8cbdb26068b4
(xftfont_list): Adjusted for the change of `list'
Kenichi Handa <handa@m17n.org>
parents:
92184
diff
changeset
|
231 UNBLOCK_INPUT; |
|
8cbdb26068b4
(xftfont_list): Adjusted for the change of `list'
Kenichi Handa <handa@m17n.org>
parents:
92184
diff
changeset
|
232 if (! xftfont) |
|
8cbdb26068b4
(xftfont_list): Adjusted for the change of `list'
Kenichi Handa <handa@m17n.org>
parents:
92184
diff
changeset
|
233 return Qnil; |
| 90400 | 234 /* We should not destroy PAT here because it is kept in XFTFONT and |
| 235 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
|
236 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
|
237 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
|
238 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
|
239 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
|
240 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
|
241 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
|
242 if (len > 0) |
|
8cbdb26068b4
(xftfont_list): Adjusted for the change of `list'
Kenichi Handa <handa@m17n.org>
parents:
92184
diff
changeset
|
243 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
|
244 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
|
245 if (len > 0) |
|
8cbdb26068b4
(xftfont_list): Adjusted for the change of `list'
Kenichi Handa <handa@m17n.org>
parents:
92184
diff
changeset
|
246 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
|
247 else |
|
8cbdb26068b4
(xftfont_list): Adjusted for the change of `list'
Kenichi Handa <handa@m17n.org>
parents:
92184
diff
changeset
|
248 ASET (font_object, FONT_FULLNAME_INDEX, |
|
8cbdb26068b4
(xftfont_list): Adjusted for the change of `list'
Kenichi Handa <handa@m17n.org>
parents:
92184
diff
changeset
|
249 AREF (font_object, FONT_NAME_INDEX)); |
|
8cbdb26068b4
(xftfont_list): Adjusted for the change of `list'
Kenichi Handa <handa@m17n.org>
parents:
92184
diff
changeset
|
250 ASET (font_object, FONT_FILE_INDEX, |
|
8cbdb26068b4
(xftfont_list): Adjusted for the change of `list'
Kenichi Handa <handa@m17n.org>
parents:
92184
diff
changeset
|
251 make_unibyte_string ((char *) file, strlen ((char *) file))); |
|
8cbdb26068b4
(xftfont_list): Adjusted for the change of `list'
Kenichi Handa <handa@m17n.org>
parents:
92184
diff
changeset
|
252 ASET (font_object, FONT_FORMAT_INDEX, ftfont_font_format (pattern)); |
|
8cbdb26068b4
(xftfont_list): Adjusted for the change of `list'
Kenichi Handa <handa@m17n.org>
parents:
92184
diff
changeset
|
253 font = XFONT_OBJECT (font_object); |
|
8cbdb26068b4
(xftfont_list): Adjusted for the change of `list'
Kenichi Handa <handa@m17n.org>
parents:
92184
diff
changeset
|
254 font->pixel_size = pixel_size; |
|
8cbdb26068b4
(xftfont_list): Adjusted for the change of `list'
Kenichi Handa <handa@m17n.org>
parents:
92184
diff
changeset
|
255 font->driver = &xftfont_driver; |
|
8cbdb26068b4
(xftfont_list): Adjusted for the change of `list'
Kenichi Handa <handa@m17n.org>
parents:
92184
diff
changeset
|
256 font->encoding_charset = font->repertory_charset = -1; |
| 90400 | 257 |
|
94941
8cbdb26068b4
(xftfont_list): Adjusted for the change of `list'
Kenichi Handa <handa@m17n.org>
parents:
92184
diff
changeset
|
258 xftfont_info = (struct xftfont_info *) font; |
| 90400 | 259 xftfont_info->display = display; |
| 260 xftfont_info->screen = FRAME_X_SCREEN_NUMBER (f); | |
| 261 xftfont_info->xftfont = xftfont; | |
| 262 font->pixel_size = size; | |
| 263 font->driver = &xftfont_driver; | |
| 264 if (FcPatternGetInteger (xftfont->pattern, FC_SPACING, 0, &spacing) | |
| 265 != FcResultMatch) | |
| 266 spacing = FC_PROPORTIONAL; | |
|
90959
3f83c9d3f96c
(xftfont_open): If one of font's ASCII glyph has
Kenichi Handa <handa@m17n.org>
parents:
90714
diff
changeset
|
267 if (! ascii_printable[0]) |
|
3f83c9d3f96c
(xftfont_open): If one of font's ASCII glyph has
Kenichi Handa <handa@m17n.org>
parents:
90714
diff
changeset
|
268 { |
|
3f83c9d3f96c
(xftfont_open): If one of font's ASCII glyph has
Kenichi Handa <handa@m17n.org>
parents:
90714
diff
changeset
|
269 int i; |
|
3f83c9d3f96c
(xftfont_open): If one of font's ASCII glyph has
Kenichi Handa <handa@m17n.org>
parents:
90714
diff
changeset
|
270 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
|
271 ascii_printable[i] = ' ' + i; |
|
3f83c9d3f96c
(xftfont_open): If one of font's ASCII glyph has
Kenichi Handa <handa@m17n.org>
parents:
90714
diff
changeset
|
272 } |
|
94941
8cbdb26068b4
(xftfont_list): Adjusted for the change of `list'
Kenichi Handa <handa@m17n.org>
parents:
92184
diff
changeset
|
273 BLOCK_INPUT; |
| 90400 | 274 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
|
275 { |
|
94941
8cbdb26068b4
(xftfont_list): Adjusted for the change of `list'
Kenichi Handa <handa@m17n.org>
parents:
92184
diff
changeset
|
276 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
|
277 = xftfont->max_advance_width; |
|
3f83c9d3f96c
(xftfont_open): If one of font's ASCII glyph has
Kenichi Handa <handa@m17n.org>
parents:
90714
diff
changeset
|
278 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
|
279 } |
| 90400 | 280 else |
| 281 { | |
| 282 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
|
283 font->space_width = extents.xOff; |
|
8cbdb26068b4
(xftfont_list): Adjusted for the change of `list'
Kenichi Handa <handa@m17n.org>
parents:
92184
diff
changeset
|
284 if (font->space_width <= 0) |
| 90400 | 285 /* dirty workaround */ |
|
94941
8cbdb26068b4
(xftfont_list): Adjusted for the change of `list'
Kenichi Handa <handa@m17n.org>
parents:
92184
diff
changeset
|
286 font->space_width = pixel_size; |
| 90400 | 287 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
|
288 font->average_width = (font->space_width + extents.xOff) / 95; |
| 90400 | 289 } |
|
90442
d6abf2344438
(xftfont_open): Make the font name fontconfig's
Kenichi Handa <handa@m17n.org>
parents:
90427
diff
changeset
|
290 UNBLOCK_INPUT; |
| 90400 | 291 |
|
90959
3f83c9d3f96c
(xftfont_open): If one of font's ASCII glyph has
Kenichi Handa <handa@m17n.org>
parents:
90714
diff
changeset
|
292 font->ascent = xftfont->ascent; |
|
3f83c9d3f96c
(xftfont_open): If one of font's ASCII glyph has
Kenichi Handa <handa@m17n.org>
parents:
90714
diff
changeset
|
293 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
|
294 font->ascent = extents.y; |
|
3f83c9d3f96c
(xftfont_open): If one of font's ASCII glyph has
Kenichi Handa <handa@m17n.org>
parents:
90714
diff
changeset
|
295 font->descent = xftfont->descent; |
|
3f83c9d3f96c
(xftfont_open): If one of font's ASCII glyph has
Kenichi Handa <handa@m17n.org>
parents:
90714
diff
changeset
|
296 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
|
297 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
|
298 font->height = font->ascent + font->descent; |
|
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 ft_face = XftLockFace (xftfont); |
|
8cbdb26068b4
(xftfont_list): Adjusted for the change of `list'
Kenichi Handa <handa@m17n.org>
parents:
92184
diff
changeset
|
301 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
|
302 { |
|
8cbdb26068b4
(xftfont_list): Adjusted for the change of `list'
Kenichi Handa <handa@m17n.org>
parents:
92184
diff
changeset
|
303 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
|
304 |
|
8cbdb26068b4
(xftfont_list): Adjusted for the change of `list'
Kenichi Handa <handa@m17n.org>
parents:
92184
diff
changeset
|
305 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
|
306 font->underline_thickness = -ft_face->underline_thickness * size / upEM; |
|
8cbdb26068b4
(xftfont_list): Adjusted for the change of `list'
Kenichi Handa <handa@m17n.org>
parents:
92184
diff
changeset
|
307 } |
|
8cbdb26068b4
(xftfont_list): Adjusted for the change of `list'
Kenichi Handa <handa@m17n.org>
parents:
92184
diff
changeset
|
308 else |
|
8cbdb26068b4
(xftfont_list): Adjusted for the change of `list'
Kenichi Handa <handa@m17n.org>
parents:
92184
diff
changeset
|
309 { |
|
8cbdb26068b4
(xftfont_list): Adjusted for the change of `list'
Kenichi Handa <handa@m17n.org>
parents:
92184
diff
changeset
|
310 font->underline_position = -1; |
|
8cbdb26068b4
(xftfont_list): Adjusted for the change of `list'
Kenichi Handa <handa@m17n.org>
parents:
92184
diff
changeset
|
311 font->underline_thickness = 0; |
|
8cbdb26068b4
(xftfont_list): Adjusted for the change of `list'
Kenichi Handa <handa@m17n.org>
parents:
92184
diff
changeset
|
312 } |
|
8cbdb26068b4
(xftfont_list): Adjusted for the change of `list'
Kenichi Handa <handa@m17n.org>
parents:
92184
diff
changeset
|
313 #ifdef HAVE_LIBOTF |
|
8cbdb26068b4
(xftfont_list): Adjusted for the change of `list'
Kenichi Handa <handa@m17n.org>
parents:
92184
diff
changeset
|
314 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
|
315 xftfont_info->otf = NULL; |
|
8cbdb26068b4
(xftfont_list): Adjusted for the change of `list'
Kenichi Handa <handa@m17n.org>
parents:
92184
diff
changeset
|
316 #endif /* HAVE_LIBOTF */ |
|
8cbdb26068b4
(xftfont_list): Adjusted for the change of `list'
Kenichi Handa <handa@m17n.org>
parents:
92184
diff
changeset
|
317 XftUnlockFace (xftfont); |
|
90959
3f83c9d3f96c
(xftfont_open): If one of font's ASCII glyph has
Kenichi Handa <handa@m17n.org>
parents:
90714
diff
changeset
|
318 |
| 90400 | 319 /* Unfortunately Xft doesn't provide a way to get minimum char |
| 320 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
|
321 font->min_width = font->space_width; |
| 90400 | 322 |
|
94941
8cbdb26068b4
(xftfont_list): Adjusted for the change of `list'
Kenichi Handa <handa@m17n.org>
parents:
92184
diff
changeset
|
323 font->baseline_offset = 0; |
|
8cbdb26068b4
(xftfont_list): Adjusted for the change of `list'
Kenichi Handa <handa@m17n.org>
parents:
92184
diff
changeset
|
324 font->relative_compose = 0; |
|
8cbdb26068b4
(xftfont_list): Adjusted for the change of `list'
Kenichi Handa <handa@m17n.org>
parents:
92184
diff
changeset
|
325 font->default_ascent = 0; |
|
8cbdb26068b4
(xftfont_list): Adjusted for the change of `list'
Kenichi Handa <handa@m17n.org>
parents:
92184
diff
changeset
|
326 font->vertical_centering = 0; |
| 90400 | 327 |
|
94941
8cbdb26068b4
(xftfont_list): Adjusted for the change of `list'
Kenichi Handa <handa@m17n.org>
parents:
92184
diff
changeset
|
328 return font_object; |
| 90400 | 329 } |
| 330 | |
| 331 static void | |
| 332 xftfont_close (f, font) | |
| 333 FRAME_PTR f; | |
| 334 struct font *font; | |
| 335 { | |
| 336 struct xftfont_info *xftfont_info = (struct xftfont_info *) font; | |
| 337 | |
| 91143 | 338 #ifdef HAVE_LIBOTF |
| 339 if (xftfont_info->otf) | |
| 340 OTF_close (xftfont_info->otf); | |
| 341 #endif | |
|
94941
8cbdb26068b4
(xftfont_list): Adjusted for the change of `list'
Kenichi Handa <handa@m17n.org>
parents:
92184
diff
changeset
|
342 BLOCK_INPUT; |
| 90400 | 343 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
|
344 UNBLOCK_INPUT; |
| 90400 | 345 } |
| 346 | |
| 347 static int | |
| 348 xftfont_prepare_face (f, face) | |
| 349 FRAME_PTR f; | |
| 350 struct face *face; | |
| 351 { | |
|
90489
78a820ef12db
(xftfont_prepare_face): Make non-ascii face share
Kenichi Handa <handa@m17n.org>
parents:
90473
diff
changeset
|
352 struct xftface_info *xftface_info; |
| 90400 | 353 |
|
90499
32b8f672da38
(xftfont_prepare_face): Cancel previous change.
Kenichi Handa <handa@m17n.org>
parents:
90489
diff
changeset
|
354 #if 0 |
|
32b8f672da38
(xftfont_prepare_face): Cancel previous change.
Kenichi Handa <handa@m17n.org>
parents:
90489
diff
changeset
|
355 /* 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
|
356 if (face != face->ascii_face) |
|
78a820ef12db
(xftfont_prepare_face): Make non-ascii face share
Kenichi Handa <handa@m17n.org>
parents:
90473
diff
changeset
|
357 { |
|
78a820ef12db
(xftfont_prepare_face): Make non-ascii face share
Kenichi Handa <handa@m17n.org>
parents:
90473
diff
changeset
|
358 face->extra = face->ascii_face->extra; |
|
78a820ef12db
(xftfont_prepare_face): Make non-ascii face share
Kenichi Handa <handa@m17n.org>
parents:
90473
diff
changeset
|
359 return 0; |
|
78a820ef12db
(xftfont_prepare_face): Make non-ascii face share
Kenichi Handa <handa@m17n.org>
parents:
90473
diff
changeset
|
360 } |
|
90499
32b8f672da38
(xftfont_prepare_face): Cancel previous change.
Kenichi Handa <handa@m17n.org>
parents:
90489
diff
changeset
|
361 #endif |
|
90489
78a820ef12db
(xftfont_prepare_face): Make non-ascii face share
Kenichi Handa <handa@m17n.org>
parents:
90473
diff
changeset
|
362 |
|
78a820ef12db
(xftfont_prepare_face): Make non-ascii face share
Kenichi Handa <handa@m17n.org>
parents:
90473
diff
changeset
|
363 xftface_info = malloc (sizeof (struct xftface_info)); |
| 90400 | 364 if (! xftface_info) |
| 365 return -1; | |
| 366 xftfont_get_colors (f, face, face->gc, NULL, | |
| 367 &xftface_info->xft_fg, &xftface_info->xft_bg); | |
| 368 face->extra = xftface_info; | |
| 369 return 0; | |
| 370 } | |
| 371 | |
| 372 static void | |
| 373 xftfont_done_face (f, face) | |
| 374 FRAME_PTR f; | |
| 375 struct face *face; | |
| 376 { | |
|
90489
78a820ef12db
(xftfont_prepare_face): Make non-ascii face share
Kenichi Handa <handa@m17n.org>
parents:
90473
diff
changeset
|
377 struct xftface_info *xftface_info; |
|
78a820ef12db
(xftfont_prepare_face): Make non-ascii face share
Kenichi Handa <handa@m17n.org>
parents:
90473
diff
changeset
|
378 |
|
90499
32b8f672da38
(xftfont_prepare_face): Cancel previous change.
Kenichi Handa <handa@m17n.org>
parents:
90489
diff
changeset
|
379 #if 0 |
|
32b8f672da38
(xftfont_prepare_face): Cancel previous change.
Kenichi Handa <handa@m17n.org>
parents:
90489
diff
changeset
|
380 /* 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
|
381 if (face != face->ascii_face |
|
78a820ef12db
(xftfont_prepare_face): Make non-ascii face share
Kenichi Handa <handa@m17n.org>
parents:
90473
diff
changeset
|
382 || ! face->extra) |
|
78a820ef12db
(xftfont_prepare_face): Make non-ascii face share
Kenichi Handa <handa@m17n.org>
parents:
90473
diff
changeset
|
383 return; |
|
90499
32b8f672da38
(xftfont_prepare_face): Cancel previous change.
Kenichi Handa <handa@m17n.org>
parents:
90489
diff
changeset
|
384 #endif |
| 90400 | 385 |
|
90489
78a820ef12db
(xftfont_prepare_face): Make non-ascii face share
Kenichi Handa <handa@m17n.org>
parents:
90473
diff
changeset
|
386 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
|
387 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
|
388 { |
|
63b888896eba
* xftfont.c (xftfont_done_face): Call XftDrawDestroy only if xftface_info
Jan Dj?rv <jan.h.d@swipnet.se>
parents:
90511
diff
changeset
|
389 free (xftface_info); |
|
91110
82a42637237c
(struct xftface_info): Delete the member xft_draw.
Kenichi Handa <handa@m17n.org>
parents:
91027
diff
changeset
|
390 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
|
391 } |
| 90400 | 392 } |
| 393 | |
| 394 static unsigned | |
| 395 xftfont_encode_char (font, c) | |
| 396 struct font *font; | |
| 397 int c; | |
| 398 { | |
| 399 struct xftfont_info *xftfont_info = (struct xftfont_info *) font; | |
| 400 unsigned code = XftCharIndex (xftfont_info->display, xftfont_info->xftfont, | |
| 401 (FcChar32) c); | |
| 402 | |
|
91269
421d7c7d296a
(xftfont_encode_char): Use the macro FONT_INVALID_CODE.
Kenichi Handa <handa@m17n.org>
parents:
91243
diff
changeset
|
403 return (code ? code : FONT_INVALID_CODE); |
| 90400 | 404 } |
| 405 | |
| 406 static int | |
| 407 xftfont_text_extents (font, code, nglyphs, metrics) | |
| 408 struct font *font; | |
| 409 unsigned *code; | |
| 410 int nglyphs; | |
| 411 struct font_metrics *metrics; | |
| 412 { | |
| 413 struct xftfont_info *xftfont_info = (struct xftfont_info *) font; | |
| 414 XGlyphInfo extents; | |
| 415 | |
| 416 BLOCK_INPUT; | |
| 417 XftGlyphExtents (xftfont_info->display, xftfont_info->xftfont, code, nglyphs, | |
| 418 &extents); | |
| 419 UNBLOCK_INPUT; | |
| 420 if (metrics) | |
| 421 { | |
| 422 metrics->lbearing = - extents.x; | |
| 423 metrics->rbearing = - extents.x + extents.width; | |
| 424 metrics->width = extents.xOff; | |
| 425 metrics->ascent = extents.y; | |
|
90616
68d59ef20174
(xftfont_text_extents): Fix calculation of descent
Kenichi Handa <handa@m17n.org>
parents:
90589
diff
changeset
|
426 metrics->descent = extents.height - extents.y; |
| 90400 | 427 } |
| 428 return extents.xOff; | |
| 429 } | |
| 430 | |
|
91110
82a42637237c
(struct xftface_info): Delete the member xft_draw.
Kenichi Handa <handa@m17n.org>
parents:
91027
diff
changeset
|
431 static XftDraw * |
|
82a42637237c
(struct xftface_info): Delete the member xft_draw.
Kenichi Handa <handa@m17n.org>
parents:
91027
diff
changeset
|
432 xftfont_get_xft_draw (f) |
|
82a42637237c
(struct xftface_info): Delete the member xft_draw.
Kenichi Handa <handa@m17n.org>
parents:
91027
diff
changeset
|
433 FRAME_PTR f; |
|
82a42637237c
(struct xftface_info): Delete the member xft_draw.
Kenichi Handa <handa@m17n.org>
parents:
91027
diff
changeset
|
434 { |
|
82a42637237c
(struct xftface_info): Delete the member xft_draw.
Kenichi Handa <handa@m17n.org>
parents:
91027
diff
changeset
|
435 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
|
436 |
|
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 { |
|
82a42637237c
(struct xftface_info): Delete the member xft_draw.
Kenichi Handa <handa@m17n.org>
parents:
91027
diff
changeset
|
439 BLOCK_INPUT; |
|
82a42637237c
(struct xftface_info): Delete the member xft_draw.
Kenichi Handa <handa@m17n.org>
parents:
91027
diff
changeset
|
440 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
|
441 FRAME_X_WINDOW (f), |
|
82a42637237c
(struct xftface_info): Delete the member xft_draw.
Kenichi Handa <handa@m17n.org>
parents:
91027
diff
changeset
|
442 FRAME_X_VISUAL (f), |
|
82a42637237c
(struct xftface_info): Delete the member xft_draw.
Kenichi Handa <handa@m17n.org>
parents:
91027
diff
changeset
|
443 FRAME_X_COLORMAP (f)); |
|
82a42637237c
(struct xftface_info): Delete the member xft_draw.
Kenichi Handa <handa@m17n.org>
parents:
91027
diff
changeset
|
444 UNBLOCK_INPUT; |
|
82a42637237c
(struct xftface_info): Delete the member xft_draw.
Kenichi Handa <handa@m17n.org>
parents:
91027
diff
changeset
|
445 if (! xft_draw) |
|
82a42637237c
(struct xftface_info): Delete the member xft_draw.
Kenichi Handa <handa@m17n.org>
parents:
91027
diff
changeset
|
446 abort (); |
|
82a42637237c
(struct xftface_info): Delete the member xft_draw.
Kenichi Handa <handa@m17n.org>
parents:
91027
diff
changeset
|
447 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
|
448 } |
|
82a42637237c
(struct xftface_info): Delete the member xft_draw.
Kenichi Handa <handa@m17n.org>
parents:
91027
diff
changeset
|
449 return xft_draw; |
|
82a42637237c
(struct xftface_info): Delete the member xft_draw.
Kenichi Handa <handa@m17n.org>
parents:
91027
diff
changeset
|
450 } |
|
82a42637237c
(struct xftface_info): Delete the member xft_draw.
Kenichi Handa <handa@m17n.org>
parents:
91027
diff
changeset
|
451 |
| 90400 | 452 static int |
| 453 xftfont_draw (s, from, to, x, y, with_background) | |
| 454 struct glyph_string *s; | |
| 455 int from, to, x, y, with_background; | |
| 456 { | |
| 457 FRAME_PTR f = s->f; | |
| 458 struct face *face = s->face; | |
|
94941
8cbdb26068b4
(xftfont_list): Adjusted for the change of `list'
Kenichi Handa <handa@m17n.org>
parents:
92184
diff
changeset
|
459 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
|
460 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
|
461 XftDraw *xft_draw = xftfont_get_xft_draw (f); |
| 90400 | 462 FT_UInt *code; |
| 463 XftColor fg, bg; | |
| 464 XRectangle r; | |
| 465 int len = to - from; | |
| 466 int i; | |
| 467 | |
|
94941
8cbdb26068b4
(xftfont_list): Adjusted for the change of `list'
Kenichi Handa <handa@m17n.org>
parents:
92184
diff
changeset
|
468 if (s->font == face->font) |
|
91110
82a42637237c
(struct xftface_info): Delete the member xft_draw.
Kenichi Handa <handa@m17n.org>
parents:
91027
diff
changeset
|
469 xftface_info = (struct xftface_info *) face->extra; |
| 90400 | 470 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
|
471 &fg, with_background ? &bg : NULL); |
| 90400 | 472 BLOCK_INPUT; |
|
91027
04b81a720da9
(xftfont_draw): Adjusted for the change of struct
Kenichi Handa <handa@m17n.org>
parents:
91011
diff
changeset
|
473 if (s->num_clips > 0) |
|
04b81a720da9
(xftfont_draw): Adjusted for the change of struct
Kenichi Handa <handa@m17n.org>
parents:
91011
diff
changeset
|
474 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
|
475 else |
|
04b81a720da9
(xftfont_draw): Adjusted for the change of struct
Kenichi Handa <handa@m17n.org>
parents:
91011
diff
changeset
|
476 XftDrawSetClip (xft_draw, NULL); |
|
04b81a720da9
(xftfont_draw): Adjusted for the change of struct
Kenichi Handa <handa@m17n.org>
parents:
91011
diff
changeset
|
477 |
| 90400 | 478 if (with_background) |
|
94941
8cbdb26068b4
(xftfont_list): Adjusted for the change of `list'
Kenichi Handa <handa@m17n.org>
parents:
92184
diff
changeset
|
479 XftDrawRect (xft_draw, &bg, |
|
8cbdb26068b4
(xftfont_list): Adjusted for the change of `list'
Kenichi Handa <handa@m17n.org>
parents:
92184
diff
changeset
|
480 x, y - face->font->ascent, s->width, face->font->height); |
| 90400 | 481 code = alloca (sizeof (FT_UInt) * len); |
| 482 for (i = 0; i < len; i++) | |
| 483 code[i] = ((XCHAR2B_BYTE1 (s->char2b + from + i) << 8) | |
| 484 | XCHAR2B_BYTE2 (s->char2b + from + i)); | |
| 485 | |
|
92184
6218afb021ac
(xftfont_draw): Pay attention to s->padding_p.
Kenichi Handa <handa@m17n.org>
parents:
91907
diff
changeset
|
486 if (s->padding_p) |
|
6218afb021ac
(xftfont_draw): Pay attention to s->padding_p.
Kenichi Handa <handa@m17n.org>
parents:
91907
diff
changeset
|
487 for (i = 0; i < len; i++) |
|
6218afb021ac
(xftfont_draw): Pay attention to s->padding_p.
Kenichi Handa <handa@m17n.org>
parents:
91907
diff
changeset
|
488 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
|
489 x + i, y, code + i, 1); |
|
6218afb021ac
(xftfont_draw): Pay attention to s->padding_p.
Kenichi Handa <handa@m17n.org>
parents:
91907
diff
changeset
|
490 else |
|
6218afb021ac
(xftfont_draw): Pay attention to s->padding_p.
Kenichi Handa <handa@m17n.org>
parents:
91907
diff
changeset
|
491 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
|
492 x, y, code, len); |
| 90400 | 493 UNBLOCK_INPUT; |
| 494 | |
| 495 return len; | |
| 496 } | |
| 497 | |
| 498 static int | |
| 499 xftfont_anchor_point (font, code, index, x, y) | |
| 500 struct font *font; | |
| 501 unsigned code; | |
| 502 int index; | |
| 503 int *x, *y; | |
| 504 { | |
| 505 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
|
506 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
|
507 int result; |
| 90400 | 508 |
| 509 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
|
510 result = -1; |
|
040f2e332dc3
(struct xftfont_info): Delete the member ft_face.
Kenichi Handa <handa@m17n.org>
parents:
91163
diff
changeset
|
511 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
|
512 result = -1; |
|
040f2e332dc3
(struct xftfont_info): Delete the member ft_face.
Kenichi Handa <handa@m17n.org>
parents:
91163
diff
changeset
|
513 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
|
514 result = -1; |
|
040f2e332dc3
(struct xftfont_info): Delete the member ft_face.
Kenichi Handa <handa@m17n.org>
parents:
91163
diff
changeset
|
515 else |
|
040f2e332dc3
(struct xftfont_info): Delete the member ft_face.
Kenichi Handa <handa@m17n.org>
parents:
91163
diff
changeset
|
516 { |
|
040f2e332dc3
(struct xftfont_info): Delete the member ft_face.
Kenichi Handa <handa@m17n.org>
parents:
91163
diff
changeset
|
517 *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
|
518 *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
|
519 } |
|
040f2e332dc3
(struct xftfont_info): Delete the member ft_face.
Kenichi Handa <handa@m17n.org>
parents:
91163
diff
changeset
|
520 XftUnlockFace (xftfont_info->xftfont); |
|
040f2e332dc3
(struct xftfont_info): Delete the member ft_face.
Kenichi Handa <handa@m17n.org>
parents:
91163
diff
changeset
|
521 return result; |
| 90400 | 522 } |
| 523 | |
|
91110
82a42637237c
(struct xftface_info): Delete the member xft_draw.
Kenichi Handa <handa@m17n.org>
parents:
91027
diff
changeset
|
524 static int |
|
82a42637237c
(struct xftface_info): Delete the member xft_draw.
Kenichi Handa <handa@m17n.org>
parents:
91027
diff
changeset
|
525 xftfont_end_for_frame (f) |
|
82a42637237c
(struct xftface_info): Delete the member xft_draw.
Kenichi Handa <handa@m17n.org>
parents:
91027
diff
changeset
|
526 FRAME_PTR f; |
|
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 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
|
529 |
|
82a42637237c
(struct xftface_info): Delete the member xft_draw.
Kenichi Handa <handa@m17n.org>
parents:
91027
diff
changeset
|
530 if (xft_draw) |
|
82a42637237c
(struct xftface_info): Delete the member xft_draw.
Kenichi Handa <handa@m17n.org>
parents:
91027
diff
changeset
|
531 { |
|
82a42637237c
(struct xftface_info): Delete the member xft_draw.
Kenichi Handa <handa@m17n.org>
parents:
91027
diff
changeset
|
532 BLOCK_INPUT; |
|
82a42637237c
(struct xftface_info): Delete the member xft_draw.
Kenichi Handa <handa@m17n.org>
parents:
91027
diff
changeset
|
533 XftDrawDestroy (xft_draw); |
|
82a42637237c
(struct xftface_info): Delete the member xft_draw.
Kenichi Handa <handa@m17n.org>
parents:
91027
diff
changeset
|
534 UNBLOCK_INPUT; |
|
82a42637237c
(struct xftface_info): Delete the member xft_draw.
Kenichi Handa <handa@m17n.org>
parents:
91027
diff
changeset
|
535 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
|
536 } |
|
82a42637237c
(struct xftface_info): Delete the member xft_draw.
Kenichi Handa <handa@m17n.org>
parents:
91027
diff
changeset
|
537 return 0; |
|
82a42637237c
(struct xftface_info): Delete the member xft_draw.
Kenichi Handa <handa@m17n.org>
parents:
91027
diff
changeset
|
538 } |
| 90400 | 539 |
| 91143 | 540 #ifdef HAVE_LIBOTF |
| 541 #ifdef HAVE_M17N_FLT | |
| 542 static Lisp_Object | |
| 543 xftfont_shape (lgstring) | |
| 544 Lisp_Object lgstring; | |
| 545 { | |
| 546 struct font *font; | |
| 547 struct xftfont_info *xftfont_info; | |
|
94941
8cbdb26068b4
(xftfont_list): Adjusted for the change of `list'
Kenichi Handa <handa@m17n.org>
parents:
92184
diff
changeset
|
548 Lisp_Object result; |
|
91226
040f2e332dc3
(struct xftfont_info): Delete the member ft_face.
Kenichi Handa <handa@m17n.org>
parents:
91163
diff
changeset
|
549 FT_Face ft_face; |
| 91143 | 550 |
| 551 CHECK_FONT_GET_OBJECT (LGSTRING_FONT (lgstring), font); | |
| 552 xftfont_info = (struct xftfont_info *) font; | |
| 553 if (! xftfont_info->maybe_otf) | |
| 554 return Qnil; | |
|
91226
040f2e332dc3
(struct xftfont_info): Delete the member ft_face.
Kenichi Handa <handa@m17n.org>
parents:
91163
diff
changeset
|
555 ft_face = XftLockFace (xftfont_info->xftfont); |
| 91143 | 556 if (! xftfont_info->otf) |
| 557 { | |
|
91226
040f2e332dc3
(struct xftfont_info): Delete the member ft_face.
Kenichi Handa <handa@m17n.org>
parents:
91163
diff
changeset
|
558 OTF *otf = OTF_open_ft_face (ft_face); |
| 91143 | 559 |
| 560 if (! otf || OTF_get_table (otf, "head") < 0) | |
| 561 { | |
| 562 if (otf) | |
| 563 OTF_close (otf); | |
| 564 xftfont_info->maybe_otf = 0; | |
|
91226
040f2e332dc3
(struct xftfont_info): Delete the member ft_face.
Kenichi Handa <handa@m17n.org>
parents:
91163
diff
changeset
|
565 XftUnlockFace (xftfont_info->xftfont); |
|
94941
8cbdb26068b4
(xftfont_list): Adjusted for the change of `list'
Kenichi Handa <handa@m17n.org>
parents:
92184
diff
changeset
|
566 return Qnil; |
| 91143 | 567 } |
| 568 xftfont_info->otf = otf; | |
| 569 } | |
| 570 | |
|
91226
040f2e332dc3
(struct xftfont_info): Delete the member ft_face.
Kenichi Handa <handa@m17n.org>
parents:
91163
diff
changeset
|
571 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
|
572 XftUnlockFace (xftfont_info->xftfont); |
|
040f2e332dc3
(struct xftfont_info): Delete the member ft_face.
Kenichi Handa <handa@m17n.org>
parents:
91163
diff
changeset
|
573 return result; |
| 91143 | 574 } |
| 575 #endif /* HAVE_M17N_FLT */ | |
| 576 #endif /* HAVE_LIBOTF */ | |
| 577 | |
| 90400 | 578 void |
| 579 syms_of_xftfont () | |
| 580 { | |
| 581 DEFSYM (Qxft, "xft"); | |
| 582 | |
| 583 xftfont_driver = ftfont_driver; | |
| 584 xftfont_driver.type = Qxft; | |
| 585 xftfont_driver.get_cache = xfont_driver.get_cache; | |
| 586 xftfont_driver.list = xftfont_list; | |
|
90559
fb5d3ac2d786
(xftfont_match): New function.
Kenichi Handa <handa@m17n.org>
parents:
90527
diff
changeset
|
587 xftfont_driver.match = xftfont_match; |
| 90400 | 588 xftfont_driver.open = xftfont_open; |
| 589 xftfont_driver.close = xftfont_close; | |
| 590 xftfont_driver.prepare_face = xftfont_prepare_face; | |
| 591 xftfont_driver.done_face = xftfont_done_face; | |
| 592 xftfont_driver.encode_char = xftfont_encode_char; | |
| 593 xftfont_driver.text_extents = xftfont_text_extents; | |
| 594 xftfont_driver.draw = xftfont_draw; | |
| 595 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
|
596 xftfont_driver.end_for_frame = xftfont_end_for_frame; |
| 91143 | 597 #ifdef HAVE_LIBOTF |
| 598 #ifdef HAVE_M17N_FLT | |
| 599 xftfont_driver.shape = xftfont_shape; | |
| 600 #endif /* HAVE_M17N_FLT */ | |
| 601 #endif /* HAVE_LIBOTF */ | |
| 90400 | 602 |
| 603 register_font_driver (&xftfont_driver, NULL); | |
| 604 } | |
| 90427 | 605 |
| 606 /* arch-tag: 64ec61bf-7c8e-4fe6-b953-c6a85d5e1605 | |
| 607 (do not change this comment) */ |
