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 utfchar, floor = utf.char, math.floor
21 local texwrite, getcount = tex.write, tex.getcount
22 local cnt_stack = luatexbase.registernumber 'ltj@@stack'
23 local KSJ = luatexja.stack_table_index.KSJ
24 local get_stack_table = ltjs.get_stack_table
25 local function to_kansuji(num)
26 if not num then num=0; return
27 elseif num<0 then num = -num; texwrite '-'
31 s = utfchar(get_stack_table(KSJ + num%10, '', getcount(cnt_stack))) .. s
37 local function error_invalid_charcode(i)
38 ltjb.package_error('luatexja',
39 "invalid character code (".. tostring(i) .. ")",
40 "I'm going to use 0 instead of that illegal character code.")
44 local function from_ucs(i)
45 if type(i)~='number' then error_invalid_charcode(i); i=0 end
49 -- \kuten: 面区点 (それぞれで16進2桁を使用)=> Unicode 符号位置
50 local function from_kuten(i)
51 if type(i)~='number' then error_invalid_charcode(i); i=0 end
52 if (i%256==0)or(i%256>94) then
55 texwrite(tostring(jisx0208.table_jisx0208_uptex[(i//256)*94+(i%256)-94] or 0))
59 -- \euc: EUC-JP による符号位置 => Unicode 符号位置
60 local function from_euc(i)
61 if type(i)~='number' then
62 error_invalid_charcode(i); i=0
63 elseif i>=0x10000 or i<0xa0a0 then
69 -- \jis: ISO-2022-JP による符号位置 => Unicode 符号位置
70 local function from_jis(i)
71 if type(i)~='number' then error_invalid_charcode(i); i=0 end
75 -- \sjis: Shift_JIS による符号位置 => Unicode 符号位置
76 local function from_sjis(i)
77 if (type(i)~='number') or i>=0x10000 or i<0 then
78 error_invalid_charcode(i); texwrite '0'; return
80 local c2, c1 = i//256, i%256
81 local shift_jisx0213_s1a3_table = {
82 { [false]= 1, [true]= 8},
83 { [false]= 3, [true]= 4},
84 { [false]= 5, [true]=12},
85 { [false]=13, [true]=14},
88 if c2 >= 0xF0 then -- this if block won't be true
89 if (c2 <= 0xF3 or (c2 == 0xF4 and c1 < 0x9F)) then
90 c2 = 0x100 + shift_jisx0213_s1a3_table[c2 - 0xF0 + 1][(0x9E < c1)];
92 c2 = c2 * 2 - 413 + 0x100; if 0x9E < c1 then c2=c2+1 end
95 if c2<=0x9f then i=0x101 else i=0x181 end
96 c2 = c2 + c2 - i; if 0x9E < c1 then c2=c2+1 end
99 if c1>0x7f then i=0x40 else i=0x3f end; c1 = c1 - i
103 from_kuten(c2*256+c1)
107 luatexja.binary_pars.kansujichar = function(c, t)
108 if type(c)~='number' or c<0 or c>9 then
109 ltjb.package_error('luatexja',
110 'Invalid KANSUJI number (' .. tostring(c) .. ')',
111 'A KANSUJI number should be in the range 0..9.\n'..
112 'So I changed this one to zero.')
115 return get_stack_table(KSJ + c, 0, t)
120 from_euc = from_euc, from_kuten = from_kuten,
121 from_jis = from_jis, from_sjis = from_sjis,
122 from_ucs = from_ucs, to_kansuji = to_kansuji,