summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/luatex/luatexja/ltj-compat.lua
diff options
context:
space:
mode:
authorNorbert Preining <preining@logic.at>2012-04-24 00:13:14 +0000
committerNorbert Preining <preining@logic.at>2012-04-24 00:13:14 +0000
commit8f29bdce0bdd08ec81df555e98692d1f288c3289 (patch)
treec4f9a6b00a587f635e55fc4068c1961780c90591 /Master/texmf-dist/tex/luatex/luatexja/ltj-compat.lua
parent74e624196144ae218a63a4c35672fc7a0e7b18dc (diff)
new package luatexja (24apr)
adapt ctan2tds to deal with it git-svn-id: svn://tug.org/texlive/trunk@26115 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/tex/luatex/luatexja/ltj-compat.lua')
-rw-r--r--Master/texmf-dist/tex/luatex/luatexja/ltj-compat.lua92
1 files changed, 92 insertions, 0 deletions
diff --git a/Master/texmf-dist/tex/luatex/luatexja/ltj-compat.lua b/Master/texmf-dist/tex/luatex/luatexja/ltj-compat.lua
new file mode 100644
index 00000000000..c21e2616219
--- /dev/null
+++ b/Master/texmf-dist/tex/luatex/luatexja/ltj-compat.lua
@@ -0,0 +1,92 @@
+--
+-- luatexja/compat.lua
+--
+luatexbase.provides_module({
+ name = 'luatexja.compat',
+ date = '2011/06/03',
+ version = '0.1',
+ description = 'Partial implementation of primitives of pTeX',
+})
+module('luatexja.compat', package.seeall)
+local err, warn, info, log = luatexbase.errwarinf(_NAME)
+
+luatexja.load_module('base'); local ltjb = luatexja.base
+luatexja.load_module('stack'); local ltjs = luatexja.stack
+
+-- \kuten, \jis, \euc, \sjis, \ucs, \kansuji
+function to_kansuji(num)
+ if not num then num=0; return
+ elseif num<0 then
+ num = -num; tex.write('-')
+ end
+ local s = ""
+ while num~=0 do
+ s = utf.char(
+ ltjs.get_penalty_table('ksj', num%10,
+ '', tex.getcount('ltj@@stack'))) .. s
+ num=math.floor(num/10)
+ end
+ tex.write(s)
+end
+
+-- \ucs: 単なる identity
+function from_ucs(i)
+ tex.write(i)
+end
+
+-- \kuten: 面区点 (それぞれで16進2桁を使用)=> Unicode 符号位置
+function from_kuten(i)
+ if not i then i=0 end
+ tex.write(tostring(luatexja.jisx0208.table_jisx0208_uptex[i]) or '0')
+end
+
+-- \euc: EUC-JP による符号位置 => Unicode 符号位置
+function from_euc(i)
+ if not i then i=0
+ elseif i>=0x10000 or i<0xa0a0 then
+ i=0
+ end
+ from_kuten(i-0xa0a0)
+end
+
+-- \jis: ISO-2022-JP による符号位置 => Unicode 符号位置
+function from_jis(i)
+ if (not i) or i>=0x10000 or i<0 then
+ i=0
+ end
+ from_kuten(i-0x2020)
+end
+
+-- \sjis: Shift_JIS による符号位置 => Unicode 符号位置
+function from_sjis(i)
+ if (not i) or i>=0x10000 or i<0 then
+ tex.write('0'); return
+ end
+ local c2 = math.floor(i/256)
+ local c1 = i%256
+ local shift_jisx0213_s1a3_table = {
+ { [false]= 1, [true]= 8},
+ { [false]= 3, [true]= 4},
+ { [false]= 5, [true]=12},
+ { [false]=13, [true]=14},
+ { [false]=15 } }
+ if c2 >= 0x81 then
+ if c2 >= 0xF0 then -- this if block won't be true
+ if (c2 <= 0xF3 or (c2 == 0xF4 and c1 < 0x9F)) then
+ c2 = 0x100 + shift_jisx0213_s1a3_table[c2 - 0xF0 + 1][(0x9E < c1)];
+ else -- 78<=k<=94
+ c2 = c2 * 2 - 413 + 0x100; if 0x9E < c1 then c2=c2+1 end
+ end
+ else
+ if c2<=0x9f then i=0x101 else i=0x181 end
+ c2 = c2 + c2 - i; if 0x9E < c1 then c2=c2+1 end
+ end
+ if c1 < 0x9F then
+ if c1>0x7f then i=0x40 else i=0x3f end
+ c1 = c1 - i
+ else
+ c1 = c1 - 0x7e
+ end
+ from_kuten(c2*256+c1)
+ end
+end