summaryrefslogtreecommitdiff
path: root/tex/context/base/s-fnt-35.mkiv
blob: 157d3062cb3fb9e40d0ffc42282f32006434c9ef (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
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
%D \module
%D   [      file=s-fnt-35,
%D        version=2011.10.10,
%D          title=\CONTEXT\ Style File,
%D       subtitle=Feature List,
%D         author=Hans Hagen,
%D           date=\currentdate,
%D      copyright={PRAGMA ADE \& \CONTEXT\ Development Team}]
%C
%C This module is part of the \CONTEXT\ macro||package and is
%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
%C details.

% we already have a way to show character tables

\startluacode

-- the table will move to a font-* file

moduledata.fonts = moduledata.fonts or { }

local digits = {
    dflt = {
        dflt = "1234567890 1/2",
    },
}

local punctuation = {
    dflt = {
        dflt = ". , : ; ? !",
    },
}

local symbols = {
    dflt = {
        dflt = "@ # $ % & * () [] {} <> + - = / |",
    },
}

local uppercase = {
    latn = {
        dflt = "ABCDEFGHIJKLMNOPQRSTUVWXYZ",
    },
    grek = {
        dftl = "ΑΒΓΔΕΗΘΙΚΛΜΝΞΟΠΡΣΤΥΦΧΨΩ",
    },
    cyrl= {
        dflt = "АБВГДЕЖЗИІЙКЛМНОПРСТУФХЦЧШЩЪЫЬѢЭЮЯѲ"
    },
}

local lowercase = {
    latn = {
        dftl = "abcdefghijklmnopqrstuvwxyz",
    },
    grek = {
        dftl = "αβγδεηθικλμνξοπρστυφχψω",
    },
    cyrl= {
        dflt = "абвгдежзиійклмнопрстуфхцчшщъыьѣэюяѳ"
    },
}

local samples = {
    digits      = digits,
    punctuation = punctuation,
    symbols     = symbols,
    uppercase   = uppercase,
    lowercase   = lowercase,
}

fonts.tracers.samples = samples

table.setmetatableindex(uppercase,        function(t,k) return rawget(t,"latn") end)
table.setmetatableindex(lowercase,        function(t,k) return rawget(t,"latn") end)
table.setmetatableindex(digits,           function(t,k) return rawget(t,"dflt") end)
table.setmetatableindex(symbols,          function(t,k) return rawget(t,"dflt") end)
table.setmetatableindex(punctuation,      function(t,k) return rawget(t,"dflt") end)

table.setmetatableindex(uppercase.latn,   function(t,k) return rawget(t,"dflt") end)
table.setmetatableindex(uppercase.grek,   function(t,k) return rawget(t,"dflt") end)
table.setmetatableindex(uppercase.cyrl,   function(t,k) return rawget(t,"dflt") end)

table.setmetatableindex(lowercase.latn,   function(t,k) return rawget(t,"dflt") end)
table.setmetatableindex(lowercase.grek,   function(t,k) return rawget(t,"dflt") end)
table.setmetatableindex(lowercase.cyrl,   function(t,k) return rawget(t,"dflt") end)

table.setmetatableindex(digits.dflt,      function(t,k) return rawget(t,"dflt") end)
table.setmetatableindex(symbols.dflt,     function(t,k) return rawget(t,"dflt") end)
table.setmetatableindex(punctuation.dflt, function(t,k) return rawget(t,"dflt") end)

fonts.constructors.keys = {
    properties = {
        encodingbytes          = "number",
        embedding              = "number",
        cidinfo                = "table",
        format                 = "string",
        fontname               = "string",
        fullname               = "string",
        filename               = "filename",
        psname                 = "string",
        name                   = "string",
        virtualized            = "boolean",
        italic_correction      = "boolean",
        auto_italic_correction = "boolean",
        no_stackmath           = "boolean",
        noglyphnames           = "boolean",
        mode                   = "string",
        has_math               = "boolean",
        no_math_italics        = "boolean",
        no_text_italics        = "boolean",
        finalized              = "boolean",
    },
    parameters = {
        mathsize               = "scaledpoints",
        scriptpercentage       = "float",
        scriptscriptpercentage = "float",
        units                  = "cardinal",
        designsize             = "basepoints",
        expansion              = "table",
        protrusion             = "table",
        expand_factor          = "float",
        slant_factor           = "float",
        factor                 = "float",
        hfactor                = "float",
        vfactor                = "float",
        size                   = "scaledpoints",
        units                  = "scaledpoints",
        scaledpoints           = "scaledpoints",
        slant                  = "float",
        space                  = "scaledpoints",
        space_stretch          = "scaledpoints",
        space_shrink           = "scaledpoints",
        x_height               = "scaledpoints",
        quad                   = "scaledpoints",
        extra_space            = "scaledpoints",
        ascender               = "scaledpoints",
        descender              = "scaledpoints",
    },
}

--       parameters.expansion = {
--           stretch = tfmdata.stretch     or 0,
--           shrink  = tfmdata.shrink      or 0,
--           step    = tfmdata.step        or 0,
--           auto    = tfmdata.auto_expand or false,
--       }
--       parameters.protrusion = {
--           auto = auto_protrude
--       }

local function showtable(t,keys)
    if t then
        context.starttabulate { "|Tl|Tl|" }
        for k, v in table.sortedhash(keys) do
            context.NC()
            context(k)
            context.NC()
            local tk = t[k]
            if not tk then
                context("<unset>")
            elseif v == "filename" then
                context(file.basename(tk))
            elseif v == "boolean" then
                context(tostring(tk or false))
            elseif v == "scaledpoints" or v == "basepoints" then
                context(number.points(tk))
            elseif v == "table" then
                -- todo
                context("<table>")
            else
                context(tostring(tk))
            end
            context.NC()
            context.NR()
        end
        context.stoptabulate()
    end
end

function moduledata.fonts.show_properties()
    local tfmdata = fonts.hashes.identifiers[font.current()]
    showtable(tfmdata.properties,fonts.constructors.keys.properties)
end

function moduledata.fonts.show_parameters()
    local tfmdata = fonts.hashes.identifiers[font.current()]
    showtable(tfmdata.parameters,fonts.constructors.keys.parameters)
end

function moduledata.fonts.show_positional_features()
    local tfmdata = fonts.hashes.identifiers[font.current()]
    local resources = tfmdata.resources
    if resources then
        local features = resources.features
        if features then
            local gpos = features.gpos
            if gpos and next(gpos) then
                context.starttabulate { "|Tl|Tl|Tlp|" }
                for feature, scripts in table.sortedpairs(gpos) do
                    for script, languages in table.sortedpairs(scripts) do
                        context.NC()
                        context(feature)
                        context.NC()
                        context(script)
                        context.NC()
                        context(table.concat(table.sortedkeys(languages)," "))
                        context.NC()
                        context.NR()
                    end
                end
                context.stoptabulate()
            else
                context("no entries")
                context.par()
            end
        end
    end
end

local dynamics = true

function moduledata.fonts.show_substitution_features()
    local tfmdata = fonts.hashes.identifiers[font.current()]
    local resources = tfmdata.resources
    if resources then
        local features = resources.features
        if features then
            local gsub = features.gsub
            if gsub then
                local makes_sense = { }
                for feature, scripts in table.sortedpairs(gsub) do
                    for script, languages in table.sortedpairs(scripts) do
                        for language in table.sortedpairs(languages) do
                            local tag = string.format("dummy-%s-%s-%s",feature,script,language)
                            local fnt = string.format("file:%s*%s",file.basename(tfmdata.properties.filename),tag)
                            context.definefontfeature (
                                { tag },
                                {
                                    mode      = "node",
                                    script    = script,
                                    language  = language,
                                    [feature] = "yes"
                                }
                            )
                            if not dynamics then
                                context.definefont( { fnt }, { fnt } )
                            end
                            makes_sense[#makes_sense+1] = {
                                feature    = feature,
                                tag        = tag,
                                script     = script,
                                language   = language,
                                fontname   = fnt,
                            }
                        end
                    end
                end
                if #makes_sense > 0 then
                    context.starttabulate { "|Tl|Tl|Tl|p|" }
                    for i=1,#makes_sense do
                        local data     = makes_sense[i]
                        local script   = data.script
                        local language = data.language
                        context.NC()
                            context(data.feature)
                        context.NC()
                            context(script)
                        context.NC()
                            context(language)
                        context.NC()
                            if not dynamics then
                                context.startfont { data.fontname }
                            else
                                context.addff(data.tag)
                            end
                            context.verbatim(samples.lowercase  [script][language]) context.par()
                            context.verbatim(samples.uppercase  [script][language]) context.par()
                            context.verbatim(samples.digits     [script][language]) context.par()
                            context.verbatim(samples.punctuation[script][language])
                            context.verbatim(samples.symbols    [script][language])
                            if not dynamics then
                                context.stopfont()
                            end
                        context.NC()
                        context.NR()
                    end
                    context.stoptabulate()
                else
                    context("no entries")
                    context.par()
                end
            end
        end
    end
end

function moduledata.fonts.show_a_lot(title)

    if title == "" then title = false end

    if title then
        context.starttitle { title = title }
    end

    context.startsubject { title = "Properties" }
        moduledata.fonts.show_properties()
    context.stopsubject()

    context.startsubject { title = "Parameters" }
        moduledata.fonts.show_parameters()
    context.stopsubject()

    context.startsubject { title = "Positional features" }
        moduledata.fonts.show_positional_features()
    context.stopsubject()

    context.startsubject { title = "Substitution features" }
        moduledata.fonts.show_substitution_features()
    context.stopsubject()

    if title then
        context.stoptitle()
    end

end

\stopluacode

% todo: make a mtxrun --script --font <name> option

\continueifinputfile{s-fnt-35.mkiv}

\usemodule[art-01]

\setupbodyfont
  [cambria]

\starttext
    \ctxlua{moduledata.fonts.show_a_lot("Cambria")}
\stoptext