1if not modules then modules = { } end modules ['font-trt'] = {
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
9local rawget, dofile, next, type = rawget, dofile, next, type
10
11local cleanfilename = fonts.names.cleanfilename
12local splitbase = file.splitbase
13local lower = string.lower
14
15
16
17
18
19local treatments = fonts.treatments or { }
20fonts.treatments = treatments
21
22local treatmentdata = treatments.data or utilities.storage.allocate()
23treatments.data = treatmentdata
24
25treatments.filename = "treatments.lfg"
26
27local trace_treatments = false trackers.register("fonts.treatments", function(v) trace_treatments = v end)
28local report_treatment = logs.reporter("fonts","treatment")
29
30treatments.report = report_treatment
31
32function treatments.trace(...)
33 if trace_treatments then
34 report_treatment(...)
35 end
36end
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53table.setmetatableindex(treatmentdata,function(t,k)
54 local files = resolvers.findfiles(treatments.filename)
55 if files then
56 for i=1,#files do
57 local goodies = dofile(files[i])
58 if goodies then
59 local treatments = goodies.treatments
60 if treatments then
61 for name, data in next, treatments do
62 if not rawget(t,name) then
63 t[name] = data
64 end
65 end
66 end
67 end
68 end
69 end
70 table.setmetatableindex(treatmentdata,nil)
71 return treatmentdata[k]
72end)
73
74local function applyfix(fix,filename,data,n)
75 if type(fix) == "function" then
76
77
78
79
80 fix(data)
81 elseif trace_treatments then
82 report_treatment("invalid treatment %a for file %a",n,filename)
83 end
84end
85
86function treatments.applyfixes(filename,data)
87 local filename = cleanfilename(filename)
88 local pathpart, basepart = splitbase(filename)
89 local treatment = treatmentdata[filename] or treatmentdata[basepart]
90 if treatment then
91 local fixes = treatment.fixes
92 if not fixes then
93
94 elseif type(fixes) == "table" then
95 for i=1,#fixes do
96 applyfix(fixes[i],filename,data,i)
97 end
98 else
99 applyfix(fixes,filename,data,1)
100 end
101 end
102end
103
104function treatments.ignoredfile(fullname)
105 local treatmentdata = treatments.data or { }
106 local _, basepart = splitbase(fullname)
107 local treatment = treatmentdata[basepart] or treatmentdata[lower(basepart)]
108 if treatment and treatment.ignored then
109 report_treatment("font file %a resolved as %a is ignored, reason %a",basepart,fullname,treatment.comment or "unknown")
110 return true
111 end
112end
113
114fonts.names.ignoredfile = treatments.ignoredfile
115 |