+do
+ local start_time_measure, stop_time_measure
+ = ltjb.start_time_measure, ltjb.stop_time_measure
+ local Dnode = node.direct or node
+ local nullfunc = function (n) return n end
+ local to_node = (Dnode ~= node) and Dnode.tonode or nullfunc
+ local to_direct = (Dnode ~= node) and Dnode.todirect or nullfunc
+ local ensure_tex_attr = ltjb.ensure_tex_attr
+
+ -- mode = true iff main_process is called from pre_linebreak_filter
+ local function main_process(head, mode, dir, gc)
+ ensure_tex_attr(attr_icflag, 0)
+ if gc == 'fin_row' then return head
+ else
+ --luatexja.ext_show_node_list(head, 'T> ', print)
+ start_time_measure('jfmglue')
+ local p = ltjj.main(to_direct(head),mode, dir)
+ stop_time_measure('jfmglue')
+ return to_node(p)
+ end
+ end
+
+ local function adjust_icflag(h)
+ -- kern from luaotfload will have icflag = 1
+ -- (same as italic correction)
+ ensure_tex_attr(attr_icflag, 1)
+ return h
+ end
+
+ -- callbacks
+ luatexbase.add_to_callback(
+ 'pre_linebreak_filter',
+ function (head,groupcode)
+ return main_process(head, true, tex.textdir, groupcode)
+ end,'ltj.pre_linebreak_filter',
+ luatexbase.priority_in_callback('pre_linebreak_filter',
+ 'luaotfload.node_processor') + 1)
+ luatexbase.add_to_callback(
+ 'hpack_filter',
+ function (head,groupcode,size,packtype, dir)
+ return main_process(head, false, dir, groupcode)
+ end,'ltj.hpack_filter',
+ luatexbase.priority_in_callback('hpack_filter',
+ 'luaotfload.node_processor') + 1)
+ luatexbase.add_to_callback('pre_linebreak_filter', adjust_icflag, 'ltj.adjust_icflag', 1)
+ luatexbase.add_to_callback('hpack_filter', adjust_icflag, 'ltj.adjust_icflag', 1)
+
+end
+
+-- cleanup process
+function luatexja.ext_cleanup()
+ ltjf.cleanup_size_cache()
+ ltjd.remove_end_whatsit()