OSDN Git Service

Initial Commit.
[luatex-ja/luatexja.git] / src / luatexja-core-aux.lua
1
2 --  和文文字と満たす unicode の範囲(適当)
3 function ltj.is_ucs_in_japanese_char(c)
4    if (c>=0x2000)and(c<=0x27FF) then return true
5    elseif (c>=0x2900)and(c<=0x29FF) then return true
6    elseif (c>=0x3000)and(c<=0x30FF) then return true
7    elseif (c>=0x31F0)and(c<=0x4DBF) then return true
8    elseif (c>=0x4E00)and(c<=0x9FFF) then return true
9    elseif (c>=0xF900)and(c<=0xFAFF) then return true
10    elseif (c>=0xFF00)and(c<=0xFFEF) then return true
11    elseif (c>=0x20000)and(c<=0xDFFFF) then return true
12    else return false
13    end
14 end
15
16
17 -- gb: 前側の和文文字 b 由来の glue/kern (maybe nil)
18 -- ga: 後側の和文文字 a 由来の glue/kern (maybe nil)
19 -- 両者から,b と a の間に入る glue/kern を計算する
20
21 function ltj.calc_between_two_jchar_aux(gb,ga)
22    if not gb then 
23       return ga
24    else
25       if not ga then return gb end
26       local k = node.type(gb.id) .. node.type(ga.id)
27       if k == 'glueglue' then 
28          -- 両方とも glue.平均をとる
29          gb.spec.width   = tex.round((gb.spec.width+ga.spec.width)/2)
30          gb.spec.stretch = tex.round((gb.spec.stretch+ga.spec.shrink)/2)
31          gb.spec.shrink  = tex.round((gb.spec.shrink+ga.spec.shrink)/2)
32       elseif k == 'kernkern' then
33          -- 両方とも kern.平均をとる
34          gb.kern = tex.round((gb.kern+ga.kern)/2)
35       elseif k == 'kernglue' then 
36          -- gb: kern, ga: glue
37          return ga
38       else
39          -- gb: glue, ga: kern
40          return gb
41       end
42    end
43 end