OSDN Git Service

implement \tfont. (Alignment does not work)
authorHironori Kitagawa <h_kitagawa2001@yahoo.co.jp>
Tue, 6 May 2014 12:34:52 +0000 (21:34 +0900)
committerHironori Kitagawa <h_kitagawa2001@yahoo.co.jp>
Tue, 6 May 2014 12:34:52 +0000 (21:34 +0900)
13 files changed:
src/jfm-ujisv.lua [new file with mode: 0644]
src/ltj-direction.lua
src/ltj-jfmglue.lua
src/ltj-jfont.lua
src/ltj-otf.lua
src/ltj-plain.sty
src/ltj-pretreat.lua
src/ltj-rmlgbm.lua
src/ltj-setwidth.lua
src/luatexja-core.sty
src/luatexja.lua
test/test51-vtest.pdf
test/test51-vtest.tex

diff --git a/src/jfm-ujisv.lua b/src/jfm-ujisv.lua
new file mode 100644 (file)
index 0000000..1a73013
--- /dev/null
@@ -0,0 +1,247 @@
+-- -*- coding: utf-8 -*-
+-- jfm-ujis.lua: LuaTeX-ja 標準 JFM
+-- based on upnmlminr-h.tfm (a metric in UTF/OTF package used by upTeX).
+
+-- JIS X 4051:2004 では,行末の句読点や中点はベタなのでそれに従う
+-- kanjiskip:    0pt plus .25zw minus 0pt
+-- xkanjiskip: .25zw plus .25zw (or .0833zw) minus .125zw
+
+
+luatexja.jfont.define_jfm {
+   dir = 'tate',
+   zw = 1.0, zh = 1.0,
+   kanjiskip =  {0.0, 0.25, 0},
+   xkanjiskip = {0.25, 0.25, .125},
+   [0] = {
+      align = 'middle', left = 0.0, down = 0.0,
+      width = 1.0, height = 0.50, depth = 0.50, italic=0.0,
+      glue = {
+        -- [index] = { width, stretch, shrink, [priority, [ratio]] }
+        [1] = { 0.5 , 0.0, 0.5,  0, 1 },
+        [2] = {0, 0, 0},
+        [3] = { 0.25, 0.0, 0.25, 1, 1 },
+        [4] = {0, 0, 0},
+        [6] = {0, 0, 0},
+        [7] = {0, 0, 0},
+         [8] = {0, 0, 0},
+        [9] = {0, 0, 0},
+      }
+   },
+
+   [1] = { -- 開き括弧類
+      chars = {
+        '‘', '“', '〈', '《', '「', '『', '【', '〔', '〖', 
+        '〘', '〝', '(', '[', '{', '⦅'
+      },
+      align = 'right', left = 0.0, down = 0.0,
+      width = 0.5, height = 0.50, depth = 0.50, italic=0.0,
+      glue = {
+-- 3 のみ四分,あとは0
+         [0] = {0, 0, 0},
+         [1] = {0, 0, 0},
+        [2] = {0, 0, 0},
+        [3] = { 0.25, 0.0, 0.25, 1 },
+        [4] = {0, 0, 0},
+        [5] = {0, 0, 0},
+        [6] = {0, 0, 0},
+        [7] = {0, 0, 0},
+         [8] = {0, 0, 0},
+        [9] = {0, 0, 0},
+      }
+   },
+
+   [2] = { -- 閉じ括弧類
+      chars = {
+        '’', '”', '〉', '》', '」', '』', '】', '〕', 
+        '〗', '〙', '〟', ')', ']', '}', '⦆', '、*', ',*'
+      },
+      align = 'left', left = 0.0, down = 0.0,
+      width = 0.5, height = 0.50, depth = 0.50, italic=0.0,
+      glue = {
+-- 3 は四分, 2, 4, 9 は0, あとは0.5
+        [0] = { 0.5 , 0.0, 0.5, 0, -1 },
+        [1] = { 0.5 , 0.0, 0.5, 0, -1 },
+         [2] = {0, 0, 0},
+        [3] = { 0.25, 0.0, 0.25, 1, 1 },
+         [4] = {0, 0, 0},
+        [5] = { 0.5 , 0.0, 0.5, 0, -1 },
+        [6] = { 0.5 , 0.0, 0.5, 0, -1 },
+        [7] = { 0.5 , 0.0, 0.5, 0, -1 },
+        [8] = { 0.5 , 0.0, 0.5, 0, -1 },
+         [9] = {0, 0, 0},
+      }
+   },
+
+   [3] = { -- 中点類
+      chars = {'・', ':', ';'},
+      align = 'middle', left = 0.0, down = 0.0,
+      width = 0.5, height = 0.50, depth = 0.50, italic=0.0,
+      --end_stretch = 0.25,
+      glue = {
+-- 3 のみ 0.5,あとは0.25
+        [0] = { 0.25, 0.0, 0.25, 1, 1 },
+        [1] = { 0.25, 0.0, 0.25, 1, 1 },
+        [2] = { 0.25, 0.0, 0.25, 1, 1 },
+        [3] = { 0.5 , 0.0, 0.5 , 1, 0 },
+        [4] = { 0.25, 0.0, 0.25, 1, 1 },
+        [5] = { 0.25, 0.0, 0.25, 1, 1 },
+        [6] = { 0.25, 0.0, 0.25, 1, 1 },
+        [7] = { 0.25, 0.0, 0.25, 1, 1 },
+        [8] = { 0.25, 0.0, 0.25, 1, 1 },
+        [9] = { 0.25, 0.0, 0.25, 1, 1 },
+      }
+   },
+
+   [4] = { -- 句点類
+      chars = {'。', '.'},
+      align = 'left', left = 0.0, down = 0.0,
+      width = 0.5, height = 0.50, depth = 0.50, italic=0.0,
+      glue = {
+-- 3 は.75, 2, 4 は0, あとは0.5
+        [0] = { 0.5 , 0.0, 0.5, 0, -1 },
+        [1] = { 0.5 , 0.0, 0.5, 0, -1 },
+        [3] = { 0.75, 0.0, 0.25, 1, -1/3 },
+        [5] = { 0.5 , 0.0, 0.5, 0, -1 },
+        [6] = { 0.5 , 0.0, 0.5, 0, -1 },
+        [7] = { 0.5 , 0.0, 0.5, 0, -1 },
+        [8] = { 0.5 , 0.0, 0.5, 0, -1 },
+         [9] = { 0.5 , 0.0, 0.5, 0, -1 },
+      }
+   },
+
+   [5] = { -- ダッシュ
+      chars = { '—', '―', '‥', '…', '〳', '〴', '〵', },
+      align = 'left', left = 0.0, down = 0.0,
+      width = 1.0, height = 0.50, depth = 0.50, italic=0.0,
+      glue = {
+        [1] = { 0.5 , 0.0, 0.5, 0, 1 },
+        [2] = {0, 0, 0},
+        [3] = { 0.25, 0.0, 0.25, 1, 1 },
+        [4] = {0, 0, 0},
+        [6] = {0, 0, 0},
+        [9] = {0, 0, 0},
+      },
+      kern = {
+        [5] = 0.0
+      }
+   },
+
+   [6] = { -- 感嘆符・疑問符
+      chars = { '?', '!', '‼', '⁇', '⁈', '⁉', },
+      align = 'left', left = 0.0, down = 0.0,
+      width = 1.0, height = 0.50, depth = 0.50, italic=0.0,
+      glue = {
+         [0] = { 0.5 , 0.0, 0.5, 0, 1 },
+        [1] = { 0.5 , 0.0, 0.5, 0, 1 },
+        [2] = {0, 0, 0},
+        [3] = { 0.75, 0.0, 0.25, 1, 1 },
+        [4] = {0, 0, 0},
+        [6] = {0, 0, 0},
+        [7] = { 0.5 , 0.0, 0.5, 0, 1 },
+        [8] = {0, 0, 0},
+        [9] = {0, 0, 0},
+      },
+      kern = {
+        [5] = 0.0
+      }
+   },
+
+   [7] = { -- 半角カナ
+      chars = {
+        '。', '「', '」', '、', '・', 'ヲ', 'ァ', 'ィ', 'ゥ', 
+        'ェ', 'ォ', 'ャ', 'ュ', 'ョ', 'ッ', 'ー', 'ア', 'イ', 
+        'ウ', 'エ', 'オ', 'カ', 'キ', 'ク', 'ケ', 'コ', 'サ', 
+        'シ', 'ス', 'セ', 'ソ', 'タ', 'チ', 'ツ', 'テ', 'ト', 
+        'ナ', 'ニ', 'ヌ', 'ネ', 'ノ', 'ハ', 'ヒ', 'フ', 'ヘ', 
+        'ホ', 'マ', 'ミ', 'ム', 'メ', 'モ', 'ヤ', 'ユ', 'ヨ', 
+        'ラ', 'リ', 'ル', 'レ', 'ロ', 'ワ', 'ン', '゙', '゚',
+        "AJ1-516", "AJ1-517", "AJ1-518", "AJ1-519", "AJ1-520", "AJ1-521", "AJ1-522", 
+        "AJ1-523", "AJ1-524", "AJ1-525", "AJ1-526", "AJ1-527", "AJ1-528", "AJ1-529", 
+        "AJ1-530", "AJ1-531", "AJ1-532", "AJ1-533", "AJ1-534", "AJ1-535", "AJ1-536", 
+        "AJ1-537", "AJ1-538", "AJ1-539", "AJ1-540", "AJ1-541", "AJ1-542", "AJ1-543", 
+        "AJ1-544", "AJ1-545", "AJ1-546", "AJ1-547", "AJ1-548", "AJ1-549", "AJ1-550", 
+        "AJ1-551", "AJ1-552", "AJ1-553", "AJ1-554", "AJ1-555", "AJ1-556", "AJ1-557", 
+        "AJ1-558", "AJ1-559", "AJ1-560", "AJ1-561", "AJ1-562", "AJ1-563", "AJ1-564", 
+        "AJ1-565", "AJ1-566", "AJ1-567", "AJ1-568", "AJ1-569", "AJ1-570", "AJ1-571", 
+        "AJ1-572", "AJ1-573", "AJ1-574", "AJ1-575", "AJ1-576", "AJ1-577", "AJ1-578", 
+        "AJ1-579", "AJ1-580", "AJ1-581", "AJ1-582", "AJ1-583", "AJ1-584", "AJ1-585", 
+        "AJ1-586", "AJ1-587", "AJ1-588", "AJ1-589", "AJ1-590", "AJ1-591", "AJ1-592", 
+        "AJ1-593", "AJ1-594", "AJ1-595", "AJ1-596", "AJ1-597", "AJ1-598",
+      },
+      align = 'left', left = 0.0, down = 0.0,
+      width = 0.5, height = 0.50, depth = 0.50, italic=0.0,      
+      glue = {
+        [1] = { 0.5 , 0.0, 0.5, 0, 1 },
+        [2] = {0, 0, 0},
+        [3] = { 0.25, 0.0, 0.25, 1, 1 },
+        [4] = {0, 0, 0},
+        [6] = {0, 0, 0},
+        [7] = {0, 0, 0},
+         [8] = {0, 0, 0},
+        [9] = {0, 0, 0},
+      }
+   },
+
+   [8] = { -- 罫線類.
+      chars = {
+        '─', '━', '│', '┃', '┄', '┅', '┆', '┇',
+        '┈', '┉', '┊', '┋', '┌', '┍', '┎', '┏',
+        '┐', '┑', '┒', '┓', '└', '┕', '┖', '┗',
+        '┘', '┙', '┚', '┛', '├', '┝', '┞', '┟',
+        '┠', '┡', '┢', '┣', '┤', '┥', '┦', '┧',
+        '┨', '┩', '┪', '┫', '┬', '┭', '┮', '┯',
+        '┰', '┱', '┲', '┳', '┴', '┵', '┶', '┷',
+        '┸', '┹', '┺', '┻', '┼', '┽', '┾', '┿',
+        '╀', '╁', '╂', '╃', '╄', '╅', '╆', '╇', 
+        '╈', '╉', '╊', '╋', '╌', '╍', '╎', '╏',
+        '═', '║', '╒', '╓', '╔', '╕', '╖', '╗',
+        '╘', '╙', '╚', '╛', '╜', '╝', '╞', '╟',
+        '╠', '╡', '╢', '╣', '╤', '╥', '╦', '╧',
+        '╨', '╩', '╪', '╫', '╬', '╭', '╮', '╯',
+        '╰', '╱', '╲', '╳', '╴', '╵', '╶', '╷',
+        '╸', '╹', '╺', '╻', '╼', '╽', '╾', '╿',
+      },
+      align = 'left', left = 0.0, down = 0.0,
+      width = 1.0, height = 0.50, depth = 0.50, italic=0.0,
+      glue = {
+        [1] = { 0.5 , 0.0, 0.5, 0, 1 },
+        [2] = {0, 0, 0},
+        [3] = { 0.25, 0.0, 0.25, 1, 1 },
+        [4] = {0, 0, 0},
+        [6] = {0, 0, 0},
+        [9] = {0, 0, 0},
+      },
+      kern = {
+        [8] = 0.0
+      }
+   },
+
+   [9] = { -- 和字間隔
+      chars = {
+        ' '
+      },
+      align = 'left', left = 0.0, down = 0.0,
+      width = 1.0, height = 0.50, depth = 0.50, italic=0.0,
+      glue = {
+         [0] = {0, 0, 0}, 
+         [1] = {0, 0, 0}, 
+         [2] = {0, 0, 0}, 
+        [3] = { 0.25, 0.0, 0.25, 1 },
+         [4] = {0, 0, 0}, 
+         [5] = {0, 0, 0}, 
+         [6] = {0, 0, 0}, 
+         [7] = {0, 0, 0}, 
+         [8] = {0, 0, 0}, 
+         [9] = {0, 0, 0}, 
+      },
+   },
+
+
+   [99] = { -- box末尾
+      chars = {'boxbdd', 'parbdd'},
+      glue = {
+        [3] = { 0.25, 0.0, 0.25, 1 },
+      }
+   },
+
+}
index 0bea28f..8717556 100644 (file)
@@ -161,12 +161,10 @@ do
             setfield(b, 'head', node_next(bh))
            set_attr(b, attr_icflag, PROCESSED)
             node_free(bh)
