unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Eli Zaretskii <eliz@gnu.org>
To: "Clément Pit--Claudel" <clement.pit@gmail.com>
Cc: emacs-devel@gnu.org
Subject: Re: How do I set up font fallback in a robust way?
Date: Sun, 10 Apr 2016 19:38:51 +0300	[thread overview]
Message-ID: <83k2k5h10k.fsf@gnu.org> (raw)
In-Reply-To: <570A5CB0.8070107@gmail.com> (message from Clément Pit--Claudel on Sun, 10 Apr 2016 10:01:20 -0400)

> Cc: emacs-devel@gnu.org
> From: Clément Pit--Claudel <clement.pit@gmail.com>
> Date: Sun, 10 Apr 2016 10:01:20 -0400
> 
> In emacs -Q, insert the following in the *scratch* buffer:
> 
>     (set-fontset-font "fontset-default" 'unicode (font-spec :name "Ubuntu Mono") nil)
>     (set-fontset-font "fontset-default" 'unicode (font-spec :name "FreeMono") nil 'append)
>     (set-fontset-font "fontset-default" 'unicode (font-spec :name "Symbola") nil 'append)
> 
>     (insert "ℕ𝓟⧺×≠≥≤±¬∨∧∃∀λ⟿⟹⊥⊤⊢")
> 
> Now run the lines one by one, and observe the "(insert ...)" line. Before running anything, it looks fine. It still looks fine after running the first line. Running the second line causes the 𝓟 to disappear; it is replaced by a square containing 01D4DF, and C-u C-x = says "display: no font available". Finally, running the third line fixes the 𝓟.
> 
> I don't understand how this is possible. How can adding FreeMono cause Emacs to think that no font is available to display the 𝓟?

If this surprises you, your mental model of how Emacs looks for a
suitable font needs to be updated. ;-)

I'm guessing you expect Emacs to test whether each font can actually
display a character.  But doing so would be prohibitively slow,
because it requires opening each font, an expensive operation.  There
are hundreds of fonts installed on any given system, and opening all
of them one by one takes a long time and considerably slows redisplay.

So Emacs uses shortcuts: it examines the font meta-data, where a font
declares which blocks of Unicode it supports, and picks up the first
font that claims support for the block of the character.  But if a
font claims support for a certain block, but has no glyphs for the
specific character we need to display, we lose.  Coupled with the fact
that you have no control on the order in which Emacs looks up fonts,
this is why adding a font to a fontset could actually make things
worse.

For this reason, just lumping fonts indiscriminately into the fontset
is not a good idea.  Instead, you should examine the character ranges
where you have problems, and add fonts in a way that instructs Emacs
to use each font only in the range of characters where you know it
will produce good results.  And since "good results" is largely in the
eyes of the beholder, this can only approximately be done in the
default settings, the rest must be done by the end user.

> Same here; I need to find a good example. I ran into issues that seemed to be connected with the fact that (set-face-attribute 'default nil :height 120) creates a new fontset, as reported by fontset-list:
> 
>     (fontset-list)
>     => ("-unknown-Ubuntu Mono-normal-normal-normal-*-15-*-*-*-m-0-fontset-startup" "-*-fixed-medium-r-normal-*-16-*-*-*-*-*-fontset-standard" "-*-*-*-*-*-*-*-*-*-*-*-*-fontset-default")
> 
>     (set-face-attribute 'default nil :height 120)
>     => nil
> 
>     (fontset-list)
>     => ("-unknown-Ubuntu Mono-normal-normal-normal-*-16-*-*-*-m-0-fontset-auto1" "-unknown-Ubuntu Mono-normal-normal-normal-*-15-*-*-*-m-0-fontset-startup" "-*-fixed-medium-r-normal-*-16-*-*-*-*-*-fontset-standard" "-*-*-*-*-*-*-*-*-*-*-*-*-fontset-default")

It just added the fonts for the larger height, but they are fonts from
the same families, so I see no issues here: if the original fontset
supported the characters you want, the updated one will, too.



      reply	other threads:[~2016-04-10 16:38 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-04-09 19:14 How do I set up font fallback in a robust way? Clément Pit--Claudel
2016-04-09 19:46 ` Eli Zaretskii
2016-04-09 20:01   ` Clément Pit--Claudel
2016-04-10  2:44     ` Eli Zaretskii
2016-04-10 14:01       ` Clément Pit--Claudel
2016-04-10 16:38         ` Eli Zaretskii [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=83k2k5h10k.fsf@gnu.org \
    --to=eliz@gnu.org \
    --cc=clement.pit@gmail.com \
    --cc=emacs-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).