-
Notifications
You must be signed in to change notification settings - Fork 3
/
luametalatex-pdf-font-cmap1.lua
54 lines (54 loc) · 1.25 KB
/
luametalatex-pdf-font-cmap1.lua
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
local template = [[%%!PS-Adobe-3.0 Resource-CMap
%%%%DocumentNeededResources: ProcSet (CIDInit)
%%%%IncludeResource: ProcSet (CIDInit)
%%%%BeginResource: CMap (TeX-%s-0)
%%%%Title: (TeX-%s-0 TeX %s 0)
%%%%Version: 1.000
%%%%EndComments
/CIDInit /ProcSet findresource begin
12 dict begin
begincmap
/CIDSystemInfo
<< /Registry (TeX)
/Ordering (%s)
/Supplement 0
>> def
/CMapName /TeX-%s-0 def
/CMapType 2 def
1 begincodespacerange
<00> <FF>
endcodespacerange
]]
local separator = [[endbfrange
%i beginbfchar
]]
local betweenchars = [[endbfchar
%i beginbfchar
]]
local trailer = [[endbfchar
endcmap
CMapName currentdict /CMap defineresource pop
end
end
%%EndResource
%%EOF
]]
return function(f)
local name = 'XXXstuffXXX-' .. f.name
local text = template:format(name, name, name, name, name)
text = text .. "0 beginbfrange\n"
local count, chars = 0, ""
local next_head = separator
for u, char in pairs(f.characters) do
if char.used and char.tounicode then
count = count + 1
chars = chars .. ("<%02X> <%s>\n"):format(u, char.tounicode)
if count == 100 then
text = text .. next_head:format(100) .. chars
next_head = betweenchars
end
end
end
text = text .. next_head:format(count) .. chars .. trailer
return text
end