diff options
author | Marius <mariausol@gmail.com> | 2014-01-07 15:20:21 +0200 |
---|---|---|
committer | Marius <mariausol@gmail.com> | 2014-01-07 15:20:21 +0200 |
commit | ff54944f72aa8a402a330a82e847c9c19fba5f24 (patch) | |
tree | 961dc9e94862dbc1f3cbc98d55f81b66b7c8bda4 /tex/context/base/node-acc.lua | |
parent | 9e10531d96003139dbb12ef6c59f9b9827a65121 (diff) | |
download | context-ff54944f72aa8a402a330a82e847c9c19fba5f24.tar.gz |
beta 2014.01.07 14:00
Diffstat (limited to 'tex/context/base/node-acc.lua')
-rw-r--r-- | tex/context/base/node-acc.lua | 114 |
1 files changed, 73 insertions, 41 deletions
diff --git a/tex/context/base/node-acc.lua b/tex/context/base/node-acc.lua index 81ae496b2..6a1b986bc 100644 --- a/tex/context/base/node-acc.lua +++ b/tex/context/base/node-acc.lua @@ -11,10 +11,25 @@ local nodes, node = nodes, node local nodecodes = nodes.nodecodes local tasks = nodes.tasks -local traverse_nodes = node.traverse -local traverse_id = node.traverse_id -local copy_node = node.copy -local free_nodelist = node.flush_list +local nuts = nodes.nuts +local tonut = nodes.tonut +local tonode = nodes.tonode + +local getid = nuts.getid +local getfield = nuts.getfield +local getattr = nuts.getattr +local getlist = nuts.getlist +local getchar = nuts.getchar +local getnext = nuts.getnext + +local setfield = nuts.setfield +local setattr = nuts.setattr + +local traverse_nodes = nuts.traverse +local traverse_id = nuts.traverse_id +local copy_node = nuts.copy +local free_nodelist = nuts.flush_list +local insert_after = nuts.insert_after local glue_code = nodecodes.glue local kern_code = nodecodes.kern @@ -29,57 +44,68 @@ local threshold = 65536 -- todo: nbsp etc -- todo: collapse kerns +-- p_id + local function injectspaces(head) - local p + local p, p_id local n = head while n do - local id = n.id + local id = getid(n) if id == glue_code then -- todo: check for subtype related to spacing (13/14 but most seems to be 0) - -- if n.spec.width > 0 then -- threshold - if p and p.id == glyph_code then + -- if getfield(getfield(n,"spec"),"width") > 0 then -- threshold + if p and p_id == glyph_code then local g = copy_node(p) - local c = g.components + local c = getfield(g,"components") if c then -- it happens that we copied a ligature free_nodelist(c) - g.components = nil - g.subtype = 256 + setfield(g,"components",nil) + setfield(g,"subtype",256) end - local a = n[a_characters] - local s = copy_node(n.spec) - g.char, n.spec = 32, s - p.next, g.prev = g, p - g.next, n.prev = n, g - s.width = s.width - g.width + -- p .. g + local a = getattr(n,a_characters) + local s = copy_node(getfield(n,"spec")) + setfield(g,"char",32) + insert_after(p,p,g) + -- setfield(p,"next",g) + -- setfield(g,"prev",p) + -- setfield(g,"next",n) + -- setfield(n,"prev",g) + setfield(n,"spec",s) + setfield(s,"width",getfield(s,"width") - getfield(g,"width")) if a then - g[a_characters] = a + setattr(g,a_characters,a) end - s[a_characters] = 0 - n[a_characters] = 0 + setattr(s,a_characters,0) + setattr(n,a_characters,0) end -- end elseif id == hlist_code or id == vlist_code then - injectspaces(n.list,attribute) + injectspaces(getlist(n),attribute) -- elseif id == kern_code then -- the backend already collapses -- local first = n -- while true do - -- local nn = n.next - -- if nn and nn.id == kern_code then + -- local nn = getnext(n) + -- if nn and getid(nn) == kern_code then -- -- maybe we should delete kerns but who cares at this stage - -- first.kern = first.kern + nn.kern - -- nn.kern = 0 + -- setfield(first,"kern",getfield(first,"kern") + getfield(nn,"kern") + -- setfield(nn,"kern",0) -- n = nn -- else -- break -- end -- end end + p_id = id p = n - n = n.next + n = getnext(n) end - return head, true + return head, true -- always done anyway end -nodes.handlers.accessibility = injectspaces +nodes.handlers.accessibility = function(head) + local head, done = injectspaces(tonut(head)) + return tonode(head), done +end -- todo: @@ -90,16 +116,18 @@ nodes.handlers.accessibility = injectspaces -- local function compact(n) -- local t = { } -- for n in traverse_id(glyph_code,n) do --- t[#t+1] = utfchar(n.char) -- check for unicode +-- t[#t+1] = utfchar(getchar(n)) -- check for unicode -- end -- return concat(t,"") -- end -- -- local function injectspans(head) --- for n in traverse_nodes(head) do --- local id = n.id +-- local done = false +-- for n in traverse_nodes(tonuts(head)) do +-- local id = getid(n) -- if id == disc then --- local r, p = n.replace, n.pre +-- local r = getfield(n,"replace") +-- local p = getfield(n,"pre") -- if r and p then -- local str = compact(r) -- local hsh = hyphenated[str] @@ -108,13 +136,14 @@ nodes.handlers.accessibility = injectspaces -- hyphenated[str] = hsh -- codes[hsh] = str -- end --- n[a_hyphenated] = hsh +-- setattr(n,a_hyphenated,hsh) +-- done = true -- end -- elseif id == hlist_code or id == vlist_code then --- injectspans(n.list) +-- injectspans(getlist(n)) -- end -- end --- return head, true +-- return tonodes(head), done -- end -- -- nodes.injectspans = injectspans @@ -122,19 +151,22 @@ nodes.handlers.accessibility = injectspaces -- tasks.appendaction("processors", "words", "nodes.injectspans") -- -- local function injectspans(head) --- for n in traverse_nodes(head) do --- local id = n.id +-- local done = false +-- for n in traverse_nodes(tonut(head)) do +-- local id = getid(n) -- if id == disc then --- local a = n[a_hyphenated] +-- local a = getattr(n,a_hyphenated) -- if a then -- local str = codes[a] -- local b = new_pdfliteral(format("/Span << /ActualText %s >> BDC", lpdf.tosixteen(str))) -- local e = new_pdfliteral("EMC") --- node.insert_before(head,n,b) --- node.insert_after(head,n,e) +-- insert_before(head,n,b) +-- insert_after(head,n,e) +-- done = true -- end -- elseif id == hlist_code or id == vlist_code then --- injectspans(n.list) +-- injectspans(getlist(n)) -- end -- end +-- return tonodes(head), done -- end |