diff options
author | Mojca Miklavec <mojca.miklavec@gmail.com> | 2014-05-05 20:29:55 +0000 |
---|---|---|
committer | Mojca Miklavec <mojca.miklavec@gmail.com> | 2014-05-05 20:29:55 +0000 |
commit | ba9a57343987f1c2c72396e7c38f1fa30352c24c (patch) | |
tree | 66a8b12cdf67427ce96770fd0e9e581759aade1c /Master/texmf-dist/tex/context/base/font-trt.lua | |
parent | 15242121b8ddf7d4a041fb3998d295dd8232e1eb (diff) |
ConTeXt 2014.04.28 23:24
git-svn-id: svn://tug.org/texlive/trunk@33856 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/tex/context/base/font-trt.lua')
-rw-r--r-- | Master/texmf-dist/tex/context/base/font-trt.lua | 71 |
1 files changed, 65 insertions, 6 deletions
diff --git a/Master/texmf-dist/tex/context/base/font-trt.lua b/Master/texmf-dist/tex/context/base/font-trt.lua index 6fc8028d128..abc92ba5265 100644 --- a/Master/texmf-dist/tex/context/base/font-trt.lua +++ b/Master/texmf-dist/tex/context/base/font-trt.lua @@ -6,7 +6,11 @@ if not modules then modules = { } end modules ['font-trt'] = { license = "see context related readme files" } -local rawget, dofile, next = rawget, dofile, next +local rawget, dofile, next, type = rawget, dofile, next, type + +local cleanfilename = fonts.names.cleanfilename +local splitbase = file.splitbase +local lower = string.lower --[[ldx-- <p>We provide a simple treatment mechanism (mostly because I want to demonstrate @@ -14,11 +18,24 @@ something in a manual). It's one of the few places where an lfg file gets loaded outside the goodies manager.</p> --ldx]]-- -local treatments = utilities.storage.allocate() -fonts.treatments = treatments -local treatmentdata = { } -treatments.data = treatmentdata -treatments.filename = "treatments.lfg" +local treatments = fonts.treatments or { } +fonts.treatments = treatments + +local treatmentdata = treatments.data or utilities.storage.allocate() +treatments.data = treatmentdata + +treatments.filename = "treatments.lfg" + +local trace_treatments = false trackers.register("fonts.treatments", function(v) trace_treatments = v end) +local report_treatment = logs.reporter("fonts","treatment") + +treatments.report = report_treatment + +function treatments.trace(...) + if trace_treatments then + report_treatment(...) + end +end -- function treatments.load(name) -- local filename = resolvers.findfile(name) @@ -55,3 +72,45 @@ table.setmetatableindex(treatmentdata,function(t,k) table.setmetatableindex(treatmentdata,nil) return treatmentdata[k] end) + +local function applyfix(fix,filename,data,n) + if type(fix) == "function" then + -- we assume that when needed the fix reports something + -- if trace_treatments then + -- report_treatment("applying treatment %a to file %a",n,filename) + -- end + fix(data) + elseif trace_treatments then + report_treatment("invalid treatment %a for file %a",n,filename) + end +end + +function treatments.applyfixes(filename,data) + local filename = cleanfilename(filename) + local pathpart, basepart = splitbase(filename) + local treatment = treatmentdata[filename] or treatmentdata[basepart] + if treatment then + local fixes = treatment.fixes + if not fixes then + -- nothing to fix + elseif type(fixes) == "table" then + for i=1,#fixes do + applyfix(fixes[i],filename,data,i) + end + else + applyfix(fixes,filename,data,1) + end + end +end + +function treatments.ignoredfile(fullname) + local treatmentdata = treatments.data or { } -- when used outside context + local _, basepart = splitbase(fullname) + local treatment = treatmentdata[basepart] or treatmentdata[lower(basepart)] + if treatment and treatment.ignored then + report_treatment("font file %a resolved as %a is ignored, reason %a",basepart,fullname,treatment.comment or "unknown") + return true + end +end + +fonts.names.ignoredfile = treatments.ignoredfile |