summaryrefslogtreecommitdiff
path: root/luaotfload-override.lua
blob: c047dad4f8d51fa3d6f20eed9a2bbade9c39cc46 (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
if not modules then modules = { } end modules ['luat-ovr'] = {
    version   = 2.2,
    comment   = "companion to luatex-*.tex",
    author    = "Khaled Hosny, Elie Roux, Philipp Gesang",
    copyright = "Luaotfload Development Team",
    license   = "GNU GPL v2"
}

local module_name = "luaotfload"

local texiowrite_nl = texio.write_nl
local stringformat  = string.format
local tableconcat   = table.concat
local type          = type

--[[doc--
We recreate the verbosity levels previously implemented in font-nms:

    ==========================================================
    lvl      arg  trace_loading  trace_search  suppress_output
    ----------------------------------------------------------
    (0)  ->  -q         ⊥              ⊥            ⊤
    (1)  ->  ∅          ⊥              ⊥            ⊥
    (2)  ->  -v         ⊤              ⊥            ⊥
    (>2) ->  -vv        ⊤              ⊤            ⊥
    ==========================================================

--doc]]--

local loglevel = 1 --- default
local logout   = "log"

local set_loglevel = function (n)
    if type(n) == "number" then
        loglevel = n
    end
end
logs.set_loglevel   = set_loglevel
logs.set_log_level  = set_loglevel --- accomodating lazy typists

local set_logout = function (s)
    if s == "stdout" then
        logout = "term"
    --else --- remains “log”
    end
end

logs.set_logout = set_logout

local log = function (category, fmt, ...)
    local res = { module_name, " |" }
    if category then res[#res+1] = " " .. category end
    if fmt      then res[#res+1] = ": " .. stringformat(fmt, ...) end
    texiowrite_nl(logout, tableconcat(res))
end

local stdout = function (category, fmt, ...)
    local res = { module_name, " |" }
    if category then res[#res+1] = " " .. category end
    if fmt      then res[#res+1] = ": " .. stringformat(fmt, ...) end
    texiowrite_nl(tableconcat(res))
end

local level_ids = { common  = 0, loading = 1, search  = 2 }

local names_report = function (mode, lvl, ...)
    if type(lvl) == "string" then
        lvl = level_ids[lvl]
    end
    if not lvl then lvl = 0 end

    if loglevel >= lvl then
        if mode == "log" then
            log (...)
        elseif mode == "both" then
            log (...)
            stdout (...)
        else
            stdout (...)
        end
    end
end

logs.names_report = names_report

--[[doc--

    Adobe Glyph List.
    -------------------------------------------------------------------

    Context provides a somewhat different font-age.lua from an unclear
    origin. Unfortunately, the file name it reads from is hard-coded
    in font-enc.lua, so we have to replace the entire table.

    This shouldn’t cause any complications. Due to its implementation
    the glyph list will be loaded upon loading a OTF or TTF for the
    first time during a TeX run. (If one sticks to TFM/OFM then it is
    never read at all.) For this reason we can install a metatable that
    looks up the file of our choosing and only falls back to the
    Context one in case it cannot be found.

--doc]]--

if next(fonts.encodings.agl) then
    print(next, fonts.encodings.agl)
    --- unnecessary because the file shouldn’t be loaded at this time
    --- but we’re just making sure
    fonts.encodings.agl = nil
    collectgarbage"collect"
end


fonts.encodings.agl = { }

setmetatable(fonts.encodings.agl, { __index = function (t, k)
    if k == "unicodes" then
        local glyphlist = resolvers.findfile"luaotfload-glyphlist.lua"
        if glyphlist then
            names_report("both", 0, "load", "loading the Adobe glyph list")
        else
            glyphlist = resolvers.findfile"font-age.lua"
            names_report("both", 0, "load", "loading the extended glyph list from ConTeXt")
        end
        local unicodes      = dofile(glyphlist)
        fonts.encodings.agl = { unicodes = unicodes }
        return unicodes
    else
        return nil
    end
end })

-- vim:tw=71:sw=4:ts=4:expandtab