diff options
author | Taco Hoekwater <taco@elvenkind.com> | 2010-05-24 14:05:02 +0000 |
---|---|---|
committer | Taco Hoekwater <taco@elvenkind.com> | 2010-05-24 14:05:02 +0000 |
commit | 57ea7dad48fbf2541c04e434c31bde655ada3ac4 (patch) | |
tree | 1f8b43bc7cb92939271e1f5bec610710be69097f /Master/texmf-dist/tex/context/base/page-lin.lua | |
parent | 6ee41e1f1822657f7f23231ec56c0272de3855e3 (diff) |
here is context 2010.05.24 13:05
git-svn-id: svn://tug.org/texlive/trunk@18445 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/tex/context/base/page-lin.lua')
-rw-r--r-- | Master/texmf-dist/tex/context/base/page-lin.lua | 238 |
1 files changed, 103 insertions, 135 deletions
diff --git a/Master/texmf-dist/tex/context/base/page-lin.lua b/Master/texmf-dist/tex/context/base/page-lin.lua index 0efb6314e93..1f2c9625116 100644 --- a/Master/texmf-dist/tex/context/base/page-lin.lua +++ b/Master/texmf-dist/tex/context/base/page-lin.lua @@ -8,14 +8,19 @@ if not modules then modules = { } end modules ['page-lin'] = { -- experimental +local trace_numbers = false trackers.register("lines.numbers", function(v) trace_numbers = v end) + local format = string.format -local texsprint, texbox = tex.sprint, tex.box +local texsprint, texwrite, texbox = tex.sprint, tex.write, tex.box local ctxcatcodes = tex.ctxcatcodes +local variables = interfaces.variables + +nodes = nodes or { } +nodes.lines = nodes.lines or { } +nodes.lines.data = nodes.lines.data or { } -- start step tag -nodes = nodes or { } -nodes.lines = nodes.lines or { } -nodes.lines.data = nodes.lines.data or { } -- start step tag +storage.register("lines/data", nodes.lines.data, "nodes.lines.data") -- if there is demand for it, we can support multiple numbering streams -- and use more than one attibute @@ -30,27 +35,34 @@ local current_list = { } local cross_references = { } local chunksize = 250 -- not used in boxed -local has_attribute = node.has_attribute -local traverse_id = node.traverse_id -local traverse = node.traverse -local copy_node = node.copy +local has_attribute = node.has_attribute +local traverse_id = node.traverse_id +local traverse = node.traverse +local copy_node = node.copy +local hpack_node = node.hpack +local insert_node_after = node.insert_after +local insert_node_before = node.insert_before + +local whatsit = node.id("whatsit") local data = nodes.lines.data +local last = #data nodes.lines.scratchbox = nodes.lines.scratchbox or 0 -- cross referencing function nodes.lines.number(n) + n = tonumber(n) local cr = cross_references[n] or 0 cross_references[n] = nil return cr end -local function resolve(n,m) +local function resolve(n,m) -- we can now check the 'line' flag (todo) while n do local id = n.id - if id == whatsit then + if id == whatsit then -- why whatsit local a = has_attribute(n,line_reference) if a then cross_references[a] = m @@ -62,33 +74,88 @@ local function resolve(n,m) end end --- boxed variant +function nodes.lines.finalize(t) + local getnumber = nodes.lines.number + for _,p in next, t do + for _,r in next, p do + if r.metadata.kind == "line" then + local e = r.entries + local u = r.userdata + e.linenumber = getnumber(e.text or 0) -- we can nil e.text + e.conversion = u and u.conversion + r.userdata = nil -- hack + end + end + end +end + +local filters = jobreferences.filters +local helpers = structure.helpers + +jobreferences.registerfinalizer(nodes.lines.finalize) + +filters.line = filters.line or { } + +function filters.line.default(data) +-- helpers.title(data.entries.linenumber or "?",data.metadata) + texsprint(ctxcatcodes,format("\\convertnumber{%s}{%s}",data.entries.conversion or "numbers",data.entries.linenumber or "0")) +end + +function filters.line.page(data,prefixspec,pagespec) -- redundant + helpers.prefixpage(data,prefixspec,pagespec) +end + +function filters.line.linenumber(data) -- raw + texwrite(data.entries.linenumber or "0") +end + +-- boxed variant, todo: use number mechanism nodes.lines.boxed = { } +-- todo: cache setups, and free id no longer used +-- use interfaces.cachesetup(t) + function nodes.lines.boxed.register(configuration) - data[#data+1] = configuration - return #data + last = last + 1 + data[last] = configuration + if trace_numbers then + logs.report("lines","registering setup %s",last) + end + return last end + function nodes.lines.boxed.setup(n,configuration) local d = data[n] if d then - for k,v in pairs(configuration) do d[k] = v end + if trace_numbers then + logs.report("lines","updating setup %s",n) + end + for k,v in next, configuration do + d[k] = v + end else + if trace_numbers then + logs.report("lines","registering setup %s (br)",n) + end data[n] = configuration end return n end -local leftskip = nodes.leftskip +local the_left_margin = nodes.the_left_margin -local function check_number(n,a) -- move inline +local function check_number(n,a,skip) -- move inline local d = data[a] if d then - local s = d.start + local s = d.start or 1 current_list[#current_list+1] = { n, s } - if d.start % d.step == 0 then - texsprint(ctxcatcodes, format("\\makenumber{%s}{%s}{%s}{%s}{%s}\\endgraf", d.tag or "", s, n.shift, n.width, leftskip(n.list))) + if not skip and s % d.step == 0 then + local tag = d.tag or "" + texsprint(ctxcatcodes, format("\\makenumber{%s}{%s}{%s}{%s}{%s}{%s}\\endgraf",tag,s,n.shift,n.width,the_left_margin(n.list),n.dir)) + if trace_numbers then + logs.report("numbers","making number %s for setup %s: %s (%s)",#current_list,a,s,d.continue or "no") + end else texsprint(ctxcatcodes, "\\skipnumber\\endgraf") end @@ -101,24 +168,30 @@ function nodes.lines.boxed.stage_one(n) local head = texbox[n] if head then local list = head.list - --~ while list.id == vlist and not list.next do - --~ list = list.list - --~ end + local last_a, skip = nil, false for n in traverse_id(hlist,list) do -- attr test here and quit as soon as zero found if n.height == 0 and n.depth == 0 then -- skip funny hlists else local a = has_attribute(n.list,line_number) if a and a > 0 then + if last_a ~= a then + if data[a].method == variables.next then + skip = true + end + last_a = a + end if has_attribute(n,display_math) then if nodes.is_display_math(n) then - check_number(n,a) + check_number(n,a,skip) end else - if node.first_character(n.list) then - check_number(n,a) - end + -- the following test fails somehow (change in luatex?) + -- if node.first_character(n.list) then + check_number(n,a,skip) + -- end end + skip = false end end end @@ -132,116 +205,11 @@ function nodes.lines.boxed.stage_two(n,m) for l in traverse_id(hlist,texbox[m].list) do t[#t+1] = copy_node(l) end - for j=1,#current_list do - local l = current_list[j] - local n, m = l[1], l[2] - i = i + 1 - t[i].next = n.list - n.list = t[i] + for i=1,#current_list do + local li = current_list[i] + local n, m, ti = li[1], li[2], t[i] + ti.next, n.list = n.list, ti resolve(n,m) end end end - --- flow variant --- --- it's too hard to make this one robust, so for the moment it's not --- available; todo: line refs - -if false then - - nodes.lines.flowed = { } - - function nodes.lines.flowed.prepare(tag) - for i=1,#data do -- ?? - texsprint(ctxcatcodes,format("\\ctxlua{nodes.lines.flowed.prepare_a(%s)}\\ctxlua{nodes.lines.flowed.prepare_b(%s)}",i,i)) - end - end - - function nodes.lines.flowed.prepare_a(i) - local d = data[i] - local p = d.present - if p and p < chunksize then - local b = nodes.lines.scratchbox - texsprint(ctxcatcodes, format("{\\forgetall\\global\\setbox%s=\\vbox{\\unvbox%s\\relax\\offinterlineskip", b, b)) - while p < chunksize do - texsprint(ctxcatcodes, format("\\mkmaketextlinenumber{%s}{%s}\\endgraf",d.start,1)) - p = p + 1 - d.start = d.start + d.step - end - d.present = p - texsprint(ctxcatcodes, "}}") - end - end - - function nodes.lines.flowed.prepare_b(i) - local d = data[i] - local b = nodes.lines.scratchbox - local l = texbox[b] - if l then - l = l.list - local n = d.numbers - while l do - if l.id == hlist then - local m = copy_node(l) - m.next = nil - if n then - n.next = m - else - d.numbers = m - end - n = m - end - l = l.next - end - end - tex.box[b] = nil - end - - function nodes.lines.flowed.cleanup(i) - if i then - node.flush_list(data[i].numbers) - else - for i=1,#data do - node.flush_list(data[i].numbers) - end - end - end - - local function check_number(n,a) - local d = data[a] - if d then - local m = d.numbers - if m then - d.numbers = m.next - m.next = n.list - n.list = m - d.present = d.present - 1 - end - end - end - - function nodes.lines.flowed.apply(head) - for n in node.traverse(head) do - local id = n.id - if id == hlist then - if n.height == 0 and n.depth == 0 then - -- skip funny hlists - else - local a = has_attribute(n,line_number) - if a and a > 0 then - if has_attribute(n,display_math) then - if nodes.is_display_math(n) then - check_number(n,a) - end - else - check_number(n,a) - end - end - end - end - end - return head, true - end - -end |