OSDN Git Service

Added 'tounicode' entry in each characters in noembed fonts.
authorHironori Kitagawa <h_kitagawa2001@yahoo.co.jp>
Sat, 16 Mar 2013 10:04:43 +0000 (19:04 +0900)
committerHironori Kitagawa <h_kitagawa2001@yahoo.co.jp>
Sat, 16 Mar 2013 10:04:43 +0000 (19:04 +0900)
no_runtime/mk-rmlgbm-data.tex [deleted file]
src/ltj-rmlgbm.lua

diff --git a/no_runtime/mk-rmlgbm-data.tex b/no_runtime/mk-rmlgbm-data.tex
deleted file mode 100644 (file)
index 363d01b..0000000
+++ /dev/null
@@ -1,123 +0,0 @@
-%#! lualatex
-\documentclass{article}
-
-\usepackage{luaotfload}
-
-\font\a=file:AdobeMingStd-Light.otf
-\font\b=file:AdobeMyungjoStd-Medium.otf
-\usepackage{luacode}
-\begin{luacode}
--- only for debug
-function table_search(tbl, name, prefix)
-  for i,x in pairs(tbl) do
-    if string.match(i, name) then
-      print('found: entry' .. prefix .. '.' .. i)
-    elseif type(x) == 'string' and string.match(x, name)  then
-      print('found: entry' .. prefix .. '.' .. i .. ' = ' .. x)
-    elseif type(x) == 'table' then
-      table_search(x, name, prefix .. '.' .. i)
-    end
-  end
-end
-
-function mkrmlgbm(nonfilename,opfilename)
-       local fontdata = containers.read(fonts.otf.cache, string.lower(nonfilename))
-       
-       -- from fonts.otf.otf_to_tfm()
-       local tfmdata
-       fontdata.shared = fontdata.shared or {
-          featuredata = { },
-          anchorhash  = { },
-          initialized = false,
-       }
-       tfmdata = fonts.otf.copy_to_tfm(fontdata)
-       tfmdata.unique = tfmdata.unique or { }
-       tfmdata.shared = tfmdata.shared or { } -- combine
-       local shared = tfmdata.shared
-       shared.otfdata = fontdata
-       shared.features = features -- default
-       shared.dynamics = { }
-       shared.processes = { }
-       tfmdata.luatex = fontdata.luatex
-       tfmdata.indices = fontdata.luatex.indices
-       tfmdata.unicodes = fontdata.luatex.unicodes
-       tfmdata.marks = fontdata.luatex.marks
-       tfmdata.originals = fontdata.luatex.originals
-       tfmdata.changed = { }
-       tfmdata.has_italic = fontdata.metadata.has_italic
-       if not tfmdata.language then tfmdata.language = 'dflt' end
-       if not tfmdata.script   then tfmdata.script   = 'dflt' end
-       _, shared.features = fonts.otf.set_features(tfmdata,fonts.define.check(features,fonts.otf.features.default))
-       
-       -- from fonts.otf.read_from_open_type()
-       tfmdata = fonts.tfm.scale(tfmdata, 655360)
-       
-       -- delete extra data
-       fontdata.subfonts = nil
-       fontdata.metadata = {}
-       fontdata.pfminfo = {}
-       fontdata.luatex.filename = 'dummy.otf'
-       fontdata.luatex.foundfilename = nil
-       fontdata.size = nil
-       fontdata.time = nil
-       fontdata.glyphs = nil
-       fontdata.luatex.indices = nil
-       fontdata.luatex.unicodes = nil
-       fontdata.luatex.originals = nil
-       fontdata.luatex.tounicode = nil
-       tfmdata.indices = nil
-       tfmdata.descriptions = {}
-       
-       tfmdata.psname = ''
-       tfmdata.filename = ''
-       tfmdata.fontname = ''
-       tfmdata.fullname = ''
-       tfmdata.name = ''
-       tfmdata.embedding = 'no'
-       tfmdata.cache = 'yes'
-       
-       for k, v in pairs(tfmdata.characters) do
-          v.height = nil
-          v.depth = nil
-       if v.width == 655360 then v.width = nil     -- 全角
-       elseif v.width == 327680 then v.width = 327680 -- 半角
-       elseif v.width == 163840 then v.width = 163840 -- 1/4 角
-       elseif v.width == 218234.88 then v.width = 218234.88 -- 1/3 角
-       elseif k>=128 then v.width = nil 
-       end
-       end
-       
-    if fontdata then -- remove gpos data
-      local tmpt = fontdata.shared.featuredata
-      tmpt.gpos_single  = {}
-      tmpt.gpos_pair  = {}
-      tmpt.gpos_reversecontextchain  = {}
-      tmpt.gpos_contextchain  = {}
-      tmpt.gpos_cursive  = {}
-      tmpt.gpos_mark2base  = {}
-      tmpt.gpos_mark2ligature = {}
-      tmpt.gpos_mark2mark = {}
-      shared.otfdata.luatex.features.gpos = nil
-      for i,x in pairs(tfmdata.shared.otfdata.luatex.sequences) do
-        if string.match(x.type,'gpos') then x.subtables = {} end
-      end
-      -- Following features use proportional glyphs, so remove them.
-      shared.otfdata.luatex.features.gsub.pwid = nil
-      shared.otfdata.luatex.features.gsub.pkna = nil
-      shared.otfdata.luatex.features.gsub.palt = nil
-    end
-
-       -- for luaotfload
-       if fontdata.pfminfo then
-         fontdata.pfminfo.os2_capheight = 0
-       end
-       table.tofile(opfilename, tfmdata, 'return', false, true, false)
-end
-mkrmlgbm('AdobeMingStd-Light', 'ltj-cid-adobe-cns1.lua')
-mkrmlgbm('AdobeSongStd-Light', 'ltj-cid-adobe-gb1.lua')
-mkrmlgbm('KozMinPr6N-Regular', 'ltj-cid-adobe-japan1.lua')
-mkrmlgbm('AdobeMyungjoStd-Medium', 'ltj-cid-adobe-korea1.lua')
-\end{luacode}
-
-\begin{document}
-\end{document}
index 912c584..62349b1 100644 (file)
@@ -35,52 +35,52 @@ do
    local line, fh -- line, file handler
    local tt, cidm  -- characters, cid->glyph_index
    
