summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/context/base/lpdf-ren.lua
diff options
context:
space:
mode:
Diffstat (limited to 'Master/texmf-dist/tex/context/base/lpdf-ren.lua')
-rw-r--r--Master/texmf-dist/tex/context/base/lpdf-ren.lua122
1 files changed, 87 insertions, 35 deletions
diff --git a/Master/texmf-dist/tex/context/base/lpdf-ren.lua b/Master/texmf-dist/tex/context/base/lpdf-ren.lua
index 54c78845ed4..e0c4b19731a 100644
--- a/Master/texmf-dist/tex/context/base/lpdf-ren.lua
+++ b/Master/texmf-dist/tex/context/base/lpdf-ren.lua
@@ -12,7 +12,7 @@ local tostring, tonumber, next = tostring, tonumber, next
local format = string.format
local settings_to_array = utilities.parsers.settings_to_array
-local backends, lpdf = backends, lpdf
+local backends, lpdf, nodes, node = backends, lpdf, nodes, node
local nodeinjections = backends.pdf.nodeinjections
local codeinjections = backends.pdf.codeinjections
@@ -41,6 +41,10 @@ local pdfreference = lpdf.reference
local pdfflushobject = lpdf.flushobject
local pdfreserveobject = lpdf.reserveobject
+local nodepool = nodes.pool
+local register = nodepool.register
+local pdfliteral = nodepool.pdfliteral
+
local pdf_ocg = pdfconstant("OCG")
local pdf_ocmd = pdfconstant("OCMD")
local pdf_off = pdfconstant("OFF")
@@ -48,12 +52,56 @@ local pdf_on = pdfconstant("ON")
local pdf_toggle = pdfconstant("Toggle")
local pdf_setocgstate = pdfconstant("SetOCGState")
+local copy_node = node.copy
+
local lpdf_usage = pdfdictionary { Print = pdfdictionary { PrintState = pdf_off } }
-- We can have references to layers before they are places, for instance from
-- hide and vide actions. This is why we need to be able to force usage of layers
-- at several moments.
+-- injection
+
+local cache = { }
+
+function codeinjections.startlayer(name)
+ codeinjections.useviewerlayer(name)
+ return format("/OC /%s BDC",name)
+end
+
+function codeinjections.stoplayer(name)
+ return "EMC"
+end
+
+function nodeinjections.startlayer(name)
+ local c = cache[name]
+ if not c then
+ codeinjections.useviewerlayer(name)
+ c = register(pdfliteral(format("/OC /%s BDC",name)))
+ cache[name] = c
+ end
+ return copy_node(c)
+end
+
+local stop = register(pdfliteral("EMC"))
+
+function nodeinjections.stoplayer()
+ return copy_node(stop)
+end
+
+local cache = { }
+
+function nodeinjections.switchlayer(name) -- not used, optimization
+ local c = cache[name]
+ if not c then
+ codeinjections.useviewerlayer(name)
+ c = register(pdfliteral(format("EMC /OC /%s BDC",name)))
+ end
+ return copy_node(c)
+end
+
+-- management
+
local pdfln, pdfld = { }, { }
local textlayers, hidelayers, videlayers = pdfarray(), pdfarray(), pdfarray()
local pagelayers, pagelayersreference, cache = nil, nil, { }
@@ -70,42 +118,46 @@ function codeinjections.defineviewerlayer(specification)
end
end
-local function useviewerlayer(name)
- local specification = specifications[name]
- if not environment.initex and specification and not initialized[name] then
- specifications[name] = nil -- or not
- initialized [name] = true
- if not pagelayers then
- pagelayers = pdfdictionary()
- pagelayersreference = pdfreserveobject()
- end
- local tag = specification.tag
- -- todo: reserve
- local nn = pdfreserveobject()
- local nr = pdfreference(nn)
- local nd = pdfdictionary {
- Type = pdf_ocg,
- Name = specification.title or "unknown",
- Intent = ((specification.editable ~= v_no) and pdf_design) or nil, -- disable layer hiding by user
- Usage = ((specification.printable == v_no) and lpdf_usage) or nil, -- printable or not
- }
- cache[#cache+1] = { nn, nd }
- pdfln[tag] = nr -- was n
- local dn = pdfreserveobject()
- local dr = pdfreference(dn)
- local dd = pdfdictionary {
- Type = pdf_ocmd,
- OCGs = pdfarray { nr },
- }
- cache[#cache+1] = { dn, dd }
- pdfld[tag] = dr
- textlayers[#textlayers+1] = nr
- if specification.visible == v_start then
- videlayers[#videlayers+1] = nr
+local function useviewerlayer(name) -- move up so that we can use it as local
+ if not environment.initex and not initialized[name] then
+ local specification = specifications[name]
+ if specification then
+ specifications[name] = nil -- or not
+ initialized [name] = true
+ if not pagelayers then
+ pagelayers = pdfdictionary()
+ pagelayersreference = pdfreserveobject()
+ end
+ local tag = specification.tag
+ -- todo: reserve
+ local nn = pdfreserveobject()
+ local nr = pdfreference(nn)
+ local nd = pdfdictionary {
+ Type = pdf_ocg,
+ Name = specification.title or "unknown",
+ Intent = ((specification.editable ~= v_no) and pdf_design) or nil, -- disable layer hiding by user
+ Usage = ((specification.printable == v_no) and lpdf_usage) or nil, -- printable or not
+ }
+ cache[#cache+1] = { nn, nd }
+ pdfln[tag] = nr -- was n
+ local dn = pdfreserveobject()
+ local dr = pdfreference(dn)
+ local dd = pdfdictionary {
+ Type = pdf_ocmd,
+ OCGs = pdfarray { nr },
+ }
+ cache[#cache+1] = { dn, dd }
+ pdfld[tag] = dr
+ textlayers[#textlayers+1] = nr
+ if specification.visible == v_start then
+ videlayers[#videlayers+1] = nr
+ else
+ hidelayers[#hidelayers+1] = nr
+ end
+ pagelayers[tag] = dr -- check
else
- hidelayers[#hidelayers+1] = nr
+ -- todo: message
end
- pagelayers[tag] = dr -- check
end
end