latex3 / luaotfload

OpenType font loader for LuaTeX
Other
56 stars 6 forks source link

Patching callbacks and `harf` fonts #114

Open zauguin opened 4 years ago

zauguin commented 4 years ago

We have two callbacks for patching fonts: luaotfload.patch_font and luaotfload.patch_font and .patch_font_unsafe. Currently .patch_font handles all node fonts and .patch_font_unsafe everything else. This leads to the question how harf fonts should be patched: The original idea was that _unsafe was for TFM fonts because patching them easily breaks the code and lots of fields are ignored there anyway. So it could be argued that .patch_font should get harf fonts too but that would probably break most existing callbacks.

Maybe we need a new callback .patch_font_harf? If we do this we might want to reconsider the naming of the existing ones (e.g. .patch_font -> .patch_font_node and .patch_font_unsafe to .patch_font_tfm)? Of course, we would probably have to keep the old names too for compatibility.

u-fischer commented 4 years ago

are the patch_font callbacks something that we want to "officially" support as interface? I know that it is used (I have done it myself) but I always wondered if it is "hackish" or not and what would happen if it is used more widely.

If yes, what sort of patches are actually possible in harf mode? And would it make sense to move the callback(s) to the luaotfload.aux- or fonts.handlers-namespace?

zauguin commented 4 years ago

are the patch_font callbacks something that we want to "officially" support as interface? I know that it is used (I have done it myself) but I always wondered if it is "hackish" or not and what would happen if it is used more widely.

I agree that it is hackish but it is documented, so it is more or less official.

If yes, what sort of patches are actually possible in harf mode?

Pretty much all the things currently done in the patch_font callbacks in luaotfload-auxiliary.lua could also be done in harf mode (so e.g. adjusting font names, font dimensions etc.) Also it could be used to add TeX-level ligatures and modify the features which HarfBuzz will use.

Pretty much all use-cases for this would be better handled as virtual font features, but that is even more true for node fonts.

And would it make sense to move the callback(s) to the luaotfload.aux- or fonts.handlers-namespace?

I don't think we should move anything into fonts.* because that is the fontloader namespace and these callbacks are pretty luaotfload specific. I don't have any opinion if it should be .aux or not, if we rename them anyway we can move them wherever you think the should belong.