Prepare for interpreting extra attributes in map

This commit is contained in:
Marcel Krüger 2020-06-19 16:33:48 +02:00
parent 9f4c671114
commit 599ae713e3
3 changed files with 8 additions and 70 deletions

View File

@ -37,42 +37,17 @@ font.read_tfm = read_tfm
font.read_vf = read_vf
local callback_register = callback.register
require'module'
font.fonts = {}
function font.getfont(id)
return font.fonts[id]
end
pdf = {
getfontname = function(id) -- No font sharing
return id
end,
variable = {},
}
local olddefinefont = font.define
function font.define(f)
local i = olddefinefont(f)
font.fonts[i] = f
return i
end
require'luametalatex-font-resolve' -- Replace font.define
local function base_define_font_cb(name, size)
local f = read_tfm(name, size)
if not f then return end
local vf = read_vf(name, size)
if vf then
local fonts = {}
f.fonts = fonts
for i, f in next, vf.fonts do
if vf.id then
fonts[i] = f
else
fonts[i] = {id = assert(base_define_font_cb(f.name, f.size))}
end
end
f.type = 'virtual'
local realchars = f.characters
for cp, char in next, vf.characters do
assert(realchars[cp]).commands = char.commands
end
end
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)

View File

@ -42,7 +42,13 @@ local function mapfile(filename, operator)
for line in file:lines() do mapline(line, operator) end
file:close()
end
local function reset()
for k in next, fontmap do
fontmap[k] = nil
end
end
return {
reset = reset,
mapline = mapline,
mapfile = mapfile,
fontmap = fontmap

View File

@ -1,5 +1,3 @@
local mapping = require'luametalatex-pdf-font-map'
mapping.mapfile(kpse.find_file('pdftex.map', 'map', true))
local tounicode = {
[-3] = require'luametalatex-pdf-font-cmap3',
require'luametalatex-pdf-font-cmap1',
@ -224,48 +222,7 @@ local function buildfont0(pdf, fontdir, usedcids)
touni,
cidfont)
end
local fontextensions = {
ttf = {"truetype", "truetype fonts",},
otf = {"opentype", "opentype fonts",},
pfb = {"type1", "type1 fonts",},
}
fontextensions.cff = fontextensions.otf
local fontformats = {
fontextensions.pfb, fontextensions.otf, fontextensions.ttf,
}
return function(pdf, fontdir, usedcids)
if fontdir.encodingbytes == 0 then fontdir.encodingbytes = nil end
if fontdir.format == "unknown" or not fontdir.format or fontdir.encodingbytes == 1 then -- TODO: How to check this?
fontdir.encodingbytes = fontdir.encodingbytes or 1
local mapentry = mapping.fontmap[fontdir.name]
if mapentry then
local format = mapentry[3] and mapentry[3]:sub(-4, -4) == '.' and fontextensions[mapentry[3]:sub(-3, -1)]
if format then
fontdir.format = format[1]
fontdir.filename = kpse.find_file(mapentry[3], format[2])
if mapentry[4] then
fontdir.encoding = kpse.find_file(mapentry[4], 'enc files')
end
goto format_set
else
for _, format in ipairs(fontformats) do
local font = kpse.find_file(mapentry[3],format[2])
if font then
fontdir.format = "type1"
fontdir.filename = font
if mapentry[4] then
fontdir.encoding = kpse.find_file(mapentry[4], 'enc files')
end
goto format_set
end
end
end
end
fontdir.format = "type3"
::format_set::
else
fontdir.encodingbytes = fontdir.encodingbytes or 2
end
if fontdir.format == "type3" then
error[[Currently unsupported]] -- TODO
else