diff options
Diffstat (limited to 'Master/texmf-dist/tex/context/base/lpdf-ano.lua')
-rw-r--r-- | Master/texmf-dist/tex/context/base/lpdf-ano.lua | 140 |
1 files changed, 78 insertions, 62 deletions
diff --git a/Master/texmf-dist/tex/context/base/lpdf-ano.lua b/Master/texmf-dist/tex/context/base/lpdf-ano.lua index 87014365b39..e9e67e16319 100644 --- a/Master/texmf-dist/tex/context/base/lpdf-ano.lua +++ b/Master/texmf-dist/tex/context/base/lpdf-ano.lua @@ -1,6 +1,6 @@ if not modules then modules = { } end modules ['lpdf-ano'] = { version = 1.001, - comment = "companion to lpdf-ini.tex", + comment = "companion to lpdf-ini.mkiv", author = "Hans Hagen, PRAGMA-ADE, Hasselt NL", copyright = "PRAGMA ADE / ConTeXt Development Team", license = "see context related readme files" @@ -31,18 +31,17 @@ local specials = jobreferences.specials local handlers = jobreferences.handlers local executers = jobreferences.executers -local pdfdictionary = lpdf.dictionary -local pdfarray = lpdf.array -local pdfreference = lpdf.reference -local pdfunicode = lpdf.unicode -local pdfconstant = lpdf.constant +local pdfdictionary = lpdf.dictionary +local pdfarray = lpdf.array +local pdfreference = lpdf.reference +local pdfunicode = lpdf.unicode +local pdfconstant = lpdf.constant +local pdfflushobject = lpdf.flushobject +local pdfreserveobject = lpdf.reserveobject +local pdfannotation = nodes.pdfannotation +local pdfdestination = nodes.pdfdestination -local pdfreserveobj = pdf.reserveobj -local pdfimmediateobj = pdf.immediateobj -local pdfpageref = tex.pdfpageref - -local pdfannot = nodes.pdfannot -local pdfdest = nodes.pdfdest +local pdfpagereference = tex.pdfpageref local pdf_uri = pdfconstant("URI") local pdf_gotor = pdfconstant("GoToR") @@ -60,10 +59,10 @@ local function pagedest(n) local pd = cache[n] if not pd then local a = pdfarray { - pdfreference(pdfpageref(n)), + pdfreference(pdfpagereference(n)), pdfconstant("Fit") } - pd = pdfreference(pdfimmediateobj(tostring(a))) + pd = pdfreference(pdfflushobject(a)) cache[n] = pd end return pd @@ -71,6 +70,8 @@ end lpdf.pagedest = pagedest +local defaultdestination = pdfarray { 0, pdfconstant("Fit") } + local function link(url,filename,destination,page,actions) if filename and filename ~= "" then if file.basename(filename) == tex.jobname then @@ -93,9 +94,9 @@ local function link(url,filename,destination,page,actions) } elseif filename and filename ~= "" then return pdfdictionary { - S = pdf_gotor, + S = pdf_gotor, -- can also be pdf_launch F = filename, - D = destination and destination ~= "" and destination, + D = (destination and destination ~= "" and destination), -- or defaultdestination, NewWindow = (actions.newwindow and true) or nil, } elseif destination and destination ~= "" then @@ -221,7 +222,7 @@ end -- } -- local cm = cache[main] -- if not cm then --- cm = "/A ".. tostring(pdfreference(pdfimmediateobj(tostring(main)))) +-- cm = "/A ".. tostring(pdfreference(pdfflushobject(main)) -- cache[main] = cm -- end -- return cm @@ -236,7 +237,7 @@ function nodeinjections.reference(width,height,depth,prerolled) if trace_references then logs.report("references","w=%s, h=%s, d=%s, a=%s",width,height,depth,prerolled) end - return pdfannot(width,height,depth,prerolled) + return pdfannotation(width,height,depth,prerolled) end end @@ -247,7 +248,7 @@ function nodeinjections.destination(width,height,depth,name,view) if trace_destinations then logs.report("destinations","w=%s, h=%s, d=%s, n=%s, v=%s",width,height,depth,name,view or "no view") end - return pdfdest(width,height,depth,name,view) + return pdfdestination(width,height,depth,name,view) end -- runners and specials @@ -266,23 +267,27 @@ runners["inner"] = function(var,actions) end runners["inner with arguments"] = function(var,actions) + logs.report("references","todo: inner with arguments") return false end runners["outer"] = function(var,actions) - return link(nil,var.o,nil,nil,actions) -- var.o ? + local file, url = jobreferences.checkedfileorurl(var.outer,var.outer) + return link(url,file,var.arguments,nil,actions) end runners["outer with inner"] = function(var,actions) - -- todo: resolve url/file name - return link(nil,var.f,var.inner,var.r,actions) + local file = jobreferences.checkedfile(var.f) + return link(nil,file,var.inner,var.r,actions) end runners["special outer with operation"] = function(var,actions) - return false + local handler = specials[var.special] + return handler and handler(var,actions) end runners["special outer"] = function(var,actions) + logs.report("references","todo: special outer") return false end @@ -292,25 +297,29 @@ runners["special"] = function(var,actions) end runners["outer with inner with arguments"] = function(var,actions) + logs.report("references","todo: outer with inner with arguments") return false end runners["outer with special and operation and arguments"] = function(var,actions) + logs.report("references","todo: outer with special and operation and arguments") return false end runners["outer with special"] = function(var,actions) + logs.report("references","todo: outer with special") return false end runners["outer with special and operation"] = function(var,actions) + logs.report("references","todo: outer with special and operation") return false end runners["special operation"] = runners["special"] runners["special operation with arguments"] = runners["special"] -function specials.internal(var,actions) +function specials.internal(var,actions) -- better resolve in strc-ref local i = tonumber(var.operation) local v = jobreferences.internals[i] if not v then @@ -326,49 +335,56 @@ end specials.i = specials.internal -function specials.page(var,actions) - local p = jobreferences.pages[var.operation] - if type(p) == "function" then - p = p() +function specials.page(var,actions) -- better resolve in strc-ref + local file = var.f + if file then + file = jobreferences.checkedfile(file) + return link(nil,file,nil,p or var.operation,actions) + else + local p = jobreferences.pages[var.operation] + if type(p) == "function" then + p = p() + end + return link(nil,nil,nil,p or var.operation,actions) end - return link(nil,nil,nil,p or var.operation,actions) end -function specials.url(var,actions) - local url = var.operation - if url then - local u = jobreferences.urls[url] - if u then - local u, f = u[1], u[2] - if f and f ~= "" then - url = u .. "/" .. f - else - url = u - end +-- todo, do this in references namespace ordered instead (this is an experiment) + +local splitter = lpeg.splitat(":") + +function specials.order(var,actions) -- jobreferences.specials ! + local operation = var.operation + if operation then + local kind, name, n = lpegmatch(splitter,operation) + local order = lists.ordered[kind] + order = order and order[name] + local v = order[tonumber(n)] + local r = v and v.references.realpage + if r then + var.operation = r -- brrr, but test anyway + return specials.page(var,actions) end end +end + +function specials.url(var,actions) + local url = jobreferences.checkedurl(var.operation) return link(url,nil,var.arguments,nil,actions) end function specials.file(var,actions) - local file = var.operation - if file then - local f = jobreferences.files[file] - if f then - file = f[1] or file - end - end + local file = jobreferences.checkedfile(var.operation) return link(nil,file,var.arguments,nil,actions) end +function specials.fileorurl(var,actions) + local file, url = jobreferences.checkedfileorurl(var.operation,var.operation) + return link(url,file,var.arguments,nil,actions) +end + function specials.program(var,content) - local program = var.operation - if program then - local p = jobreferences.programs[program] - if p then - program = p[1] - end - end + local program = jobreferences.checkedprogram(var.operation) return lpdf.launch(program,var.arguments) end @@ -512,13 +528,13 @@ local function build(levels,start,parent,method) local level, title, reference, open = li[1], li[2], li[3], li[4] if level == startlevel then if trace_bookmarks then - logs.report("bookmark","%3i %s%s %s",realpage,rep(" ",level-1),(open and "+") or "-",title) + logs.report("bookmark","%3i %s%s %s",reference.realpage,rep(" ",level-1),(open and "+") or "-",title) end local prev = child - child = pdfreserveobj() + child = pdfreserveobject() if entry then entry.Next = child and pdfreference(child) - pdfimmediateobj(prev,tostring(entry)) + pdfflushobject(prev,entry) end entry = pdfdictionary { Title = pdfunicode(title), @@ -536,7 +552,7 @@ local function build(levels,start,parent,method) n = n + 1 i = i + 1 elseif level < startlevel then - pdfimmediateobj(child,tostring(entry)) + pdfflushobject(child,entry) return i, n, first, last elseif i < #levels and level > startlevel then i, m, f, l = build(levels,i,pdfreference(child),method) @@ -551,16 +567,16 @@ local function build(levels,start,parent,method) if m > 0 then entry.First, entry.Last = pdfreference(f), pdfreference(l) end - pdfimmediateobj(child,tostring(entry)) + pdfflushobject(child,entry) return i, n, first, last end end - pdfimmediateobj(child,tostring(entry)) + pdfflushobject(child,entry) return nil, n, first, last end function codeinjections.addbookmarks(levels,method) - local parent = pdfreserveobj() + local parent = pdfreserveobject() local _, m, first, last = build(levels,1,pdfreference(parent),method or "internal") local dict = pdfdictionary { Type = pdfconstant("Outlines"), @@ -568,6 +584,6 @@ function codeinjections.addbookmarks(levels,method) Last = pdfreference(last), Count = m, } - pdfimmediateobj(parent,tostring(dict)) + pdfflushobject(parent,dict) lpdf.addtocatalog("Outlines",lpdf.reference(parent)) end |