2020-07-15 04:51:59 +02:00
|
|
|
local readfile = require'luametalatex-readfile'
|
|
|
|
|
2019-07-17 21:14:34 +02:00
|
|
|
local purenumber = lpeg.R'09'^1
|
|
|
|
local optoperator = lpeg.C(lpeg.S'+-='^-1)*lpeg.C(lpeg.P(1)^0)
|
|
|
|
local commentchar = lpeg.S' %*;#'+-1
|
|
|
|
local wordpatt = (lpeg.C('"') * lpeg.C((1-lpeg.P'"')^0) * lpeg.P'"'^-1 + lpeg.C(('<' * lpeg.S'<['^-1)^-1) * lpeg.S' \t'^0 * lpeg.C((1-lpeg.S' \t')^0)) * lpeg.S' \t'^0 * lpeg.Cp()
|
|
|
|
local fontmap = {}
|
|
|
|
local function mapline(line, operator)
|
|
|
|
if not operator then
|
|
|
|
operator, line = optoperator:match(line)
|
|
|
|
end
|
|
|
|
if commentchar:match(line) then return end
|
|
|
|
local pos = 1
|
|
|
|
local tfmname, psname, flags, special, enc, font, subset
|
|
|
|
local kind, word
|
|
|
|
while pos ~= #line+1 do
|
|
|
|
kind, word, pos = wordpatt:match(line, pos)
|
|
|
|
if kind == "" then
|
|
|
|
if not tfmname then tfmname = word
|
|
|
|
elseif not psname and not purenumber:match(word) then
|
|
|
|
psname = word
|
|
|
|
elseif purenumber:match(word) then flags = tonumber(word)
|
|
|
|
else
|
|
|
|
error[[Invalid map file line, excessive simple words]]
|
|
|
|
end
|
|
|
|
elseif kind == '"' then
|
|
|
|
special = word
|
|
|
|
else
|
|
|
|
if kind == "<[" or (kind ~= "<<" and word:sub(-4) == ".enc") then
|
|
|
|
enc = word
|
|
|
|
else
|
|
|
|
font = word
|
|
|
|
subset = kind ~= "<<"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
fontmap[tfmname] = {psname or tfmname, flags or (font and 4 or 0x22), font, enc, special, subset}
|
|
|
|
end
|
|
|
|
local function mapfile(filename, operator)
|
|
|
|
if not operator then
|
|
|
|
operator, filename = optoperator:match(filename)
|
|
|
|
end
|
2020-07-15 16:36:11 +02:00
|
|
|
local file <close> = readfile('map', filename)
|
2019-07-17 21:14:34 +02:00
|
|
|
for line in file:lines() do mapline(line, operator) end
|
|
|
|
end
|
2020-06-19 16:33:48 +02:00
|
|
|
local function reset()
|
|
|
|
for k in next, fontmap do
|
|
|
|
fontmap[k] = nil
|
|
|
|
end
|
|
|
|
end
|
2019-07-17 21:14:34 +02:00
|
|
|
return {
|
2020-06-19 16:33:48 +02:00
|
|
|
reset = reset,
|
2019-07-17 21:14:34 +02:00
|
|
|
mapline = mapline,
|
|
|
|
mapfile = mapfile,
|
|
|
|
fontmap = fontmap
|
|
|
|
}
|