OSDN Git Service

moved (almost) luaotfload-related code into ltj-lotf_aux.lua
authorHironori Kitagawa <h_kitagawa2001@yahoo.co.jp>
Sun, 15 Sep 2019 08:00:35 +0000 (17:00 +0900)
committerHironori Kitagawa <h_kitagawa2001@yahoo.co.jp>
Sun, 15 Sep 2019 08:00:35 +0000 (17:00 +0900)
src/ltj-jfont.lua
src/ltj-lotf_aux.lua
src/ltj-otf.lua
src/ltj-rmlgbm.lua

index b5a2e1c..a82b07a 100644 (file)
@@ -904,13 +904,14 @@ do
   luatexbase.add_to_callback(
      'luaotfload.patch_font',
      function (tfmdata)
-        local cidinfo = tfmdata.cidinfo or tfmdata.resources.cidinfo
+        local cidinfo = tfmdata.cidinfo or (tfmdata.resource and tfmdata.resources.cidinfo)
         if cidinfo and cidinfo.registry and cidinfo.ordering then
            local rd = ltjr_prepare_cid_font(cidinfo.registry, cidinfo.ordering)
            if rd then
-              local ru, rc = rd.resources.unicodes, rd.characters
+             local ru = rd.resources.unicodes -- defined by LuaTeX-ja
+             local rc = rd.characters
               for i,v in pairs(tfmdata.characters) do
-                 local w = ru["Japan1." .. tostring(v.index)]
+                 local w = ru[cidinfo.ordering .. "." .. tostring(v.index)]
                  if w then
                     v.tounicode = v.tounicode or rc[w]. tounicode
                  end
index 153bc7c..0973837 100644 (file)
@@ -29,12 +29,24 @@ function aux.specified_feature(id, name)
   return (t and t.shared and t.shared.features and t.shared.features[name])
 end
 
+
+do
+local nulltable = {}
+local function get_cidinfo(id) -- table
+  local t = getfont(id)
+  local a = t and (t.cidinfo or (t.resources and t.resources and t.resources.cidinfo)) or nulltable
+  return a
+end
+aux.get_cidinfo = get_cidinfo
+end
+
 local function get_ascender(id) -- scaled points
   if font_metric_table[id].ascender then return font_metric_table[id].ascender end
   local t = getfont(id)
   local a = t and t.parameters and t.parameters.ascender or 0
   font_metric_table[id].ascender = a; return a
 end
+
 local function get_descender(id) -- scaled points
   if font_metric_table[id].descender then return font_metric_table[id].descender end
   local t = getfont(id)
index 0bdad6b..0aaa74a 100644 (file)
@@ -73,19 +73,22 @@ local function get_ucs_from_rmlgbm(c)
       or ltjr_cidfont_data["Adobe-Japan1"].resources.unicodes["Japan1." .. tostring(c)])
       or 0
    if v>=0x200000 then -- table
