diff options
Diffstat (limited to 'Master/texmf-dist/tex/context/base/node-pro.lua')
-rw-r--r-- | Master/texmf-dist/tex/context/base/node-pro.lua | 116 |
1 files changed, 74 insertions, 42 deletions
diff --git a/Master/texmf-dist/tex/context/base/node-pro.lua b/Master/texmf-dist/tex/context/base/node-pro.lua index 60f2d8a720e..2cc00601c77 100644 --- a/Master/texmf-dist/tex/context/base/node-pro.lua +++ b/Master/texmf-dist/tex/context/base/node-pro.lua @@ -13,15 +13,15 @@ local trace_callbacks = false trackers.register("nodes.callbacks", function(v) local report_nodes = logs.reporter("nodes","processors") -local nodes, node = nodes, node +local nodes = nodes local nodecodes = nodes.nodecodes local glyph_code = nodecodes.glyph local tasks = nodes.tasks +local nuts = nodes.nuts -local free_node = node.free -local first_glyph = node.first_glyph or node.first_character -local has_attribute = node.has_attribute +local first_glyph = nodes.first_glyph +local has_glyph = nodes.has_glyph nodes.processors = nodes.processors or { } local processors = nodes.processors @@ -31,47 +31,57 @@ local processors = nodes.processors local actions = tasks.actions("processors") -local n = 0 +do -local function reconstruct(head) -- we probably have a better one - local t, n, h = { }, 0, head - while h do + local tonut = nuts.tonut + local getid = nuts.getid + local getchar = nuts.getchar + local getnext = nuts.getnext + + local n = 0 + + local function reconstruct(head) -- we probably have a better one + local t, n, h = { }, 0, tonut(head) + while h do + n = n + 1 + local id = getid(h) + if id == glyph_code then -- todo: disc etc + t[n] = utfchar(getchar(h)) + else + t[n] = "[]" + end + h = getnext(h) + end + return concat(t) + end + + local function tracer(what,state,head,groupcode,before,after,show) + if not groupcode then + groupcode = "unknown" + elseif groupcode == "" then + groupcode = "mvl" + end n = n + 1 - local id = h.id - if id == glyph_code then -- todo: disc etc - t[n] = utfchar(h.char) + if show then + report_nodes("%s: location %a, state %a, group %a, # before %a, # after %s, stream: %s",what,n,state,groupcode,before,after,reconstruct(head)) else - t[n] = "[]" + report_nodes("%s: location %a, state %a, group %a, # before %a, # after %s",what,n,state,groupcode,before,after) end - h = h.next end - return concat(t) -end -local function tracer(what,state,head,groupcode,before,after,show) - if not groupcode then - groupcode = "unknown" - elseif groupcode == "" then - groupcode = "mvl" - end - n = n + 1 - if show then - report_nodes("%s: location %a, state %a, group %a, # before %a, # after %s, stream: %s",what,n,state,groupcode,before,after,reconstruct(head)) - else - report_nodes("%s: location %a, state %a, group %a, # before %a, # after %s",what,n,state,groupcode,before,after) - end -end + processors.tracer = tracer -processors.tracer = tracer +end processors.enabled = true -- this will become a proper state (like trackers) -function processors.pre_linebreak_filter(head,groupcode,size,packtype,direction) - local first, found = first_glyph(head) -- they really need to be glyphs +function processors.pre_linebreak_filter(head,groupcode) -- ,size,packtype,direction + -- local first, found = first_glyph(head) -- they really need to be glyphs + local found = has_glyph(head) if found then if trace_callbacks then local before = nodes.count(head,true) - local head, done = actions(head,groupcode,size,packtype,direction) -- todo : pass first + local head, done = actions(head,groupcode) -- ,size,packtype,direction local after = nodes.count(head,true) if done then tracer("pre_linebreak","changed",head,groupcode,before,after,true) @@ -80,7 +90,7 @@ function processors.pre_linebreak_filter(head,groupcode,size,packtype,direction) end return done and head or true else - local head, done = actions(head,groupcode,size,packtype,direction) -- todo : pass first + local head, done = actions(head,groupcode) -- ,size,packtype,direction return done and head or true end elseif trace_callbacks then @@ -94,7 +104,8 @@ local enabled = true function processors.hpack_filter(head,groupcode,size,packtype,direction) if enabled then - local first, found = first_glyph(head) -- they really need to be glyphs + -- local first, found = first_glyph(head) -- they really need to be glyphs + local found = has_glyph(head) if found then if trace_callbacks then local before = nodes.count(head,true) @@ -118,15 +129,36 @@ function processors.hpack_filter(head,groupcode,size,packtype,direction) return true end -local hpack = node.hpack +do + + local setfield = nodes.setfield + local hpack = nodes.hpack + + function nodes.fasthpack(...) -- todo: pass explicit arguments + enabled = false + local hp, b = hpack(...) + setfield(hp,"prev",nil) + setfield(hp,"next",nil) + enabled = true + return hp, b + end + +end + +do + + local setfield = nuts.setfield + local hpack = nuts.hpack + + function nuts.fasthpack(...) -- todo: pass explicit arguments + enabled = false + local hp, b = hpack(...) + setfield(hp,"prev",nil) + setfield(hp,"next",nil) + enabled = true + return hp, b + end -function nodes.fasthpack(...) -- todo: pass explicit arguments - enabled = false - local hp, b = hpack(...) - hp.prev = nil - hp.next = nil - enabled = true - return hp, b end callbacks.register('pre_linebreak_filter', processors.pre_linebreak_filter, "all kind of horizontal manipulations (before par break)") |