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

Taco Hoekwater taco at elvenkind.com
Sun Feb 6 10:25:06 CET 2011

On 02/05/2011 09:31 PM, Philipp Stephani wrote:
> The tounicode entries still don't work as expected; hopefully Taco can enlighten us.

tounicode (and the PDF /ToUnicode feature) works on the font glyphs
that are actually included in the pdf, that is why it does not work. In
the virtual font, it does notwork because there is no actual glyph, and
in the original is works 'too well' as both 'a' and 'b' use the same

As long as you are actually re-encoding, it is not too hard to alter
the font, but getting two input characters that map to the same glyph
to have two different tounicode values is impossible.

Virtual fonts do not really help that much for the posted problem
because of the need to adjust tounicode as well. 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:

   -- copy the table from 'b'
   for a,v in pairs(fontdata.characters[0x0062]) do
     fontdata.characters[0x0061][a] = v

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

After the assignment(s), you can add

   fontdata.characters[0x0061].tounicode = "0061"

to set the correct tounicode value.

Best wishes,

More information about the lualatex-dev mailing list