diff options
author | Hans Hagen <pragma@wxs.nl> | 2009-05-28 11:23:00 +0200 |
---|---|---|
committer | Hans Hagen <pragma@wxs.nl> | 2009-05-28 11:23:00 +0200 |
commit | 1d3090326210c6e6f7ec5432799ded25b75bba46 (patch) | |
tree | c5921203789ec669e6bccaba4bd56f9c072dc56b /tex/context/base/page-lin.lua | |
parent | 94d83f84758766511c5e324721e39fea6ab71dae (diff) | |
download | context-1d3090326210c6e6f7ec5432799ded25b75bba46.tar.gz |
beta 2009.05.28 11:23
Diffstat (limited to 'tex/context/base/page-lin.lua')
-rw-r--r-- | tex/context/base/page-lin.lua | 299 |
1 files changed, 155 insertions, 144 deletions
diff --git a/tex/context/base/page-lin.lua b/tex/context/base/page-lin.lua index a8d868f36..0efb6314e 100644 --- a/tex/context/base/page-lin.lua +++ b/tex/context/base/page-lin.lua @@ -8,95 +8,103 @@ if not modules then modules = { } end modules ['page-lin'] = { -- experimental +local format = string.format +local texsprint, texbox = tex.sprint, tex.box + +local ctxcatcodes = tex.ctxcatcodes + nodes = nodes or { } nodes.lines = nodes.lines or { } nodes.lines.data = nodes.lines.data or { } -- start step tag -do - - -- if there is demand for it, we can support multiple numbering streams - -- and use more than one attibute +-- if there is demand for it, we can support multiple numbering streams +-- and use more than one attibute - local hlist, vlist, whatsit = node.id('hlist'), node.id('vlist'), node.id('whatsit') +local hlist, vlist, whatsit = node.id('hlist'), node.id('vlist'), node.id('whatsit') - local display_math = attributes.numbers['display-math'] or 121 - local line_number = attributes.numbers['line-number'] or 131 - local line_reference = attributes.numbers['line-reference'] or 132 +local display_math = attributes.private('display-math') +local line_number = attributes.private('line-number') +local line_reference = attributes.private('line-reference') - local current_list = { } - local cross_references = { } - local chunksize = 250 -- not used in boxed +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 copy = node.copy - local format = string.format - local sprint = tex.sprint +local has_attribute = node.has_attribute +local traverse_id = node.traverse_id +local traverse = node.traverse +local copy_node = node.copy - local data = nodes.lines.data +local data = nodes.lines.data - nodes.lines.scratchbox = nodes.lines.scratchbox or 0 +nodes.lines.scratchbox = nodes.lines.scratchbox or 0 - -- cross referencing +-- cross referencing - function nodes.lines.number(n) - local cr = cross_references[n] or 0 - cross_references[n] = nil - return cr - end +function nodes.lines.number(n) + local cr = cross_references[n] or 0 + cross_references[n] = nil + return cr +end - local function resolve(n,m) - while n do - local id = n.id - if id == whatsit then - local a = has_attribute(n,line_reference) - if a then - cross_references[a] = m - end - elseif id == hlist or id == vlist then - resolve(n.list,m) +local function resolve(n,m) + while n do + local id = n.id + if id == whatsit then + local a = has_attribute(n,line_reference) + if a then + cross_references[a] = m end - n = n.next + elseif id == hlist or id == vlist then + resolve(n.list,m) end + n = n.next end +end - -- boxed variant +-- boxed variant - nodes.lines.boxed = { } +nodes.lines.boxed = { } - function nodes.lines.boxed.register(configuration) - data[#data+1] = configuration - return #data +function nodes.lines.boxed.register(configuration) + data[#data+1] = configuration + return #data +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 + else + data[n] = configuration 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 + return n +end + +local leftskip = nodes.leftskip + +local function check_number(n,a) -- move inline + local d = data[a] + if d then + local s = d.start + 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))) else - data[n] = configuration + texsprint(ctxcatcodes, "\\skipnumber\\endgraf") end - return n + d.start = s + 1 -- (d.step or 1) end +end - local leftskip = nodes.leftskip - - function nodes.lines.boxed.stage_one(n) - current_list = { } - local head = tex.box[n].list - local function check_number(n,a) -- move inline - local d = data[a] - if d then - local s = d.start - current_list[#current_list+1] = { n, s } - if d.start % d.step == 0 then - sprint(tex.ctxcatcodes, format("\\makenumber{%s}{%s}{%s}{%s}{%s}\\endgraf", d.tag or "", s, n.shift, n.width, leftskip(n.list))) - else - sprint(tex.ctxcatcodes, "\\skipnumber\\endgraf") - end - d.start = s + 1 -- (d.step or 1) - end - end - for n in traverse_id(hlist,head) do -- attr test here and quit as soon as zero found +function nodes.lines.boxed.stage_one(n) + current_list = { } + local head = texbox[n] + if head then + local list = head.list + --~ while list.id == vlist and not list.next do + --~ list = list.list + --~ end + 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 @@ -115,14 +123,17 @@ do end end end +end - function nodes.lines.boxed.stage_two(n,m) +function nodes.lines.boxed.stage_two(n,m) + if #current_list > 0 then m = m or nodes.lines.scratchbox local t, i = { }, 0 - for l in traverse_id(hlist,tex.box[m].list) do - t[#t+1] = copy(l) + for l in traverse_id(hlist,texbox[m].list) do + t[#t+1] = copy_node(l) end - for _, l in ipairs(current_list) do + 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 @@ -130,107 +141,107 @@ do 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 +-- 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 +if false then - nodes.lines.flowed = { } + nodes.lines.flowed = { } - function nodes.lines.flowed.prepare() - for i=1,#data do - sprint(tex.ctxcatcodes,format("\\ctxlua{nodes.lines.flowed.prepare_a(%s)}\\ctxlua{nodes.lines.flowed.prepare_b(%s)}",i, i)) - end + 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 < chunksize then - local b = nodes.lines.scratchbox - sprint(tex.ctxcatcodes, format("{\\forgetall\\global\\setbox%s=\\vbox{\\unvbox%s\\relax\\offinterlineskip", b, b)) - while p < chunksize do - sprint(tex.ctxcatcodes, format("\\mkmaketextlinenumber{%s}{%s}\\endgraf",d.start,1)) - p = p + 1 - d.start = d.start + d.step - end - d.present = p - sprint(tex.ctxcatcodes, "}}") + 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 = tex.box[b] - if l then - l = l.list - local n = d.numbers - while l do - if l.id == hlist then - local m = node.copy(l) - m.next = nil - if n then - n.next = m - else - d.numbers = m - end - n = m + 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 - l = l.next + n = m end + l = l.next end - tex.box[b] = nil end + tex.box[b] = nil + end - function nodes.lines.flowed.cleanup(i) - if i then + 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) - else - for i=1,#data do - node.flush_list(data[i].numbers) - end end end + end - function nodes.lines.flowed.apply(head) - 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 + 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 - 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 + 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 - return head, true end - + return head, true end end |