OSDN Git Service

Fixed dir whatsit in \vtop
[luatex-ja/luatexja.git] / src / luatexja.lua
index 6dddc1a..8ffdf86 100644 (file)
@@ -48,7 +48,6 @@ stack_table_index.RIPOST = 0xC00000 -- characterごと,ruby post
 stack_table_index.JWP  = 0 -- これだけ
 stack_table_index.KSK  = 1 -- これだけ
 stack_table_index.XSK  = 2 -- これだけ
-stack_table_index.DIR  = 3 -- これだけ
 stack_table_index.MJT  = 0x100 -- 0--255
 stack_table_index.MJS  = 0x200 -- 0--255
 stack_table_index.MJSS = 0x300 -- 0--255
@@ -61,6 +60,15 @@ userid_table.STCK = luatexbase.newuserwhatsitid('stack_marker', 'luatexja') -- 
 userid_table.BPAR = luatexbase.newuserwhatsitid('begin_par',    'luatexja') -- 「段落始め」
 userid_table.DIR  = luatexbase.newuserwhatsitid('direction',    'luatexja') -- 組方向
 
+local dir_table = {}
+luatexja.dir_table = dir_table
+dir_table.dir_dtou = 1
+dir_table.dir_tate = 3
+dir_table.dir_yoko = 4
+dir_table.dir_node_auto   = 16 -- 組方向を合わせるために自動で作られたもの
+dir_table.dir_node_manual = 32 -- 寸法代入によって作られたもの
+
+
 ------------------------------------------------------------------------
 -- FIX node.remove
 ------------------------------------------------------------------------
@@ -105,12 +113,19 @@ local load_module = luatexja.load_module
 load_module('base');      local ltjb = luatexja.base
 load_module('rmlgbm');    local ltjr = luatexja.rmlgbm -- must be 1st
 
+if luatexja_debug then load_module('debug') end
+
+load_module('charrange'); local ltjc = luatexja.charrange
+load_module('jfont');     local ltjf = luatexja.jfont
+
 -- define_font
 do
    local otfl_fdr = fonts.definers.read
    local ltjr_font_callback = ltjr.font_callback
+   local ltjf_extract_metric = ltjf.extract_metric
    function luatexja.font_callback(name, size, id)
-      local res =  ltjr_font_callback(name, size, id, otfl_fdr)
+      local new_name = ltjf_extract_metric(name)
+      local res =  ltjr_font_callback(new_name, size, id, otfl_fdr)
       luatexbase.call_callback('luatexja.define_font', res, name, size, id)
       return res
    end
@@ -119,10 +134,6 @@ do
 end
 
 
---load_module('debug')
-
-load_module('charrange'); local ltjc = luatexja.charrange
-load_module('jfont');     local ltjf = luatexja.jfont
 load_module('inputbuf');  local ltji = luatexja.inputbuf
 load_module('stack');     local ltjs = luatexja.stack
 load_module('pretreat');  local ltjp = luatexja.pretreat
@@ -296,6 +307,7 @@ function luatexja.ext_print_global()
    if luatexja.isglobal=='global' then tex.sprint(cat_lp, '\\global') end
 end
 
+
 -- main process
 do
    local start_time_measure, stop_time_measure 
@@ -304,10 +316,10 @@ do
    local nullfunc = function (n) return n end
    local to_node = (Dnode ~= node) and Dnode.tonode or nullfunc
    local to_direct = (Dnode ~= node) and Dnode.todirect or nullfunc
-   local time_jfm, time_width = 0,0 
+   local tex_set_attr = tex.setattribute
    -- mode = true iff main_process is called from pre_linebreak_filter
    local function main_process(head, mode, dir, gc)
-      tex.setattribute('global', attr_icflag, 0)
+      tex_set_attr('global', attr_icflag, 0)
       if gc == 'fin_row' then return head
       else
            local p = to_direct(head)
@@ -323,7 +335,7 @@ do
    local function adjust_icflag(h)
       -- kern from luaotfload will have icflag = 1
       -- (same as italic correction)
-      tex.setattribute('global', attr_icflag, 1)
+      tex_set_attr('global', attr_icflag, 1)
       return h
    end
 
@@ -343,8 +355,8 @@ do
       end,'ltj.hpack_filter',
       luatexbase.priority_in_callback('hpack_filter',
                                      'luaotfload.node_processor') + 1)
-   luatexbase.add_to_callback('pre_linebreak_filter', adjust_icflag, 'adjust_icflag', 1)
-   luatexbase.add_to_callback('hpack_filter', adjust_icflag, 'adjust_icflag', 1)
+   luatexbase.add_to_callback('pre_linebreak_filter', adjust_icflag, 'ltj.adjust_icflag', 1)
+   luatexbase.add_to_callback('hpack_filter', adjust_icflag, 'ltj.adjust_icflag', 1)
 
 end
 
@@ -387,8 +399,9 @@ local function debug_show_node_X(p,print_fn)
       print_fn(s)
    elseif pt=='hlist' or pt=='vlist' or pt=='unset' then
       s = base .. '(' .. print_scaled(p.height) .. '+'
-         .. print_scaled(p.depth) .. ')x' .. print_scaled(p.width) .. p.dir
-      if p.shift or 0~=0 then
+         .. print_scaled(p.depth) .. ')x' .. print_scaled(p.width) 
+        .. ', dir=' .. tostring(node.has_attribute(p, attr_dir))
+      if (p.shift or 0)~=0 then
          s = s .. ', shifted ' .. print_scaled(p.shift)
       end
       if p.glue_sign >= 1 then
@@ -445,18 +458,22 @@ local function debug_show_node_X(p,print_fn)
       end
       print_fn(s)
    elseif pt == 'whatsit' then
-      s = base .. '(' .. node.whatsits()[p.subtype] .. ') '
+      s = base
       if p.subtype==sid_user then
+        local t = tostring(p.user_id) .. ' (' .. 
+           luatexbase.get_user_whatsit_name(p.user_id) .. ') '
          if p.type ~= 110 then
-            s = s .. ' user_id: ' .. p.user_id .. ' ' .. p.value
+            s = s .. ' userid:' .. t .. p.value
             print_fn(s)
          else
-            s = s .. ' user_id: ' .. p.user_id .. ' (node list)'
+            s = s .. ' userid:' .. t .. '(node list)'
+           if p.user_id==userid_table.DIR then
+              s = s .. ' dir: ' .. tostring(node.has_attribute(p, attr_dir))
+           end
             print_fn(s)
-            local q = p.value
             debug_depth=debug_depth.. '.'
-            while q do
-               debug_show_node_X(q, print_fn); q = node_next(q)
+            for q in node.traverse(p.value) do
+               debug_show_node_X(q, print_fn)
             end
             debug_depth=k
          end
@@ -512,3 +529,4 @@ function luatexja.ext_show_node(head,depth,print_fn)
 end
 
 end
+