summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/source/luatex/luatexja/mk-rmlgbm-data.tex
blob: 363d01b124dbb17f76254ffc522df21bf2b9151b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
%#! 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}