O/T : linux: can I list which small caps are in a ttf/otf font ?

Ken Moffat zarniwhoop at ntlworld.com
Thu Oct 26 20:43:25 CEST 2023


On Thu, Oct 26, 2023 at 08:52:15AM +0200, Herbert Voss wrote:
> 
> 
> Am 26.10.23 um 00:46 schrieb Peter Flynn:
> > On 25/10/2023 22:40, Karl Berry wrote:
> > > pf> I believe fontforge is able to dump all the metadata from a font
> > > pf> file,
> > > 
> > > Just to mention, for dumping data from otf/ttf, I have had good luck
> > > with ttx from "fonttools". https://github.com/fonttools/fontools
> > 
> > I had utterly forgotten ttx, thanks.
> 
> you can also list the fonts with lualatex:
> 
> \documentclass[a4paper]{article}
> \usepackage{luacode}
> \usepackage[margin=0.5cm]{geometry}
> \usepackage{libertinus-otf}
> \usepackage{multicol}
> \setlength{\columnsep}{0.3cm} \setlength{\columnseprule}{1pt}
> 
> \newfontface\FiraSC{FiraSans-Regular.otf}[RawFeature=+c2sc]   %
> \begin{document}
> 
> \begin{multicols}{4}\noindent
> \begin{luacode*}
>     local f = fontloader.open('/tmp/FiraSans-Regular.otf') -- the test font
>     local glyphs = {}
>     for i = 0, f.glyphmax - 1 do
>         local g = f.glyphs[i]
>       if g then
>         table.insert(glyphs, {name = g.name, unicode = g.unicode})
>       end
>     end
>     table.sort(glyphs, function (a,b) return (a.unicode < b.unicode) end)
>     for i = 1, #glyphs do
>       tex.sprint(glyphs[i].unicode .. ": ")
>       if glyphs[i].name:match("^.+(%..+)$") == ".sc" then
>         if glyphs[i].unicode > 0 then
>             tex.sprint("{\\FiraSC\\char" .. glyphs[i].unicode .. "\\relax}")
>         else
> tex.sprint("{\\FiraSC\\char\\directlua{tex.print(luaotfload.aux.slot_of_name(font.current(),
> [["
>                 .. glyphs[i].name .. "]]))}}")
>            end
>           tex.print(" { \\small\\space(")
>         tex.print(-2, glyphs[i].name)
>         tex.sprint(')}\\\\')
>       end
>     end
>     fontloader.close(f)
> \end{luacode*}
> \end{multicols}
> 
> \end{document}
> 
> 
> lists all glyphs with extension .cs
> 
> Herbert

Thanks.  Looks interesting, but I cannot get it to work (I have zero
experience of lua).

I'm using TL2023 with patch for luatex vulnerability but no
further updates. In the end I downloaded Fira from google (now a
ttf) trying to match your example rather than looking at a different
font - with that in /tmp, and both \newfontface and fontloader.open
specifying the ttf, fontspec did not find it.  Moved it to
/usr/share/fonts/for-analysis where I'm looking at fonts.  

That line then read
    local f = fontloader.open('/usr/share/fonts/for-analysis/FiraSans-Regular.ttf') -- the test font

I ran luaotfload-tool --update

the font showed in fontconfig:
 $fc-list | grep FiraSans-Regular.ttf
/usr/share/fonts/for-analysis/FiraSans-Regular.ttf: Fira Sans:style=Regular

but the lua code still failed somewhere,:

/opt/texlive/2023/texmf-dist/tex/latex/unicode-math/unicode-math-table.tex)))
*************************************
* Using libertinus math *
*************************************
) (/opt/texlive/2023/texmf-dist/tex/latex/tools/multicol.sty) (./voss.aux)
*geometry* driver: auto-detecting
*geometry* detected driver: luatex
[\directlua]:1: syntax error near ' local'.
\luacode at dbg@exec ...code at maybe@printdbg {#1} #1 }

l.44 \end{luacode*}

Since that changed line is the first line of the lua code, I assume
it is pointing to that line.

I also see that vim's syntax highlighting does notlike the '^' in
if glyphs[i].name:match("^.+(%..+)$") == ".sc" then
and colours everything from '%' to end of line as if comments.
But I assume that is just one of the oddities of vim's syntax
highlighting.

I then googled a bit further for the otf font and found it.  My
assumption is that the ttf font should have been suitable for Small
Caps, but I'm now trying to fully match the example.

If I set the \newfontface back to FiraSans-Regular.otf *without*
making it known to fontconfig, fails, fontspec cannot find it.
With it in /usr/share/fonts/for-analysis it gets past that but still
fails with the same syntax error.

It appears that fontconfig has to recognize the font, so putting it
in /tmp is not generally likely to work ?

I've tried pointing fontloader.open to the otf file in
/usr/share/fonts/for-analysis and then changing single quotes to
double quotes, but it make no difference.

ĸen
-- 
  'The universe is so big, sir, that it obeys all possible laws,'
  said Ponder, 'For a given value of "teapot".
           -- The Science of Discworld II, 'The Globe'


More information about the tex-live mailing list.