summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/context/base/lpdf-swf.lua
diff options
context:
space:
mode:
Diffstat (limited to 'Master/texmf-dist/tex/context/base/lpdf-swf.lua')
-rw-r--r--Master/texmf-dist/tex/context/base/lpdf-swf.lua216
1 files changed, 155 insertions, 61 deletions
diff --git a/Master/texmf-dist/tex/context/base/lpdf-swf.lua b/Master/texmf-dist/tex/context/base/lpdf-swf.lua
index 9fe0cd09fc8..04825446c3e 100644
--- a/Master/texmf-dist/tex/context/base/lpdf-swf.lua
+++ b/Master/texmf-dist/tex/context/base/lpdf-swf.lua
@@ -9,101 +9,195 @@ if not modules then modules = { } end modules ['lpdf-swf'] = {
-- 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 format, gsub = string.format, string.gsub
-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 backends, lpdf = backends, lpdf
-function backends.pdf.helpers.insertswf(spec)
+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 width, height, filename = spec.width, spec.height, spec.foundname
+local checkedkey = lpdf.checkedkey
- local eref = backends.codeinjections.embedfile(filename)
+local codeinjections = backends.pdf.codeinjections
+local nodeinjections = backends.pdf.nodeinjections
+
+local pdfannotation_node = nodes.pool.pdfannotation
+
+local activations = {
+ click = "XA",
+ page = "PO",
+ focus = "PV",
+}
+
+local deactivations = {
+ click = "XD",
+ page = "PI",
+ focus = "PC",
+}
+
+table.setmetatableindex(activations, function() return activations .click end)
+table.setmetatableindex(deactivations,function() return deactivations.focus end)
+
+local function insertswf(spec)
+
+ local width = spec.width
+ local height = spec.height
+ local filename = spec.foundname
+ local resources = spec.resources
+ local display = spec.display
+ local controls = spec.controls
+
+ local resources = resources and parametersets[resources]
+ local display = display and parametersets[display]
+ local controls = controls and parametersets[controls] -- not yet used
+
+ local preview = checkedkey(display,"preview","string")
+ local toolbar = checkedkey(display,"toolbar","boolean")
+
+ local embeddedreference = codeinjections.embedfile { file = filename }
local flash = pdfdictionary {
Subtype = pdfconstant("Flash"),
Instances = pdfarray {
pdfdictionary {
- Asset = eref,
+ Asset = embeddedreference,
Params = pdfdictionary {
- Binding = pdfconstant("Foreground")
+ Binding = pdfconstant("Background") -- Foreground makes swf behave erratic
}
},
},
}
- local fref = pdfreference(pdf.immediateobj(tostring(flash)))
+ local flashreference = pdfreference(pdfimmediateobject(tostring(flash)))
local configuration = pdfdictionary {
- Configurations = pdfarray { fref },
+ Configurations = pdfarray { flashreference },
Assets = pdfdictionary {
Names = pdfarray {
pdfstring(filename),
- eref,
+ embeddedreference,
}
},
}
- local cref = pdfreference(pdf.immediateobj(tostring(configuration)))
+ if resources then
+ local names = configuration.Assets.Names
+ local function add(filename)
+ local filename = gsub(filename,"%./","")
+ local embeddedreference = codeinjections.embedfile { file = filename, keepdir = true }
+ names[#names+1] = pdfstring(filename)
+ names[#names+1] = embeddedreference
+ end
+ local paths = resources.paths
+ if paths then
+ for i=1,#paths do
+ local files = dir.glob(paths[i] .. "/**")
+ for i=1,#files do
+ add(files[i])
+ end
+ end
+ end
+ local files = resources.files
+ if files then
+ for i=1,#files do
+ add(files[i])
+ end
+ end
+ end
+
+ local configurationreference = 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,
- }
+ Type = pdfconstant("RichMediaActivation"),
+ Condition = pdfconstant(activations[display.open]),
+ Configuration = flashreference,
+ Animation = pdfdictionary {
+ Subtype = pdfconstant("Linear"),
+ Speed = 1,
+ Playcount = 1,
+ },
+ Presentation = pdfdictionary {
+ PassContextClick = false,
+ Style = pdfconstant("Embedded"),
+ Toolbar = toolbar,
+ 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,
}
}
- }
+ },
+ -- View
+ -- Scripts
+ }
+
+ local deactivation = pdfdictionary {
+ Type = pdfconstant("RichMediaDeactivation"),
+ Condition = pdfconstant(deactivations[display.close]),
+ }
+
+ local richmediasettings = pdfdictionary {
+ Type = pdfconstant("RichMediaSettings"),
+ Activation = activation,
+ Deactivation = deactivation,
}
- local aref = pdfreference(pdf.immediateobj(tostring(activation)))
+ local settingsreference = pdfreference(pdfimmediateobject(tostring(richmediasettings)))
+
+ local appearance
+
+ if preview then
+ local figure = codeinjections.getpreviewfigure { name = preview, width = width, height = height }
+ if figure then
+ local image = img.package(figure.status.private)
+ appearance = pdfdictionary { N = pdfreference(image.objnum) }
+ end
+ end
local annotation = pdfdictionary {
- Subtype = pdfconstant("RichMedia"),
- RichMediaContent = cref,
- RichMediaSettings = aref,
+ Subtype = pdfconstant("RichMedia"),
+ RichMediaContent = configurationreference,
+ RichMediaSettings = settingsreference,
+ AP = appearance,
}
return annotation, nil, nil
end
+
+function backends.pdf.nodeinjections.insertswf(spec)
+ local annotation, preview, ref = insertswf {
+ foundname = spec.foundname,
+ width = spec.width,
+ height = spec.height,
+ display = spec.display,
+ controls = spec.controls,
+ resources = spec.resources,
+ -- factor = spec.factor,
+ -- label = spec.label,
+ }
+ node.write(pdfannotation_node(spec.width,spec.height,0,annotation()))
+end