-      local curjfnt_num = tex_get_attr((ltjd_get_dir_count()==dir_tate)
+      local curjfnt = tex_get_attr((ltjd_get_dir_count()==dir_tate)
                                         and attr_curtfnt or attr_curjfnt)
-      local curjfnt = font_getfont(curjfnt_num).resources
-      local base, ivs = v % 0x200000, 0xE00FF + math.floor(v/0x200000)
-      curjfnt = curjfnt and curjfnt.variants
-      curjfnt = curjfnt and curjfnt[ivs]
-      return curjfnt and curjfnt[base] or base
+      local tfmdata = font_getfont(curjfnt)
+      if tfmdata and tfmdata.resources then
+        local base, ivs = v % 0x200000, 0xE00FF + math.floor(v/0x200000)
+        curjfnt = tfmdata and tfmdata.variants
+        curjfnt = curjfnt and curjfnt[ivs]
+        return curjfnt and curjfnt[base] or base
+      else return base
+      end
    elseif v<0xF0000 then -- 素直に Unicode にマップ可能
       return v
    else -- privete use area
       local r, aj = nil, ltjr_cidfont_data["Adobe-Japan1"] 
       -- 先に ltj_vert_table を見る
-      for i,w in pairs(aj.shared.ltj_vert_table) do
+      for i,w in pairs(aj.ltj_vert_table) do
          if w==v then r=i; break end
       end
       if not r then
@@ -103,7 +106,7 @@ local function get_ucs_from_rmlgbm(c)
             end
          end
       end
-      if aj.shared.ltj_vert_table[r] then
+      if aj.ltj_vert_table[r] then
          -- CID が縦組用字形だった場合
          return ltju.replace_vert_variant(
             tex_get_attr((ltjd_get_dir_count()==dir_tate) and attr_curtfnt or attr_curjfnt),
@@ -139,29 +142,18 @@ local cid
 do
    cid = function (key)
       if key==0 then return append_jglyph(0) end
-      local curjfnt_num = tex_get_attr((ltjd_get_dir_count()==dir_tate)
+      local curjfnt = tex_get_attr((ltjd_get_dir_count()==dir_tate)
                                         and attr_curtfnt or attr_curjfnt)
-      local curjfnt = font_getfont(curjfnt_num)
-      local cidinfo = curjfnt.resources.cidinfo
-      if not cidinfo or
+      local cidinfo = ltju.get_cidinfo(cudjfnt)
+      if type(cidinfo)~="table" or
          cidinfo.ordering ~= "Japan1" and
          cidinfo.ordering ~= "GB1" and
          cidinfo.ordering ~= "CNS1" and
          cidinfo.ordering ~= "Korea1" and
          cidinfo.ordering ~= "KR" then
-         --      ltjb.package_warning('luatexja-otf',
-         --                       'Current Japanese font (or other CJK font) "'
-         --                          ..curjfnt.psname..'" is not a CID-Keyed font (Adobe-Japan1 etc.)')
             return append_jglyph(get_ucs_from_rmlgbm(key))
       else
-        local char = ltjf_font_extra_info[curjfnt_num].ind_to_uni[key]
-        if not char then
---         ltjb.package_warning('luatexja-otf',
---               '"' ..curjfnt.psname..'" does not have CID character '
---               ..tostring(key),
---            'Use a font including the specified CID character.')
-         char = 0
-        end
+        local char = ltjf_font_extra_info[curjfnt].ind_to_uni[key] or 0
         return append_jglyph(char)
       end
    end
@@ -211,10 +203,9 @@ ltjb.add_to_callback('pre_linebreak_filter', extract,'ltj.otf',
 
 -- 和文フォント読み込み時に,ind -> unicode 対応をとっておく.
 local function ind_to_uni(fmtable, fn)
-   local fi = font_getfont(fn)
+   local cid = ltju.get_cidinfo(fn)
    local t = ltjf_font_extra_info[fn].ind_to_uni
-   if t and fi.resources and fi.resources.cidinfo 
-      and fi.resources.cidinfo.ordering == "Japan1" then
+   if t and cid.ordering == "Japan1" then
       for i, v in pairs(fmtable.chars) do
         local j = string.match(i, "^AJ1%-([0-9]*)")
         if j then
index a0b084e..9f6aa74 100644 (file)
@@ -5,7 +5,7 @@ luatexja.load_module('base');      local ltjb = luatexja.base
 
 local cidfont_data = {}
 local cache_chars = {}
-local cache_ver = 8
+local cache_ver = 9
 local identifiers = fonts.hashes.identifiers
 
 local cid_reg, cid_order, cid_supp, cid_name
@@ -181,7 +181,7 @@ do
 
       -- 縦書用字形
       tt, cidm = {}, {}
-      local ttv = {}; k.shared.ltj_vert_table = ttv
+      local ttv = {}; k.ltj_vert_table = ttv
       for i = 0,kx[2] do cidm[i] = -1 end
       open_cmap_file(kx[1] .. "-V", increment, tonumber, entry)
       for i,v in pairs(tt) do
@@ -233,7 +233,7 @@ do
       function (head, fnum)
          local fontdata = font_getfont(fnum)
          if head and luatexja.jfont.font_metric_table[fnum].vert_activated then
-           local vt = fontdata.shared.ltj_vert_table
+           local vt = fontdata.ltj_vert_table
            local nh = is_node(head) and to_direct(head) or head 
             for n in traverse_id(id_glyph, head) do
                if getfont(n)==fnum then
@@ -400,7 +400,7 @@ local function font_callback(name, size, id, fallback)
       return mk_rml(basename, size, id)
    else
       local tfmdata=fallback(name, size, id)
-      if type (tfmdata) == "table" and tfmdata.shared then
+      if type (tfmdata) == "table" and tfmdata.encodingbytes == 2 then
         luatexbase.call_callback("luaotfload.patch_font", tfmdata, name)
       end
       return tfmdata