diff options
Diffstat (limited to 'Master/texmf-dist/tex/context/base/typo-krn.lua')
-rw-r--r-- | Master/texmf-dist/tex/context/base/typo-krn.lua | 67 |
1 files changed, 52 insertions, 15 deletions
diff --git a/Master/texmf-dist/tex/context/base/typo-krn.lua b/Master/texmf-dist/tex/context/base/typo-krn.lua index 54b1fd2d3cf..fb28d3b2de4 100644 --- a/Master/texmf-dist/tex/context/base/typo-krn.lua +++ b/Master/texmf-dist/tex/context/base/typo-krn.lua @@ -6,15 +6,11 @@ if not modules then modules = { } end modules ['typo-krn'] = { license = "see context related readme files" } -local utf = unicode.utf8 - -local next, type = next, type +local next, type, tonumber = next, type, tonumber local utfchar = utf.char local nodes, node, fonts = nodes, node, fonts -local has_attribute = node.has_attribute -local unset_attribute = node.unset_attribute local find_node_tail = node.tail or node.slide local free_node = node.free local free_nodelist = node.flush_list @@ -22,6 +18,7 @@ local copy_node = node.copy local copy_nodelist = node.copy_list local insert_node_before = node.insert_before local insert_node_after = node.insert_after +local end_of_math = node.end_of_math local texattribute = tex.attribute local unsetvalue = attributes.unsetvalue @@ -31,6 +28,7 @@ local tasks = nodes.tasks local new_gluespec = nodepool.gluespec local new_kern = nodepool.kern +local new_glue = nodepool.glue local nodecodes = nodes.nodecodes local kerncodes = nodes.kerncodes @@ -42,6 +40,7 @@ local disc_code = nodecodes.disc local glue_code = nodecodes.glue local hlist_code = nodecodes.hlist local vlist_code = nodecodes.vlist +local math_code = nodecodes.math local kerning_code = kerncodes.kerning local userkern_code = kerncodes.userkern @@ -55,6 +54,8 @@ local chardata = fonthashes.characters local quaddata = fonthashes.quads local markdata = fonthashes.marks +local v_max = interfaces.variables.max + typesetters = typesetters or { } local typesetters = typesetters @@ -86,16 +87,47 @@ kerns.keeptogether = false -- just for fun (todo: control setting with key/value -- can be optimized .. the prev thing .. but hardly worth the effort +local function kern_injector(fillup,kern) + if fillup then + local g = new_glue(kern) + local s = g.spec + s.stretch = kern + s.stretch_order = 1 + return g + else + return new_kern(kern) + end +end + +local function spec_injector(fillup,width,stretch,shrink) + if fillup then + local s = new_gluespec(width,2*stretch,2*shrink) + s.stretch_order = 1 + return s + else + return new_gluespec(width,stretch,shrink) + end +end + +-- needs checking ... base mode / node mode + local function do_process(namespace,attribute,head,force) -- todo: glue so that we can fully stretch local start, done, lastfont = head, false, nil local keepligature = kerns.keepligature local keeptogether = kerns.keeptogether + local fillup = false while start do -- faster to test for attr first - local attr = force or has_attribute(start,attribute) + local attr = force or start[attribute] if attr and attr > 0 then - unset_attribute(start,attribute) + start[attribute] = unsetvalue local krn = mapping[attr] + if krn == v_max then + krn = .25 + fillup = true + else + fillup = false + end if krn and krn ~= 0 then local id = start.id if id == glyph_code then @@ -136,7 +168,7 @@ local function do_process(namespace,attribute,head,force) -- todo: glue so that if not pid then -- nothing elseif pid == kern_code then - if prev.subtype == kerning_code or has_attribute(prev,a_fontkern) then + if prev.subtype == kerning_code or prev[a_fontkern] then if keeptogether and prev.prev.id == glyph_code and keeptogether(prev.prev,start) then -- we could also pass start -- keep 'm else @@ -155,12 +187,12 @@ local function do_process(namespace,attribute,head,force) -- todo: glue so that local kerns = chardata[lastfont][prevchar].kerns local kern = kerns and kerns[lastchar] or 0 krn = kern + quaddata[lastfont]*krn -- here - insert_node_before(head,start,new_kern(krn)) + insert_node_before(head,start,kern_injector(fillup,krn)) done = true end else krn = quaddata[lastfont]*krn -- here - insert_node_before(head,start,new_kern(krn)) + insert_node_before(head,start,kern_injector(fillup,krn)) done = true end elseif pid == disc_code then @@ -218,7 +250,7 @@ local function do_process(namespace,attribute,head,force) -- todo: glue so that else krn = quaddata[lastfont]*krn -- here end - disc.replace = new_kern(krn) + disc.replace = kern_injector(false,krn) -- only kerns permitted, no glue end end end @@ -229,7 +261,7 @@ local function do_process(namespace,attribute,head,force) -- todo: glue so that local w = s.width if w > 0 then local width, stretch, shrink = w+gluefactor*w*krn, s.stretch, s.shrink - start.spec = new_gluespec(width,stretch*width/w,shrink*width/w) + start.spec = spec_injector(fillup,width,stretch*width/w,shrink*width/w) done = true end end @@ -244,14 +276,16 @@ local function do_process(namespace,attribute,head,force) -- todo: glue so that elseif lastfont and (id == hlist_code or id == vlist_code) then -- todo: lookahead local p = start.prev if p and p.id ~= glue_code then - insert_node_before(head,start,new_kern(quaddata[lastfont]*krn)) + insert_node_before(head,start,kern_injector(fillup,quaddata[lastfont]*krn)) done = true end local n = start.next if n and n.id ~= glue_code then - insert_node_after(head,start,new_kern(quaddata[lastfont]*krn)) + insert_node_after(head,start,kern_injector(fillup,quaddata[lastfont]*krn)) done = true end + elseif id == math_code then + start = end_of_math(start) end end end @@ -265,7 +299,10 @@ end local enabled = false function kerns.set(factor) - if factor ~= 0 then + if factor ~= v_max then + factor = tonumber(factor) or 0 + end + if factor == v_max or factor ~= 0 then if not enabled then tasks.enableaction("processors","typesetters.kerns.handler") enabled = true |