Fix small errors (Esp. a TTF component off by one)

This commit is contained in:
Marcel Krüger 2020-07-16 01:41:42 +02:00
parent 063251b54f
commit e02c78e1b5
2 changed files with 15 additions and 15 deletions

View File

@ -18,11 +18,11 @@ local function addglyph(glyph, usedcids, cidtogid)
local flags, component = string.unpack(">I2I2", glyph, offset) local flags, component = string.unpack(">I2I2", glyph, offset)
local gid = cidtogid[component] local gid = cidtogid[component]
if not gid then if not gid then
gid = #usedcids gid = #usedcids+1
usedcids[gid+1] = {component} usedcids[gid] = {component}
cidtogid[component] = gid cidtogid[component] = gid
end end
glyph = glyph:sub(1, offset+1) .. string.pack(">I2", gid).. glyph:sub(offset+4) glyph = glyph:sub(1, offset+1) .. string.pack(">I2", gid-1).. glyph:sub(offset+4)
offset = flags&32==32 and offset + 4 + (flags&1==1 and 4 or 2) + (flags&8==8 and 2 or (flags&64==64 and 4 or (flags&128==128 and 8 or 0))) offset = flags&32==32 and offset + 4 + (flags&1==1 and 4 or 2) + (flags&8==8 and 2 or (flags&64==64 and 4 or (flags&128==128 and 8 or 0)))
end end
end end
@ -69,7 +69,7 @@ local function readpostnames(buf, i, usedcids, encoding)
return newusedcids return newusedcids
end end
return function(filename, fontid, reencode) return function(filename, fontid, reencode)
local file <close> = readfile('truetype', filename) local file <close> = assert(readfile('truetype', filename))
local buf = file() local buf = file()
local magic, tables = sfnt.parse(buf, 1, fontid) local magic, tables = sfnt.parse(buf, 1, fontid)
if magic ~= "\0\1\0\0" then error[[Invalid TTF font]] end if magic ~= "\0\1\0\0" then error[[Invalid TTF font]] end

View File

@ -7,17 +7,17 @@ local callbacks = require'luametalatex-callbacks'
-- local categories = { data = 1, map = 2, image = 3, subset = 4, font = 5 -- , enc = 6, pdf_stream = 7, pdf_stream = 8, silent = 9} -- local categories = { data = 1, map = 2, image = 3, subset = 4, font = 5 -- , enc = 6, pdf_stream = 7, pdf_stream = 8, silent = 9}
local our_callbacks = { local our_callbacks = {
vf = {'vf', false, 'rb', 'find_vf_file_callback', 'read_vf_file_callback'}, vf = {'vf', false, 'rb', 'find_vf_file', 'read_vf_file'},
tfm = {'tfm', false, 'rb', 'find_font_file_callback', 'read_font_file_callback'}, tfm = {'tfm', false, 'rb', 'find_font_file', 'read_font_file'},
map = {'map', 2, 'rb', 'find_map_file_callback', 'read_map_file_callback'}, map = {'map', 2, 'rb', 'find_map_file', 'read_map_file'},
enc = {'enc', false, 'rb', 'find_enc_file_callback', 'read_enc_file_callback'}, enc = {'enc', false, 'rb', 'find_enc_file', 'read_enc_file'},
type1 = {'type1 fonts', 4, 'rb', 'find_type1_file_callback', 'read_type1_file_callback'}, type1 = {'type1 fonts', 4, 'rb', 'find_type1_file', 'read_type1_file'},
truetype = {'truetype fonts', 4, 'rb', 'find_truetype_file_callback', 'read_truetype_file_callback'}, truetype = {'truetype fonts', 4, 'rb', 'find_truetype_file', 'read_truetype_file'},
opentype = {'opentype fonts', 4, 'rb', 'find_opentype_file_callback', 'read_opentype_file_callback'}, opentype = {'opentype fonts', 4, 'rb', 'find_opentype_file', 'read_opentype_file'},
pk = {'pk', 4, 'rb', 'find_pk_file_callback', 'read_pk_file_callback'}, pk = {'pk', 4, 'rb', 'find_pk_file', 'read_pk_file'},
enc = {'enc files', false, 'rb', 'find_enc_file_callback', 'read_enc_file_callback'}, enc = {'enc files', false, 'rb', 'find_enc_file', 'read_enc_file'},
image = {'tex', 3, 'rb', 'find_image_file_callback', 'read_image_file_callback'}, image = {'tex', 3, 'rb', 'find_image_file', 'read_image_file'},
data = {'tex', 1, 'rb', 'find_data_file_callback', 'read_data_file_callback'}, data = {'tex', 1, 'rb', 'find_data_file', 'read_data_file'},
} }
local start_categories = { [0] = '?', '(', '{', '<', '<', '<<' } local start_categories = { [0] = '?', '(', '{', '<', '<', '<<' }