-   local function load_bf_char()
+   local function load_cid_char(cid_dec, mke)
       local cid, ucs, ucsa
       line = fh:read("*l")
       while line do
-         if line == "endcidchar" then 
+         if string.find(line, "end...?char") then 
             line = fh:read("*l"); return
          else -- WMA l is in the form "<%x+>%s%d+"
-            ucs, cid = string.match(line, "<(%x+)>%s+(%d+)")
-            cid = tonumber(cid, 10); ucs = tonumber(ucs, 16); 
+            ucs, cid = string.match(line, "<(%x+)>%s+<?(%x+)>?")
+            cid = cid_dec(cid); ucs = tonumber(ucs, 16); 
             if not tt[ucs]  then 
-               tt[ucs] = { index = cid }; cidm[cid]=ucs
+               tt[ucs] = mke(cid); cidm[cid]=ucs
             end
          end
          line = fh:read("*l")
       end
    end
 
-   local function load_bf_range()
+   local function load_cid_range(inc, cid_dec, mke)
       local bucs, eucs, cid
       line = fh:read("*l")
       while line do
-         if line == "endcidrange" then 
+        if string.find(line, "end...?range") then 
             line = fh:read("*l"); return
          else -- WMA l is in the form "<%x+>%s+<%x+>"
-            bucs, eucs, cid = string.match(line, "<(%x+)>%s+<(%x+)>%s+(%d+)")
-            cid = tonumber(cid, 10); bucs = tonumber(bucs, 16)
-            eucs = tonumber(eucs, 16);
+            bucs, eucs, cid = string.match(line, "<(%x+)>%s+<(%x+)>%s+<?(%x+)>?")
+            cid = cid_dec(cid); 
+           bucs = tonumber(bucs, 16); eucs = tonumber(eucs, 16)
             for ucs = bucs, eucs do
                if not tt[ucs]  then 
-                  tt[ucs] = { index = cid }; cidm[cid]=ucs
+                  tt[ucs] = mke(cid); cidm[cid]=ucs
                end
