diff options
author | Context Git Mirror Bot <phg42.2a@gmail.com> | 2016-06-10 08:51:59 +0200 |
---|---|---|
committer | Context Git Mirror Bot <phg42.2a@gmail.com> | 2016-06-10 08:51:59 +0200 |
commit | b916cffae098b7bcfb8847fc269460271072d19d (patch) | |
tree | 9d603b5ebdf71405017aae01247dde5393bb74f7 /tex/context/base/mkiv/grph-mem.lua | |
parent | be735a865e2bdc6b7ac57161a24e4911741024f1 (diff) | |
download | context-b916cffae098b7bcfb8847fc269460271072d19d.tar.gz |
2016-06-10 08:15:00
Diffstat (limited to 'tex/context/base/mkiv/grph-mem.lua')
-rw-r--r-- | tex/context/base/mkiv/grph-mem.lua | 73 |
1 files changed, 42 insertions, 31 deletions
diff --git a/tex/context/base/mkiv/grph-mem.lua b/tex/context/base/mkiv/grph-mem.lua index b1ca1a15d..bb48ae8d5 100644 --- a/tex/context/base/mkiv/grph-mem.lua +++ b/tex/context/base/mkiv/grph-mem.lua @@ -15,53 +15,52 @@ if not modules then modules = { } end modules ['grph-mem'] = { -- \externalfigure[memstream:///t:/sources/cow.pdf] -- \externalfigure[memstream:///whatever] +local gsub = string.gsub + local report = logs.reporter("memstream") +local trace = false trackers.register ("graphics.memstreams", function(v) trace = v end) local data = { } -local trace = false - local opened = { } -function resolvers.finders.memstream(specification) - local name = specification.path - local identifier = data[name] - if identifier then +local function setmemstream(name,stream,once) + if once and data[name] then if trace then - report("reusing %a",identifier) + report("not overloading %a",name) -- end - return identifier + return data[name] end - local stream = io.loaddata(name) - if not stream or stream == "" then - return resolvers.finders.notfound() - end - local memstream, identifier = epdf.openMemStream(stream,#stream,original) + local memstream, identifier = epdf.openMemStream(stream,#stream,name) if not identifier then - report("invalid %a",name) + report("no valid stream %a",name) identifier = "invalid-memstream" elseif trace then - report("using %a",identifier) + report("setting %a with identifier %a",name,identifier) end data [name] = identifier opened[name] = memstream return identifier end -function resolvers.setmemstream(name,stream,once) - if once and data[name] then +resolvers.setmemstream = setmemstream + +function resolvers.finders.memstream(specification) + local name = specification.path + local identifier = data[name] + if identifier then if trace then - report("not overloading %a",name) -- + report("reusing %a with identifier %a",name,identifier) end - return + return identifier end - local memstream, identifier = epdf.openMemStream(stream,#stream,name) - if not identifier then - report("invalid %a",name) - identifier = "invalid-memstream" - elseif trace then - report("setting %a as %a",name,identifier) + 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 - data [name] = identifier - opened[name] = memstream end local flush = { } @@ -83,12 +82,24 @@ luatex.registerpageactions(function() end 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 + if name then + local base = gsub(name,"^memstream:///","") + if base ~= name then + local identifier = data[base] + if identifier then + if trace then + report("requested %a has identifier %s",name,identifier) + end + specification.status.status = 1 + specification.used.fullname = name + else + if trace then + report("requested %a is not found",name) + end + end + end end end |