summaryrefslogtreecommitdiff
path: root/tex/context/base/mlib-pdf.lua
diff options
context:
space:
mode:
authorMarius <mariausol@gmail.com>2012-10-19 01:20:13 +0300
committerMarius <mariausol@gmail.com>2012-10-19 01:20:13 +0300
commit69d2352af4b60929b37fc49f3bdb263977016244 (patch)
treedb5eb11398e345dfa23b4c4500fb93575d2afb7c /tex/context/base/mlib-pdf.lua
parentc18f7cbe51449a611ea1819fedd9a4ff18529b7d (diff)
downloadcontext-69d2352af4b60929b37fc49f3bdb263977016244.tar.gz
stable 2012.05.30 11:26
Diffstat (limited to 'tex/context/base/mlib-pdf.lua')
-rw-r--r--tex/context/base/mlib-pdf.lua93
1 files changed, 51 insertions, 42 deletions
diff --git a/tex/context/base/mlib-pdf.lua b/tex/context/base/mlib-pdf.lua
index 88f26e755..7a23ba947 100644
--- a/tex/context/base/mlib-pdf.lua
+++ b/tex/context/base/mlib-pdf.lua
@@ -11,41 +11,26 @@ local abs, sqrt, round = math.abs, math.sqrt, math.round
local setmetatable = setmetatable
local Cf, C, Cg, Ct, P, S, lpegmatch = lpeg.Cf, lpeg.C, lpeg.Cg, lpeg.Ct, lpeg.P, lpeg.S, lpeg.match
+local allocate = utilities.storage.allocate
+
local report_metapost = logs.reporter("metapost")
local mplib, context = mplib, context
-local allocate = utilities.storage.allocate
-
-local copy_node = node.copy
-local write_node = node.write
-
-metapost = metapost or { }
-local metapost = metapost
-
-metapost.flushers = metapost.flushers or { }
-local pdfflusher = { }
-metapost.flushers.pdf = pdfflusher
+local copy_node = node.copy
+local write_node = node.write
-metapost.multipass = false
-metapost.n = 0
-metapost.optimize = true -- false
+metapost = metapost or { }
+local metapost = metapost
-local experiment = true -- uses context(node) that already does delayed nodes
-
-local savedliterals = nil -- needs checking
-local mpsliteral = nodes.pool.register(node.new("whatsit",nodes.whatsitcodes.pdfliteral)) -- pdfliteral.mode = 1
-
-local pdfliteral = function(s)
- local literal = copy_node(mpsliteral)
- literal.data = s
- return literal
-end
+metapost.multipass = false
+metapost.n = 0
+metapost.optimize = true -- false
--- Because in MKiV we always have two passes, we save the objects. When an extra
--- mp run is done (due to for instance texts identifier in the parse pass), we
--- get a new result table and the stored objects are forgotten. Otherwise they
--- are reused.
+--~ Because in MKiV we always have two passes, we save the objects. When an extra
+--~ mp run is done (due to for instance texts identifier in the parse pass), we
+--~ get a new result table and the stored objects are forgotten. Otherwise they
+--~ are reused.
local function getobjects(result,figure,f)
if metapost.optimize then
@@ -79,6 +64,23 @@ function metapost.convert(result, trialrun, flusher, multipass, askedfig)
return true -- done
end
+metapost.flushers = { }
+metapost.flushers.pdf = { }
+
+-- \def\MPLIBtoPDF#1{\ctxlua{metapost.flushliteral(#1)}}
+
+local savedliterals = nil -- needs checking
+
+local mpsliteral = nodes.pool.register(node.new("whatsit",8)) -- pdfliteral
+
+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)
@@ -93,7 +95,7 @@ function metapost.flushreset() -- will become obsolete and internal
savedliterals = nil
end
-function pdfflusher.comment(message)
+function metapost.flushers.pdf.comment(message)
if message then
message = format("%% mps graphic %s: %s", metapost.n, message)
if experiment then
@@ -111,20 +113,20 @@ function pdfflusher.comment(message)
end
end
-function pdfflusher.startfigure(n,llx,lly,urx,ury,message)
+function metapost.flushers.pdf.startfigure(n,llx,lly,urx,ury,message)
savedliterals = nil
metapost.n = metapost.n + 1
context.startMPLIBtoPDF(llx,lly,urx,ury)
- if message then pdfflusher.comment(message) end
+ if message then metapost.flushers.pdf.comment(message) end
end
-function pdfflusher.stopfigure(message)
- if message then pdfflusher.comment(message) end
+function metapost.flushers.pdf.stopfigure(message)
+ if message then metapost.flushers.pdf.comment(message) end
context.stopMPLIBtoPDF()
context.MPLIBflushreset() -- maybe just at the beginning
end
-function pdfflusher.flushfigure(pdfliterals) -- table
+function metapost.flushers.pdf.flushfigure(pdfliterals) -- table
if #pdfliterals > 0 then
pdfliterals = concat(pdfliterals,"\n")
if experiment then
@@ -142,7 +144,7 @@ function pdfflusher.flushfigure(pdfliterals) -- table
end
end
-function pdfflusher.textfigure(font,size,text,width,height,depth) -- we could save the factor
+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.MPtextext(font,size,text,0,-number.dimenfactors.bp*depth)
end
@@ -271,7 +273,7 @@ function metapost.flush(result,flusher,askedfig)
if result then
local figures = result.fig
if figures then
- flusher = flusher or pdfflusher
+ flusher = flusher or metapost.flushers.pdf
local resetplugins = metapost.resetplugins or ignore -- before figure
local processplugins = metapost.processplugins or ignore -- each object
local synchronizeplugins = metapost.synchronizeplugins or ignore
@@ -288,7 +290,7 @@ function metapost.flush(result,flusher,askedfig)
local t = { }
local miterlimit, linecap, linejoin, dashed = -1, -1, -1, false
local bbox = figure:boundingbox()
- local llx, lly, urx, ury = bbox[1], bbox[2], bbox[3], bbox[4]
+ local llx, lly, urx, ury = bbox[1], bbox[2], bbox[3], bbox[4] -- faster than unpack
metapost.llx = llx
metapost.lly = lly
metapost.urx = urx
@@ -449,17 +451,24 @@ function metapost.parse(result,askedfig)
local figures = result.fig
if figures then
local analyzeplugins = metapost.analyzeplugins -- each object
- for f=1,#figures do
+ for f=1, #figures do
local figure = figures[f]
local fignum = figure:charcode() or 0
if askedfig == "direct" or askedfig == "all" or askedfig == fignum then
local bbox = figure:boundingbox()
- metapost.llx = bbox[1]
- metapost.lly = bbox[2]
- metapost.urx = bbox[3]
- metapost.ury = bbox[4]
+ local llx, lly, urx, ury = bbox[1], bbox[2], bbox[3], bbox[4] -- faster than unpack
+ metapost.llx = llx
+ metapost.lly = lly
+ metapost.urx = urx
+ metapost.ury = ury
local objects = getobjects(result,figure,f)
if objects then
+ -- for o=1,#objects do
+ -- local object = objects[o]
+ -- local prescript = object.prescript
+ -- if prescript then
+ -- analyzeplugins(object)
+ -- end
for o=1,#objects do
analyzeplugins(objects[o])
end