From 36e4d78a69fe2383b06ffc22aa730d3b84e5c1df Mon Sep 17 00:00:00 2001 From: Hironori Kitagawa Date: Sun, 31 Jan 2016 18:22:32 +0900 Subject: [PATCH 1/1] luatexbase.add_to_callback is indeterministic, so we use det. version of it (def'ed in ltj-base.lua). --- src/ltj-base.lua | 27 +++++++++++++++++++++++++++ src/ltj-direction.lua | 10 +++++----- src/ltj-otf.lua | 25 ++++++++----------------- src/ltj-pretreat.lua | 9 ++++----- src/luatexja.lua | 14 ++++++-------- test/test19-ivs-vert.tex | 39 +++++++++++++++++++++++++++++++++++++++ 6 files changed, 89 insertions(+), 35 deletions(-) create mode 100644 test/test19-ivs-vert.tex diff --git a/src/ltj-base.lua b/src/ltj-base.lua index f48c2ab..e66a196 100644 --- a/src/ltj-base.lua +++ b/src/ltj-base.lua @@ -400,6 +400,33 @@ ltjb.generic_info_no_line = generic_info_no_line ltjb.ltj_warning_no_line = ltj_warning_no_line ltjb.ltj_error = ltj_error +---- deterministic version of luatexbase.add_to_callback +function ltjb.add_to_callback(name,fun,description,priority) + local priority= priority + if priority==nil then + priority=#luatexbase.callback_descriptions(name)+1 + end + if(luatexbase.callbacktypes[name] == 3 and + priority == 1 and + #luatexbase.callback_descriptions(name)==1) then + luatexbase.module_warning("luatexbase", + "resetting exclusive callback: " .. name) + luatexbase.reset_callback(name) + end + local saved_callback={},ff,dd + for k,v in ipairs(luatexbase.callback_descriptions(name)) do + if k >= priority then + ff,dd= luatexbase.remove_from_callback(name, v) + saved_callback[#saved_callback+1]={ff,dd} + end + end + luatexbase.base_add_to_callback(name,fun,description) + for _,v in ipairs(saved_callback) do + luatexbase.base_add_to_callback(name,v[1],v[2]) + end + return +end + -------------------- mock of debug logger if not ltjb.out_debug then local function no_op() end diff --git a/src/ltj-direction.lua b/src/ltj-direction.lua index a46fdeb..b5f267c 100644 --- a/src/ltj-direction.lua +++ b/src/ltj-direction.lua @@ -275,7 +275,7 @@ do end end - luatexbase.add_to_callback('hpack_filter', + ltjb.add_to_callback('hpack_filter', create_dir_whatsit_hpack, 'ltj.create_dir_whatsit', 10000) end @@ -290,7 +290,7 @@ do ensure_tex_attr(attr_dir, 0) return h end - luatexbase.add_to_callback('post_linebreak_filter', + ltjb.add_to_callback('post_linebreak_filter', create_dir_whatsit_parbox, 'ltj.create_dir_whatsit', 10000) end @@ -987,7 +987,7 @@ do stop_time_measure('direction_vpack') return to_node(hd) end - luatexbase.add_to_callback('vpack_filter', + ltjb.add_to_callback('vpack_filter', dir_adjust_vpack, 'ltj.direction', 10000) end @@ -997,7 +997,7 @@ do local function dir_adjust_pre_output(h, gc) return to_node(create_dir_whatsit_vbox(to_direct(h), gc)) end - luatexbase.add_to_callback('pre_output_filter', + ltjb.add_to_callback('pre_output_filter', dir_adjust_pre_output, 'ltj.direction', 10000) @@ -1026,7 +1026,7 @@ do end end end - luatexbase.add_to_callback('buildpage_filter', + ltjb.add_to_callback('buildpage_filter', dir_adjust_buildpage, 'ltj.direction', 10000) end diff --git a/src/ltj-otf.lua b/src/ltj-otf.lua index ed1a197..75494d6 100644 --- a/src/ltj-otf.lua +++ b/src/ltj-otf.lua @@ -158,15 +158,10 @@ local function extract(head) return to_node(head) end -luatexbase.add_to_callback('hpack_filter', extract, - 'ltj.otf', - luatexbase.priority_in_callback('pre_linebreak_filter', - 'ltj.main')) -luatexbase.add_to_callback('pre_linebreak_filter', extract, - 'ltj.otf', - luatexbase.priority_in_callback('pre_linebreak_filter', - 'ltj.main')) - +ltjb.add_to_callback('hpack_filter', extract,'ltj.otf', + luatexbase.priority_in_callback('hpack_filter', 'ltj.main')) +ltjb.add_to_callback('pre_linebreak_filter', extract,'ltj.otf', + luatexbase.priority_in_callback('pre_linebreak_filter', 'ltj.main')) -- additional callbacks -- 以下は,LuaTeX-ja に用意された callback のサンプルになっている. -- JFM の文字クラスの指定の所で,"AJ1-xxx" 形式での指定を可能とした. @@ -273,14 +268,10 @@ do ltjb.package_warning('luatexja-otf', 'luatexja.otf.enable_ivs() was already called, so this call is ignored', '') else - luatexbase.add_to_callback('hpack_filter', - do_ivs_repr, 'ltj.do_ivs', - luatexbase.priority_in_callback('hpack_filter', - 'ltj.set_stack_level')+1) - luatexbase.add_to_callback('pre_linebreak_filter', - do_ivs_repr, 'ltj.do_ivs', - luatexbase.priority_in_callback('pre_linebreak_filter', - 'ltj.set_stack_level')+1) + ltjb.add_to_callback('hpack_filter', do_ivs_repr, 'ltj.do_ivs', + luatexbase.priority_in_callback('hpack_filter', 'luaotfload.node_processor')) + ltjb.add_to_callback('pre_linebreak_filter', do_ivs_repr, 'ltj.do_ivs', + luatexbase.priority_in_callback('pre_linebreak_filter', 'luaotfload.node_processor')) is_ivs_enabled = true end end diff --git a/src/ltj-pretreat.lua b/src/ltj-pretreat.lua index 9b2bc07..f95ae5f 100644 --- a/src/ltj-pretreat.lua +++ b/src/ltj-pretreat.lua @@ -116,7 +116,7 @@ do return h end - luatexbase.add_to_callback('hyphenate', + ltjb.add_to_callback('hyphenate', function (head,tail) return suppress_hyphenate_ja(head) end,'ltj.hyphenate') @@ -139,9 +139,8 @@ local function set_box_stack_level(head, mode) if ltjs.list_dir == dir_tate then for p in Dnode.traverse_id(id_glyph,to_direct(head)) do if (has_attr(p, attr_icflag) or 0)<=0 and getfield(p, 'lang')==lang_ja then - local pfn = has_attr(p, attr_curtfnt) or getfont(p) local pc = ltjs_orig_char_table[p] - local nf = ltjf_replace_altfont(pfn, pc) + local nf = ltjf_replace_altfont( has_attr(p, attr_curtfnt) or getfont(p) , pc) setfield(p, 'font', nf) if ltjf_font_metric_table[nf].vert_activated then pc = ltjf_vert_form_table [getchar(p)] @@ -154,11 +153,11 @@ local function set_box_stack_level(head, mode) end -- CALLBACKS -luatexbase.add_to_callback('hpack_filter', +ltjb.add_to_callback('hpack_filter', function (head) return set_box_stack_level(head, true) end,'ltj.set_stack_level',1) -luatexbase.add_to_callback('pre_linebreak_filter', +ltjb.add_to_callback('pre_linebreak_filter', function (head) return set_box_stack_level(head, false) end,'ltj.set_stack_level',1) diff --git a/src/luatexja.lua b/src/luatexja.lua index 491454c..7b0cd15 100644 --- a/src/luatexja.lua +++ b/src/luatexja.lua @@ -318,22 +318,20 @@ do end -- callbacks - luatexbase.add_to_callback( + ltjb.add_to_callback( 'pre_linebreak_filter', function (head,groupcode) return main_process(head, true, tex.textdir, groupcode) end,'ltj.main', - luatexbase.priority_in_callback('pre_linebreak_filter', - 'luaotfload.node_processor')+1) - luatexbase.add_to_callback( + luatexbase.priority_in_callback('pre_linebreak_filter', 'luaotfload.node_processor')+1) + ltjb.add_to_callback( 'hpack_filter', function (head,groupcode,size,packtype, dir) return main_process(head, false, dir, groupcode) end,'ltj.main', - 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) + luatexbase.priority_in_callback('hpack_filter', 'luaotfload.node_processor')+1) + ltjb.add_to_callback('pre_linebreak_filter', adjust_icflag, 'ltj.adjust_icflag', 1) + ltjb.add_to_callback('hpack_filter', adjust_icflag, 'ltj.adjust_icflag', 1) end diff --git a/test/test19-ivs-vert.tex b/test/test19-ivs-vert.tex new file mode 100644 index 0000000..aef53fd --- /dev/null +++ b/test/test19-ivs-vert.tex @@ -0,0 +1,39 @@ +\RequirePackage{luatex85} +\documentclass{ltjarticle} +\usepackage[margin=20mm]{geometry} +\usepackage{luatexja-otf} +\usepackage[kozuka-pr6n]{luatexja-preset} +\normalsize +\def\test{ある日、モモちゃんが初めて「お使い」に行ったとき, + 彼女は道に迷って泣きました。医学,芦屋} +\def\CB{\par{\catcode`_=12\ttfamily PR\directlua{ + for i,v in pairs(luatexbase.callback_descriptions('hpack_filter')) do + tex.sprint(v .. ', ') + end +}}\par{\catcode`_=12\ttfamily HP\directlua{ + for i,v in pairs(luatexbase.callback_descriptions('pre_linebreak_filter')) do + tex.sprint(v .. ', ') + end +}}\par} + +\begin{document} +\CB +\addjfontfeatures{RawFeature={+trad;+jp04}}\test +\medskip + +\vbox{\tate\Large\hsize=9\zw\test} +\medskip + +\directlua{luatexja.otf.enable_ivs()} +\CB +\vbox{\tate\Large\hsize=9\zw\test} +\medskip + +\directlua{luatexja.otf.disable_ivs()} +\CB +\vbox{\tate\Large\hsize=9\zw\test} +\medskip + +\test +\end{document} + -- 2.11.0