summaryrefslogtreecommitdiff
path: root/tex/context/base/mlib-pdf.lua
diff options
context:
space:
mode:
authorMarius <mariausol@gmail.com>2013-10-20 01:21:09 +0300
committerMarius <mariausol@gmail.com>2013-10-20 01:21:09 +0300
commitb8ac6d7b7fdb16293c28034c349efd5b0b7b20b3 (patch)
tree0e9051dbe21b4e9cfc72fe594df5b0fe7bc511f3 /tex/context/base/mlib-pdf.lua
parent965214d981e6129b782c67adcaf3a81aedcb0bac (diff)
downloadcontext-b8ac6d7b7fdb16293c28034c349efd5b0b7b20b3.tar.gz
beta 2013.10.20 07:09
Diffstat (limited to 'tex/context/base/mlib-pdf.lua')
-rw-r--r--tex/context/base/mlib-pdf.lua77
1 files changed, 67 insertions, 10 deletions
diff --git a/tex/context/base/mlib-pdf.lua b/tex/context/base/mlib-pdf.lua
index 963309951..d5f22cd7e 100644
--- a/tex/context/base/mlib-pdf.lua
+++ b/tex/context/base/mlib-pdf.lua
@@ -10,8 +10,9 @@ if not modules then modules = { } end modules ['mlib-pdf'] = {
local format, concat, gsub = string.format, table.concat, string.gsub
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 setmetatable, rawset, tostring, tonumber, type = setmetatable, rawset, tostring, tonumber, type
+local P, S, C, Ct, Cc, Cg, Cf, Carg = lpeg.P, lpeg.S, lpeg.C, lpeg.Ct, lpeg.Cc, lpeg.Cg, lpeg.Cf, lpeg.Carg
+local lpegmatch = lpeg.match
local formatters = string.formatters
local report_metapost = logs.reporter("metapost")
@@ -30,13 +31,12 @@ metapost.flushers = metapost.flushers or { }
local pdfflusher = { }
metapost.flushers.pdf = pdfflusher
-metapost.multipass = false
+metapost.multipass = false -- to be stacked
metapost.n = 0
-metapost.optimize = true -- false
+metapost.optimize = true -- false
local experiment = true -- uses context(node) that already does delayed nodes
-
-local savedliterals = nil -- needs checking
+local savedliterals = nil -- needs checking
local mpsliteral = nodes.pool.register(node.new("whatsit",nodes.whatsitcodes.pdfliteral)) -- pdfliteral.mode = 1
local pdfliteral = function(s)
@@ -268,7 +268,48 @@ metapost.flushnormalpath = flushnormalpath
-- performance penalty, but so is passing extra arguments (result, flusher, after)
-- and returning stuff.
-local function ignore() end
+local ignore = function () end
+
+local space = P(" ")
+local equal = P("=")
+local key = C((1-equal)^1) * equal
+local newline = S("\n\r")^1
+local number = (((1-space-newline)^1) / tonumber) * (space^0)
+local variable =
+ lpeg.P("1:") * key * number
+ + lpeg.P("2:") * key * C((1-newline)^0)
+ + lpeg.P("3:") * key * (P("false") * Cc(false) + P("true") * Cc(true))
+ + lpeg.S("4568") * P(":") * key * Ct(number^1)
+ + lpeg.P("7:") * key * Ct(Ct(number * number^-5)^1)
+
+local pattern = Cf ( Carg(1) * (Cg(variable * newline^0)^0), rawset)
+
+metapost.variables = { } -- to be stacked
+metapost.llx = 0 -- to be stacked
+metapost.lly = 0 -- to be stacked
+metapost.urx = 0 -- to be stacked
+metapost.ury = 0 -- to be stacked
+
+function commands.mprunvar(key,n)
+ local value = metapost.variables[key]
+ if value ~= nil then
+ local tvalue = type(value)
+ if tvalue == "table" then
+ local ntype = type(n)
+ if ntype == "number" then
+ context(value[n])
+ elseif ntype == "string" then
+ context(concat(value,n))
+ else
+ context(concat(value," "))
+ end
+ elseif tvalue == "number" or tvalue == "boolean" then
+ context(tostring(value))
+ elseif tvalue == "string" then
+ context(value)
+ end
+ end
+end
function metapost.flush(result,flusher,askedfig)
if result then
@@ -283,15 +324,29 @@ function metapost.flush(result,flusher,askedfig)
local stopfigure = flusher.stopfigure
local flushfigure = flusher.flushfigure
local textfigure = flusher.textfigure
- for f=1, #figures do
+ for f=1,#figures do
local figure = figures[f]
local objects = getobjects(result,figure,f)
- local fignum = figure:charcode() or 0
+ local fignum = figure:charcode() or 0
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()
local llx, lly, urx, ury = bbox[1], bbox[2], bbox[3], bbox[4]
+ local variables = { }
+ metapost.variables = variables
+ metapost.properties = {
+ llx = llx,
+ lly = lly,
+ urx = urx,
+ ury = ury,
+ slot = figure:charcode(),
+ width = figure:width(),
+ height = figure:height(),
+ depth = figure:depth(),
+ italic = figure:italcorr(),
+ }
+ -- replaced by the above
metapost.llx = llx
metapost.lly = lly
metapost.urx = urx
@@ -308,8 +363,10 @@ function metapost.flush(result,flusher,askedfig)
for o=1,#objects do
local object = objects[o]
local objecttype = object.type
- if objecttype == "start_bounds" or objecttype == "stop_bounds" or objecttype == "special" then
+ if objecttype == "start_bounds" or objecttype == "stop_bounds" then
-- skip
+ elseif objecttype == "special" then
+ lpegmatch(pattern,object.prescript,1,variables)
elseif objecttype == "start_clip" then
t[#t+1] = "q"
flushnormalpath(object.path,t,false)