Dohyun Kim wrote:
Considering current state that we don't know any fonts that has ITLC table, it would be better than nothing to implement italic correction as follows. In the following code, "fontdata" is a table returned by the function "fonts.define.read".
local param = fontdata.parameters local italicangle = fontdata.shared.otfdata.metadata.italicangle if italicangle and italicangle < 0 then local uwidth = fontdata.shared.otfdata.metadata.uwidth or 40 local factor = fontdata.factor or 655.36 param.slant = - math.tan(italicangle*math.pi/180) * param.quad for i,v in pairs(fontdata.characters) do local gl = fontdata.descriptions[i] local it = (gl.boundingbox[3] - gl.width + uwidth*0.5) * factor if it > 0 then v.italic = it end end end
there are seleveral solutions: - extend the font with this info (faster but then it's always there which might not be ok as it's an approximation) - calculate it after loading (which is what you propose) in the mkiv code we do have a hook for that kind of things so this is then what i propose. watch how we don't scale here, we just add an entry to the shared data as that's where we hook in; the real implementation would look slightly different as an optimization is possible \starttext \startluacode table.insert(fonts.triggers,"itlc") local function itlc(tfmdata,value) if value then -- the magic 40 and it formula come from Dohyun Kim local fontdata = tfmdata.shared.otfdata or tfmdata.shared.afmdata local metadata = fontdata and fontdata.metadata if metadata then local italicangle = metadata.italicangle if italicangle and italicangle ~= 0 then local uwidth = (metadata.uwidth or 40)/2 for unicode, d in next, tfmdata.descriptions do local it = d.boundingbox[3] - d.width + uwidth if it ~= 0 then d.italic = it end end end end end end fonts.initializers.base.otf.itlc = itlc fonts.initializers.node.otf.itlc = itlc fonts.initializers.base.afm.itlc = itlc fonts.initializers.node.afm.itlc = itlc \stopluacode \definedfont[SerifItalic*default at 24pt] test\/test \definefontfeature[xdefault][default][itlc=yes] \definedfont[SerifItalic*xdefault at 24pt] test\/test \stoptext i could add it to the generic code (although i'm not going to add all the other context goodies to the generic code definitely not as long as they're experimental) ----------------------------------------------------------------- Hans Hagen | PRAGMA ADE Ridderstraat 27 | 8061 GH Hasselt | The Netherlands tel: 038 477 53 69 | fax: 038 477 53 74 | www.pragma-ade.com | www.pragma-pod.nl -----------------------------------------------------------------