2 -- luatexja/ltj-pretreat.lua
5 luatexja.load_module('charrange'); local ltjc = luatexja.charrange
6 luatexja.load_module('jfont'); local ltjf = luatexja.jfont
7 luatexja.load_module('stack'); local ltjs = luatexja.stack
9 local floor = math.floor
10 local has_attr = node.has_attribute
11 local set_attr = node.set_attribute
12 local node_traverse = node.traverse
13 local node_type = node.type
14 local node_remove = node.remove
15 local node_next = node.next
16 local node_free = node.free
17 local tex_getcount = tex.getcount
18 local fonts_ids = fonts.ids
20 local id_glyph = node.id('glyph')
21 local id_math = node.id('math')
22 local id_whatsit = node.id('whatsit')
23 local sid_user = node.subtype('user_defined')
25 local attr_curjfnt = luatexbase.attributes['ltj@curjfnt']
26 local attr_icflag = luatexbase.attributes['ltj@icflag']
28 local ltjf_font_metric_table = ltjf.font_metric_table
29 local ltjc_is_ucs_in_japanese_char = ltjc.is_ucs_in_japanese_char
30 local attr_orig_char = luatexbase.attributes['ltj@origchar']
31 local STCK = luatexja.userid_table.STCK
78 ------------------------------------------------------------------------
79 -- MAIN PROCESS STEP 1: replace fonts
80 ------------------------------------------------------------------------
83 local function suppress_hyphenate_ja(head)
84 local non_math, p = true, head
88 if pid == id_glyph then
89 if (has_attr(p, attr_icflag) or 0)<=0 and ltjc_is_ucs_in_japanese_char(p) then
90 local pf = has_attr(p, attr_curjfnt) or p.font
92 p.subtype = floor(p.subtype*0.5)*2
93 set_attr(p, attr_orig_char, p.char)
94 local pfd = fonts_ids[pf]
95 if ltjf_font_metric_table[pf] and ltjf_font_metric_table[pf].mono_flag then
96 local pco = pfd.cidinfo.ordering
97 for i,v in pairs(fwglyph) do
98 if pco == i and pfd.resources then
99 local fwc = pfd.resources.unicodes[pco .. '.'.. tostring(v[p.char])]
100 if fwc then p.char = fwc end
106 elseif pid == id_math then
107 p = node_next(p) -- skip math on
108 while p and p.id~=id_math do p = node_next(p) end
109 elseif pid == id_whatsit and p.subtype==sid_user and p.user_id==STCK then
110 wt[#wt+1] = p; head = node_remove(head, p)
118 -- mode: true iff this function is called from hpack_filter
119 local function set_box_stack_level(head, mode)
120 local box_set, cl = 0, tex.currentgrouplevel + 1
121 for _,p in pairs(wt) do
122 if mode and p.value==cl then box_set = 1 end; node_free(p)
124 ltjs.report_stack_level(tex_getcount('ltj@@stack') + box_set)
129 luatexbase.add_to_callback('hpack_filter',
131 return set_box_stack_level(head, true)
132 end,'ltj.hpack_filter_pre',1)
133 luatexbase.add_to_callback('pre_linebreak_filter',
135 return set_box_stack_level(head, false)
136 end,'ltj.pre_linebreak_filter_pre',1)
137 luatexbase.add_to_callback('hyphenate',
139 return suppress_hyphenate_ja(head)
142 luatexja.pretreat = {
143 set_box_stack_level = set_box_stack_level,