font-ini.lmt /size: 3665 b    last modification: 2025-02-21 11:03
1if not modules then modules = { } end modules ['font-ini'] = {
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 sortedhash, setmetatableindex = table.sortedhash, table.setmetatableindex
10local allocate = utilities.storage.allocate
11
12fonts             = fonts or { }
13local fonts       = fonts
14
15local identifiers = allocate()
16
17fonts.hashes      = fonts.hashes     or { identifiers = identifiers }
18fonts.tables      = fonts.tables     or { }
19fonts.helpers     = fonts.helpers    or { }
20fonts.tracers     = fonts.tracers    or { } -- for the moment till we have move to moduledata
21fonts.specifiers  = fonts.specifiers or { } -- in format !
22fonts.callbacks   = fonts.callbacks  or { }
23
24fonts.analyzers   = { } -- not needed here
25fonts.readers     = { }
26fonts.definers    = { methods = { } }
27fonts.loggers     = { register = function() end }
28
29fonts.privateoffsets = {
30    textbase      = 0xF0000, -- used for hidden (opentype features)
31    textextrabase = 0xFD000, -- used for visible by name
32    mathextrabase = 0xFE000, -- used for visible by code
33    mathbase      = 0xFF000, -- used for hidden (virtual math)
34    keepnames     = false,   -- when set to true names are always kept (not for context)
35}
36
37local effects = setmetatableindex(
38    function(t,slant)
39        local v = setmetatableindex(
40            function(t,squeeze)
41                local v = setmetatableindex(
42                    function(t,extend)
43                        local v = setmetatableindex(
44                            function(t,mode)
45                                local v = setmetatableindex(
46                                    function(t,line)
47                                        local v = {
48                                            slant   = slant,
49                                            squeeze = squeeze,
50                                            extend  = extend,
51                                            mode    = mode,
52                                            line    = line * 1000,
53                                        }
54                                        t[line] = v
55                                        return v
56                                    end)
57                                t[mode] = v
58                                return v
59                            end)
60                        t[extend] = v
61                        return v
62                    end)
63                t[squeeze] = v
64                return v
65            end)
66        t[slant] = v
67        return v
68    end)
69
70-- This is an experiment, part of math engine project (MS and HH) where we wondered
71-- how to deal with bad or missing alphabets. One solution is a character specific
72-- effect which is supported by the engine (in fact the backend). By using a table
73-- cache we limit checking. We use tweaks in font goodies to achieve it.
74--
75-- character.effect = fonts.effects[slant][squeeze][extend][mode][line]
76-- character.effect = fonts.toeffect { slant = .2 }
77
78fonts.effects = effects
79
80fonts.effects[0][1][1][0][0] = false
81
82function fonts.toeffect(t)
83    local slant   = t.slant   or 0
84    local squeeze = t.squeeze or 1
85    local extend  = t.extend  or 1
86    local mode    = t.mode    or 0
87    local line    = t.weight  or t.line or 0 -- I need to check this .line!
88    if slant or squeeze or extend or mode or line then
89        local effect = effects[slant][squeeze][extend][mode][line]
90        if effect then
91            return effect
92        end
93    end
94end
95
96-- Also here now:
97