2 -- luatexja/ltj-compat.lua
5 luatexja.load_module('base'); local ltjb = luatexja.base
6 luatexja.load_module('stack'); local ltjs = luatexja.stack
11 local cache_outdate_fn = function (t) return t.version~=cache_ver end
12 local jisx0208 = ltjb.load_cache('ltj-jisx0208',cache_outdate_fn)
13 if not jisx0208 then -- make cache
14 jisx0208 = require('ltj-jisx0208.lua')
15 ltjb.save_cache_luc('ltj-jisx0208', jisx0208)
19 -- \kuten, \jis, \euc, \sjis, \ucs, \kansuji
20 local function to_kansuji(num)
21 if not num then num=0; return
23 num = -num; tex.write('-')
28 ltjs.get_penalty_table(luatexja.stack_table_index.KSJ + num%10,
29 '', tex.getcount('ltj@@stack'))) .. s
30 num=math.floor(num/10)
36 local function from_ucs(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.")
46 -- \kuten: 面区点 (それぞれで16進2桁を使用)=> Unicode 符号位置
47 local function from_kuten(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.")
54 tex.write(tostring(jisx0208.table_jisx0208_uptex[i] or 0))
57 -- \euc: EUC-JP による符号位置 => Unicode 符号位置
58 local function from_euc(i)
59 if type(i)~='number' then
60 ltjb.package_error('luatexja',
61 "invalid character code (".. tostring(i) .. ")",
62 "I'm going to use 0 instead of that illegal character code.")
64 elseif i>=0x10000 or i<0xa0a0 then
70 -- \jis: ISO-2022-JP による符号位置 => Unicode 符号位置
71 local function from_jis(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.")
81 -- \sjis: Shift_JIS による符号位置 => Unicode 符号位置
82 local function from_sjis(i)
83 if (type(i)~='number') or i>=0x10000 or i<0 then
84 ltjb.package_error('luatexja',
85 "invalid character code (".. tostring(i) .. ")",
86 "I'm going to use 0 instead of that illegal character code.")
87 tex.write('0'); return
89 local c2 = math.floor(i/256)
91 local shift_jisx0213_s1a3_table = {
92 { [false]= 1, [true]= 8},
93 { [false]= 3, [true]= 4},
94 { [false]= 5, [true]=12},
95 { [false]=13, [true]=14},
98 if c2 >= 0xF0 then -- this if block won't be true
99 if (c2 <= 0xF3 or (c2 == 0xF4 and c1 < 0x9F)) then
100 c2 = 0x100 + shift_jisx0213_s1a3_table[c2 - 0xF0 + 1][(0x9E < c1)];
102 c2 = c2 * 2 - 413 + 0x100; if 0x9E < c1 then c2=c2+1 end
105 if c2<=0x9f then i=0x101 else i=0x181 end
106 c2 = c2 + c2 - i; if 0x9E < c1 then c2=c2+1 end
109 if c1>0x7f then i=0x40 else i=0x3f end
114 from_kuten(c2*256+c1)
120 from_kuten = from_kuten,
122 from_sjis = from_sjis,
124 to_kansuji = to_kansuji,