OSDN Git Service

First attempt for new luaotfload/luatexbase
authorHironori Kitagawa <h_kitagawa2001@yahoo.co.jp>
Tue, 7 May 2013 14:22:11 +0000 (23:22 +0900)
committerHironori Kitagawa <h_kitagawa2001@yahoo.co.jp>
Tue, 7 May 2013 14:22:11 +0000 (23:22 +0900)
Requirements:
 * LuaTeX >=0.74.0
 * luaotfload v2.2
 * luatexbase v0.6

---
 * luatexja-otf can't process some CIDs
 * some fonts (HG fonts?) are incorrectly displayed (too large)
 * merged 'kitagawa_cid' branch; now non-embedded fonts don't support any features.
   (I want to re-support 'expand' and 'slant', but not else)

src/ltj-jfont.lua
src/ltj-otf.lua
src/ltj-pretreat.lua
src/ltj-rmlgbm.lua
src/luatexja.lua

index e858906..47ac1ac 100644 (file)
@@ -173,8 +173,6 @@ luatexbase.create_callback("luatexja.find_char_class", "data",
 function find_char_class(c,m)
 -- c: character code, m: 
    if not m then return 0 end
---   print("**")
---   for i,v in pairs(m) do print(i,v) end
    return m.chars[c] or 
       luatexbase.call_callback("luatexja.find_char_class", 0, m, c)
 end
@@ -236,8 +234,10 @@ function jfontdefY() -- for horizontal font
                     zw = sz.zw, zh = sz.zh, 
                     chars = sz.chars, char_type = sz.char_type,
                     kanjiskip = sz.kanjiskip, xkanjiskip = sz.xkanjiskip, 
-                    mono_flag = not string.match((fonts.ids[fn].name or ''), "+[(pwid)(palt)]"),
                    }
+   fmtable.mono_flag = fonts.ids[fn].cidinfo
+      and (not string.match((fonts.ids[fn].name or ''), "+[(pwid)(palt)]"))
+      
    fmtable = luatexbase.call_callback("luatexja.define_jfont", fmtable, fn)
    font_metric_table[fn]=fmtable
    tex.sprint(cat_lp, luatexja.is_global .. '\\protected\\expandafter\\def\\csname ' 
@@ -291,11 +291,10 @@ local function extract_metric(name)
 end
 
 -- replace fonts.define.read()
-local ljft_dr_orig = fonts.define.read
-function fonts.define.read(name, size, id)
+function font_callback(name, size, id, fallback)
    extract_metric(name)
    -- In the present imple., we don't remove "jfm=..." from name.
-   return ljft_dr_orig(name, size, id)
+   return fallback(name, size, id)
 end
 
 ------------------------------------------------------------------------
index e2f8cad..6884550 100644 (file)
@@ -73,16 +73,17 @@ end
 
 function cid(key)
    local curjfnt = fonts.ids[tex.attribute[attr_curjfnt]]
-   if curjfnt.cidinfo.ordering ~= "Japan1" and
-          curjfnt.cidinfo.ordering ~= "GB1" and
-          curjfnt.cidinfo.ordering ~= "CNS1" and
-          curjfnt.cidinfo.ordering ~= "Korea1" 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))
+   if not curjfnt.cidinfo or 
+      curjfnt.cidinfo.ordering ~= "Japan1" and
+      curjfnt.cidinfo.ordering ~= "GB1" and
+      curjfnt.cidinfo.ordering ~= "CNS1" and
+      curjfnt.cidinfo.ordering ~= "Korea1" 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))
    end
