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 -- \kuten, \jis, \euc, \sjis, \ucs, \kansuji
14 function to_kansuji(num)
15 if not num then num=0; return
17 num = -num; tex.write('-')
22 luatexja.stack.get_penalty_table('ksj', num%10,
23 '', tex.getcount('ltj@@stack'))) .. s
24 num=math.floor(num/10)
30 -- jisx0213.lua: JIS X 0213:2004 から Unicode への対応テーブル.
32 -- "JIS X 0213:2004 8-bit code vs Unicode mapping table".
33 -- (by Project X0213, http://x0213.org/codetable/jisx0213-2004-8bit-std.txt)
35 -- \kuten: 面区点 (それぞれで16進2桁を使用)=> Unicode 符号位置
36 function from_kuten(i)
38 tex.write(luatexja.jisx0213.table_jisx0213_2004[i] or 0)
41 -- \euc: EUC-JIS-2004 による符号位置 => Unicode 符号位置
42 -- 第2面の文字は 0x8f で始まる 16進6桁で指定
43 -- JIS X 0201 (0x8e に続く1バイト)はサポートせず.
45 -- EUC-JIS-2004: (8f)a1a1 => 1(2)
47 elseif i>=0x8f0000 then
49 elseif i>=0x10000 or i<0 then
55 -- \jis: ISO-2011-JP-2004 による符号位置 => Unicode 符号位置
56 -- エスケープシーケンスはサポートせず,第1面の文字のみ指定可能.
59 if (not i) or i>=0x10000 or i<0 then
65 -- \sjis: Shift JIS-2004 による符号位置 => Unicode 符号位置
66 -- JIS X 0201 はサポートせず.
69 if (not i) or i>=0x10000 or i<0 then
70 tex.write('0'); return
72 local c2 = math.floor(i/256)
74 local shift_jisx0213_s1a3_table = {
75 { [false]= 1, [true]= 8},
76 { [false]= 3, [true]= 4},
77 { [false]= 5, [true]=12},
78 { [false]=13, [true]=14},
82 if (c2 <= 0xF3 or (c2 == 0xF4 and c1 < 0x9F)) then
83 c2 = 0x100 + shift_jisx0213_s1a3_table[c2 - 0xF0 + 1][(0x9E < c1)];
85 c2 = c2 * 2 - 413 + 0x100; if 0x9E < c1 then c2=c2+1 end
88 if c2<=0x9f then i=0x101 else i=0x181 end
89 c2 = c2 + c2 - i; if 0x9E < c1 then c2=c2+1 end
92 if c1>0x7f then i=0x40 else i=0x3f end