summaryrefslogtreecommitdiff
path: root/tex/context/base/mkiv/font-osd.lua
diff options
context:
space:
mode:
Diffstat (limited to 'tex/context/base/mkiv/font-osd.lua')
-rw-r--r--tex/context/base/mkiv/font-osd.lua199
1 files changed, 100 insertions, 99 deletions
diff --git a/tex/context/base/mkiv/font-osd.lua b/tex/context/base/mkiv/font-osd.lua
index 6ff2e38b6..ca20f6782 100644
--- a/tex/context/base/mkiv/font-osd.lua
+++ b/tex/context/base/mkiv/font-osd.lua
@@ -79,13 +79,10 @@ fonts.analyzers.methods = fonts.analyzers.methods or { node = { otf = { } } }
local otf = fonts.handlers.otf
-local nodecodes = nodes.nodecodes
-local glyph_code = nodecodes.glyph
-
local handlers = otf.handlers
local methods = fonts.analyzers.methods
-local otffeatures = fonts.constructors.newfeatures("otf")
+local otffeatures = fonts.constructors.features.otf
local registerotffeature = otffeatures.register
local nuts = nodes.nuts
@@ -110,9 +107,9 @@ local ischar = nuts.is_char
local insert_node_after = nuts.insert_after
local copy_node = nuts.copy
-local free_node = nuts.free
local remove_node = nuts.remove
local flush_list = nuts.flush_list
+local flush_node = nuts.flush_node
local copyinjection = nodes.injections.copy -- KE: is this necessary? HH: probably not as positioning comes later and we rawget/set
@@ -616,13 +613,12 @@ local function initializedevanagi(tfmdata)
local steps = sequence.steps
local nofsteps = sequence.nofsteps
local features = sequence.features
- if features["rphf"] then
- -- deva
+ local has_rphf = features.rphf
+ local has_blwf = features.blwf
+ if has_rphf and has_rphf.deva then
devanagari.reph = true
- elseif features["blwf"] then
- -- deva
+ elseif has_blwf and has_blwf.deva then
devanagari.vattu = true
- -- dev2
for i=1,nofsteps do
local step = steps[i]
local coverage = step.coverage
@@ -635,59 +631,71 @@ local function initializedevanagi(tfmdata)
end
end
end
- if valid[kind] then
- for i=1,nofsteps do
- local step = steps[i]
- local coverage = step.coverage
- if coverage then
- local reph = false
- if step.osdstep then
- -- rphf acts on consonant + halant
- for k, v in next, ra do
- local r = coverage[k]
- if r then
- local h = false
- for k, v in next, halant do
- local h = r[k]
- if h then
- reph = h.ligature or false
- break
+ for kind, spec in next, features do -- beware, this is
+ if spec.dev2 and valid[kind] then
+ for i=1,nofsteps do
+ local step = steps[i]
+ local coverage = step.coverage
+ if coverage then
+ local reph = false
+ if kind == "rphf" then
+ --
+ -- KE: I don't understand the rationale behind osdstep. The original if
+ -- statement checked whether coverage is contextual chaining.
+ --
+ -- HH: The osdstep signals that we deal with our own feature here, not
+ -- one in the font itself so it was just a safeguard against us overloading
+ -- something driven by the font.
+ --
+ -- if step.osdstep then -- selective
+ if true then -- always
+ -- rphf acts on consonant + halant
+ for k, v in next, ra do
+ local r = coverage[k]
+ if r then
+ local h = false
+ for k, v in next, halant do
+ local h = r[k]
+ if h then
+ reph = h.ligature or false
+ break
+ end
+ end
+ if reph then
+ break
+ end
end
end
- if reph then
- break
- end
+ else
+ -- rphf might be result of other handler/chainproc
end
end
- else
- -- rphf might be result of other handler/chainproc
+ seqsubset[#seqsubset+1] = { kind, coverage, reph }
end
- seqsubset[#seqsubset+1] = { kind, coverage, reph }
end
end
- end
- if kind == "pref" then
- local sequence = dataset[3] -- was [5]
- local steps = sequence.steps
- local nofsteps = sequence.nofsteps
- for i=1,nofsteps do
- local step = steps[i]
- local coverage = step.coverage
- if coverage then
- for k, v in next, halant do
- local h = coverage[k]
- if h then
- local found = false
- for k, v in next, h do
- found = v and v.ligature
+ if kind == "pref" then
+ local steps = sequence.steps
+ local nofsteps = sequence.nofsteps
+ for i=1,nofsteps do
+ local step = steps[i]
+ local coverage = step.coverage
+ if coverage then
+ for k, v in next, halant do
+ local h = coverage[k]
+ if h then
+ local found = false
+ for k, v in next, h do
+ found = v and v.ligature
+ if found then
+ pre_base_reordering_consonants[k] = found
+ break
+ end
+ end
if found then
- pre_base_reordering_consonants[k] = found
break
end
end
- if found then
- break
- end
end
end
end
@@ -795,7 +803,7 @@ local function deva_reorder(head,start,stop,font,attr,nbspaces)
if current == stop then
stop = getprev(stop)
head = remove_node(head,current)
- free_node(current)
+ flush_node(current)
return head, stop, nbspaces
else
nbspaces = nbspaces + 1
@@ -833,7 +841,7 @@ local function deva_reorder(head,start,stop,font,attr,nbspaces)
setchar(current,getchar(tempcurrent)) -- we assumes that the result of blwf consists of one node
local freenode = getnext(current)
setlink(current,tmp)
- free_node(freenode)
+ flush_node(freenode)
flush_list(tempcurrent)
if changestop then
stop = current
@@ -1096,7 +1104,7 @@ local function deva_reorder(head,start,stop,font,attr,nbspaces)
if getchar(base) == c_nbsp then
nbspaces = nbspaces - 1
head = remove_node(head,base)
- free_node(base)
+ flush_node(base)
end
return head, stop, nbspaces
@@ -1132,9 +1140,12 @@ function handlers.devanagari_reorder_matras(head,start) -- no leak
head = remove_node(head,start)
setlink(start,next)
setlink(current,start)
+ -- setlink(current,start,next) -- maybe
start = startnext
break
end
+ else
+ break
end
current = next
end
@@ -1174,12 +1185,12 @@ function handlers.devanagari_reorder_reph(head,start)
local startfont = getfont(start)
local startattr = getprop(start,a_syllabe)
while current do
- local char = ischar(current,font)
+ local char = ischar(current,startfont)
if char and getprop(current,a_syllabe) == startattr then -- step 2
if halant[char] and not getprop(current,a_state) then
local next = getnext(current)
if next then
- local nextchar = ischar(next,font)
+ local nextchar = ischar(next,startfont)
if nextchar and zw_char[nextchar] and getprop(next,a_syllabe) == startattr then
current = next
next = getnext(current)
@@ -1189,6 +1200,7 @@ function handlers.devanagari_reorder_reph(head,start)
head = remove_node(head,start)
setlink(start,next)
setlink(current,start)
+ -- setlink(current,start,next) -- maybe
start = startnext
startattr = getprop(start,a_syllabe)
break
@@ -1201,14 +1213,14 @@ function handlers.devanagari_reorder_reph(head,start)
if not startnext then
current = getnext(start)
while current do
- local char = ischar(current,font)
+ local char = ischar(current,startfont)
if char and getprop(current,a_syllabe) == startattr then -- step 4
if getprop(current,a_state) == s_pstf then -- post-base
startnext = getnext(start)
head = remove_node(head,start)
- local prev = getprev(current)
- setlink(prev,start)
+ setlink(getprev(current),start)
setlink(start,current)
+ -- setlink(getprev(current),start,current) -- maybe
start = startnext
startattr = getprop(start,a_syllabe)
break
@@ -1226,7 +1238,7 @@ function handlers.devanagari_reorder_reph(head,start)
current = getnext(start)
local c = nil
while current do
- local char = ischar(current,font)
+ local char = ischar(current,startfont)
if char and getprop(current,a_syllabe) == startattr then -- step 5
if not c and mark_above_below_post[char] and reorder_class[char] ~= "after subscript" then
c = current
@@ -1240,9 +1252,9 @@ function handlers.devanagari_reorder_reph(head,start)
if c then
startnext = getnext(start)
head = remove_node(head,start)
- local prev = getprev(c)
- setlink(prev,start)
+ setlink(getprev(c),start)
setlink(start,c)
+ -- setlink(getprev(c),start,c) -- maybe
-- end
start = startnext
startattr = getprop(start,a_syllabe)
@@ -1253,7 +1265,7 @@ function handlers.devanagari_reorder_reph(head,start)
current = start
local next = getnext(current)
while next do
- local nextchar = ischar(next,font)
+ local nextchar = ischar(next,startfont)
if nextchar and getprop(next,a_syllabe) == startattr then --step 6
current = next
next = getnext(current)
@@ -1264,9 +1276,9 @@ function handlers.devanagari_reorder_reph(head,start)
if start ~= current then
startnext = getnext(start)
head = remove_node(head,start)
- local next = getnext(current)
- setlink(start,next)
- setlink(current,"next",start)
+ setlink(start,getnext(current))
+ setlink(current,start)
+ -- setlink(current,start,getnext(current)) -- maybe
start = startnext
end
end
@@ -1293,12 +1305,12 @@ function handlers.devanagari_reorder_pre_base_reordering_consonants(head,start)
local startattr = getprop(start,a_syllabe)
-- can be fast for loop + caching state
while current do
- local char = ischar(current,font)
+ local char = ischar(current,startfont)
if char and getprop(current,a_syllabe) == startattr then
local next = getnext(current)
if halant[char] and not getprop(current,a_state) then
if next then
- local nextchar = ischar(next,font)
+ local nextchar = ischar(next,startfont)
if nextchar and getprop(next,a_syllabe) == startattr then
if nextchar == c_zwnj or nextchar == c_zwj then
current = next
@@ -1310,6 +1322,7 @@ function handlers.devanagari_reorder_pre_base_reordering_consonants(head,start)
removenode(start,start)
setlink(start,next)
setlink(current,start)
+ -- setlink(current,start,next) -- maybe
start = startnext
break
end
@@ -1322,14 +1335,14 @@ function handlers.devanagari_reorder_pre_base_reordering_consonants(head,start)
current = getnext(start)
startattr = getprop(start,a_syllabe)
while current do
- local char = ischar(current,font)
+ local char = ischar(current,startfont)
if char and getprop(current,a_syllabe) == startattr then
if not consonant[char] and getprop(current,a_state) then -- main
startnext = getnext(start)
removenode(start,start)
- local prev = getprev(current)
- setlink(start,prev)
+ setlink(getprev(current),start)
setlink(start,current)
+ -- setlink(getprev(current),start,current) -- maybe
start = startnext
break
end
@@ -1429,21 +1442,7 @@ local function dev2_reorder(head,start,stop,font,attr,nbspaces) -- maybe do a pa
local kind = subset[1]
local lookupcache = subset[2]
if kind == "rphf" then
- for k, v in next, ra do
- local r = lookupcache[k]
- if r then
- for k, v in next, halant do
- local h = r[k]
- if h then
- reph = h.ligature or false
- break
- end
- end
- if reph then
- break
- end
- end
- end
+ reph = subset[3]
local current = start
local last = getnext(stop)
while current ~= last do
@@ -1476,7 +1475,7 @@ local function dev2_reorder(head,start,stop,font,attr,nbspaces) -- maybe do a pa
if current ~= stop then
local c = locl[current] or getchar(current)
local found = lookupcache[c]
- if found then
+ if found then -- pre-base: pref Halant + Consonant
local next = getnext(current)
local n = locl[next] or getchar(next)
if found[n] then
@@ -1574,7 +1573,7 @@ local function dev2_reorder(head,start,stop,font,attr,nbspaces) -- maybe do a pa
if current == stop then
stop = getprev(stop)
head = remove_node(head,current)
- free_node(current)
+ flush_node(current)
return head, stop, nbspaces
else
nbspaces = nbspaces + 1
@@ -1694,9 +1693,9 @@ local function dev2_reorder(head,start,stop,font,attr,nbspaces) -- maybe do a pa
end
start = current
end
- local prev = getprev(halfpos)
- setlink(prev,current)
+ setlink(getprev(halfpos),current)
setlink(current,halfpos)
+ -- setlink(getprev(halfpos),current,halfpos) -- maybe
halfpos = current
elseif above_mark[char] then -- After main consonant
target = basepos
@@ -1721,13 +1720,13 @@ local function dev2_reorder(head,start,stop,font,attr,nbspaces) -- maybe do a pa
local prev = getprev(current)
if prev ~= target then
local next = getnext(current)
- setlink(next,prev)
+ setlink(prev,next)
if current == stop then
stop = prev
end
- local next = getnext(target)
- setlink(current,next)
+ setlink(current,getnext(target))
setlink(target,current)
+ -- setlink(target,current,getnext(target)) -- maybe
end
end
end
@@ -1754,8 +1753,7 @@ local function dev2_reorder(head,start,stop,font,attr,nbspaces) -- maybe do a pa
if stop == next then
stop = current
end
- local prev = getprev(c)
- setlink(next,prev)
+ setlink(getprev(c),next)
local nextnext = getnext(next)
setnext(current,nextnext)
local nextnextnext = getnext(nextnext)
@@ -1769,9 +1767,12 @@ local function dev2_reorder(head,start,stop,font,attr,nbspaces) -- maybe do a pa
end
if getchar(base) == c_nbsp then
+ if base == stop then
+ stop = getprev(stop)
+ end
nbspaces = nbspaces - 1
head = remove_node(head, base)
- free_node(base)
+ flush_node(base)
end
return head, stop, nbspaces
@@ -1818,7 +1819,7 @@ local function analyze_next_chars_one(c,font,variant) -- skip one dependent vowe
elseif (vv == c_zwnj or vv == c_zwj) and halant[vvv] then
local nnnn = getnext(nnn)
if nnnn then
- local vvvv = ischar(nnnn)
+ local vvvv = ischar(nnnn,font)
if vvvv and consonant[vvvv] then
c = nnnn
end
@@ -1841,7 +1842,7 @@ local function analyze_next_chars_one(c,font,variant) -- skip one dependent vowe
local nn = getnext(n)
if nn then
local vv = ischar(nn,font)
- if vv and zw_char[vv] then
+ if vv and zw_char[v] then
n = nn
v = vv
nn = getnext(nn)