-            print('FROM WHATSit')
       else
-        old_dir = has_attr(b, attr_dir)
-        if old_dir==0 then old_dir =4 end
+        old_dir = has_attr(b, attr_dir) or dir_yoko
+        if old_dir==0 then old_dir =dir_yoko end
       end
-      print(old_dir, new_dir)
       if old_dir==new_dir  then 
         set_attr(b, attr_icflag, PROCESSED)
         return head, node_next(b), b, false
@@ -229,7 +227,7 @@ do
    end
    local function process_dir_node(head)
       local h = to_direct(head)
-      local x, new_dir = h, ltjs.table_current_stack[DIR]
+      local x, new_dir = h, ltjs.table_current_stack[DIR] or dir_yoko 
       while x do
         local xid = getid(x)
         if (xid==id_hlist and has_attr(x, attr_icflag)~=PACKED) or xid==id_vlist then
@@ -244,3 +242,60 @@ do
    luatexbase.add_to_callback('vpack_filter', 
                              process_dir_node, 'ltj.dir_node', 10001)
 end
+
+local font_vert_table = {} -- key: fontnumber
+do
+   local font_vert_basename = {} -- key: basename
+
+   local function add_feature_table(tname, src, dest)
+      for i,v in pairs(src) do
+        if type(v.slookups)=='table' then
+           local s = v.slookups[tname]
+           if s and not dest[i] then
+              dest[i] = s
+           end
+        end
+      end
+   end
+
+   local function prepare_vert_data(n, id)
+      -- test if already loaded
+      if type(id)=='number' then -- sometimes id is an integer
+         font_vert_table[n] = font_vert_table[id]; return
+      elseif not id then return
+      end
+
+      local fname = id.filename
+      local bname = file.basename(fname)
+      if not fname then 
+         font_vert_table[n] = {}; return
+      elseif font_vert_basename[bname] then 
+         font_vert_table[n] = font_vert_basename[bname]; return
+      end
+
+      local vtable = {}
+      local a = id.resources.sequences
+      if a then
+        local s = id.shared.rawdata.descriptions
+        for i,v in pairs(a) do
+           if v.features.vert or v.features.vrt2 then 
+              add_feature_table(v.subtables[1], s, vtable)
+           end
+        end
+      end
+      font_vert_basename[bname] = vtable
+      font_vert_table[n] = vtable
+   end
+   
+   function luatexja.direction.get_vert_glyph(n, chr)
+      local fn = font_vert_table[n]
+      return (fn and fn[chr]) or chr
+   end
+
+   luatexbase.add_to_callback('luatexja.define_font',
+                             function (res, name, size, id)
+                                prepare_vert_data(id, res)
+                             end,
+                             'prepare_vert_data', 1)
+   
+end
index 3e43335..4e26e27 100644 (file)
@@ -43,6 +43,8 @@ local node_tail = Dnode.tail
 local node_free = Dnode.free
 local node_end_of_math = Dnode.end_of_math
 