-               cid = cid+1
+               cid = inc(cid)
             end
          end
          line = fh:read("*l")
       end
    end
 
-   local function open_cmap_file(name)
+   local function open_cmap_file(name, inc, cid_dec, mke)
       fh = io.open(kpse.find_file(name, 'cmap files'), "r")
       line = fh:read("*l")
       while line do
-         if string.find(line, "%x+%s+begincidchar") then
-            load_bf_char()
-         elseif string.find(line, "%x+%s+begincidrange") then
-            load_bf_range()
+         if string.find(line, "%x+%s+begin...?char") then
+            load_cid_char(cid_dec, mke)
+         elseif string.find(line, "%x+%s+begin...?range") then
+            load_cid_range(inc, cid_dec, mke)
          else
             line = fh:read("*l")
          end
@@ -88,25 +88,30 @@ do
       fh:close();  
    end
    
+   local function increment(a) return a+1 end
+   local function entry(a)     return {index = a} end
    function make_cid_font()
       cidfont_data[cid_name] = {
          cidinfo = { ordering=cid_order, registry=cid_reg, supplement=cid_supp },
          encodingbytes = 2, extend=1000, format = 'opentype',
          direction = 0, characters = {}, parameters = {}, embedding = "no", cache = "yes", 
-         ascender = 0, descender = 0, factor = 0, hfactor = 0, vfactor = 0, 
+         ascender = 0, descender = 0, factor = 0, hfactor = 0, vfactor = 0,
+        tounicode = 1,
       }
+
+      -- CID => Unicode 負号空間
+      -- TODO: vertical fonts?
       tt, cidm = {}, {}
       for i = 0,cid_replace[cid_name][2] do cidm[i] = -1 end
-      
-      -- Open
-      -- TODO: vertical fonts?
-      open_cmap_file(cid_replace[cid_name][1] .. "-H")
+      open_cmap_file(cid_replace[cid_name][1] .. "-H",
+                    increment, tonumber, entry)
       if cid_replace[cid_name][3] then
-         open_cmap_file(cid_replace[cid_name][3] .. "-H")
+         open_cmap_file(cid_replace[cid_name][3] .. "-H",
+                       increment, tonumber, entry)
       end
       cidfont_data[cid_name].characters = tt
-      
-      -- Unicode にマップされなかった文字
+
+      -- Unicode にマップされなかった文字の処理
       -- これらは TrueType フォントを使って表示するときはおかしくなる
       local ttu, pricode = {}, 0xF0000
       for i,v in ipairs(cidm) do
@@ -115,10 +120,29 @@ do
          end
          ttu[cid_order .. '.' .. i] = cidm[i]
       end
-      cidfont_data[cid_name].unicodes = ttu
-      
+      cidfont_data[cid_name].unicodes = ttu      
       cache_chars[cid_name]  = { [655360] = cidfont_data[cid_name].characters }
-      
+
+      -- tounicode エントリ
+      local cidp = {nil, nil}; local cidmo = cidm
+      tt, ttu, cidm = {}, {}, {}
+      open_cmap_file(cid_name .. "-UCS2",
+                    function(a) 
+                       a[2] = a[2] +1 ; return a
+                    end, 
+                    function(a) 
+                       cidp[1] = string.upper(string.sub(a,1,string.len(a)-4))
+                       cidp[2] = tonumber(string.sub(a,-4),16)
+                       return cidp
+                    end,
+                    function(a) return a[1] ..string.format('%04X',a[2])  end)
+      -- tt は cid -> tounicode になっているので cidm -> tounicode に変換
+      for i,v in ipairs(cidmo) do
+        if v>=0xF0000 then
+           cidfont_data[cid_name].characters[v].tounicode = tt[i]
+        end
+      end
+
       -- Save
       local savepath  = path.localdir .. '/luatexja/'
       if not lfs.isdir(savepath) then
@@ -128,6 +152,7 @@ do
                            .. string.lower(cid_name)  .. ".lua")
       if file.iswritable(savepath) then
          cidfont_data[cid_name].characters[46].width = math.floor(655360/14);
+        -- Standard fonts are ``seriffed''. 
          table.tofile(savepath, cidfont_data[cid_name],'return', false, true, false )
       else 
          ltjb.package_warning('luatexja',