Compare commits

...

2 Commits

Author SHA1 Message Date
Marcel Krüger 15052dbc43 Some pdf extensions/variables 2019-07-21 14:19:05 +02:00
Marcel Krüger 136261f1e9 Read config values from kpathsea 2019-07-20 16:39:34 +02:00
5 changed files with 71 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.scan_token()
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()
for fid, id in pairs(fontdirs) do
local f = font.getfont(fid)
@ -38,6 +59,7 @@ callback.register("stop_run", function()
end
pfile.root = pfile:getobj()
pfile:indirect(pfile.root, string.format([[<</Type/Catalog/Version/1.7/Pages %i 0 R>>]], pfile:writepages()))
pfile.info = write_infodir(pfile)
pfile:close()
end, "Finish PDF file")
token.luacmd("pdfvariable", function()
@ -49,7 +71,11 @@ token.luacmd("pdfvariable", function()
end
-- The following error message gobbles the next word as a side effect.
-- This is intentional to make error-recovery easier.
--[[
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)
local whatsit_id = node.id'whatsit'
local whatsits = node.whatsits()
@ -129,6 +155,8 @@ token.luacmd("pdffeedback", function()
local mode = scan_literal_mode()
local default = token.scan_string()
tex.sprint(tostring(pdf.newcolorstack(default, mode, page)))
elseif token.scan_keyword"creationdate" then
tex.sprint(creationdate)
else
-- The following error message gobbles the next word as a side effect.
-- This is intentional to make error-recovery easier.
@ -148,6 +176,8 @@ token.luacmd("pdfextension", function()
data = literal,
})
node.write(whatsit)
elseif token.scan_keyword"info" then
infodir = infodir .. token.scan_string()
else
-- The following error message gobbles the next word as a side effect.
-- This is intentional to make error-recovery easier.

View File

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

View File

@ -0,0 +1,34 @@
local var_value = kpse.var_value
local texconfig = texconfig
-- These are special in two ways: They are strings and I think they are ignored
-- We set them anyway because they should be emulated at some point
for _, name in ipairs{
"shell_escape",
"shell_escape_commands",
} do
local value = var_value(name)
texconfig[name] = value
end
for _, name in ipairs{
"string_vacancies",
"pool_free",
"max_strings",
"strings_free",
"nest_size",
"max_in_open",
"param_size",
"save_size",
"stack_size",
"dvi_buf_size",
"error_line",
"half_error_line",
"max_print_line",
"hash_extra",
"pk_dpi",
"trace_file_names",
"file_line_error",
"halt_on_error",
} do
local value = var_value(name)
texconfig[name] = tonumber(value) or value or nil
end

View File

@ -336,6 +336,7 @@ kpse.set_maketex("kpse_fmt_format", true)
bit32 = require'luametalatex-bit32'
kpse.init_prog("LUATEX", 400, "nexthi", nil)
status.init_kpse = 1
require'luametalatex-init-config'
status.safer_option = 0
local read_tfm = require'luametalatex-font-tfm'
read_vf = require'luametalatex-font-vf'

View File

@ -52,7 +52,8 @@ local function trailer(pdf)
offsets[linked+1] = '\0\0\0\0\255'
pdf[nextid] = assigned
-- 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')
end
local function close(pdf)