OSDN Git Service

Rewrited process_input_buffer callback (ticket #25231).
[luatex-ja/luatexja.git] / src / luatexja / inputbuf.lua
1 --
2 -- luatexja/inputbuf.lua
3 --
4 luatexbase.provides_module({
5   name = 'luatexja.inputbuf',
6   date = '2011/04/01',
7   version = '0.1',
8   description = 'Supressing a space by newline after Japanese characters',
9 })
10 module('luatexja.inputbuf', package.seeall)
11 local err, warn, info, log = luatexbase.errwarinf(_NAME)
12
13 local node_new = node.new
14 local id_glyph = node.id('glyph')
15
16 --- the following function is modified from jafontspec.lua (by K. Maeda).
17 --- Instead of "%", we use U+FFFFF for suppressing spaces.
18 function add_comment(buffer)
19    local i = utf.len(buffer)
20    while (i>0) and (tex.getcatcode(utf.byte(buffer, i))==1 
21                  or tex.getcatcode(utf.byte(buffer, i))==2) do
22       i=i-1
23    end
24    if i>0 then
25       local c = utf.byte(buffer, i)
26       local ct = tex.getcatcode(c)
27       if (ct==11) or (ct==12) then
28          local p =  node.new(id_glyph)
29          p.char = c
30          if luatexja.charrange.is_ucs_in_japanese_char(p) then
31             buffer = buffer .. string.char(0xF3,0xBF,0xBF,0xBF) -- U+FFFFF
32          end
33          node.free(p)
34       end
35    end
36    return buffer
37 end
38
39 luatexbase.add_to_callback('process_input_buffer', 
40    add_comment,'ltj.process_input_buffer')
41
42 --EOF