summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/context/base/mkiv/typo-itc.lua
diff options
context:
space:
mode:
Diffstat (limited to 'Master/texmf-dist/tex/context/base/mkiv/typo-itc.lua')
-rw-r--r--Master/texmf-dist/tex/context/base/mkiv/typo-itc.lua69
1 files changed, 42 insertions, 27 deletions
diff --git a/Master/texmf-dist/tex/context/base/mkiv/typo-itc.lua b/Master/texmf-dist/tex/context/base/mkiv/typo-itc.lua
index 2683eecc3e1..328bf14067e 100644
--- a/Master/texmf-dist/tex/context/base/mkiv/typo-itc.lua
+++ b/Master/texmf-dist/tex/context/base/mkiv/typo-itc.lua
@@ -29,9 +29,13 @@ local enableaction = nodes.tasks.enableaction
local nuts = nodes.nuts
local nodepool = nuts.pool
+local tonode = nuts.tonode
+local tonut = nuts.tonut
+
local getprev = nuts.getprev
local getnext = nuts.getnext
local getid = nuts.getid
+local getfont = nuts.getfont
local getchar = nuts.getchar
local getdisc = nuts.getdisc
local getattr = nuts.getattr
@@ -124,22 +128,14 @@ local function okay(data,current,font,prevchar,previtalic,char,what)
return false
end
if threshold then
- -- if getid(current) == glyph_code then
- while current and getid(current) ~= glyph_code do
- current = getprev(current)
- end
- if current then
- local ht = getheight(current)
- local ex = exheights[font]
- local th = threshold * ex
- if ht <= th then
- if trace_italics then
- report_italics("ignoring correction between %s italic %C and regular %C, height %p less than threshold %p",prevchar,what,char,ht,th)
- end
- return false
+ local ht = getheight(current)
+ local ex = exheights[font]
+ local th = threshold * ex
+ if ht <= th then
+ if trace_italics then
+ report_italics("ignoring correction between %s italic %C and regular %C, height %p less than threshold %p",prevchar,what,char,ht,th)
end
- else
- -- maybe backtrack to glyph
+ return false
end
end
if trace_italics then
@@ -181,7 +177,7 @@ local textokay = false
local enablemath = false
local enabletext = false
-local function domath(head,current)
+local function domath(head,current, done)
current = end_of_math(current)
local next = getnext(current)
if next then
@@ -204,7 +200,8 @@ local function domath(head,current)
a = a + 100
end
local i = getkern(kern)
- local c, f = isglyph(glyph)
+ local f = getfont(glyph)
+ local c = getchar(glyph)
if getheight(next) < 1.25*exheights[f] then
if i == 0 then
if trace_italics then
@@ -215,6 +212,7 @@ local function domath(head,current)
report_italics("%s italic between math %C and punctuation %C","removing",i,c,char)
end
setkern(kern,0) -- or maybe a small value or half the ic
+ done = true
end
elseif i == 0 then
local d = chardata[f][c]
@@ -228,6 +226,7 @@ local function domath(head,current)
if trace_italics then
report_italics("%s italic %p between math %C and punctuation %C","setting",i,c,char)
end
+ done = true
end
elseif trace_italics then
report_italics("%s italic %p between math %C and punctuation %C","keeping",k,c,char)
@@ -252,31 +251,34 @@ local function domath(head,current)
report_italics("%s italic %p between math %C and non punctuation %C","adding",a,getchar(glyph),char)
end
insert_node_after(head,glyph,correction_kern(a,glyph))
+ done = true
end
end
end
end
end
end
- return current
+ return current, done
end
local function mathhandler(head)
- local current = head
+ local nuthead = tonut(head)
+ local current = nuthead
+ local done = false
while current do
if getid(current) == math_code then
- current = domath(head,current)
+ current, done = domath(nuthead,current,done)
end
current = getnext(current)
end
- return head
+ return head, done
end
local function texthandler(head)
local prev = nil
local prevchar = nil
- local prevhead = head
+ local prevhead = tonut(head)
local previtalic = 0
local previnserted = nil
@@ -298,18 +300,20 @@ local function texthandler(head)
local replaceinserted = nil
local current = prevhead
+ local done = false
local lastfont = nil
local lastattr = nil
while current do
local char, id = isglyph(current)
if char then
- local font = id
+ local font = getfont(current)
local data = italicsdata[font]
if font ~= lastfont then
if previtalic ~= 0 then
if okay(data,current,font,prevchar,previtalic,char,"glyph") then
insert_node_after(prevhead,prev,correction_kern(previtalic,current))
+ done = true
end
elseif previnserted and data then
if trace_italics then
@@ -321,6 +325,7 @@ local function texthandler(head)
if replaceitalic ~= 0 then
if okay(data,replace,font,replacechar,replaceitalic,char,"replace") then
insert_node_after(replacehead,replace,correction_kern(replaceitalic,current))
+ done = true
end
replaceitalic = 0
elseif replaceinserted and data then
@@ -333,6 +338,7 @@ local function texthandler(head)
if postitalic ~= 0 then
if okay(data,post,font,postchar,postitalic,char,"post") then
insert_node_after(posthead,post,correction_kern(postitalic,current))
+ done = true
end
postitalic = 0
elseif postinserted and data then
@@ -389,7 +395,7 @@ local function texthandler(head)
while current do
local char, id = isglyph(current)
if char then
- local font = id
+ local font = getfont(current)
local data = italicsdata[font]
if data then
local attr = forcedvariant or getattr(current,a_italics)
@@ -425,7 +431,7 @@ local function texthandler(head)
while current do
local char, id = isglyph(current)
if char then
- local font = id
+ local font = getfont(current)
local data = italicsdata[font]
if data then
local attr = forcedvariant or getattr(current,a_italics)
@@ -473,6 +479,7 @@ local function texthandler(head)
end
previnserted = correction_glue(previtalic,current) -- maybe just add ? else problem with penalties
previtalic = 0
+ done = true
insert_node_after(prevhead,prev,previnserted)
else
if replaceitalic ~= 0 then
@@ -481,6 +488,7 @@ local function texthandler(head)
end
replaceinserted = correction_kern(replaceitalic,current) -- needs to be a kern
replaceitalic = 0
+ done = true
insert_node_after(replacehead,replace,replaceinserted)
end
if postitalic ~= 0 then
@@ -489,6 +497,7 @@ local function texthandler(head)
end
postinserted = correction_kern(postitalic,current) -- needs to be a kern
postitalic = 0
+ done = true
insert_node_after(posthead,post,postinserted)
end
end
@@ -501,7 +510,7 @@ local function texthandler(head)
postinserted = nil
postitalic = 0
if mathokay then
- current = domath(head,current)
+ current, done = domath(head,current,done)
else
current = end_of_math(current)
end
@@ -517,6 +526,7 @@ local function texthandler(head)
replaceitalic = 0
postinserted = nil
postitalic = 0
+ done = true
else
if replaceitalic ~= 0 then
if trace_italics then
@@ -529,6 +539,7 @@ local function texthandler(head)
replaceitalic = 0
postinserted = nil
postitalic = 0
+ done = true
end
if postitalic ~= 0 then
if trace_italics then
@@ -541,6 +552,7 @@ local function texthandler(head)
replaceitalic = 0
postinserted = nil
postitalic = 0
+ done = true
end
end
end
@@ -552,22 +564,25 @@ local function texthandler(head)
report_italics("inserting %p between %s italic %C and end of list",previtalic,"glyph",prevchar)
end
insert_node_after(prevhead,prev,correction_kern(previtalic,current))
+ done = true
else
if replaceitalic ~= 0 then
if trace_italics then
report_italics("inserting %p between %s italic %C and end of list",replaceitalic,"replace",replacechar)
end
insert_node_after(replacehead,replace,correction_kern(replaceitalic,current))
+ done = true
end
if postitalic ~= 0 then
if trace_italics then
report_italics("inserting %p between %s italic %C and end of list",postitalic,"post",postchar)
end
insert_node_after(posthead,post,correction_kern(postitalic,current))
+ done = true
end
end
end
- return head
+ return head, done
end
function italics.handler(head)