4 luatexbase.provides_module({
5 name = 'luatexja.compat',
8 description = 'Partial implementation of primitives of pTeX',
10 module('luatexja.compat', package.seeall)
11 local err, warn, info, log = luatexbase.errwarinf(_NAME)
13 luatexja.load_module('base'); local ltjb = luatexja.base
14 luatexja.load_module('stack'); local ltjs = luatexja.stack
16 -- \kuten, \jis, \euc, \sjis, \ucs, \kansuji
17 function to_kansuji(num)
18 if not num then num=0; return
20 num = -num; tex.write('-')
25 ltjs.get_penalty_table('ksj', num%10,
26 '', tex.getcount('ltj@@stack'))) .. s
27 num=math.floor(num/10)
37 -- \kuten: 面区点 (それぞれで16進2桁を使用)=> Unicode 符号位置
38 function from_kuten(i)
40 tex.write(tostring(luatexja.jisx0208.table_jisx0208_uptex[i]) or '0')
43 -- \euc: EUC-JP による符号位置 => Unicode 符号位置
46 elseif i>=0x10000 or i<0xa0a0 then
52 -- \jis: ISO-2022-JP による符号位置 => Unicode 符号位置
54 if (not i) or i>=0x10000 or i<0 then
60 -- \sjis: Shift_JIS による符号位置 => Unicode 符号位置
62 if (not i) or i>=0x10000 or i<0 then
63 tex.write('0'); return
65 local c2 = math.floor(i/256)
67 local shift_jisx0213_s1a3_table = {
68 { [false]= 1, [true]= 8},
69 { [false]= 3, [true]= 4},
70 { [false]= 5, [true]=12},
71 { [false]=13, [true]=14},
74 if c2 >= 0xF0 then -- this if block won't be true
75 if (c2 <= 0xF3 or (c2 == 0xF4 and c1 < 0x9F)) then
76 c2 = 0x100 + shift_jisx0213_s1a3_table[c2 - 0xF0 + 1][(0x9E < c1)];
78 c2 = c2 * 2 - 413 + 0x100; if 0x9E < c1 then c2=c2+1 end
81 if c2<=0x9f then i=0x101 else i=0x181 end
82 c2 = c2 + c2 - i; if 0x9E < c1 then c2=c2+1 end
85 if c1>0x7f then i=0x40 else i=0x3f end