OSDN Git Service

changed implicit activation method of vrt2 feature
authorHironori Kitagawa <h_kitagawa2001@yahoo.co.jp>
Fri, 7 Nov 2014 02:23:08 +0000 (11:23 +0900)
committerHironori Kitagawa <h_kitagawa2001@yahoo.co.jp>
Fri, 7 Nov 2014 02:23:08 +0000 (11:23 +0900)
src/ltj-jfmglue.lua
src/ltj-jfont.lua
src/ltj-setwidth.lua
src/luatexja-core.sty

index 3da2877..7935f7e 100644 (file)
@@ -564,7 +564,7 @@ do
    local attr_jchar_class = luatexbase.attributes['ltj@charclass']
    local attr_autospc = luatexbase.attributes['ltj@autospc']
    local attr_autoxspc = luatexbase.attributes['ltj@autoxspc']
-   local ltjf_get_vert_glyph = ltjf.get_vert_glyph
+   --local ltjf_get_vert_glyph = ltjf.get_vert_glyph
    function set_np_xspc_jachar_yoko(Nx, x)
       local m = ltjf_font_metric_table[getfont(x)]
       local cls, c = slow_find_char_class(ltjs_orig_char_table[x], m, getchar(x))
@@ -581,7 +581,7 @@ do
       local xf = getfont(x)
       local m = ltjf_font_metric_table[xf]
       local cls = slow_find_char_class(c, m, c_glyph)
-      setfield(x, 'char', ltjf_get_vert_glyph(xf, c_glyph) or c_glyph)
+      --setfield(x, 'char', ltjf_get_vert_glyph(xf, c_glyph) or c_glyph)
       Nx.met = m; Nx.class = cls;
       if cls~=0 then set_attr(x, attr_jchar_class, cls) end
       Nx.pre  = table_current_stack[PRE + c]  or 0
index 310a72a..c8743e5 100644 (file)
@@ -54,7 +54,7 @@ luatexbase.create_callback("luatexja.load_jfm", "data", function (ft, jn) return
 
 local jfm_file_name, jfm_var
 local defjfm_res
-local jfm_dir
+local jfm_dir, is_def_jfont
 
 function define_jfm(t)
    local real_char -- Does current character class have the 'real' character?
@@ -249,7 +249,8 @@ do
    end
 
 -- EXT
-   function jfontdefX(g)
+   function jfontdefX(g, dir)
+      jfm_dir, is_def_jfont = dir, true
       local t = token.get_next()
       cstemp=token.csname_name(t)
       global_flag = g and '\\global' or ''
@@ -260,9 +261,8 @@ do
 
 -- EXT
    local identifiers = fonts.hashes.identifiers
-   function jfontdefY(dir)
-      jfm_dir = dir
-      local j = load_jfont_metric(dir)
+   function jfontdefY()
+      local j = load_jfont_metric(jfm_dir)
       local fn = font.id(cstemp)
       local f = font_getfont(fn)
       if not j then
@@ -290,7 +290,7 @@ do
       font_metric_table[fn]=fmtable
       tex.sprint(cat_lp, global_flag, '\\protected\\expandafter\\def\\csname ',
                    cstemp , '\\endcsname{\\ltj@cur'..
-                   (dir == 'yoko' and 'j' or 't') .. 'fnt', fn, '\\relax}')
+                   (jfm_dir == 'yoko' and 'j' or 't') .. 'fnt', fn, '\\relax}')
    end
 end
 
@@ -353,6 +353,11 @@ do
            name = name .. 'jfmvar=' .. jfm_var
         end
       end
+      if jfm_dir == 'tate' then
+         if not name:match('vert') and not name:match('vrt2') then
+            name = name .. ';vrt2'
+         end
+      end
       return name
    end
 
@@ -360,9 +365,11 @@ do
    local otfl_fdr = fonts.definers.read
    local ltjr_font_callback = ltjr.font_callback
    function luatexja.font_callback(name, size, id)
-      local new_name = extract_metric(name)
+      local new_name = is_def_jfont and extract_metric(name) or name
+      is_def_jfont = false
       local res =  ltjr_font_callback(new_name, size, id, otfl_fdr)
       luatexbase.call_callback('luatexja.define_font', res, new_name, size, id)
+      -- this callback processes variation selector, so we execute it always
       return res
    end
    luatexbase.create_callback('luatexja.define_font', 'simple', function (n) return n end)
@@ -624,7 +631,7 @@ do
       end
       return vw, tsb, vk
    end
-   
+
    local sort = table.sort
    local function add_fl_table(dest, tg, unitable, glyphmax, asc_des, units)
       for i = 0, glyphmax-1 do
