summaryrefslogtreecommitdiff
path: root/tex/context/base/mkiv/grph-mem.lua
diff options
context:
space:
mode:
authorHans Hagen <pragma@wxs.nl>2018-06-24 21:49:41 +0200
committerContext Git Mirror Bot <phg42.2a@gmail.com>2018-06-24 21:49:41 +0200
commit00e28123f9c3e7393ea0a49052bc0a3b91a0db4f (patch)
tree7fecbc23e4f5a783d6d26d58edaf0481d4a17feb /tex/context/base/mkiv/grph-mem.lua
parenta80891cbf45f9705865ea2774b4e1abdcd36dbf9 (diff)
downloadcontext-00e28123f9c3e7393ea0a49052bc0a3b91a0db4f.tar.gz
2018-06-24 18:36:00
Diffstat (limited to 'tex/context/base/mkiv/grph-mem.lua')
-rw-r--r--tex/context/base/mkiv/grph-mem.lua164
1 files changed, 120 insertions, 44 deletions
diff --git a/tex/context/base/mkiv/grph-mem.lua b/tex/context/base/mkiv/grph-mem.lua
index bb48ae8d5..ff3548350 100644
--- a/tex/context/base/mkiv/grph-mem.lua
+++ b/tex/context/base/mkiv/grph-mem.lua
@@ -20,67 +20,143 @@ local gsub = string.gsub
local report = logs.reporter("memstream")
local trace = false trackers.register ("graphics.memstreams", function(v) trace = v end)
local data = { }
-local opened = { }
-local function setmemstream(name,stream,once)
- if once and data[name] then
+if pdfe then
+
+ local function setmemstream(name,stream,once)
+ if once and data[name] then
+ if trace then
+ report("not overloading %a",name) --
+ end
+ return data[name]
+ end
+ local kind = figures.guessfromstring(stream)
+ local identifier = false
+ if kind == "pdf" then
+ identifier = pdfe.new(stream,#stream,name)
+ if not identifier then
+ report("no valid pdf stream %a",name)
+ elseif trace then
+ report("setting %a with identifier %a",name,identifier)
+ end
+ else
+ identifier = "m_k_i_v_memstream_" .. name .. "." .. kind
+ io.savedata(identifier,stream)
+ end
+ if not identifier then
+ identifier = "invalid-memstream"
+ end
+ data[name] = identifier
+ return identifier
+ end
+
+ resolvers.setmemstream = setmemstream
+
+ function resolvers.finders.memstream(specification)
+ local name = specification.path
+ local identifier = data[name]
+ if identifier then
+ if trace then
+ report("reusing %a with identifier %a",name,identifier)
+ end
+ return identifier
+ end
+ local stream = io.loaddata(name)
+ if stream and stream ~= "" then
+ return setmemstream(name,stream)
+ end
if trace then
- report("not overloading %a",name) --
+ report("no valid memstream %a",name)
end
- return data[name]
+ return resolvers.finders.notfound()
end
- local memstream, identifier = epdf.openMemStream(stream,#stream,name)
- if not identifier then
- report("no valid stream %a",name)
- identifier = "invalid-memstream"
- elseif trace then
- report("setting %a with identifier %a",name,identifier)
+
+ local flush = { }
+
+ function resolvers.resetmemstream(name,afterpage)
+ if afterpage then
+ flush[#flush+1] = name
+ end
end
- data [name] = identifier
- opened[name] = memstream
- return identifier
-end
-resolvers.setmemstream = setmemstream
+ luatex.registerpageactions(function()
+ if #flush > 0 then
+ for i=1,#flush do
+ local identifier = data[name]
+ if identifier then
+ os.remove(identifier)
+ data[name] = nil
+ end
+ end
+ flush = { }
+ end
+ end)
+
+else
-function resolvers.finders.memstream(specification)
- local name = specification.path
- local identifier = data[name]
- if identifier then
- if trace then
- report("reusing %a with identifier %a",name,identifier)
+ local opened = { }
+
+ local function setmemstream(name,stream,once)
+ if once and data[name] then
+ if trace then
+ report("not overloading %a",name) --
+ end
+ return data[name]
end
+ local memstream, identifier = epdf.openMemStream(stream,#stream,name)
+ if not identifier then
+ report("no valid stream %a",name)
+ identifier = "invalid-memstream"
+ elseif trace then
+ report("setting %a with identifier %a",name,identifier)
+ end
+ data [name] = identifier
+ opened[name] = memstream
return identifier
end
- local stream = io.loaddata(name)
- if not stream or stream == "" then
- if trace then
- report("no valid file %a",name)
+
+ resolvers.setmemstream = setmemstream
+
+ function resolvers.finders.memstream(specification)
+ local name = specification.path
+ local identifier = data[name]
+ if identifier then
+ if trace then
+ report("reusing %a with identifier %a",name,identifier)
+ end
+ return identifier
+ end
+ local stream = io.loaddata(name)
+ if not stream or stream == "" then
+ if trace then
+ report("no valid file %a",name)
+ end
+ return resolvers.finders.notfound()
+ else
+ return setmemstream(name,stream)
end
- return resolvers.finders.notfound()
- else
- return setmemstream(name,stream)
end
-end
-local flush = { }
+ local flush = { }
-function resolvers.resetmemstream(name,afterpage)
- if afterpage then
- flush[#flush+1] = name
- else
- opened[name] = nil
+ function resolvers.resetmemstream(name,afterpage)
+ if afterpage then
+ flush[#flush+1] = name
+ else
+ opened[name] = nil
+ end
end
-end
-luatex.registerpageactions(function()
- if #flush > 0 then
- for i=1,#flush do
- opened[flush[i]] = nil -- we keep of course data[name] because of reuse
+ luatex.registerpageactions(function()
+ if #flush > 0 then
+ for i=1,#flush do
+ opened[flush[i]] = nil -- we keep of course data[name] because of reuse
+ end
+ flush = { }
end
- flush = { }
- end
-end)
+ end)
+
+end
figures.identifiers.list[#figures.identifiers.list+1] = function(specification)
local name = specification.request.name