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

-- todo

local format, join = string.format, table.concat
local sprint = tex.sprint

metapost = metapost or {}
metapost.defaultformat = "metafun"

function metapost.graphic(instance,mpsformat,str,preamble)
    local mpx = metapost.format(instance,mpsformat or metapost.defaultformat)
    metapost.graphic_base_pass(mpx,str,preamble)
end

function metapost.filterclippath(result)
    if result then
        local figures = result.fig
        if figures and #figures > 0 then
            local figure = figures[1]
            local objects = figure:objects()
            if objects then
                for o=1,#objects do
                    local object = objects[o]
                    if object.type == "start_clip" then
                        return join(metapost.flushnormalpath(object.path,{ }),"\n")
                    end
                end
            end
        end
    end
    return ""
end

statistics.register("metapost processing time", function()
    local n =  metapost.n
    if n > 0 then
        return format("%s seconds, loading: %s seconds, execution: %s seconds, n: %s",
            statistics.elapsedtime(metapost), statistics.elapsedtime(mplib), statistics.elapsedtime(metapost.exectime),n)
    else
        return nil
    end
end)