From: Hironori Kitagawa Date: Wed, 22 Jan 2014 14:05:38 +0000 (+0900) Subject: lltjfont.sty: append garbage to argument of \jfont only if alternate fonts is set... X-Git-Tag: 20140204.0~8^2~10 X-Git-Url: http://git.osdn.net/view?p=luatex-ja%2Fluatexja.git;a=commitdiff_plain;h=c1f148d3b912d2f47d83f083c1ad942313305328 lltjfont.sty: append garbage to argument of \jfont only if alternate fonts is set for current Japanese font family processing time of luatexja-ja.tex this commit previous commit 13/12/30 LuaTeX 10.005 16.955 10.290 LuaJITTeX 8.636 33.199 8.048 (Note that alternate font is not supported in the source at 13/12/30.) processing time of test05-speed.tex (\count300=30) prev commit 13/12/30 LuaTeX 22.593 29.045 LuaJITTeX 16.609 22.982 --- diff --git a/src/ltj-jfmglue.lua b/src/ltj-jfmglue.lua index 307c68c..4b8aa17 100644 --- a/src/ltj-jfmglue.lua +++ b/src/ltj-jfmglue.lua @@ -198,11 +198,7 @@ local function check_box(box_ptr, box_end) -- Note that another node_next will be executed outside this if-statement. else found_visible_node = true - if find_first_char then - find_first_char = false - else - last_char = nil - end + find_first_char = false; last_char = nil end elseif pid==id_hlist then if PACKED == get_attr_icflag(p) then @@ -213,11 +209,8 @@ local function check_box(box_ptr, box_end) else if getfield(p, 'shift')==0 then if check_box(getlist(p), nil) then found_visible_node = true end - else if find_first_char then - find_first_char = false - else - last_char = nil - end + else + find_first_char = false; last_char = nil end end elseif pid==id_math then @@ -229,11 +222,7 @@ local function check_box(box_ptr, box_end) or pid==id_adjust or pid==id_whatsit or pid==id_penalty) then found_visible_node = true - if find_first_char then - find_first_char = false - else - last_char = nil - end + find_first_char = false; last_char = nil end p = node_next(p) end @@ -289,15 +278,15 @@ local function check_next_ickern(lp) end end -local function calc_np_pbox(lp, last) +local function calc_np_pbox(lp) Np.first = Np.first or lp; Np.id = id_pbox - local lpa = KINSOKU -- dummy= + local lpa, nc = KINSOKU, nil set_attr(lp, attr_icflag, get_attr_icflag(lp)); - while lp~=last and lpa>=PACKED and lpa=PACKED) and (lpa=PACKED then if lpa%PROCESSED_BEGIN_FLAG == BOXBDD then local lq = node_next(lp) head = node_remove(head, lp); node_free(lp); lp = lq - else return calc_np_pbox(lp, last) + else return calc_np_pbox(lp) end -- id_pbox else k, lp = calc_np_auxtable[getid(lp)](lp) @@ -855,6 +844,7 @@ end -------------------- 開始・終了時の処理 +do -- リスト末尾の処理 local JWP = luatexja.stack_table_index.JWP @@ -936,17 +926,15 @@ local function init_var(mode) or ((lpi==id_hlist) and (lps==3))) do if (lpi==id_hlist) and (lps==3) then par_indented = 'parbdd' end lp=node_next(lp); lpi, lps = getid(lp), getsubtype(lp) end - return lp, node_tail(head), par_indented + return lp, par_indented + -- return lp, node_tail(head), par_indented else -- the current list is the contents of a hbox: - -- insert a sentinel - local g = node_new(id_kern) - insert_after(head, node_tail(head), g); last = g - return head, g, 'boxbdd' + return head, 'boxbdd' end end -local function cleanup(mode, last) +local function cleanup(mode) -- adjust attr_icflag for avoiding error tex.setattribute('global', attr_icflag, 0) node_free(kanji_skip); node_free(xkanji_skip) @@ -960,7 +948,6 @@ local function cleanup(mode, last) end return head else - head = node_remove(head, last); node_free(last);-- remove the sentinel set_attr(head, attr_icflag, get_attr_icflag(head) + PROCESSED_BEGIN_FLAG); return head @@ -972,14 +959,14 @@ end function main(ahead, mode) if not ahead then return ahead end head = ahead; - local lp, last, par_indented = init_var(mode); + local lp, par_indented = init_var(mode); lp = calc_np(lp, last) if Np then extract_np(); handle_list_head(par_indented) else return cleanup(mode, last) end - lp = calc_np(lp, last) + lp = calc_np(lp) while Np do extract_np(); adjust_nq(); @@ -994,10 +981,11 @@ function main(ahead, mode) if Nq.id==id_hlist then handle_nq_ja_hlist() else handle_nq_jachar() end end - lp = calc_np(lp, last) + lp = calc_np(lp) end handle_list_tail(mode) - return cleanup(mode, last) + return cleanup(mode) +end end do diff --git a/src/ltj-jfont.lua b/src/ltj-jfont.lua index 7f5f639..cb63545 100644 --- a/src/ltj-jfont.lua +++ b/src/ltj-jfont.lua @@ -369,8 +369,8 @@ end ------ used in ltjp.suppress_hyphenate_ja callback function replace_altfont(pf, pc) - return (alt_font_table[pf] and alt_font_table[pf][pc]) - and alt_font_table[pf][pc] or pf + local a = alt_font_table[pf] + return a and a[pc] or pf end ------ for LaTeX interface @@ -426,26 +426,30 @@ end -- ここから先は 新 \selectfont の内部でしか実行されない do local alt_font_base, alt_font_base_num - --- EXT - function print_aftl_address(bbase) - local t = alt_font_table_latex[bbase] - if not t then t = {}; alt_font_table_latex[bbase] = t end - tex.sprint(cat_lp, (tostring(t):gsub('table: ','ltjaltfont'))) + local aftl_base + -- EXT + function does_alt_set(bbase) + aftl_base = alt_font_table_latex[bbase] + tex.sprint(cat_lp, '\\if' .. (aftl_base and 'true' or 'false')) end + -- EXT + function print_aftl_address() + tex.sprint(cat_lp, ';ltjaltfont' .. tostring(aftl_base):sub(8)) + end + -- EXT function output_alt_font_cmd(bbase) alt_font_base = bbase alt_font_base_num = tex.getattribute(attr_curjfnt) local t = alt_font_table[alt_font_base_num] if t then - for i,_ in pairs(t) do t[i]=nil end + for i,_ in pairs(t) do t[i]=nil end end t = alt_font_table_latex[bbase] if t then - for i,_ in pairs(t) do - tex.sprint(cat_lp, '\\ltj@pickup@altfont@aux{' .. i .. '}') - end + for i,_ in pairs(t) do + tex.sprint(cat_lp, '\\ltj@pickup@altfont@aux{' .. i .. '}') + end end end @@ -453,18 +457,18 @@ do function pickup_alt_font_a(size_str) local t = alt_font_table_latex[alt_font_base] if t then - for i,v in pairs(t) do - tex.sprint(cat_lp, '\\expandafter\\ltj@pickup@altfont@copy' - .. '\\csname ' .. i .. '/' .. size_str .. '\\endcsname{' .. i .. '}') - end + for i,v in pairs(t) do + tex.sprint(cat_lp, '\\expandafter\\ltj@pickup@altfont@copy' + .. '\\csname ' .. i .. '/' .. size_str .. '\\endcsname{' .. i .. '}') + end end - end + end local function pickup_alt_font_class(class, afnt_num, afnt_chars) local t = alt_font_table[alt_font_base_num] local tx = font_metric_table[alt_font_base_num].chars for i,v in pairs(tx) do - if v==class and afnt_chars[i] then t[i]=afnt_num end + if v==class and afnt_chars[i] then t[i]=afnt_num end end end @@ -474,17 +478,17 @@ do local ac = font_getfont(afnt_num).characters if not t then t = {}; alt_font_table[alt_font_base_num] = t end for i,v in pairs(alt_font_table_latex[alt_font_base]) do - if i == afnt_base then - for j,_ in pairs(v) do - if j>=0 then - if ac[j] then t[j]=afnt_num end - else -- -n (n>=1) means that the character class n, - -- which is defined in the JFM - pickup_alt_font_class(-j, afnt_num, ac) - end - end - return - end + if i == afnt_base then + for j,_ in pairs(v) do + if j>=0 then + if ac[j] then t[j]=afnt_num end + else -- -n (n>=1) means that the character class n, + -- which is defined in the JFM + pickup_alt_font_class(-j, afnt_num, ac) + end + end + return + end end end diff --git a/src/luatexja-core.sty b/src/luatexja-core.sty index e645fb7..139615a 100644 --- a/src/luatexja-core.sty +++ b/src/luatexja-core.sty @@ -101,6 +101,11 @@ {Package loading is aborted now.\MessageBreak} \expandafter\endinput\fi\relax + \@PackageInfo{luatexja-core} + {This LuaTeX-ja uses\space% + \directlua{if node.direct==node then tex.write('traditional node') + else tex:write('DIRECT') end} access model for accessing nodes.} + %! なお、luatexbase-compat の説明に従うと、LuaTeX 拡張プリミティブは %! plain/LaTeX の両方で \luatex 付の名前(\directlua はそのまま) %! で使えると考えてよい。 @@ -138,7 +143,10 @@ \newluatexattribute\ltj@yablshift % attribute for \yabaselineshift \newluatexattribute\ltj@ykblshift % attribute for \ykbaselineshift \newluatexattribute\jfam % index for current jfam -\ltj@icflag=0\ltj@origchar=0\ltj@charclass=0 +\ltj@icflag=0 +\ltj@origchar=0 +\ltj@charclass=0 +\ltj@curjfnt=-1 %%%%%%%% Attributes for character ranges \newcount\ltj@tempcnta diff --git a/src/patches/lltjfont.sty b/src/patches/lltjfont.sty index 244ae45..e10834c 100644 --- a/src/patches/lltjfont.sty +++ b/src/patches/lltjfont.sty @@ -585,12 +585,13 @@ % 異なる和文 enc/fam/ser/shape からは異なるフォント番号が振られるように % わざと「ゴミをつける」 \def\ltj@@patch@external@font#1 at{% - #1;\directlua{luatexja.jfont.print_aftl_address(% - '\luatexluaescapestring{\f@encoding/\f@family/\f@series/\f@shape}')}\space at% + #1\directlua{luatexja.jfont.print_aftl_address()}\space at% } \def\extract@jfont{% \get@external@font - \edef\external@font{\expandafter\ltj@@patch@external@font\external@font}% + \ltj@@does@alt@set{\f@encoding/\f@family/\f@series/\f@shape}% + \edef\external@font{\expandafter\ltj@@patch@external@font\external@font}% + \fi \expandafter\globaljfont\font@name\external@font\relax \font@name%\global\zw=\zw\global\zh=\zh \csname \f@encoding+\f@family\endcsname @@ -682,11 +683,15 @@ \let\ltj@@alt@selectfont@orig=\selectfont \def\selectfont{% \ltj@@alt@selectfont@orig - % alt fonts の定義 - \directlua{luatexja.jfont.output_alt_font_cmd('\luatexluaescapestring{\curr@kfontshape}')}% - % 定義した alt fonts のデータを \ltjdeclarealtfont に渡すのと同等の処理をする - \directlua{luatexja.jfont.pickup_alt_font_a('\f@size')}% + \ltj@@does@alt@set{\curr@kfontshape} + % alt fonts の定義 + \directlua{luatexja.jfont.output_alt_font_cmd('\luatexluaescapestring{\curr@kfontshape}')}% + % 定義した alt fonts のデータを \ltjdeclarealtfont に渡すのと同等の処理をする + \directlua{luatexja.jfont.pickup_alt_font_a('\f@size')}% + \fi } +%\let\selectfont=\ltj@@alt@selectfont@orig + \def\ltj@pickup@altfont@aux#1{% {\edef\font@name{\csname #1/\f@size\endcsname}\pickup@jfont}% } @@ -695,4 +700,7 @@ \directlua{luatexja.jfont.pickup_alt_font_b(\the\ltj@tempcntc,'\luatexluaescapestring{#2}')}% } +\def\ltj@@does@alt@set#1{% + \directlua{luatexja.jfont.does_alt_set'\luatexluaescapestring{#1}'}} + \endinput