summaryrefslogtreecommitdiff
path: root/src/fontloader/misc/fontloader-font-ots.lua
diff options
context:
space:
mode:
Diffstat (limited to 'src/fontloader/misc/fontloader-font-ots.lua')
-rw-r--r--src/fontloader/misc/fontloader-font-ots.lua158
1 files changed, 114 insertions, 44 deletions
diff --git a/src/fontloader/misc/fontloader-font-ots.lua b/src/fontloader/misc/fontloader-font-ots.lua
index 10f0518..d371156 100644
--- a/src/fontloader/misc/fontloader-font-ots.lua
+++ b/src/fontloader/misc/fontloader-font-ots.lua
@@ -275,6 +275,13 @@ local checkstep = (nodes and nodes.tracers and nodes.tracers.steppers.chec
local registerstep = (nodes and nodes.tracers and nodes.tracers.steppers.register) or function() end
local registermessage = (nodes and nodes.tracers and nodes.tracers.steppers.message) or function() end
+local function checkdisccontent(d)
+ local pre, post, replace = getdisc(d)
+ if pre then for n in traverse_id(glue_code,pre) do print("pre",nodes.idstostring(pre)) break end end
+ if post then for n in traverse_id(glue_code,post) do print("pos",nodes.idstostring(post)) break end end
+ if replace then for n in traverse_id(glue_code,replace) do print("rep",nodes.idstostring(replace)) break end end
+end
+
local function logprocess(...)
if trace_steps then
registermessage(...)
@@ -351,7 +358,7 @@ end
local function copy_glyph(g) -- next and prev are untouched !
local components = getfield(g,"components")
if components then
- setfield(g,"components",nil)
+ setfield(g,"components")
local n = copy_node(g)
copyinjection(n,g) -- we need to preserve the lig indices
setfield(g,"components",components)
@@ -364,11 +371,18 @@ local function copy_glyph(g) -- next and prev are untouched !
end
local function flattendisk(head,disc)
- local _, _, replace, _, _, replacetail = getdisc(disc,true)
- setfield(disc,"replace",nil)
+ local pre, post, replace, pretail, posttail, replacetail = getdisc(disc,true)
+ local prev, next = getboth(disc)
+ local ishead = head == disc
+ setdisc(disc)
flush_node(disc)
- if head == disc then
- local next = getnext(disc)
+ if pre then
+ flush_node_list(pre)
+ end
+ if post then
+ flush_node_list(post)
+ end
+ if ishead then
if replace then
if next then
setlink(replacetail,next)
@@ -380,7 +394,6 @@ local function flattendisk(head,disc)
return -- maybe warning
end
else
- local prev, next = getboth(disc)
if replace then
if next then
setlink(replacetail,next)
@@ -419,8 +432,8 @@ local function markstoligature(head,start,stop,char)
else
local prev = getprev(start)
local next = getnext(stop)
- setprev(start,nil)
- setnext(stop,nil)
+ setprev(start)
+ setnext(stop)
local base = copy_glyph(start)
if head == start then
head = base
@@ -482,8 +495,8 @@ local function toligature(head,start,stop,char,dataset,sequence,markflag,discfou
local prev = getprev(start)
local next = getnext(stop)
local comp = start
- setprev(start,nil)
- setnext(stop,nil)
+ setprev(start)
+ setnext(stop)
local base = copy_glyph(start)
if start == head then
head = base
@@ -553,38 +566,37 @@ local function toligature(head,start,stop,char,dataset,sequence,markflag,discfou
-- anyway
local pre, post, replace, pretail, posttail, replacetail = getdisc(discfound,true)
if not replace then -- todo: signal simple hyphen
- local prev = getprev(base)
--- local copied = copy_node_list(comp)
-local current = comp
-local previous = nil
-local copied = nil
-while current do
- if getid(current) == glyph_code then
- local n = copy_node(current)
- if copied then
- setlink(previous,n)
- else
- copied = n
- end
- previous = n
- end
- current = getnext(current)
-end
- setprev(discnext,nil) -- also blocks funny assignments
- setnext(discprev,nil) -- also blocks funny assignments
+ local prev = getprev(base)
+ local current = comp
+ local previous = nil
+ local copied = nil
+ while current do
+ if getid(current) == glyph_code then
+ local n = copy_node(current)
+ if copied then
+ setlink(previous,n)
+ else
+ copied = n
+ end
+ previous = n
+ end
+ current = getnext(current)
+ end
+ setprev(discnext) -- also blocks funny assignments
+ setnext(discprev) -- also blocks funny assignments
if pre then
setlink(discprev,pre)
end
pre = comp
if post then
setlink(posttail,discnext)
- setprev(post,nil)
+ setprev(post)
else
post = discnext
end
setlink(prev,discfound)
setlink(discfound,next)
- setboth(base,nil,nil)
+ setboth(base)
setfield(base,"components",copied)
setdisc(discfound,pre,post,base,discretionary_code)
base = prev -- restart
@@ -1751,6 +1763,42 @@ end
-- order to handle that we need more complex code which also slows down even more. The main
-- loop variant could deal with that: test, collapse, backtrack.
+local new_kern = nuts.pool.kern
+
+local function checked(head)
+ local current = head
+ while current do
+ if getid(current) == glue_code then
+ local kern = new_kern(getfield(current,"width"))
+ if head == current then
+ local next = getnext(current)
+ if next then
+ setlink(kern,next)
+ end
+ flush_node(current)
+ head = kern
+ current = next
+ else
+ local prev, next = getboth(current)
+ setlink(prev,kern)
+ setlink(kern,next)
+ flush_node(current)
+ current = next
+ end
+ else
+ current = getnext(current)
+ end
+ end
+ return head
+end
+
+local function setdiscchecked(d,pre,post,replace)
+ if pre then pre = checked(pre) end
+ if post then post = checked(post) end
+ if replace then replace = checked(replace) end
+ setdisc(d,pre,post,replace)
+end
+
local function chaindisk(head,start,last,dataset,sequence,chainlookup,rlmode,k,ck,chainproc)
if not start then
@@ -1773,8 +1821,10 @@ local function chaindisk(head,start,last,dataset,sequence,chainlookup,rlmode,k,c
local current = start
local last = start
local prev = getprev(start)
+ local hasglue = false
-- fishy: so we can overflow and then go on in the sweep?
+ -- todo : id can also be glue_code as we checked spaces
local i = f
while i <= l do
@@ -1783,6 +1833,11 @@ local function chaindisk(head,start,last,dataset,sequence,chainlookup,rlmode,k,c
i = i + 1
last = current
current = getnext(current)
+ elseif id == glue_code then
+ i = i + 1
+ last = current
+ current = getnext(current)
+ hasglue = true
elseif id == disc_code then
if keepdisc then
keepdisc = false
@@ -1835,8 +1890,8 @@ local function chaindisk(head,start,last,dataset,sequence,chainlookup,rlmode,k,c
tail = find_node_tail(head)
end
setnext(sweepnode,current)
- setprev(head,nil)
- setnext(tail,nil)
+ setprev(head)
+ setnext(tail)
appenddisc(sweepnode,head)
end
end
@@ -1849,6 +1904,10 @@ local function chaindisk(head,start,last,dataset,sequence,chainlookup,rlmode,k,c
if id == glyph_code then
i = i + 1
current = getnext(current)
+ elseif id == glue_code then
+ i = i + 1
+ current = getnext(current)
+ hasglue = true
elseif id == disc_code then
if keepdisc then
keepdisc = false
@@ -1891,6 +1950,9 @@ local function chaindisk(head,start,last,dataset,sequence,chainlookup,rlmode,k,c
local id = getid(current)
if id == glyph_code then
i = i - 1
+ elseif id == glue_code then
+ i = i - 1
+ hasglue = true
elseif id == disc_code then
if keepdisc then
keepdisc = false
@@ -1939,8 +2001,8 @@ local function chaindisk(head,start,last,dataset,sequence,chainlookup,rlmode,k,c
if cprev then
setnext(cprev,lookaheaddisc)
end
- setprev(cf,nil)
- setnext(cl,nil)
+ setprev(cf)
+ setnext(cl)
if startishead then
head = lookaheaddisc
end
@@ -1967,7 +2029,11 @@ local function chaindisk(head,start,last,dataset,sequence,chainlookup,rlmode,k,c
local tail = find_node_tail(new)
setlink(tail,replace)
end
- setdisc(lookaheaddisc,cf,post,new)
+ if hasglue then
+ setdiscchecked(lookaheaddisc,cf,post,new)
+ else
+ setdisc(lookaheaddisc,cf,post,new)
+ end
start = getprev(lookaheaddisc)
sweephead[cf] = getnext(clast)
sweephead[new] = getnext(last)
@@ -1993,8 +2059,8 @@ local function chaindisk(head,start,last,dataset,sequence,chainlookup,rlmode,k,c
setprev(cnext,backtrackdisc)
end
setnext(backtrackdisc,cnext)
- setprev(cf,nil)
- setnext(cl,nil)
+ setprev(cf)
+ setnext(cl)
local pre, post, replace, pretail, posttail, replacetail = getdisc(backtrackdisc,true)
local new = copy_node_list(cf)
local cnew = find_node_tail(new)
@@ -2021,7 +2087,11 @@ local function chaindisk(head,start,last,dataset,sequence,chainlookup,rlmode,k,c
else
replace = new
end
- setdisc(backtrackdisc,pre,post,replace)
+ if hasglue then
+ setdiscchecked(backtrackdisc,pre,post,replace)
+ else
+ setdisc(backtrackdisc,pre,post,replace)
+ end
start = getprev(backtrackdisc)
sweephead[post] = getnext(clast)
sweephead[replace] = getnext(last)
@@ -2744,7 +2814,7 @@ local function kernrun(disc,k_run,font,attr,...)
done = true
end
setprev(pre,nest)
--- setprev(pre,nil)
+-- setprev(pre)
setnext(prev,disc)
end
end
@@ -2758,7 +2828,7 @@ local function kernrun(disc,k_run,font,attr,...)
if k_run(posttail,"postinjections",next,font,attr,...) then
done = true
end
- setnext(posttail,nil)
+ setnext(posttail)
setprev(next,disc)
end
end
@@ -2774,7 +2844,7 @@ local function kernrun(disc,k_run,font,attr,...)
done = true
end
setprev(replace,nest)
--- setprev(replace,nil)
+-- setprev(replace)
setnext(prev,disc)
end
if next then
@@ -2782,7 +2852,7 @@ local function kernrun(disc,k_run,font,attr,...)
if k_run(replacetail,"replaceinjections",next,font,attr,...) then
done = true
end
- setnext(replacetail,nil)
+ setnext(replacetail)
setprev(next,disc)
end
elseif prev and next then
@@ -2862,7 +2932,7 @@ local function testrun(disc,t_run,c_run,...)
local ok, overflow = t_run(replace,next,...)
if ok and overflow then
-- so, we can have crossed the boundary
- setfield(disc,"replace",nil)
+ setfield(disc,"replace")
setlink(prev,replace)
-- setlink(replacetail,next)
setboth(disc)