ソースコードの管理場所
Revision | 2851387cb262598acd81146fb4b624bdb062dcda (tree) |
---|---|
Time | 2014-08-21 20:03:11 |
Author | Hironori Kitagawa <h_kitagawa2001@yaho...> |
Commiter | Hironori Kitagawa |
Fix #34207 (cherry-pick 5ee9868b)
@@ -146,7 +146,10 @@ | ||
146 | 146 | |
147 | 147 | %%%%%%%% TeX command |
148 | 148 | \protected\def\ltjruby{\@ifnextchar[\ltj@@ruby{\ltj@@ruby[]}}%] |
149 | -\AtBeginDocument{\ifdefined\ruby\else\let\ruby=\ltjruby\fi} | |
149 | +\AtBeginDocument{% | |
150 | + \ifdefined\ruby\else\let\ruby=\ltjruby\fi | |
151 | + \directlua{luatexja.ruby.read_old_break_info()}% | |
152 | +} | |
150 | 153 | \def\ltj@@ruby[#1]#2#3{{% #1: option #2: 親文字群,#3: ルビ文字列群,共に| 区切り |
151 | 154 | \setkeys[ltj]{ruby}{#1}% |
152 | 155 | \directlua{ruby_tmplist_r = \string{\string}; ruby_tmplist_p = \string{\string}}% |
@@ -125,6 +125,15 @@ end | ||
125 | 125 | |
126 | 126 | -- 実行回数 + ルビ中身 から uniq_id を作る関数 |
127 | 127 | old_break_info = {} -- public, 前 run 時の分割情報 |
128 | +local cache_handle | |
129 | +function read_old_break_info() | |
130 | + if tex.jobname then | |
131 | + local fname = tex.jobname .. '.ltjruby' | |
132 | + local real_file = kpse.find_file(fname) | |
133 | + if real_file then dofile(real_file) end | |
134 | + cache_handle = io.open(fname, 'w') | |
135 | + end | |
136 | +end | |
128 | 137 | local make_uniq_id |
129 | 138 | do |
130 | 139 | local exec_count = 0 |
@@ -477,6 +486,7 @@ do | ||
477 | 486 | end |
478 | 487 | end |
479 | 488 | |
489 | +local next_cluster_array = {} | |
480 | 490 | -- ノード追加 |
481 | 491 | local function pre_low_app_node(head, w, cmp, coef, ht, dp) |
482 | 492 | -- メインの node list 更新 |
@@ -497,17 +507,21 @@ local function pre_low_app_node(head, w, cmp, coef, ht, dp) | ||
497 | 507 | insert_after(head, nt, nta) |
498 | 508 | set_attr(nta, attr_ruby, 2*i+1) |
499 | 509 | -- glue |
500 | - nt = node_new(id_glue) | |
501 | - local ntb = node_new(id_glue_spec); | |
510 | + local ntb = node_new(id_glue_spec); | |
502 | 511 | setfield(ntb, 'width', coef[i*2+1][2*cmp+2]) |
503 | 512 | setfield(ntb, 'stretch_order', 0); setfield(ntb, 'stretch', 0) |
504 | 513 | setfield(ntb, 'shrink_order', 0); setfield(ntb, 'shrink', 0) |
514 | + if i~=cmp or not next_cluster_array[w] then | |
515 | + nt = node_new(id_glue); insert_after(head, nta, nt) | |
516 | + else | |
517 | + nt = next_cluster_array[w] | |
518 | + end | |
505 | 519 | setfield(nt, 'subtype', 0); setfield(nt, 'spec', ntb) |
506 | 520 | set_attr(nt, attr_ruby, 2*i+2) |
507 | - insert_after(head, nta, nt) | |
508 | 521 | end |
509 | 522 | tex.setattribute('global', attr_ruby, -0x7FFFFFFF) |
510 | 523 | setfield(w, 'user_id', RUBY_POST) |
524 | + next_cluster_array[w]=nil | |
511 | 525 | return head, first_whatsit(node_next(nt)) |
512 | 526 | end |
513 | 527 |
@@ -558,10 +572,10 @@ do | ||
558 | 572 | local function write_aux(wv, num) |
559 | 573 | local id = has_attr(wv, attr_ruby_id) |
560 | 574 | if id>0 then |
561 | - tex.sprint(cat_lp, | |
562 | - '\\write\\@mainaux{\\string\\directlua{luatexja.ruby.old_break_info[' | |
563 | - .. tostring(id) .. ']=' .. num | |
564 | - .. '}}') | |
575 | + cache_handle:write( | |
576 | + 'luatexja.ruby.old_break_info[' | |
577 | + .. tostring(id) .. ']=' .. num | |
578 | + .. '\n') | |
565 | 579 | end |
566 | 580 | end |
567 | 581 |
@@ -575,7 +589,7 @@ do | ||
575 | 589 | if fn==2*cmp+2 then |
576 | 590 | local hn = node_tail(wv) |
577 | 591 | node_remove(wv, hn) |
578 | - insert_after(ch, rs[#rs], hn) | |
592 | + insert_after(ch, rs[1], hn) | |
579 | 593 | set_attr(hn, attr_icflag, PROCESSED) |
580 | 594 | write_aux(wv, has_attr(hn, attr_ruby))-- 行中形 |
581 | 595 | else |
@@ -583,7 +597,7 @@ do | ||
583 | 597 | for i = 1, deg do hn = node_next(hn) end; |
584 | 598 | node_remove(wv, hn) |
585 | 599 | setfield(hn, 'next', nil) |
586 | - insert_after(ch, rs[#rs], hn) | |
600 | + insert_after(ch, rs[1], hn) | |
587 | 601 | set_attr(hn, attr_icflag, PROCESSED) |
588 | 602 | write_aux(wv, has_attr(hn, attr_ruby)) |
589 | 603 | end |
@@ -593,7 +607,7 @@ do | ||
593 | 607 | -- -1 is needed except the case hn = 3, |
594 | 608 | -- because a ending-line form is removed already from the list |
595 | 609 | node_remove(wv, hn); setfield(hn, 'next', nil) |
596 | - insert_after(ch, rs[#rs], hn) | |
610 | + insert_after(ch, rs[1], hn) | |
597 | 611 | set_attr(hn, attr_icflag, PROCESSED) |
598 | 612 | if fn == 2*cmp-1 then |
599 | 613 | write_aux(wv, has_attr(hn, attr_ruby)) |
@@ -727,8 +741,15 @@ end | ||
727 | 741 | |
728 | 742 | do |
729 | 743 | local RIPOST = luatexja.stack_table_index.RIPOST |
730 | - local function whatsit_after_callback(s, Nq, Np, bsl) | |
744 | + local function whatsit_after_callback(s, Nq, Np) | |
731 | 745 | if not s and getfield(Nq.nuc, 'user_id') == RUBY_PRE then |
746 | + if Np then | |
747 | + local last_glue = node_new(id_glue) | |
748 | + set_attr(last_glue, attr_icflag, 0) | |
749 | + insert_before(Nq.nuc, Np.first, last_glue) | |
750 | + Np.first = last_glue | |
751 | + next_cluster_array[Nq.nuc] = last_glue -- ルビ処理用のグルー | |
752 | + end | |
732 | 753 | local nqnv = getfield(Nq.nuc, 'value') |
733 | 754 | local x = node_next(node_next(nqnv)) |
734 | 755 | for i = 2, getfield(nqnv, 'value') do x = node_next(node_next(x)) end |