Subject: Re: bug#53924: 26.1; fontification sometimes fails for some characters despite available glyphs

From: Eli Zaretskii <[email-masked]>
Date: Tue, 15 Feb 2022 16:21:43 +0200

> Date: Mon, 14 Feb 2022 18:01:43 -0800
> From: "Greg A. Woods" <[email-masked]>
> Cc: GNU Emacs Bug Reports <[email-masked]>
> 
> > > 	(font-families (cl-remove-duplicates
> > > 			(sort (font-family-list)
> > > 			      (lambda(x y) (string> (upcase x) (upcase y))))
> > > 			:test 'cl-equalp)))
> >
> > This is not recommended as a way to get useful fonts.
> 
> Perhaps you can explain that better or differently so I can try to
> understand?

Certainly.  Which part(s) would you like me to explain better?

> I chose font-family-list because it is (supposedly) window-system
> agnostic.  Indeed it works fine on macOS too, and it transparently even
> does approximately the right thing on a TTY.

font-family-list yields a list that includes fonts that are not
necessarily appropriate for Emacs.  As does x-list-fonts, if run with
just one argument.

> >  My suggestion
> > is to use the following instead:
> >
> >   (delete-dups
> >    (x-list-fonts "-*-*-medium-r-normal-*-*-*-*-*-*-iso10646-1"
> > 		 'default (selected-frame)))
> 
> BTW, delete-dups is wrong, but I finally found seq-uniq (to avoid
> cl-lib):

I don't see why delete-dups would be wrong here, but that's a tangent.

> 	(seq-uniq
> 	 (sort (font-family-list)
> 	       (lambda(x y) (string> (upcase x) (upcase y))))
> 	 (lambda(x y) (string= (upcase x) (upcase y))))

The problem with this is that it doesn't filter out fonts that are too
small for the frame, and fonts that cannot be used for the 'default'
face.  So the result is still unsafe.

> > Indeed, using x-list-fonts indiscriminately could very well include
> > fonts that Emacs cannot use or even those which will crash Emacs.
> 
> Indeed -- that's another reason why I chose not to use x-list-fonts!

But font-family-list is not better.  In fact, it's worse, because it
doesn't support the filtering x-list-fonts does when used with 3
arguments, and when the font XLFD pattern is set up to produce only
fonts that can be safely used in Emacs for the 'default' face.

> > Is this with the above Lisp program that tries all the fonts collected
> > by font-family-list, or is this with some other recipe to reproduce
> > the crash?  Also, was that in "emacs -Q"?
> 
> It turns out the crash happens with one font in particular,
> "Inconsolata".  I have some cleanup of the versions of that font in
> particular that I need to do to be sure I know which one is being used.
> 
> I can also now confirm the same crash occurs with both GTK+2.0 and with
> the Lucid (xaw3d) toolkits, and in both 26.1 and today's Git "master".

Can you show a simple Emacs -Q invocation with that font which
crashes?  Then I think I or someone else could look into the reasons.