2 -- luatexja/ltj-compat.lua
5 luatexja.load_module('base'); local ltjb = luatexja.base
6 luatexja.load_module('stack'); local ltjs = luatexja.stack
8 -- \kuten, \jis, \euc, \sjis, \ucs, \kansuji
9 local function to_kansuji(num)
10 if not num then num=0; return
12 num = -num; tex.write('-')
17 ltjs.get_penalty_table(luatexja.stack_table_index.KSJ + num%10,
18 '', tex.getcount('ltj@@stack'))) .. s
19 num=math.floor(num/10)
25 local function from_ucs(i)
26 if type(i)~='number' then
27 ltjb.package_error('luatexja',
28 "invalid character code (".. tostring(i) .. ")",
29 "I'm going to use 0 instead of that illegal character code.")
35 -- \kuten: 面区点 (それぞれで16進2桁を使用)=> Unicode 符号位置
36 local function from_kuten(i)
37 if type(i)~='number' then
38 ltjb.package_error('luatexja',
39 "invalid character code (".. tostring(i) .. ")",
40 "I'm going to use 0 instead of that illegal character code.")
43 tex.write(tostring(luatexja.jisx0208.table_jisx0208_uptex[i] or 0))
46 -- \euc: EUC-JP による符号位置 => Unicode 符号位置
47 local function from_euc(i)
48 if type(i)~='number' then
49 ltjb.package_error('luatexja',
50 "invalid character code (".. tostring(i) .. ")",
51 "I'm going to use 0 instead of that illegal character code.")
53 elseif i>=0x10000 or i<0xa0a0 then
59 -- \jis: ISO-2022-JP による符号位置 => Unicode 符号位置
60 local function from_jis(i)
61 if (type(i)~='number') or i>=0x10000 or i<0 then
62 ltjb.package_error('luatexja',
63 "invalid character code (".. tostring(i) .. ")",
64 "I'm going to use 0 instead of that illegal character code.")
70 -- \sjis: Shift_JIS による符号位置 => Unicode 符号位置
71 local function from_sjis(i)
72 if (type(i)~='number') or i>=0x10000 or i<0 then
73 ltjb.package_error('luatexja',
74 "invalid character code (".. tostring(i) .. ")",
75 "I'm going to use 0 instead of that illegal character code.")
76 tex.write('0'); return
78 local c2 = math.floor(i/256)
80 local shift_jisx0213_s1a3_table = {
81 { [false]= 1, [true]= 8},
82 { [false]= 3, [true]= 4},
83 { [false]= 5, [true]=12},
84 { [false]=13, [true]=14},
87 if c2 >= 0xF0 then -- this if block won't be true
88 if (c2 <= 0xF3 or (c2 == 0xF4 and c1 < 0x9F)) then
89 c2 = 0x100 + shift_jisx0213_s1a3_table[c2 - 0xF0 + 1][(0x9E < c1)];
91 c2 = c2 * 2 - 413 + 0x100; if 0x9E < c1 then c2=c2+1 end
94 if c2<=0x9f then i=0x101 else i=0x181 end
95 c2 = c2 + c2 - i; if 0x9E < c1 then c2=c2+1 end
98 if c1>0x7f then i=0x40 else i=0x3f end
103 from_kuten(c2*256+c1)
109 from_kuten = from_kuten,
111 from_sjis = from_sjis,
113 to_kansuji = to_kansuji,