summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/context/base/lpdf-swf.lua
diff options
context:
space:
mode:
authorMojca Miklavec <mojca.miklavec@gmail.com>2012-05-14 17:38:55 +0000
committerMojca Miklavec <mojca.miklavec@gmail.com>2012-05-14 17:38:55 +0000
commit15995e10bfc68edf79970c4ea4fbb6678566c46e (patch)
tree2de7ca2a83f2d37ef043ad7429a5cb945bb79ddb /Master/texmf-dist/tex/context/base/lpdf-swf.lua
parentc9a39f716f1e5ec820ed3aab2c9aef25c5a9d730 (diff)
ConTeXt 2012.05.14 16:00
git-svn-id: svn://tug.org/texlive/trunk@26371 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/tex/context/base/lpdf-swf.lua')
-rw-r--r--Master/texmf-dist/tex/context/base/lpdf-swf.lua133
1 files changed, 118 insertions, 15 deletions
diff --git a/Master/texmf-dist/tex/context/base/lpdf-swf.lua b/Master/texmf-dist/tex/context/base/lpdf-swf.lua
index 04825446c3e..4bbec8dbe84 100644
--- a/Master/texmf-dist/tex/context/base/lpdf-swf.lua
+++ b/Master/texmf-dist/tex/context/base/lpdf-swf.lua
@@ -21,7 +21,7 @@ local pdfdictionary = lpdf.dictionary
local pdfarray = lpdf.array
local pdfnull = lpdf.null
local pdfreference = lpdf.reference
-local pdfimmediateobject = lpdf.immediateobject
+local pdfflushobject = lpdf.flushobject
local checkedkey = lpdf.checkedkey
@@ -30,6 +30,10 @@ local nodeinjections = backends.pdf.nodeinjections
local pdfannotation_node = nodes.pool.pdfannotation
+local trace_swf = false trackers.register("backend.swf", function(v) trace_swf = v end)
+
+local report_swf = logs.reporter("backend","swf")
+
local activations = {
click = "XA",
page = "PO",
@@ -56,7 +60,7 @@ local function insertswf(spec)
local resources = resources and parametersets[resources]
local display = display and parametersets[display]
- local controls = controls and parametersets[controls] -- not yet used
+ local controls = controls and parametersets[controls] -- not yet used
local preview = checkedkey(display,"preview","string")
local toolbar = checkedkey(display,"toolbar","boolean")
@@ -75,7 +79,7 @@ local function insertswf(spec)
},
}
- local flashreference = pdfreference(pdfimmediateobject(tostring(flash)))
+ local flashreference = pdfreference(pdfflushobject(flash))
local configuration = pdfdictionary {
Configurations = pdfarray { flashreference },
@@ -87,36 +91,103 @@ local function insertswf(spec)
},
}
+ -- todo: check op subpath figuur (relatief)
+
+ -- filename : ./test.swf (graphic)
+ -- root : .
+ -- prefix : ^%./
+ -- fullname : ./assets/whatever.xml
+ -- usedname : assets/whatever.xml
+ -- filename : assets/whatever.xml
+
+ local root = file.dirname(filename)
+ local relativepaths = nil
+ local paths = nil
+
if resources then
local names = configuration.Assets.Names
- local function add(filename)
- local filename = gsub(filename,"%./","")
- local embeddedreference = codeinjections.embedfile { file = filename, keepdir = true }
+ local prefix = false
+ if root ~= "" and root ~= "." then
+ prefix = format("^%s/",string.escapedpattern(root,true))
+ end
+ if prefix and trace_swf then
+ report_swf("using strip pattern '%s'",prefix)
+ end
+ local function add(fullname,strip)
+ local filename = gsub(fullname,"^%./","")
+ local usedname = strip and prefix and gsub(filename,prefix,"") or filename
+ local embeddedreference = codeinjections.embedfile {
+ file = fullname,
+ usedname = usedname,
+ keepdir = true,
+ }
names[#names+1] = pdfstring(filename)
names[#names+1] = embeddedreference
+ if trace_swf then
+ report_swf("embedding file '%s' as '%s'",fullname,usedname)
+ end
+ end
+ relativepaths = resources.relativepaths
+ if relativepaths then
+ if trace_swf then
+ report_swf("checking %s relative paths",#relativepaths)
+ end
+ for i=1,#relativepaths do
+ local relativepath = relativepaths[i]
+ if trace_swf then
+ report_swf("checking path '%s' relative to '%s'",relativepath,root)
+ end
+ local path = file.join(root == "" and "." or root,relativepath)
+ local files = dir.glob(path .. "/**")
+ for i=1,#files do
+ add(files[i],true)
+ end
+ end
end
- local paths = resources.paths
+ paths = resources.paths
if paths then
+ if trace_swf then
+ report_swf("checking absolute %s paths",#paths)
+ end
for i=1,#paths do
- local files = dir.glob(paths[i] .. "/**")
+ local path = paths[i]
+ if trace_swf then
+ report_swf("checking path '%s'",path)
+ end
+ local files = dir.glob(path .. "/**")
for i=1,#files do
- add(files[i])
+ add(files[i],false)
end
end
end
+ local relativefiles = resources.relativefiles
+ if relativefiles then
+ if trace_swf then
+ report_swf("checking %s relative files",#relativefiles)
+ end
+ for i=1,#relativefiles do
+ add(relativefiles[i],true)
+ end
+ end
local files = resources.files
if files then
+ if trace_swf then
+ report_swf("checking absolute %s files",#files)
+ end
for i=1,#files do
- add(files[i])
+ add(files[i],false)
end
end
end
- local configurationreference = pdfreference(pdfimmediateobject(tostring(configuration)))
+ local opendisplay = display and display.open or false
+ local closedisplay = display and display.close or false
+
+ local configurationreference = pdfreference(pdfflushobject(configuration))
local activation = pdfdictionary {
Type = pdfconstant("RichMediaActivation"),
- Condition = pdfconstant(activations[display.open]),
+ Condition = pdfconstant(activations[opendisplay]),
Configuration = flashreference,
Animation = pdfdictionary {
Subtype = pdfconstant("Linear"),
@@ -156,7 +227,7 @@ local function insertswf(spec)
local deactivation = pdfdictionary {
Type = pdfconstant("RichMediaDeactivation"),
- Condition = pdfconstant(deactivations[display.close]),
+ Condition = pdfconstant(deactivations[closedisplay]),
}
local richmediasettings = pdfdictionary {
@@ -165,15 +236,47 @@ local function insertswf(spec)
Deactivation = deactivation,
}
- local settingsreference = pdfreference(pdfimmediateobject(tostring(richmediasettings)))
+ local settingsreference = pdfreference(pdfflushobject(richmediasettings))
local appearance
if preview then
+ preview = gsub(preview,"%*",file.nameonly(filename))
local figure = codeinjections.getpreviewfigure { name = preview, width = width, height = height }
+ if relativepaths and not figure then
+ for i=1,#relativepaths do
+ local path = file.join(root == "" and "." or root,relativepaths[i])
+ if trace_swf then
+ report_swf("checking preview on relative path %s",path)
+ end
+ local p = file.join(path,preview)
+ figure = codeinjections.getpreviewfigure { name = p, width = width, height = height }
+ if figure then
+ preview = p
+ break
+ end
+ end
+ end
+ if paths and not figure then
+ for i=1,#paths do
+ local path = paths[i]
+ if trace_swf then
+ report_swf("checking preview on absolute path %s",path)
+ end
+ local p = file.join(path,preview)
+ figure = codeinjections.getpreviewfigure { name = p, width = width, height = height }
+ if figure then
+ preview = p
+ break
+ end
+ end
+ end
if figure then
local image = img.package(figure.status.private)
appearance = pdfdictionary { N = pdfreference(image.objnum) }
+ if trace_swf then
+ report_swf("using preview %s",preview)
+ end
end
end
@@ -199,5 +302,5 @@ function backends.pdf.nodeinjections.insertswf(spec)
-- factor = spec.factor,
-- label = spec.label,
}
- node.write(pdfannotation_node(spec.width,spec.height,0,annotation()))
+ context(pdfannotation_node(spec.width,spec.height,0,annotation())) -- the context wrap is probably also needed elsewhere
end