summaryrefslogtreecommitdiff
path: root/tex/context/base/mkiv/grph-mem.lua
diff options
context:
space:
mode:
authorContext Git Mirror Bot <phg42.2a@gmail.com>2016-06-08 11:39:00 +0200
committerContext Git Mirror Bot <phg42.2a@gmail.com>2016-06-08 11:39:00 +0200
commit641b8d0802ead673334ad7048c701238e6c8c81e (patch)
tree9ab587f935e96f6eb24b739983e319541b983ee5 /tex/context/base/mkiv/grph-mem.lua
parentd78828b55508aae49922032ebd9117804a940f73 (diff)
downloadcontext-641b8d0802ead673334ad7048c701238e6c8c81e.tar.gz
2016-06-08 10:54:00
Diffstat (limited to 'tex/context/base/mkiv/grph-mem.lua')
-rw-r--r--tex/context/base/mkiv/grph-mem.lua68
1 files changed, 68 insertions, 0 deletions
diff --git a/tex/context/base/mkiv/grph-mem.lua b/tex/context/base/mkiv/grph-mem.lua
new file mode 100644
index 000000000..80a6bfdbf
--- /dev/null
+++ b/tex/context/base/mkiv/grph-mem.lua
@@ -0,0 +1,68 @@
+if not modules then modules = { } end modules ['grph-mem'] = {
+ version = 1.001,
+ comment = "companion to grph-inc.mkiv",
+ author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
+ copyright = "PRAGMA ADE / ConTeXt Development Team",
+ license = "see context related readme files"
+}
+
+-- very experimental and likely to change
+--
+-- \startluacode
+-- figures.setmemstream("whatever",io.loaddata("t:/sources/cow.pdf"))
+-- \stopluacode
+--
+-- \externalfigure[memstream:///t:/sources/cow.pdf]
+-- \externalfigure[memstream:///whatever]
+
+local report = logs.reporter("memstream")
+local data = { }
+local trace = false
+
+function resolvers.finders.memstream(specification)
+ local original = specification.original
+ local identifier = data[original]
+ if identifier then
+ if trace then
+ report("reusing %a",identifier)
+ end
+ return identifier
+ end
+ local stream = io.loaddata(specification.path)
+ if not stream or stream == "" then
+ return resolvers.finders.notfound()
+ end
+ local memstream = { epdf.openMemStream(stream,#stream,original) }
+ local identifier = memstream[2]
+ if not identifier then
+ report("invalid %a",name)
+ identifier = "invalid-memstream"
+ elseif trace then
+ report("using %a",identifier)
+ end
+ data[original] = identifier
+ return identifier
+end
+
+function resolvers.setmemstream(name,stream)
+ local original = "memstream:///" .. name
+ local memstream = { epdf.openMemStream(stream,#stream,original) }
+ local identifier = memstream[2]
+ if not identifier then
+ report("invalid %a",name)
+ identifier = "invalid-memstream"
+ elseif trace then
+ report("setting %a",identifier)
+ end
+ data[original] = identifier
+end
+
+figures.identifiers.list[#figures.identifiers.list+1] = function(specification)
+ local name = specification.request.name
+ if name and data[name] then
+ specification.status.status = 1
+ specification.used.fullname = name
+ end
+end
+
+figures.setmemstream = resolvers.setmemstream