X-Git-Url: http://git.osdn.jp/view?a=blobdiff_plain;f=src%2Fltj-adjust.lua;h=3d7e31e0c409e4f4d75d30cb7b803a6562901a12;hb=f078ac2f7998a102c7ec765e725f2269eed9f872;hp=54af8cf33de3aa0460f6ca81785aa172ad4b43ce;hpb=0aa44651e40f676a9d0bd1197e96822a8e01df57;p=luatex-ja%2Fluatexja.git diff --git a/src/ltj-adjust.lua b/src/ltj-adjust.lua index 54af8cf..3d7e31e 100644 --- a/src/ltj-adjust.lua +++ b/src/ltj-adjust.lua @@ -1,6 +1,7 @@ -- -- ltj-adjust.lua -- +luatexja.load_module('base'); local ltjb = luatexja.base luatexja.load_module('jfont'); local ltjf = luatexja.jfont luatexja.load_module('jfmglue'); local ltjj = luatexja.jfmglue luatexja.load_module('stack'); local ltjs = luatexja.stack @@ -404,8 +405,9 @@ do local is_reg = false function enable_cb(status_le, status_pr, status_lp, status_ls) if (status_le>0 or status_pr>0) and (not is_reg) then - luatexbase.add_to_callback('post_linebreak_filter', - adjust_width, 'Adjust width', 100) + ltjb.add_to_callback('post_linebreak_filter', + adjust_width, 'Adjust width', + luatexbase.priority_in_callback('post_linebreak_filter', 'ltj.lineskip')-1) is_reg = true elseif is_reg and (status_le==0 and status_pr==0) then luatexbase.remove_from_callback('post_linebreak_filter', 'Adjust width') @@ -413,7 +415,7 @@ do end if status_le==2 then if not luatexbase.in_callback('luatexja.adjust_jfmglue', 'luatexja.adjust') then - luatexbase.add_to_callback('luatexja.adjust_jfmglue', insert_lineend_kern, 'luatexja.adjust') + ltjb.add_to_callback('luatexja.adjust_jfmglue', insert_lineend_kern, 'luatexja.adjust') end myaw_step1, myaw_step1_last = dummy, aw_step1_last else @@ -443,58 +445,85 @@ luatexja.unary_pars.adjust = function(t) return is_reg and 1 or 0 end +-- ---------------------------------- +do + local max, ins, sort = math.max, table.insert, table.sort + local function insert(package, ind, d, b, e) + local bound = package[2] + bound[b], bound[e]=true, true + ins(package[1], {b,e,[ind]=d}) + end + local function flatten(package) + local bd={} for i,_ in pairs(package[2]) do ins(bd,{i}) end + sort(bd, function (a,b) return a[1]=3 then + bd[j][k]=bd[j][k] and max(bd[j][k],w) or w + end + end + j=j+1 + end + end + package[2]=nil; package[1]=nil; package.flatten, package.insert=nil, nil + bd[#bd]=nil + return bd + end + function init_range() + return {{},{}, insert=insert, flatten=flatten} + end +end + -- ----------------------------------- luatexja.adjust.step_factor = 0.5 +luatexja.unary_pars.linestep_factor = function(t) + return luatexja.adjust.step_factor +end +luatexja.adjust.profile_hgap_factor = 1 +luatexja.unary_pars.profile_hgap_factor = function(t) + return luatexja.adjust.profile_hgap_factor +end do local insert = table.insert local rangedimensions, max = node.direct.rangedimensions, math.max - function ltjl.p_profile(before, after, mirrored, bw) - local t = {} - do - local w_acc, d_before = 0, 0 - local x = getlist(before); local xn = node_next(x) - while x do - local w, d - if xn then w, _, d= rangedimensions(before,x,xn) - else w, _, d= rangedimensions(before,x) end - if d~=d_before then - d_before = d; t[w_acc] = t[w_acc] or {} - if t[w_acc][1] then t[w_acc][1]=max(t[w_acc][1],d) - else t[w_acc][1]=d end - end - w_acc = w_acc + w - x = xn; if x then xn = node_next(x) end - end - end - do - local w_acc, h_before = 0, 0 - local x = getlist(after); local xn = node_next(x) - while x do - local w, h, d - if xn then w, h, d = rangedimensions(after,x,xn) - else w, h,d = rangedimensions(after,x) end - if mirrored then h=d end - if h~=h_before then - h_before = h; t[w_acc] = t[w_acc] or {} - if t[w_acc][2] then t[w_acc][2]=max(t[w_acc][2],h) - else t[w_acc][2]=h end - end - w_acc = w_acc + w - x = xn; if x then xn = node_next(x) end + local function profile_inner(box, range, ind, vmirrored, adj) + local w_acc, d_before = getfield(box,'shift'), 0 + local x = getlist(box); local xn = node_next(x) + while x do + local w, h, d + if xn then w, h, d= rangedimensions(box,x,xn) + else w, h, d= rangedimensions(box,x) end + if vmirrored then h=d end + local w_new = w_acc + w + if w>=0 then + range:insert(ind, h, w_acc-adj, w_new) + else + range:insert(ind, h, w_new-adj, w_acc) end + w_acc = w_new; x = xn; if x then xn = node_next(x) end end - local t2 = {} - for i,v in pairs(t) do insert(t2, { i, v[1], v[2] } ) end - table.sort(t2, function(a,b) return a[1]dmax then dmax=d end if h>hmax then hmax=h end - if (bw-h-d)