
Hello all, a somewhat generic question. I am playing with variable fonts, and I can see that I can create font metrics with font:set_variation(...) so the shaper takes the new widths into account. But writing this font into PDF has no visible effect. I assume the subsetter in LuaTeX does not take the variations into account. If this is correct so far: Are there any plans to change this, for example to use the harfbuzz subsetter? Thanks, Patrick

Hi Patrick, On Wed, 2025-04-09 at 09:19 +0200, Patrick Gundlach wrote:
I am playing with variable fonts, and I can see that I can create font metrics with
font:set_variation(...)
so the shaper takes the new widths into account.
But writing this font into PDF has no visible effect. I assume the subsetter in LuaTeX does not take the variations into account.
You can use the (undocumented) "glyph_stream_provider" callback to write
the correct data to the PDF file. If you're using luaotfload or ConTeXt,
it handles the "glyph_stream_provider" for you, so you can just add the
data for each character to "fonts.hashes.streams[

Thank you, Max. Do you know (does anyone know) how to activate this callback? I do callback.register("glyph_stream_provider",function () assert(false) end) but this never gets called. Other callbacks seem to work fine. I use this LuaTeX This is LuaHBTeX, Version 1.22.0 (TeX Live 2025) Development id: 7673 Patrick

On Wed, 9 Apr 2025 at 10:47, Patrick Gundlach
Thank you, Max.
Do you know (does anyone know) how to activate this callback?
I do
callback.register("glyph_stream_provider",function () assert(false) end)
but this never gets called.
I know nothing, but luaotfload registers a 3-arg function luatexbase.add_to_callback("glyph_stream_provider",function(id,index,mode) if id <= 0 then return "" end local stream = streams[id].streams if not stream then return "" end return stream[index] or "" end, "luaotfload.glyph_stream") in latex3/luaotfload/src/luaotfload-init.lua I suspect you can read that font loader code better than me so I won't attempt to trace where this actually gets called:-) David
Other callbacks seem to work fine.
I use this LuaTeX
This is LuaHBTeX, Version 1.22.0 (TeX Live 2025) Development id: 7673
Patrick
_______________________________________________ dev-luatex mailing list -- dev-luatex@ntg.nl To unsubscribe send an email to dev-luatex-leave@ntg.nl

Thank you David, I've got it to work now. I had to activate it with f.streamprovider = 2 where f is the font table I pass to define_font. Sadly, this is (as the name suggests) only the code for each glyph. I wish I could pass a complete font program to a callback and subset everything by myself (or rather: the harfbuzz subsetting library). Patrick

Hi Patrick, On Wed, 2025-04-09 at 11:45 +0200, Patrick Gundlach wrote:
Do you know (does anyone know) how to activate this callback?
I do
callback.register("glyph_stream_provider",function () assert(false) end)
but this never gets called.
This is the shortest document that I was able to get to work: \directlua{ callback.register("glyph_stream_provider",function(font_id, char_index, mode) texio.write_nl("") print("glyph_stream_provider", font_id, char_index, mode) if mode == 1 or mode == 2 then return "" elseif mode == 3 then return 0, 0, 0, 0 else error() end end) local characters = {} for _, code in utf8.codes("Hello, world!") do characters[code] = { index = code, } end local otf = font.define { name = "texgyreheros-regular.otf", characters = characters, streamprovider = 1, format = "opentype", filename = "texgyreheros-regular.otf", } token.set_char("otf", otf) local ttf = font.define { name = "NotoSans-Regular.ttf", characters = characters, streamprovider = 3, format = "truetype", filename = "NotoSans-Regular.ttf", } token.set_char("ttf", ttf) } {\setfontid\otf Hello, world! \vfill\eject} {\setfontid\ttf Hello, world! \vfill\eject} \bye On Wed, 2025-04-09 at 12:37 +0200, Patrick Gundlach wrote:
Sadly, this is (as the name suggests) only the code for each glyph. I wish I could pass a complete font program to a callback and subset everything by myself (or rather: the harfbuzz subsetting library
You should be able to write out the subsetted font directly to the PDF, then make a virtual font with commands something like commands = { { "pdf", "direct", "/yourfontname 10 Tf (yourcharacter)" }, } although that is kinda ugly. But the LaTeX additions to luaotfload support variable fonts via HarfBuzz, so you should probably look at what they're doing there. Thanks, -- Max

Hello Max,
although that is kinda ugly. But the LaTeX additions to luaotfload support variable fonts via HarfBuzz, so you should probably look at what they're doing there.
I wish I could avoid the magic that is being done there: https://github.com/latex3/luaotfload/blob/main/src/luaotfload-harf-var-ttf.l... currently I use the high-level harfbuzz API for font loading and shaping, parsing the font just for variable fonts is not something I am keen to implement (especially since there is some alternative in form of the harfbuzz subsetting library). Patrick
participants (3)
-
David Carlisle
-
Max Chernoff
-
Patrick Gundlach