@@ -659,7 +666,7 @@ do
            end
            -- vertical kern
            if vk then
-              dest = dest or {}; 
+              dest = dest or {};
               local dest_vk = dest.vkerns or {}; dest.vkerns = dest_vk
               for _,v in pairs(vk) do
                  local vl = v.lookup
@@ -729,7 +736,7 @@ do
       end
       return dest
    end
-   prepare_vert_data = function (dest, id) 
+   prepare_vert_data = function (dest, id)
       local a = id.resources.sequences
       if a then
         local s = id.shared.rawdata.descriptions
@@ -741,16 +748,16 @@ do
       end
       return dest
    end
-   -- 縦書き用字形への変換
-   function get_vert_glyph(n, chr)
-      local fn = font_extra_info[n]
-      return (fn and fn[chr] and fn[chr].vert) or chr
-   end
+   -- -- 縦書き用字形への変換
+   -- function get_vert_glyph(n, chr)
+   --    local fn = font_extra_info[n]
+   --    return (fn and fn[chr] and fn[chr].vert) or chr
+   -- end
 end
 
--- 
+--
 do
-   local cache_ver = 5
+   local cache_ver = 6
    local checksum = file.checksum
 
    local function prepare_extra_data_base(id)
@@ -769,7 +776,6 @@ do
            font_extra_basename[bname] = dat[1] or {}
         else
            local dat = nil
