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