• R/O
  • HTTP
  • SSH
  • HTTPS

luatexja: コミット

ソースコードの管理場所


コミットメタ情報

リビジョン4a30589bf10e6bef7479de111a3d7d56f3d9ed5c (tree)
日時2018-11-15 20:36:58
作者Hironori Kitagawa <h_kitagawa2001@yaho...>
コミッターHironori Kitagawa

ログメッセージ

Merge branch 'kitagawa_test' into kitagawa_save_jfont

変更サマリ

差分

--- a/src/ltj-adjust.lua
+++ b/src/ltj-adjust.lua
@@ -445,56 +445,75 @@ luatexja.unary_pars.adjust = function(t)
445445 return is_reg and 1 or 0
446446 end
447447
448+-- ----------------------------------
449+do
450+ local max, ins, sort = math.max, table.insert, table.sort
451+ local function insert(package, ind, d, b, e)
452+ local bound = package[2]
453+ bound[b], bound[e]=true, true
454+ ins(package[1], {b,e,[ind]=d})
455+ end
456+ local function flatten(package)
457+ local bd={} for i,_ in pairs(package[2]) do ins(bd,{i}) end
458+ sort(bd, function (a,b) return a[1]<b[1] end)
459+ local bdc=#bd; local t = package[1]
460+ sort(t, function (a,b) return a[1]<b[1] end)
461+ local bdi =1
462+ for i=1,#t do
463+ while bd[bdi][1]<t[i][1] do bdi=bdi+1 end
464+ local j = bdi
465+ while j<bdc and bd[j+1][1]<=t[i][2] do
466+ for k,w in pairs(t[i]) do
467+ if k>=3 then
468+ bd[j][k]=bd[j][k] and max(bd[j][k],w) or w
469+ end
470+ end
471+ j=j+1
472+ end
473+ end
474+ package[2]=nil; package[1]=nil; package.flatten, package.insert=nil, nil
475+ bd[#bd]=nil
476+ return bd
477+ end
478+ function init_range()
479+ return {{},{}, insert=insert, flatten=flatten}
480+ end
481+end
482+
448483 -- -----------------------------------
449484 luatexja.adjust.step_factor = 0.5
450485 do
451486 local insert = table.insert
452487 local rangedimensions, max = node.direct.rangedimensions, math.max
453- function ltjl.p_profile(before, after, mirrored, bw)
454- local t = {}
455- do
456- local w_acc, d_before = getfield(before,'shift'), 0
457- local x = getlist(before); local xn = node_next(x)
458- while x do
459- local w, d
460- if xn then w, _, d= rangedimensions(before,x,xn)
461- else w, _, d= rangedimensions(before,x) end
462- if d~=d_before then
463- d_before = d; t[w_acc] = t[w_acc] or {}
464- if t[w_acc][1] then t[w_acc][1]=max(t[w_acc][1],d)
465- else t[w_acc][1]=d end
466- end
467- w_acc = w_acc + w
468- x = xn; if x then xn = node_next(x) end
469- end
470- end
471- do
472- local w_acc, h_before = getfield(after,'shift'), 0
473- local x = getlist(after); local xn = node_next(x)
474- while x do
475- local w, h, d
476- if xn then w, h, d = rangedimensions(after,x,xn)
477- else w, h,d = rangedimensions(after,x) end
478- if mirrored then h=d end
479- if h~=h_before then
480- h_before = h; t[w_acc] = t[w_acc] or {}
481- if t[w_acc][2] then t[w_acc][2]=max(t[w_acc][2],h)
482- else t[w_acc][2]=h end
483- end
484- w_acc = w_acc + w
485- x = xn; if x then xn = node_next(x) end
488+ local function profile_inner(box, range, ind, vmirrored, adj)
489+ local w_acc, d_before = getfield(box,'shift'), 0
490+ local x = getlist(box); local xn = node_next(x)
491+ while x do
492+ local w, h, d
493+ if xn then w, h, d= rangedimensions(box,x,xn)
494+ else w, h, d= rangedimensions(box,x) end
495+ if vmirrored then h=d end
496+ local w_new = w_acc + w
497+ if w>=0 then
498+ range:insert(ind, h, w_acc-adj, w_new)
499+ else
500+ range:insert(ind, h, w_new-adj, w_acc)
486501 end
502+ w_acc = w_new; x = xn; if x then xn = node_next(x) end
487503 end
488- local t2 = {}
489- for i,v in pairs(t) do insert(t2, { i, v[1], v[2] } ) end
490- table.sort(t2, function(a,b) return a[1]<b[1] end)
504+ end
505+ function ltjl.p_profile(before, after, mirrored, bw)
506+ local range, tls = init_range(), tex.lineskip.width
507+ profile_inner(before, range, 3, true, tls)
508+ profile_inner(after, range, 4, mirrored, tls)
509+ range = range:flatten()
491510 do
492511 local dmax, d, hmax, h, lmin = 0, 0, 0, 0, 1/0
493- for i,v in ipairs(t2) do
494- d, h = (v[2] or d), (v[3] or h)
512+ for i,v in ipairs(range) do
513+ d, h = (v[3] or 0), (v[4] or 0)
495514 if d>dmax then dmax=d end
496515 if h>hmax then hmax=h end
497- if (bw-h-d)<lmin then lmin=bw-h-d end
516+ if bw-h-d<lmin then lmin=bw-h-d end
498517 end
499518 if lmin==1/0 then lmin = bw end
500519 return lmin,
@@ -513,7 +532,7 @@ do
513532 return ltjl.l_dummy(dist, g, adj, normal, bw, loc)
514533 end
515534 if dist < tex.lineskiplimit then
516- local f = max(1, bw*ltja.step_factor)
535+ local f = max(1, bw*ltja.step_factor)
517536 copy_glue(g, tex.baselineskip, 1, normal - f * floor((dist-tex.lineskip.width)/f))
518537 else
519538 copy_glue(g, tex.baselineskip, 2, normal)
Binary files a/test/test27-lineprofile.pdf and b/test/test27-lineprofile.pdf differ
--- a/test/test27-lineprofile.tex
+++ b/test/test27-lineprofile.tex
@@ -72,4 +72,23 @@
7272 \R{false}{true}%
7373 \R{true}{true}%
7474
75+\ltjdisableadjust
76+\ltjenableadjust[profile]
77+
78+\def\R#1{%
79+ \fbox{\parbox[t]{130pt}{\lineskip1pt\textbf{#1pt (\texttt{lineskip}: \the\lineskip)}\\%
80+ \noindent\vrule height 5pt depth 50pt width 45pt\kern30pt%
81+ \vrule height 5pt depth 50pt width 30pt\\
82+ \textcolor{red}{\kern\dimexpr45pt+#1pt\vrule height 50pt depth 5pt width20pt}%
83+ \textcolor{blue}{\kern-40pt\vrule height 5pt depth 5pt width 60pt}%
84+ }}\hskip0pt\ignorespaces
85+}
86+
87+\noindent
88+\R{0}
89+\R{0.5}
90+\R{1}
91+\R{9}
92+\R{10}
93+
7594 \end{document}
旧リポジトリブラウザで表示