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

Ulrike Fischer luatex at nililand.de
Fri Mar 11 13:53:16 CET 2011


Am Sun, 06 Feb 2011 10:25:06 +0100 schrieb Taco Hoekwater:

[About virtual fonts and tounicode entries]

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

I have now a working virtual font which reencodes a chess font. But
I'm still struck how to manipulate the tounicode values. I have now
put various combinations of XXX.characters[YY].tounicode=ZZ  in
various places and nothing works. Can you tell me what I should do? 

The code of the virtual font is below, (it uses Arial instead of the
chess font to allow easier testing). It should go in a file e.g.
testfont.lua and then can be used in a current context with 

 \font\mine=file:testfont.lua at 12pt

 \starttext
 \mine KQRBNp
 \stoptext
 \bye

I would like to get as result of a copy and paste in the pdf
"KQRBNp" oder better "KQRBNP" or even better "KDTLBb"


********** virtual font testfont.lua

 return function(specification)
    local f1, id1 = fonts.tfm.readanddefine('Arial',
specification.size)
    local reencoding = {
         --bishop
         [66] = 8226,
         --king
         [75] = 162,
         -- Knight
         [78] = 167,
         -- Queen
         [81] = 163,
         -- Rook
         [82] = 182,
         -- Pawn
         [112]= 223,
     }

    if f1 then
        f1.name = specification.name
        f1.virtualized = true
        f1.tounicode=1 --needed?
        f1.fonts = {
            { id = id1 },
        }
       local chars = fonts.identifiers[id1].characters
       -- reencode
       -- u=target, v=source
       for u, v in next, reencoding do
           local c = chars[v]
            chars[u].commands = {{ 'char', v }}
            chars[u].kerns    = nil
            chars[u].width    = c.width
            chars[u].height   = c.height
            chars[u].depth    = c.depth
            chars[u].italic   = nil
       end
       -- remove the other chars
       for u,v in next,chars do
        if not reencoding[u] then
         chars[u]=nil
        end
       end
    end
    return f1
end


-- 
Ulrike Fischer 



More information about the luatex mailing list