Added initial version of \pdfvariable

This commit is contained in:
Marcel Krüger 2019-07-18 13:10:33 +02:00
parent d72ac36935
commit 0bbab18434
2 changed files with 50 additions and 5 deletions

View File

@ -5,9 +5,9 @@ local fontdirs = setmetatable({}, {__index=function(t, k)t[k] = pfile:getobj() r
local usedglyphs = {}
token.luacmd("shipout", function()
local voff = node.new'kern'
voff.kern = tex.voffset + tex.sp'1in'
voff.kern = tex.voffset + pdf.variable.horigin
voff.next = token.scan_list()
voff.next.shift = tex.hoffset + tex.sp'1in'
voff.next.shift = tex.hoffset + pdf.variable.vorigin
local list = node.vpack(voff)
list.height = tex.pageheight
list.width = tex.pagewidth
@ -33,3 +33,14 @@ callback.register("stop_run", function()
pfile:indirect(pfile.root, string.format([[<</Type/Catalog/Version/1.7/Pages %i 0 R>>]], pfile:writepages()))
pfile:close()
end, "Finish PDF file")
token.luacmd("pdfvariable", function()
for n, t in pairs(pdf.variable_tokens) do
if token.scan_keyword(n) then
token.put_next(t)
return
end
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_string()))
end)

View File

@ -2,6 +2,11 @@
\catcode`\^^^^ffff=11
\catcode`\@=11
\toks0{%
do
local function frozen(s)
local t = token.create(s)
return token.new(t.mode, t.command)
end
local dimen_cmd = token.command_id'assign_dimen'
local tex_params = {}
local texmeta = getmetatable(tex)
@ -27,11 +32,35 @@
return texmetaoldnewindex(t, k, v)
end
end
local pdf_params = {}
pdf.variable_tokens = pdf_params
pdf.variable = setmetatable({}, {
__index = function(t, k)
local v = pdf_params[k]
if v then
if v.command == dimen_cmd then
return tex.dimen[v.index]
end
else
return texmetaoldindex(t, k)
end
end,
__newindex = function(t, k, v)
local p = pdf_params[k]
if p then
if p.command == dimen_cmd then
tex.dimen[p.index] = v
end
else
return texmetaoldnewindex(t, k, v)
end
end,
})
}
\def\InternalAlloc#1#2#3#4#5{%
\csname new#3\endcsname#1%
\global#1=#5\relax
\etoksapp0{#2_params["\luaescapestring{#4}"] = token.create"\luaescapestring{\csstring#1}"}
\etoksapp0{#2_params["\luaescapestring{#4}"] = frozen"\luaescapestring{\csstring#1}"}
}
\def\internalAlloc#1#2#3{%
\expandafter\InternalAlloc\csname ^^^^fffe#3@#1\endcsname{#1}{#2}{#3}%
@ -39,11 +68,16 @@
\def\texAlloc#1#2{%
\expandafter\InternalAlloc\csname #2\endcsname{tex}{#1}{#2}%
}
\def\pdfAlloc{%
\internalAlloc{pdf}%
}
\texAlloc{dimen}{pageheight}{11in}
\texAlloc{dimen}{pagewidth}{8.5in}
% \internalAlloc{tex}{dimen}{pagewidth}
\pdfAlloc{dimen}{horigin}{1in}
\pdfAlloc{dimen}{vorigin}{1in}
\directlua{
lua.prepared_code[\csstring#lua.prepared_code+1] = tex.toks[0]
lua.prepared_code[\csstring#lua.prepared_code+1] = tex.toks[0] .. "end"
\the\toks0
end
}
\endgroup