summaryrefslogtreecommitdiff
path: root/tex/context/base/mkiv/typo-brk.lua
diff options
context:
space:
mode:
Diffstat (limited to 'tex/context/base/mkiv/typo-brk.lua')
-rw-r--r--tex/context/base/mkiv/typo-brk.lua121
1 files changed, 55 insertions, 66 deletions
diff --git a/tex/context/base/mkiv/typo-brk.lua b/tex/context/base/mkiv/typo-brk.lua
index 106bb4954..84eff0654 100644
--- a/tex/context/base/mkiv/typo-brk.lua
+++ b/tex/context/base/mkiv/typo-brk.lua
@@ -32,11 +32,15 @@ local getsubtype = nuts.getsubtype
local getfont = nuts.getfont
local getid = nuts.getid
local getfield = nuts.getfield
-local getattr = nuts.getattr
+----- getattr = nuts.getattr
+local getattrlist = nuts.getattrlist
+local takeattr = nuts.takeattr
+local getlang = nuts.getlang
local isglyph = nuts.isglyph
local setfield = nuts.setfield
local setattr = nuts.setattr
+local setattrlist = nuts.setattrlist
local setlink = nuts.setlink
local setchar = nuts.setchar
local setdisc = nuts.setdisc
@@ -45,9 +49,9 @@ local setprev = nuts.setprev
local setboth = nuts.setboth
local setsubtype = nuts.setsubtype
-local copy_node = nuts.copy
-local copy_nodelist = nuts.copy_list
-local free_node = nuts.free
+local copy_node = nuts.copy_node
+local copy_node_list = nuts.copy_list
+local flush_node = nuts.flush_node
local insert_node_before = nuts.insert_before
local insert_node_after = nuts.insert_after
local remove_node = nuts.remove
@@ -59,7 +63,7 @@ local texsetattribute = tex.setattribute
local unsetvalue = attributes.unsetvalue
local nodepool = nuts.pool
-local tasks = nodes.tasks
+local enableaction = nodes.tasks.enableaction
local v_reset = interfaces.variables.reset
local v_yes = interfaces.variables.yes
@@ -79,7 +83,7 @@ local kern_code = nodecodes.kern
local math_code = nodecodes.math
local fontkern_code = kerncodes.fontkern
-local userkern_code = kerncodes.userkern
+----- userkern_code = kerncodes.userkern
local italickern_code = kerncodes.italiccorrection
local typesetters = typesetters
@@ -109,19 +113,21 @@ end
-- todo: use boundaries
-local function withattribute(n,a)
- setfield(n,"attr",a)
- return n
-end
-
local function insert_break(head,start,stop,before,after,kern)
- local a = getfield(start,"attr")
if not kern then
- insert_node_before(head,start,withattribute(new_penalty(before),a))
- insert_node_before(head,start,withattribute(new_glue(0),a))
+ local p = new_penalty(before)
+ local g = new_glue()
+ setattrlist(p,start)
+ setattrlist(g,start)
+ insert_node_before(head,start,p)
+ insert_node_before(head,start,g)
end
- insert_node_after(head,stop,withattribute(new_glue(0),a))
- insert_node_after(head,stop,withattribute(new_penalty(after),a))
+ local p = new_penalty(after)
+ local g = new_glue()
+ setattrlist(p,start)
+ setattrlist(g,start)
+ insert_node_after(head,stop,g)
+ insert_node_after(head,stop,p)
end
methods[1] = function(head,start,stop,settings,kern)
@@ -142,21 +148,15 @@ methods[6] = function(head,start,stop,settings,kern)
local l = new_wordboundary()
local d = new_disc()
local r = new_wordboundary()
- local a = getfield(start,"attr")
- -- setfield(l,"attr",a)
- setfield(d,"attr",a) -- otherwise basemode is forces and we crash
- -- setfield(r,"attr",a)
- setlink(p,l)
- setlink(l,d)
- setlink(d,r)
- setlink(r,n)
+ setattrlist(d,start) -- otherwise basemode is forced and we crash
+ setlink(p,l,d,r,n)
if start == stop then
setboth(start)
setdisc(d,start,nil,copy_node(start))
else
setprev(start)
setnext(stop)
- setdisc(d,start,nil,copy_nodelist(start))
+ setdisc(d,start,nil,copy_node_list(start))
end
stop = r
end
@@ -167,17 +167,14 @@ end
methods[2] = function(head,start) -- ( => (-
local p, n = getboth(start)
if p and n then
- local tmp
- head, start, tmp = remove_node(head,start)
- head, start = insert_node_before(head,start,new_disc())
- -- setfield(start,"attr",copy_nodelist(getfield(tmp,"attr"))) -- just a copy will do
- setfield(start,"attr",getfield(tmp,"attr"))
- setfield(start,"replace",tmp)
- local tmp = copy_node(tmp)
- local hyphen = copy_node(tmp)
- setchar(hyphen,languages.prehyphenchar(getfield(tmp,"lang")))
- setlink(tmp,hyphen)
- setfield(start,"post",tmp)
+ local replace
+ head, start, replace = remove_node(head,start)
+ local post = copy_node(replace)
+ local hyphen = copy_node(post)
+ setchar(hyphen,languages.prehyphenchar(getlang(post)))
+ setlink(post,hyphen)
+ head, start = insert_node_before(head,start,new_disc(nil,post,replace))
+ setattrlist(start,replace)
insert_break(head,start,start,10000,10000)
end
return head, start
@@ -186,17 +183,14 @@ end
methods[3] = function(head,start) -- ) => -)
local p, n = getboth(start)
if p and n then
- local tmp
- head, start, tmp = remove_node(head,start)
- head, start = insert_node_before(head,start,new_disc())
- -- setfield(start,"attr",copy_nodelist(getfield(tmp,"attr"))) -- just a copy will do
- setfield(start,"attr",getfield(tmp,"attr"))
- setfield(start,"replace",tmp)
- local tmp = copy_node(tmp)
- local hyphen = copy_node(tmp)
- setchar(hyphen,languages.prehyphenchar(getfield(tmp,"lang")))
- setlink(hyphen,tmp)
- setfield(start,"pre",hyphen)
+ local replace
+ head, start, replace = remove_node(head,start)
+ local pre = copy_node(replace)
+ local hyphen = copy_node(pre)
+ setchar(hyphen,languages.prehyphenchar(getlang(pre)))
+ setlink(hyphen,pre)
+ head, start = insert_node_before(head,start,new_disc(hyphen,nil,replace)) -- so not pre !
+ setattrlist(start,tmp)
insert_break(head,start,start,10000,10000)
end
return head, start
@@ -208,8 +202,7 @@ methods[4] = function(head,start) -- - => - - -
local tmp
head, start, tmp = remove_node(head,start)
head, start = insert_node_before(head,start,new_disc())
- -- setfield(start,"attr",copy_nodelist(getfield(tmp,"attr"))) -- just a copy will do
- setfield(start,"attr",getfield(tmp,"attr"))
+ setattrlist(start,tmp)
setdisc(start,copy_node(tmp),copy_node(tmp),tmp)
insert_break(head,start,start,10000,10000)
end
@@ -221,11 +214,11 @@ methods[5] = function(head,start,stop,settings) -- x => p q r
if p and n then
local tmp
head, start, tmp = remove_node(head,start)
- head, start = insert_node_before(head,start,new_disc())
- local attr = getfield(tmp,"attr")
- local font = getfont(tmp)
- local left = settings.left
- local right = settings.right
+ head, start = insert_node_before(head,start,new_disc())
+ local attr = getattrlist(tmp)
+ local font = getfont(tmp)
+ local left = settings.left
+ local right = settings.right
local middle = settings.middle
if left then
left = tonodes(tostring(left),font,attr)
@@ -237,9 +230,8 @@ methods[5] = function(head,start,stop,settings) -- x => p q r
middle = tonodes(tostring(middle),font,attr)
end
setdisc(start,left,right,middle)
- -- setfield(start,"attr",copy_nodelist(attr)) -- todo: critical only -- just a copy will do
- setfield(start,"attr",attr) -- todo: critical only -- just a copy will do
- free_node(tmp)
+ setattrlist(start,attr)
+ flush_node(tmp)
insert_break(head,start,start,10000,10000)
end
return head, start
@@ -258,7 +250,8 @@ function breakpoints.handler(head)
while current do
local char, id = isglyph(current)
if char then
- local a = getattr(current,a_breakpoints)
+ -- local a = getattr(current,a_breakpoints)
+ local a = takeattr(current,a_breakpoints)
if a and a > 0 then
if a ~= attr then
local data = mapping[a]
@@ -272,9 +265,10 @@ function breakpoints.handler(head)
if map then
local cmap = map[char]
if cmap then
+ -- setattr(current,a_breakpoints,unsetvalue) -- should not be needed
-- for now we collect but when found ok we can move the handler here
-- although it saves nothing in terms of performance
- local lang = getfield(current,"lang")
+ local lang = getlang(current)
local smap = lang and lang >= 0 and lang < 0x7FFF and (cmap[numbers[lang]] or cmap[""])
if smap then
local skip = smap.skip
@@ -301,7 +295,6 @@ function breakpoints.handler(head)
else
current = getnext(current)
end
- setattr(start,a_breakpoints,unsetvalue) -- should not be needed
else
current = getnext(current)
end
@@ -332,7 +325,7 @@ function breakpoints.handler(head)
local stop = data[2]
local cmap = data[3]
local smap = data[4]
--- local lang = getfield(start,"lang")
+-- local lang = getlang(start)
-- -- we do a sanity check for language
-- local smap = lang and lang >= 0 and lang < 0x7FFF and (cmap[numbers[lang]] or cmap[""])
-- if smap then
@@ -454,7 +447,7 @@ function breakpoints.set(n)
if trace_breakpoints then
report_breakpoints("enabling breakpoints handler")
end
- tasks.enableaction("processors","typesetters.breakpoints.handler")
+ enableaction("processors","typesetters.breakpoints.handler")
end
n = n.number
end
@@ -462,10 +455,6 @@ function breakpoints.set(n)
texsetattribute(a_breakpoints,n)
end
--- function breakpoints.enable()
--- tasks.enableaction("processors","typesetters.breakpoints.handler")
--- end
-
-- interface
implement {