aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorKenichi Handa2006-06-09 02:15:23 +0000
committerKenichi Handa2006-06-09 02:15:23 +0000
commitdcce3c588c79d8931ebca87636a4b87d81cd1bf2 (patch)
tree8851fa1e53e1df05f3eed1fdee158945d648774e /src
parentc2801c99bed19470fd4799355056ae0816aa47b4 (diff)
downloademacs-dcce3c588c79d8931ebca87636a4b87d81cd1bf2.tar.gz
emacs-dcce3c588c79d8931ebca87636a4b87d81cd1bf2.zip
(xftfont_open): Make the font name fontconfig's
style. Add BLOCK_INPUT and UNBLOCK_INPUT. (xftfont_close): Free font->font.name if not NULL.
Diffstat (limited to 'src')
-rw-r--r--src/xftfont.c27
1 files changed, 24 insertions, 3 deletions
diff --git a/src/xftfont.c b/src/xftfont.c
index d4d8ab46bc8..4bbd856bd56 100644
--- a/src/xftfont.c
+++ b/src/xftfont.c
@@ -197,13 +197,14 @@ xftfont_open (f, entity, pixel_size)
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
@@ -216,20 +217,36 @@ xftfont_open (f, entity, pixel_size)
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));
@@ -237,6 +254,7 @@ xftfont_open (f, entity, pixel_size)
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;
@@ -248,7 +266,7 @@ xftfont_open (f, entity, pixel_size)
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;
@@ -279,6 +297,7 @@ xftfont_open (f, entity, 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. */
@@ -333,6 +352,8 @@ xftfont_close (f, 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}