summaryrefslogtreecommitdiff
path: root/tex/context/base/font-lua.lua
blob: fe07dd38b679fb393047e66d8c50b0027e32f5c2 (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
if not modules then modules = { } end modules ['font-lua'] = {
    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 trace_defining = false  trackers.register("fonts.defining", function(v) trace_defining = v end)

local report_lua = logs.new("fonts","lua loading")

fonts.formats.lua = "lua"

local readers = fonts.tfm.readers

local function check_lua(specification,fullname)
    -- standard tex file lookup
    local fullname = resolvers.findfile(fullname) or ""
    if fullname ~= "" then
        local loader = loadfile(fullname)
        loader = loader and loader()
        return loader and loader(specification)
    end
end

function readers.lua(specification)
    local original = specification.specification
    if trace_defining then
        report_lua("using lua reader for '%s'",original)
    end
    local fullname, tfmtable = specification.filename or "", nil
    if fullname == "" then
        local forced = specification.forced or ""
        if forced ~= "" then
            tfmtable = check_lua(specification,specification.name .. "." .. forced)
        end
        if not tfmtable then
            tfmtable = check_lua(specification,specification.name)
        end
    else
        tfmtable = check_lua(specification,fullname)
    end
    return tfmtable
end