OSDN Git Service

Reduced 'global variables' in ltj-jfmglue.lua.
[luatex-ja/luatexja.git] / no_runtime / mk-rmlgbm-data.tex
1 %#! lualatex
2 \documentclass{article}
3
4 \usepackage{luaotfload}
5
6 \font\a=file:AdobeMingStd-Light.otf
7 \font\b=file:AdobeMyungjoStd-Medium.otf
8 \usepackage{luacode}
9 \begin{luacode}
10 -- only for debug
11 function table_search(tbl, name, prefix)
12   for i,x in pairs(tbl) do
13     if string.match(i, name) then
14       print('found: entry' .. prefix .. '.' .. i)
15     elseif type(x) == 'string' and string.match(x, name)  then
16       print('found: entry' .. prefix .. '.' .. i .. ' = ' .. x)
17     elseif type(x) == 'table' then
18       table_search(x, name, prefix .. '.' .. i)
19     end
20   end
21 end
22
23 function mkrmlgbm(nonfilename,opfilename)
24         local fontdata = containers.read(fonts.otf.cache, string.lower(nonfilename))
25         
26         -- from fonts.otf.otf_to_tfm()
27         local tfmdata
28         fontdata.shared = fontdata.shared or {
29            featuredata = { },
30            anchorhash  = { },
31            initialized = false,
32         }
33         tfmdata = fonts.otf.copy_to_tfm(fontdata)
34         tfmdata.unique = tfmdata.unique or { }
35         tfmdata.shared = tfmdata.shared or { } -- combine
36         local shared = tfmdata.shared
37         shared.otfdata = fontdata
38         shared.features = features -- default
39         shared.dynamics = { }
40         shared.processes = { }
41         tfmdata.luatex = fontdata.luatex
42         tfmdata.indices = fontdata.luatex.indices
43         tfmdata.unicodes = fontdata.luatex.unicodes
44         tfmdata.marks = fontdata.luatex.marks
45         tfmdata.originals = fontdata.luatex.originals
46         tfmdata.changed = { }
47         tfmdata.has_italic = fontdata.metadata.has_italic
48         if not tfmdata.language then tfmdata.language = 'dflt' end
49         if not tfmdata.script   then tfmdata.script   = 'dflt' end
50         _, shared.features = fonts.otf.set_features(tfmdata,fonts.define.check(features,fonts.otf.features.default))
51         
52         -- from fonts.otf.read_from_open_type()
53         tfmdata = fonts.tfm.scale(tfmdata, 655360)
54         
55         -- delete extra data
56         fontdata.subfonts = nil
57         fontdata.metadata = {}
58         fontdata.pfminfo = {}
59         fontdata.luatex.filename = 'dummy.otf'
60         fontdata.luatex.foundfilename = nil
61         fontdata.size = nil
62         fontdata.time = nil
63         fontdata.glyphs = nil
64         fontdata.luatex.indices = nil
65         fontdata.luatex.unicodes = nil
66         fontdata.luatex.originals = nil
67         fontdata.luatex.tounicode = nil
68         tfmdata.indices = nil
69         tfmdata.descriptions = {}
70         
71         tfmdata.psname = ''
72         tfmdata.filename = ''
73         tfmdata.fontname = ''
74         tfmdata.fullname = ''
75         tfmdata.name = ''
76         tfmdata.embedding = 'no'
77         tfmdata.cache = 'yes'
78         
79         for k, v in pairs(tfmdata.characters) do
80            v.height = nil
81            v.depth = nil
82        if v.width == 655360 then v.width = nil     -- 全角
83        elseif v.width == 327680 then v.width = 327680 -- 半角
84        elseif v.width == 163840 then v.width = 163840 -- 1/4 角
85        elseif v.width == 218234.88 then v.width = 218234.88 -- 1/3 角
86        elseif k>=128 then v.width = nil 
87        end
88         end
89         
90     if fontdata then -- remove gpos data
91       local tmpt = fontdata.shared.featuredata
92       tmpt.gpos_single  = {}
93       tmpt.gpos_pair  = {}
94       tmpt.gpos_reversecontextchain  = {}
95       tmpt.gpos_contextchain  = {}
96       tmpt.gpos_cursive  = {}
97       tmpt.gpos_mark2base  = {}
98       tmpt.gpos_mark2ligature = {}
99       tmpt.gpos_mark2mark = {}
100       shared.otfdata.luatex.features.gpos = nil
101       for i,x in pairs(tfmdata.shared.otfdata.luatex.sequences) do
102         if string.match(x.type,'gpos') then x.subtables = {} end
103       end
104       -- Following features use proportional glyphs, so remove them.
105       shared.otfdata.luatex.features.gsub.pwid = nil
106       shared.otfdata.luatex.features.gsub.pkna = nil
107       shared.otfdata.luatex.features.gsub.palt = nil
108     end
109
110         -- for luaotfload
111         if fontdata.pfminfo then
112           fontdata.pfminfo.os2_capheight = 0
113         end
114         table.tofile(opfilename, tfmdata, 'return', false, true, false)
115 end
116 mkrmlgbm('AdobeMingStd-Light', 'ltj-cid-adobe-cns1.lua')
117 mkrmlgbm('AdobeSongStd-Light', 'ltj-cid-adobe-gb1.lua')
118 mkrmlgbm('KozMinPr6N-Regular', 'ltj-cid-adobe-japan1.lua')
119 mkrmlgbm('AdobeMyungjoStd-Medium', 'ltj-cid-adobe-korea1.lua')
120 \end{luacode}
121
122 \begin{document}
123 \end{document}