--
luatexbase.provides_module({
name = 'luatexja.base',
- date = '2011/11/18',
+ date = '2013/12/22',
description = '',
})
module('luatexja.base', package.seeall)
-------------------- cache management
+-- load_cache (filename, outdate)
+-- * filename: without suffix '.lua'
+-- * outdate(t): return true iff the cache is outdated
+-- * return value: non-nil iff the cache is up-to-date
+-- save_cache (filename, t): no return value
+-- save_cache_luc (filename, t): no return value
+-- save_cache always calls save_cache_luc.
+-- But sometimes we want to create only the precompiled cache,
+-- when its 'text' version is already present in LuaTeX-ja distribution.
+
require('lualibs-lpeg') -- string.split
+require('lualibs-os') -- os.type
do
- local path = string.split(
- kpse.expand_var("$TEXMFCACHE;$TEXMFVAR;$TEXMFSYSVAR"), ';'
- )
+ local path = kpse.expand_var("$TEXMFVAR;$TEXMFSYSVAR;$TEXMFCACHE")
+ if os.type~='windows' then path = string.gsub(path, ':', ';') end
+ path = string.split(path, ';')
+
local cache_dir = '/luatexja'
local find_file = kpse.find_file
local join, isreadable = file.join, file.isreadable
+ local tofile, serialize = table.tofile, table.serialize
+ local luc_suffix = jit and '.lub' or '.luc'
-- determine save path
local savepath = ''
if lfs.isdir(testpath) then savepath = testpath; break end
end
- -- filename: WITHOUT suffix '.lua'
+ function save_cache_luc(filename, t)
+ local fullpath = savepath .. '/' .. filename .. luc_suffix
+ local s = serialize(t, 'return', false)
+ if s then
+ local f = io.open(fullpath, 'wb')
+ if f then
+ f:write(string.dump(load(s), true))
+ texio.write('(save cache: ' .. fullpath .. ')')
+ end
+ f:close()
+ end
+ end
+
+ function save_cache(filename, t)
+ local fullpath = savepath .. '/' .. filename .. '.lua'
+ tofile(fullpath, t, 'return', false)
+ texio.write('(save cache: ' .. fullpath .. ')')
+ save_cache_luc(filename, t)
+ end
+
+ local function luc_load (n)
+ texio.write('(load cache: ' .. n .. ')')
+ local f = loadfile(n, 'b'); return f
+ end
function load_cache (filename, outdate)
- local kpsefound = find_file(filename .. '.lua')
- local result
- if kpsefound and isreadable(kpsefound) then
- result = require(kpsefound)
+ local r = load_cache_a(filename .. luc_suffix, outdate, luc_load)
+ if r then
+ return r
else
- for _,v in pairs(path) do
- local fn = join(v, cache_dir, filename .. '.lua')
- if isreadable(fn) then
- result = require(fn); break
- end
+ local r = load_cache_a(filename .. '.lua', outdate, loadfile)
+ if r then save_cache_luc(filename, r) end -- update the precompiled cache
+ return r
+ end
+ end
+
+ function load_cache_a (filename, outdate, loader)
+ local result
+ for _,v in pairs(path) do
+ local fn = join(v, cache_dir, filename)
+ if isreadable(fn) then
+ result = loader(fn)
+ if result then result = result(); break end
end
end
if (not result) or outdate(result) then
end
end
- function save_cache(filename, t)
- local fullpath = savepath .. '/' .. filename .. '.lua'
- table.tofile(fullpath, t, 'return', false, true, false )
- package_info_no_line('luatexja', "save '" .. fullpath .. "'", '')
- end
-
end
-------------------- all done
luatexja.load_module('base'); local ltjb = luatexja.base
luatexja.load_module('stack'); local ltjs = luatexja.stack
+-- load jisx0208 table
+local cache_ver = 2
+
+local cache_outdate_fn = function (t) return t.version~=cache_ver end
+local jisx0208 = ltjb.load_cache('ltj-jisx0208',cache_outdate_fn)
+if not jisx0208 then -- make cache
+ jisx0208 = require('ltj-jisx0208.lua')
+ ltjb.save_cache_luc('ltj-jisx0208', jisx0208)
+end
+
+
-- \kuten, \jis, \euc, \sjis, \ucs, \kansuji
local function to_kansuji(num)
if not num then num=0; return
"I'm going to use 0 instead of that illegal character code.")
i=0
end
- tex.write(tostring(luatexja.jisx0208.table_jisx0208_uptex[i] or 0))
+ tex.write(tostring(jisx0208.table_jisx0208_uptex[i] or 0))
end
-- \euc: EUC-JP による符号位置 => Unicode 符号位置
--
--- luatexja/otf.lua
+-- luatexja/ltj-otf.lua
--
-luatexbase.provides_module({
- name = 'luatexja.otf',
- date = '2013/05/11',
- description = 'The OTF Lua module for LuaTeX-ja',
-})
-
require('unicode')
require('lualibs')
-
luatexja.load_module('base'); local ltjb = luatexja.base
luatexja.load_module('jfont'); local ltjf = luatexja.jfont
luatexja.load_module('rmlgbm'); local ltjr = luatexja.rmlgbm
for _,at in pairs(ga) do
local bu, vsel = at.unicode, (at.variant or -1)
if vsel~=-1 then
+ if vsel>=0xE0100 then vsel = vsel - 0xE0100 end
if not ivs[bu] then ivs[bu] = {} end
uniq_flag = true
for i,_ in pairs(ivs[bu]) do
-- loading and saving
local font_ivs_basename = {} -- key: basename
- local cache_ver = '3'
+ local cache_ver = '4'
local checksum = file.checksum
local function prepare_ivs_data(n, id)
-- test if already loaded
- if type(id)=='number' then
+ if type(id)=='number' then -- sometimes id is an integer
font_ivs_table[n] = font_ivs_table[id]; return
end
local fname = id.filename
font_ivs_table[n] = font_ivs_basename[bname]; return
end
- -- if cache is present; read them
- local newsum = checksum(fname)
+ -- if the cache is present, read it
+ local newsum = checksum(fname) -- MD5 checksum of the fontfile
local v = "ivs_" .. string.lower(file.nameonly(fname))
local dat = ltjb.load_cache(v,
function (t) return (t.version~=cache_ver) or (t.chksum~=newsum) end
)
- -- if cache is not found or outdated, save the cache
+ -- if the cache is not found or outdated, save the cache
if dat then
font_ivs_basename[bname] = dat[1] or {}
else
local qc = q.char
if (qc>=0xFE00 and qc<=0xFE0F) or (qc>=0xE0100 and qc<0xE01F0) then
-- q is a variation selector
+ if qc>=0xE0100 then qc = qc - 0xE0100 end
pt = pt and pt[p.char]; pt = pt and pt[qc]
head = node_remove(head,q)
if pt then
end
end
--------------------- all done
luatexja.otf = {
append_jglyph = append_jglyph,
enable_ivs = enable_ivs, -- 隠し機能: IVS