2

Context

I would like to print a full glyph table for a given font. Glyphs in an open type font can be identified by

  1. an optional code point value
  2. by a glyph name

Some fonts like cambriai.ttf have some glyphs without a codepoint assigned, but they still have a glyph name, for example uni02E5_uni02E8_uni02E6.ccmp. Those glyphs get code point value -1 assigned.

Problem

How can I print a glyph by name and not by code point value, even if the value is -1? I'm using the code from here with LuaTeX and it works, but clearly for the font above, the glyphs with value -1 are not shown.

enter image description here

2
  • check the unicodefonttable package ctan.org/pkg/unicodefonttable or provide a suitable test document. Commented Nov 18, 2022 at 17:17
  • @UlrikeFischer The code is the exactly same that I linked, only the font name changed to cambriai.ttf. With unicodefonttable I get a smaller table than with the linked code, because it ignores the -1 values completely, but that's exactly the interesting ones. Such a table that only works over code point values can't solve the problem of showing all glyphs in a font.
    – Guest
    Commented Nov 18, 2022 at 17:38

1 Answer 1

1

I now found a solution based on the discussion here that works for my font created with FontLab 8, but not with the example font name cambriai.ttf. Together with the following code, the linked glyph table can be completed to print all glyphs in the font), but as I said, for some reason it does not work with cambriai.ttf but with others it works...

\documentclass[a4paper]{article}
\usepackage{fontspec}

\begin{document}
\setmainfont{my_fontname.otf}
% the following line prints the glyph with the glyph name S_t that has no code point value assigned (codepoint value = -1). It seems that it does not work with cambriai.ttf but with a OTF-font created by FontLab 8 (maybe otf only solution?)
\char\directlua{tex.print(luaotfload.aux.slot_of_name(font.current(), [[S_t]])) }
\end{document}

Here is the patched glyph table from the linked answer that is now able to also print glyphs which don't have a codepoint value:

\documentclass[a4paper]{article}
\usepackage{luacode}
\usepackage[margin=0.5cm]{geometry}
\usepackage{fontspec}
\usepackage{multicol}
\setlength{\columnsep}{0.3cm} \setlength{\columnseprule}{1pt}
\setmainfont{Linux Libertine O}

\newfontface\OD{my_fontname.otf}
\begin{document}

\begin{multicols}{4}\noindent
\begin{luacode*}
local f = fontloader.open('my_fontname.otf')
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].unicode > 0) then
       tex.sprint("{\\OD\\char" .. glyphs[i].unicode .. "}");
   else
       -- Here the updated code: the first glyph table in LuaTeX printing ALL glyphs in a font!
       tex.sprint("{\\OD\\char\\directlua{tex.print(luaotfload.aux.slot_of_name(font.current(), [[" .. glyphs[i].name .. "]]))}}")
   end
   tex.print(" {\\small(")
   tex.print(-2, glyphs[i].name )
   tex.sprint(')}\\\\')
end
fontloader.close(f)

\end{luacode*}
\end{multicols}
\end{document}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .