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

if CONTEXTLMTXMODE > 0 then
    return
end

-- Here we plug in the regular luatex image handler. The low level module itself
-- is hidden from the user.

local codeinjections = backends.pdf.codeinjections
local imgnew         = img.new

function codeinjections.newimage(specification)
    if type(specification) == "table" then
        specification.kind = nil
    end
    return imgnew(specification)
end

codeinjections.copyimage  = img.copy
codeinjections.scanimage  = img.scan
codeinjections.embedimage = img.immediatewrite
codeinjections.wrapimage  = img.node

-- We cannot nil the img table because the backend code explicitly accesses the
-- new field when dealing with virtual characters. I should patch luatex for that
-- and maybe I will. So no:
--
-- img = nil
--
-- We keep the low level img.new function but make the rest kind of unseen. At some
-- point the other ones will be gone and one has to use the images.* wrappers.

local unpack = unpack
local sortedkeys = table.sortedkeys
local context = context

img = table.setmetatableindex (
    {
        new                  = images.create,
    },
    {
     -- new                  = images.create,
        scan                 = images.scan,
        copy                 = images.copy,
        node                 = images.wrap,
        write                = function(specification) context(images.wrap(specification)) end,
        immediatewrite       = images.embed,
        immediatewriteobject = function() end, -- not upported, experimental anyway
        boxes                = function() return sortedkeys(images.sizes) end,
        fields               = function() return images.keys end,
        types                = function() return { unpack(images.types,0,#images.types) } end,
    }
)

--

do

    local function prepare()
        if not environment.initex then
            -- install new functions in pdf namespace
            updaters.apply("backend.update.pdf")
            -- install new functions in lpdf namespace
            updaters.apply("backend.update.lpdf")
            -- adapt existing shortcuts to lpdf namespace
            updaters.apply("backend.update.tex")
            -- adapt existing shortcuts to tex namespace
            updaters.apply("backend.update")
            --
        end
    end

    local function outputfilename()
        if not filename then
            filename = addsuffix(tex.jobname,"pdf")
        end
        return filename
    end

    function lpdf.flushers()
        return { }
    end

    function lpdf.actions()
        return {
            convert        = tex.shipout,
            outputfilename = outputfilename,
            prepare        = prepare,
        }
    end

    drivers.install {
        name     = "pdf",
        flushers = lpdf.flushers(),
        actions  = lpdf.actions(),
    }

end