comparison src/xftfont.c @ 90959:3f83c9d3f96c

(xftfont_open): If one of font's ASCII glyph has bigger ascent and descent than those of the font, use them as font's ascent and descent.
author Kenichi Handa <handa@m17n.org>
date Wed, 20 Jun 2007 12:10:07 +0000
parents 698001835583
children 7239c19e55e9
comparison
equal deleted inserted replaced
90958:119629f41ebb 90959:3f83c9d3f96c
221 double size = 0; 221 double size = 0;
222 XftFont *xftfont = NULL; 222 XftFont *xftfont = NULL;
223 int spacing; 223 int spacing;
224 char *name; 224 char *name;
225 int len; 225 int len;
226 XGlyphInfo extents;
226 227
227 val = AREF (entity, FONT_EXTRA_INDEX); 228 val = AREF (entity, FONT_EXTRA_INDEX);
228 if (XTYPE (val) != Lisp_Misc 229 if (XTYPE (val) != Lisp_Misc
229 || XMISCTYPE (val) != Lisp_Misc_Save_Value) 230 || XMISCTYPE (val) != Lisp_Misc_Save_Value)
230 return NULL; 231 return NULL;
283 goto err; 284 goto err;
284 font->font.full_name = font->font.name = name; 285 font->font.full_name = font->font.name = name;
285 font->file_name = (char *) file; 286 font->file_name = (char *) file;
286 font->font.size = xftfont->max_advance_width; 287 font->font.size = xftfont->max_advance_width;
287 font->font.charset = font->encoding_charset = font->repertory_charset = -1; 288 font->font.charset = font->encoding_charset = font->repertory_charset = -1;
288 font->ascent = xftfont->ascent;
289 font->descent = xftfont->descent;
290 font->font.height = xftfont->ascent + xftfont->descent;
291 289
292 if (FcPatternGetInteger (xftfont->pattern, FC_SPACING, 0, &spacing) 290 if (FcPatternGetInteger (xftfont->pattern, FC_SPACING, 0, &spacing)
293 != FcResultMatch) 291 != FcResultMatch)
294 spacing = FC_PROPORTIONAL; 292 spacing = FC_PROPORTIONAL;
293 if (! ascii_printable[0])
294 {
295 int i;
296 for (i = 0; i < 95; i++)
297 ascii_printable[i] = ' ' + i;
298 }
295 if (spacing != FC_PROPORTIONAL) 299 if (spacing != FC_PROPORTIONAL)
296 font->font.average_width = font->font.space_width 300 {
297 = xftfont->max_advance_width; 301 font->font.average_width = font->font.space_width
302 = xftfont->max_advance_width;
303 XftTextExtents8 (display, xftfont, ascii_printable + 1, 94, &extents);
304 }
298 else 305 else
299 { 306 {
300 XGlyphInfo extents;
301
302 if (! ascii_printable[0])
303 {
304 int i;
305 for (i = 0; i < 95; i++)
306 ascii_printable[i] = ' ' + i;
307 }
308 XftTextExtents8 (display, xftfont, ascii_printable, 1, &extents); 307 XftTextExtents8 (display, xftfont, ascii_printable, 1, &extents);
309 font->font.space_width = extents.xOff; 308 font->font.space_width = extents.xOff;
310 if (font->font.space_width <= 0) 309 if (font->font.space_width <= 0)
311 /* dirty workaround */ 310 /* dirty workaround */
312 font->font.space_width = pixel_size; 311 font->font.space_width = pixel_size;
313 XftTextExtents8 (display, xftfont, ascii_printable + 1, 94, &extents); 312 XftTextExtents8 (display, xftfont, ascii_printable + 1, 94, &extents);
314 font->font.average_width = (font->font.space_width + extents.xOff) / 95; 313 font->font.average_width = (font->font.space_width + extents.xOff) / 95;
315 } 314 }
316 UNBLOCK_INPUT; 315 UNBLOCK_INPUT;
317 316
317 font->ascent = xftfont->ascent;
318 if (font->ascent < extents.y)
319 font->ascent = extents.y;
320 font->descent = xftfont->descent;
321 if (font->descent < extents.height - extents.y)
322 font->descent = extents.height - extents.y;
323 font->font.height = font->ascent + font->descent;
324
318 /* Unfortunately Xft doesn't provide a way to get minimum char 325 /* Unfortunately Xft doesn't provide a way to get minimum char
319 width. So, we use space_width instead. */ 326 width. So, we use space_width instead. */
320 font->min_width = font->font.space_width; 327 font->min_width = font->font.space_width;
321 328
322 font->font.baseline_offset = 0; 329 font->font.baseline_offset = 0;
324 font->font.default_ascent = 0; 331 font->font.default_ascent = 0;
325 font->font.vertical_centering = 0; 332 font->font.vertical_centering = 0;
326 333
327 /* Setup pseudo XFontStruct */ 334 /* Setup pseudo XFontStruct */
328 xfont->fid = xftfont_default_fid (f); 335 xfont->fid = xftfont_default_fid (f);
329 xfont->ascent = xftfont->ascent; 336 xfont->ascent = font->ascent;
330 xfont->descent = xftfont->descent; 337 xfont->descent = font->descent;
331 xfont->max_bounds.descent = xftfont->descent; 338 xfont->max_bounds.descent = font->descent;
332 xfont->max_bounds.width = xftfont->max_advance_width; 339 xfont->max_bounds.width = xftfont->max_advance_width;
333 xfont->min_bounds.width = font->font.space_width; 340 xfont->min_bounds.width = font->font.space_width;
334 font->font.font = xfont; 341 font->font.font = xfont;
335 342
336 dpyinfo->n_fonts++; 343 dpyinfo->n_fonts++;