diff options
Diffstat (limited to 'Master/texmf-dist/tex/context/base/typo-itc.lua')
-rw-r--r-- | Master/texmf-dist/tex/context/base/typo-itc.lua | 89 |
1 files changed, 58 insertions, 31 deletions
diff --git a/Master/texmf-dist/tex/context/base/typo-itc.lua b/Master/texmf-dist/tex/context/base/typo-itc.lua index b39ea2f23cd..7373c0321fb 100644 --- a/Master/texmf-dist/tex/context/base/typo-itc.lua +++ b/Master/texmf-dist/tex/context/base/typo-itc.lua @@ -9,9 +9,10 @@ if not modules then modules = { } end modules ['typo-itc'] = { local utfchar = utf.char local trace_italics = false trackers.register("typesetters.italics", function(v) trace_italics = v end) - local report_italics = logs.reporter("nodes","italics") +local threshold = 0.5 trackers.register("typesetters.threshold", function(v) threshold = v == true and 0.5 or tonumber(v) end) + typesetters.italics = typesetters.italics or { } local italics = typesetters.italics @@ -24,20 +25,36 @@ local math_code = nodecodes.math local tasks = nodes.tasks -local insert_node_after = node.insert_after -local delete_node = nodes.delete -local end_of_math = node.end_of_math +local nuts = nodes.nuts +local nodepool = nuts.pool + +local tonode = nuts.tonode +local tonut = nuts.tonut + +local getfield = nuts.getfield +local getnext = nuts.getnext +local getid = nuts.getid +local getfont = nuts.getfont +local getchar = nuts.getchar +local getattr = nuts.getattr +local setattr = nuts.setattr + +local insert_node_after = nuts.insert_after +local delete_node = nuts.delete +local end_of_math = nuts.end_of_math -local texattribute = tex.attribute +local texgetattribute = tex.getattribute +local texsetattribute = tex.setattribute local a_italics = attributes.private("italics") local unsetvalue = attributes.unsetvalue -local new_correction_kern = nodes.pool.fontkern -local new_correction_glue = nodes.pool.glue +local new_correction_kern = nodepool.fontkern +local new_correction_glue = nodepool.glue local fonthashes = fonts.hashes local fontdata = fonthashes.identifiers local italicsdata = fonthashes.italics +local exheights = fonthashes.exheights local forcedvariant = false @@ -81,7 +98,8 @@ end -- todo: clear attribute -local function process(namespace,attribute,head) +function italics.handler(head) + head = tonut(head) local done = false local italic = 0 local lastfont = nil @@ -91,10 +109,10 @@ local function process(namespace,attribute,head) local current = head local inserted = nil while current do - local id = current.id + local id = getid(current) if id == glyph_code then - local font = current.font - local char = current.char + local font = getfont(current) + local char = getchar(current) local data = italicsdata[font] if font ~= lastfont then if italic ~= 0 then @@ -103,11 +121,25 @@ local function process(namespace,attribute,head) report_italics("ignoring %p between italic %C and italic %C",italic,prevchar,char) end else - if trace_italics then - report_italics("inserting %p between italic %C and regular %C",italic,prevchar,char) + local okay = true + if threshold then + local ht = getfield(current,"height") + local ex = exheights[font] + local th = threshold * ex + if ht <= th then + if trace_italics then + report_italics("ignoring correction between italic %C and regular %C, height %p less than threshold %p",prevchar,char,ht,th) + end + okay = false + end + end + if okay then + if trace_italics then + report_italics("inserting %p between italic %C and regular %C",italic,prevchar,char) + end + insert_node_after(head,previous,new_correction_kern(italic)) + done = true end - insert_node_after(head,previous,new_correction_kern(italic)) - done = true end elseif inserted and data then if trace_italics then @@ -120,7 +152,7 @@ local function process(namespace,attribute,head) lastfont = font end if data then - local attr = forcedvariant or current[attribute] + local attr = forcedvariant or getattr(current,a_italics) if attr and attr > 0 then local cd = data[char] if not cd then @@ -172,7 +204,7 @@ local function process(namespace,attribute,head) italic = 0 done = true end - current = current.next + current = getnext(current) end if italic ~= 0 and lastattr > 1 then -- more control is needed here if trace_italics then @@ -181,7 +213,7 @@ local function process(namespace,attribute,head) insert_node_after(head,previous,new_correction_kern(italic)) done = true end - return head, done + return tonode(head), done end local enable @@ -199,22 +231,16 @@ function italics.set(n) enable() end if n == variables.reset then - texattribute[a_italics] = unsetvalue + texsetattribute(a_italics,unsetvalue) else - texattribute[a_italics] = tonumber(n) or unsetvalue + texsetattribute(a_italics,tonumber(n) or unsetvalue) end end function italics.reset() - texattribute[a_italics] = unsetvalue + texsetattribute(a_italics,unsetvalue) end -italics.handler = nodes.installattributehandler { - name = "italics", - namespace = italics, - processor = process, -} - local variables = interfaces.variables local settings_to_hash = utilities.parsers.settings_to_hash @@ -229,12 +255,13 @@ function commands.setupitaliccorrection(option) -- no grouping ! elseif options[variables.always] then variant = 2 end + -- maybe also keywords for threshold if options[variables.global] then forcedvariant = variant - texattribute[a_italics] = unsetvalue + texsetattribute(a_italics,unsetvalue) else forcedvariant = false - texattribute[a_italics] = variant + texsetattribute(a_italics,variant) end if trace_italics then report_italics("forcing %a, variant %a",forcedvariant,variant ~= unsetvalue and variant) @@ -246,11 +273,11 @@ end local stack = { } function commands.pushitaliccorrection() - table.insert(stack,{forcedvariant, texattribute[a_italics] }) + table.insert(stack,{forcedvariant, texgetattribute(a_italics) }) end function commands.popitaliccorrection() local top = table.remove(stack) forcedvariant = top[1] - texattribute[a_italics] = top[2] + texsetattribute(a_italics,top[2]) end |