OSDN Git Service

Partly fixed ticket #25519.
authorHironori Kitagawa <h_kitagawa2001@yahoo.co.jp>
Tue, 28 Jun 2011 08:50:33 +0000 (17:50 +0900)
committerHironori Kitagawa <h_kitagawa2001@yahoo.co.jp>
Tue, 28 Jun 2011 08:50:33 +0000 (17:50 +0900)
 - new lua file: src/luatexja/setwidth.lua
 - new test: test/test06-offset.tex

doc/jfmglue.pdf
doc/sample1.pdf
src/luatexja-core.lua
src/luatexja-core.sty
src/luatexja/jfmglue.lua
src/luatexja/setwidth.lua [new file with mode: 0644]
test/test01-noembed.pdf
test/test04-jfm.pdf
test/test05-speed.pdf [deleted file]
test/test06-offset.pdf [new file with mode: 0644]
test/test06-offset.tex [new file with mode: 0644]

index cdf9eb5..20fb35c 100644 (file)
Binary files a/doc/jfmglue.pdf and b/doc/jfmglue.pdf differ
index 9c26c0a..4e21aba 100644 (file)
Binary files a/doc/sample1.pdf and b/doc/sample1.pdf differ
index dff6d99..ba5330f 100644 (file)
@@ -1,8 +1,13 @@
-local ltjb = luatexja.base
-local ltjc = luatexja.charrange
-local ltjs = luatexja.stack
-local ltjj = luatexja.jfmglue
-local ltjf = luatexja.jfont
+require('lualibs')
+require('luatexja.rmlgbm');    local ltjr = luatexja.rmlgbm -- must be 1st
+require('luatexja.base');      local ltjb = luatexja.base
+require('luatexja.charrange'); local ltjc = luatexja.charrange
+require('luatexja.jfont');     local ltjf = luatexja.jfont
+require('luatexja.inputbuf');  local ltji = luatexja.inputbuf
+require('luatexja.jfmglue');   local ltjj = luatexja.jfmglue
+require('luatexja.pretreat');  local ltjp = luatexja.pretreat
+require('luatexja.stack');     local ltjs = luatexja.stack
+require('luatexja.setwidth');  local ltjw = luatexja.setwidth
 
 local node_type = node.type
 local node_new = node.new
@@ -96,12 +101,6 @@ local function print_spec(p)
 return out
 end
 
--- return true if and only if p is a Japanese character node
-local function is_japanese_glyph_node(p)
-   return p and (p.id==id_glyph) 
-   and (p.font==has_attr(p,attr_curjfnt))
-end
-
 function math.two_add(a,b) return a+b end
 function math.two_average(a,b) return (a+b)/2 end
 
@@ -182,98 +181,12 @@ function ltj.ext_print_global()
 end
 
 
