summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/context/modules/mkiv/s-fonts-variable.lua
blob: d50df01214f7e07653e781e7b143fdc88a952473 (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
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
if not modules then modules = { } end modules ['s-fonts-variable'] = {
    version   = 1.001,
    comment   = "companion to s-fonts-variable.mkiv",
    author    = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
    copyright = "PRAGMA ADE / ConTeXt Development Team",
    license   = "see context related readme files"
}

moduledata.fonts          = moduledata.fonts          or { }
moduledata.fonts.variable = moduledata.fonts.variable or { }

local format      = string.format
local stripstring = string.nospaces
local lower       = string.lower
local rep         = string.rep

local context = context
local NC, NR, HL = context.NC, context.NR, context.HL
local bold, monobold, mono, formattedmono = context.bold, context.monobold, context.mono, context.formatted.mono

function moduledata.fonts.variable.showvariations(specification)

    specification = interfaces.checkedspecification(specification)

    local fontfile = specification.font
    local fontname = format("testfont-%s",i)
    local fontsize = tex.dimen.bodyfontsize
    if not fontfile then
        return
    end

    local id, fontdata = fonts.definers.define {
        name = fontfile,
     -- size = fontsize,
        cs   = fontname,
    }

    if not fontdata then
        context("no font with name %a found",fontname)
    end

    local resources = fontdata.resources

    if not resources then
        return
    end

    local variabledata = resources.variabledata

    if not variabledata then
        return
    end

    context.starttitle { title = fontdata.shared.rawdata.metadata.fullname }

    local parameters = fontdata.parameters

    context.startsubject { title = "parameters" }
        if parameters then
            context.starttabulate { "|||" }
                NC() monobold("ascender")  NC() context("%p",parameters.ascender)     NC() NR()
                NC() monobold("descender") NC() context("%p",parameters.descender)    NC() NR()
                NC() monobold("emwidth")   NC() context("%p",parameters.em)           NC() NR()
                NC() monobold("exheight")  NC() context("%p",parameters.ex)           NC() NR()
                NC() monobold("size")      NC() context("%p",parameters.size)         NC() NR()
                NC() monobold("slant")     NC() context("%s",parameters.slant)        NC() NR()
                NC() monobold("space")     NC() context("%p",parameters.space)        NC() NR()
                NC() monobold("shrink")    NC() context("%p",parameters.spaceshrink)  NC() NR()
                NC() monobold("stretch")   NC() context("%p",parameters.spacestretch) NC() NR()
                NC() monobold("units")     NC() context("%s",parameters.units)        NC() NR()
            context.stoptabulate()
        else
            context("no parameters")
        end
    context.stopsubject()

    local features = fontdata.shared.rawdata.resources.features

    context.startsubject { title = "features" }
        if features then
            local function f(g)
                if g then
                    local t = table.sortedkeys(g)
                    local n = 0
                    for i=1,#t do
                        if #t[i] <= 4 then
                            n = n + 1
                            t[n] = t[i]
                        end
                    end
                    return table.concat(t," ",1,n)
                end
            end
            context.starttabulate { "||p|" }
                NC() monobold("gpos")  NC() mono(f(features.gpos)) NC() NR()
                NC() monobold("gsub")  NC() mono(f(features.gsub)) NC() NR()
            context.stoptabulate()
        else
            context("no features")
        end
    context.stopsubject()

    local designaxis = variabledata.designaxis

    context.startsubject { title = "design axis" }
        if designaxis then
            context.starttabulate { "||||c|c|c|c|c|" }
                NC() bold("tag")
                NC() bold("name")
                NC() bold("variant")
                NC() bold("flags")
                NC() bold("value")
                NC() bold("min")
                NC() bold("max")
                NC() bold("link")
                NC() NR()
                HL()
                for k=1,#designaxis do
                    local axis      = designaxis[k]
                    local tag       = axis.tag
                    local name      = axis.name
                    local variants  = axis.variants
                    local haslimits = variants[1].maximum
                    local haslink   = variants[1].link
                    for i=1,#variants do
                        local variant = variants[i]
                        NC() monobold(tag)
                        NC() context(name)
                        NC() context(variant.name)
                        NC() formattedmono("0x%04x",variant.flags)
                        NC() context(variant.value)
                        NC() context(variant.minimum or "-")
                        NC() context(variant.maximum or "-")
                        NC() context(variant.link or "-")
                        NC() NR()
                        tag  = nil
                        name = nil
                    end
                end
            context.stoptabulate()
        else
            context("no design axis defined (no \\type{stat} table)")
        end
    context.stopsubject()

    local axis      = variabledata.axis
    local instances = variabledata.instances
    local list      = { }

    context.startsubject { title = "axis" }
        if axis then
            context.starttabulate { "|||c|c|c|" }
                NC() bold("tag")
                NC() bold("name")
                NC() bold("min")
                NC() bold("def")
                NC() bold("max")
                NC() NR()
                HL()
                for k=1,#axis do
                    local a = axis[k]
                    NC() monobold(a.tag)
                    NC() context(a.name)
                    NC() context(a.minimum)
                    NC() context(a.default)
                    NC() context(a.maximum)
                    NC() NR()
                    list[#list+1] = a.tag
                end
            context.stoptabulate()
        else
            context("no axis defined, incomplete \\type{fvar} table")
        end
    context.stopsubject()

    local collected = { }

    context.startsubject { title = "instances" }
        if instances and #list > 0 then
            context.starttabulate { "||" .. rep("c|",#list) .. "|" }
                NC()
                for i=1,#list do
                    NC() monobold(list[i])
                end
                NC()
                local fullname = lower(stripstring(fontdata.shared.rawdata.metadata.fullname))
                formattedmono("%s*",fullname)
                NC() NR()
                HL()
                for k=1,#instances do
                    local i = instances[k]
                    NC() monobold(i.subfamily)
                    local values = i.values
                    local hash = { }
                    for k=1,#values do
                        local v = values[k]
                        hash[v.axis] = v.value
                    end
                    for i=1,#list do
                        NC() context(hash[list[i]])
                    end
                    NC()
                    local instance = lower(stripstring(i.subfamily))
                    mono(instance)
                    collected[#collected+1] = fullname .. instance
                    NC() NR()
                end
            context.stoptabulate()
        else
            context("no instances defined, incomplete \\type{fvar} table")
        end
    context.stopsubject()

    for i=1,#collected do

        local instance = collected[i]
        context.startsubject { title = instance }
            context.start()
            context.definedfont { "name:" .. instance .. "*default" }
            context.input("zapf.tex")
            context.par()
            context.stop()
        context.stopsubject()
    end

 -- local function showregions(tag)
 --
 --     local regions = variabledata[tag]
 --
 --     context.startsubject { title = tag }
 --         if regions then
 --             context.starttabulate { "|r|c|r|r|r|" }
 --             NC() bold("n")
 --             NC() bold("axis")
 --             NC() bold("start")
 --             NC() bold("peak")
 --             NC() bold("stop")
 --             NC() NR()
 --             HL()
 --             local designaxis = designaxis or axis
 --             for i=1,#regions do
 --                 local axis = regions[i]
 --                 for j=1,#axis do
 --                     local a = axis[j]
 --                     NC() monobold(i)
 --                     NC() monobold(designaxis[j].tag)
 --                     NC() context("%0.3f",a.start)
 --                     NC() context("%0.3f",a.peak)
 --                     NC() context("%0.3f",a.stop)
 --                     NC() NR()
 --                     i = nil
 --                 end
 --             end
 --             context.stoptabulate()
 --         else
 --             context("no %s defined",tag)
 --         end
 --     context.stopsubject()
 --
 -- end
 --
 -- showregions("gregions")
 -- showregions("mregions")
 -- showregions("hregions")

    context.stoptitle()

end