5 luatexja.load_module 'base'; local ltjb = luatexja.base
6 luatexja.load_module 'charrange'; local ltjc = luatexja.charrange
9 local utfbyte = utf.byte
10 local utfchar = utf.char
11 local id_glyph = node.id 'glyph'
12 local getcatcode, getcount = tex.getcatcode, tex.getcount
13 local ltjc_is_japanese_char_curlist = ltjc.is_japanese_char_curlist
17 local uchar = utf.char
18 local cd, cp = uchar(0x3099), uchar(0x309A)
19 substituter = (utf.substituter or utf.subtituter) -- typo in lualibs?
21 ['ウ'..cd] = 'ヴ', ['う'..cd] = uchar(0x30F4),
22 ['か'..cd] = 'が', ['カ'..cd] = 'ガ',
23 ['き'..cd] = 'ぎ', ['キ'..cd] = 'ギ',
24 ['く'..cd] = 'ぐ', ['ク'..cd] = 'グ',
25 ['け'..cd] = 'げ', ['ケ'..cd] = 'ゲ',
26 ['こ'..cd] = 'ご', ['コ'..cd] = 'ゴ',
28 ['さ'..cd] = 'ざ', ['サ'..cd] = 'ザ',
29 ['し'..cd] = 'じ', ['シ'..cd] = 'ジ',
30 ['す'..cd] = 'ず', ['ス'..cd] = 'ズ',
31 ['せ'..cd] = 'ぜ', ['セ'..cd] = 'ゼ',
32 ['そ'..cd] = 'ぞ', ['ソ'..cd] = 'ゾ',
34 ['た'..cd] = 'だ', ['タ'..cd] = 'ダ',
35 ['ち'..cd] = 'ぢ', ['チ'..cd] = 'ヂ',
36 ['つ'..cd] = 'づ', ['ツ'..cd] = 'ヅ',
37 ['て'..cd] = 'で', ['テ'..cd] = 'デ',
38 ['と'..cd] = 'ど', ['ト'..cd] = 'ド',
40 ['は'..cd] = 'ば', ['ハ'..cd] = 'バ', ['は'..cp] = 'ぱ', ['ハ'..cp] = 'パ',
41 ['ひ'..cd] = 'び', ['ヒ'..cd] = 'ビ', ['ひ'..cp] = 'ぴ', ['ヒ'..cp] = 'ピ',
42 ['ふ'..cd] = 'ぶ', ['フ'..cd] = 'ブ', ['ふ'..cp] = 'ぷ', ['フ'..cp] = 'プ',
43 ['へ'..cd] = 'べ', ['ヘ'..cd] = 'ベ', ['へ'..cp] = 'ぺ', ['ヘ'..cp] = 'ペ',
44 ['ほ'..cd] = 'ぼ', ['ホ'..cd] = 'ボ', ['ほ'..cp] = 'ぽ', ['ホ'..cp] = 'ポ',
46 ['ゝ'..cd] = 'ゞ', ['ヽ'..cd] = 'ヾ',
47 ['ワ'..cd] = uchar(0x30F7), ['ヰ'..cd] = uchar(0x30F8),
48 ['ヱ'..cd] = uchar(0x30F9), ['ヲ'..cd] = uchar(0x30FA),
52 --- the following function is modified from jafontspec.lua (by K. Maeda).
53 --- Instead of "%", we use U+FFFFF for suppressing spaces.
54 --DEBUG require"socket"
56 local start_time_measure, stop_time_measure
57 = ltjb.start_time_measure, ltjb.stop_time_measure
58 local function add_comment(buffer)
59 start_time_measure 'inputbuf'; buffer = substituter(buffer)
60 local i = utflen(buffer)
61 local c = utfbyte(buffer, i)
62 while (i>0) and (getcatcode(c)==1 or getcatcode(c)==2) do
63 i=i-1; if (i>0) then c = utfbyte(buffer, i) end;
67 local te = tex.endlinechar
68 -- Is the catcode of endline character is 5 (end-of-line)?
69 if (te ~= -1) and (getcatcode(te)==5) then
70 local ct = getcatcode(c)
71 if (ct==11) or (ct==12) then
72 local lec = getcount 'ltjlineendcomment'
73 -- Is the catcode of \ltjlineendcomment (new comment char) is 14 (comment)?
74 if ltjc_is_japanese_char_curlist(c) and (getcatcode(lec)==14) then
75 stop_time_measure 'inputbuf'; return buffer .. utfchar(lec)
81 stop_time_measure 'inputbuf'
85 luatexbase.add_to_callback('process_input_buffer',
86 add_comment,'ltj.process_input_buffer')