lpdf-eng.lua /size: 3040 b    last modification: 2021-10-28 13:50
1if not modules then modules = { } end modules ['lpdf-eng'] = {
2    version   = 1.001,
3    optimize  = true,
4    comment   = "companion to lpdf-ini.mkiv",
5    author    = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
6    copyright = "PRAGMA ADE / ConTeXt Development Team",
7    license   = "see context related readme files"
8}
9
10-- Here we plug in the regular luatex image handler. The low level module itself
11-- is hidden from the user.
12
13local codeinjections = backends.pdf.codeinjections
14local imgnew         = img.new
15
16function codeinjections.newimage(specification)
17    if type(specification) == "table" then
18        specification.kind = nil
19    end
20    return imgnew(specification)
21end
22
23codeinjections.copyimage  = img.copy
24codeinjections.scanimage  = img.scan
25codeinjections.embedimage = img.immediatewrite
26codeinjections.wrapimage  = img.node
27
28-- We cannot nil the img table because the backend code explicitly accesses the
29-- new field when dealing with virtual characters. I should patch luatex for that
30-- and maybe I will. So no:
31--
32-- img = nil
33--
34-- We keep the low level img.new function but make the rest kind of unseen. At some
35-- point the other ones will be gone and one has to use the images.* wrappers.
36
37local unpack = unpack
38local sortedkeys = table.sortedkeys
39local context = context
40
41img = table.setmetatableindex (
42    {
43        new                  = images.create,
44    },
45    {
46     -- new                  = images.create,
47        scan                 = images.scan,
48        copy                 = images.copy,
49        node                 = images.wrap,
50        write                = function(specification) context(images.wrap(specification)) end,
51        immediatewrite       = images.embed,
52        immediatewriteobject = function() end, -- not upported, experimental anyway
53        boxes                = function() return sortedkeys(images.sizes) end,
54        fields               = function() return images.keys end,
55        types                = function() return { unpack(images.types,0,#images.types) } end,
56    }
57)
58
59--
60
61do
62
63    local function prepare(driver)
64        if not environment.initex then
65            -- install new functions in pdf namespace
66            updaters.apply("backend.update.pdf")
67            -- install new functions in lpdf namespace
68            updaters.apply("backend.update.lpdf")
69            -- adapt existing shortcuts to lpdf namespace
70            updaters.apply("backend.update.tex")
71            -- adapt existing shortcuts to tex namespace
72            updaters.apply("backend.update")
73            --
74        end
75    end
76
77    local function outputfilename(driver)
78        if not filename then
79            filename = addsuffix(tex.jobname,"pdf")
80        end
81        return filename
82    end
83
84    drivers.install {
85        name     = "pdf",
86        flushers = {
87            -- nothing here
88        },
89        actions  = {
90            convert        = drivers.converters.engine,
91            outputfilename = outputfilename,
92            prepare        = prepare,
93        },
94    }
95
96end
97
98