[luatex] Kerning: when does it not work?

Heilmann, Till A. till.heilmann at unibas.ch
Wed May 4 09:15:46 CEST 2011


On 03/05/2011 04:58 PM, Paul Isambert wrote:

> [...] Anyway I've analysed what is produce by \url{http://}, and the
> result is (nodes are separated by space; for glyphs I give the character):
> 
> math_node h t t p glue_node : glue_node / / math_node
> 
> So the problem here stems from glues, not penalties, between characters. 
> [...] Meanwhile, Till, here's a solution that ignores glues with 0 width
> and stretch and shrink and insert kern pairs; again, I've tested it with
> plain TeX, hope it'll work in your document.

Paul, thank you again for your efforts. Unfortunately, your code does not work with my example (see below). This whole kerning thing seems to be quite tricky...

Best,
--Till

\begin{filecontents*}{mybonum.fea}
languagesystem DFLT dflt ;
languagesystem latn dflt ;
feature kern {
  pos colon slash 100 ;
  pos slash slash -150 ;
} kern ;
\end{filecontents*}
\documentclass{article}
\usepackage{url}
\urlstyle{same}
\usepackage{fontspec}
\setmainfont[FeatureFile=mybonum.fea]{TeX Gyre Bonum}
\directlua{
local GLYF = node.id("glyph")
local GLUE = node.id("glue")
local KERN = node.id("kern")
local function add_kerns (head)
   node.kerning(head)
   for glyph in node.traverse_id(GLYF, head) do
     local next = glyph.next
     while next and next.id == GLUE and next.spec.width == 0 and next.spec.stretch == 0 and next.spec.shrink == 0 do
       next = next.next
     end
     if next and next.id == GLYF then
       if glyph.font == next.font then
         local kerns = font.getfont(glyph.font).characters[glyph.char].kerns
         if kerns and kerns[next.char] then
           local kern = node.new(KERN, 1)
           kern.kern = kerns[next.char]
           node.insert_before(head, next, kern)
         end
       end
     end
   end
end
luatexbase.add_to_callback("kerning", add_kerns, "add_kerns")
}
\begin{document}
http:// \url{http://}
\end{document}



More information about the luatex mailing list