summaryrefslogtreecommitdiff
path: root/tex/context/base/mkiv/mlib-run.lua
diff options
context:
space:
mode:
Diffstat (limited to 'tex/context/base/mkiv/mlib-run.lua')
-rw-r--r--tex/context/base/mkiv/mlib-run.lua105
1 files changed, 37 insertions, 68 deletions
diff --git a/tex/context/base/mkiv/mlib-run.lua b/tex/context/base/mkiv/mlib-run.lua
index fb1367151..bf7c8a796 100644
--- a/tex/context/base/mkiv/mlib-run.lua
+++ b/tex/context/base/mkiv/mlib-run.lua
@@ -57,6 +57,7 @@ metapost.showlog = false
metapost.lastlog = ""
metapost.texerrors = false
metapost.exectime = metapost.exectime or { } -- hack
+metapost.nofruns = 0
local mpxformats = { }
local mpxterminals = { }
@@ -100,6 +101,7 @@ local function executempx(mpx,data)
elseif type(data) == "table" then
data = prepareddata(data,collapse)
end
+ metapost.nofruns = metapost.nofruns + 1
return mpx:execute(data)
end
@@ -822,70 +824,13 @@ function metapost.directrun(formatname,filename,outputformat,astable,mpdata)
report_metapost("producing postscript and svg is no longer supported")
end
--- goodie
-
-function metapost.quickanddirty(mpxformat,data,incontext)
- if not data then
- mpxformat = "metafun"
- data = mpxformat
- end
- local code, bbox
- local flusher = {
- startfigure = function(n,llx,lly,urx,ury)
- code = { }
- bbox = { llx, lly, urx, ury }
- end,
- flushfigure = function(t)
- for i=1,#t do
- code[#code+1] = t[i]
- end
- end,
- stopfigure = function()
- end
- }
- local data = formatters["; beginfig(1) ;\n %s\n ; endfig ;"](data)
- metapost.process {
- mpx = mpxformat,
- flusher = flusher,
- askedfig = "all",
- useplugins = incontext,
- incontext = incontext,
- data = { data },
- }
- if code then
- return {
- bbox = bbox or { 0, 0, 0, 0 },
- code = code,
- data = data,
- }
- else
- report_metapost("invalid quick and dirty run")
- end
-end
-
-function metapost.getstatistics(memonly)
- if memonly then
- local n, m = 0, 0
- for name, mpx in next, mpxformats do
- n = n + 1
- m = m + mpx:statistics().memory
- end
- return n, m
- else
- local t = { }
- for name, mpx in next, mpxformats do
- t[name] = mpx:statistics()
- end
- return t
- end
-end
-
do
local result = { }
local width = 0
local height = 0
local depth = 0
+ local bbox = { 0, 0, 0, 0 }
local flusher = {
startfigure = function(n,llx,lly,urx,ury)
@@ -893,35 +838,59 @@ do
width = urx - llx
height = ury
depth = -lly
+ bbox = { llx, lly, urx, ury }
end,
flushfigure = function(t)
+ local r = #result
for i=1,#t do
- result[#result+1] = t[i]
+ r = r + 1
+ result[r] = t[i]
end
end,
stopfigure = function()
- end
+ end,
}
- function metapost.simple(format,code) -- even less than metapost.quickcanddirty
- local mpx = metapost.pushformat { } -- takes defaults
- -- metapost.setoutercolor(2)
+ function metapost.simple(format,code,useextensions)
+ local mpx = metapost.pushformat {
+ instance = "simplefun",
+ format = "metafun",
+ method = "double",
+ }
metapost.process {
mpx = mpx,
flusher = flusher,
askedfig = 1,
- useplugins = false,
- incontext = false,
+ useplugins = useextensions,
data = { "beginfig(1);", code, "endfig;" },
+ incontext = false,
}
metapost.popformat()
if result then
local stream = concat(result," ")
- result = nil -- cleanup
- return stream, width, height, depth
+ result = { } -- nil -- cleanup .. weird, we can have a dangling q
+ return stream, width, height, depth, bbox
else
- return "", 0, 0, 0
+ return "", 0, 0, 0, { 0, 0, 0, 0 }
end
end
end
+
+function metapost.getstatistics(memonly)
+ if memonly then
+ local n, m = 0, 0
+ for name, mpx in next, mpxformats do
+ n = n + 1
+ m = m + mpx:statistics().memory
+ end
+ return n, m
+ else
+ local t = { }
+ for name, mpx in next, mpxformats do
+ t[name] = mpx:statistics()
+ end
+ return t
+ end
+end
+