OSDN Git Service

Added luatexja.node_remove and luatexja.Dnode_remove ("safe node.remove")
[luatex-ja/luatexja.git] / src / ltj-rmlgbm.lua
index e08cbf1..b81c269 100644 (file)
@@ -1,26 +1,13 @@
 --
--- luatexja/rmlgbm.lua
+-- luatexja/ltj-rmlgbm.lua
 --
-luatexbase.provides_module({
-  name = 'luatexja.rmlgbm',
-  date = '2013/05/14',
-  description = 'Definitions of non-embedded Japanese (or other CJK) fonts',
-})
-module('luatexja.rmlgbm', package.seeall)
-local err, warn, info, log = luatexbase.errwarinf(_NAME)
-
 luatexja.load_module('base');      local ltjb = luatexja.base
 
-cidfont_data = {}
-local cidfont_data = cidfont_data
+local cidfont_data = {}
 local cache_chars = {}
-local path           = {
-    localdir  = file.join(kpse.expand_var("$TEXMFVAR"), aux_dir),
-    systemdir = file.join(kpse.expand_var("$TEXMFSYSVAR"), aux_dir),
-}
+local cache_ver = '2'
 
 local cid_reg, cid_order, cid_supp, cid_name
-local taux_dir = 'luatex-cache/luatexja'
 local cid_replace = {
    ["Adobe-Japan1"] = {"UniJIS2004-UTF32", 23057, 6,
                       function (i)
@@ -56,6 +43,7 @@ local cid_replace = {
 }
 
 -- reading CID maps
+local make_cid_font
 do
    local line, fh -- line, file handler
    local tt,cidm -- characters, cid->(Unicode)
@@ -117,7 +105,7 @@ do
    local function entry(a)     
       return {index = a} 
    end
-   function make_cid_font()
+   make_cid_font = function ()
       local kx = cid_replace[cid_name]
       if not kx then return end
       local k = {
@@ -184,42 +172,23 @@ do
       end
 
       -- Save
-      local savepath  = path.localdir .. '/luatexja/'
-      if not lfs.isdir(savepath) then
-         dir.mkdirs(savepath)
-      end
-      savepath = file.join(savepath, "ltj-cid-auto-" 
-                           .. string.lower(cid_name)  .. ".lua")
-      if file.iswritable(savepath) then
-         k.characters[46].width = math.floor(655360/14);
-        -- Standard fonts are ``seriffed''. 
-         table.tofile(savepath, k,'return', false, true, false )
-         ltjb.package_info_no_line('luatexja', "saved :'" .. savepath .. "'", '')
-      else 
-         ltjb.package_warning_no_line('luatexja', "failed to save to '" .. savepath .. "'", '')
-      end
+      k.characters[46].width = math.floor(655360/14);
+      ltjb.save_cache( "ltj-cid-auto-" .. string.lower(cid_name),
+                      {
+                         version = cache_ver,
+                         k,
+                      })
    end
 end
-local make_cid_font = make_cid_font
 
 -- 
-local function cid_cache_load(fullpath)
-   cidfont_data[cid_name] = require(fullpath)
-   cache_chars[cid_name]  = { [655360] = cidfont_data[cid_name].characters }
-end
-
+local function cid_cache_outdated(t) return t.version~=cache_ver end
 local function read_cid_font()
-   -- local v = "ltj-cid-" .. string.lower(cid_name) .. ".lua"
-   local v = "ltj-cid-auto-" .. string.lower(cid_name) .. ".lua"
-   local localpath  = file.join(path.localdir .. '/luatexja', v)
-   local systempath = file.join(path.systemdir .. '/luatexja' , v)
-   local kpsefound  = kpse.find_file(v)
-   if kpsefound and file.isreadable(kpsefound) then
-      cid_cache_load(kpsefound)
-   elseif file.isreadable(localpath)  then
-      cid_cache_load(localpath)
-   elseif file.isreadable(systempath) then
-      cid_cache_load(systempath)
+   local dat = ltjb.load_cache("ltj-cid-auto-" .. string.lower(cid_name),
+                              cid_cache_outdated )
+   if dat then 
+      cidfont_data[cid_name] = dat[1]
+      cache_chars[cid_name]  = { [655360] = cidfont_data[cid_name].characters }
    else
       -- Now we must create the virtual metrics from CMap.
       make_cid_font()
@@ -324,7 +293,7 @@ local function mk_rml(name, size, id)
    return fontdata
 end
 
-function font_callback(name, size, id, fallback)
+local function font_callback(name, size, id, fallback)
    local p = utf.find(name, ":") or utf.len(name)+1
    if utf.sub(name, 1, p-1) == 'psft' then
       local s = "Adobe-Japan1-6"
@@ -370,3 +339,9 @@ end
 
 cid_reg, cid_order, cid_name, cid_supp = 'Adobe', 'Japan1', 'Adobe-Japan1'
 read_cid_font()
+
+
+luatexja.rmlgbm = {
+   cidfont_data = cidfont_data,
+   font_callback = font_callback,
+}