X-Git-Url: http://git.osdn.jp/view?a=blobdiff_plain;f=src%2Fltj-compat.lua;h=bc8ac9d6795acc6964dafb877e8c40ed37a4d1a0;hb=ab23049deb6fb90ca689fdf4924b3783f08f8f2e;hp=eb63eb8ff07e82fe00cea3a5bccdef363719e57d;hpb=0590acee45671e6e92769b7a4e5f8683aaec9eb3;p=luatex-ja%2Fluatexja.git diff --git a/src/ltj-compat.lua b/src/ltj-compat.lua index eb63eb8..bc8ac9d 100644 --- a/src/ltj-compat.lua +++ b/src/ltj-compat.lua @@ -2,18 +2,31 @@ -- luatexja/ltj-compat.lua -- -luatexja.load_module('base'); local ltjb = luatexja.base +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) if not num then num=0; return - elseif num<0 then + elseif num<0 then num = -num; tex.write('-') end 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 @@ -22,34 +35,34 @@ end -- \ucs: 単なる identity local function from_ucs(i) - if type(i)~='number' then + 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 + i=0 end tex.write(i) end -- \kuten: 面区点 (それぞれで16進2桁を使用)=> Unicode 符号位置 local function from_kuten(i) - if type(i)~='number' then + 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 + 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 符号位置 local function from_euc(i) - if type(i)~='number' then + 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 - elseif i>=0x10000 or i<0xa0a0 then + elseif i>=0x10000 or i<0xa0a0 then i=0 end from_kuten(i-0xa0a0) @@ -57,7 +70,7 @@ end -- \jis: ISO-2022-JP による符号位置 => Unicode 符号位置 local function from_jis(i) - if (type(i)~='number') or i>=0x10000 or i<0 then + if (type(i)~='number') or i>=0x10000 or i<0 then ltjb.package_error('luatexja', "invalid character code (".. tostring(i) .. ")", "I'm going to use 0 instead of that illegal character code.") @@ -68,19 +81,19 @@ end -- \sjis: Shift_JIS による符号位置 => Unicode 符号位置 local function from_sjis(i) - if (type(i)~='number') or i>=0x10000 or i<0 then + if (type(i)~='number') or i>=0x10000 or i<0 then ltjb.package_error('luatexja', "invalid character code (".. tostring(i) .. ")", "I'm going to use 0 instead of that illegal character code.") - tex.write('0'); return + tex.write('0'); return end local c2 = math.floor(i/256) local c1 = i%256 local shift_jisx0213_s1a3_table = { - { [false]= 1, [true]= 8}, - { [false]= 3, [true]= 4}, - { [false]= 5, [true]=12}, - { [false]=13, [true]=14}, + { [false]= 1, [true]= 8}, + { [false]= 3, [true]= 4}, + { [false]= 5, [true]=12}, + { [false]=13, [true]=14}, { [false]=15 } } if c2 >= 0x81 then if c2 >= 0xF0 then -- this if block won't be true @@ -103,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,