From 0a5f59a9aa25b3de7e9659b39ad201aaf7eb5a67 Mon Sep 17 00:00:00 2001 From: Hans Hagen Date: Fri, 27 Sep 2019 20:24:34 +0200 Subject: 2019-09-27 18:10:00 --- tex/context/base/mkiv/mlib-run.lua | 105 +++++++++++++------------------------ 1 file changed, 37 insertions(+), 68 deletions(-) (limited to 'tex/context/base/mkiv/mlib-run.lua') 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 + -- cgit v1.2.3