Subject: Re: bug#3081: 23.0.92;x-list-fonts no longer gives correct result - substitutes * forfixed font size

From: Kenichi Handa <[email-masked]>
Date: Thu, 23 Apr 2009 20:26:21 +0900

In article <[email-masked]>, "Drew Adams" <[email-masked]> writes:

> > > I have this defcustom, which I use to choose a small font:
> > > (defcustom palette-font
> > >   (and window-system
> > >        (or (car (x-list-fonts
> > >   "-*-Courier-*-*-*-*-5-*-*-*-*-*-iso8859-1" nil nil 1)) ; 1
> > >            (car (x-list-fonts 
> > "-*-fixed-*-*-*-*-5-*-*-*-*-*-iso8859-1"
> > >   nil nil 1)) ; 2
> > >            (car (x-list-fonts
> > >   "-*-Terminal-*-*-*-*-5-*-*-*-*-*-iso8859-1" nil nil 1)) ; 3
> > >            (car (x-list-fonts 
> > "-*-*-*-*-*-*-5-*-*-*-*-*-iso8859-1" nil
> > >   nil 1)))) ;4
> > >   "...")
> > [...]
> > > In Emacs 23, these are the values:
> >  
> > > 1. 
> > ("-outline-Courier-bold-normal-normal-mono-*-*-*-*-c-*-iso8859-1")
> > > 2. nil
> > > 3. nil
> > > 4. ("-outline-Lucida Sans
> > > Typewriter-bold-normal-normal-sans-*-*-*-*-c-*-iso8859-1")
> >  
> > > The first difference to notice is #4: a completely different font
> > > family is used. Why should this be? Anyway, I don't really have a
> > > problem with this.
> >  
> > If you don't specify a family, which family is selected is
> > completely arbitrary.

> I guess you're speaking about #2 and #3 - the nil values. That's OK. (And thanks
> for the explanation.)

No, I'm speaking about #4.  In #2 and #3 you specify family
name ("fixed" and "terminal" respectively).

> > > The problem is that the font size is not correct: * instead 
> > > of a real font size.  The whole point of this defcustom is to try to find a
> > > default value for the option that provides a tiny font that the user
> > > has available. It tries to match various fonts of size 5, until it
> > > finds a match.
> >  
> > I installed a fix.  Please try again.

> Thanks for the quick fix.

> What do I need to pick up, to try it? Is this a Lisp fix (which library)? 

No, the change was in src/xfaces.c.

2009-04-23  Kenichi Handa  <[email-masked]>

	* xfaces.c (Fx_list_fonts): If a font size is specified in
	PATTERN, set it in returned scalable fonts.

Index: xfaces.c
===================================================================
RCS file: /cvsroot/emacs/emacs/src/xfaces.c,v
retrieving revision 1.432
retrieving revision 1.433
diff -u -r1.432 -r1.433
--- xfaces.c	16 Apr 2009 01:08:24 -0000	1.432
+++ xfaces.c	23 Apr 2009 01:33:33 -0000	1.433
@@ -1904,7 +1904,22 @@
       }
     args[0] = Flist_fonts (font_spec, frame, maximum, font_spec);
     for (tail = args[0]; CONSP (tail); tail = XCDR (tail))
-      XSETCAR (tail, Ffont_xlfd_name (XCAR (tail), Qnil));
+      {
+	Lisp_Object font_entity;
+
+	font_entity = XCAR (tail);
+	if ((NILP (AREF (font_entity, FONT_SIZE_INDEX))
+	     || XINT (AREF (font_entity, FONT_SIZE_INDEX)) == 0)
+	    && ! NILP (AREF (font_spec, FONT_SIZE_INDEX)))
+	  {
+	    /* This is a scalable font.  For backward compatibility,
+	       we set the specified size. */
+	    font_entity = Fcopy_font_spec (font_entity);
+	    ASET (font_entity, FONT_SIZE_INDEX,
+		  AREF (font_spec, FONT_SIZE_INDEX));
+	  }
+	XSETCAR (tail, Ffont_xlfd_name (font_entity, Qnil));
+      }
     if (NILP (frame))
       /* We don't have to check fontsets.  */
       return args[0];

---
Kenichi Handa
[email-masked]