Adjust to newer LuaMetaTeX versions

This commit is contained in:
Marcel Krüger 2020-01-02 04:14:39 +01:00
parent 29c97800a3
commit b5c91c4312
12 changed files with 247 additions and 112 deletions

65
ltexpl.ltx Normal file
View File

@ -0,0 +1,65 @@
%%
%% This is file `ltexpl.ltx',
%% generated with the docstrip utility.
%%
%% The original source files were:
%%
%% ltexpl.dtx (with options: `2ekernel')
%%
%% This is a generated file.
%%
%% The source is maintained by the LaTeX Project team and bug
%% reports for it can be opened at https://latex-project.org/bugs.html
%% (but please observe conditions on bug reports sent to that address!)
%%
%%
%% Copyright (C) 1993-2019
%% The LaTeX3 Project and any individual authors listed elsewhere
%% in this file.
%%
%% This file was generated from file(s) of the LaTeX base system.
%% --------------------------------------------------------------
%%
%% It may be distributed and/or modified under the
%% conditions of the LaTeX Project Public License, either version 1.3c
%% of this license or (at your option) any later version.
%% The latest version of this license is in
%% https://www.latex-project.org/lppl.txt
%% and version 1.3c or later is part of all distributions of LaTeX
%% version 2008 or later.
%%
%% This file has the LPPL maintenance status "maintained".
%%
%% This file may only be distributed together with a copy of the LaTeX
%% base system. You may however distribute the LaTeX base system without
%% such generated files.
%%
%% The list of all files belonging to the LaTeX base distribution is
%% given in the file `manifest.txt'. See also `legal.txt' for additional
%% information.
%%
%% The list of derived (unpacked) files belonging to the distribution
%% and covered by LPPL is defined by the unpacking scripts (with
%% extension .ins) which are part of the distribution.
%%% From File: ltexpl.dtx
\input luametalatex-baseregisters
\IfFileExists{expl3.ltx}
{%
\ifnum0%
\ifdefined\pdffilesize 1\fi
\ifdefined\filesize 1\fi
\ifdefined\luatexversion\ifnum\luatexversion>94 1\fi\fi
>0 %
\else
\message{Skipping expl3-dependent extensions}
\expandafter\endinput
\fi
}
{%
\message{Skipping expl3-dependent extensions}%
\endinput
}%
\input{expl3.ltx}
\endinput
%%
%% End of file `ltexpl.ltx'.

View File

@ -10,12 +10,13 @@ local colorstacks = {{
default = "0 g 0 G", default = "0 g 0 G",
page_stack = {"0 g 0 G"}, page_stack = {"0 g 0 G"},
}} }}
token.scan_list = token.scan_box -- They are equal if no parameter is present
token.luacmd("shipout", function() token.luacmd("shipout", function()
local voff = node.new'kern' local voff = node.new'kern'
voff.kern = tex.voffset + pdf.variable.vorigin voff.kern = tex.voffset + pdf.variable.vorigin
voff.next = token.scan_list() voff.next = token.scan_list()
voff.next.shift = tex.hoffset + pdf.variable.horigin voff.next.shift = tex.hoffset + pdf.variable.horigin
local list = node.vpack(voff) local list = node.direct.tonode(node.direct.vpack(node.direct.todirect(voff)))
list.height = tex.pageheight list.height = tex.pageheight
list.width = tex.pagewidth list.width = tex.pagewidth
local out, resources, annots = writer(pfile, list, fontdirs, usedglyphs, colorstacks) local out, resources, annots = writer(pfile, list, fontdirs, usedglyphs, colorstacks)

View File

@ -83,12 +83,14 @@
\texAlloc{count}{suppressfontnotfounderror}{0} \texAlloc{count}{suppressfontnotfounderror}{0}
\texAlloc{count}{outputmode}{1} % The "traditional" default would be 0, \texAlloc{count}{outputmode}{1} % The "traditional" default would be 0,
% but we do not actually support that. % but we do not actually support that.
\texAlloc{dimen}{pageheight}{210mm} \texAlloc{dimen}{pageheight}{297mm}
\texAlloc{dimen}{pagewidth}{297mm} \texAlloc{dimen}{pagewidth}{210mm}
\pdfAlloc{dimen}{horigin}{1in} \pdfAlloc{dimen}{horigin}{1in}
\pdfAlloc{dimen}{vorigin}{1in} \pdfAlloc{dimen}{vorigin}{1in}
\pdfAlloc{count}{majorversion}{1} \pdfAlloc{count}{majorversion}{1}
\pdfAlloc{count}{minorversion}{7} \pdfAlloc{count}{minorversion}{7}
\pdfAlloc{count}{compresslevel}{0} % 0 is actually the only supported value right now, so this is basically ignored
\pdfAlloc{count}{objcompresslevel}{0} % see above
\directlua{ \directlua{
lua.prepared_code[\csstring#lua.prepared_code+1] = tex.toks[0] .. "end" lua.prepared_code[\csstring#lua.prepared_code+1] = tex.toks[0] .. "end"
\the\toks0 \the\toks0

1
luametalatex-dev-init.lua Symbolic link
View File

@ -0,0 +1 @@
luametalatex-init.lua

1
luametalatex-dev.lua Symbolic link
View File

@ -0,0 +1 @@
luametalatex.lua

View File

@ -15,7 +15,7 @@ function token.luacmd(name, func, ...)
functions[idx] = func functions[idx] = func
return idx return idx
end end
local properties = node.get_properties_table() local properties = node.direct.get_properties_table()
-- setmetatable(node.direct.get_properties_table(), { -- setmetatable(node.direct.get_properties_table(), {
-- __index = function(t, id) -- __index = function(t, id)
-- local new = {} -- local new = {}
@ -110,9 +110,9 @@ token.luacmd("openout", function(_, immediate) -- \openout
if immediate == "immediate" then if immediate == "immediate" then
do_openout(props) do_openout(props)
else else
local whatsit = node.new(whatsit_id, whatsits.open) local whatsit = node.direct.new(whatsit_id, whatsits.open)
properties[whatsit] = props properties[whatsit] = props
node.write(whatsit) node.direct.write(whatsit)
end end
end, "protected") end, "protected")
local function do_closeout(p) local function do_closeout(p)
@ -127,9 +127,9 @@ token.luacmd("closeout", function(_, immediate) -- \closeout
if immediate == "immediate" then if immediate == "immediate" then
do_closeout(props) do_closeout(props)
else else
local whatsit = node.new(whatsit_id, whatsits.close) local whatsit = node.direct.new(whatsit_id, whatsits.close)
properties[whatsit] = props properties[whatsit] = props
node.write(whatsit) node.direct.write(whatsit)
end end
end, "protected") end, "protected")
local function do_write(p) local function do_write(p)
@ -148,9 +148,9 @@ token.luacmd("write", function(_, immediate) -- \write
if immediate == "immediate" then if immediate == "immediate" then
do_write(props) do_write(props)
else else
local whatsit = node.new(whatsit_id, whatsits.write) local whatsit = node.direct.new(whatsit_id, whatsits.write)
properties[whatsit] = props properties[whatsit] = props
node.write(whatsit) node.direct.write(whatsit)
end end
end, "protected") end, "protected")
local lua_call_cmd = token.command_id'lua_call' local lua_call_cmd = token.command_id'lua_call'

View File

@ -339,10 +339,10 @@ status.init_kpse = 1
require'luametalatex-init-config' require'luametalatex-init-config'
status.safer_option = 0 status.safer_option = 0
local read_tfm = require'luametalatex-font-tfm' local read_tfm = require'luametalatex-font-tfm'
read_vf = require'luametalatex-font-vf' local read_vf = require'luametalatex-font-vf'
font.read_tfm = read_tfm font.read_tfm = read_tfm
font.read_vf = read_vf font.read_vf = read_vf
local reserved_ids = -1 require'module'
font.fonts = {} font.fonts = {}
function font.getfont(id) function font.getfont(id)
return font.fonts[id] return font.fonts[id]
@ -352,24 +352,20 @@ pdf = {
return id return id
end, end,
} }
callback.register('define_font', function(name, size)
if status.ini_version then
reserved_ids = font.nextid()-1
lua.prepared_code[#lua.prepared_code+1] = string.format("font.define(%i, font.read_tfm(%q, %i))", reserved_ids, name, size)
end
local f = read_tfm(name, size)
font.fonts[font.nextid()-1] = f
return f
end)
local olddefinefont = font.define local olddefinefont = font.define
function font.define(i, f) function font.define(f)
if not f then local i = olddefinefont(f)
f = i
i = font.nextid(true)
end
font.fonts[i] = f font.fonts[i] = f
return olddefinefont(i, f) return i
end end
callback.register('define_font', function(name, size)
local f = read_tfm(name, size)
local id = font.define(f)
if status.ini_version then
lua.prepared_code[#lua.prepared_code+1] = string.format("assert(%i == font.define(font.read_tfm(%q, %i)))", id, name, size)
end
return id
end)
-- do -- do
-- local register = callback.register -- local register = callback.register
-- function callback.register(...) -- function callback.register(...)
@ -391,12 +387,7 @@ callback.register('show_error_message', function()
texio.write_nl(status.lasterrorstring) texio.write_nl(status.lasterrorstring)
end) end)
callback.register('pre_dump', function() callback.register('pre_dump', function()
-- for k,v in pairs(callback.list()) do print('CB', k,v) end lua.bytecode[1] = assert(load(table.concat(lua.prepared_code, ' ')))
lua.bytecode[1], msg = load("do local id "
.. "repeat id = font.nextid(true) "
.. "until id == " .. reserved_ids
.. " end "
.. table.concat(lua.prepared_code, ' '))
end) end)
if status.ini_version then if status.ini_version then
lua.prepared_code = {} lua.prepared_code = {}

View File

@ -1,7 +1,32 @@
local format = string.format local format = string.format
local concat = table.concat local concat = table.concat
local write = texio.write_nl local write = texio.write_nl
local properties = node.get_properties_table() local direct = node.direct
local properties = direct.get_properties_table()
local tonode = direct.tonode
local todirect = direct.todirect
local getid = direct.getid
local traverse = direct.traverse
local getsubtype = direct.getsubtype
local setsubtype = direct.setsubtype
local getdepth = direct.getdepth
local getheight = direct.getheight
local getwidth = direct.getwidth
local setdepth = direct.setdepth
local setheight = direct.setheight
local setwidth = direct.setwidth
local getshift = direct.getshift
local getlist = direct.getlist
local getkern = direct.getkern
local getreplace = direct.getreplace
local getleader = direct.getleader
local setfont = direct.setfont
local getfont = direct.getfont
local getoffsets = direct.getoffsets
local getnext = direct.getnext
local getexpansion = direct.getexpansion
local getchar = direct.getchar
local rangedimensions = direct.rangedimensions
local function doublekeyed(t, id2name, name2id, index) local function doublekeyed(t, id2name, name2id, index)
return setmetatable(t, { return setmetatable(t, {
__index = index, __index = index,
@ -17,7 +42,7 @@ local function doublekeyed(t, id2name, name2id, index)
end end
local nodehandler = (function() local nodehandler = (function()
local function unknown_handler(_, n, x, y) local function unknown_handler(_, n, x, y)
write(format("Sorry, but the PDF backend does not support %q (id = %i) nodes right now. The supplied node will be dropped at coordinates (%i, %i).", node.type(n.id), n.id, x, y)) write(format("Sorry, but the PDF backend does not support %q (id = %i) nodes right now. The supplied node will be dropped at coordinates (%i, %i).", node.type(getid(n)), getid(n), x, y))
end end
return doublekeyed({}, node.type, node.id, function() return doublekeyed({}, node.type, node.id, function()
return unknown_handler return unknown_handler
@ -26,11 +51,11 @@ end)()
local whatsithandler = (function() local whatsithandler = (function()
local whatsits = node.whatsits() local whatsits = node.whatsits()
local function unknown_handler(p, n, x, y, ...) local function unknown_handler(p, n, x, y, ...)
local prop = properties[n] or node.getproperty(n) local prop = properties[n]-- or node.getproperty(n)
if prop and prop.handle then if prop and prop.handle then
prop:handle(p, n, x, y, ...) prop:handle(p, n, x, y, ...)
else else
write(format("Sorry, but the PDF backend does not support %q (id = %i) whatsits right now. The supplied node will be dropped at coordinates (%i, %i).", whatsits[n.subtype], n.subtype, x, y)) write(format("Sorry, but the PDF backend does not support %q (id = %i) whatsits right now. The supplied node will be dropped at coordinates (%i, %i).", whatsits[getsubtype(n)], getsubtype(n), x, y))
end end
end end
return doublekeyed({}, function(n)return whatsits[n]end, function(n)return whatsits[n]end, function() return doublekeyed({}, function(n)return whatsits[n]end, function(n)return whatsits[n]end, function()
@ -173,8 +198,8 @@ local function addlinkpoint(p, link, x, y, list, final)
p.annots[#p.annots+1] = link.objnum .. " 0 R" p.annots[#p.annots+1] = link.objnum .. " 0 R"
end end
local m = p.matrix local m = p.matrix
local lx, ly = projected_point(m, x, y-(link.depth or list.depth)) local lx, ly = projected_point(m, x, y-(link.depth or getdepth(list)))
local ux, uy = projected_point(m, x, y+(link.height or list.height)) local ux, uy = projected_point(m, x, y+(link.height or getheight(list)))
local n = #quads local n = #quads
quads[n+1], quads[n+2], quads[n+3], quads[n+4] = lx, ly, ux, uy quads[n+1], quads[n+2], quads[n+3], quads[n+4] = lx, ly, ux, uy
if final or (link.force_separate and (n+4)%8 == 0) then if final or (link.force_separate and (n+4)%8 == 0) then
@ -185,20 +210,20 @@ local function addlinkpoint(p, link, x, y, list, final)
end end
function nodehandler.hlist(p, list, x0, y, outerlist, origin, level) function nodehandler.hlist(p, list, x0, y, outerlist, origin, level)
if outerlist then if outerlist then
if outerlist.id == 0 then if getid(outerlist) == 0 then
y = y - list.shift y = y - getshift(list)
else else
x0 = x0 + list.shift x0 = x0 + getshift(list)
end end
end end
local x = x0 local x = x0
for _,l in ipairs(p.linkcontext) do if l.level == level+1 then for _,l in ipairs(p.linkcontext) do if l.level == level+1 then
addlinkpoint(p, l, x, y, list) addlinkpoint(p, l, x, y, list)
end end end end
for n in node.traverse(list.head) do for n in traverse(getlist(list)) do
local next = n.next local next = getnext(n)
local w = next and node.rangedimensions(list, n, next) or node.rangedimensions(list, n) local w = next and rangedimensions(list, n, next) or rangedimensions(list, n)
nodehandler[n.id](p, n, x, y, list, x0, level+1) nodehandler[getid(n)](p, n, x, y, list, x0, level+1)
x = w + x x = w + x
end end
for _,l in ipairs(p.linkcontext) do if l.level == level+1 then for _,l in ipairs(p.linkcontext) do if l.level == level+1 then
@ -207,29 +232,29 @@ function nodehandler.hlist(p, list, x0, y, outerlist, origin, level)
end end
function nodehandler.vlist(p, list, x, y0, outerlist, origin, level) function nodehandler.vlist(p, list, x, y0, outerlist, origin, level)
if outerlist then if outerlist then
if outerlist.id == 0 then if getid(outerlist) == 0 then
y0 = y0 - list.shift y0 = y0 - getshift(list)
else else
x = x + list.shift x = x + getshift(list)
end end
end end
y0 = y0 + list.height y0 = y0 + getheight(list)
local y = y0 local y = y0
for n in node.traverse(list.head) do for n in traverse(getlist(list)) do
local d, h, _ = 0, node.effective_glue(n, list) or math.tointeger(n.kern) local d, h, _ = 0, direct.effective_glue(n, list) or math.tointeger(getkern(n))
if not h then if not h then
_, h, d = node.direct.getwhd(node.direct.todirect(n)) _, h, d = direct.getwhd(n)
end end
y = y - (h or 0) y = y - (h or 0)
nodehandler[n.id](p, n, x, y, list, y0, level+1) nodehandler[getid(n)](p, n, x, y, list, y0, level+1)
y = y - (d or 0) y = y - (d or 0)
end end
end end
function nodehandler.rule(p, n, x, y, outer) function nodehandler.rule(p, n, x, y, outer)
if n.width == -1073741824 then n.width = outer.width end if getwidth(n) == -1073741824 then setwidth(n, getwidth(outer)) end
if n.height == -1073741824 then n.height = outer.height end if getheight(n) == -1073741824 then setheight(n, getheight(outer)) end
if n.depth == -1073741824 then n.depth = outer.depth end if getdepth(n) == -1073741824 then setdepth(n, getdepth(outer)) end
local sub = n.subtype local sub = getsubtype(n)
if sub == 1 then if sub == 1 then
error[[We can't handle boxes yet]] error[[We can't handle boxes yet]]
elseif sub == 2 then elseif sub == 2 then
@ -240,42 +265,42 @@ function nodehandler.rule(p, n, x, y, outer)
elseif sub == 9 then elseif sub == 9 then
error[[We can't handle outline rules yet]] error[[We can't handle outline rules yet]]
else else
if n.width <= 0 or n.depth + n.height <= 0 then return end if getwidth(n) <= 0 or getdepth(n) + getheight(n) <= 0 then return end
topage(p) topage(p)
p.strings[#p.strings+1] = gsub(format("%f %f %f %f re f", sp2bp(x), sp2bp(y - n.depth), sp2bp(n.width), sp2bp(n.depth + n.height)), '%.?0+ ', ' ') p.strings[#p.strings+1] = gsub(format("%f %f %f %f re f", sp2bp(x), sp2bp(y - getdepth(n)), sp2bp(getwidth(n)), sp2bp(getdepth(n) + getheight(n))), '%.?0+ ', ' ')
end end
end end
function nodehandler.boundary() end function nodehandler.boundary() end
function nodehandler.disc(p, n, x, y, list, ...) -- FIXME: I am not sure why this can happen, let's assume we can use .replace function nodehandler.disc(p, n, x, y, list, ...) -- FIXME: I am not sure why this can happen, let's assume we can use .replace
for n in node.traverse(n.replace) do for n in traverse(getreplace(n)) do
local next = n.next local next = getnext(n)
local w = next and node.rangedimensions(list, n, next) or node.rangedimensions(list, n) local w = next and rangedimensions(list, n, next) or rangedimensions(list, n)
nodehandler[n.id](p, n, x, y, list, ...) nodehandler[getid(n)](p, n, x, y, list, ...)
x = w + x x = w + x
end end
end end
function nodehandler.local_par() end function nodehandler.local_par() end
function nodehandler.math() end function nodehandler.math() end
function nodehandler.glue(p, n, x, y, outer, origin, level) -- Naturally this is an interesting one. function nodehandler.glue(p, n, x, y, outer, origin, level) -- Naturally this is an interesting one.
local subtype = n.subtype local subtype = getsubtype(n)
if subtype < 100 then return end -- We only really care about leaders if subtype < 100 then return end -- We only really care about leaders
local leader = n.leader local leader = getleader(n)
local w = node.effective_glue(n, outer) local w = direct.effective_glue(n, outer)
if leader.id == 2 then -- We got a rule, this should be easy if getid(leader) == 2 then -- We got a rule, this should be easy
if outer.id == 0 then if getid(outer) == 0 then
leader.width = w setwidth(leader, w)
else else
leader.height = w setheight(leader, w)
leader.depth = 0 setdepth(leader, 0)
end end
return nodehandler.rule(p, leader, x, y, outer) return nodehandler.rule(p, leader, x, y, outer)
end end
local lwidth = outer.id == 0 and leader.width or leader.height + leader.depth local lwidth = getid(outer) == 0 and getwidth(leader) or getheight(leader) + getdepth(leader)
if outer.id ~= 0 then if getid(outer) ~= 0 then
y = y + w y = y + w
end end
if subtype == 100 then if subtype == 100 then
if outer.id == 0 then if getid(outer) == 0 then
local newx = ((x-origin - 1)//lwidth + 1) * lwidth + origin local newx = ((x-origin - 1)//lwidth + 1) * lwidth + origin
-- local newx = -(origin-x)//lwidth * lwidth + origin -- local newx = -(origin-x)//lwidth * lwidth + origin
w = w + x - newx w = w + x - newx
@ -288,7 +313,7 @@ function nodehandler.glue(p, n, x, y, outer, origin, level) -- Naturally this is
end end
elseif subtype == 101 then elseif subtype == 101 then
local inner = w - (w // lwidth) * lwidth local inner = w - (w // lwidth) * lwidth
if outer.id == 0 then if getid(outer) == 0 then
x = x + inner/2 x = x + inner/2
else else
y = y - inner/2 y = y - inner/2
@ -296,14 +321,14 @@ function nodehandler.glue(p, n, x, y, outer, origin, level) -- Naturally this is
elseif subtype == 102 then elseif subtype == 102 then
local count = w // lwidth local count = w // lwidth
local skip = (w - count * lwidth) / (count + 1) local skip = (w - count * lwidth) / (count + 1)
if outer.id == 0 then if getid(outer) == 0 then
x = x + skip x = x + skip
else else
y = y - skip y = y - skip
end end
lwidth = lwidth + skip lwidth = lwidth + skip
elseif subtype == 103 then elseif subtype == 103 then
if outer.id == 0 then if getid(outer) == 0 then
local newx = ((x - 1)//lwidth + 1) * lwidth local newx = ((x - 1)//lwidth + 1) * lwidth
w = w + x - newx w = w + x - newx
x = newx x = newx
@ -313,15 +338,15 @@ function nodehandler.glue(p, n, x, y, outer, origin, level) -- Naturally this is
y = newy y = newy
end end
end end
local handler = nodehandler[leader.id] local handler = nodehandler[getid(leader)]
if outer.id == 0 then if getid(outer) == 0 then
while w >= lwidth do while w >= lwidth do
handler(p, leader, x, y, outer, origin, level+1) handler(p, leader, x, y, outer, origin, level+1)
w = w - lwidth w = w - lwidth
x = x + lwidth x = x + lwidth
end end
else else
y = y - leader.height y = y - getheight(leader)
while w >= lwidth do while w >= lwidth do
handler(p, leader, x, y, outer, origin, level+1) handler(p, leader, x, y, outer, origin, level+1)
w = w - lwidth w = w - lwidth
@ -339,28 +364,31 @@ local function do_commands(p, c, f, fid, x, y, outer, ...)
for _, cmd in ipairs(c.commands) do for _, cmd in ipairs(c.commands) do
if cmd[1] == "node" then if cmd[1] == "node" then
local cmd = cmd[2] local cmd = cmd[2]
nodehandler[cmd.id](p, cmd, x, y, nil, ...) nodehandler[getid(cmd)](p, cmd, x, y, nil, ...)
x = x + cmd.width x = x + getwidth(cmd)
elseif cmd[1] == "font" then elseif cmd[1] == "font" then
current_font = fonts[cmd[2]] current_font = fonts[cmd[2]]
elseif cmd[1] == "char" then elseif cmd[1] == "char" then
local n = node.new'glyph' local n = direct.new'glyph'
n.subtype, n.font, n.char = 256, current_font.id, cmd[2] setsubtype(n, 256)
setfont(n, current_font.id, cmd[2])
nodehandler.glyph(p, n, x, y, outer, ...) nodehandler.glyph(p, n, x, y, outer, ...)
node.free(n) direct.free(n)
x = x + n.width x = x + getwidth(n)
elseif cmd[1] == "slot" then elseif cmd[1] == "slot" then
local n = node.new'glyph' local n = direct.new'glyph'
n.subtype, n.font, n.char = 256, cmd[2], cmd[3] setsubtype(n, 256)
setfont(n, cmd[2], cmd[3])
nodehandler.glyph(p, n, x, y, outer, ...) nodehandler.glyph(p, n, x, y, outer, ...)
node.free(n) direct.free(n)
x = x + n.width x = x + getwidth(n)
elseif cmd[1] == "rule" then elseif cmd[1] == "rule" then
local n = node.new'rule' local n = direct.new'rule'
n.height, n.width = cmd[2], cmd[3] setheight(n, cmd[2])
setwidth(n, cmd[3])
nodehandler.rule(p, n, x, y, outer, ...) nodehandler.rule(p, n, x, y, outer, ...)
node.free(n) direct.free(n)
x = x + n.width x = x + getwidth(n)
elseif cmd[1] == "left" then elseif cmd[1] == "left" then
x = x + cmd[2] x = x + cmd[2]
elseif cmd[1] == "down" then elseif cmd[1] == "down" then
@ -389,26 +417,27 @@ local function do_commands(p, c, f, fid, x, y, outer, ...)
if #commands ~= 1 then error[[Unsupported command number]] end if #commands ~= 1 then error[[Unsupported command number]] end
if commands[1][1] ~= "node" then error[[Unsupported command name]] end if commands[1][1] ~= "node" then error[[Unsupported command name]] end
commands = commands[1][2] commands = commands[1][2]
nodehandler[commands.id](p, commands, x, y, nil, ...) nodehandler[getid(commands)](p, commands, x, y, nil, ...)
end end
end end
function nodehandler.glyph(p, n, x, y, ...) function nodehandler.glyph(p, n, x, y, ...)
if n.font ~= p.vfont.fid then if getfont(n) ~= p.vfont.fid then
p.vfont.fid = n.font p.vfont.fid = getfont(n)
p.vfont.font = font.getfont(n.font) or font.fonts[n.font] p.vfont.font = font.getfont(getfont(n)) or font.fonts[getfont(n)]
end end
local f, fid = p.vfont.font, p.vfont.fid local f, fid = p.vfont.font, p.vfont.fid
local c = f.characters[n.char] local c = f.characters[getchar(n)]
if not c then if not c then
texio.write_nl("Missing character") texio.write_nl("Missing character")
return return
end end
if c.commands then return do_commands(p, c, f, fid, x, y, ...) end if c.commands then return do_commands(p, c, f, fid, x, y, ...) end
toglyph(p, n.font, x + n.xoffset, y + n.yoffset, n.expansion_factor) local xoffset, yoffset = getoffsets(n)
toglyph(p, getfont(n), x + xoffset, y + yoffset, getexpansion(n))
local index = c.index local index = c.index
if index then if index then
-- if f.encodingbytes == -3 then -- if f.encodingbytes == -3 then
if true then if false then
if index < 0x80 then if index < 0x80 then
p.pending[#p.pending+1] = match(literalescape, string.pack('>B', index)) p.pending[#p.pending+1] = match(literalescape, string.pack('>B', index))
elseif index < 0x7F80 then elseif index < 0x7F80 then
@ -423,15 +452,15 @@ function nodehandler.glyph(p, n, x, y, ...)
p.usedglyphs[index] = {index, math.floor(c.width * 1000 / f.size + .5), c.tounicode} p.usedglyphs[index] = {index, math.floor(c.width * 1000 / f.size + .5), c.tounicode}
end end
else else
p.pending[#p.pending+1] = match(literalescape, string.char(n.char)) p.pending[#p.pending+1] = match(literalescape, string.char(getchar(n)))
if not p.usedglyphs[n.char] then if not p.usedglyphs[getchar(n)] then
p.usedglyphs[n.char] = {n.char, math.floor(c.width * 1000 / f.size + .5), c.tounicode} p.usedglyphs[getchar(n)] = {getchar(n), math.floor(c.width * 1000 / f.size + .5), c.tounicode}
end end
end end
p.pos.x = p.pos.x + math.floor(n.width*(1+n.expansion_factor/1000000)+.5) p.pos.x = p.pos.x + math.floor(getwidth(n)*(1+getexpansion(n)/1000000)+.5)
end end
function nodehandler.whatsit(p, n, ...) -- Whatsit? function nodehandler.whatsit(p, n, ...) -- Whatsit?
return whatsithandler[n.subtype](p, n, ...) return whatsithandler[getsubtype(n)](p, n, ...)
end end
--[[ -- These use the old whatsit handling system which might get removed. --[[ -- These use the old whatsit handling system which might get removed.
function whatsithandler.pdf_save(p, n, x, y, outer) function whatsithandler.pdf_save(p, n, x, y, outer)
@ -514,6 +543,7 @@ local function writeresources(p)
end end
local fontnames = setmetatable({}, {__index = function(t, k) local res = format("F%i", k) t[k] = res return res end}) local fontnames = setmetatable({}, {__index = function(t, k) local res = format("F%i", k) t[k] = res return res end})
return function(file, n, fontdirs, usedglyphs, colorstacks) return function(file, n, fontdirs, usedglyphs, colorstacks)
n = todirect(n)
setmetatable(usedglyphs, ondemandmeta) setmetatable(usedglyphs, ondemandmeta)
local linkcontext = file.linkcontext local linkcontext = file.linkcontext
if not linkcontext then if not linkcontext then
@ -552,8 +582,8 @@ return function(file, n, fontdirs, usedglyphs, colorstacks)
end end
end end
end end
nodehandler[n.id](p, n, 0, 0, n, nil, 0) nodehandler[getid(n)](p, n, 0, 0, n, nil, 0)
-- nodehandler[n.id](p, n, 0, n.depth, n) -- nodehandler[getid(n)](p, n, 0, getdepth(n), n)
topage(p) topage(p)
return concat(p.strings, '\n'), writeresources(p), (p.annots[1] and string.format("/Annots[%s]", table.concat(p.annots, ' ')) or "") return concat(p.strings, '\n'), writeresources(p), (p.annots[1] and string.format("/Annots[%s]", table.concat(p.annots, ' ')) or "")
end end

View File

@ -209,7 +209,7 @@ local function buildfont0(pdf, fontdir, usedcids)
local enc local enc
if fontdir.encodingbytes == 1 then if fontdir.encodingbytes == 1 then
enc = cidmap1byte(pdf) enc = cidmap1byte(pdf)
elseif true then -- FIXME: This should only be used for encodingbyzes == -3 (variable, max 3) elseif false then -- FIXME: This should only be used for encodingbyzes == -3 (variable, max 3)
fontdir.encodingbytes = -3 -- FIXME fontdir.encodingbytes = -3 -- FIXME
enc = cidmap3byte(pdf) enc = cidmap3byte(pdf)
else else

View File

@ -27,7 +27,7 @@
\let\savedversionofdump\dump \let\savedversionofdump\dump
\let\dump\relax \let\dump\relax
\input latex.ltx \input latex.ltx
\input luametalatex-baseregisters % \input luametalatex-baseregisters
\let\dump\savedversionofdump \let\dump\savedversionofdump
\let\savedversionofdump\undefined \let\savedversionofdump\undefined
\directlua{fixupluafunctions()}% \directlua{fixupluafunctions()}%

View File

@ -83,7 +83,7 @@ local dir = absdir(os.selfdir)
local dirseparators = {((lpeg.S'\\/'^1 + 1 * lpeg.P':' * lpeg.S'\\/'^-1) * lpeg.Cp() * ((1-lpeg.S'\\/')^0*lpeg.S'\\/'*lpeg.Cp())^0):match(dir)} local dirseparators = {((lpeg.S'\\/'^1 + 1 * lpeg.P':' * lpeg.S'\\/'^-1) * lpeg.Cp() * ((1-lpeg.S'\\/')^0*lpeg.S'\\/'*lpeg.Cp())^0):match(dir)}
-- First step: Find our actual format. -- First step: Find our actual format.
local init_script = format .. "-init.lua" local init_script = format .. "-init.lua"
local texmf_dir = "tex/lualatex/" .. format .. '/' .. init_script local texmf_dir = "tex/luametalatex/" .. format .. '/' .. init_script
local paths = { local paths = {
init_script, init_script,
"share/texmf-local/" .. texmf_dir, "share/texmf-local/" .. texmf_dir,

44
module.lua Normal file
View File

@ -0,0 +1,44 @@
local loaded = package.loaded
local findtable = lpeg.Cf(lpeg.Cc(_G) * (lpeg.C((1-lpeg.P'.')^0) * '.')^0 * lpeg.C((1-lpeg.P'.')^0) * -1,
function(t, name)
local subtable = t[name]
if subtable == nil then
subtable = {}
t[name] = subtable
elseif type(subtable) ~= "table" then
error("Naming conflict for (sub)module " .. name)
end
return subtable
end)
local package_patt = lpeg.C(((1-lpeg.P'.')^0 * '.')^0) * (1-lpeg.P'.')^0 * -1
function module(name, ...)
local modtable = loaded[name]
if type(modtable) ~= "table" then
modtable = findtable:match(name)
loaded[name] = modtable
end
if modtable._NAME == nil then
modtable._M = modtable
modtable._NAME = name
modtable._PACKAGE = package_patt:match(name)
end
local info = debug.getinfo(2, "fS")
if not info or info.what == "C" then
error[['module' should only be called from Lua functions]]
end
debug.setupvalue(info.func, 1, modtable)
for i = 1, select('#', ...) do
local opt = select(i, ...) if type(opt) == "function" then
opt(modtable)
end
end
return modtable
end
function package.seeall(modtable)
local meta = getmetatable(modtable)
if not meta then
meta = {}
setmetatable(modtable, meta)
end
meta.__index = _G
end