1if not modules then modules = { } end modules ['font-fmp'] = {
2 version = 1.001,
3 comment = "companion to font-ini.mkiv",
4 author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
5 copyright = "PRAGMA ADE / ConTeXt Development Team",
6 license = "see context related readme files"
7}
8
9
10
11
12
13
14
15
16
17
18
19local find, match, splitlines = string.find, string.match, string.splitlines
20
21local implement = interfaces.implement
22
23local mappings = { }
24
25local function setline(n)
26 if trace_fonts then
27 report_fonts("mapline: %s",n)
28 end
29 local name, fullname, encfile, pfbfile = match(n,"(%S+)%s+(%S+).-<(.-%.enc).-<(.-%.pfb)")
30 if name then
31 mappings[name] = { fullname, encfile, pfbfile }
32 end
33end
34
35local function setfile(n)
36 local okay, data = resolvers.loadbinfile(n,"map")
37 if okay and data then
38 data = splitlines(data)
39 for i=1,#data do
40 local d = data[i]
41 if d ~= "" and not find(d,"^[#%%]") then
42 setline(d)
43 end
44 end
45 end
46end
47
48local function getentry(n)
49 local n = file.nameonly(n)
50 local m = mappings[n]
51 if m then
52 local encfile = m[2]
53 local encoding = fonts.encodings.load(encfile)
54 if not encoding then
55 return
56 end
57 local pfbfile = resolvers.findfile(m[3],"pfb")
58 if not pfbfile or pfbfile == "" then
59 return
60 end
61 return encoding, pfbfile, encfile
62 end
63end
64
65
66
67local mappings = fonts.mappings or { }
68fonts.mappings = mappings
69
70local loaded = {
71
72
73
74
75}
76
77function mappings.loadfile(name)
78 name = file.addsuffix(name,"map")
79 if not loaded[name] then
80 if trace_mapfiles then
81 report_mapfiles("loading map file %a",name)
82 end
83 setfile(name)
84 loaded[name] = true
85 end
86end
87
88local loaded = {
89}
90
91function mappings.loadline(how,line)
92 if line then
93 how = how .. " " .. line
94 elseif how == "" then
95 how = "= " .. line
96 end
97 if not loaded[how] then
98 if trace_mapfiles then
99 report_mapfiles("processing map line %a",line)
100 end
101 setline(how)
102 loaded[how] = true
103 end
104end
105
106function mappings.reset()
107 local setmapfile = lpdf and lpdf.setmapfile
108 if setmapfile then
109 setmapfile("")
110 end
111end
112
113mappings.getentry = getentry
114
115implement {
116 name = "loadmapfile",
117 actions = mappings.loadfile,
118 arguments = "string"
119}
120
121implement {
122 name = "loadmapline",
123 actions = mappings.loadline,
124 arguments = "string"
125}
126
127implement {
128 name = "resetmapfiles",
129 actions = mappings.reset,
130 arguments = "string"
131}
132 |