summaryrefslogtreecommitdiff
path: root/tex/context/base/mkxl/font-ots.lmt
diff options
context:
space:
mode:
Diffstat (limited to 'tex/context/base/mkxl/font-ots.lmt')
-rw-r--r--tex/context/base/mkxl/font-ots.lmt240
1 files changed, 94 insertions, 146 deletions
diff --git a/tex/context/base/mkxl/font-ots.lmt b/tex/context/base/mkxl/font-ots.lmt
index bd70d6d47..478dc700d 100644
--- a/tex/context/base/mkxl/font-ots.lmt
+++ b/tex/context/base/mkxl/font-ots.lmt
@@ -205,7 +205,8 @@ local setlink = nuts.setlink
local getwidth = nuts.getwidth
local getglyphdata = nuts.getglyphdata
-local getscale = nuts.getscale
+local getscales = nuts.getscales
+local getwhatever = nuts.getwhatever
---------------------------------------------------------------------------------------
@@ -295,6 +296,8 @@ local marks = false
local classes = false
local currentfont = false
local currentattr = false
+local currentxscale = false
+local currentyscale = false
local factor = 0
local threshold = 0
local checkmarks = false
@@ -761,7 +764,7 @@ function handlers.gsub_ligature(head,start,dataset,sequence,ligature,rlmode,skip
local startchar = getchar(start)
if skiphash and skiphash[startchar] then
while current do
- local nxt, char = isnextchar(current,currentfont,currentattr)
+ local nxt, char = isnextchar(current,currentfont,currentxscale,currentyscale)
if char then
local lg = ligature[char]
if lg then
@@ -795,7 +798,7 @@ function handlers.gsub_ligature(head,start,dataset,sequence,ligature,rlmode,skip
local discfound = false
local hasmarks = marks[startchar]
while current do
- local nxt, char, id = isnextchar(current,currentfont,currentattr)
+ local nxt, char, id = isnextchar(current,currentfont,currentxscale,currentyscale)
if char then
if skiphash and skiphash[char] then
current = nxt
@@ -830,20 +833,20 @@ function handlers.gsub_ligature(head,start,dataset,sequence,ligature,rlmode,skip
local pre, post, replace = getdisc(discfound)
local match
if replace then
- local char = ischar(replace,currentfont,currentattr)
+ local char = ischar(replace,currentfont,currentxscale,currentyscale)
if char and ligature[char] then
match = true
end
end
if not match and pre then
- local char = ischar(pre,currentfont,currentattr)
+ local char = ischar(pre,currentfont,currentxscale,currentyscale)
if char and ligature[char] then
match = true
end
end
if not match and not pre or not replace then
local n = getnext(discfound)
- local char = ischar(n,currentfont,currentattr)
+ local char = ischar(n,currentfont,currentxscale,currentyscale)
if char and ligature[char] then
match = true
end
@@ -947,7 +950,7 @@ function handlers.gpos_pair(head,start,dataset,sequence,kerns,rlmode,skiphash,st
else
local prev = start
while snext do
- local nextchar = ischar(snext,currentfont,currentattr)
+ local nextchar = ischar(snext,currentfont,currentxscale,currentyscale)
if nextchar then
if skiphash and skiphash[nextchar] then -- includes marks too when flag
prev = snext
@@ -1013,13 +1016,13 @@ function handlers.gpos_mark2base(head,start,dataset,sequence,markanchors,rlmode,
if marks[markchar] then
local base = getprev(start) -- [glyph] [start=mark]
if base then
- local basechar = ischar(base,currentfont,currentattr)
+ local basechar = ischar(base,currentfont,currentxscale,currentyscale)
if basechar then
if marks[basechar] then
while base do
base = getprev(base)
if base then
- basechar = ischar(base,currentfont,currentattr)
+ basechar = ischar(base,currentfont,currentxscale,currentyscale)
if basechar then
if not marks[basechar] then
break
@@ -1068,13 +1071,13 @@ function handlers.gpos_mark2ligature(head,start,dataset,sequence,markanchors,rlm
if marks[markchar] then
local base = getprev(start) -- [glyph] [optional marks] [start=mark]
if base then
- local basechar = ischar(base,currentfont,currentattr)
+ local basechar = ischar(base,currentfont,currentxscale,currentyscale)
if basechar then
if marks[basechar] then
while base do
base = getprev(base)
if base then
- basechar = ischar(base,currentfont,currentattr)
+ basechar = ischar(base,currentfont,currentxscale,currentyscale)
if basechar then
if not marks[basechar] then
break
@@ -1144,7 +1147,7 @@ function handlers.gpos_mark2mark(head,start,dataset,sequence,markanchors,rlmode,
end
end
if base then
- local basechar = ischar(base,currentfont,currentattr)
+ local basechar = ischar(base,currentfont,currentxscale,currentyscale)
if basechar then -- subtype test can go
local ba = markanchors[1][basechar] -- slot 1 has been made copy of the class hash
if ba then
@@ -1173,7 +1176,7 @@ function handlers.gpos_cursive(head,start,dataset,sequence,exitanchors,rlmode,sk
else
local nxt = getnext(start)
while nxt do
- local nextchar = ischar(nxt,currentfont,currentattr)
+ local nextchar = ischar(nxt,currentfont,currentxscale,currentyscale)
if not nextchar then
break
elseif marks[nextchar] then -- always sequence.flags[1]
@@ -1501,7 +1504,7 @@ function chainprocs.gsub_ligature(head,start,stop,dataset,sequence,currentlookup
-- end
-- end
--
- local nxt, schar, id = isnextchar(current,currentfont,currentattr)
+ local nxt, schar, id = isnextchar(current,currentfont,currentxscale,currentyscale)
if schar then
if skiphash and skiphash[schar] then -- marks
-- if current == stop then -- maybe add this
@@ -1610,7 +1613,7 @@ function chainprocs.gpos_pair(head,start,stop,dataset,sequence,currentlookup,rlm
if kerns then
local prev = start
while snext do
- local nextchar = ischar(snext,currentfont,currentattr)
+ local nextchar = ischar(snext,currentfont,currentxscale,currentyscale)
if not nextchar then
break
end
@@ -1679,13 +1682,13 @@ function chainprocs.gpos_mark2base(head,start,stop,dataset,sequence,currentlooku
if markanchors then
local base = getprev(start) -- [glyph] [start=mark]
if base then
- local basechar = ischar(base,currentfont,currentattr)
+ local basechar = ischar(base,currentfont,currentxscale,currentyscale)
if basechar then
if marks[basechar] then
while base do
base = getprev(base)
if base then
- local basechar = ischar(base,currentfont,currentattr)
+ local basechar = ischar(base,currentfont,currentxscale,currentyscale)
if basechar then
if not marks[basechar] then
break
@@ -1744,13 +1747,13 @@ function chainprocs.gpos_mark2ligature(head,start,stop,dataset,sequence,currentl
if markanchors then
local base = getprev(start) -- [glyph] [optional marks] [start=mark]
if base then
- local basechar = ischar(base,currentfont,currentattr)
+ local basechar = ischar(base,currentfont,currentxscale,currentyscale)
if basechar then
if marks[basechar] then
while base do
base = getprev(base)
if base then
- local basechar = ischar(base,currentfont,currentattr)
+ local basechar = ischar(base,currentfont,currentxscale,currentyscale)
if basechar then
if not marks[basechar] then
break
@@ -1824,7 +1827,7 @@ function chainprocs.gpos_mark2mark(head,start,stop,dataset,sequence,currentlooku
end
end
if base then -- subtype test can go
- local basechar = ischar(base,currentfont,currentattr)
+ local basechar = ischar(base,currentfont,currentxscale,currentyscale)
if basechar then
local ba = markanchors[1][basechar]
if ba then
@@ -1870,7 +1873,7 @@ function chainprocs.gpos_cursive(head,start,stop,dataset,sequence,currentlookup,
else
local nxt = getnext(start)
while nxt do
- local nextchar = ischar(nxt,currentfont,currentattr)
+ local nextchar = ischar(nxt,currentfont,currentxscale,currentyscale)
if not nextchar then
break
elseif marks[nextchar] then
@@ -2045,7 +2048,7 @@ local function chainrun(head,start,last,dataset,sequence,rlmode,skiphash,ck)
while start do
if skiphash then -- hm, so we know we skip some
while start do
- local char = ischar(start,currentfont,currentattr)
+ local char = ischar(start,currentfont,currentxscale,currentyscale)
if char then
if skiphash and skiphash[char] then
start = getnext(start)
@@ -2306,7 +2309,7 @@ local function chaindisk(head,start,dataset,sequence,rlmode,skiphash,ck)
local insertedmarks = 0
while cprev do
- local char = ischar(cf,currentfont,currentattr)
+ local char = ischar(cf,currentfont,currentxscale,currentyscale)
if char and marks[char] then
insertedmarks = insertedmarks + 1
cf = cprev
@@ -2372,7 +2375,7 @@ local function chaindisk(head,start,dataset,sequence,rlmode,skiphash,ck)
local insertedmarks = 0
while cnext do
- local char = ischar(cnext,currentfont,currentattr)
+ local char = ischar(cnext,currentfont,currentxscale,currentyscale)
if char and marks[char] then
insertedmarks = insertedmarks + 1
cl = cnext
@@ -2481,8 +2484,9 @@ local function handle_contextchain(head,start,dataset,sequence,contexts,rlmode,s
end
checkdisc = getprev(head)
end
- local currentfont = currentfont
- local currentattr = currentattr
+ local currentfont = currentfont -- really ?
+ local currentxscale = currentxscale -- really ?
+ local currentyscale = currentyscale -- really ?
local skipped -- = false
@@ -2501,7 +2505,7 @@ local function handle_contextchain(head,start,dataset,sequence,contexts,rlmode,s
local nofcontexts = contexts.n -- #contexts
- local startchar = nofcontext == 1 or ischar(start,currentfont,currentattr) -- only needed in a chain
+ local startchar = nofcontext == 1 or ischar(start,currentfont,currentxscale,currentyscale) -- only needed in a chain
for k=1,nofcontexts do -- does this disc mess work well with n > 1
@@ -2535,7 +2539,7 @@ local function handle_contextchain(head,start,dataset,sequence,contexts,rlmode,s
end
if last then
-- local char, id = ischar(last,currentfont)
- local nxt, char, id = isnextchar(last,currentfont,currentattr)
+ local nxt, char, id = isnextchar(last,currentfont,currentxscale,currentyscale)
if char then
if skiphash and skiphash[char] then
skipped = true
@@ -2648,7 +2652,7 @@ local function handle_contextchain(head,start,dataset,sequence,contexts,rlmode,s
while n >= 1 do
if prev then
-- local char, id = ischar(prev,currentfont)
- local prv, char, id = isprevchar(prev,currentfont,currentattr)
+ local prv, char, id = isprevchar(prev,currentfont,currentxscale,currentyscale)
if char then
if skiphash and skiphash[char] then
skipped = true
@@ -2786,7 +2790,7 @@ local function handle_contextchain(head,start,dataset,sequence,contexts,rlmode,s
while n <= s do
if current then
-- local char, id = ischar(current,currentfont)
- local nxt, char, id = isnextchar(current,currentfont,currentattr)
+ local nxt, char, id = isnextchar(current,currentfont,currentxscale,currentyscale)
if char then
if skiphash and skiphash[char] then
skipped = true
@@ -3423,48 +3427,6 @@ local function c_run_single(head,font,attr,lookupcache,step,dataset,sequence,rlm
return head, done
end
--- local function c_run_single(head,font,attr,lookupcache,step,dataset,sequence,rlmode,skiphash,handler)
--- local done = false
--- local sweep = sweephead[head]
--- local start
--- if sweep then
--- start = sweep
--- -- sweephead[head] = nil
--- sweephead[head] = false
--- else
--- start = head
--- end
--- while start do
--- local nxt, char, id = isnextchar(start,font,currentattribute)
--- if char then
--- local lookupmatch = lookupcache[char]
--- if lookupmatch then
--- local ok
--- head, start, ok = handler(head,start,dataset,sequence,lookupmatch,rlmode,skiphash,step)
--- if ok then
--- done = true
--- end
--- if start then
--- start = getnext(start)
--- end
--- else
--- start = nxt
--- end
--- elseif char == false then
--- return head, done
--- elseif sweep then
--- -- else we loose the rest
--- return head, done
--- else
--- -- in disc component
--- start = nxt
--- end
--- end
--- return head, done
--- end
-
--- only replace?
-
local function t_run_single(start,stop,font,attr,lookupcache)
local lastd = nil
while start ~= stop do
@@ -3860,18 +3822,19 @@ do
nesting = nesting + 1
if nesting == 1 then
- currentfont = font
- currentattr = attr
-currentattr = false
- tfmdata = fontdata[font]
- descriptions = tfmdata.descriptions -- only needed in gref so we could pass node there instead
- characters = tfmdata.characters -- but this branch is not entered that often anyway
- local resources = tfmdata.resources
- marks = resources.marks
- classes = resources.classes
+ currentfont = font
+ currentattr = attr
+ currentxscale = false
+ currentyscale = false
+ tfmdata = fontdata[font]
+ descriptions = tfmdata.descriptions -- only needed in gref so we could pass node there instead
+ characters = tfmdata.characters -- but this branch is not entered that often anyway
+ local resources = tfmdata.resources
+ marks = resources.marks
+ classes = resources.classes
threshold,
- factor = getthreshold(font)
- checkmarks = tfmdata.properties.checkmarks
+ factor = getthreshold(font)
+ checkmarks = tfmdata.properties.checkmarks
if not otfdataset then
otfdataset = otf.dataset
@@ -3908,7 +3871,6 @@ currentattr = false
initialrl = -1
end
- -- local done = false
local datasets = otfdataset(tfmdata,font,attr)
local dirstack = { nil } -- could move outside function but we can have local runs
sweephead = { }
@@ -3939,9 +3901,6 @@ currentattr = false
-- are not frozen as we might extend or change this. Is this used at all apart from some
-- experiments?
local h, ok = handler(head,dataset,sequence,initialrl,font,attr) -- less arguments now
- -- if ok then
- -- done = true
- -- end
if h and h ~= head then
head = h
end
@@ -3955,20 +3914,24 @@ currentattr = false
local rlmode = 0 -- how important is this .. do we need to check for dir?
local merged = steps.merged
while start do
- local char = ischar(start,font)
+-- local prv, char, id = isprevchar(start,font)
+ local prv, char, id = isprevchar(start,font)
if char then
local m = merged[char]
if m then
- local a -- happens often so no assignment is faster
- if attr then
- a = getglyphdata(start)
- end
- if not a or (a == attr) then
-currentattr = getscale(start)
+-- local a -- happens often so no assignment is faster
+-- if attr then
+-- a = getglyphdata(start)
+-- end
+-- if not a or (a == attr) then
+-- currentxscale, currentyscale = getscales(start)
+
+ local a
+ a, currentxscale, currentyscale = getwhatever(start,attr,attribute)
+ if a then
+
for i=m[1],m[2] do
local step = steps[i]
- -- for i=1,#m do
- -- local step = m[i]
local lookupcache = step.coverage
local lookupmatch = lookupcache[char]
if lookupmatch then
@@ -3984,13 +3947,13 @@ currentattr = getscale(start)
start = getprev(start)
end
else
- start = getprev(start)
+ start = prv
end
else
- start = getprev(start)
+ start = prv
end
else
- start = getprev(start)
+ start = prv
end
end
else
@@ -4000,47 +3963,45 @@ currentattr = getscale(start)
local step = steps[1]
local lookupcache = step.coverage
while start do
- -- local char, id = ischar(start,font)
local nxt, char, id = isnextchar(start,font)
if char then
if skiphash and skiphash[char] then -- we never needed it here but let's try
- -- start = getnext(start)
start = nxt
else
local lookupmatch = lookupcache[char]
if lookupmatch then
- local a -- happens often so no assignment is faster
- if attr then
- if getglyphdata(start) == attr and (not attribute or getstate(start,attribute)) then
- a = true
- end
- elseif not attribute or getstate(start,attribute) then
- a = true
- end
+-- local a -- happens often so no assignment is faster
+-- if attr then
+-- if getglyphdata(start) == attr and (not attribute or getstate(start,attribute)) then
+-- a = true
+-- end
+-- elseif not attribute or getstate(start,attribute) then
+-- a = true
+-- end
+-- if a then
+-- currentxscale, currentyscale = getscales(start)
+
+ local a
+ a, currentxscale, currentyscale = getwhatever(start,attr,attribute)
if a then
-currentattr = getscale(start)
+
local ok, df
head, start, ok, df = handler(head,start,dataset,sequence,lookupmatch,rlmode,skiphash,step)
- -- if ok then
- -- done = true
- -- end
if df then
-- print("restart 1",typ)
elseif start then
start = getnext(start) -- can be a new start
end
else
- -- start = getnext(start)
start = nxt
end
else
- -- start = getnext(start)
start = nxt
end
+
end
elseif char == false or id == glue_code then
-- a different font|state or glue (happens often)
- -- start = getnext(start)
start = nxt
elseif id == disc_code then
if not discs or discs[start] == true then
@@ -4056,51 +4017,48 @@ currentattr = getscale(start)
-- done = true
-- end
else
- -- start = getnext(start)
start = nxt
end
elseif id == math_code then
start = getnext(end_of_math(start))
elseif id == dir_code then
topstack, rlmode = txtdirstate(start,dirstack,topstack,rlparmode)
- -- start = getnext(start)
start = nxt
-- elseif id == par_code and start_of_par(start) then
-- rlparmode, rlmode = pardirstate(start)
- -- -- start = getnext(start)
-- start = nxt
else
- -- start = getnext(start)
start = nxt
end
end
else
local merged = steps.merged
while start do
- -- local char, id = ischar(start,font)
local nxt, char, id = isnextchar(start,font)
if char then
if skiphash and skiphash[char] then -- we never needed it here but let's try
- -- start = getnext(start)
start = nxt
else
local m = merged[char]
if m then
- local a -- happens often so no assignment is faster
- if attr then
- if getglyphdata(start) == attr and (not attribute or getstate(start,attribute)) then
- a = true
- end
- elseif not attribute or getstate(start,attribute) then
- a = true
- end
+-- local a -- happens often so no assignment is faster
+-- if attr then
+-- if getglyphdata(start) == attr and (not attribute or getstate(start,attribute)) then
+-- a = true
+-- end
+-- elseif not attribute or getstate(start,attribute) then
+-- a = true
+-- end
+-- if a then
+-- currentxscale, currentyscale = getscales(start)
+
+ local a
+ a, currentxscale, currentyscale = getwhatever(start,attr,attribute)
if a then
-currentattr = getscale(start)
+
local ok, df
for i=m[1],m[2] do
local step = steps[i]
- -- for i=1,#m do
- -- local step = m[i]
local lookupcache = step.coverage
local lookupmatch = lookupcache[char]
if lookupmatch then
@@ -4110,7 +4068,6 @@ currentattr = getscale(start)
if df then
break
elseif ok then
- -- done = true
break
elseif not start then
-- don't ask why ... shouldn't happen
@@ -4124,17 +4081,14 @@ currentattr = getscale(start)
start = getnext(start) -- can be a new next
end
else
- -- start = getnext(start)
start = nxt
end
else
- -- start = getnext(start)
start = nxt
end
end
elseif char == false or id == glue_code then
-- a different font|state or glue (happens often)
- -- start = getnext(start)
start = nxt
elseif id == disc_code then
if not discs or discs[start] == true then
@@ -4146,24 +4100,18 @@ currentattr = getscale(start)
else
start, ok = comprun(start,c_run_multiple, font,attr,steps,nofsteps,dataset,sequence,rlmode,skiphash,handler)
end
- -- if ok then
- -- done = true
- -- end
else
- -- start = getnext(start)
start = nxt
end
elseif id == math_code then
start = getnext(end_of_math(start))
elseif id == dir_code then
topstack, rlmode = txtdirstate(start,dirstack,topstack,rlparmode)
- -- start = getnext(start)
start = nxt
-- elseif id == par_code and start_of_par(start) then
-- rlparmode, rlmode = pardirstate(start)
- -- start = getnext(start)
+ -- start = nxt
else
- -- start = getnext(start)
start = nxt
end
end
@@ -4178,7 +4126,6 @@ currentattr = getscale(start)
nesting = nesting - 1
- -- return head, done
return head
end
@@ -4188,7 +4135,8 @@ currentattr = getscale(start)
function otf.datasetpositionprocessor(head,font,direction,dataset)
currentfont = font
- currentattr = false
+ currentxscale = false
+ currentyscale = false
tfmdata = fontdata[font]
descriptions = tfmdata.descriptions -- only needed in gref so we could pass node there instead
characters = tfmdata.characters -- but this branch is not entered that often anyway