diff options
author | Norbert Preining <preining@logic.at> | 2019-02-24 15:12:57 +0000 |
---|---|---|
committer | Norbert Preining <preining@logic.at> | 2019-02-24 15:12:57 +0000 |
commit | 1314fbe93790c501dc436a5cf99f106b9e5c0f63 (patch) | |
tree | 04dc7734c8be8ffe385d41f4388826ef5857b6f9 /Master/texmf-dist/tex/generic/context/luatex/luatex-basics-nod.lua | |
parent | eb80ce7b34f59896a1dfee5ca422495394d6677f (diff) |
Revert "ConTeXt version 2019.02.22 19:35"
This reverts commit 5c6357cdb820b4f628d036ba7b2248f221d50c0b.
git-svn-id: svn://tug.org/texlive/trunk@50112 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/tex/generic/context/luatex/luatex-basics-nod.lua')
-rw-r--r-- | Master/texmf-dist/tex/generic/context/luatex/luatex-basics-nod.lua | 317 |
1 files changed, 218 insertions, 99 deletions
diff --git a/Master/texmf-dist/tex/generic/context/luatex/luatex-basics-nod.lua b/Master/texmf-dist/tex/generic/context/luatex/luatex-basics-nod.lua index e22f170ef90..40fb9ee4ef6 100644 --- a/Master/texmf-dist/tex/generic/context/luatex/luatex-basics-nod.lua +++ b/Master/texmf-dist/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. I will move some to another namespace as I don't see other macro packages --- use the context logic. It's a subset anyway. +-- Don't depend on code here as it is only needed to complement the +-- font handler code. -- Attributes: @@ -59,11 +59,11 @@ for k, v in next, node.types() do nodecodes[k] = v nodecodes[v] = k end -for k, v in next, glyphcodes do - glyphcodes[v] = k +for i=0,#glyphcodes do + glyphcodes[glyphcodes[i]] = i end -for k, v in next, disccodes do - disccodes[v] = k +for i=0,#disccodes do + disccodes[disccodes[i]] = i end nodes.nodecodes = nodecodes @@ -74,8 +74,19 @@ local flush_node = node.flush_node local remove_node = node.remove local traverse_id = node.traverse_id -nodes.handlers.protectglyphs = node.protect_glyphs -- beware: nodes! -nodes.handlers.unprotectglyphs = node.unprotect_glyphs -- beware: nodes! +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 function nodes.remove(head, current, free_too) local t = current @@ -144,6 +155,8 @@ 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 @@ -165,104 +178,128 @@ nodes.tonut = tonut nuts.tonode = tonode nuts.tonut = tonut -nuts.getattr = direct.get_attribute -nuts.getboth = direct.getboth -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 -----.getheight = direct.getheight -nuts.getid = direct.getid -nuts.getkern = direct.getkern -----.getleader = direct.getleader -nuts.getlist = direct.getlist +local getfield = direct.getfield +local setfield = direct.setfield + +nuts.getfield = getfield +nuts.setfield = setfield nuts.getnext = direct.getnext -nuts.getoffsets = direct.getoffsets +nuts.setnext = direct.setnext nuts.getprev = direct.getprev -nuts.getsubtype = direct.getsubtype -nuts.getwidth = direct.getwidth -nuts.setattr = direct.setfield +nuts.setprev = direct.setprev +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.getfont = direct.getfont +nuts.setfont = direct.setfont +nuts.getsubtype = direct.getsubtype +nuts.setsubtype = direct.setsubtype +nuts.getchar = direct.getchar nuts.setchar = direct.setchar -nuts.setcomponents = direct.setcomponents -----.setdepth = direct.setdepth -nuts.setdir = direct.setdir -nuts.setdirection = direct.setdirection +nuts.getdisc = direct.getdisc 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.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.getlist = direct.getlist +nuts.setlist = direct.setlist + +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.is_char = direct.is_char -nuts.is_glyph = direct.is_glyph nuts.ischar = direct.is_char +nuts.is_char = direct.is_char nuts.isglyph = direct.is_glyph +nuts.is_glyph = 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_list = direct.copy_list nuts.copy_node = direct.copy -nuts.delete = direct.delete -nuts.end_of_math = direct.end_of_math -nuts.flush = direct.flush +nuts.copy_list = direct.copy_list +nuts.tail = direct.tail nuts.flush_list = direct.flush_list nuts.flush_node = direct.flush_node +nuts.flush = direct.flush nuts.free = direct.free -nuts.insert_after = direct.insert_after -nuts.insert_before = direct.insert_before -nuts.is_node = direct.is_node -nuts.kerning = direct.kerning -nuts.ligaturing = direct.ligaturing -nuts.new = direct.new nuts.remove = direct.remove -nuts.tail = direct.tail +nuts.is_node = direct.is_node +nuts.end_of_math = direct.end_of_math nuts.traverse = direct.traverse -nuts.traverse_char = direct.traverse_char -nuts.traverse_glyph = direct.traverse_glyph nuts.traverse_id = direct.traverse_id +nuts.traverse_char = direct.traverse_char +nuts.ligaturing = direct.ligaturing +nuts.kerning = direct.kerning +nuts.new = direct.new --- 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 - -end +nuts.getprop = nuts.getattr +nuts.setprop = nuts.setattr -- properties as used in the (new) injector: local propertydata = direct.get_properties_table() nodes.properties = { data = propertydata } -if direct.set_properties_mode then - direct.set_properties_mode(true,true) - function direct.set_properties_mode() end -end +direct.set_properties_mode(true,true) -- needed for injection + +function direct.set_properties_mode() end -- we really need the set modes nuts.getprop = function(n,k) local p = propertydata[n] @@ -305,6 +342,76 @@ 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 @@ -342,22 +449,34 @@ end nuts.uses_font = direct.uses_font -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), - } - +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 + |