OSDN Git Service

lltjp-fontspec: adapt fontspec 2.7e, and removed codes for <2.7c
[luatex-ja/luatexja.git] / test / test27-lineprofile.tex
index 7272b10..7c8e337 100644 (file)
@@ -1,152 +1,8 @@
 \documentclass[10ptj]{ltjsarticle}
 \usepackage[width=40\zw, lines=40,centering]{geometry}
-\usepackage{amsmath,luacode,xcolor}
-\begin{luacode}
-  lineskip = {}
-do
-  local insert = table.insert
-  local rangedimensions, max = node.rangedimensions, math.max
-  function lineskip.p_profile(before, after)
-    local t = {}
-    do
-      local w_acc, d_before = 0, 0
-      local x = before.head; local xn = x.next
-      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 = x.next end
-      end
-    end
-    do
-      local w_acc, h_before = 0, 0
-      local x = after.head; local xn = x.next
-      while x do
-        local w, h
-        if xn then w, h = rangedimensions(after,x,xn)
-        else w, h = rangedimensions(after,x) 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 = x.next end
-      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]<b[1] end)
-    do
-      local bls = tex.baselineskip.width
-      local dmax, d, hmax, h, lmin = 0, 0, 0, 0, 1/0
-      for i,v in ipairs(t2) do
-        d, h = (v[2] or d), (v[3] or h)
-        if d>dmax then dmax=d end
-        if h>hmax then hmax=h end
-        if (bls-h-d)<lmin then lmin=bls-h-d end
-      end
-      if lmin==1/0 then lmin = 0 end
-      return lmin, bls - lmin - (before.depth+after.height)
-    end
-  end
-  function lineskip.p_dummy(before, after)
-    return nil, 0
-  end
-end
-do
-  local setglue = node.setglue
-  local floor, min = math.floor, math.min
-  function lineskip.l_dummy(dist, g, adj, normal)
-    if dist < tex.lineskiplimit then
-      local ng = tex.lineskip; g.subtype=2
-      setglue(g, ng.width + adj, ng.stretch, ng.shrink, ng.stretch_order, ng.shrink_order)
-    else
-      local ng = tex.baselineskip; g.subtype=2
-      setglue(g, normal, ng.stretch, ng.shrink, ng.stretch_order, ng.shrink_order)
-    end
-  end
-  function lineskip.l_fixed(dist, g, adj, normal)
-    local ng = tex.baselineskip; local f = ng.width*lineskip.fixed_factor
-    if f==0 then return lineskip.l_dummy(dist, g, adj, normal) end
-    g.subtype=2
-    setglue(g,
-      normal - f * floor((dist-lineskip.fixed_mindist)/f),
-      ng.stretch, ng.shrink, ng.stretch_order, ng.shrink_order)
-  end
-end
-
-  local l_profiler, l_skip = lineskip.p_dummy, lineskip.l_dummy
-  function lineskip.setting(profiler, skip_method)
-    l_profiler = lineskip['p_'..tostring(profiler)] or lineskip.p_dummy
-    l_skip = lineskip['l_'..tostring(skip_method)] or lineskip.l_dummy
-  end
-  
-do
-  luatexbase.add_to_callback('post_linebreak_filter',
-    function(h)
-      for x in node.traverse_id(12, h) do
-        if (x.subtype==1)or(x.subtype==2)then
-          local p, n = x.prev, x.next
-          if p then 
-            while ((p.id==14)or(p.id==12)or(p.id==13)) and p.prev do p = p.prev end
-            if p.id==0 and n.id==0 then
-              local normal = tex.baselineskip.width - p.depth - n.height
-              local lmin, adj; lmin, adj = l_profiler(p,n)
-              l_skip(lmin or normal,x,adj, normal)
-            end
-          end
-        end
-      end
-      return true
-    end, 'test', 10000
-  )
-end
-
-do
-  local to_direct, to_node = node.direct.todirect, node.direct.tonode
-  local make_dir_whatsit = luatexja.direction.make_dir_whatsit
-  local get_dir_count = luatexja.direction.get_dir_count
-  local function lineskip_append_vlist(b, loc, prev, mirrored)
-     local new_b = to_node(loc=='box' and 
-          make_dir_whatsit(to_direct(b), to_direct(b), get_dir_count(), 'append_vlist')) or b
-     local tail = tex.nest[tex.nest.ptr].tail
-     if tail and tail.id==12 and tail.subtype==3 then
-        tail = tail.prev
-     end
-     if tail and (prev > -65536000) then
-        local normal = tex.baselineskip.width - prev - new_b.height
-        local lmin, adj = nil, 0;
-        if tail.id==0 and new_b.id==0 then
-          if tail.depth==prev then lmin, adj = l_profiler(tail,new_b) end
-        end
-        local g = node.new(12); l_skip(lmin or normal, g, adj, normal)
-        node.write(g)
-      end
-      node.write(new_b)
-      tex.prevdepth = new_b.depth
-      return nil -- do nothing on tex side
-   end
-   luatexbase.remove_from_callback('append_to_vlist_filter','ltj.direction')
-   luatexja.base.add_to_callback('append_to_vlist_filter',
-                       lineskip_append_vlist,
-                       'line profile', 10000)
-end  
-\end{luacode}
+\usepackage{amsmath,luacode,xcolor,luatexja-adjust}
 \begin{document}
