luatex-fonts-demo-vf-1.lua /size: 1781 b    last modification: 2020-07-01 14:35
1if not modules then modules = { } end modules ['luatex-fonts-demo-vf-1'] = {
2    version   = 1.001,
3    comment   = "companion to luatex-*.tex",
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 identifiers = fonts.hashes.identifiers
10
11local defaults = { [0] =
12    { "pdf", "origin", "0 g" },
13    { "pdf", "origin", "1 0 0 rg" },
14    { "pdf", "origin", "0 1 0 rg" },
15    { "pdf", "origin", "0 0 1 rg" },
16    { "pdf", "origin", "0 0 1 rg" },
17}
18
19return function(specification)
20    local f1, id1 = fonts.constructors.readanddefine('lmroman10-regular',     specification.size)
21    local f2, id2 = fonts.constructors.readanddefine('lmsans10-regular',      specification.size)
22    local f3, id3 = fonts.constructors.readanddefine('lmtypewriter10-regular',specification.size)
23    if f1 and f2 and f3 then
24        f1.properties.name = specification.name
25        f1.properties.virtualized = true
26        f1.fonts = {
27            { id = id1 },
28            { id = id2 },
29            { id = id3 },
30        }
31        local chars = {
32            identifiers[id1].characters,
33            identifiers[id2].characters,
34            identifiers[id3].characters,
35        }
36        for u, v in next, f1.characters do
37            local n = math.floor(math.random(1,3)+0.5)
38            local c = chars[n][u] or v
39            v.commands = {
40                defaults[n] or defaults[0],
41                { 'slot', n, u },
42                defaults[0],
43                { 'nop' }
44            }
45            v.kerns    = nil
46            v.width    = c.width
47            v.height   = c.height
48            v.depth    = c.depth
49            v.italic   = nil
50        end
51    end
52    return f1
53end
54