lpdf-res.lua /size: 1392 b    last modification: 2020-07-01 14:35
1if not modules then modules = { } end modules ['lpdf-res'] = {
2    version   = 1.001,
3    comment   = "companion to lpdf-ini.mkiv",
4    author    = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
5    copyright = "PRAGMA ADE / ConTeXt Development Team",
6    license   = "see context related readme files"
7}
8
9local codeinjections           = backends.codeinjections
10
11local nuts                     = nodes.nuts
12local tonut                    = nodes.tonut
13
14local setwhd                   = nuts.setwhd
15local setlist                  = nuts.setlist
16
17local new_hlist                = nuts.pool.hlist
18
19local boxresources             = tex.boxresources
20local saveboxresource          = boxresources.save
21local useboxresource           = boxresources.use
22local getboxresourcedimensions = boxresources.getdimensions
23
24local pdfcollectedresources    = lpdf.collectedresources
25
26function codeinjections.registerboxresource(n,offset)
27    local r = saveboxresource(n,nil,pdfcollectedresources(),true,0,offset or 0) -- direct, todo: accept functions as attr/resources
28    return r
29end
30
31function codeinjections.restoreboxresource(index)
32    local hbox = new_hlist()
33    local list, wd, ht, dp = useboxresource(index)
34    setlist(hbox,tonut(list))
35    setwhd(hbox,wd,ht,dp)
36    return hbox -- so we return a nut !
37end
38
39function codeinjections.boxresourcedimensions(index)
40    return getboxresourcedimensions(index)
41end
42