OSDN Git Service

index->unicode
[luatex-ja/luatexja.git] / src / ltj-jfont.lua
index dabed15..3bcabf7 100644 (file)
@@ -3,7 +3,7 @@
 --
 luatexbase.provides_module({
   name = 'luatexja.jfont',
-  date = '2019/02/11',
+  date = '2019/05/01',
   description = 'Loader for Japanese fonts',
 })
 
@@ -43,7 +43,7 @@ luatexbase.create_callback("luatexja.load_jfm", "data", function (ft, jn) return
 
 local jfm_file_name, jfm_var, jfm_ksp
 local defjfm_res
-local jfm_dir, is_def_jfont, is_vert_enabled, auto_enable_vrt2
+local jfm_dir, is_def_jfont, vert_activated, auto_enable_vrt2
 
 local function norm_val(a)
    if (not a) or (a==0.) then
@@ -297,10 +297,10 @@ do
    end
 
 -- EXT
-   local utf8 = unicode.utf8
+   local utfbyte = utf.byte
    function luatexja.jfont.jfontdefX(g, dir, csname)
       jfm_dir, is_def_jfont = dir, true
-      cstemp = csname:sub( (utf8.byte(csname,1,1) == tex.escapechar) and 2 or 1, -1)
+      cstemp = csname:sub( (utfbyte(csname,1,1) == tex.escapechar) and 2 or 1, -1)
       cstemp = cstemp:sub(1, ((cstemp:sub(-1,-1)==' ') and (cstemp:len()>=2)) and -2 or -1)
       global_flag = g and '\\global' or ''
       tex.sprint(cat_lp, '\\expandafter\\font\\csname ',
@@ -338,7 +338,7 @@ do
                         chars = sz.chars, char_type = sz.char_type,
                         kanjiskip = sz.kanjiskip, xkanjiskip = sz.xkanjiskip,
                         chars_cbcache = {},
-                        vert_activated = is_vert_enabled,
+                        vert_activated = vert_activated,
       }
       local t = identifiers[fn]
       if auto_enable_vrt2 then
@@ -434,11 +434,11 @@ do
          jfm_ksp = not (x=='-')
       end
       if jfm_dir == 'tate' then
-         is_vert_enabled = (not name:match('[:;]%-vert')) and (not  name:match('[:;]%-vrt2'))
+         vert_activated = (not name:match('[:;]%-vert')) and (not  name:match('[:;]%-vrt2'))
          auto_enable_vrt2 
            = (not name:match('[:;][+%-]?vert')) and (not name:match('[:;][+%-]?vrt2'))
       else
-         is_vert_enabled, auto_enable_vrt2 = nil, nil
+         vert_activated, auto_enable_vrt2 = nil, nil
       end
       return name
    end
@@ -950,7 +950,7 @@ end
 
 --
 do
-   local cache_ver = 16
+   local cache_ver = 17
 
    local function prepare_extra_data_base(id)
       if (not id) or (not id.filename) then return end
@@ -1093,16 +1093,32 @@ do
      [0x300C]=0xFE41, [0x300D]=0xFE42, [0x300E]=0xFE43, [0x300F]=0xFE44,
      [0xFF3B]=0xFE47, [0xFF3D]=0xFE48, 
   }
-  local function add_vform(coverage, vform, ft, add_vert)
-     if type(coverage)~='table' then return end
-     for i,v in pairs(vert_form_table) do
-         if not coverage[i] and ft.characters[v] then
-             vform[i] = v
-         end
-     end
-     if add_vert then -- vert feature が有効にならない場合
-        for i,v in pairs(coverage) do vform[i] = vform[i] or v end
-     end
+  local vert_jpotf_table = {}
+  local function add_vform(coverage, vform, ft, add_vert, jpotf_vert)
+    if type(coverage)~='table' then return end
+    for i,v in pairs(vert_form_table) do
+       if not coverage[i] and ft.characters[v] then vform[i] = v end
+    end
+    if jpotf_vert then
+      for i,v in pairs(vert_jpotf_table) do
+       if ft.characters[v] then  vform[i] = coverage[v] or vform[v] or v end
+      end
+    end
+    if add_vert then -- vert feature が有効にならない場合
+      for i,v in pairs(coverage) do vform[i] = vform[i] or v end
+    end
+  end
+
+  local utfbyte, utfsub = utf.byte, utf.sub
+  luatexja.jfont.register_vert_replace = function(t)
+    for i,v in pairs(t) do
+      local ic = (type(i)=='number') and i or 
+        ((type(i)=='string') and utfbyte(utfsub(i,1,1)) or nil)
+      if ic then
+        vert_jpotf_table[ic] = (type(v)=='number') and v or 
+          ((type(v)=='string') and utfbyte(utfsub(v,1,1)) or nil)
+      end
+    end  
   end
 
 luatexbase.add_to_callback(
@@ -1114,11 +1130,14 @@ luatexbase.add_to_callback(
          local add_vert  
            = not (provides_feature(fnum, t.properties.script, t.properties.language, 'vert'))
              and not (provides_feature(fnum, t.properties.script, t.properties.language, 'vrt2'))
+         local jpotf_vert = t.shared.features.jpotf
          -- 現在の language, script で vert もvrt2 も有効にできない場合,強制的に vert 適用
          for _,i in pairs(t.resources.sequences) do
             if i.order[1]== 'vert' and i.type == 'gsub_single' and i.steps then
                for _,j in pairs(i.steps) do
-                  if type(j)=='table' then add_vform(j.coverage,vform, t, add_vert) end
+                  if type(j)=='table' then
+                     add_vform(j.coverage,vform, t, add_vert, jpotf_vert)
+                 end
                end
             end
           end