OSDN Git Service

Import from old kitagawa_ruby branch (may not work now)
[luatex-ja/luatexja.git] / src / ltj-inputbuf.lua
1 --
2 -- luatexja/ltj-inputbuf.lua
3 --
4
5 luatexja.load_module('charrange'); local ltjc = luatexja.charrange
6
7 require("unicode")
8 local utflen = unicode.utf8.len
9 local utfbyte = unicode.utf8.byte
10 local node_new = node.new
11 local node_free = node.free
12 local id_glyph = node.id('glyph')
13 local getcatcode = tex.getcatcode
14 local ltjc_is_japanese_char_curlist = ltjc.is_japanese_char_curlist
15 local FFFFF = string.char(0xF3,0xBF,0xBF,0xBF)
16
17 --- the following function is modified from jafontspec.lua (by K. Maeda).
18 --- Instead of "%", we use U+FFFFF for suppressing spaces.
19 local function add_comment(buffer)
20    local i = utflen(buffer)
21    while (i>0) and (getcatcode(utfbyte(buffer, i))==1 
22                  or getcatcode(utfbyte(buffer, i))==2) do
23       i=i-1
24    end
25    if i>0 then
26       local c = utfbyte(buffer, i)
27       if c>0x80 then
28          local ct = getcatcode(c)
29          local te = tex.endlinechar
30          local ctl = (te ~= -1) and (getcatcode(te)==5) and (getcatcode(0xFFFFF)==14)
31          -- Is the catcode of endline character is 5 (end-of-line)?
32          -- Is the catcode of U+FFFFF (new comment char) is 14 (comment)?
33          if ((ct==11) or (ct==12)) and ctl then
34             if ltjc_is_japanese_char_curlist(c) then
35                buffer = buffer .. FFFFF -- U+FFFFF
36             end
37          end
38       end
39    end
40    return buffer
41 end
42
43 luatexbase.add_to_callback('process_input_buffer', 
44    add_comment,'ltj.process_input_buffer')
45
46 --EOF