+-- 縦書き用字形への変換テーブル
+local prepare_vert_data
+do
+ -- local function add_feature_table(tname, src, dest)
+ -- for i,v in pairs(src) do
+ -- if type(v.slookups)=='table' then
+ -- local s = v.slookups[tname]
+ -- if s then
+ -- dest = dest or {}
+ -- dest[i] = dest[i] or {}
+ -- dest[i].vert = dest[i].vert or s
+ -- end
+ -- end
+ -- end
+ -- return dest
+ -- end
+ -- prepare_vert_data = function (dest, id)
+ -- local a = id.resources.sequences
+ -- if a then
+ -- local s = id.shared.rawdata.descriptions
+ -- for i,v in pairs(a) do
+ -- if v.features.vert or v.features.vrt2 then
+ -- dest= add_feature_table(v.subtables[1], s, dest)
+ -- end
+ -- end
+ -- end
+ -- return dest
+ -- end
+ -- -- 縦書き用字形への変換
+ -- function get_vert_glyph(n, chr)
+ -- local fn = font_extra_info[n]
+ -- return (fn and fn[chr] and fn[chr].vert) or chr
+ -- end
+end
+
+--
+do
+ local cache_ver = 6
+ local checksum = file.checksum
+
+ local function prepare_extra_data_base(id)
+ if not id then return end
+ local bname = file.nameonly(id.filename or '')
+ if not font_extra_basename[bname] then
+ -- if the cache is present, read it
+ local newsum = checksum(id.filename) -- MD5 checksum of the fontfile
+ local v = "extra_" .. string.lower(file.nameonly(id.filename))
+ local dat = ltjb.load_cache(
+ v,
+ function (t) return (t.version~=cache_ver) or (t.chksum~=newsum) end
+ )
+ -- if the cache is not found or outdated, save the cache
+ if dat then
+ font_extra_basename[bname] = dat[1] or {}
+ else
+ local dat = nil
+ dat = prepare_fl_data(dat, id)
+ font_extra_basename[bname] = dat or {}
+ ltjb.save_cache( v,
+ {
+ chksum = checksum(id.filename),
+ version = cache_ver,
+ dat,
+ })
+ end
+ return bname
+ end
+ end
+ local function prepare_extra_data_font(id, res)
+ if type(res)=='table' and res.shared then
+ font_extra_info[id] = font_extra_basename[file.nameonly(res.filename)]
+ end
+ end
+ luatexbase.add_to_callback(
+ 'luaotfload.patch_font',
+ function (tfmdata)
+ -- these function is executed one time per one fontfile
+ local bname = prepare_extra_data_base(tfmdata)
+ if bname then supply_vkern_table(tfmdata, bname) end
+ return tfmdata
+ end,
+ 'ltj.prepare_extra_data', 1)
+ luatexbase.add_to_callback(
+ 'luatexja.define_font',
+ function (res, name, size, id)
+ prepare_extra_data_font(id, res)
+ end,
+ 'ltj.prepare_extra_data', 1)
+
+ local nulltable = {} -- dummy
+ ltjr.vert_addfunc = function (n) font_extra_info[n] = nulltable end
+
+ local identifiers = fonts.hashes.identifiers
+ for i=1,font.nextid()-1 do
+ if identifiers[i] then
+ prepare_extra_data_base(identifiers[i])
+ prepare_extra_data_font(i,identifiers[i])
+ end
+ end