-------------------------------------------------------------------------
--- MAIN PROCESS STEP 4: width of japanese chars (prefix: main4)
-------------------------------------------------------------------------
-
--- TeX's \hss
-local function main4_get_hss()
-   local hss = node_new(id_glue)
-   local fil_spec = node_new(id_glue_spec)
-   fil_spec.width = 0
-   fil_spec.stretch = 65536
-   fil_spec.stretch_order = 2
-   fil_spec.shrink = 65536
-   fil_spec.shrink_order = 2
-   hss.spec = fil_spec
-   return hss
-end
-
-local function main4_set_ja_width(head, dir)
-   local p = head
-   local met_tb, t, s, g, q, a, h
-   local m = false -- is in math mode?
-   while p do
-      local v=has_attr(p,attr_yablshift) or 0
-      if p.id==id_glyph then
-        p.yoffset = p.yoffset-v
-        if is_japanese_glyph_node(p) then
-           met_tb = ltjf.font_metric_table[p.font]
-           t = ltjf.metrics[met_tb.jfm]
-           s = t.char_type[has_attr(p,attr_jchar_class)]
-           if s.width ~= 'prop' and
-              not(s.left==0.0 and s.down==0.0 and s.align=='left' 
-                  and round(s.width*met_tb.size)==p.width) then
-              -- must be encapsuled by a \hbox
-              head, q = node.remove(head, p)
-              local full_width = round(s.width*met_tb.size)
-              p.yoffset=p.yoffset-round(met_tb.size*s.down)
-              p.xoffset=p.xoffset-round(met_tb.size*s.left)
-              
-              -- The next if block sets h:=(head of a new list)
-              if s.align=='left' then
-                 h = node_new(id_kern); h.subtype = 0
-                 h.kern = full_width - p.width
-                 p.next = h; h = p
-              elseif s.align=='right' then
-                 h = node_new(id_kern); h.subtype = 0
-                 h.kern = full_width - p.width
-                 p.next = nil; h.next = p
-              elseif s.align=='middle' then
-                 local total = full_width - p.width
-                 h = node_new(id_kern); h.subtype = 0
-                 h.kern = round(total/2); p.next = h
-                 h = node_new(id_kern); h.subtype = 0
-                 h.kern = total - round(total/2); h.next = p
-              end
-              g = node_new(id_hlist); g.width = full_width
-              g.height = round(met_tb.size*s.height)
-              g.depth = round(met_tb.size*s.depth)
-              g.glue_set = 0; g.glue_order = 0; g.head = h
-              g.shift = 0; g.dir = dir or 'TLT'
-              node.set_attribute(g, attr_icflag, PACKED)
-              if q then
-                 head = node_insert_before(head, q, g)
-              else
-                 head = node_insert_after(head, node.tail(head), g)
-              end
-              p = q
-           else p=node_next(p)
-           end
-        else p=node_next(p)
-        end
-      elseif p.id==id_math then
-        m=(p.subtype==0); p=node_next(p)
-      else
-        if m then
-           if p.id==id_hlist or p.id==id_vlist then
-              p.shift=p.shift+v
-           elseif p.id==id_rule then
-              p.height=p.height-v; p.depth=p.depth+v 
-           end
-        end
-        p=node_next(p)
-      end
-   end
-return head
-end
-
 -- main process
 -- mode = true iff main_process is called from pre_linebreak_filter
 local function main_process(head, mode, dir)
    local p = head
    p = ltjj.main(p,mode)
-   p = main4_set_ja_width(p, dir)
+   p = ltjw.set_ja_width(p, dir)
    return p
 end
 
@@ -305,7 +218,10 @@ function debug_show_node_X(p,print_fn)
    local base = debug_depth .. string.format('%X', has_attr(p,attr_icflag) or 0) 
      .. ' ' .. pt .. ' ' ..  p.subtype 
    if pt == 'glyph' then
-      print_fn(base, utf.char(p.char), p.font)
+      s = base .. ' ' .. utf.char(p.char) .. ' ' .. tostring(p.font)
+         .. ' (' .. print_scaled(p.height) .. '+' 
+         .. print_scaled(p.depth) .. ')x' .. print_scaled(p.width)
+      print_fn(s)
    elseif pt=='hlist' then
       s = base .. '(' .. print_scaled(p.height) .. '+' 
          .. print_scaled(p.depth) .. ')x' .. print_scaled(p.width)
index a59e56d..3d13c0e 100644 (file)
     texio.write_nl("("..path..")")
     dofile(path)
   end
-  require('lualibs')
-  
-
-    }
-\RequireLuaModule{luatexja.rmlgbm} % For Ryumin-Light and GothicBBB-Medium.
-\RequireLuaModule{luatexja.charrange}
-\RequireLuaModule{luatexja.jfont}
-\RequireLuaModule{luatexja.stack}
-\RequireLuaModule{luatexja.pretreat}
-\RequireLuaModule{luatexja.inputbuf}
-\RequireLuaModule{luatexja.jfmglue}
-
-\directlua{
   ltj.loadlua('luatexja-core.lua')
 }
 
