2 -- luatexja/pretreat.lua
4 luatexbase.provides_module({
5 name = 'luatexja.pretreat',
10 module('luatexja.pretreat', package.seeall)
11 local err, warn, info, log = luatexbase.errwarinf(_NAME)
13 require('luatexja.charrange'); local ltjc = luatexja.charrange
14 require('luatexja.jfont'); local ltjf = luatexja.jfont
15 require('luatexja.stack'); local ltjs = luatexja.stack
17 local has_attr = node.has_attribute
18 local set_attr = node.set_attribute
19 local unset_attr = node.unset_attribute
20 local node_remove = node.remove
21 local node_next = node.next
22 local node_free = node.free
24 local id_glyph = node.id('glyph')
25 local id_whatsit = node.id('whatsit')
26 local sid_user = node.subtype('user_defined')
28 local attr_jchar_class = luatexbase.attributes['ltj@charclass']
29 local attr_curjfnt = luatexbase.attributes['ltj@curjfnt']
30 local attr_yablshift = luatexbase.attributes['ltj@yablshift']
31 local attr_ykblshift = luatexbase.attributes['ltj@ykblshift']
33 local ltjf_font_metric_table = ltjf.font_metric_table
34 local ltjf_find_char_class = ltjf.find_char_class
36 ------------------------------------------------------------------------
37 -- MAIN PROCESS STEP 1: replace fonts
38 ------------------------------------------------------------------------
40 -- This is used in jfmglue.lua.
42 local function suppress_hyphenate_ja(head)
43 for p in node.traverse_id(id_glyph, head) do
44 if ltjc.is_ucs_in_japanese_char(p) then
45 local v = has_attr(p, attr_curjfnt)
48 set_attr(p, attr_jchar_class,
49 ltjf_find_char_class(p.char, ltjf_font_metric_table[v]))
51 v = has_attr(p, attr_ykblshift)
53 set_attr(p, attr_yablshift, v)
55 unset_attr(p, attr_yablshift)
57 if p.subtype%2==1 then p.subtype = p.subtype - 1 end
65 -- mode: true iff this function is called from hpack_filter
66 function set_box_stack_level(head, mode)
69 local cl = tex.currentgrouplevel + 1
70 for p in node.traverse_id(id_whatsit, head) do
71 if p.subtype==sid_user and p.user_id==30112 then
73 if mode and g.value==cl then box_set = true end
74 head, p = node_remove(head, g); node_free(g); break
78 box_stack_level = tex.getcount('ltj@@stack') + 1
80 box_stack_level = tex.getcount('ltj@@stack')
86 luatexbase.add_to_callback('hpack_filter',
88 return set_box_stack_level(head, true)
89 end,'ltj.hpack_filter_pre',1)
90 luatexbase.add_to_callback('pre_linebreak_filter',
92 return set_box_stack_level(head, false)
93 end,'ltj.pre_linebreak_filter_pre',1)
94 luatexbase.add_to_callback('hyphenate',
96 return suppress_hyphenate_ja(head)