summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/context/base/mkiv/font-ldr.lua
blob: 175b4d0cc50e26eb5fcebeb855e89987db8af3f6 (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
if not modules then modules = { } end modules ['font-ldr'] = {
    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"
}

-- This module provides an experimental replacement for fontloader.to_table
-- but is not used that much.

local fields = fontloader.fields

if fields then

    local glyphfields

    local function get_glyphs(r)
        local t = { }
        local g = r.glyphs
        for i=1,r.glyphmax-1 do
            local gi = g[i]
            if gi then
                if not glyphfields then
                    glyphfields = fields(gi)
                end
                local h = { }
                for i=1,#glyphfields do
                    local s = glyphfields[i]
                    h[s] = gi[s]
                end
                t[i] = h
            end
        end
        return t
    end

    local function to_table(r)
        local f = fields(r)
        if f then
            local t = { }
            for i=1,#f do
                local fi = f[i]
                local ri = r[fi]
                if not ri then
                    -- skip
                elseif fi == "glyphs" then
                    t.glyphs = get_glyphs(r)
                elseif fi == "subfonts" then
                    t[fi] = ri
                    ri.glyphs = get_glyphs(ri)
                else
                    t[fi] = r[fi]
                end
            end
            return t
        end
    end

    -- currently glyphs, subfont-glyphs and the main table are userdata

    function fonts.to_table(raw)
        return to_table(raw)
    end

else

    fonts.to_table = fontloader.to_table

end