X-Git-Url: http://git.osdn.jp/view?a=blobdiff_plain;f=src%2Fltj-compat.lua;h=af5da70c41c03aacc5796c538a58d7afbc956616;hb=a693b63eadfcabe5f4f513a4cc90302f2360b18b;hp=6e1da777226846e5cef9f7e0cfe3ba0a7975f097;hpb=cd98a66b6441c0ebbe9af14dccafbb15a0063680;p=luatex-ja%2Fluatexja.git diff --git a/src/ltj-compat.lua b/src/ltj-compat.lua index 6e1da77..af5da70 100644 --- a/src/ltj-compat.lua +++ b/src/ltj-compat.lua @@ -1,20 +1,24 @@ -- --- luatexja/compat.lua +-- luatexja/ltj-compat.lua -- -luatexbase.provides_module({ - name = 'luatexja.compat', - date = '2011/06/03', - version = '0.1', - description = 'Partial implementation of primitives of pTeX', -}) -module('luatexja.compat', package.seeall) -local err, warn, info, log = luatexbase.errwarinf(_NAME) -luatexja.load_module('base'); local ltjb = luatexja.base -luatexja.load_module('stack'); local ltjs = luatexja.stack +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 -function to_kansuji(num) +local function to_kansuji(num) if not num then num=0; return elseif num<0 then num = -num; tex.write('-') @@ -22,7 +26,7 @@ function to_kansuji(num) local s = "" while num~=0 do s = utf.char( - ltjs.get_penalty_table('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 @@ -30,7 +34,7 @@ function to_kansuji(num) end -- \ucs: 単なる identity -function from_ucs(i) +local function from_ucs(i) if type(i)~='number' then ltjb.package_error('luatexja', "invalid character code (".. tostring(i) .. ")", @@ -40,19 +44,19 @@ function from_ucs(i) tex.write(i) end --- \kuten: 面区点 (それぞれで16進2桁を使用)=> Unicharacter code 符号位置 -function from_kuten(i) +-- \kuten: 面区点 (それぞれで16進2桁を使用)=> Unicode 符号位置 +local function from_kuten(i) if type(i)~='number' then ltjb.package_error('luatexja', "invalid character code (".. tostring(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 による符号位置 => Unicharacter code 符号位置 -function from_euc(i) +-- \euc: EUC-JP による符号位置 => Unicode 符号位置 +local function from_euc(i) if type(i)~='number' then ltjb.package_error('luatexja', "invalid character code (".. tostring(i) .. ")", @@ -64,8 +68,8 @@ function from_euc(i) from_kuten(i-0xa0a0) end --- \jis: ISO-2022-JP による符号位置 => Unicharacter code 符号位置 -function from_jis(i) +-- \jis: ISO-2022-JP による符号位置 => Unicode 符号位置 +local function from_jis(i) if (type(i)~='number') or i>=0x10000 or i<0 then ltjb.package_error('luatexja', "invalid character code (".. tostring(i) .. ")", @@ -75,8 +79,8 @@ function from_jis(i) from_kuten(i-0x2020) end --- \sjis: Shift_JIS による符号位置 => Unicharacter code 符号位置 -function from_sjis(i) +-- \sjis: Shift_JIS による符号位置 => Unicode 符号位置 +local function from_sjis(i) if (type(i)~='number') or i>=0x10000 or i<0 then ltjb.package_error('luatexja', "invalid character code (".. tostring(i) .. ")", @@ -111,3 +115,25 @@ function from_sjis(i) from_kuten(c2*256+c1) 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, + from_jis = from_jis, + from_sjis = from_sjis, + from_ucs = from_ucs, + to_kansuji = to_kansuji, +} +luatexja.compat = t