summaryrefslogtreecommitdiff
path: root/tex/context/base/mkxl/font-vfc.lmt
blob: 6e9cd401350d576d1fb7a710be2abf7e54ff001c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
if not modules then modules = { } end modules ['font-vfc'] = {
    version   = 1.001,
    comment   = "companion to font-ini.mkiv and hand-ini.mkiv",
    author    = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
    copyright = "PRAGMA ADE / ConTeXt Development Team",
    license   = "see context related readme files"
}

local select, type = select, type
local insert = table.insert

local fonts             = fonts
local helpers           = fonts.helpers

local setmetatableindex = table.setmetatableindex
----- makeweak          = table.makeweak

-- Helpers dealing with virtual fonts: beware, these are final values so
-- don't change the content of tables fetched from here!

local pushcommand  = { "push" }
local popcommand   = { "pop" }
local dummycommand = { "comment" }

local slotcommand = setmetatableindex(function(t,k)
    local v = setmetatableindex(function(tt,kk)
        local vv = { "slot", k, kk }
        tt[kk] = vv
        return vv
    end)
    t[k] = v
    return v
end)

function helpers.prependcommands(commands,...)
    insert(commands,1,pushcommand)
    for i=select("#",...),1,-1 do
        local s = (select(i,...))
        if s then
            insert(commands,1,s)
        end
    end
    insert(commands,popcommand)
    return commands
end

function helpers.appendcommands(commands,...)
    insert(commands,1,pushcommand)
    insert(commands,popcommand)
    for i=1,select("#",...) do
        local s = (select(i,...))
        if s then
            insert(commands,s)
        end
    end
    return commands
end

function helpers.prependcommandtable(commands,t)
    insert(commands,1,pushcommand)
    for i=#t,1,-1 do
        local s = t[i]
        if s then
            insert(commands,1,s)
        end
    end
    insert(commands,popcommand)
    return commands
end

function helpers.appendcommandtable(commands,t)
    insert(commands,1,pushcommand)
    insert(commands,popcommand)
    for i=1,#t do
        local s = t[i]
        if s then
            insert(commands,s)
        end
    end
    return commands
end

helpers.commands = utilities.storage.allocate {
    char  = setmetatableindex(function(t,k) local v = { "char",  k } t[k] = v return v end),
    stay  = setmetatableindex(function(t,k) local v = { "stay",  k } t[k] = v return v end),
    right = setmetatableindex(function(t,k) local v = { "right", k } t[k] = v return v end),
    left  = setmetatableindex(function(t,k) local v = { "left",  k } t[k] = v return v end),
    down  = setmetatableindex(function(t,k) local v = { "down",  k } t[k] = v return v end),
    up    = setmetatableindex(function(t,k) local v = { "up",    k } t[k] = v return v end),
    push  = pushcommand,
    pop   = popcommand,
    dummy = dummycommand,
    slot  = slotcommand,
}

local codeinjections = backends.codeinjections
local vfstartcolor   = codeinjections.vfstartcolor
local vfstopcolor    = codeinjections.vfstopcolor
----- vfliteral      = codeinjections.vfliteral

helpers.vfinjectors = {
 -- startcolor = function(h,v,packet) codeinjections.vfstartcolor(h,v,packet) end,
 -- stopcolor  = function(h,v,packet) codeinjections.vfstartcolor(h,v,packet) end,
 -- literal    = function(h,v,packet) codeinjections.vfliteral   (h,v,packer) end,
    startcolor = function(h,v,packet) vfstartcolor(h,v,packet) end,
    stopcolor  = function(h,v,packet) vfstopcolor (h,v,packet) end,
 -- literal    = function(h,v,packet) vfliteral   (h,v,packer) end,
}

updaters.register("backends.injections.latebindings",function()
    vfstartcolor = backends.codeinjections.vfstartcolor
    vfstopcolor  = backends.codeinjections.vfstopcolor
 -- vfliteral    = backends.codeinjections.vfliteral
end)

-- maybe round()

local defaultline = 16384

helpers.vfspecials = {

    backgrounds = setmetatableindex(function(t,h)
        local v = setmetatableindex(function(t,d)
            local v = setmetatableindex(function(t,w)
                local v = { "frame", w, h, d, defaultline, false, false }
                t[w] = v
                return v
            end)
            t[d] = v
            return v
        end)
        t[h] = v
        return v
    end),

    outlines = setmetatableindex(function(t,h)
        local v = setmetatableindex(function(t,d)
            local v = setmetatableindex(function(t,w)
                local v = { "frame", w, h, d, defaultline, true, false }
                t[w] = v
                return v
            end)
            t[d] = v
            return v
        end)
        t[h] = v
        return v
    end),

}

-- In the past we only copied when we had something that got scaled but the problem
-- is that we then run into issues when we extend a commands in the parent. This
-- needs checking. When we go to glyph scaling, this can go away.
--
-- The alternative is to work with unscaled values and always do scaling at the
-- TeX end. So, then we need accessors instead of tables and we also need to check
-- all the context code: where do we access values?
--
-- On the other hand, in glyph scale mode we hardly do any scaling so we seldom
-- call the next one.
--
-- What if we use named fields: then we can scale by field name.

local scaled = {
    right  = true,
    down   = true,
    left   = true,
    right  = true,
    offset = true,
    rule   = true,
    char   = false,
    font   = false,
    slot   = false,
    use    = false,
    push   = false,
    pop    = false,
    lua    = false,
    -- obsolete
    node   = false,
    -- additional ones are never scaled (color etc)
}

-- normally we don't have these, and if so, only in old school fonts
-- in which case we don't have extensions so ...

function helpers.scalecommands(list,hdelta,vdelta)
    local n = #list
    for i=1,n do
        local cmd = list[i]
        if scaled[cmd[1]] then
            local result = { }
            for i=1,n do
                local cmd = list[i]
                local key = cmd[1]
                if key == "right" or key == "left" then
                    result[i] = { key, cmd[2]*hdelta }
                elseif key == "down" or key == "up" then
                    result[i] = { key, cmd[2]*vdelta }
                elseif key == "offset" then
                    result[i] = { key, cmd[2]*hdelta, cmd[3]*vdelta, cmd[4], cmd[5], cmd[6] }
                elseif key == "rule" then
                    result[i] = { key, cmd[2]*hdelta, cmd[3]*vdelta }
                elseif key == "line" then
                    result[i] = { key, cmd[2]*hdelta, cmd[3]*vdelta, cmd[4]*vdelta, cmd[5] }
             -- elseif key == "frame" then
             --     result[i] = cmd -- already scaled, for now
                else
                    result[i] = cmd -- shared since in cache and untouched
                end
            end
            return result
        end
    end
    return list
end