comparison src/xftfont.c @ 90442:d6abf2344438

(xftfont_open): Make the font name fontconfig's style. Add BLOCK_INPUT and UNBLOCK_INPUT. (xftfont_close): Free font->font.name if not NULL.
author Kenichi Handa <handa@m17n.org>
date Fri, 09 Jun 2006 02:15:23 +0000
parents ddb25860d044
children 86449661f321
comparison
equal deleted inserted replaced
90441:d63258b13d84 90442:d6abf2344438
195 { 195 {
196 Display_Info *dpyinfo = FRAME_X_DISPLAY_INFO (f); 196 Display_Info *dpyinfo = FRAME_X_DISPLAY_INFO (f);
197 Display *display = FRAME_X_DISPLAY (f); 197 Display *display = FRAME_X_DISPLAY (f);
198 Lisp_Object val; 198 Lisp_Object val;
199 FcPattern *pattern, *pat; 199 FcPattern *pattern, *pat;
200 FcChar8 *file; 200 FcChar8 *file, *name;
201 XFontStruct *xfont; 201 XFontStruct *xfont;
202 struct xftfont_info *xftfont_info; 202 struct xftfont_info *xftfont_info;
203 struct font *font; 203 struct font *font;
204 double size = 0; 204 double size = 0;
205 XftFont *xftfont; 205 XftFont *xftfont;
206 int spacing; 206 int spacing;
207 int len;
207 208
208 val = AREF (entity, FONT_EXTRA_INDEX); 209 val = AREF (entity, FONT_EXTRA_INDEX);
209 if (XTYPE (val) != Lisp_Misc 210 if (XTYPE (val) != Lisp_Misc
210 || XMISCTYPE (val) != Lisp_Misc_Save_Value) 211 || XMISCTYPE (val) != Lisp_Misc_Save_Value)
211 return NULL; 212 return NULL;
214 return NULL; 215 return NULL;
215 216
216 size = XINT (AREF (entity, FONT_SIZE_INDEX)); 217 size = XINT (AREF (entity, FONT_SIZE_INDEX));
217 if (size == 0) 218 if (size == 0)
218 size = pixel_size; 219 size = pixel_size;
220 if (FcPatternGetString (pattern, FC_FILE, 1, &name) != FcResultMatch)
221 {
222 int isize = size;
223
224 name = malloc (strlen ((char *) file) + 30);
225 if (! name)
226 return NULL;
227 sprintf (name, ":file=%s:pixelsize=%d", (char *) file, isize);
228 }
229
219 pat = FcPatternCreate (); 230 pat = FcPatternCreate ();
220 FcPatternAddString (pat, FC_FILE, file); 231 FcPatternAddString (pat, FC_FILE, file);
221 FcPatternAddDouble (pat, FC_PIXEL_SIZE, pixel_size); 232 FcPatternAddDouble (pat, FC_PIXEL_SIZE, pixel_size);
222 FcPatternAddBool (pat, FC_ANTIALIAS, FcTrue); 233 FcPatternAddBool (pat, FC_ANTIALIAS, FcTrue);
234
235 BLOCK_INPUT;
223 xftfont = XftFontOpenPattern (display, pat); 236 xftfont = XftFontOpenPattern (display, pat);
224 /* We should not destroy PAT here because it is kept in XFTFONT and 237 /* We should not destroy PAT here because it is kept in XFTFONT and
225 destroyed automatically when XFTFONT is closed. */ 238 destroyed automatically when XFTFONT is closed. */
226 if (! xftfont) 239 if (! xftfont)
227 return NULL; 240 {
241 UNBLOCK_INPUT;
242 return NULL;
243 }
228 244
229 xftfont_info = malloc (sizeof (struct xftfont_info)); 245 xftfont_info = malloc (sizeof (struct xftfont_info));
230 if (! xftfont_info) 246 if (! xftfont_info)
231 { 247 {
232 XftFontClose (display, xftfont); 248 XftFontClose (display, xftfont);
249 UNBLOCK_INPUT;
233 return NULL; 250 return NULL;
234 } 251 }
235 xfont = malloc (sizeof (XFontStruct)); 252 xfont = malloc (sizeof (XFontStruct));
236 if (! xftfont_info) 253 if (! xftfont_info)
237 { 254 {
238 XftFontClose (display, xftfont); 255 XftFontClose (display, xftfont);
239 free (xftfont_info); 256 free (xftfont_info);
257 UNBLOCK_INPUT;
240 return NULL; 258 return NULL;
241 } 259 }
242 xftfont_info->display = display; 260 xftfont_info->display = display;
243 xftfont_info->screen = FRAME_X_SCREEN_NUMBER (f); 261 xftfont_info->screen = FRAME_X_SCREEN_NUMBER (f);
244 xftfont_info->xftfont = xftfont; 262 xftfont_info->xftfont = xftfont;
246 264
247 font = (struct font *) xftfont_info; 265 font = (struct font *) xftfont_info;
248 font->entity = entity; 266 font->entity = entity;
249 font->pixel_size = size; 267 font->pixel_size = size;
250 font->driver = &xftfont_driver; 268 font->driver = &xftfont_driver;
251 font->font.name = font->font.full_name = NULL; 269 font->font.full_name = font->font.name = (char *) name;
252 font->file_name = (char *) file; 270 font->file_name = (char *) file;
253 font->font.size = xftfont->max_advance_width; 271 font->font.size = xftfont->max_advance_width;
254 font->ascent = xftfont->ascent; 272 font->ascent = xftfont->ascent;
255 font->descent = xftfont->descent; 273 font->descent = xftfont->descent;
256 font->font.height = xftfont->ascent + xftfont->descent; 274 font->font.height = xftfont->ascent + xftfont->descent;
277 /* dirty workaround */ 295 /* dirty workaround */
278 font->font.space_width = pixel_size; 296 font->font.space_width = pixel_size;
279 XftTextExtents8 (display, xftfont, ascii_printable + 1, 94, &extents); 297 XftTextExtents8 (display, xftfont, ascii_printable + 1, 94, &extents);
280 font->font.average_width = (font->font.space_width + extents.xOff) / 95; 298 font->font.average_width = (font->font.space_width + extents.xOff) / 95;
281 } 299 }
300 UNBLOCK_INPUT;
282 301
283 /* Unfortunately Xft doesn't provide a way to get minimum char 302 /* Unfortunately Xft doesn't provide a way to get minimum char
284 width. So, we use space_width instead. */ 303 width. So, we use space_width instead. */
285 font->min_width = font->font.space_width; 304 font->min_width = font->font.space_width;
286 305
331 { 350 {
332 struct xftfont_info *xftfont_info = (struct xftfont_info *) font; 351 struct xftfont_info *xftfont_info = (struct xftfont_info *) font;
333 352
334 XftUnlockFace (xftfont_info->xftfont); 353 XftUnlockFace (xftfont_info->xftfont);
335 XftFontClose (xftfont_info->display, xftfont_info->xftfont); 354 XftFontClose (xftfont_info->display, xftfont_info->xftfont);
355 if (font->font.name)
356 free (font->font.name);
336 free (font); 357 free (font);
337 FRAME_X_DISPLAY_INFO (f)->n_fonts--; 358 FRAME_X_DISPLAY_INFO (f)->n_fonts--;
338 } 359 }
339 360
340 static int 361 static int