summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/source/ptex-fontmaps/tools/mkmap-tc.lua
blob: db27b831cf8ec107583ed0bda93dbc5012ab4149 (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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
#! /usr/bin/env texlua

-- '?' は 'Pro' 等に置換される(今のところ tc では不使用)
local foundry = {
   ['noEmbed']   = {
      mr='!MSung-Light',
      gr='!MHei-Medium',
      {'n'},
   },
   ['adobe']   = {
      noncid = false,
      mr='AdobeMingStd-Light.otf',
      gr='AdobeFanHeitiStd-Bold.otf',
      {''},
   },
   ['arphic']   = {  -- gr がサンセリフになっていない
      noncid = true,
      mr='bsmi00lp.ttf %!PS ShanHeiSun-Light',
      gr='bkai00mp.ttf %!PS ZenKai-Medium',
      {''},
   },
   ['cjkunifonts']   = {  -- gr がサンセリフになっていない
      noncid = true,
      mr=':2:uming.ttc %!PS UMingTW',
      gr=':2:ukai.ttc %!PS UKaiTW',
      {''},
   },
   ['cjkunifonts-ttf']   = {  -- gr がサンセリフになっていない
      noncid = true,
      mr='uming.ttf %!PS ShanHeiSun-Uni',
      gr='ukai.ttf %!PS ZenKai-Uni',
      {''},
   },
   ['ms']   = { -- for windows vista, 7
      noncid = true,
      mr=':0:mingliu.ttc %!PS MingLiU',
      gr='msjh.ttf %!PS MicrosoftJhengHeiRegular',
      {''},
   },
   ['ms-win10']   = { -- for windows 8, 8.1, 10
      noncid = true,
      mr=':0:mingliu.ttc %!PS MingLiU',
      gr=':0:msjh.ttc %!PS MicrosoftJhengHeiRegular',
      {''},
   },
   ['dynacomware']   = {
      noncid = true,
      mr='LiSongPro.ttf',
      gr='LiHeiPro.ttf',
      {''},
   },
}

local suffix = {
   -- { '?' 置換, tcEmbed 接尾辞, (ttc index mov)}
   ['']   = {'', ''},          -- 非 CID フォント用ダミー
   ['n']  = {'!', ''},         -- 非埋め込みに使用
   ['4']  = {'Pro', ''},
   ['6']  = {'Pr6', '-pr6'},
}

-- '#' は 'h', 'v' に置換される
-- '@' は tcEmbed の値に置換される
local maps = {
   ['uptex-tc-@'] = {
      {'upmsl-#', 'UniCNS-UTF16-#', 'mr'},
      {'upmhm-#', 'UniCNS-UTF16-#', 'gr'},
   },
   ['otf-tc-@'] = {
      '% CID',
      {'otf-ctmr-#', 'Identity-#',     'mr'},
      {'otf-ctgr-#', 'Identity-#',     'gr'},
      '% Unicode',
      {'otf-utmr-#', 'UniCNS-UCS2-#', 'mr'},
      {'otf-utgr-#', 'UniCNS-UCS2-#', 'gr'},
   },
}

local jis2004_flag = 'n'
local gsub = string.gsub

function string.explode(s, sep)
   local t = {}
   sep = sep or '\n'
   string.gsub(s, "([^"..sep.."]*)"..sep, function(c) t[#t+1]=c end)
   return t
end

local function ret_suffix(fd, s, fa)
      return suffix[s][1]
end

local function replace_index(line, s)
   local ttc_mov = suffix[s][3]
   if ttc_mov then
      local ttc_index, ttc_dir = line:match('#(%d)(.)')
      if tonumber(ttc_index) then
	 return line:gsub('#..', ':' .. tostring(tonumber(ttc_index)+tonumber(ttc_dir .. ttc_mov)) .. ':')
      end
   end
   return line
end

local function make_one_line(o, fd, s)
   if type(o) == 'string' then
      return '\n' .. o .. '\n'
   else
      local fx = foundry[fd]
      local fn = replace_index(gsub(fx[o[3]], '?', ret_suffix(fd,s,o[3])), s)
      if fx.noncid and string.match(o[2],'Identity') then
	 if string.match(fn, '%!PS') then
	    fn = gsub(fn, ' %%!PS', '/AC14 %%!PS')
	 else
	    fn = fn .. '/AC14'
	 end
      end
      if string.match(o[1], '#') then -- 'H', 'V' 一括出力
	 return gsub(o[1], '#', 'h') .. '\t' .. gsub(o[2], '#', 'H') .. '\t' .. fn .. '\n'
          .. gsub(o[1], '#', 'v') .. '\t' .. gsub(o[2], '#', 'V') .. '\t' .. fn .. '\n'
      else
	 return o[1] .. '\t' .. o[2] .. '\t' .. fn .. '\n'
      end
   end
end

for fd, v1 in pairs(foundry) do
   for _,s in pairs(v1[1]) do
      local dirname = fd .. suffix[s][2]
      print('tcEmbed: ' .. dirname)
      -- Linux しか想定していない
      os.execute('mkdir ' .. dirname .. ' &>/dev/null')
      for mnx, mcont in pairs(maps) do
	 --if not string.match(mnx, '-04') or string.match(s, jis2004_flag) then
	 if not string.match(mnx, '-04') or not foundry[fd].noncid then
	    local mapbase = gsub(mnx, '@', dirname)
	    local f = io.open(dirname .. '/' .. mapbase .. '.map', 'w+')
	    for _,x in ipairs(mcont) do
	       f:write(make_one_line(x, fd, s))
	    end
	    f:close()
	 end
      end
   end
end