summaryrefslogtreecommitdiff
path: root/tex/context/base/lpdf-swf.lua
blob: fc06c96998c16079cb8ac76596546a978cb8af35 (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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
if not modules then modules = { } end modules ['lpdf-swf'] = {
    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"
}

-- The following code is based on tests by Luigi Scarso. His prototype
-- was using tex code. This is the official implementation.

local format = string.format

local backends, lpdf = backends, lpdf

local pdfconstant        = lpdf.constant
local pdfboolean         = lpdf.boolean
local pdfstring          = lpdf.string
local pdfunicode         = lpdf.unicode
local pdfdictionary      = lpdf.dictionary
local pdfarray           = lpdf.array
local pdfnull            = lpdf.null
local pdfreference       = lpdf.reference
local pdfimmediateobject = lpdf.immediateobject

local codeinjections     = backends.pdf.codeinjections
local nodeinjections     = backends.pdf.nodeinjections

local function insertswf(spec)

    local width, height, filename = spec.width, spec.height, spec.foundname

    local eref = codeinjections.embedfile(filename)

    local flash = pdfdictionary {
        Subtype   = pdfconstant("Flash"),
        Instances = pdfarray {
            pdfdictionary {
                Asset  = eref,
                Params = pdfdictionary {
                    Binding = pdfconstant("Foreground")
                }
            },
        },
    }

    local fref = pdfreference(pdfimmediateobject(tostring(flash)))

    local configuration = pdfdictionary {
        Configurations = pdfarray { fref },
        Assets         = pdfdictionary {
            Names = pdfarray {
                pdfstring(filename),
                eref,
            }
        },
    }

    local cref = pdfreference(pdfimmediateobject(tostring(configuration)))

    local activation = pdfdictionary {
        Activation = pdfdictionary {
            Type          = pdfconstant("RichMediaActivation"),
            Condition     = pdfconstant("PO"),
            Configuration = fref,
            Animation     = pdfdictionary {
                Subtype   = pdfconstant("Linear"),
                Speed     = 1,
                Playcount = 1,
            },
            Deactivation  = pdfdictionary {
                Type      = pdfconstant("RichMediaDeactivation"),
                Condition = pdfconstant("XD"),
            },
            Presentation  = pdfdictionary {
                PassContextClick = false,
                Style            = pdfconstant("Embedded"),
                Toolbar          = false,
                NavigationPane   = false,
                Transparent      = true,
                Window           = pdfdictionary {
                    Type     = pdfconstant("RichMediaWindow"),
                    Width    = pdfdictionary {
                        Default = 100,
                        Min     = 100,
                        Max     = 100,
                    },
                    Height   = pdfdictionary {
                        Default = 100,
                        Min     = 100,
                        Max     = 100,
                    },
                    Position = pdfdictionary {
                        Type    = pdfconstant("RichMediaPosition"),
                        HAlign  = pdfconstant("Near"),
                        VAlign  = pdfconstant("Near"),
                        HOffset = 0,
                        VOffset = 0,
                    }
                }
            }
        }
    }

    local aref = pdfreference(pdfimmediateobject(tostring(activation)))

    local annotation = pdfdictionary {
       Subtype           = pdfconstant("RichMedia"),
       RichMediaContent  = cref,
       RichMediaSettings = aref,
    }

    return annotation, nil, nil

end

function backends.pdf.nodeinjections.insertswf(spec)
    local annot, preview, ref = insertswf {
        foundname = spec.foundname,
        width     = spec.width,
        height    = spec.height,
    --  factor    = spec.factor,
    --  display   = spec.display,
    --  controls  = spec.controls,
    --  label     = spec.label,
    }
 -- texsprint(ctxcatcodes,format("\\pdfannot width %ssp height %ssp {%s}",spec.width,spec.height,annot())) -- brrrr
    node.write(pdfannotation(spec.width,spec.height,0,annotation()))
end