lpdf-mov.lua /size: 2589 b    last modification: 2021-10-28 13:50
1if not modules then modules = { } end modules ['lpdf-mov'] = {
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 format = string.format
10
11local lpdf               = lpdf
12local context            = context
13
14local nodeinjections     = backends.pdf.nodeinjections
15local pdfconstant        = lpdf.constant
16local pdfdictionary      = lpdf.dictionary
17local pdfarray           = lpdf.array
18local pdfborder          = lpdf.border
19
20-- We should actually make sure that inclusion only happens once. But this mechanism
21-- is dropped in pdf anyway so it will go away (read: mapped onto the newer mechanisms).
22
23function nodeinjections.insertmovie(specification)
24    -- managed in figure inclusion: width, height, factor, repeat, controls, preview, label, foundname
25    local width  = specification.width
26    local height = specification.height
27    local factor = specification.factor or number.dimenfactors.bp
28    local moviedict = pdfdictionary {
29        F      = specification.foundname or specification.file,
30        Aspect = pdfarray { factor * width, factor * height },
31        Poster = (specification.preview and true) or false,
32    }
33    local controldict = pdfdictionary {
34        ShowControls = (specification.controls and true) or false,
35        Mode         = (specification["repeat"] and pdfconstant("Repeat")) or nil,
36    }
37    local bs, bc = pdfborder()
38    local action = pdfdictionary {
39        Subtype = pdfconstant("Movie"),
40        Border  = bs,
41        C       = bc,
42        T       = format("movie %s",specification.tag or specification.label),
43        Movie   = moviedict,
44        A       = controldict,
45    }
46    context(nodeinjections.annotation(width,height,0,action())) -- test: context(...)
47end
48
49function nodeinjections.insertsound(specification)
50    local controldict = nil
51    if specification["repeat"] then
52        controldict = pdfdictionary {
53            Mode = pdfconstant("Repeat")
54        }
55    end
56    local sounddict = pdfdictionary {
57        F = specification.foundname or specification.file
58    }
59    local bs, bc = pdfborder()
60    local action = pdfdictionary {
61        Subtype = pdfconstant("Movie"),
62        Border  = bs,
63        C       = bc,
64        T       = format("sound %s",specification.tag or specification.label),
65        Movie   = sounddict,
66        A       = controldict,
67    }
68    context(nodeinjections.annotation(0,0,0,action())) -- test: context(...)
69end
70