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

Reinhard Kotucha reinhard.kotucha at web.de
Mon Feb 21 22:31:55 CET 2011


On 2011-02-21 at 17:04:39 +0100, Ulrike Fischer wrote:

 > Am Sun, 20 Feb 2011 18:48:52 +0200 schrieb Khaled Hosny:
 > 
 > 
 > > Another way to patch the fonts is to do something like:
 > > 
 > > \input luaotfload.sty
 > > \directlua{
 > >  local function chess(tfmdata,value)
 > >      if value then
 > >      % whatever
 > >      end
 > >  end
 > >  table.insert(fonts.triggers,"chess")
 > >  fonts.initializers.base.otf.chess = chess
 > >  fonts.initializers.node.otf.chess = chess
 > > }
 > > \font\test=name:foo:chess=yes at 15pt
 > > \test foo
 > > \bye
 > > 
 > > This way you can control which fonts to be processed, and "chess" option
 > > can take any value so your code might even do different patching
 > > conditionally (this should work for ConTeXt as well).
 > 
 > This seems to work great. I even can declare the font in the normal
 > latex way:
 > 
 > \documentclass{article}
 > \usepackage[LSF,T1]{fontenc}
 > \DeclareFontFamily{LSF}{skaknewOTF}{}
 >  \DeclareFontShape{LSF}{skaknewOTF}{m}{n}{<->
 > file:SkakNew-Figurine.otf:chess=yes}{}
 > 
 > \usepackage{luaotfload}
 > \directlua{
 >  local function chess(tfmdata,value)
 >      if value then
 >       tfmdata.indices[75]=14
 >       table.tofile("filechess.lua", tfmdata, true)
 >     end
 >  end
 >  table.insert(fonts.triggers,"chess")
 >  fonts.initializers.base.otf.chess = chess
 >  fonts.initializers.node.otf.chess = chess
 > }
 > 
 > \begin{document}
 > \fontfamily{skaknewOTF}\fontencoding{LSF}\selectfont KQ
 > \end{document}
 > 
 > 
 >  
 > > BTW, you can save "tfmdata" to a file using:
 > >   table.tofile("file.lua", tfmdata, true)
 > > 
 > > If you want to inspect its structure.
 > 
 > Well here starts the problems. I can see the structure, but how can
 > I understand it? Which tables and table entries do I have to copy to
 > get a clean reencoding? Above I set the "indices" to copy the queen
 > to the "K" (which normally shows a king in this font). But I doubt
 > that the bounding box and other things are correct. 

Hi Ulrike,
I must admit that it's all quite new to me too, but your example file
is a good starting point.  Thanks!

>From the output of your example file it's hard to determine whether
the metrics are correct because the queen and the king have almost the
same width.  Fortunately, there is an uparrow in the font, assigned
to the letter 'C'.

I modified your file a bit.  After replacing the king by a queen, I
replaced the queen by an uparrow.  It seems that it's necessary to
replace tfmdata.descriptions too.  Comment out the tfmdata.descriptions 
lines and see what happens.

I don't know whether tfmdata.shared.otfdata.glyphs has to be adapted
too.

Regards,
  Reinhard


\documentclass{article}
\usepackage[LSF,T1]{fontenc}
\DeclareFontFamily{LSF}{skaknewOTF}{}
 \DeclareFontShape{LSF}{skaknewOTF}{m}{n}{<->
file:SkakNew-Figurine.otf:chess=yes}{}

\usepackage{luaotfload}
\directlua{
 local function chess(tfmdata,value)
    if value then

      % replace king by queen
      tfmdata.indices[75]=14
      tfmdata.descriptions[75]=tfmdata.descriptions[81]

      % replace queen by uparrow
      tfmdata.indices[81]=45
      tfmdata.descriptions[81]=tfmdata.descriptions[67]

      table.tofile("filechess.lua", tfmdata, true)
    end
 end
 table.insert(fonts.triggers,"chess")
 fonts.initializers.base.otf.chess = chess
 fonts.initializers.node.otf.chess = chess
}

\begin{document}
\fontfamily{skaknewOTF}\fontencoding{LSF}\selectfont KQQQKQQQK
\end{document}


-- 
----------------------------------------------------------------------------
Reinhard Kotucha                                      Phone: +49-511-3373112
Marschnerstr. 25
D-30167 Hannover                              mailto:reinhard.kotucha at web.de
----------------------------------------------------------------------------
Microsoft isn't the answer. Microsoft is the question, and the answer is NO.
----------------------------------------------------------------------------


More information about the lualatex-dev mailing list