summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/context/base/meta-pdf.lua
diff options
context:
space:
mode:
Diffstat (limited to 'Master/texmf-dist/tex/context/base/meta-pdf.lua')
-rw-r--r--Master/texmf-dist/tex/context/base/meta-pdf.lua71
1 files changed, 39 insertions, 32 deletions
diff --git a/Master/texmf-dist/tex/context/base/meta-pdf.lua b/Master/texmf-dist/tex/context/base/meta-pdf.lua
index 23f8d4de05d..b554810ee93 100644
--- a/Master/texmf-dist/tex/context/base/meta-pdf.lua
+++ b/Master/texmf-dist/tex/context/base/meta-pdf.lua
@@ -13,7 +13,10 @@ if not modules then modules = { } end modules ['meta-pdf'] = {
local concat, format, gsub, find, byte, gmatch, match = table.concat, string.format, string.gsub, string.find, string.byte, string.gmatch, string.match
local lpegmatch = lpeg.match
local round = math.round
-local texsprint, ctxcatcodes = tex.sprint, tex.ctxcatcodes
+
+local report_mptopdf = logs.reporter("graphics","mptopdf")
+
+local mplib, metapost, lpdf, context = mplib, metapost, lpdf, context
local pdfrgbcode = lpdf.rgbcode
local pdfcmykcode = lpdf.cmykcode
@@ -21,9 +24,12 @@ local pdfgraycode = lpdf.graycode
local pdfspotcode = lpdf.spotcode
local pdftransparencycode = lpdf.transparencycode
local pdffinishtransparencycode = lpdf.finishtransparencycode
+local pdfliteral = nodes.pool.pdfliteral
-mptopdf = { }
-mptopdf.n = 0
+metapost.mptopdf = metapost.mptopdf or { }
+local mptopdf = metapost.mptopdf
+
+mptopdf.nofconverted = 0
local m_path, m_stack, m_texts, m_version, m_date, m_shortcuts = { }, { }, { }, 0, 0, false
@@ -44,18 +50,16 @@ end
resetall()
--- todo: collect and flush packed using pdfliteral node injection but we're
--- in no hurry as this kind of conversion does not happen that often in mkiv
-
-local function pdfcode(str) -- could be a node.write instead
- texsprint(ctxcatcodes,"\\pdfliteral{",str,"}")
-end
+-- -- this does not work as expected (displacement of text)
+-- -- beware, needs another comment hack
+--
+-- local function pdfcode(str)
+-- context(pdfliteral(str))
+-- end
-local function texcode(str)
- texsprint(ctxcatcodes,str)
-end
+local pdfcode = context.pdfliteral
-function mpscode(str)
+local function mpscode(str)
if ignore_path then
pdfcode("h W n")
if extra_path_code then
@@ -92,11 +96,11 @@ local function flushpath(cmd)
local px, py = v[3], v[4] ; v[3], v[4] = (sy*(px-tx)-ry*(py-ty))/d, (sx*(py-ty)-rx*(px-tx))/d -- mpconcat(v[3],v[4])
local px, py = v[5], v[6] ; v[5], v[6] = (sy*(px-tx)-ry*(py-ty))/d, (sx*(py-ty)-rx*(px-tx))/d -- mpconcat(v[5],v[6])
end
- path[#path+1] = concat(v," ")
+ path[k] = concat(v," ")
end
else
for k=1,#m_stack_path do
- path[#path+1] = concat(m_stack_path[k]," ")
+ path[k] = concat(m_stack_path[k]," ")
end
end
flushconcat()
@@ -112,7 +116,7 @@ end
-- mp interface
-mps = mps or { }
+local mps = { }
function mps.creator(a, b, c)
m_version = tonumber(b)
@@ -127,7 +131,7 @@ function mps.newpath()
end
function mps.boundingbox(llx, lly, urx, ury)
- texcode("\\MPSboundingbox{" .. llx .. "}{" .. lly .. "}{" .. urx .. "}{" .. ury .. "}")
+ context.MPSboundingbox(llx,lly,urx,ury)
end
function mps.moveto(x,y)
@@ -144,10 +148,13 @@ end
function mps.rlineto(x,y)
local dx, dy = 0, 0
- if #m_stack_path > 0 then
- dx, dy = m_stack_path[#m_stack_path][1], m_stack_path[#m_stack_path][2]
+ local topofstack = #m_stack_path
+ if topofstack > 0 then
+ local msp = m_stack_path[topofstack]
+ dx = msp[1]
+ dy = msp[2]
end
- m_stack_path[#m_stack_path+1] = {dx,dy,"l"}
+ m_stack_path[topofstack+1] = {dx,dy,"l"}
end
function mps.translate(tx,ty)
@@ -221,7 +228,7 @@ function mps.textext(font, scale, str) -- old parser
dx, dy = m_stack_path[1][1], m_stack_path[1][2]
end
flushconcat()
- texcode("\\MPStextext{"..font.."}{"..scale.."}{"..str.."}{"..dx.."}{"..dy.."}")
+ context.MPStextext(font,scale,str,dx,dy)
resetpath()
end
@@ -304,9 +311,9 @@ end
-- not supported in mkiv , use mplib instead
-handlers[10] = function() logs.report("mptopdf","skipping special %s",10) end
-handlers[20] = function() logs.report("mptopdf","skipping special %s",20) end
-handlers[50] = function() logs.report("mptopdf","skipping special %s",50) end
+handlers[10] = function() report_mptopdf("skipping special %s",10) end
+handlers[20] = function() report_mptopdf("skipping special %s",20) end
+handlers[50] = function() report_mptopdf("skipping special %s",50) end
--end of not supported
@@ -320,7 +327,7 @@ function mps.setrgbcolor(r,g,b) -- extra check
if handler then
handler(s)
else
- logs.report("mptopdf","unknown special handler %s (1)",h)
+ report_mptopdf("unknown special handler %s (1)",h)
end
elseif r == 0.123 and g < 0.1 then
g, b = round(g*1000), round(b*1000)
@@ -330,7 +337,7 @@ function mps.setrgbcolor(r,g,b) -- extra check
if handler then
handler(s)
else
- logs.report("mptopdf","unknown special handler %s (2)",h)
+ report_mptopdf("unknown special handler %s (2)",h)
end
else
pdfcode(pdffinishtransparencycode())
@@ -505,7 +512,6 @@ local verbose = (
-- order matters in terms of speed / we could check for procset first
local captures_old = ( space + verbose + preamble )^0
---~ local captures_new = ( space + procset + preamble + verbose )^0
local captures_new = ( space + verbose + procset + preamble )^0
local function parse(m_data)
@@ -526,25 +532,26 @@ function mptopdf.convertmpstopdf(name)
if ok then
mps.colormodel = tex.attribute[a_colorspace]
statistics.starttiming(mptopdf)
- mptopdf.n = mptopdf.n + 1
- pdfcode(format("\\letterpercent\\space mptopdf begin: n=%s, file=%s",mptopdf.n,file.basename(name)))
+ mptopdf.nofconverted = mptopdf.nofconverted + 1
+ -- pdfcode(format("%% mptopdf begin: n=%s, file=%s",mptopdf.nofconverted,file.basename(name)))
+ pdfcode(format("\\letterpercent\\space mptopdf begin: n=%s, file=%s",mptopdf.nofconverted,file.basename(name)))
pdfcode("q 1 0 0 1 0 0 cm")
parse(m_data)
pdfcode(pdffinishtransparencycode())
pdfcode("Q")
+ -- pdfcode("% mptopdf end")
pdfcode("\\letterpercent\\space mptopdf end")
resetall()
statistics.stoptiming(mptopdf)
else
- commands.writestatus("mptopdf","file '%s' not found",name)
+ report_mptopdf("file '%s' not found",name)
end
end
-
-- status info
statistics.register("mps conversion time",function()
- local n = mptopdf.n
+ local n = mptopdf.nofconverted
if n > 0 then
return format("%s seconds, %s conversions", statistics.elapsedtime(mptopdf),n)
else