diff options
Diffstat (limited to 'Master/texmf-dist/tex/context/base/mlib-pdf.lua')
-rw-r--r-- | Master/texmf-dist/tex/context/base/mlib-pdf.lua | 75 |
1 files changed, 49 insertions, 26 deletions
diff --git a/Master/texmf-dist/tex/context/base/mlib-pdf.lua b/Master/texmf-dist/tex/context/base/mlib-pdf.lua index 8000d5a282e..7a23ba94772 100644 --- a/Master/texmf-dist/tex/context/base/mlib-pdf.lua +++ b/Master/texmf-dist/tex/context/base/mlib-pdf.lua @@ -64,14 +64,24 @@ function metapost.convert(result, trialrun, flusher, multipass, askedfig) return true -- done end -metapost.flushers = { } +metapost.flushers = { } metapost.flushers.pdf = { } -local savedliterals = nil +-- \def\MPLIBtoPDF#1{\ctxlua{metapost.flushliteral(#1)}} + +local savedliterals = nil -- needs checking local mpsliteral = nodes.pool.register(node.new("whatsit",8)) -- pdfliteral -function metapost.flushliteral(d) -- \def\MPLIBtoPDF#1{\ctxlua{metapost.flush_literal(#1)}} +local pdfliteral = function(s) + local literal = copy_node(mpsliteral) + literal.data = s + return literal +end + +local experiment = true -- uses context(node) that already does delayed nodes + +function metapost.flushliteral(d) if savedliterals then local literal = copy_node(mpsliteral) literal.data = savedliterals[d] @@ -88,13 +98,17 @@ end function metapost.flushers.pdf.comment(message) if message then message = format("%% mps graphic %s: %s", metapost.n, message) - if savedliterals then - local last = #savedliterals + 1 - savedliterals[last] = message - context.MPLIBtoPDF(last) + if experiment then + context(pdfliteral(message)) else - savedliterals = { message } - context.MPLIBtoPDF(1) + if savedliterals then + local last = #savedliterals + 1 + savedliterals[last] = message + context.MPLIBtoPDF(last) + else + savedliterals = { message } + context.MPLIBtoPDF(1) + end end end end @@ -115,20 +129,24 @@ end function metapost.flushers.pdf.flushfigure(pdfliterals) -- table if #pdfliterals > 0 then pdfliterals = concat(pdfliterals,"\n") - if savedliterals then - local last = #savedliterals + 1 - savedliterals[last] = pdfliterals - context.MPLIBtoPDF(last) + if experiment then + context(pdfliteral(pdfliterals)) else - savedliterals = { pdfliterals } - context.MPLIBtoPDF(1) + if savedliterals then + local last = #savedliterals + 1 + savedliterals[last] = pdfliterals + context.MPLIBtoPDF(last) + else + savedliterals = { pdfliterals } + context.MPLIBtoPDF(1) + end end end end function metapost.flushers.pdf.textfigure(font,size,text,width,height,depth) -- we could save the factor text = gsub(text,".","\\hbox{%1}") -- kerning happens in metapost (i have to check if this is true for mplib) - context.MPLIBtextext(font,size,text,0,-number.dimenfactors.bp*depth) + context.MPtextext(font,size,text,0,-number.dimenfactors.bp*depth) end local bend_tolerance = 131/65536 @@ -256,9 +274,10 @@ function metapost.flush(result,flusher,askedfig) local figures = result.fig if figures then flusher = flusher or metapost.flushers.pdf - local resetplugins = metapost.resetplugins or ignore - local processplugins = metapost.processplugins or ignore - local pluginactions = metapost.pluginactions or ignore + local resetplugins = metapost.resetplugins or ignore -- before figure + local processplugins = metapost.processplugins or ignore -- each object + local synchronizeplugins = metapost.synchronizeplugins or ignore + local pluginactions = metapost.pluginactions or ignore -- before / after local startfigure = flusher.startfigure local stopfigure = flusher.stopfigure local flushfigure = flusher.flushfigure @@ -267,7 +286,7 @@ function metapost.flush(result,flusher,askedfig) local figure = figures[f] local objects = getobjects(result,figure,f) local fignum = figure:charcode() or 0 - if not askedfig or (askedfig == fignum) then + if askedfig == "direct" or askedfig == "all" or askedfig == fignum then local t = { } local miterlimit, linecap, linejoin, dashed = -1, -1, -1, false local bbox = figure:boundingbox() @@ -284,8 +303,7 @@ function metapost.flush(result,flusher,askedfig) startfigure(fignum,llx,lly,urx,ury,"begin",figure) t[#t+1] = "q" if objects then - resetplugins() -- we should move the colorinitializer here - t[#t+1] = metapost.colorinitializer() + resetplugins(t) -- we should move the colorinitializer here for o=1,#objects do local object = objects[o] local objecttype = object.type @@ -309,6 +327,9 @@ function metapost.flush(result,flusher,askedfig) else -- we use an indirect table as we want to overload -- entries but this is not possible in userdata + -- + -- can be optimized if no path + -- local original = object local object = { } setmetatable(object, { @@ -416,7 +437,7 @@ function metapost.flush(result,flusher,askedfig) flushfigure(t) stopfigure("end") end - if askedfig then + if askedfig ~= "all" then break end end @@ -429,11 +450,11 @@ function metapost.parse(result,askedfig) if result then local figures = result.fig if figures then - local analyzeplugins = metapost.analyzeplugins + local analyzeplugins = metapost.analyzeplugins -- each object for f=1, #figures do local figure = figures[f] local fignum = figure:charcode() or 0 - if not askedfig or (askedfig == fignum) then + if askedfig == "direct" or askedfig == "all" or askedfig == fignum then local bbox = figure:boundingbox() local llx, lly, urx, ury = bbox[1], bbox[2], bbox[3], bbox[4] -- faster than unpack metapost.llx = llx @@ -452,7 +473,9 @@ function metapost.parse(result,askedfig) analyzeplugins(objects[o]) end end - break + if askedfig ~= "all" then + break + end end end end |