-\directlua{%
-  lineskip.fixed_mindist = tex.lineskip.width
-  lineskip.fixed_factor = 0.5
-}
-
-
-\def\R#1#2{\directlua{lineskip.setting('#1','#2')}%
+\def\R#1#2{\ltjenableadjust[profile=#1,linestep=#2]%
 \noindent\fbox{\parbox{25\zw}{%
 \baselineskip14pt\noindent
 \setbox2=\vtop{\noindent\hsize20\zw\textcolor{cyan!30!white}{%
@@ -157,9 +13,20 @@ end
  □□□□■□□□□■□□□□■□□□□■□□□□■□□□□■□□□□■□□□□■
  □□□□■□□□□■□□□□■□□□□■□□□□■□□□□■□□□□■□□□□■
  □□□□■□□□□■□□□□■□□□□■□□□□■□□□□■□□□□■□□□□■
+ □□□□■□□□□■□□□□■□□□□■□□□□■□□□□■□□□□■□□□□■
+ □□□□■□□□□■□□□□■□□□□■□□□□■□□□□■□□□□■□□□□■
+ □□□□■□□□□■□□□□■□□□□■□□□□■□□□□■□□□□■□□□□■
+ □□□□■□□□□■□□□□■□□□□■□□□□■□□□□■□□□□■□□□□■
+ □□□□■□□□□■□□□□■□□□□■□□□□■□□□□■□□□□■□□□□■
+ □□□□■□□□□■□□□□■□□□□■□□□□■□□□□■□□□□■□□□□■
+ □□□□■□□□□■□□□□■□□□□■□□□□■□□□□■□□□□■□□□□■
+ □□□□■□□□□■□□□□■□□□□■□□□□■□□□□■□□□□■□□□□■
+ □□□□■□□□□■□□□□■□□□□■□□□□■□□□□■□□□□■□□□□■
  □□□□■□□□□■□□□□■□□□□■
 }}\dp2=0pt\rlap{\copy2}\par\vspace*{-\baselineskip}
-\textbf{#1, #2}\\
+\textbf{profile: #1, linestep: #2}\par
+\vrule height 2pt depth 0pt width 10\zw\\
+\vrule height 2pt depth 0pt width 10\zw\\
 \the\baselineskip あああああああああああああああ\\
 あああああああああ$X_{X_{X_X}}$ああああああ\\
 ああああああああああああああああああ\\
@@ -171,15 +38,64 @@ end
 あいであるから$b=\dfrac1{X_2}$となる.新段落!\\
 一方$\dfrac{A^A}{B_B}=21$なので……
 
+\hbox{感じ感じ$\displaystyle\int$}
+ほげであるから$b=\dfrac1{X_2}$となる.新段落!\\
+一方$\dfrac{A^A}{B_B}=21$なので……
+
+\hrule
+かきであるから$b=\dfrac1{X_2}$となる.hrule無効\\
+一方$\dfrac{A^A}{B_B}=21$なので……
+
 \prevdepth0pt
 うえであるから$b=\dfrac1{X_2}$prevdepth設定のため無効\\
 一方$\dfrac{A^A}{B_B}=21$なので……
-}}\par}
+}}\newpage}
+
+
+\R{false}{false}
+\R{true}{false}
+\R{false}{true}
+\R{true}{true}
+
+\ltjgetparameter{linestep_factor}
+
+\ltjdisableadjust
+\def\R#1#2{\ltjenableadjust[profile=#1,priority=#2]%
+\noindent\fbox{\parbox[t]{20\zw}{%
+\baselineskip14pt\noindent
+\textbf{profile: #1, priority: #2}\par
+  \ltjsetparameter{xkanjiskip=.25\zw plus 20pt minus 20pt}
+  ああxあaaaあxあx\vrule height 30pt depth 30pt width 9.7\zw「\break
+  \vrule height 30pt depth 30pt width9.6\zw xあxあxあaaaああ「\break
+}}}
+
+\R{false}{false}%
+\R{true}{false}\\
+\R{false}{true}%
+\R{true}{true}%
+
+\ltjdisableadjust
+\ltjenableadjust[profile]
+
+\def\R#1{%
+  \fbox{\parbox[t]{130pt}{\lineskip1pt\textbf{#1pt (\texttt{lineskip}: \the\lineskip)}\\%
+    \noindent\vrule height 5pt depth 50pt width 45pt\kern30pt%
+    \vrule height 5pt depth 50pt width 30pt\\
+    \textcolor{red}{\kern\dimexpr45pt+#1pt\vrule height 50pt depth 5pt width20pt}%
+    \textcolor{blue}{\kern-40pt\vrule height 5pt depth 5pt width 60pt}%
+  }}\hskip0pt\ignorespaces
+}
+
+\newpage
+\texttt{profile\_hgap\_factor=\ltjgetparameter{profile_hgap_factor}}\par
+\noindent
+\R{0}\R{0.5}\R{1}\R{2}\R{8}\R{9}\R{10}
 
 
-\R{null}{null}
-\R{profile}{null}
-\R{null}{fixed}
-\R{profile}{fixed}
+\newpage
+\ltjsetparameter{profile_hgap_factor=2}
+\texttt{profile\_hgap\_factor=\ltjgetparameter{profile_hgap_factor}}\par
+\noindent
+\R{0}\R{0.5}\R{1}\R{2}\R{8}\R{9}\R{10}
 
 \end{document}