OSDN Git Service

Added luatexja.node_remove and luatexja.Dnode_remove ("safe node.remove")
[luatex-ja/luatexja.git] / src / ltj-compat.lua
index 6f66b99..af5da70 100644 (file)
@@ -4,6 +4,18 @@
 
 luatexja.load_module('base');   local ltjb = luatexja.base
 luatexja.load_module('stack');  local ltjs = luatexja.stack
+local stack_table_index = luatexja.stack_table_index
+
+-- 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)
@@ -14,7 +26,7 @@ local function to_kansuji(num)
    local s = ""
    while num~=0 do
       s = utf.char(
-        ltjs.get_penalty_table(luatexja.stack_table_index.KSJ + num%10,
+        ltjs.get_stack_table(luatexja.stack_table_index.KSJ + num%10,
                                '', tex.getcount('ltj@@stack'))) .. s
       num=math.floor(num/10)
    end
@@ -40,7 +52,7 @@ local function from_kuten(i)
                         "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 符号位置
@@ -104,6 +116,18 @@ local function from_sjis(i)
   end
 end
 
+luatexja.binary_pars.kansujichar = function(c, t)
+   if type(c)~='number' or c<0 or c>9 then
+      ltjb.package_error('luatexja',
+                        'Invalid KANSUJI number (' .. tostring(c) .. ')',
+                        'A KANSUJI number should be in the range 0..9.\n'..
+                           'So I changed this one to zero.')
+      c=0
+   end
+   return ltjs.get_stack_table(stack_table_index.KSJ + c, 0, t)
+end
+
+
 local t = {
    from_euc   = from_euc,
    from_kuten = from_kuten,