summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/context/base/lpdf-mis.lua
diff options
context:
space:
mode:
Diffstat (limited to 'Master/texmf-dist/tex/context/base/lpdf-mis.lua')
-rw-r--r--Master/texmf-dist/tex/context/base/lpdf-mis.lua156
1 files changed, 113 insertions, 43 deletions
diff --git a/Master/texmf-dist/tex/context/base/lpdf-mis.lua b/Master/texmf-dist/tex/context/base/lpdf-mis.lua
index a68c7b4873d..426c00286a9 100644
--- a/Master/texmf-dist/tex/context/base/lpdf-mis.lua
+++ b/Master/texmf-dist/tex/context/base/lpdf-mis.lua
@@ -17,8 +17,9 @@ if not modules then modules = { } end modules ['lpdf-mis'] = {
local next, tostring = next, tostring
local format = string.format
-local texsprint, texset = tex.sprint, tex.set
-local ctxcatcodes = tex.ctxcatcodes
+local texset = tex.set
+
+local backends, lpdf, nodes = backends, lpdf, nodes
local nodeinjections = backends.pdf.nodeinjections
local codeinjections = backends.pdf.codeinjections
@@ -26,22 +27,22 @@ local registrations = backends.pdf.registrations
local copy_node = node.copy
-local pdfliteral, register = nodes.pdfliteral, nodes.register
+local nodepool = nodes.pool
-local pdfdictionary = lpdf.dictionary
-local pdfarray = lpdf.array
-local pdfboolean = lpdf.boolean
-local pdfconstant = lpdf.constant
-local pdfreference = lpdf.reference
-local pdfunicode = lpdf.unicode
-local pdfverbose = lpdf.verbose
-local pdfstring = lpdf.string
-local pdfflushobject = lpdf.flushobject
+local pdfliteral, register = nodepool.pdfliteral, nodepool.register
-local pdfimmediateobj = pdf.immediateobj
+local pdfdictionary = lpdf.dictionary
+local pdfarray = lpdf.array
+local pdfboolean = lpdf.boolean
+local pdfconstant = lpdf.constant
+local pdfreference = lpdf.reference
+local pdfunicode = lpdf.unicode
+local pdfverbose = lpdf.verbose
+local pdfstring = lpdf.string
+local pdfflushobject = lpdf.flushobject
+local pdfimmediateobject = lpdf.immediateobject
-local tobasepoints = number.tobasepoints
-local variables = interfaces.variables
+local variables = interfaces.variables
--
@@ -58,7 +59,7 @@ local function initializenegative()
Range = a,
Domain = a,
}
- local negative = pdfdictionary { Type = g, TR = pdfreference(pdf.immediateobj("stream","1 exch sub",d())) }
+ local negative = pdfdictionary { Type = g, TR = pdfreference(pdfimmediateobject("stream","1 exch sub",d())) }
local positive = pdfdictionary { Type = g, TR = pdfconstant("Identity") }
lpdf.adddocumentextgstate("GSnegative", pdfreference(pdfflushobject(negative)))
lpdf.adddocumentextgstate("GSPositive", pdfreference(pdfflushobject(positive)))
@@ -108,20 +109,28 @@ end
local openpage, closepage, opendocument, closedocument
-function codeinjections.flushdocumentactions(open,close)
- opendocument, closedocument = open, close
+function codeinjections.registerdocumentopenaction(open)
+ opendocument = open
+end
+
+function codeinjections.registerdocumentcloseaction(close)
+ closedocument = close
end
-function codeinjections.flushpageactions(open,close)
- openpage, closepage = open, close
+function codeinjections.registerpageopenaction(open)
+ openpage = open
+end
+
+function codeinjections.registerpagecloseaction(close)
+ closepage = close
end
local function flushdocumentactions()
if opendocument then
- lpdf.addtocatalog("OpenAction",lpdf.pdfaction(opendocument))
+ lpdf.addtocatalog("OpenAction",lpdf.action(opendocument))
end
if closedocument then
- lpdf.addtocatalog("CloseAction",lpdf.pdfaction(closedocument))
+ lpdf.addtocatalog("CloseAction",lpdf.action(closedocument))
end
end
@@ -129,39 +138,50 @@ local function flushpageactions()
if openpage or closepage then
local d = pdfdictionary()
if openpage then
- d.O = lpdf.pdfaction(openpage)
+ d.O = lpdf.action(openpage)
end
if closepage then
- d.C = lpdf.pdfaction(closepage)
+ d.C = lpdf.action(closepage)
end
lpdf.addtopageattributes("AA",d)
end
end
-lpdf.registerpagefinalizer(flushpageactions)
-lpdf.registerdocumentfinalizer(flushdocumentactions)
+lpdf.registerpagefinalizer (flushpageactions, "page actions")
+lpdf.registerdocumentfinalizer(flushdocumentactions,"document actions")
+
+--- info : this can change and move elsewhere
---- info
+local identity = { }
function codeinjections.setupidentity(specification)
- local title = specification.title or ""
- if title ~= "" then
- lpdf.addtoinfo("Title", pdfunicode(title), title)
+ for k, v in next, specification do
+ if v ~= "" then
+ identity[k] = v
+ end
end
- local subject = specification.subject or ""
- if subject ~= "" then
- lpdf.addtoinfo("Subject", pdfunicode(subject), subject)
+end
+
+local function setupidentity()
+ local title = identity.title
+ if not title or title == "" then
+ title = tex.jobname
end
- local author = specification.author or ""
+ lpdf.addtoinfo("Title", pdfunicode(title), title)
+ local subtitle = identity.subtitle or ""
+ if subtitle ~= "" then
+ lpdf.addtoinfo("Subject", pdfunicode(subtitle), subtitle)
+ end
+ local author = identity.author or ""
if author ~= "" then
lpdf.addtoinfo("Author", pdfunicode(author), author) -- '/Author' in /Info, 'Creator' in XMP
end
- local creator = specification.creator or ""
+ local creator = identity.creator or ""
if creator ~= "" then
lpdf.addtoinfo("Creator", pdfunicode(creator), creator) -- '/Creator' in /Info, 'CreatorTool' in XMP
end
lpdf.addtoinfo("CreationDate", pdfstring(lpdf.pdftimestamp(lpdf.timestamp())))
- local date = specification.date or ""
+ local date = identity.date or ""
local pdfdate = lpdf.pdftimestamp(date)
if pdfdate then
lpdf.addtoinfo("ModDate", pdfstring(pdfdate), date)
@@ -171,17 +191,20 @@ function codeinjections.setupidentity(specification)
date = lpdf.timestamp()
lpdf.addtoinfo("ModDate", pdfstring(lpdf.pdftimestamp(date)), date)
end
- local keywords = specification.keywords or ""
+ local keywords = identity.keywords or ""
if keywords ~= "" then
keywords = string.gsub(keywords, "[%s,]+", " ")
lpdf.addtoinfo("Keywords",pdfunicode(keywords), keywords)
end
local id = lpdf.id()
lpdf.addtoinfo("ID", pdfstring(id), id) -- needed for pdf/x
+ setupidentity = function() end
end
+lpdf.registerpagefinalizer(setupidentity,"identity")
+
local function flushjavascripts()
- local t = javascripts.flushpreambles()
+ local t = interactions.javascripts.flushpreambles()
if #t > 0 then
local a = pdfarray()
local pdf_javascript = pdfconstant("JavaScript")
@@ -189,7 +212,7 @@ local function flushjavascripts()
local name, script = t[i][1], t[i][2]
local j = pdfdictionary {
S = pdf_javascript,
- JS = pdfreference(pdfimmediateobj("stream",script)),
+ JS = pdfreference(pdfimmediateobject("stream",script)),
}
a[#a+1] = pdfstring(name)
a[#a+1] = pdfreference(pdfflushobject(j))
@@ -198,7 +221,7 @@ local function flushjavascripts()
end
end
-lpdf.registerdocumentfinalizer(flushjavascripts)
+lpdf.registerdocumentfinalizer(flushjavascripts,"javascripts")
-- -- --
@@ -278,7 +301,7 @@ local function pagespecification()
local pageheight = tex.pdfpageheight
local box = pdfarray { -- can be cached
boxvalue(leftoffset),
- boxvalue(pageheight-topoffset-height),
+ boxvalue(pageheight+topoffset-height),
boxvalue(width-leftoffset),
boxvalue(pageheight-topoffset),
}
@@ -288,5 +311,52 @@ local function pagespecification()
-- lpdf.addtopageattributes("ArtBox",box)
end
-lpdf.registerpagefinalizer(pagespecification)
-lpdf.registerdocumentfinalizer(documentspecification)
+lpdf.registerpagefinalizer(pagespecification,"page specification")
+lpdf.registerdocumentfinalizer(documentspecification,"document specification")
+
+-- Page Label support ...
+--
+-- In principle we can also support /P (prefix) as we can just use the verbose form
+-- and we can then forget about the /St (start) as we don't care about those few
+-- extra bytes due to lack of collapsing. Anyhow, for that we need a stupid prefix
+-- variant and that's not on the agenda now.
+
+local map = {
+ numbers = "D",
+ Romannumerals = "R",
+ romannumerals = "r",
+ Characters = "A",
+ characters = "a",
+}
+
+local function featurecreep()
+ local pages, lastconversion, list = structures.pages.tobesaved, nil, pdfarray()
+ local getstructureset = structures.sets.get
+ for i=1,#pages do
+ local p = pages[i]
+ if not p then
+ return -- fatal error
+ else
+ local numberdata = p.numberdata
+ if numberdata then
+ local conversionset = numberdata.conversionset
+ if conversionset then
+ local conversion = getstructureset("structure:conversions",p.block,conversionset,1,"numbers")
+ if conversion ~= lastconversion then
+ lastconversion = conversion
+ list[#list+1] = i - 1 -- pdf starts numbering at 0
+ list[#list+1] = pdfdictionary { S = pdfconstant(map[conversion] or map.numbers) }
+ end
+ end
+ end
+ if not lastconversion then
+ lastconversion = "numbers"
+ list[#list+1] = i - 1 -- pdf starts numbering at 0
+ list[#list+1] = pdfdictionary { S = pdfconstant(map.numbers) }
+ end
+ end
+ end
+ lpdf.addtocatalog("PageLabels", pdfdictionary { Nums = list })
+end
+
+lpdf.registerdocumentfinalizer(featurecreep,"featurecreep")