-   local char = curjfnt.unicodes[curjfnt.cidinfo.ordering..'.'..tostring(key)]
+   local char = curjfnt.resources.unicodes[curjfnt.cidinfo.ordering..'.'..tostring(key)]
    if not char then
       ltjb.package_warning('luatexja-otf',
                            'Current Japanese font (or other CJK font) "'
@@ -145,7 +146,7 @@ local function cid_to_char(fmtable, fn)
       for i, v in pairs(fmtable.chars) do
         local j = string.match(i, "^AJ1%-([0-9]*)")
         if j then
-           j = tonumber(fi.unicodes['Japan1.'..tostring(j)])
+           j = tonumber(fi.resources.unicodes['Japan1.'..tostring(j)])
            if j then
               fmtable.cid_char_type[j] = v 
            end
index 21f0076..4404327 100644 (file)
@@ -92,10 +92,20 @@ local function suppress_hyphenate_ja(head)
            p.subtype = floor(p.subtype*0.5)*2
            set_attr(p, attr_orig_char, p.char)
            if ltjf_font_metric_table[pf] and ltjf_font_metric_table[pf].mono_flag then
-              local pco = fonts_ids[pf].cidinfo.ordering
+              local pfd = fonts_ids[pf]
+              local pco = pfd.cidinfo.ordering
               for i,v in pairs(fwglyph) do
-                 if pco == i then
-                    local fwc = fonts_ids[pf].unicodes[pco .. '.'.. tostring(v[p.char])]
+                 if pco == i and pfd.shared.resources then
+                    -- print(pf, pfd.fullname, pfd)
+                    -- for j,w in pairs(pfd.resources) do
+                    --         print('["' .. j .. '"] = ' .. tostring(w))
+                    --         if type(w) == 'table' and j~='characters' then
+                    --            for k,x in pairs(w) do
+                    --               print('    ["' .. k .. '"] = ' .. tostring(x))
+                    --            end
+                    --         end
+                    -- end
+                    local fwc = pfd.shared.resources.unicodes[pco .. '.'.. tostring(v[p.char])]
                     if fwc then p.char = fwc end
                     break
                  end
@@ -140,4 +150,4 @@ luatexbase.add_to_callback('hyphenate',
 
 luatexja.pretreat = {
    set_box_stack_level = set_box_stack_level,
-}
\ No newline at end of file
+}
index d6eea2f..4bafaf2 100644 (file)
@@ -1,10 +1,19 @@
 --
--- luatexja/ltj-rmlgbm.lua
+-- luatexja/rmlgbm.lua
 --
+luatexbase.provides_module({
+  name = 'luatexja.rmlgbm',
+  date = '2013/03/17',
+  version = '0.4',
+  description = 'Definitions of non-embedded Japanese (or other CJK) fonts',
+})
+module('luatexja.rmlgbm', package.seeall)
+local err, warn, info, log = luatexbase.errwarinf(_NAME)
 
 luatexja.load_module('base');      local ltjb = luatexja.base
 
-local cidfont_data = {}
+cidfont_data = {}
+local cidfont_data = cidfont_data
 local cache_chars = {}
 local path           = {
     localdir  = file.join(kpse.expand_var("$TEXMFVAR"), aux_dir),
@@ -14,7 +23,7 @@ local path           = {
 local cid_reg, cid_order, cid_supp, cid_name
 local taux_dir = 'luatex-cache/luatexja'
 local cid_replace = {
-   ["Adobe-Japan1"] = {"UniJIS-UTF32", 23057, 
+   ["Adobe-Japan1"] = {"UniJIS2004-UTF32", 23057, 
                       function (i)
                          if (231<=i and i<=632) or (8718<=i and i<=8719) 
                             or (12063<=i and i<=12087) then
@@ -24,10 +33,8 @@ local cid_replace = {
                          elseif 9738<=i and i<=9757 then
                             return 163840 -- 655360/4
                          end
-                      end, 
-                      "UniJIS2004-UTF32"},
-                       -- 基本的には JIS X 0208:1990 に沿ったマッピングだが
-                       -- JIS X 0213:2004 のみにある字も使えるようにする
+                      end},
+                       -- 基本的には JIS X 0213:2004 に沿ったマッピング
    ["Adobe-Korea1"] = {"UniKS-UTF32",  18351,
                       function (i)
                          if 8094<=i and i<=8100 then 
@@ -108,7 +115,9 @@ do
    end
    
    local function increment(a) return a+1 end
-   local function entry(a)     return {index = a} end
+   local function entry(a)     
+      return {index = a} 
+   end
    function make_cid_font()
       local k = {
          cidinfo = { ordering=cid_order, registry=cid_reg, supplement=cid_supp },
@@ -120,14 +129,11 @@ do
       local kx = cid_replace[cid_name]
       cidfont_data[cid_name] = k
 
-      -- CID => Unicode 号空間
+      -- CID => Unicode 号空間
       -- TODO: vertical fonts?
       tt, cidm = {}, {}
       for i = 0,kx[2] do cidm[i] = -1 end
       open_cmap_file(kx[1] .. "-H", increment, tonumber, entry)
-      if kx[4] then
-         open_cmap_file(kx[4] .. "-H", increment, tonumber, entry)
-      end
       k.characters = tt
 
       -- Unicode にマップされなかった文字の処理
@@ -135,11 +141,24 @@ do
       local ttu, pricode = {}, 0xF0000
       for i,v in ipairs(cidm) do
          if v==-1 then 
-            tt[pricode], cidm[i], pricode=  { index = i }, pricode, pricode+1;
+            tt[pricode], cidm[i], pricode 
+              = { index = i }, pricode, pricode+1;
          end
          ttu[cid_order .. '.' .. i] = cidm[i]
       end
-      k.unicodes = ttu      
+      -- shared
+      k.shared = {
+         otfdata = { 
+            cidinfo= k.cidinfo, verbose = false, 
+            shared = { featuredata = {}, }, 
+            luatex = { features = {}, 
+                      defaultwidth=1000, 
+                      sequences = {  }, },
+         },
+         dynamics = {}, features = {}, processes = {}, 
+      }
+      k.resources = { unicodes = ttu, }
+      k.descriptions = {}
       cache_chars[cid_name]  = { [655360] = k.characters }
 
       -- tounicode エントリ
@@ -163,17 +182,6 @@ do
         end
       end
 
-      -- shared
-      k.shared = {
-         otfdata = { 
-            cidinfo= k.cidinfo, verbose = false, 
-            shared = { featuredata = {}, }, 
-            luatex = { features = {}, defaultwidth=1000, sequences = {  }, },
-         },
-         dynamics = {}, features = {}, processes = {}, 
-      }
-      k.descriptions = {}
-
       -- Save
       local savepath  = path.localdir .. '/luatexja/'
       if not lfs.isdir(savepath) then
@@ -225,8 +233,8 @@ end
 
 -- High-level
 local function mk_rml(name, size, id)
-   local specification = fonts.define.analyze(name,size)
-   specification = fonts.define.specify[':'](specification)
+   local specification = fonts.definers.analyze(name,size)
+   specification = fonts.definers.resolve(specification)
    local features = specification.features.normal
 
    local fontdata = {}
@@ -238,7 +246,6 @@ local function mk_rml(name, size, id)
    end
    fontdata.characters = nil
    cachedata.characters = nil
-   fontdata.unicodes = nil
    fontdata.shared = nil
    cachedata.shared = nil
    if s.shared then
@@ -247,9 +254,6 @@ local function mk_rml(name, size, id)
       for k, v in pairs(s.shared) do
         shared[k] = v
       end
-      
-      shared.set_dynamics = fonts.otf.set_dynamics 
-      shared.processes, shared.features = fonts.otf.set_features(cachedata,fonts.define.check(features,fonts.otf.features.default))
    end
 
    -- characters & scaling
@@ -280,17 +284,19 @@ local function mk_rml(name, size, id)
    fontdata.hfactor = fontdata.hfactor * scale;     cachedata.hfactor = fontdata.hfactor
    fontdata.vfactor = fontdata.vfactor * scale;     cachedata.vfactor = fontdata.vfactor
    fontdata.size = size;                            cachedata.size = size
-
+   fontdata.resources = s.resources
+   cachedata.resources = s.resources
+   
    -- no embedding
    local var = ''
-   if features.slant then 
-      fontdata.slant = features.slant*1000;         cachedata.slant = fontdata.slant
-      var = var .. 's' .. tostring(features.slant)
-   end
-   if features.extend then 
-      fontdata.extend = features.extend*1000;       cachedata.extend = fontdata.extend
-       var = var .. 'x' .. tostring(features.extend)
-  end
+  --  if features.slant then 
+  --     fontdata.slant = features.slant*1000;         cachedata.slant = fontdata.slant
+  --     var = var .. 's' .. tostring(features.slant)
+  --  end
+  --  if features.extend then 
+  --     fontdata.extend = features.extend*1000;       cachedata.extend = fontdata.extend
+  --      var = var .. 'x' .. tostring(features.extend)
+  --  end
    fontdata.name = specification.name .. size .. var; cachedata.name = fontdata.name
    fontdata.fullname = specification.name .. var; cachedata.fullname = fontdata.fullname
    fontdata.psname = specification.name; cachedata.psname = fontdata.psname
@@ -299,8 +305,7 @@ local function mk_rml(name, size, id)
    return fontdata
 end
 
-local dr_orig = fonts.define.read
-function fonts.define.read(name, size, id)
+function font_callback(name, size, id, fallback)
    local p = utf.find(name, ":") or utf.len(name)+1
    if utf.sub(name, 1, p-1) == 'psft' then
       local s = "Adobe-Japan1-6"
@@ -335,13 +340,9 @@ function fonts.define.read(name, size, id)
       end
       return mk_rml(basename, size, id)
    else 
-      return dr_orig(name, size, id)
+      return fallback(name, size, id)
    end
 end
 
-cid_reg, cid_order, cid_name = 'Adobe', 'Japan1', 'Adobe-Japan1'
+cid_reg, cid_order, cid_name, cid_supp = 'Adobe', 'Japan1', 'Adobe-Japan1'
 read_cid_font()
-
-luatexja.rmlgbm = {
-   cidfont_data = cidfont_data,
-}
\ No newline at end of file
index a1dee4e..de9da60 100644 (file)
@@ -1,7 +1,5 @@
 
-local floor = math.floor
-
-require('lualibs')
+require('lualibs-table')
 
 ------------------------------------------------------------------------
 -- naming:
@@ -9,18 +7,7 @@ require('lualibs')
 --    int_... : called from other Lua codes, but not from \directlua{}
 --    (other)     : only called from this file
 function luatexja.load_module(name)
-   if not package.loaded['luatexja.' .. name] then
-      local fn = 'ltj-' .. name .. '.lua'
-      local found = kpse.find_file(fn, 'tex')
-      if not found then
-        tex.error("LuaTeX-ja error: File `" .. fn .. "' not found", 
-                       {'This file ' .. fn .. ' is required for LuaTeX-ja.', 
-                        'Please check your installation.'})
-      else 
-        texio.write_nl('(' .. found .. ')')
-        require(found) -- 2度読み防止; これでいいのか?
-      end
-   end
+   require('ltj-' .. name.. '.lua')
 end
 function luatexja.load_lua(fn)
    local found = kpse.find_file(fn, 'tex')
@@ -83,28 +70,6 @@ load_module('setwidth');  local ltjw = luatexja.setwidth
 load_module('math');      local ltjm = luatexja.math
 load_module('tangle');    local ltjb = luatexja.base
 
-
-local node_type = node.type
-local node_new = node.new
-local node_prev = node.prev
-local node_next = node.next
-local has_attr = node.has_attribute
-local node_insert_before = node.insert_before
-local node_insert_after = node.insert_after
-local node_hpack = node.hpack
-
-local id_penalty = node.id('penalty')
-local id_glyph = node.id('glyph')
-local id_glue_spec = node.id('glue_spec')
-local id_glue = node.id('glue')
-local id_kern = node.id('kern')
-local id_hlist = node.id('hlist')
-local id_vlist = node.id('vlist')
-local id_rule = node.id('rule')
-local id_math = node.id('math')
-local id_whatsit = node.id('whatsit')
-local sid_user = node.subtype('user_defined')
-
 local attr_jchar_class = luatexbase.attributes['ltj@charclass']
 local attr_curjfnt = luatexbase.attributes['ltj@curjfnt']
 local attr_yablshift = luatexbase.attributes['ltj@yablshift']
@@ -112,8 +77,15 @@ local attr_icflag = luatexbase.attributes['ltj@icflag']
 local attr_uniqid = luatexbase.attributes['ltj@uniqid']
 local cat_lp = luatexbase.catcodetables['latex-package']
 
+
+---- table: charprop_stack_table [stack_level].{pre|post|xsp}[chr_code]
+
+
 -- Three aux. functions, bollowed from tex.web
+
 local unity=65536
+local floor = math.floor
+
 local function print_scaled(s)
    local out=''
    local delta=10
@@ -144,7 +116,7 @@ local function print_glue(d,order)
    return out
 end
 
-function print_spec(p)
+local function print_spec(p)
    local out=print_scaled(p.width)..'pt'
    if p.stretch~=0 then
       out=out..' plus '..print_glue(p.stretch,p.stretch_order)
@@ -156,8 +128,6 @@ return out
 end
 
 
----- table: charprop_stack_table [stack_level].{pre|post|xsp}[chr_code]
-
 ------------------------------------------------------------------------
 -- CODE FOR GETTING/SETTING PARAMETERS 
 ------------------------------------------------------------------------
@@ -265,15 +235,46 @@ luatexbase.add_to_callback('pre_linebreak_filter',
       return main_process(head, true, tex.textdir)
    end,'ltj.pre_linebreak_filter',
    luatexbase.priority_in_callback('pre_linebreak_filter',
-                                  'luaotfload.pre_linebreak_filter') + 1)
+                                  'luaotfload.node_processor') + 1)
 luatexbase.add_to_callback('hpack_filter', 
   function (head,groupcode,size,packtype, dir)
      return main_process(head, false, dir)
   end,'ltj.hpack_filter',
    luatexbase.priority_in_callback('hpack_filter',
-                                  'luaotfload.hpack_filter') + 1)
+                                  'luaotfload.node_processor') + 1)
+
+-- define_font
+
+local otfl_fdr = fonts.definers.read
+function luatexja.font_callback(name, size, id)
+  return ltjf.font_callback(
+     name, size, id, 
+     function (name, size, id) return ltjr.font_callback(name, size, id, otfl_fdr) end
+  )
+end
+--luatexbase.remove_from_callback('define_font',"luaotfload.define_font")
+luatexbase.add_to_callback('define_font',luatexja.font_callback,"luatexja.font_callback", 1)
+
+
+
+
 
 -- debug
+
+do
+
+local id_penalty = node.id('penalty')
+local id_glyph = node.id('glyph')
+local id_glue_spec = node.id('glue_spec')
+local id_glue = node.id('glue')
+local id_kern = node.id('kern')
+local id_hlist = node.id('hlist')
+local id_vlist = node.id('vlist')
+local id_rule = node.id('rule')
+local id_math = node.id('math')
+local id_whatsit = node.id('whatsit')
+local sid_user = node.subtype('user_defined')
+
 local function get_attr_icflag(p)
    return (has_attr(p, attr_icflag) or 0) % icflag_table.PROCESSED_BEGIN_FLAG
 end
@@ -410,4 +411,6 @@ function luatexja.ext_show_node(head,depth,print_fn)
    else
       print_fn(debug_depth .. ' (null list)')
    end
-end
\ No newline at end of file
+end
+
+end