OSDN Git Service

Stop use of stack system for direction.
authorHironori Kitagawa <h_kitagawa2001@yahoo.co.jp>
Sat, 10 May 2014 12:47:21 +0000 (21:47 +0900)
committerHironori Kitagawa <h_kitagawa2001@yahoo.co.jp>
Sat, 10 May 2014 12:47:21 +0000 (21:47 +0900)
src/jfm-ujisv.lua
src/ltj-direction.lua
src/ltj-jfmglue.lua
src/ltj-pretreat.lua
src/ltj-setwidth.lua
src/luatexja-core.sty
src/patches/lltjfont.sty

index d332818..1923f0d 100644 (file)
@@ -1,5 +1,5 @@
 -- -*- coding: utf-8 -*-
--- jfm-ujis.lua: LuaTeX-ja 標準 JFM
+-- jfm-ujisv.lua: LuaTeX-ja 標準 JFM(縦組み用)
 -- based on upnmlminr-h.tfm (a metric in UTF/OTF package used by upTeX).
 
 -- JIS X 4051:2004 では,行末の句読点や中点はベタなのでそれに従う
@@ -53,7 +53,7 @@ luatexja.jfont.define_jfm {
    [2] = { -- 閉じ括弧類
       chars = {
         '’', '”', '〉', '》', '」', '』', '】', '〕',
-        '〗', '〙', '〟', ')', ']', '}', '⦆', '、*', ',*'
+        '〗', '〙', '〟', ')', ']', '}', '⦆', '、', ','
       },
       align = 'left', left = 0.0, down = 0.0,
       width = 0.5, height = 0.50, depth = 0.50, italic=0.0,
@@ -82,7 +82,7 @@ luatexja.jfont.define_jfm {
         [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 },
+        [3] = { 0.5 , 0.0, 0.25 , 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 },
@@ -131,7 +131,7 @@ luatexja.jfont.define_jfm {
       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 },
+         [0] = { 1.0 , 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 },
index bcaea43..693021a 100644 (file)
@@ -47,18 +47,46 @@ local wh_DIR = luatexja.userid_table.DIR
 local dir_tate = 3
 local dir_yoko = 4
 
+
+local get_dir_count 
+do
+   local gc = tex.getcount
+   get_dir_count = function() return gc('ltj@dir@count') end
+end
+luatexja.direction.get_dir_count = get_dir_count 
+
 -- \tate, \yoko
 do
   local node_next = node.next
   local function set_list_direction(v, name)
-    if node.next(tex.nest[tex.nest.ptr].head) then
-      ltjb.package_error('luatexja',
-                        "Use `\\" .. name .. "' at top of list",
-                        'Direction change command by LuaTeX-ja is available\n'
-                           .. 'only while current list is null.')
-    else
-       ltjs.set_stack_table(luatexja.stack_table_index.DIR, v, true)
-    end
+     local lv, w = tex.nest[tex.nest.ptr], tex.lists.page_head
+     if lv.mode == 1 and w then
+        if w.id==id_whatsit and w.subtype==sid_user
+        and w.user_id==wh_DIR then
+           w.value=v
+        end
+     else
+        local w = node_next(to_direct(lv.head))
+        if to_node(w) then
+           if getid(w)==id_whatsit and getsubtype(w)==sid_user
+           and getfield('user_id', wh_DIR) then
+              setfield(w, 'value', v)
+           else
+              ltjb.package_error(
+                 'luatexja',
+                 "Use `\\" .. name .. "' at top of list",
+                 'Direction change command by LuaTeX-ja is available\n'
+                 .. 'only while current list is null.')
+           end
+        else
+           local w = node_new(id_whatsit, sid_user)
+           setfield(w, 'next', hd)
+           setfield(w, 'user_id', wh_DIR)
+           setfield(w, 'type', 100)
+           setfield(w, 'value', v)
+           Dnode.write(w)
+        end
+     end
   end
   luatexja.direction.set_list_direction = set_list_direction
 end
@@ -70,39 +98,42 @@ do
       if gc=='fin_row' or gc == 'preamble'  then
         return h
       else
-        local hd, new_dir = to_direct(h), ltjs.table_current_stack[DIR]
+        local hd = to_direct(h)
         local w
         if hd and getid(hd)==id_whatsit and getsubtype(hd)==sid_user
         and getfield(hd, 'user_id')==wh_DIR then
-           w = hd
+           return h
         else
            w = node_new(id_whatsit, sid_user)
            setfield(w, 'next', hd)
+            setfield(w, 'user_id', wh_DIR)
+            setfield(w, 'type', 100)
+            setfield(w, 'value', ltjs.list_dir)
+            return to_node(w)
         end
-        setfield(w, 'user_id', wh_DIR)
-        setfield(w, 'type', 100)
-        setfield(w, 'value', new_dir)
-        return to_node(w)
       end
    end
    luatexbase.add_to_callback('hpack_filter', set_dir_flag, 'ltj.set_dir_flag', 10000)
-   luatexbase.add_to_callback('vpack_filter',
-                             function (h, gc)
-                                local box_set, cl = 0, tex.currentgrouplevel + 1
-                                local hd = to_direct(h)
-                                for w in traverse_id(id_whatsit, hd) do
-                                   if getsubtype(w)==sid_user and
-                                   getfield(w, 'user_id')==STCK and
-                                   getfield(w, 'value')==cl then box_set = 1;
-                                      hd = node_remove(hd, w); node_free(w); break
-                                   end
-                                end
-                               ltjs.report_stack_level(tex_getcount('ltj@@stack') + box_set)
-                               return set_dir_flag(to_node(hd), gc)
-                             end, 'ltj.set_dir_flag', 1)
+
+   local function set_dir_flag_vbox(h, gc)
+      local w = to_direct(h)
+      ltjs.list_dir = get_dir_count()
+      if getid(w)==id_whatsit and getsubtype(w)==sid_user
+      and getfield(w, 'user_id')==wh_DIR then
+         ltjs.list_dir = getfield(w, 'value')
+      --print('VB', gc, ltjs.list_dir)
+      --luatexja.ext_show_node_list(h, '   > ', print)
+         return h
+      else
+      --print('VB', gc, ltjs.list_dir)
+      --luatexja.ext_show_node_list(h, '   > ', print)
+         return set_dir_flag(h, gc)
+      end
+   end
+   luatexbase.add_to_callback('vpack_filter', set_dir_flag_vbox, 'ltj.set_dir_flag', 1)
    luatexbase.add_to_callback('post_linebreak_filter',
                              function (h)
-                                local new_dir = ltjs.table_current_stack[DIR]
+                                local new_dir = ltjs.list_dir
                                 for line in traverse_id(id_hlist, to_direct(h)) do
                                    set_attr(line, attr_dir, new_dir)
                                 end
@@ -197,13 +228,14 @@ do
             old_dir = getfield(bh, 'value')
             set_attr(b, attr_dir, old_dir)
             setfield(b, 'head', (node_remove(bh, x)))
-            set_attr(b, attr_icflag, PROCESSED)
             node_free(x); break
         end
       end
       if not old_dir then
-        old_dir = has_attr(b, attr_dir) or dir_yoko
-        if old_dir==0 then old_dir =dir_yoko end
+        old_dir = has_attr(b, attr_dir) or 0
+         if old_dir ==0 then
+            old_dir = ltjs.list_dir
+         end
       end
       if old_dir==new_dir then
         set_attr(b, attr_icflag, PROCESSED)
@@ -267,7 +299,7 @@ do
    end
    local function process_dir_node(head, gc)
       local h = to_direct(head)
-      local x, new_dir = h, ltjs.table_current_stack[DIR] or dir_yoko
+      local x, new_dir = h, ltjs.list_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
@@ -351,4 +383,3 @@ do
    end
    luatexja.direction.glyph_from_packed = glyph_from_packed
 end
-
index a247bde..680c6aa 100644 (file)
@@ -937,7 +937,7 @@ do
       Bp, widow_Bp, widow_Np = {}, {}, {first = nil}
       table_current_stack = ltjs.table_current_stack
 
-      list_dir = table_current_stack[DIR] or dir_yoko
+      list_dir = ltjs.list_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 5300d4e..8df99a4 100644 (file)
@@ -46,7 +46,7 @@ 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 = luatexja.userid_table.DIR
 
 local dir_tate = 3
 local dir_yoko = 4
@@ -58,29 +58,42 @@ local wt
 do
    local head
    local is_dir_tate
+   local dir_frozen
    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 pf = has_attr(p, attr_curjfnt) or getfont(p)
+         local pc = getchar(p)
+        local pf = ltjf_replace_altfont(has_attr(p, attr_curjfnt) or getfont(p), pc)
         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
-   suppress_hyphenate_ja_aux[id_math] = function(p) return node_end_of_math(node_next(p)) end
+   suppress_hyphenate_ja_aux[id_math] = function(p) 
+      dir_frozen = true
+      return node_end_of_math(node_next(p)) end
+   suppress_hyphenate_ja_aux[50] = function(p) return p end
    suppress_hyphenate_ja_aux[id_whatsit] = function(p)
-      if getsubtype(p)==sid_user and getfield(p, 'user_id')==STCK then
-        wt[#wt+1] = p; head = node_remove(head, p)
+      if getsubtype(p)==sid_user then 
+         local uid = getfield(p, 'user_id')
+         if uid==STCK then
+            wt[#wt+1] = p; head = node_remove(head, p)
+         elseif uid==DIR and not dir_frozen then
+            ltjs.list_dir = getfield(p, 'value')
+         end
+         dir_frozen = true
       end
       return p
    end
 
    local function suppress_hyphenate_ja (h)
       local p = to_direct(h)
-      wt, head = {}, p
+      wt, head, dir_frozen = {}, p, false
+      ltjs.list_dir=ltjd.get_dir_count()
       while p do
         local pfunc = suppress_hyphenate_ja_aux[getid(p)]
-        if pfunc then p = pfunc(p) end
+        if pfunc then p = pfunc(p) else dir_frozen = true end
         p = node_next(p)
       end
       head = to_node(head)
@@ -101,19 +114,18 @@ 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
+   is_dir_tate = ltjs.list_dir == dir_tate
+   if is_dir_tate then
+      for p in Dnode.traverse_id(id_glyph,to_direct(head)) do
+         if (has_attr(p, attr_icflag) or 0)<=0 and has_attr(p, attr_curjfnt)==getfont(p) then
+            local pfn = has_attr(p, attr_curtfnt) or getfont(p)
+            local pc = getchar(p)
+            local pf = ltjf_replace_altfont(pfn, pc)
            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)
+            setfield(p, 'char', pc); set_attr(p, attr_orig_char, pc)
+            setfield(p, 'font', pf); set_attr(p, attr_curjfnt, pf)
+         end
       end
    end
    return head
index a06c402..99bc9db 100644 (file)
@@ -184,7 +184,7 @@ 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 is_dir_tate = ltjs.table_current_stack[DIR]==dir_tate
+   local is_dir_tate = ltjs.list_dir==dir_tate
    local capsule_glyph = is_dir_tate and capsule_glyph_tate or capsule_glyph_yoko
    local attr_ablshift = is_dir_tate and attr_tablshift or attr_yablshift
    while p do
index a725e0d..a2dc0ed 100644 (file)
 \newluatexattribute\ltj@tablshift % attribute for talbaselineshift
 \newluatexattribute\ltj@tkblshift % attribute for tjabaselineshift
 \newluatexattribute\jfam          % index for current jfam
-\newluatexattribute\ltj@dir       % temp attr for indicating box direction
+
+\newcount\ltj@dir@count           % counter for indicating direction
+\newluatexattribute\ltj@dir
 
 \ltj@dir=0
 \ltj@icflag=0
 \newif\iftdir
 \protected\def\tate{%
   \directlua{luatexja.direction.set_list_direction(3, 'tate')}%
-  \ltj@dir=3 \tdirtrue\ydirfalse
+  \ltj@dir@count=3 \tdirtrue\ydirfalse
 }
 \protected\def\yoko{%
   \directlua{luatexja.direction.set_list_direction(4, 'yoko')}%
-  \ltj@dir=4 \ydirtrue\tdirfalse
+  \ltj@dir@count=4 \ydirtrue\tdirfalse
 }
 \yoko
 
index 926c8fa..658fb52 100644 (file)
 
 
 \RequirePackage{everysel}
+\let\ltj@@EverySelectfont@Init=\@EverySelectfont@Init
 \@EverySelectfont@Init
+\let\@EverySelectfont@Init=\ltj@@EverySelectfont@Init
 \def\ltj@selectfont@patch{%
  \let\tmp@error@fontshape\error@fontshape
   \let\error@fontshape\error@kfontshape
   \fi
 }
 \EverySelectfont{\ltj@selectfont@patch}
-\def\@EverySelectfont@Init{\let\@EverySelectfont@Init\undefined}
 
 \def\KanjiEncodingPair#1#2{\@namedef{t@enc@#1}{#2}\@namedef{y@enc@#2}{#1}}
 \def\set@fontsize#1#2#3{%