Some pdf extensions/variables

This commit is contained in:
Marcel Krüger 2019-07-21 14:19:05 +02:00
parent 136261f1e9
commit 15052dbc43
3 changed files with 36 additions and 3 deletions

View File

@ -25,6 +25,27 @@ token.luacmd("shipout", function()
token.put_next(token.create'immediateassignment', token.create'global', token.create'deadcycles', token.create(0x30), token.create'relax') token.put_next(token.create'immediateassignment', token.create'global', token.create'deadcycles', token.create(0x30), token.create'relax')
token.scan_token() token.scan_token()
end, 'protected') end, 'protected')
local infodir = ""
local creationdate = os.date("D:%Y%m%d%H%M%S%z"):gsub("+0000$", "Z"):gsub("%d%d$", "'%0")
local function write_infodir(p)
local additional = ""
if not string.find(infodir, "/CreationDate", 1, false) then
additional = string.format("/CreationDate(%s)", creationdate)
end
if not string.find(infodir, "/ModDate", 1, false) then
additional = string.format("%s/ModDate(%s)", additional, creationdate)
end
if not string.find(infodir, "/Producer", 1, false) then
additional = string.format("%s/Producer(LuaMetaLaTeX)", additional)
end
if not string.find(infodir, "/Creator", 1, false) then
additional = string.format("%s/Creator(TeX)", additional)
end
if not string.find(infodir, "/PTEX.Fullbanner", 1, false) then
additional = string.format("%s/PTEX.Fullbanner(%s)", additional, status.banner)
end
return p:indirect(nil, string.format("<<%s%s>>", infodir, additional))
end
callback.register("stop_run", function() callback.register("stop_run", function()
for fid, id in pairs(fontdirs) do for fid, id in pairs(fontdirs) do
local f = font.getfont(fid) local f = font.getfont(fid)
@ -38,6 +59,7 @@ callback.register("stop_run", function()
end end
pfile.root = pfile:getobj() pfile.root = pfile:getobj()
pfile:indirect(pfile.root, string.format([[<</Type/Catalog/Version/1.7/Pages %i 0 R>>]], pfile:writepages())) pfile:indirect(pfile.root, string.format([[<</Type/Catalog/Version/1.7/Pages %i 0 R>>]], pfile:writepages()))
pfile.info = write_infodir(pfile)
pfile:close() pfile:close()
end, "Finish PDF file") end, "Finish PDF file")
token.luacmd("pdfvariable", function() token.luacmd("pdfvariable", function()
@ -49,7 +71,11 @@ token.luacmd("pdfvariable", function()
end end
-- The following error message gobbles the next word as a side effect. -- The following error message gobbles the next word as a side effect.
-- This is intentional to make error-recovery easier. -- This is intentional to make error-recovery easier.
--[[
error(string.format("Unknown PDF variable %s", token.scan_word())) error(string.format("Unknown PDF variable %s", token.scan_word()))
]] -- Delay the error to ensure luatex85.sty compatibility
texio.write_nl(string.format("Unknown PDF variable %s", token.scan_word()))
tex.sprint"\\unexpanded{\\undefinedpdfvariable}"
end) end)
local whatsit_id = node.id'whatsit' local whatsit_id = node.id'whatsit'
local whatsits = node.whatsits() local whatsits = node.whatsits()
@ -129,6 +155,8 @@ token.luacmd("pdffeedback", function()
local mode = scan_literal_mode() local mode = scan_literal_mode()
local default = token.scan_string() local default = token.scan_string()
tex.sprint(tostring(pdf.newcolorstack(default, mode, page))) tex.sprint(tostring(pdf.newcolorstack(default, mode, page)))
elseif token.scan_keyword"creationdate" then
tex.sprint(creationdate)
else else
-- The following error message gobbles the next word as a side effect. -- The following error message gobbles the next word as a side effect.
-- This is intentional to make error-recovery easier. -- This is intentional to make error-recovery easier.
@ -148,6 +176,8 @@ token.luacmd("pdfextension", function()
data = literal, data = literal,
}) })
node.write(whatsit) node.write(whatsit)
elseif token.scan_keyword"info" then
infodir = infodir .. token.scan_string()
else else
-- The following error message gobbles the next word as a side effect. -- The following error message gobbles the next word as a side effect.
-- This is intentional to make error-recovery easier. -- This is intentional to make error-recovery easier.

View File

@ -71,8 +71,10 @@
\def\pdfAlloc{% \def\pdfAlloc{%
\internalAlloc{pdf}% \internalAlloc{pdf}%
} }
\texAlloc{dimen}{pageheight}{11in} \texAlloc{count}{outputmode}{1} % The "traditional" default would be 0,
\texAlloc{dimen}{pagewidth}{8.5in} % but we do not actually support that.
\texAlloc{dimen}{pageheight}{210mm}
\texAlloc{dimen}{pagewidth}{297mm}
\pdfAlloc{dimen}{horigin}{1in} \pdfAlloc{dimen}{horigin}{1in}
\pdfAlloc{dimen}{vorigin}{1in} \pdfAlloc{dimen}{vorigin}{1in}
\directlua{ \directlua{

View File

@ -52,7 +52,8 @@ local function trailer(pdf)
offsets[linked+1] = '\0\0\0\0\255' offsets[linked+1] = '\0\0\0\0\255'
pdf[nextid] = assigned pdf[nextid] = assigned
-- TODO: Add an /ID according to 14.4 -- TODO: Add an /ID according to 14.4
stream(pdf, nextid, format([[/Type/XRef/Size %i/W[1 3 1]/Root %i 0 R]], nextid+1, pdf.root), table.concat(offsets)) local info = pdf.info and string.format("/Info %i 0 R", pdf.info) or ""
stream(pdf, nextid, format([[/Type/XRef/Size %i/W[1 3 1]/Root %i 0 R%s]], nextid+1, pdf.root, info), table.concat(offsets))
pdf.file:write('startxref\n', myoff, '\n%%EOF') pdf.file:write('startxref\n', myoff, '\n%%EOF')
end end
local function close(pdf) local function close(pdf)