summaryrefslogtreecommitdiff
path: root/tex/context/base/font-log.lua
blob: 97cb4ff7c1a1fb670a3e35580c93a87adcbb673f (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
if not modules then modules = { } end modules ['font-log'] = {
    version   = 1.001,
    comment   = "companion to font-ini.mkiv",
    author    = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
    copyright = "PRAGMA ADE / ConTeXt Development Team",
    license   = "see context related readme files"
}

local next, format, lower, concat = next, string.format, string.lower, table.concat

local trace_defining = false  trackers.register("fonts.defining", function(v) trace_defining = v end)

fonts.logger = fonts.logger or { }

--[[ldx--
<p>The following functions are used for reporting about the fonts
used. The message itself is not that useful in regular runs but since
we now have several readers it may be handy to know what reader is
used for which font.</p>
--ldx]]--

function fonts.logger.save(tfmtable,source,specification) -- save file name in spec here ! ! ! ! ! !
    if tfmtable and specification and specification.specification then
        local name = lower(specification.name)
        if trace_defining and not fonts.used[name] then
            logs.report("define font","registering %s as %s (used: %s)",file.basename(specification.name),source,file.basename(specification.filename))
        end
        specification.source = source
        fonts.loaded[lower(specification.specification)] = specification
     -- fonts.used[name] = source
        fonts.used[lower(specification.filename or specification.name)] = source
    end
end

function fonts.logger.report(complete)
    local t = { }
    for name, used in table.sortedhash(fonts.used) do
        if complete then
            t[#t+1] = used .. "->" .. file.basename(name)
        else
            t[#t+1] = file.basename(name)
        end
    end
    return t
end

function fonts.logger.format(name)
    return fonts.used[name] or "unknown"
end

statistics.register("loaded fonts", function()
    if next(fonts.used) then
        local t = fonts.logger.report()
        return (#t > 0 and format("%s files: %s",#t,concat(t,separator or " "))) or "none"
    else
        return nil
    end
end)