OSDN Git Service

Regenerated manual PDFs
[luatex-ja/luatexja.git] / src / ltj-stack.lua
1 --
2 -- luatexja/stack.lua
3 --
4 luatexbase.provides_module({
5   name = 'luatexja.stack',
6   date = '2014/05/08',
7   description = 'LuaTeX-ja stack system',
8 })
9 module('luatexja.stack', package.seeall)
10 local err, warn, info, log = luatexbase.errwarinf(_NAME)
11
12 luatexja.load_module('base');      local ltjb = luatexja.base
13
14 --------------------------------------------------------------------------------
15 -- stack table (obeys TeX's grouping)
16 --------------------------------------------------------------------------------
17 local node_new = node.new
18 local id_whatsit = node.id('whatsit')
19 local sid_user = node.subtype('user_defined')
20 local STCK = luatexja.userid_table.STCK
21 local fastcopy = table.fastcopy
22 local setcount = tex.setcount
23 hmode = 0 -- dummy
24
25 charprop_stack_table={};
26 local charprop_stack_table = charprop_stack_table
27 charprop_stack_table[0]={}
28
29
30 function get_stack_level()
31    local i = tex.getcount('ltj@@stack')
32    local j = tex.currentgrouplevel
33    if j > tex.getcount('ltj@@group@level') then
34       i = i+1 -- new stack level
35       local gd = tex.globaldefs
36       if gd~=0 then tex.globaldefs = 0 end
37       --  'tex.globaldefs = 0' is local even if \globaldefs > 0.
38       setcount('ltj@@group@level', j)
39       for k,v in pairs(charprop_stack_table) do -- clear the stack above i
40          if k>=i then charprop_stack_table[k]=nil end
41       end
42       charprop_stack_table[i] = fastcopy(charprop_stack_table[i-1])
43       setcount('ltj@@stack', i)
44       if gd~=0 then tex.globaldefs = gd end
45       if  tex.nest[tex.nest.ptr].mode == -hmode then -- rest. hmode のみ
46          local g = node_new(id_whatsit, sid_user)
47          g.user_id=STCK; g.type=100; g.value=j; node.write(g)
48       end
49    end
50    return i
51 end
52
53 function set_stack_table(m, p)
54    local i = get_stack_level()
55    charprop_stack_table[i][m] = p
56    if luatexja.isglobal=='global' then
57       for j,v in pairs(charprop_stack_table) do
58          charprop_stack_table[j][m] = p
59       end
60    end
61 end
62 local set_stack_table = set_stack_table
63
64 -- EXT
65 function set_stack_perchar(m,c,p,lb,ub)
66    if type(p)~='number' or p<lb or p>ub then
67       ltjb.package_error('luatexja',
68                          "invalid code (".. tostring(p) .. ")",
69                          "The code should in the range "..tostring(lb) .. '..' ..
70                          tostring(ub) .. ".\n" ..
71                       "I'm going to use 0 instead of that illegal code value.")
72       p=0
73    end
74    set_stack_table(m+ltjb.in_unicode(c, true), p)
75 end
76
77 -- EXT
78 function set_stack_font(m,c,p)
79    if type(c)~='number' or c<0 or c>255 then
80       ltjb.package_error('luatexja',
81                          "invalid family number (".. tostring(c) .. ")",
82                          "The family number should in the range 0 .. 255.\n" ..
83                           "I'm going to use 0 instead of that illegal family number.")
84       c=0
85    end
86    set_stack_table(m+c, p)
87 end
88
89 -- EXT: sp: glue_spec
90 function set_stack_skip(m,sp)
91   local i = get_stack_level()
92   if not sp then return end
93   if not charprop_stack_table[i][m] then
94      charprop_stack_table[i][m] = {}
95   end
96   charprop_stack_table[i][m].width   = sp.width
97   charprop_stack_table[i][m].stretch = sp.stretch
98   charprop_stack_table[i][m].shrink  = sp.shrink
99   charprop_stack_table[i][m].stretch_order = sp.stretch_order
100   charprop_stack_table[i][m].shrink_order  = sp.shrink_order
101   if luatexja.isglobal=='global' then
102      for j,v in pairs(charprop_stack_table) do
103         if not charprop_stack_table[j][m] then charprop_stack_table[j][m] = {} end
104         charprop_stack_table[j][m].width   = sp.width
105         charprop_stack_table[j][m].stretch = sp.stretch
106         charprop_stack_table[j][m].shrink  = sp.shrink
107         charprop_stack_table[j][m].stretch_order = sp.stretch_order
108         charprop_stack_table[j][m].shrink_order  = sp.shrink_order
109      end
110   end
111 end
112
113 -- These three functions are used in ltj-jfmglue.lua.
114 -- list_dir and orig_char_table are used in other lua files.
115 orig_char_table = {}
116 list_dir = nil -- dummy
117 table_current_stack = nil -- dummy
118 function report_stack_level(bsl)
119    table_current_stack = charprop_stack_table[bsl]
120    return bsl
121 end
122 function fast_get_stack_skip(m)
123    return table_current_stack[m]
124       or { width = 0, stretch = 0, shrink = 0, stretch_order = 0, shrink_order = 0 }
125 end
126
127 -- For other situations, use the following instead:
128 function get_stack_skip(m, idx)
129    return charprop_stack_table[idx][m]
130       or { width = 0, stretch = 0, shrink = 0, stretch_order = 0, shrink_order = 0 }
131 end
132 function get_stack_table(mc, d, idx)
133    local i = charprop_stack_table[idx][mc]
134    return i or d
135 end
136
137
138 -- EOF