X-Git-Url: http://git.osdn.jp/view?a=blobdiff_plain;f=src%2Fltj-compat.lua;h=6f66b99891ac9ea081ffb0769d6c68ead65ce77c;hb=5732f2cafd59081b3ebdad197be711d11f2fc009;hp=d72cce3313c36754b76d3dfe481ec62ef1b40650;hpb=3baeb74ffa19dbdc7d01bf9703e6ec3c323a3434;p=luatex-ja%2Fluatexja.git diff --git a/src/ltj-compat.lua b/src/ltj-compat.lua index d72cce3..6f66b99 100644 --- a/src/ltj-compat.lua +++ b/src/ltj-compat.lua @@ -1,20 +1,12 @@ -- --- 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 -- \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 +14,7 @@ function to_kansuji(num) local s = "" while num~=0 do s = utf.char( - ltjs.get_penalty_table('ksj', num%10, + ltjs.get_penalty_table(luatexja.stack_table_index.KSJ + num%10, '', tex.getcount('ltj@@stack'))) .. s num=math.floor(num/10) end @@ -30,19 +22,34 @@ 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) .. ")", + "I'm going to use 0 instead of that illegal character code.") + i=0 + end tex.write(i) end -- \kuten: 面区点 (それぞれで16進2桁を使用)=> Unicode 符号位置 -function from_kuten(i) - if not i then i=0 end +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)) end -- \euc: EUC-JP による符号位置 => Unicode 符号位置 -function from_euc(i) - if not i then i=0 +local function from_euc(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 elseif i>=0x10000 or i<0xa0a0 then i=0 end @@ -50,16 +57,22 @@ function from_euc(i) end -- \jis: ISO-2022-JP による符号位置 => Unicode 符号位置 -function from_jis(i) - if (not i) or i>=0x10000 or i<0 then +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) .. ")", + "I'm going to use 0 instead of that illegal character code.") i=0 end from_kuten(i-0x2020) end -- \sjis: Shift_JIS による符号位置 => Unicode 符号位置 -function from_sjis(i) - if (not i) or i>=0x10000 or i<0 then +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) .. ")", + "I'm going to use 0 instead of that illegal character code.") tex.write('0'); return end local c2 = math.floor(i/256) @@ -90,3 +103,13 @@ function from_sjis(i) from_kuten(c2*256+c1) end 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