OSDN Git Service

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