[lltx] Patching fonts with the luaotfload callback "luaotfload.patch_font"

Ulrike Fischer news3 at nililand.de
Sat Feb 5 15:28:14 CET 2011


I'm really happy that the newest version of luaotfload offers a
callback "luaotfload.patch_font" which can be use to change fonts. I
think that is really useful. As a first step I would like to use it
to reencode some chess fonts so that they can be used with latex.

Below is a small example of my first tests. It tries to replace the
"a" by a "b". For all fonts in the example I get the expected "look"
in the pdf ("bbc").

I have two questions:

1. I added some messages to the function (for diagnosing), but they
don't appear for all fonts in the log/terminal. I see messages from
the fontspec-fonts "The font is \EU2/lmr/m/it/10" but not from
"\font\mytest" and "\font\mytestb". The curious thing is that I get
a "The font is \mytest"-message if I uncomment the last fontspec, I
can't find a rule, why some messages appear and other not. Has
someone an idea?

2. For the first test I simply set 
fontdata.characters[0x0061]=fontdata.characters[0x0062]. 

But I'm really unsure which table(s) should be copied how. I think I
copied to much: When I copy&paste the output in the pdf I get "aac
aac aac". This means my code also affected the input "b" - something
I don't want.

What I want is
- only the input "a" should be affected.
- its output in the pdf should be "b" (with correct width and heigth
etc
- it should copy&paste as "a" or - better - as a completly different
character e.g. "d".

 

\documentclass{article}
\usepackage{fontspec}
\usepackage{luacode}
%
\begin{luacode*}
local function patch_font(fontdata)
  texio.write_nl("The font is", tex.fontidentifier(font.current()))
  texio.write_nl("")
  fontdata.characters[0x0061]=fontdata.characters[0x0062]
end
 luatexbase.add_to_callback("luaotfload.patch_font", patch_font,
"patch_font")
\end{luacode*}


\font\mytest="Georgia" \mytest

\begin{document}
\itshape abc \font\mytestb="Arial" \mytestb
abc \mytest abc
\newpage
abc

%\fontspec{"Arial"} abc
\end{document}


-- 
Ulrike Fischer 



More information about the lualatex-dev mailing list