local join, isreadable = file.join, file.isreadable
local tofile, serialize = table.tofile, table.serialize
local luc_suffix = jit and '.lub' or '.luc'
+ local dump = string.dump
-- determine save path
local savepath = ''
if not lfs.isdir(testpath) then dir.mkdirs(testpath) end
if lfs.isdir(testpath) then savepath = testpath; break end
end
-
+ local serial_spec = {functions=false, noquotes=true}
local function save_cache_luc(filename, t, serialized)
local fullpath = savepath .. '/' .. filename .. luc_suffix
- local s = serialized or serialize(t, 'return', false)
+ local s = serialized or serialize(t, 'return', false, serial_spec)
if s then
local sa = load(s)
local f = io.open(fullpath, 'wb')
if f and sa then
- f:write(string.dump(sa, true))
+ f:write(dump(sa, true))
texio.write('(save cache: ' .. fullpath .. ')')
+ f:close()
end
- f:close()
end
end
local function save_cache(filename, t)
local fullpath = savepath .. '/' .. filename .. '.lua'
- local s = serialize(t, 'return', false)
+ local s = serialize(t, 'return', false, serial_spec)
if s then
- local f = io.open(fullpath, 'w')
+ local f = io.open(fullpath, 'wb')
if f then
- f:write(s)
+ f:write(s)
texio.write('(save cache: ' .. fullpath .. ')')
+ f:close()
end
- f:close()
save_cache_luc(filename, t, s)
end
end
local result
for _,v in pairs(path) do
local fn = join(v, cache_dir, filename)
- if isreadable(fn) then
+ if isreadable(fn) then
texio.write('(load cache: ' .. fn .. ')')
result = loadfile(fn)
- result = result and result(); break
+ result = result and result()
+ break
end
end
if (not result) or outdate(result) then
--
luatexbase.provides_module({
name = 'luatexja.jfont',
- date = '2020-05-17',
+ date = '2020-06-14',
description = 'Loader for Japanese fonts',
})
end
do
+ local cache_ver = 20
local nameonly, lower = file.nameonly, string.lower
+ local lfs = require"lfs"
+ local file_attributes = lfs.attributes
+ local load_cache, save_cache = ltjb.load_cache, ltjb.save_cache
local function prepare_extra_data_base(tfmdata)
if (not tfmdata) or (not tfmdata.filename) then return end
local bname = tfmdata.psname or nameonly(tfmdata.filename)
if not font_extra_basename[bname] then
- ltjb.remove_cache("extra_" .. lower(bname)) -- remove cache
- local dest = ltju.get_vmet_table(tfmdata, dest)
- dest = list_rotate_glyphs(tfmdata, dest)
- font_extra_basename[bname] = dest or {}
+ -- if the cache is present, read it
+ --
+ local newtime = file_attributes(tfmdata.filename,"modification")
+ local v = "extra_" .. string.lower(bname)
+ local dest = load_cache(
+ v,
+ function (t) return (t.version~=cache_ver) or (t.modtime~=newtime) end
+ )
+ -- if the cache is not found or outdated, save the cache
+ if dest then
+ font_extra_basename[bname] = dest[1] or {}
+ else
+ local dest = ltju.get_vmet_table(tfmdata, nil)
+ dest = list_rotate_glyphs(tfmdata, dest)
+ font_extra_basename[bname] = dest or {}
+ save_cache( v,
+ {
+ modtime = newtime,
+ version = cache_ver,
+ dest,
+ })
+ end
return bname
end
end