[luatex] Question about creating virtual fonts

Henri Menke henrimenke at gmail.com
Thu Jun 27 06:47:31 CEST 2019


Dear list,

I want to create a virtual font where the digits are mirrored upside
down.  To this end I defined a virtual font where in the commands arrays
I apply a PDF transformation to the digits.  However, when I write
1234567 in the source, the characters show up upside down but also in
reverse.  Why is that?  Also, all the other characters seem to
have zero width.

Another issue is that if I add a size field in the fonts array, the font
completely disappears from the PDF with no error message.  I'm surely
doing something wrong but the LuaTeX manual has very little
documentation about the creation of virtual fonts.

MWE is below.

Many thanks, Henri

------------------

{\catcode`\%=12\gdef\letterpercent{%}}
\directlua{
f = font.read_tfm("cmtt10", 10)
f.name = "cmtt10-digits"
f.type = "virtual"
f.fonts = {
    {
        name = "cmtt10", 
        % size = 10 % adding this field makes the font disappear
    }
}
for i,v in pairs(f.characters) do
    local height = f.characters[i].height
    local width = f.characters[i].width
    if (string.char(i)):find("[1234567890]") then
        v.commands = {
            { "special", string.format("pdf: q 1 0 0 -1 0 \letterpercent d cm", height) },
            { "font", 0 },
            { "char", i },
            { "special", "pdf: Q" },
        }
    else
        v.commands = {
            { "font", 0 },
            { "char", i },
        }
    end
end
myfont = font.define(f)
}

\def\myfont{\setfontid\directlua{tex.print(myfont)}}
\font\cmtt=cmtt10

\cmtt abc 1234567 def

\myfont abc 1234567 def

\bye




More information about the luatex mailing list