+local dir_tate = 3
+local dir_yoko  = 4
 
 local id_glyph = node.id('glyph')
 local id_hlist = node.id('hlist')
@@ -84,6 +86,7 @@ local table_current_stack
 local list_dir
 
 local attr_curjfnt = luatexbase.attributes['ltj@curjfnt']
+local attr_dir = luatexbase.attributes['ltj@dir']
 local attr_icflag = luatexbase.attributes['ltj@icflag']
 
 local function get_attr_icflag(p)
@@ -440,7 +443,15 @@ do
    local attr_autoxspc = luatexbase.attributes['ltj@autoxspc']
    function set_np_xspc_jachar(Nx, x)
       local m = ltjf_font_metric_table[getfont(x)]
-      local cls, c = slow_find_char_class(has_attr(x, attr_orig_char), m, getchar(x))
+      local cls, c
+      if list_dir == dir_tate then
+        local c1, c2 = getchar(x), has_attr(x, attr_orig_char)
+        c = has_attr(x, attr_dir) or c1 or c2
+        cls = ltjf_find_char_class(c, m)
+        if cls==0 then cls = slow_find_char_class(c2, m, c1) end
+      else
+        cls, c = slow_find_char_class(has_attr(x, attr_orig_char), m, getchar(x))
+      end
       Nx.met, Nx.char = m, c; Nx.class = cls; 
       if cls~=0 then set_attr(x, attr_jchar_class, cls) end
       Nx.pre  = table_current_stack[PRE + c]  or 0
