treatments.lfg /size: 3871 b    last modification: 2020-07-01 14:35
1-- There can be multiple treatments.lfg files in the tree and all are loaded in
2-- the order specified by tree order access. The first treatment of a file
3-- always wins, so one can overload. These files are not (to be) loaded with
4-- font definitions. (Experiment as part of writing the font manual.)
5--
6-- So there are several ways to fix a font: add a patcher to a goodie file and
7-- load that one. Such a patch can end up in the cached file. Treatments are
8-- applied at runtime. An experimental auto-loaded goodie approach is not yet
9-- enabled and will never be if treatments can do the job.
10
11local report = fonts.treatments.report
12
13local fix_unifraktur = {
14    comment = "suspicious x height",
15    fixes   = function(data)
16        local pfminfo = data.metadata.pfminfo
17        if pfminfo then
18            local os2_xheight = pfminfo.os2_xheight
19            if os2_xheight and os2_xheight < 350 then
20                report("suspicious x-height %a, nilling",os2_xheight)
21                pfminfo.os2_xheight_original = os2_xheight
22                pfminfo.os2_xheight = nil
23            end
24        end
25    end,
26}
27
28-- local fix_lmmonoregular = {
29--     --
30--     -- there are now some extra safeguards for idris
31--     --
32--     comment = "wrong widths of some glyphs",
33--     fixes = function(data)
34--         report("fixing some wrong widths")
35--         local unicodes     = data.resources.unicodes
36--         local descriptions = data.descriptions
37--         local function getdescription(name)
38--             local unicode = unicodes[name]
39--             if not unicode then
40--                 report("no valid unicode for %a",name)
41--                 return
42--             end
43--             local description = descriptions[unicode]
44--             if not description then
45--                 report("no glyph names %a in font",name)
46--                 return
47--             end
48--             return description
49--         end
50--         local zero = getdescription("zero")
51--         if not zero then
52--             return
53--         end
54--         local defaultwidth = zero.width
55--         local function setwidth(name)
56--             local data = getdescription(name)
57--             if data then
58--                 data.width = defaultwidth
59--             end
60--         end
61--         setwidth("six")
62--         setwidth("nine")
63--         setwidth("caron")
64--         setwidth("perthousand")
65--         setwidth("numero")
66--         setwidth("caron.cap")
67--         setwidth("six.taboldstyle")
68--         setwidth("nine.taboldstyle")
69--         setwidth("dollar.oldstyle")
70--     end
71-- }
72
73return {
74    name = "treatments",
75    version = "1.00",
76    comment = "Goodies that deals with some general issues.",
77    author = "Hans Hagen",
78    copyright = "ConTeXt development team",
79    treatments = {
80        -- we need to complete this list in order to be able to warn
81        -- users not to include these files unless permitted
82        ["adobeheitistd-regular.otf"] = {
83            comment  = "this font is part of acrobat",
84            ignored  = false,
85         -- included = false, -- not yet
86        },
87        -- just an experiment .. normally no big deal but I ran into
88        -- such case
89        ["crap.ttf"] = {
90            comment = "a text file with suffix ttf", -- used in test file
91            ignored = true,
92        },
93        ["lingoes.ttf"] = {
94            comment = "bugged file",
95            ignored = true,
96        },
97        -- harmless example
98     -- ["copperplatethirtythreebc.ttf"] = {
99     --     comment = "hangs and has no hyphen",
100     --     ignored = true,
101     -- },
102     -- ["latinmodern-math.otf"] = {
103     --     comment = "experimental",
104     -- },
105        ["lmmono12regular.otf"]    = fix_lmmonoregular,
106        ["unifrakturcook.ttf"]     = fix_unifraktur,
107        ["unifrakturmaguntia.ttf"] = fix_unifraktur,
108    },
109}
110