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

Ulrike Fischer news3 at nililand.de
Tue Feb 22 10:28:26 CET 2011


Am Mon, 21 Feb 2011 22:31:55 +0100 schrieb Reinhard Kotucha:

>  > 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. 

I was quite certain that are not correct ;-)


> 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.

Me neither. Also my first example swaps two glyph. One also need to
find out what must be done if one tries to move a glyph to an empty
position. (E.g. to move the queen to the "z", one has to declare
tfmdata.characters[122]={}).

So they are a lot of open questions. The main problem is that it
quite unclear if this questions are answered by understanding the
luatex manual or the context font loading code. (fonts.triggers is
at my knowledge from the context code). 

I will make a context example and ask on the context list.
     
>       tfmdata.descriptions[81]=tfmdata.descriptions[67]

I think that is not the correct way to swap the data. See the
comment of Taco in the same thread:

> The code in the first
> post was good enough, except for a lua misunderstanding:
> 
>    fontdata.characters[0x0061] = fontdata.characters[0x0062]
> 
> is a variable assignment, not a table copy. To create an actual
> copy of fontdata.characters[0x0062], you would need to do something
> like this:
> 
>    fontdata.characters[0x0061]={}
>    -- copy the table from 'b'
>    for a,v in pairs(fontdata.characters[0x0062]) do
>      fontdata.characters[0x0061][a] = v
>    end
> 
> (if you are re-encoding an entire font, it is more efficient to
> use a remap table to actually swap the table entries instead of
> copying all keys.)


(I don't know what he meant by "use a remap table").

-- 
Ulrike Fischer 



More information about the lualatex-dev mailing list