@@ -919,7 +930,7 @@ do
       Bp, widow_Bp, widow_Np = {}, {}, {first = nil}
       table_current_stack = ltjs.table_current_stack
 
-      list_dir = table_current_stack[DIR]
+      list_dir = table_current_stack[DIR] or dir_yoko
       kanji_skip = node_new(id_glue)
       setfield(kanji_skip, 'spec', skip_table_to_spec(KSK))
       set_attr(kanji_skip, attr_icflag, KANJI_SKIP)
index 45bf490..a88d2f2 100644 (file)
@@ -52,10 +52,11 @@ luatexbase.create_callback("luatexja.load_jfm", "data", function (ft, jn) return
 
 local jfm_file_name, jfm_var
 local defjfm_res
+local jfm_dir
 
 function define_jfm(t)
    local real_char -- Does current character class have the 'real' character?
-   if t.dir~='yoko' then
+   if t.dir~=jfm_dir then
       defjfm_res= nil; return
    elseif type(t.zw)~='number' or type(t.zh)~='number' then 
       defjfm_res= nil; return
@@ -91,7 +92,8 @@ function define_jfm(t)
                v.align = 'left' -- left
             end
            if real_char then
-              if not (type(v.width)=='number' or v.width~='prop') then
+              if not (type(v.width)=='number' 
+                      or (jfm_dir=='yoko' and v.width~='prop')) then
                  defjfm_res= nil; return
               else
                  if type(v.height)~='number' then
@@ -163,7 +165,6 @@ do
         if type(i) == 'number' then -- char_type
            for k,w in pairs(v.glue) do
               local h = node_new(id_glue_spec)
-mem_leak_gs = mem_leak_gs+1
               v[k] = {true, h, (w[5] and w[5]/sz or 0), FROM_JFM + (w[4] and w[4]/sz or 0)}
               setfield(h, 'width', w[1])
               setfield(h, 'stretch', w[2])
@@ -173,7 +174,6 @@ mem_leak_gs = mem_leak_gs+1
            end
            for k,w in pairs(v.kern) do
               local g = node_new(id_kern)
-mem_leak_kern = mem_leak_kern +1
               setfield(g, 'kern', w[1])
               setfield(g, 'subtype', 1)
               set_attr(g, attr_icflag, FROM_JFM)
@@ -241,8 +241,10 @@ do
    luatexbase.create_callback("luatexja.define_jfont", "data", function (ft, fn) return ft end)
 
 -- EXT
-   function jfontdefY() -- for horizontal font
-      local j = load_jfont_metric()
+   local identifiers = fonts.hashes.identifiers
+   function jfontdefY(dir)
+      jfm_dir = dir
+      local j = load_jfont_metric(dir)
       local fn = font.id(cstemp)
       local f = font_getfont(fn)
       if not j then 
@@ -255,18 +257,21 @@ do
         return 
       end
       update_jfm_cache(j, f.size)
-      --print('MEMORY LEAK (acc): ', mem_leak_glue, mem_leak_gs, mem_leak_kern)
+      local ad = identifiers[fn].parameters
       local sz = metrics[j].size_cache[f.size]
       local fmtable = { jfm = j, size = f.size, var = jfm_var, 
-                       zw = sz.zw, zh = sz.zh, 
+                       zw = sz.zw, zh = sz.zh,
+                       ascent = ad.ascender,
+                       descent = ad.descender, 
                        chars = sz.chars, char_type = sz.char_type,
-                       kanjiskip = sz.kanjiskip, xkanjiskip = sz.xkanjiskip, 
+                       kanjiskip = sz.kanjiskip, xkanjiskip = sz.xkanjiskip,
       }
       
       fmtable = luatexbase.call_callback("luatexja.define_jfont", fmtable, fn)
       font_metric_table[fn]=fmtable
       tex.sprint(cat_lp, global_flag .. '\\protected\\expandafter\\def\\csname ' 
-                   .. cstemp  .. '\\endcsname{\\ltj@curjfnt=' .. fn .. '\\relax}')
+                   .. cstemp  .. '\\endcsname{\\ltj@cur'
+                   .. (dir == 'yoko' and 'j' or 't') .. 'fnt=' .. fn .. '\\relax}')
    end
 end
 
