summaryrefslogtreecommitdiff
path: root/tex/generic/context/luatex/luatex-basics-nod.lua
diff options
context:
space:
mode:
authorHans Hagen <pragma@wxs.nl>2019-02-22 20:29:46 +0100
committerContext Git Mirror Bot <phg@phi-gamma.net>2019-02-22 20:29:46 +0100
commit7b271baae19db1528fbe6621bdf50af89a5a336b (patch)
tree4fc24a8f2be20aa90e90f6e1bcb62d69f4946235 /tex/generic/context/luatex/luatex-basics-nod.lua
parent67b9965fe473d18f13ed4c40f1e4e008eb870322 (diff)
downloadcontext-7b271baae19db1528fbe6621bdf50af89a5a336b.tar.gz
2019-02-22 19:43:00
Diffstat (limited to 'tex/generic/context/luatex/luatex-basics-nod.lua')
-rw-r--r--tex/generic/context/luatex/luatex-basics-nod.lua317
1 files changed, 99 insertions, 218 deletions
diff --git a/tex/generic/context/luatex/luatex-basics-nod.lua b/tex/generic/context/luatex/luatex-basics-nod.lua
index 40fb9ee4e..e22f170ef 100644
--- a/tex/generic/context/luatex/luatex-basics-nod.lua
+++ b/tex/generic/context/luatex/luatex-basics-nod.lua
@@ -7,12 +7,12 @@ if not modules then modules = { } end modules ['luatex-fonts-nod'] = {
}
if context then
- texio.write_nl("fatal error: this module is not for context")
os.exit()
end
--- Don't depend on code here as it is only needed to complement the
--- font handler code.
+-- Don't depend on code here as it is only needed to complement the font handler
+-- code. I will move some to another namespace as I don't see other macro packages
+-- use the context logic. It's a subset anyway.
-- Attributes:
@@ -59,11 +59,11 @@ for k, v in next, node.types() do
nodecodes[k] = v
nodecodes[v] = k
end
-for i=0,#glyphcodes do
- glyphcodes[glyphcodes[i]] = i
+for k, v in next, glyphcodes do
+ glyphcodes[v] = k
end
-for i=0,#disccodes do
- disccodes[disccodes[i]] = i
+for k, v in next, disccodes do
+ disccodes[v] = k
end
nodes.nodecodes = nodecodes
@@ -74,19 +74,8 @@ local flush_node = node.flush_node
local remove_node = node.remove
local traverse_id = node.traverse_id
-nodes.handlers.protectglyphs = node.protect_glyphs
-nodes.handlers.unprotectglyphs = node.unprotect_glyphs
-
-local math_code = nodecodes.math
-local end_of_math = node.end_of_math
-
-function node.end_of_math(n)
- if n.id == math_code and n.subtype == 1 then
- return n
- else
- return end_of_math(n)
- end
-end
+nodes.handlers.protectglyphs = node.protect_glyphs -- beware: nodes!
+nodes.handlers.unprotectglyphs = node.unprotect_glyphs -- beware: nodes!
function nodes.remove(head, current, free_too)
local t = current
@@ -155,8 +144,6 @@ nodes.unset_attribute = node.unset_attribute
nodes.protect_glyphs = node.protect_glyphs
nodes.unprotect_glyphs = node.unprotect_glyphs
------.kerning = node.kerning
------.ligaturing = node.ligaturing
nodes.mlist_to_hlist = node.mlist_to_hlist
-- in generic code, at least for some time, we stay nodes, while in context
@@ -178,128 +165,104 @@ nodes.tonut = tonut
nuts.tonode = tonode
nuts.tonut = tonut
-local getfield = direct.getfield
-local setfield = direct.setfield
-
-nuts.getfield = getfield
-nuts.setfield = setfield
-nuts.getnext = direct.getnext
-nuts.setnext = direct.setnext
-nuts.getprev = direct.getprev
-nuts.setprev = direct.setprev
+nuts.getattr = direct.get_attribute
nuts.getboth = direct.getboth
-nuts.setboth = direct.setboth
-nuts.getid = direct.getid
-nuts.getattr = direct.get_attribute or direct.has_attribute or getfield
-nuts.setattr = setfield
+nuts.getchar = direct.getchar
+nuts.getcomponents = direct.getcomponents
+----.getdepth = direct.getdepth
+----.getdir = direct.getdir
+nuts.getdirection = direct.getdirection
+nuts.getdisc = direct.getdisc
+nuts.getfield = direct.getfield
nuts.getfont = direct.getfont
-nuts.setfont = direct.setfont
+----.getheight = direct.getheight
+nuts.getid = direct.getid
+nuts.getkern = direct.getkern
+----.getleader = direct.getleader
+nuts.getlist = direct.getlist
+nuts.getnext = direct.getnext
+nuts.getoffsets = direct.getoffsets
+nuts.getprev = direct.getprev
nuts.getsubtype = direct.getsubtype
-nuts.setsubtype = direct.setsubtype
-nuts.getchar = direct.getchar
+nuts.getwidth = direct.getwidth
+nuts.setattr = direct.setfield
+nuts.setboth = direct.setboth
nuts.setchar = direct.setchar
-nuts.getdisc = direct.getdisc
+nuts.setcomponents = direct.setcomponents
+----.setdepth = direct.setdepth
+nuts.setdir = direct.setdir
+nuts.setdirection = direct.setdirection
nuts.setdisc = direct.setdisc
+nuts.setfield = setfield
+----.setfont = direct.setfont
+----.setheight = direct.setheight
+nuts.setkern = direct.setkern
+----.setleader = direct.setleader
nuts.setlink = direct.setlink
-nuts.setsplit = direct.setsplit
-nuts.getlist = direct.getlist
nuts.setlist = direct.setlist
+nuts.setnext = direct.setnext
+nuts.setoffsets = direct.setoffsets
+nuts.setprev = direct.setprev
+nuts.setsplit = direct.setsplit
+nuts.setsubtype = direct.setsubtype
+nuts.setwidth = direct.setwidth
-nuts.getoffsets = direct.getoffsets or
- function(n)
- return getfield(n,"xoffset"), getfield(n,"yoffset")
- end
-nuts.setoffsets = direct.setoffsets or
- function(n,x,y)
- if x then setfield(n,"xoffset",x) end
- if y then setfield(n,"xoffset",y) end
- end
-
-nuts.getleader = direct.getleader or function(n) return getfield(n,"leader") end
-nuts.setleader = direct.setleader or function(n,l) setfield(n,"leader",l) end
-nuts.getcomponents = direct.getcomponents or function(n) return getfield(n,"components") end
-nuts.setcomponents = direct.setcomponents or function(n,c) setfield(n,"components",c) end
-nuts.getkern = direct.getkern or function(n) return getfield(n,"kern") end
-nuts.setkern = direct.setkern or function(n,k) setfield(n,"kern",k) end
-nuts.getdir = direct.getdir or function(n) return getfield(n,"dir") end
-nuts.setdir = direct.setdir or function(n,d) setfield(n,"dir",d) end
-nuts.getwidth = direct.getwidth or function(n) return getfield(n,"width") end
-nuts.setwidth = direct.setwidth or function(n,w) return setfield(n,"width",w) end
-nuts.getheight = direct.getheight or function(n) return getfield(n,"height") end
-nuts.setheight = direct.setheight or function(n,h) return setfield(n,"height",h) end
-nuts.getdepth = direct.getdepth or function(n) return getfield(n,"depth") end
-nuts.setdepth = direct.setdepth or function(n,d) return setfield(n,"depth",d) end
-
-if not direct.is_glyph then
- local getchar = direct.getchar
- local getid = direct.getid
- local getfont = direct.getfont
- local glyph_code = nodes.nodecodes.glyph
- function direct.is_glyph(n,f)
- local id = getid(n)
- if id == glyph_code then
- if f and getfont(n) == f then
- return getchar(n)
- else
- return false
- end
- else
- return nil, id
- end
- end
- function direct.is_char(n,f)
- local id = getid(n)
- if id == glyph_code then
- if getsubtype(n) >= 256 then
- return false
- elseif f and getfont(n) == f then
- return getchar(n)
- else
- return false
- end
- else
- return nil, id
- end
- end
-end
-
-nuts.ischar = direct.is_char
nuts.is_char = direct.is_char
-nuts.isglyph = direct.is_glyph
nuts.is_glyph = direct.is_glyph
+nuts.ischar = direct.is_char
+nuts.isglyph = direct.is_glyph
-nuts.insert_before = direct.insert_before
-nuts.insert_after = direct.insert_after
-nuts.delete = direct.delete
nuts.copy = direct.copy
-nuts.copy_node = direct.copy
nuts.copy_list = direct.copy_list
-nuts.tail = direct.tail
+nuts.copy_node = direct.copy
+nuts.delete = direct.delete
+nuts.end_of_math = direct.end_of_math
+nuts.flush = direct.flush
nuts.flush_list = direct.flush_list
nuts.flush_node = direct.flush_node
-nuts.flush = direct.flush
nuts.free = direct.free
-nuts.remove = direct.remove
+nuts.insert_after = direct.insert_after
+nuts.insert_before = direct.insert_before
nuts.is_node = direct.is_node
-nuts.end_of_math = direct.end_of_math
-nuts.traverse = direct.traverse
-nuts.traverse_id = direct.traverse_id
-nuts.traverse_char = direct.traverse_char
-nuts.ligaturing = direct.ligaturing
nuts.kerning = direct.kerning
+nuts.ligaturing = direct.ligaturing
nuts.new = direct.new
+nuts.remove = direct.remove
+nuts.tail = direct.tail
+nuts.traverse = direct.traverse
+nuts.traverse_char = direct.traverse_char
+nuts.traverse_glyph = direct.traverse_glyph
+nuts.traverse_id = direct.traverse_id
+
+-- for now
+
+if not nuts.getdirection then
+
+ local getdir = direct.getdir
+
+ function nuts.getdirection(n)
+ local d = getdir(n)
+ if d == "TLT" then return 0
+ elseif d == "TRT" then return 1
+ elseif d == "+TLT" then return 0, false
+ elseif d == "+TRT" then return 1, false
+ elseif d == "-TLT" then return 0, true
+ elseif d == "-TRT" then return 1, true
+ else return 0
+ end
+ end
-nuts.getprop = nuts.getattr
-nuts.setprop = nuts.setattr
+end
-- properties as used in the (new) injector:
local propertydata = direct.get_properties_table()
nodes.properties = { data = propertydata }
-direct.set_properties_mode(true,true) -- needed for injection
-
-function direct.set_properties_mode() end -- we really need the set modes
+if direct.set_properties_mode then
+ direct.set_properties_mode(true,true)
+ function direct.set_properties_mode() end
+end
nuts.getprop = function(n,k)
local p = propertydata[n]
@@ -342,76 +305,6 @@ local copy_node = nuts.copy_node
local glyph_code = nodes.nodecodes.glyph
-function nuts.set_components(target,start,stop)
- local head = getcomponents(target)
- if head then
- flush_list(head)
- head = nil
- end
- if start then
- setprev(start)
- else
- return nil
- end
- if stop then
- setnext(stop)
- end
- local tail = nil
- while start do
- local c = getcomponents(start)
- local n = getnext(start)
- if c then
- if head then
- setlink(tail,c)
- else
- head = c
- end
- tail = find_tail(c)
- setcomponents(start)
- flush_node(start)
- else
- if head then
- setlink(tail,start)
- else
- head = start
- end
- tail = start
- end
- start = n
- end
- setcomponents(target,head)
- -- maybe also upgrade the subtype but we don't use it anyway
- return head
-end
-
-nuts.get_components = nuts.getcomponents
-
-function nuts.take_components(target)
- local c = getcomponents(target)
- setcomponents(target)
- -- maybe also upgrade the subtype but we don't use it anyway
- return c
-end
-
-function nuts.count_components(n,marks)
- local components = getcomponents(n)
- if components then
- if marks then
- local i = 0
- for g in traverse_id(glyph_code,components) do
- if not marks[getchar(g)] then
- i = i + 1
- end
- end
- return i
- else
- return count(glyph_code,components)
- end
- else
- return 0
- end
-end
-
function nuts.copy_no_components(g,copyinjection)
local components = getcomponents(g)
if components then
@@ -449,34 +342,22 @@ end
nuts.uses_font = direct.uses_font
-if not nuts.uses_font then
- local getdisc = nuts.getdisc
- local getfont = nuts.getfont
- function nuts.uses_font(n,font)
- local pre, post, replace = getdisc(n)
- if pre then
- -- traverse_char
- for n in traverse_id(glyph_code,pre) do
- if getfont(n) == font then
- return true
- end
- end
- end
- if post then
- for n in traverse_id(glyph_code,post) do
- if getfont(n) == font then
- return true
- end
- end
- end
- if replace then
- for n in traverse_id(glyph_code,replace) do
- if getfont(n) == font then
- return true
- end
- end
- end
- return false
- end
-end
+do
+ -- another poor mans substitute ... i will move these to a more protected
+ -- namespace .. experimental hack
+
+ local dummy = tonut(node.new("glyph"))
+
+ nuts.traversers = {
+ glyph = nuts.traverse_id(nodecodes.glyph,dummy),
+ glue = nuts.traverse_id(nodecodes.glue,dummy),
+ disc = nuts.traverse_id(nodecodes.disc,dummy),
+ boundary = nuts.traverse_id(nodecodes.boundary,dummy),
+
+ char = nuts.traverse_char(dummy),
+
+ node = nuts.traverse(dummy),
+ }
+
+end