OSDN Git Service

Merge branch 'kmaeda-manual' into kitagawa_test
[luatex-ja/luatexja.git] / src / ltj-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 luatexja.load_module('charrange'); local ltjc = luatexja.charrange
14
15 local node_new = node.new
16 local id_glyph = node.id('glyph')
17
18 --- the following function is modified from jafontspec.lua (by K. Maeda).
19 --- Instead of "%", we use U+FFFFF for suppressing spaces.
20 function add_comment(buffer)
21    local i = utf.len(buffer)
22    while (i>0) and (tex.getcatcode(utf.byte(buffer, i))==1 
23                  or tex.getcatcode(utf.byte(buffer, i))==2) do
24       i=i-1
25    end
26    if i>0 then
27       local c = utf.byte(buffer, i)
28       local ct = tex.getcatcode(c)
29       local ctl = tex.getcatcode(13) -- endline character
30       local ctc = tex.getcatcode(0xFFFFF) -- new comment character
31       if ((ct==11) or (ct==12)) and (ctl==5) and (ctc==14) then
32          local p =  node_new(id_glyph)
33          p.char = c
34          if ltjc.is_ucs_in_japanese_char(p) then
35             buffer = buffer .. string.char(0xF3,0xBF,0xBF,0xBF) -- U+FFFFF
36          end
37          node.free(p)
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