OSDN Git Service

fix typo, and regenerated pdfs
[luatex-ja/luatexja.git] / src / ltj-inputbuf.lua
1 --
2 -- ltj-inputbuf.lua
3 --
4
5 luatexja.load_module 'base';      local ltjb = luatexja.base
6 luatexja.load_module 'charrange'; local ltjc = luatexja.charrange
7
8 local utflen = utf.len
9 local utfbyte = utf.byte
10 local utfchar = utf.char
11 local node_new = node.new
12 local node_free = node.free
13 local id_glyph = node.id 'glyph'
14 local getcatcode, getcount = tex.getcatcode, tex.getcount
15 local ltjc_is_japanese_char_curlist = ltjc.is_japanese_char_curlist
16
17 --- the following function is modified from jafontspec.lua (by K. Maeda).
18 --- Instead of "%", we use U+FFFFF for suppressing spaces.
19 --DEBUG require"socket"
20 local time_line = 0
21 local start_time_measure, stop_time_measure
22    = ltjb.start_time_measure, ltjb.stop_time_measure
23 local function add_comment(buffer)
24    start_time_measure 'inputbuf'
25    local i = utflen(buffer)
26    local c = utfbyte(buffer, i)
27    while (i>0) and (getcatcode(c)==1 or getcatcode(c)==2) do
28       i=i-1; if (i>0) then c = utfbyte(buffer, i) end;
29    end
30    if i>0 then
31       if c>=0x80 then
32          local te = tex.endlinechar
33          -- Is the catcode of endline character is 5 (end-of-line)?
34          if (te ~= -1) and (getcatcode(te)==5) then
35             local ct = getcatcode(c)
36             if (ct==11) or (ct==12) then
37                local lec = getcount 'ltjlineendcomment'
38                -- Is the catcode of \ltjlineendcomment (new comment char) is 14 (comment)?
39                if ltjc_is_japanese_char_curlist(c) and (getcatcode(lec)==14) then
40                   stop_time_measure 'inputbuf'; return buffer .. utfchar(lec)
41                end
42             end
43          end
44       end
45    end
46    stop_time_measure 'inputbuf'
47    return buffer
48 end
49
50 luatexbase.add_to_callback('process_input_buffer',
51    add_comment,'ltj.process_input_buffer')
52
53 --EOF