Subject: 24.1.50; NS regression: fallback font used even when glyph available in primary font

From: David Leatherman <[email-masked]>
Date: Tue, 14 Aug 2012 21:23:35 -0400

I managed to isolate the issue to the commit in which it was introduced
as well as the offending lines in the commit. The git commit when the
bug first started happening is 97665d8445c7f8b142cae9db2d81bdcafa310243
which was pushed on Sat, Feb 18 with the following commit message:

"Update char-script-table from the latest Unicode Database.

lisp/international/characters.el (script-list): Sync with the latest
Unicode Character Database."

In lisp/international/characters.el the addition of either of the
following two symbol character ranges will cause the issue: (taken out
of context here)

(#x2900 #x2BFF symbol)
(#x2E00 #x2E7F symbol)

If either of these lines remain, then the font will be incorrectly
chosen. I had to rebuild Emacs to test this despite the file being an
Emacs Lisp file, but it could be that I simply failed to figure out how
to change this file and make it work (I changed it, byte compiled it,
etc. with no effect). YMMV.

I turned on NSFONT_TRACE as suggested earlier and the below is from
starting emacs -Q, changing the font to Menlo, and inserting the EMPTY
SET character. The first trace is from the code with the two lines of
code removed (i.e., will produce the desired behavior). The second is
from the incorrect behavior. 

I've trimmed out non-essential differences. The first substantial
difference to me is the additional two lines in the second diff (the
second and third dotted pair at the beginning). This addition seems to
prevent nsfont.m from returning the 4 entities that it returns in the
correct case.

**  First - correct font chosen **

Emacs[73145:307] Request covering families for script: 'symbol'
(8192 . 10239)
(127232 . 127487)
(127744 . 128591)
(128640 . 128895)
Emacs[73145:307]     returning 4 families
Emacs[73145:307] Got desc NSCTFontDescriptor <0x1011e2e50> = {
    NSFontFamilyAttribute = Menlo;
} and found 4 matching fonts from it: 
created font_entity:
    #<font-entity ns apple Menlo nil iso10646-1 medium normal normal 0 nil 100 0 ((:script . symbol))>
created font_entity:
    #<font-entity ns apple Menlo nil iso10646-1 medium italic normal 0 nil 100 0 ((:script . symbol))>
created font_entity:
    #<font-entity ns apple Menlo nil iso10646-1 bold normal normal 0 nil 100 0 ((:script . symbol))>
created font_entity:
    #<font-entity ns apple Menlo nil iso10646-1 bold italic normal 0 nil 100 0 ((:script . symbol))>
    Returning 4 entities.
nsfont: open size 12 of fontentity:
    #<font-entity ns apple Menlo nil iso10646-1 medium normal normal 0 nil 100 0 ((:script . symbol))>
Emacs[73145:307] "Menlo-Regular 12.00 pt. P [] (0x100ae1270) fobj=0x101169740, spc=7.22"
*** nsfont_open CACHE HIT!
0x101819188	Finding glyphs for glyphs in block 34
0x101819188	Computing metrics for glyphs in block 7

** Second - incorrect font chosen **

Emacs[36212:307] Request covering families for script: 'symbol'
(8192 . 10239)
(10496 . 11263)
(11776 . 11903)
(127232 . 127487)
(127744 . 128591)
(128640 . 128895)
Emacs[36212:307]     returning 1 families
Emacs[36212:307] Got desc NSCTFontDescriptor <0x100adf8b0> = {
    NSFontFamilyAttribute = Menlo;
} and found 4 matching fonts from it: 
    Returning 0 entities.
nsfont: list for fontspec:
    #<font-spec ns nil Menlo nil iso10646-1 nil nil nil nil nil nil nil ((:script . symbol))>
Emacs[36212:307] Request covering families for script: 'symbol'
Emacs[36212:307]     returning 1 families
Emacs[36212:307] Got desc NSCTFontDescriptor <0x104408050> = {
    NSFontFamilyAttribute = Menlo;
} and found 4 matching fonts from it: 
    Returning 0 entities.
nsfont: list for fontspec:
    #<font-spec ns apple nil nil iso10646-1 nil nil nil nil nil nil nil ((:script . symbol))>
Emacs[36212:307] Request covering families for script: 'symbol'
Emacs[36212:307]     returning 1 families
Emacs[36212:307] Got desc NSCTFontDescriptor <0x104405dd0> = {
} and found 330 matching fonts from it: 
created font_entity:
    #<font-entity ns apple STIXGeneral nil iso10646-1 medium normal normal 0 nil 0 0 ((:script . symbol))>
created font_entity:
    #<font-entity ns apple STIXGeneral nil iso10646-1 medium italic normal 0 nil 0 0 ((:script . symbol))>
created font_entity:
    #<font-entity ns apple STIXGeneral nil iso10646-1 bold normal normal 0 nil 0 0 ((:script . symbol))>
created font_entity:
    #<font-entity ns apple STIXGeneral nil iso10646-1 bold italic normal 0 nil 0 0 ((:script . symbol))>
    Returning 4 entities.
nsfont: open size 12 of fontentity:
    #<font-entity ns apple STIXGeneral nil iso10646-1 medium normal normal 0 nil 0 0 ((:script . symbol))>
Emacs[36212:307] "STIXGeneral-Regular 12.00 pt. P [] (0x100ae4ec0) fobj=0x100aac290, spc=3.00"
0x1049bde68	Finding glyphs for glyphs in block 34
0x1049bde68	Computing metrics for glyphs in block 4

*****

I hope this is helpful. I don't know the cause to these effects except
to observe that somehow the extra two character ranges in characters.el
end up causing nsfont.m to look up the wrong font.

Let me know if I can help or answer any questions.

--
David