@@ -311,11 +316,11 @@ do
    end
    
    -- replace fonts.define.read()
-   function font_callback(name, size, id, fallback)
-      extract_metric(name)
-      -- In the present imple., we don't remove "jfm=..." from name.
-      return fallback(name, size, id)
-   end
+   luatexbase.add_to_callback('luatexja.define_font', 
+                             function (res, name)
+                                extract_metric(name)
+                             end,
+                             'extract_jfm_name', 1)
 end
 
 ------------------------------------------------------------------------
index f84faa4..a3d7923 100644 (file)
@@ -333,13 +333,6 @@ do
       return to_node(head)
    end
 
-   -- font define
-   local function font_callback(name, size, id, fallback)
-      local d = fallback(name, size, id)
-      prepare_ivs_data(id, d)
-      return d
-   end
-
    enable_ivs = function ()
       if is_ivs_enabled then
         ltjb.package_warning('luatexja-otf',
@@ -355,7 +348,11 @@ do
               function (name, size, id) return luatexja.font_callback(name, size, id) end
            )
         end
-        luatexbase.add_to_callback('define_font',ivs_callback,"luatexja.ivs_font_callback", 1)
+        luatexbase.add_to_callback('luatexja.define_font',
+                                   function (res, name, size, id)
+                                      prepare_ivs_data(id, res)
+                                   end,
+                                   'prepare_ivs_data', 1)
         for i=1,font.nextid()-1 do
            if identifiers[i] then prepare_ivs_data(i, identifiers[i]) end
         end
index c958ddd..ab264ff 100644 (file)
 \jfont\sevengt=\ltj@stdgtfont:jfm=ujis at 6.73551pt
 \jfont\fivegt=\ltj@stdgtfont:jfm=ujis at 4.81108pt
 
+\tfont\tentmin=\ltj@stdmcfont:jfm=ujisv at 9.62216pt
+\tfont\seventmin=\ltj@stdmcfont:jfm=ujisv at 6.73551pt
+\tfont\fivetmin=\ltj@stdmcfont:jfm=ujisv at 4.81108pt
+\tfont\tentgt=\ltj@stdgtfont:jfm=ujisv at 9.62216pt
+\tfont\seventgt=\ltj@stdgtfont:jfm=ujisv at 6.73551pt
+\tfont\fivetgt=\ltj@stdgtfont:jfm=ujisv at 4.81108pt
+
 \let\mc=\tenmin
 \let\gt=\tengt
