summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/context/base/grph-swf.lua
diff options
context:
space:
mode:
Diffstat (limited to 'Master/texmf-dist/tex/context/base/grph-swf.lua')
-rw-r--r--Master/texmf-dist/tex/context/base/grph-swf.lua82
1 files changed, 66 insertions, 16 deletions
diff --git a/Master/texmf-dist/tex/context/base/grph-swf.lua b/Master/texmf-dist/tex/context/base/grph-swf.lua
index e55454b52b5..88eed021a22 100644
--- a/Master/texmf-dist/tex/context/base/grph-swf.lua
+++ b/Master/texmf-dist/tex/context/base/grph-swf.lua
@@ -6,35 +6,85 @@ if not modules then modules = { } end modules ['grph-swf'] = {
license = "see context related readme files"
}
-local format = string.format
+local sub, format, match, byte = string.sub, string.format, string.match, string.byte
+local readstring, readnumber = io.readstring, io.readnumber
+local concat = table.concat
+local floor = math.floor
+local tonumber = tonumber
+local tobitstring = number.tobitstring
-local texsprint = tex.sprint
-local ctxcatcodes = tex.ctxcatcodes
-local pdfannotation = nodes.pdfannotation
+local todimen = number.todimen
+
+local nodeinjections = backends.nodeinjections
+
+local figures = figures
+local context = context
+
+local function getheader(name)
+ local f = io.open(name,"rb")
+ if not f then
+ return
+ end
+ local signature = readstring(f,3) -- F=uncompressed, C=compressed (zlib)
+ local version = readnumber(f,1)
+ local filelength = readnumber(f,-4)
+ local compressed = sub(signature,1,1) == "C"
+ local buffer
+ if compressed then
+ buffer = zlib.decompress(f:read('*a'))
+ else
+ buffer = f:read(20) -- ('*a')
+ end
+ f:close()
+ buffer = { match(buffer,"(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)") }
+ for i=1,9 do
+ buffer[i] = tobitstring(byte(buffer[i]))
+ end
+ local framebits = concat(buffer,"",1,9)
+ local n = tonumber(sub(framebits,1,5),2)
+ local frame = { } -- xmin xmax ymin ymax
+ local xmin = tonumber(sub(framebits,6, 5 + n),2)
+ local xmax = tonumber(sub(framebits,6 + 1*n,5 + 2*n),2)
+ local ymin = tonumber(sub(framebits,6 + 2*n,5 + 3*n),2)
+ local ymax = tonumber(sub(framebits,6 + 3*n,5 + 4*n),2)
+ return {
+ filename = name,
+ version = version,
+ filelength = filelength,
+ framerate = tonumber(byte(buffer[10]) * 256 + byte(buffer[11])),
+ framecount = tonumber(byte(buffer[12]) * 256 + byte(buffer[13])),
+ -- framebits = framebits,
+ compressed = compressed,
+ width = floor((xmax - xmin) / 20),
+ height = floor((ymax - ymin) / 20),
+ rectangle = {
+ xmin = xmin,
+ xmax = xmax,
+ ymin = ymin,
+ ymax = ymax,
+ }
+ }
+end
function figures.checkers.swf(data)
local dr, du, ds = data.request, data.used, data.status
- local width = (dr.width or figures.defaultwidth):todimen()
- local height = (dr.height or figures.defaultheight):todimen()
local foundname = du.fullname
+ local header = getheader(foundname)
+ local width, height = figures.applyratio(dr.width,dr.height,header.width,header.height)
dr.width, dr.height = width, height
du.width, du.height, du.foundname = width, height, foundname
- texsprint(ctxcatcodes,format("\\startfoundexternalfigure{%ssp}{%ssp}",width,height))
- local annot, preview, ref = backends.pdf.helpers.insertswf {
+ context.startfoundexternalfigure(todimen(width),todimen(height))
+ nodeinjections.insertswf {
foundname = foundname,
width = width,
height = height,
-- factor = number.dimenfactors.bp,
- -- display = dr.display,
- -- controls = dr.controls,
+ display = dr.display,
+ controls = dr.controls,
-- label = dr.label,
+ resources = dr.resources,
}
- -- node.write(pdfannotation(width,-height,0,annot()))
- texsprint(ctxcatcodes,format("\\pdfannot width %ssp height %ssp {%s}",width,height,annot())) -- brrrr
---~ if ref then -- wrong ! a direct ref should work
---~ texsprint(ctxcatcodes,format("\\smash{\\pdfrefximage%s\\relax}",ref)) -- brrrr
---~ end
- texsprint(ctxcatcodes,"\\stopfoundexternalfigure")
+ context.stopfoundexternalfigure()
return data
end