Hi Werner,
On Tue, 2025-09-09 at 05:16 +0000, Werner LEMBERG wrote:
> using the original and patched OpenType font produces the attached
> difference –
There's not enough context in the attached diff to actually see
anything. Can you try again but with "table.serialize" replaced with
"dot_inspect":
function dot_inspect(value, parents)
if not parents then
parents = {}
end
local literal = false
if type(value) == "table" then
local found = false
for k, v in pairs(value) do
local k = k
found = true
if type(k) ~= "string" then
k = "[" .. tostring(k) .. "]"
end
dot_inspect(v, table.imerged(parents, {k}))
end
if found then
return
else
value = "(empty table)"
literal = true
end
elseif type(value) == "function" then
local info = debug.getinfo(value)
value = info.source .. ":" .. info.linedefined
literal = true
end
if literal or (type(value) == "userdata") then
value = tostring(value)
else
value = string.format("%q", value)
end
value = table.concat(parents, ".") .. " = " .. value
print(value)
end
> the tiny modification in the font's 'mark2base' lookup
> explodes, causing four large, identical changes to `tfmdata`
> subtables.
Lua tables are reference types, so those 4 subtables may actually be the
same table, meaning that a single modification might change all of them.
This is just a guess though; I may be wrong here.
Also, most of the subtables are unused, so you probably only need to
change a single value anyways.
> In other words, it is unrealistic to modify `tfmdata`
> directly, and I need to hook into LuaTeX's OpenType font handler one
> step earlier, AFAICS. How can I do that?
With the caveat that this depends on internal implementation details,
and is therefore unsupported and could change at any time,
"fonts.handlers.otf.readers.loadfont" is the earliest point that you can
modify the font data:
\input{luaotfload.sty}
\directlua{
--[[ Force the font to be reloaded every time; only needed for testing.
]]
do
local saved = luaotfload.fontloader.containers.read
function luaotfload.fontloader.containers.read(...)
local tfmdata = saved(...)
if tfmdata and
file.basename(tfmdata.resources.filename) ==
"EBGaramond-Regular.otf"
then
tfmdata.tableversion = -1
end
return tfmdata
end
end
do
local saved = fonts.handlers.otf.readers.loadfont
function fonts.handlers.otf.readers.loadfont(...)
local tfmdata = saved(...)
--[[ Do something with the font data here. ]]
inspect {
["in"] = { ... },
["out"] = tfmdata,
}
return tfmdata
end
end
}
\font\ebgaramond={file:EBGaramond-Regular.otf} at 12pt
\ebgaramond Hello, world!
\bye
The table is actually quite a bit larger and more complicated than the
one in "luaotfload.patch_font", so this probably isn't very useful for
you.
Thanks,
-- Max