-\mc
+\mc\tentmin
 
 \directlua{
   local s = kpse.find_file('ltj-kinsoku.lua', 'tex')
index 14cec98..5be5ef0 100644 (file)
@@ -5,6 +5,7 @@
 luatexja.load_module('charrange'); local ltjc = luatexja.charrange
 luatexja.load_module('stack');     local ltjs = luatexja.stack
 luatexja.load_module('jfont');     local ltjf = luatexja.jfont
+luatexja.load_module('direction'); local ltjd = luatexja.direction
 
 local Dnode = node.direct or node
 
@@ -35,13 +36,20 @@ local id_math = node.id('math')
 local id_whatsit = node.id('whatsit')
 local sid_user = node.subtype('user_defined')
 
+local attr_dir = luatexbase.attributes['ltj@dir']
 local attr_curjfnt = luatexbase.attributes['ltj@curjfnt']
+local attr_curtfnt = luatexbase.attributes['ltj@curtfnt']
 local attr_icflag = luatexbase.attributes['ltj@icflag']
 
 local is_ucs_in_japanese_char = ltjc.is_ucs_in_japanese_char_direct
+local ltjd_get_vert_glyph = ltjd.get_vert_glyph
 local ltjf_replace_altfont = ltjf.replace_altfont
 local attr_orig_char = luatexbase.attributes['ltj@origchar']
 local STCK = luatexja.userid_table.STCK
+local DIR = luatexja.stack_table_index.DIR
+
+local dir_tate = 3
+local dir_yoko = 4
 
 ------------------------------------------------------------------------
 -- MAIN PROCESS STEP 1: replace fonts
@@ -49,15 +57,13 @@ local STCK = luatexja.userid_table.STCK
 local wt
 do
    local head
-
+   local is_dir_tate
    local suppress_hyphenate_ja_aux = {}
    suppress_hyphenate_ja_aux[id_glyph] = function(p)
       if (has_attr(p, attr_icflag) or 0)<=0 and is_ucs_in_japanese_char(p) then
-        local pc = getchar(p)
-        local pf = ltjf_replace_altfont(has_attr(p, attr_curjfnt) or getfont(p), pc)
+        local pf = has_attr(p, attr_curjfnt) or getfont(p)
         setfield(p, 'font', pf);  set_attr(p, attr_curjfnt, pf)
         setfield(p, 'subtype', floor(getsubtype(p)*0.5)*2)
-        set_attr(p, attr_orig_char, pc)
       end
       return p
    end
@@ -95,6 +101,21 @@ local function set_box_stack_level(head, mode)
       if mode and getfield(p, 'value')==cl then box_set = 1 end; node_free(p)
    end
    ltjs.report_stack_level(tex_getcount('ltj@@stack') + box_set)
+   is_dir_tate = ltjs.table_current_stack[DIR] == dir_tate
+   local jfntattr = is_dir_tate and attr_curtfnt or attr_curjfnt
+   for p in Dnode.traverse_id(id_glyph,to_direct(head)) do
+      if has_attr(p, attr_curjfnt)==getfont(p) then
+        local pfn = has_attr(p, jfntattr) or getfont(p)
+        local pc = getchar(p)
+        local pf = ltjf_replace_altfont(pfn, pc)
+        if is_dir_tate then 
+           set_attr(p, attr_dir, pc)
+           pc = ltjd_get_vert_glyph(pf, pc) or pc
+        end
+        setfield(p, 'char', pc); set_attr(p, attr_orig_char, pc)
+        setfield(p, 'font', pf); set_attr(p, attr_curjfnt, pf)
+      end
+   end
    return head
 end
 
index b81c269..484960f 100644 (file)
@@ -111,8 +111,11 @@ do
       local k = {
          cidinfo = { ordering=cid_order, registry=cid_reg, supplement=kx[3] },
          encodingbytes = 2, extend=1000, format = 'opentype',
-         direction = 0, characters = {}, parameters = {}, embedding = "no", cache = "yes", 
-         ascender = 0, descender = 0, factor = 0, hfactor = 0, vfactor = 0,
+         direction = 0, characters = {}, parameters = {
+           ascender = 655360*0.88,
+           descender = 655360*0.12,
+        },
+        embedding = "no", cache = "yes", factor = 0, hfactor = 0, vfactor = 0, 
         tounicode = 1,
       }
       cidfont_data[cid_name] = k
@@ -256,19 +259,9 @@ local function mk_rml(name, size, id)
         parameters[k] = v * scale
       end
       fontdata.parameters  = parameters
-      fontdata.ascender    = fontdata.ascender * scale
-      fontdata.descender   = fontdata.descender * scale
-      fontdata.factor      = fontdata.factor * scale
-      fontdata.hfactor     = fontdata.hfactor * scale
-      fontdata.vfactor     = fontdata.vfactor * scale
       fontdata.size        = size
       fontdata.resources   = s.resources
       cachedata.parameters = parameters
-      cachedata.ascender   = fontdata.ascender
-      cachedata.descender  = fontdata.descender
-      cachedata.factor     = fontdata.factor
-      cachedata.hfactor    = fontdata.hfactor
-      cachedata.vfactor    = fontdata.vfactor
       cachedata.size       = size
       cachedata.resources  = s.resources
    end
index 7fd6804..93c7b49 100644 (file)
@@ -3,7 +3,9 @@
 --
 
 luatexja.load_module('base');      local ltjb = luatexja.base
+luatexja.load_module('stack');     local ltjs = luatexja.stack
 luatexja.load_module('jfont');     local ltjf = luatexja.jfont
+luatexja.load_module('direction'); local ltjd = luatexja.direction
 
 local Dnode = node.direct or node
 local setfield = (Dnode ~= node) and Dnode.setfield or function(n, i, c) n[i] = c end
@@ -31,6 +33,13 @@ 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 id_whatsit = node.id('whatsit')
+local sid_save = node.subtype('pdf_save')
+local sid_restore = node.subtype('pdf_restore')
+local sid_matrix = node.subtype('pdf_setmatrix')
+local dir_tate = 3
+local dir_yoko = 4
+local DIR = luatexja.stack_table_index.DIR
 
 local attr_jchar_class = luatexbase.attributes['ltj@charclass']
 local attr_curjfnt = luatexbase.attributes['ltj@curjfnt']
@@ -66,8 +75,7 @@ local call_callback = luatexbase.call_callback
 
 local fshift =  { down = 0, left = 0}
 
--- mode: true iff p will be always encapsuled by a hbox
-local function capsule_glyph(p, met, class)
+local function capsule_glyph_yoko(p, met, class)
    local char_data = met.char_type[class]
    if not char_data then return node_next(p) end
    local fwidth, pwidth = char_data.width, getfield(p, 'width')
@@ -101,7 +109,51 @@ local function capsule_glyph(p, met, class)
       return node_next(p)
    end
 end
-luatexja.setwidth.capsule_glyph = capsule_glyph
+local function capsule_glyph_tate(p, met, class)
+   local char_data = met.char_type[class]
+   if not char_data then return node_next(p) end
+   local ascent, descent = met.ascent, met.descent
+   local fwidth, pwidth = char_data.width, ascent + descent
+   fwidth = (fwidth ~= 'prop') and fwidth or pwidth
+   fshift.down = char_data.down; fshift.left = char_data.left
+   fshift = call_callback("luatexja.set_width", fshift, met, class)
+   local fheight, fdepth = char_data.height, char_data.depth
+   
+   setfield(p, 'char', ltjd.get_vert_glyph(getfont(p), getchar(p)))
+
+      local y_shift
+         = - getfield(p, 'yoffset') + (has_attr(p,attr_ykblshift) or 0)
+      local q
+      head, q = node_remove(head, p)
+      local box = node_new(id_hlist)
+      setfield(box, 'width', fwidth)
+      setfield(box, 'height', fheight)
+      setfield(box, 'depth', fdepth)
+      setfield(box, 'shift', y_shift)
+      setfield(box, 'dir', dir)
+
+      local k1 = node_new(id_kern)
+      setfield(k1, 'kern', 
+              getfield(p, 'xoffset') + ascent
+                 + char_data.align*(fwidth-pwidth) - fshift.left)
+      local ws = node_new(id_whatsit, sid_save)
+      local wm = node_new(id_whatsit, sid_matrix)
+      setfield(wm, 'data', '0 1 -1 0')
+      local k2 = node_new(id_kern)
+      setfield(k2, 'kern', -fshift.down - fdepth)
+      local k3 = node_new(id_kern)
+      setfield(k3, 'kern', - getfield(p, 'width') +fshift.down + fdepth)
+      local wr = node_new(id_whatsit, sid_restore)
+      setfield(box, 'head', k1); setfield(k1, 'next', ws)
+      setfield(ws, 'next', wm);  setfield(wm, 'next', k2); 
+      setfield(k2, 'next', p);   setfield(p, 'next', k3); 
+      setfield(k3, 'next', wr); 
+
+      set_attr(box, attr_icflag, PACKED + get_pr_begin_flag(p))
+      head = q and node_insert_before(head, q, box) 
+               or node_insert_after(head, node_tail(head), box)
+      return q
+end
 
 local function capsule_glyph_math(p, met, class)
    local char_data = met.char_type[class]
@@ -130,6 +182,8 @@ luatexja.setwidth.capsule_glyph_math = capsule_glyph_math
 function luatexja.setwidth.set_ja_width(ahead, adir)
    local p = ahead; head  = p; dir = adir or 'TLT'
    local m = false -- is in math mode?
+   local capsule_glyph = (ltjs.table_current_stack[DIR]==dir_yoko)
+      and capsule_glyph_yoko or capsule_glyph_tate
    while p do
       local pid = getid(p)
       if (pid==id_glyph) 
index 6565bba..ebd25c1 100644 (file)
 
 %%%%%%%% Attributes for Japanese typesetting.
 \newluatexattribute\ltj@icflag    % attribute for italic correction
-\newluatexattribute\ltj@curjfnt   % index for ``current Japanese font''
+\newluatexattribute\ltj@curjfnt   % index for ``current horizontal Japanese font''
+\newluatexattribute\ltj@curtfnt   % index for ``current vertical Japanese font''
 \newluatexattribute\ltj@origchar  %
 \newluatexattribute\ltj@charclass %
 \newluatexattribute\ltj@autospc   % attribute for autospacing
 \protected\def\jfont{\afterassignment\ltj@@jfont\directlua{luatexja.jfont.jfontdefX(false)}}
 \protected\def\globaljfont{%
   \afterassignment\ltj@@jfont\directlua{luatexja.jfont.jfontdefX(true)}}
-\def\ltj@@jfont{\directlua{luatexja.jfont.jfontdefY()}}
+\def\ltj@@jfont{\directlua{luatexja.jfont.jfontdefY('yoko')}}
+
+%%%%%%%% \tfont\CS={...:...;jfm=metric;...}, \globaltfont
+\protected\def\tfont{\afterassignment\ltj@@tfont\directlua{luatexja.jfont.jfontdefX(false)}}
+\protected\def\globaltfont{%
+  \afterassignment\ltj@@tfont\directlua{luatexja.jfont.jfontdefX(true)}}
+\def\ltj@@tfont{\directlua{luatexja.jfont.jfontdefY('tate')}}
+
 
 %%%%%%%% \zw, \zh
 \protected\def\zw{\directlua{tex.setdimen('ltj@zw', luatexja.jfont.get_zw())}\ltj@zw}
index 0a6cdad..3332c1e 100644 (file)
@@ -104,6 +104,21 @@ end
 local load_module = luatexja.load_module
 load_module('base');      local ltjb = luatexja.base
 load_module('rmlgbm');    local ltjr = luatexja.rmlgbm -- must be 1st
+
+-- define_font
+do
+   local otfl_fdr = fonts.definers.read
+   local ltjr_font_callback = ltjr.font_callback
+   function luatexja.font_callback(name, size, id)
+      local res =  ltjr_font_callback(name, size, id, otfl_fdr) 
+      luatexbase.call_callback('luatexja.define_font', res, name, size, id)
+      return res
+   end
+   luatexbase.create_callback('luatexja.define_font', 'simple', function (n) return n end)
+   luatexbase.add_to_callback('define_font',luatexja.font_callback,"luatexja.font_callback", 1)
+end
+
+
 load_module('charrange'); local ltjc = luatexja.charrange
 load_module('jfont');     local ltjf = luatexja.jfont
 load_module('inputbuf');  local ltji = luatexja.inputbuf
@@ -316,22 +331,6 @@ do
 
 end
 
--- define_font
-do
-   local otfl_fdr = fonts.definers.read
-   local ltjr_font_callback = ltjr.font_callback
-   function luatexja.font_callback(name, size, id)
-      return ltjf.font_callback(
-        name, size, id, 
-        function (name, size, id) return ltjr_font_callback(name, size, id, otfl_fdr) end
-      )
-   end
-   luatexbase.add_to_callback('define_font',luatexja.font_callback,"luatexja.font_callback", 1)
-end
-
-
-
-
 -- debug
 
 do
index eab6d1f..c956354 100644 (file)
Binary files a/test/test51-vtest.pdf and b/test/test51-vtest.pdf differ
index 62d6379..1b3655a 100644 (file)
                           }%
         }%
 }