index 423e683..1cb9db7 100644 (file)
@@ -10,10 +10,10 @@ luatexbase.provides_module({
 module('luatexja.jfmglue', package.seeall)
 local err, warn, info, log = luatexbase.errwarinf(_NAME)
 
-require('luatexja.base');     local ltjb = luatexja.base
-require('luatexja.stack');    local ltjs = luatexja.stack
-require('luatexja.jfont');    local ltjf = luatexja.jfont
-require('luatexja.pretreat'); local ltjp = luatexja.pretreat
+require('luatexja.base');      local ltjb = luatexja.base
+require('luatexja.stack');     local ltjs = luatexja.stack
+require('luatexja.jfont');     local ltjf = luatexja.jfont
+require('luatexja.pretreat');  local ltjp = luatexja.pretreat
 
 local node_type = node.type
 local node_new = node.new
diff --git a/src/luatexja/setwidth.lua b/src/luatexja/setwidth.lua
new file mode 100644 (file)
index 0000000..a1c528e
--- /dev/null
@@ -0,0 +1,122 @@
+--
+-- luatexja/setwidth.lua
+--
+luatexbase.provides_module({
+  name = 'luatexja.setwidth',
+  date = '2011/06/28',
+  version = '0.1',
+  description = '',
+})
+module('luatexja.setwidth', package.seeall)
+local err, warn, info, log = luatexbase.errwarinf(_NAME)
+
+require('luatexja.base');      local ltjb = luatexja.base
+require('luatexja.jfont');     local ltjf = luatexja.jfont
+
+local node_type = node.type
+local node_new = node.new
+local node_tail = node.tail
+local node_next = node.next
+local has_attr = node.has_attribute
+local set_attr = node.set_attribute
+local node_insert_before = node.insert_before
+local node_insert_after = node.insert_after
+local round = tex.round
+
+local id_glyph = node.id('glyph')
+local id_kern = node.id('kern')
+local id_hlist = node.id('hlist')
+local id_vlist = node.id('vlist')
+local id_rule = node.id('rule')
+local id_math = node.id('math')
+
+local attr_jchar_class = luatexbase.attributes['ltj@charclass']
+local attr_curjfnt = luatexbase.attributes['ltj@curjfnt']
+local attr_yablshift = luatexbase.attributes['ltj@yablshift']
+local attr_icflag = luatexbase.attributes['ltj@icflag']
+
+local PACKED = 2
+
+local met_tb = {}
+local char_data = {}
+local head
+
+-- return true if and only if p is a Japanese character node
+local function is_japanese_glyph_node(p)
+   return p.font==has_attr(p, attr_curjfnt)
+end
+
+local function capsule_glyph(p, dir)
+   local h, box, q, fwidth, fheight, fdepth
+   p.xoffset= p.xoffset - round(met_tb.size*char_data.left)
+   if char_data.width ~= 'prop' then
+      fwidth = round(char_data.width*met_tb.size)
+   else fwidth = p.width end
+   fheight = round(met_tb.size*char_data.height)
+   fdepth = round(met_tb.size*char_data.depth)
+   if p.width ~= fwidth or p.height ~= fheight or p.depth ~= fdepth then
+      local y_shift = - p.yoffset + (has_attr(p,attr_yablshift) or 0)
+      p.yoffset = -round(met_tb.size*char_data.down)
+      head, q = node.remove(head, p)
+      local total = fwidth - p.width
+      if total == 0 then
+        h = p; p.next = nil
+      else
+        h = node_new(id_kern); h.subtype = 0
+        if char_data.align=='left' then
+           h.kern = total; p.next = h; h = p
+        elseif char_data.align=='right' then
+           h.kern = total; p.next = nil; h.next = p
+        elseif char_data.align=='middle' then
+           h.kern = round(total/2); p.next = h
+           h = node_new(id_kern); h.subtype = 0
+           h.kern = total - round(total/2); h.next = p
+        end
+      end
+      box = node_new(id_hlist); 
+      box.width = fwidth; box.height = fheight; box.depth = fdepth
+      box.glue_set = 0; box.glue_order = 0; box.head = h
+      box.shift = y_shift; box.dir = dir or 'TLT'
+      set_attr(box, attr_icflag, PACKED)
+      if q then
+        head = node_insert_before(head, q, box)
+      else
+        head = node_insert_after(head, node_tail(head), box)
+      end
+      return q
+   else
+      p.yoffset = p.yoffset - (has_attr(p, attr_yablshift) or 0) - round(met_tb.size*char_data.down)
+      return node_next(p)
+   end
+end
+
+function set_ja_width(ahead, dir)
+   local p = ahead; head  = ahead
+   local m = false -- is in math mode?
+   while p do
+      if p.id==id_glyph then
+        if is_japanese_glyph_node(p) then
+           met_tb = ltjf.font_metric_table[p.font]
+           char_data = ltjf.metrics[met_tb.jfm].char_type[has_attr(p, attr_jchar_class)]
+           p = capsule_glyph(p, dir)
+        else 
+           p.yoffset = p.yoffset - (has_attr(p,attr_yablshift) or 0); p = node_next(p)
+        end
+      elseif p.id==id_math then
+        m = (p.subtype==0); p = node_next(p)
+      else
+        if m then
+           if p.id==id_hlist or p.id==id_vlist then
+              p.shift = p.shift + (has_attr(p,attr_yablshift) or 0)
+           elseif p.id==id_rule then
+              local v = has_attr(p,attr_yablshift) or 0
+              p.height = p.height - v; p.depth = p.depth + v 
+           end
+        end
+        p = node_next(p)
+      end
+   end
+   -- adjust attr_icflag
+   tex.attribute[attr_icflag] = -(0x7FFFFFFF)
+   return head
+end
index 1e02470..3f92bad 100644 (file)
Binary files a/test/test01-noembed.pdf and b/test/test01-noembed.pdf differ
index ba2980f..679b21a 100644 (file)
Binary files a/test/test04-jfm.pdf and b/test/test04-jfm.pdf differ
diff --git a/test/test05-speed.pdf b/test/test05-speed.pdf
deleted file mode 100644 (file)
index d6dc39f..0000000
Binary files a/test/test05-speed.pdf and /dev/null differ
diff --git a/test/test06-offset.pdf b/test/test06-offset.pdf
new file mode 100644 (file)
index 0000000..9b1e3bf
Binary files /dev/null and b/test/test06-offset.pdf differ
diff --git a/test/test06-offset.tex b/test/test06-offset.tex
new file mode 100644 (file)
index 0000000..461c51d
--- /dev/null
@@ -0,0 +1,44 @@
+%#!luatex
+\input luatexja.sty
+
+\def\gbox#1{\noindent\setbox0=\hbox{\d#1}
+  \vrule height 0.2pt depth 0.2pt width \dimexpr \wd0+10pt\relax
+  \kern\dimexpr -\wd0-5pt\relax\vrule height\ht0 depth \dp0\hbox{\copy0}%
+  \vrule height\ht0 depth \dp0\relax}
+\font\d=cmr17 at 20pt
+\baselineskip=40pt
+
+\jfont\sixgt={psft:GothicBBB-Medium:jfm=ujis} at 6pt
+\font\sixtt=cmtt10 at 6pt
+\def\dumplist#1{\par\noindent\leavevmode
+\hbox to 0.2\hsize{\copy#1\hss}%
+\vbox{\hsize=0.6\hsize\sixtt\baselineskip=7.2pt\sixgt\let\\=\relax
+\directlua{ltj.ext_show_node_list(tex.getbox(#1).head, '\\par ', tex.print)}\hrule}}
+
+\ltjsetparameter{yalbaselineshift=0pt,yjabaselineshift=0pt}
+\setbox0=\hbox{\d Hy}\dumplist0
+
+\ltjsetparameter{yalbaselineshift=-10pt}\gbox{Hy}
+\ltjsetparameter{yalbaselineshift=-0pt}\gbox{Hy}
+\ltjsetparameter{yalbaselineshift=10pt}\gbox{Hy}
+\ltjsetparameter{yalbaselineshift=20pt}\gbox{Hy}
+
+\jfont\f=psft:Ryumin-Light:jfm=ujis at 20pt\f
+\ltjsetparameter{yalbaselineshift=0pt,yjabaselineshift=0pt}
+\setbox0=\hbox{\f あ}\dumplist0
+
+\ltjsetparameter{yjabaselineshift=-10pt}\gbox{あ}
+\ltjsetparameter{yjabaselineshift=0pt}\gbox{あ}
+\ltjsetparameter{yjabaselineshift=10pt}\gbox{あ}
+\ltjsetparameter{yjabaselineshift=20pt}\gbox{あ}
+
+\jfont\f=name:IPAMincho:jfm=ujis at 20pt\f
+\ltjsetparameter{yalbaselineshift=0pt,yjabaselineshift=0pt}
+\setbox0=\hbox{\f あ}\dumplist0
+
+\ltjsetparameter{yjabaselineshift=-10pt}\gbox{あ}
+\ltjsetparameter{yjabaselineshift=0pt}\gbox{あ}
+\ltjsetparameter{yjabaselineshift=10pt}\gbox{あ}
+\ltjsetparameter{yjabaselineshift=20pt}\gbox{あ}
+
+\end