On 4/20/2018 5:52 AM, Henri Menke wrote:
Dear list,

I'm trying to determine the kerning between two letters (here A and V).  For the
sake of this example I'm inserting negative kerning of -400/1000 em.  However,
when I examine the kern in the kerning callback this massive enhancement of the
negative kern doesn't show up but I only see the kerning from the font itself.

How can I access the user-defined kerns?  MWE is below.

no real answer but there is nreal need to go nuts in your code

local function show_kerns(head)
    local glyph = node.id("glyph")
    for item in node.traverse(head) do
        if item.id == glyph then
            local char = item.char
            if char == 65 then
                local font = item.font
                print(font,char)
                local next     = item.next
                if next.id == glyph then
                  local nextchar = next.char
                  local nextfont = next.font
                  local data = fonts.hashes.identifiers[font]
local kern = fonts.handlers.otf.getkern(data,char,nextchar)
                  print(kern)
                end
            end
        end
    end
end

that said, what you could do is the loop over the to be packed list (so later) and then look for a left math node and then start looking at the characters and kerns


function foo(head)
    local glyph = node.id("glyph")
    local math  = node.id("math")
    local current = head
    while current do
        if current.id == math then
            current = current.next
            while current do
                if current.id == math then
                    break
                elseif current.id == glyph then
                    local char = current.char
                    if char == 0x1D434 then
                        local font = current.font
                        local next = current.next
                        if next.id == glyph then
                            local nextchar = next.char
                            if char == 0x1D449 then
                                local nextfont = next.font
                                local data = fonts.hashes.identifiers[font]
local kern = fonts.handlers.otf.getkern(data,char,nextchar)
                                print(char,nextchar,kern)
                            end
                        end
                        current = next
                    else
                        current = current.next
                    end
                else
                    current = current.next
                end
            end
        end
        current = current.next
    end
end

depending on the macro package that you need to look at math unicodes and even then you might not see a print because there is already a kern

keep in mind that this kind of hackery is macro package dependent so your plain test might work out different elsewhere (i haven't tested it as i operate in a different environment)


Cheers, Henri

---

\input luaotfload.sty

\directlua{
local function show_kerns(head)
    for item in node.traverse(head) do
       if item.id == node.id("glyph") and item.char == 65 then
          % Get current char and font
          local nut = node.direct.todirect(item)
          local char = node.direct.getchar(nut)
          local font = node.direct.getfont(nut)
          print(font)
          % Get next char and font
          local next = node.next(item)
          local nextnut = node.direct.todirect(next)
          local nextchar = node.direct.getchar(nextnut)
          local nextfont = node.direct.getfont(nextnut)
          % Determine the kern
          local data = fonts.hashes.identifiers[font]
          local kern = fonts.handlers.otf.getkern(data,char,nextchar)
          print(kern)
       end
    end
end
%
luatexbase.add_to_callback("kerning",
                            function(head)
                               show_kerns(head)
                               node.kerning(head)
                            end,
                            "show_kerns")
}

\directlua{
fonts.handlers.otf.addfeature{
    name = "ktest",
    type = "kern",
    data = { ["A"] = { ["V"] =  -400 } } % make them overlap for the example
}
}

\font\test="Latin Modern Roman:+ktest"\test
AV

\bye



--

-----------------------------------------------------------------
                                          Hans Hagen | PRAGMA ADE
              Ridderstraat 27 | 8061 GH Hasselt | The Netherlands
       tel: 038 477 53 69 | www.pragma-ade.nl | www.pragma-pod.nl
-----------------------------------------------------------------

Reply via email to