+\protected\def\LaTeX{L\kern-.36em%
+        {\setbox\z@\hbox{T}
+         \vbox to\ht\z@{\hbox{\sevenrm A}%
+                        \vss}%
+        }%
+        \kern-.15em%
+        \TeX}
+
+\tentgt
 
 \hbox{\yoko
 横水平Hxy\hbox{\yoko 横水平Hxy}かき◆
-\hbox{\tate 縦平Hxy}◆おおおお
+\hbox{\tate 縦平Hxy}◆おおおお
 \vbox{\yoko\hsize=30mm 横垂直Hxyああああああああああ}かき◆
 \vbox{\tate\hsize=30mm  縦垂直Hxy\hfill ああ\break ああああああああ}◆ああああ
 }
@@ -68,7 +77,7 @@
 
 \vfill\eject
 \vbox{\tate\hsize=100mm
-縦垂直Hxy\hbox{\yoko 横水平Hxy}かき◆
+◆◆◆Hxy\hbox{\yoko 横水平Hxy}かき◆
 これは,意味のないサンプルテキストです.
 \hbox{\tate 縦水平Hxy}◆おおおお
 これは,意味のないサンプルテキストです.
 です.
 }
 
+
+\vbox{\tate\hsize100mm
+\tfont\f=KozMinPr6N-Regular.otf:+vert;jfm=ujisv \f
+
+\ltjsetparameter{yalbaselineshift=.25em}\baselineskip15pt
+\LaTeX の特徴として、テキストファイルであるソースコードを入力として処理することでDVIや
+PDFなどの表示形式を出力として得ることが挙げられる。
+
+\LaTeX の最大の長所は、\TeX に由来する高品質で自由度の高い組版処理能力である。組版処理能力
+は一般向けの出版物の作成にも充分に耐えられるものであり、実際の出版例もある。
+中でも数式組版の品質が高い。さらに、数式専用の命令文(コマンド)が用意されているので、
+単純なソースコードで高品質な数式表示を得られる。そのため、数式を多く含む自然科学系や工学系
+の出版物などでは、\LaTeX 形式での投稿が標準的なフォーマットとされていることも多い。
+
+くわえて、ソースコードに詳細な設定を記述することで、文書のスタイル(表示形式、見栄え、たと
+えばレイアウトやフォントなど)を自在に調節できる。また、ソースコード上で文書内容・文書構造
+(章・節・段落や強調箇所など)と文書スタイルの設定との分離が可能である。そのため、同一文書
+内で終始一貫したスタイをル保つことができる。また、同じ文書内容でレイアウトやフォントだけを
+変えることができるなど、文書内容データの再利用性が高い。一度スタイル設定を決めてしまえば、
+あとは文書内容の記述に専念することができるという利点もある。論文などの投稿では、学術雑
+誌のスタイルを記述したファイル(パッケージファイル)を Web からダウンロードして利用するこ
+とで、統一されたスタイルで論文xを投稿することができ、論文の投稿者と雑誌の編集者とのやり取り
+を簡略化できる。Kile、TeXShop、TeXworks、EasyTeX、WinShell などの \TeX 用エ
+ディタや、野鳥(やてふ、YaTeX)、TeXlipse、KaTeX(花鳥、かてふ)、祝鳥
+(のりてふ)、M's TeX Helper 2など の\TeX 用テキストエディタマクロを兼用することに
+よって、より効率的な文章作成が可能ともなる。またMapleやMathematicaなどでドキュメントを
+作成し、\TeX 形式で出力することも可能である。
+
+}
 \end