-           dat = prepare_vert_data(dat, id)
            dat = prepare_fl_data(dat, id)
            font_extra_basename[bname] = dat or {}
            ltjb.save_cache( v,
@@ -783,7 +789,7 @@ do
       end
    end
    local function prepare_extra_data_font(id, res)
-      if type(res)=='table' and res.shared then 
+      if type(res)=='table' and res.shared then
         font_extra_info[id] = font_extra_basename[file.nameonly(res.filename)]
       end
    end
@@ -808,7 +814,7 @@ do
 
    local identifiers = fonts.hashes.identifiers
    for i=1,font.nextid()-1 do
-      if identifiers[i] then 
+      if identifiers[i] then
         prepare_extra_data_base(identifiers[i])
         prepare_extra_data_font(i,identifiers[i])
       end
@@ -825,12 +831,12 @@ do
         if v.slookups then
            for sn, sv in pairs(v.slookups) do
               if subtables[sn] and type(sv)=='table' then
-                 if sv[4]~=0 then 
-                    table_vadv[char_num] 
+                 if sv[4]~=0 then
+                    table_vadv[char_num]
                        = (table_vadv[char_num] or 0) + sv[4]
                  end
-                 if sv[2]~=0 and not already_vert then 
-                    table_vorg[char_num] 
+                 if sv[2]~=0 and not already_vert then
+                    table_vorg[char_num]
                        = (table_vorg[char_num] or 0) + sv[2]
                  end
               end
@@ -840,7 +846,7 @@ do
    end
 
 luatexbase.add_to_callback(
-   "luatexja.define_jfont", 
+   "luatexja.define_jfont",
    function (fmtable, fnum)
       local vadv = {}; fmtable.v_advance = vadv
       local vorg = {}; fmtable.v_origin = vorg
@@ -858,7 +864,7 @@ luatexbase.add_to_callback(
               end
            end
         end
-        acc_feature(vadv, vorg, subtables, ft, 
+        acc_feature(vadv, vorg, subtables, ft,
                     ft.specification.features.normal.vrt2 or ft.specification.features.normal.vert)
         for i,v in pairs(vadv) do
            vadv[i]=vadv[i]/ft.units_per_em*fmtable.size
@@ -867,7 +873,7 @@ luatexbase.add_to_callback(
            vorg[i]=vorg[i]/ft.units_per_em*fmtable.size
         end
       end
-      return fmtable 
+      return fmtable
    end, 1, 'ltj.v_advance'
 )
 end
@@ -905,4 +911,3 @@ do
       end
    end
 end
-
index f8afa72..7d282d5 100644 (file)
@@ -47,7 +47,6 @@ local attr_icflag = luatexbase.attributes['ltj@icflag']
 
 local ltjf_font_metric_table = ltjf.font_metric_table
 local ltjf_font_extra_info = ltjf.font_extra_info
-local ltjf_get_vert_glyph = ltjf.get_vert_glyph
 
 local PACKED       = luatexja.icflag_table.PACKED
 local PROCESSED    = luatexja.icflag_table.PROCESSED
@@ -87,12 +86,12 @@ local function capsule_glyph_yoko(p, met, class, head, dir)
    fshift = call_callback("luatexja.set_width", fshift, met, class)
    local fheight, fdepth = char_data.height, char_data.depth
    local kbl = has_attr(p, attr_ykblshift) or 0
-   -- 
+   --
    local need_hbox
    if pwidth==fwidth then
       -- 補正後glyph node は ht: p.height - kbl - down, dp: p.depth + min(0, kbl+down) を持つ
       -- 設定されるべき寸法: ht: fheight - kbl, dp: fdepth + kbl
-      local ht_diff = fheight + fshift.down - getfield(p, 'height') 
+      local ht_diff = fheight + fshift.down - getfield(p, 'height')
       local dp_diff = fdepth  + kbl - getfield(p, 'depth') - min(kbl + fshift.down, 0)
       if  ht_diff == 0 and dp_diff ==0 then -- offset only
         set_attr(p, attr_icflag, PROCESSED)
@@ -114,7 +113,7 @@ local function capsule_glyph_yoko(p, met, class, head, dir)
       else
         need_hbox = true
       end
-   else 
+   else
       need_hbox = true
    end
 
@@ -124,7 +123,7 @@ local function capsule_glyph_yoko(p, met, class, head, dir)
       local box = node_new(id_hlist)
       setfield(p, 'yoffset', getfield(p, 'yoffset') -fshift.down);
       setfield(p, 'next', nil)
-      setfield(p, 'xoffset', getfield(p, 'xoffset') 
+      setfield(p, 'xoffset', getfield(p, 'xoffset')
                  + char_data.align*(fwidth-pwidth) - fshift.left)
       local box = node_new(id_hlist)
       setfield(box, 'width', fwidth)
@@ -152,8 +151,8 @@ local function capsule_glyph_tate(p, met, class, head, dir)
       local pf = getfont(p)
       local pc = getchar(p)
       setfield(p, 'char', pc)
-      pwidth = ltjf_font_extra_info[pf] and  ltjf_font_extra_info[pf][pc] 
-        and ltjf_font_extra_info[pf][pc].vwidth 
+      pwidth = ltjf_font_extra_info[pf] and  ltjf_font_extra_info[pf][pc]
+        and ltjf_font_extra_info[pf][pc].vwidth
         and ltjf_font_extra_info[pf][pc].vwidth * met.size or (ascent+descent)
       pwidth = pwidth + (met.v_advance[pc] or 0)
       ascent = met.v_origin[pc] and ascent - met.v_origin[pc] or ascent
@@ -224,7 +223,7 @@ luatexja.setwidth.capsule_glyph_math = capsule_glyph_math
 function luatexja.setwidth.apply_ashift_math(head, last, attr_ablshift)
    for p in node_traverse(head) do
       local pid = getid(p)
-      if p==last then 
+      if p==last then
         return
       elseif (has_attr(p, attr_icflag) or 0) ~= PROCESSED then
         if pid==id_hlist or pid==id_vlist then
index f524066..1d8af52 100644 (file)
 
 %%%%%%%% \jfont\CS={...:...;jfm=metric;...}, \globaljfont
 \protected\def\jfont{%
-  \afterassignment\ltj@@jfont\directlua{luatexja.jfont.jfontdefX(false)}}
+  \afterassignment\ltj@@jfont\directlua{luatexja.jfont.jfontdefX(false, 'yoko')}}
 \protected\def\globaljfont{%
-  \afterassignment\ltj@@jfont\directlua{luatexja.jfont.jfontdefX(true)}}
-\def\ltj@@jfont{\directlua{luatexja.jfont.jfontdefY('yoko')}}
+  \afterassignment\ltj@@jfont\directlua{luatexja.jfont.jfontdefX(true,  'yoko')}}
+\def\ltj@@jfont{\directlua{luatexja.jfont.jfontdefY()}}
 
 %%%%%%%% \tfont\CS={...:...;jfm=metric;...}, \globaltfont
-\protected\def\tfont{\afterassignment\ltj@@tfont\directlua{luatexja.jfont.jfontdefX(false)}}
+\protected\def\tfont{%
+  \afterassignment\ltj@@tfont\directlua{luatexja.jfont.jfontdefX(false, 'tate')}}
 \protected\def\globaltfont{%
-  \afterassignment\ltj@@tfont\directlua{luatexja.jfont.jfontdefX(true)}}
-\def\ltj@@tfont{\directlua{luatexja.jfont.jfontdefY('tate')}}
+  \afterassignment\ltj@@tfont\directlua{luatexja.jfont.jfontdefX(true,  'tate')}}
+\def\ltj@@tfont{\directlua{luatexja.jfont.jfontdefY()}}
 
 
 %%%%%%%% \zw, \zh