diff options
Diffstat (limited to 'Master/texmf-dist/tex/context/base/mlib-pps.lua')
-rw-r--r-- | Master/texmf-dist/tex/context/base/mlib-pps.lua | 342 |
1 files changed, 227 insertions, 115 deletions
diff --git a/Master/texmf-dist/tex/context/base/mlib-pps.lua b/Master/texmf-dist/tex/context/base/mlib-pps.lua index 7821b3dbf24..93bddc2dd4c 100644 --- a/Master/texmf-dist/tex/context/base/mlib-pps.lua +++ b/Master/texmf-dist/tex/context/base/mlib-pps.lua @@ -6,7 +6,8 @@ if not modules then modules = { } end modules ['mlib-pps'] = { license = "see context related readme files", } --- todo: report max textexts +-- todo: make a hashed textext variant where we only process the text once (normally +-- we cannot assume that no macros are involved which influence a next textext local format, gmatch, match, split = string.format, string.gmatch, string.match, string.split local tonumber, type = tonumber, type @@ -14,6 +15,7 @@ local round = math.round local insert, concat = table.insert, table.concat local Cs, Cf, C, Cg, Ct, P, S, V, Carg = lpeg.Cs, lpeg.Cf, lpeg.C, lpeg.Cg, lpeg.Ct, lpeg.P, lpeg.S, lpeg.V, lpeg.Carg local lpegmatch = lpeg.match +local formatters = string.formatters local mplib, metapost, lpdf, context = mplib, metapost, lpdf, context @@ -80,14 +82,21 @@ function metapost.setoutercolor(mode,colormodel,colorattribute,transparencyattri innertransparency = outertransparency -- not yet used end -local function checked_color_pair(color) +local f_gray = formatters["%.3f g %.3f G"] +local f_rgb = formatters["%.3f %.3f %.3f rg %.3f %.3f %.3f RG"] +local f_cmyk = formatters["%.3f %.3f %.3f %.3f k %.3f %.3f %.3f %.3f K"] +local f_cm = formatters["q %f %f %f %f %f %f cm"] +local f_shade = formatters["MpSh%s"] + +local function checked_color_pair(color,...) if not color then return innercolor, outercolor - elseif outercolormode == 3 then - innercolor = color + end + if outercolormode == 3 then + innercolor = color(...) return innercolor, innercolor else - return color, outercolor + return color(...), outercolor end end @@ -142,7 +151,7 @@ local commasplitter = lpeg.tsplitat(",") local function checkandconvertspot(n_a,f_a,c_a,v_a,n_b,f_b,c_b,v_b) -- must be the same but we don't check - local name = format("MpSh%s",nofshades) + local name = f_shade(nofshades) local ca = lpegmatch(commasplitter,v_a) local cb = lpegmatch(commasplitter,v_b) if #ca == 0 or #cb == 0 then @@ -156,7 +165,7 @@ local function checkandconvertspot(n_a,f_a,c_a,v_a,n_b,f_b,c_b,v_b) end local function checkandconvert(ca,cb) - local name = format("MpSh%s",nofshades) + local name = f_shade(nofshades) if not ca or not cb or type(ca) == "string" then return { 0 }, { 1 }, "DeviceGray", name else @@ -206,10 +215,14 @@ local current_format, current_graphic, current_initializations metapost.multipass = false -local textexts = { } +local textexts = { } -- all boxes, optionally with a different color +local texslots = { } -- references to textexts in order or usage +local texorder = { } -- references to textexts by mp index +local textrial = 0 +local texfinal = 0 local scratchbox = 0 -local function freeboxes() -- todo: mp direct list ipv box +local function freeboxes() for n, box in next, textexts do local tn = textexts[n] if tn then @@ -217,11 +230,15 @@ local function freeboxes() -- todo: mp direct list ipv box -- texbox[scratchbox] = tn -- texbox[scratchbox] = nil -- this frees too if trace_textexts then - report_textexts("freeing %s",n) + report_textexts("freeing box %s",n) end end end textexts = { } + texslots = { } + texorder = { } + textrial = 0 + texfinal = 0 end metapost.resettextexts = freeboxes @@ -237,7 +254,7 @@ end function metapost.gettext(box,slot) texbox[box] = copy_list(textexts[slot]) if trace_textexts then - report_textexts("putting %s in box %s",slot,box) + report_textexts("putting text %s in box %s",slot,box) end -- textexts[slot] = nil -- no, pictures can be placed several times end @@ -257,32 +274,32 @@ function models.all(cr) elseif metapost.reducetogray then if n == 1 then local s = cr[1] - return checked_color_pair(format("%.3f g %.3f G",s,s)) + return checked_color_pair(f_gray,s,s) elseif n == 3 then local r, g, b = cr[1], cr[2], cr[3] if r == g and g == b then - return checked_color_pair(format("%.3f g %.3f G",r,r)) + return checked_color_pair(f_gray,r,r) else - return checked_color_pair(format("%.3f %.3f %.3f rg %.3f %.3f %.3f RG",r,g,b,r,g,b)) + return checked_color_pair(f_rgb,r,g,b,r,g,b) end else local c, m, y, k = cr[1], cr[2], cr[3], cr[4] if c == m and m == y and y == 0 then k = 1 - k - return checked_color_pair(format("%.3f g %.3f G",k,k)) + return checked_color_pair(f_gray,k,k) else - return checked_color_pair(format("%.3f %.3f %.3f %.3f k %.3f %.3f %.3f %.3f K",c,m,y,k,c,m,y,k)) + return checked_color_pair(f_cmyk,c,m,y,k,c,m,y,k) end end elseif n == 1 then local s = cr[1] - return checked_color_pair(format("%.3f g %.3f G",s,s)) + return checked_color_pair(f_gray,s,s) elseif n == 3 then local r, g, b = cr[1], cr[2], cr[3] - return checked_color_pair(format("%.3f %.3f %.3f rg %.3f %.3f %.3f RG",r,g,b,r,g,b)) + return checked_color_pair(f_rgb,r,g,b,r,g,b) else local c, m, y, k = cr[1], cr[2], cr[3], cr[4] - return checked_color_pair(format("%.3f %.3f %.3f %.3f k %.3f %.3f %.3f %.3f K",c,m,y,k,c,m,y,k)) + return checked_color_pair(f_cmyk,c,m,y,k,c,m,y,k) end end @@ -293,27 +310,27 @@ function models.rgb(cr) elseif metapost.reducetogray then if n == 1 then local s = cr[1] - checked_color_pair(format("%.3f g %.3f G",s,s)) + checked_color_pair(f_gray,s,s) elseif n == 3 then local r, g, b = cr[1], cr[2], cr[3] if r == g and g == b then - return checked_color_pair(format("%.3f g %.3f G",r,r)) + return checked_color_pair(f_gray,r,r) else - return checked_color_pair(format("%.3f %.3f %.3f rg %.3f %.3f %.3f RG",r,g,b,r,g,b)) + return checked_color_pair(f_rgb,r,g,b,r,g,b) end else local c, m, y, k = cr[1], cr[2], cr[3], cr[4] if c == m and m == y and y == 0 then k = 1 - k - return checked_color_pair(format("%.3f g %.3f G",k,k)) + return checked_color_pair(f_gray,k,k) else local r, g, b = cmyktorgb(c,m,y,k) - return checked_color_pair(format("%.3f %.3f %.3f rg %.3f %.3f %.3f RG",r,g,b,r,g,b)) + return checked_color_pair(f_rgb,r,g,b,r,g,b) end end elseif n == 1 then local s = cr[1] - return checked_color_pair(format("%.3f g %.3f G",s,s)) + return checked_color_pair(f_gray,s,s) else local r, g, b if n == 3 then @@ -321,7 +338,7 @@ function models.rgb(cr) else r, g, b = cr[1], cr[2], cr[3] end - return checked_color_pair(format("%.3f %.3f %.3f rg %.3f %.3f %.3f RG",r,g,b,r,g,b)) + return checked_color_pair(f_rgb,r,g,b,r,g,b) end end @@ -332,27 +349,27 @@ function models.cmyk(cr) elseif metapost.reducetogray then if n == 1 then local s = cr[1] - return checked_color_pair(format("%.3f g %.3f G",s,s)) + return checked_color_pair(f_gray,s,s) elseif n == 3 then local r, g, b = cr[1], cr[2], cr[3] if r == g and g == b then - return checked_color_pair(format("%.3f g %.3f G",r,r)) + return checked_color_pair(f_gray,r,r) else local c, m, y, k = rgbtocmyk(r,g,b) - return checked_color_pair(format("%.3f %.3f %.3f %.3f k %.3f %.3f %.3f %.3f K",c,m,y,k,c,m,y,k)) + return checked_color_pair(f_cmyk,c,m,y,k,c,m,y,k) end else local c, m, y, k = cr[1], cr[2], cr[3], cr[4] if c == m and m == y and y == 0 then - k = 1 - k - return checked_color_pair(format("%.3f g %.3f G",k,k)) + k = k - 1 + return checked_color_pair(f_gray,k,k) else - return checked_color_pair(format("%.3f %.3f %.3f %.3f k %.3f %.3f %.3f %.3f K",c,m,y,k,c,m,y,k)) + return checked_color_pair(f_cmyk,c,m,y,k,c,m,y,k) end end elseif n == 1 then local s = cr[1] - return checked_color_pair(format("%.3f g %.3f G",s,s)) + return checked_color_pair(f_gray,s,s) else local c, m, y, k if n == 3 then @@ -360,7 +377,7 @@ function models.cmyk(cr) else c, m, y, k = cr[1], cr[2], cr[3], cr[4] end - return checked_color_pair(format("%.3f %.3f %.3f %.3f k %.3f %.3f %.3f %.3f K",c,m,y,k,c,m,y,k)) + return checked_color_pair(f_cmyk,c,m,y,k,c,m,y,k) end end @@ -375,7 +392,7 @@ function models.gray(cr) else s = cr[1] end - return checked_color_pair(format("%.3f g %.3f G",s,s)) + return checked_color_pair(f_gray,s,s) end setmetatableindex(models, function(t,k) @@ -461,27 +478,32 @@ local function sxsy(wd,ht,dp) -- helper for text return (wd ~= 0 and factor/wd) or 0, (hd ~= 0 and factor/hd) or 0 end -local no_trial_run = "mfun_trial_run := false ;" -local do_trial_run = "if unknown mfun_trial_run : boolean mfun_trial_run fi ; mfun_trial_run := true ;" -local text_data_template = "mfun_tt_w[%i] := %f ; mfun_tt_h[%i] := %f ; mfun_tt_d[%i] := %f ;" -local do_begin_fig = "; beginfig(1) ; " -local do_end_fig = "; endfig ;" -local do_safeguard = ";" +local no_first_run = "mfun_first_run := false ;" +local do_first_run = "mfun_first_run := true ;" +local no_trial_run = "mfun_trial_run := false ;" +local do_trial_run = "mfun_trial_run := true ;" +local do_begin_fig = "; beginfig(1) ; " +local do_end_fig = "; endfig ;" +local do_safeguard = ";" + +local f_text_data = formatters["mfun_tt_w[%i] := %f ; mfun_tt_h[%i] := %f ; mfun_tt_d[%i] := %f ;"] function metapost.textextsdata() local t, nt, n = { }, 0, 0 - for n, box in next, textexts do + for n=1,#texorder do + local box = textexts[texorder[n]] if box then local wd, ht, dp = box.width/factor, box.height/factor, box.depth/factor if trace_textexts then - report_textexts("passed data %s: (%0.4f,%0.4f,%0.4f)",n,wd,ht,dp) + report_textexts("passed data item %s: (%p,%p,%p)",n,wd,ht,dp) end nt = nt + 1 - t[nt] = format(text_data_template,n,wd,n,ht,n,dp) + t[nt] = f_text_data(n,wd,n,ht,n,dp) else break end end +-- inspect(t) return t end @@ -512,33 +534,69 @@ local function checkaskedfig(askedfig) -- return askedfig, wrappit end end -function metapost.graphic_base_pass(mpsformat,str,initializations,preamble,askedfig) +function metapost.graphic_base_pass(specification) + local mpx = specification.mpx -- mandate + local data = specification.data or "" + local definitions = specification.definitions or "" +-- local extensions = metapost.getextensions(specification.instance,specification.useextensions) + local extensions = specification.extensions or "" + local inclusions = specification.inclusions or "" + local initializations = specification.initializations or "" + local askedfig = specification.figure -- no default else no wrapper + -- nofruns = nofruns + 1 local askedfig, wrappit = checkaskedfig(askedfig) - local done_1, done_2, forced_1, forced_2 - str, done_1, forced_1 = checktexts(str) - if not preamble or preamble == "" then - preamble, done_2, forced_2 = "", false, false + local done_1, done_2, done_3, forced_1, forced_2, forced_3 + data, done_1, forced_1 = checktexts(data) + -- we had preamble = extensions + inclusions + if extensions == "" then + extensions, done_2, forced_2 = "", false, false else - preamble, done_2, forced_2 = checktexts(preamble) + extensions, done_2, forced_2 = checktexts(extensions) + end + if inclusions == "" then + inclusions, done_3, forced_3 = "", false, false + else + inclusions, done_3, forced_3 = checktexts(inclusions) end metapost.intermediate.needed = false metapost.multipass = false -- no needed here - current_format, current_graphic, current_initializations = mpsformat, str, initializations or "" - if metapost.method == 1 or (metapost.method == 2 and (done_1 or done_2)) then + current_format = mpx + current_graphic = data + current_initializations = initializations + local method = metapost.method + if trace_runs then + if method == 1 then + report_metapost("forcing two runs due to library configuration") + elseif method ~= 2 then + report_metapost("ignoring run due to library configuration") + elseif not (done_1 or done_2 or done_3) then + report_metapost("forcing one run only due to analysis") + elseif done_1 then + report_metapost("forcing at max two runs due to main code") + elseif done_2 then + report_metapost("forcing at max two runs due to extensions") + else + report_metapost("forcing at max two runs due to inclusions") + end + end + if method == 1 or (method == 2 and (done_1 or done_2 or done_3)) then if trace_runs then - report_metapost("first run of job %s (asked: %s)",nofruns,tostring(askedfig)) + report_metapost("first run of job %s, asked figure %a",nofruns,askedfig) end -- first true means: trialrun, second true means: avoid extra run if no multipass - local flushed = metapost.process(mpsformat, { - preamble, + local flushed = metapost.process(mpx, { + definitions, + extensions, + inclusions, wrappit and do_begin_fig or "", + do_first_run, do_trial_run, current_initializations, do_safeguard, current_graphic, wrappit and do_end_fig or "", - }, true, nil, not (forced_1 or forced_2), false, askedfig) + }, true, nil, not (forced_1 or forced_2 or forced_3), false, askedfig) if metapost.intermediate.needed then for _, action in next, metapost.intermediate.actions do action() @@ -551,23 +609,24 @@ function metapost.graphic_base_pass(mpsformat,str,initializations,preamble,asked end else if trace_runs then - report_metapost("running job %s (asked: %s)",nofruns,tostring(askedfig)) + report_metapost("running job %s, asked figure %a",nofruns,askedfig) end - metapost.process(mpsformat, { + metapost.process(mpx, { preamble, wrappit and do_begin_fig or "", + do_first_run, no_trial_run, current_initializations, do_safeguard, current_graphic, wrappit and do_end_fig or "", - }, false, nil, false, false, askedfig ) + }, false, nil, false, false, askedfig) end end function metapost.graphic_extra_pass(askedfig) if trace_runs then - report_metapost("second run of job %s (asked: %s)",nofruns,tostring(askedfig)) + report_metapost("second run of job %s, asked figure %a",nofruns,askedfig) end local askedfig, wrappit = checkaskedfig(askedfig) metapost.process(current_format, { @@ -605,7 +664,7 @@ function makempy.processgraphics(graphics) local data = io.loaddata(mpyfile) for figure in gmatch(data,"beginfig(.-)endfig") do r = r + 1 - result[r] = format("begingraphictextfig%sendgraphictextfig ;\n", figure) + result[r] = formatters["begingraphictextfig%sendgraphictextfig ;\n"](figure) end io.savedata(mpyfile,concat(result,"")) end @@ -642,7 +701,7 @@ local scriptsplitter = Ct ( Ct ( C((1-S("= "))^1) * S("= ")^1 * C((1-S("\n\r"))^0) * S("\n\r")^0 )^0 ) -local function splitscript(script) +local function splitprescript(script) local hash = lpegmatch(scriptsplitter,script) for i=#hash,1,-1 do local h = hash[i] @@ -654,6 +713,20 @@ local function splitscript(script) return hash end +-- -- not used: +-- +-- local function splitpostscript(script) +-- local hash = lpegmatch(scriptsplitter,script) +-- for i=1,#hash do +-- local h = hash[i] +-- hash[h[1]] = h[2] +-- end +-- if trace_scripts then +-- report_scripts(table.serialize(hash,"postscript")) +-- end +-- return hash +-- end + function metapost.pluginactions(what,t,flushfigure) -- before/after object, depending on what for i=1,#what do local wi = what[i] @@ -681,7 +754,7 @@ end function metapost.analyzeplugins(object) -- each object (first pass) local prescript = object.prescript -- specifications if prescript and #prescript > 0 then - return analyzer(object,splitscript(prescript)) + return analyzer(object,splitprescript(prescript)) end end @@ -690,7 +763,7 @@ function metapost.processplugins(object) -- each object (second pass) if prescript and #prescript > 0 then local before = { } local after = { } - processor(object,splitscript(prescript),before,after) + processor(object,splitprescript(prescript),before,after) return #before > 0 and before, #after > 0 and after else local c = object.color @@ -707,13 +780,17 @@ local basepoints = number.dimenfactors["bp"] local function cm(object) local op = object.path - local first, second, fourth = op[1], op[2], op[4] - local tx, ty = first.x_coord , first.y_coord - local sx, sy = second.x_coord - tx, fourth.y_coord - ty - local rx, ry = second.y_coord - ty, fourth.x_coord - tx - if sx == 0 then sx = 0.00001 end - if sy == 0 then sy = 0.00001 end - return sx,rx,ry,sy,tx,ty + if op then + local first, second, fourth = op[1], op[2], op[4] + local tx, ty = first.x_coord , first.y_coord + local sx, sy = second.x_coord - tx, fourth.y_coord - ty + local rx, ry = second.y_coord - ty, fourth.x_coord - tx + if sx == 0 then sx = 0.00001 end + if sy == 0 then sy = 0.00001 end + return sx, rx, ry, sy, tx, ty + else + return 1, 0, 0, 1, 0, 0 -- weird case + end end -- color @@ -722,50 +799,77 @@ local function cl_reset(t) t[#t+1] = metapost.colorinitializer() -- only color end --- text - -local tx_done = { } +local tx_hash = { } +local tx_last = 0 local function tx_reset() - tx_done = { } + tx_hash = { } + tx_last = 0 end +local fmt = formatters["%s %s %s % t"] + local function tx_analyze(object,prescript) -- todo: hash content and reuse them local tx_stage = prescript.tx_stage - if tx_stage then + if tx_stage == "trial" then + textrial = textrial + 1 local tx_number = tonumber(prescript.tx_number) - if not tx_done[tx_number] then - tx_done[tx_number] = true - if trace_textexts then - report_textexts("setting %s %s (first pass)",tx_stage,tx_number) - end - local s = object.postscript or "" - local c = object.color -- only simple ones, no transparency - local a = prescript.tr_alternative - local t = prescript.tr_transparency + local s = object.postscript or "" + local c = object.color -- only simple ones, no transparency + local a = prescript.tr_alternative + local t = prescript.tr_transparency + local h = fmt(tx_number,a or "?",t or "?",c) + local n = tx_hash[h] -- todo: hashed variant with s (nicer for similar labels) + if not n then + tx_last = tx_last + 1 if not c then -- no color elseif #c == 1 then if a and t then - s = format("\\directcolored[s=%f,a=%f,t=%f]%s",c[1],a,t,s) + s = formatters["\\directcolored[s=%f,a=%f,t=%f]%s"](c[1],a,t,s) else - s = format("\\directcolored[s=%f]%s",c[1],s) + s = formatters["\\directcolored[s=%f]%s"](c[1],s) end elseif #c == 3 then if a and t then - s = format("\\directcolored[r=%f,g=%f,b=%f,a=%f,t=%f]%s",c[1],c[2],c[3],a,t,s) + s = formatters["\\directcolored[r=%f,g=%f,b=%f,a=%f,t=%f]%s"](c[1],c[2],c[3],a,t,s) else - s = format("\\directcolored[r=%f,g=%f,b=%f]%s",c[1],c[2],c[3],s) + s = formatters["\\directcolored[r=%f,g=%f,b=%f]%s"](c[1],c[2],c[3],s) end elseif #c == 4 then if a and t then - s = format("\\directcolored[c=%f,m=%f,y=%f,k=%f,a=%f,t=%f]%s",c[1],c[2],c[3],c[4],a,t,s) + s = formatters["\\directcolored[c=%f,m=%f,y=%f,k=%f,a=%f,t=%f]%s"](c[1],c[2],c[3],c[4],a,t,s) else - s = format("\\directcolored[c=%f,m=%f,y=%f,k=%f]%s",c[1],c[2],c[3],c[4],s) + s = formatters["\\directcolored[c=%f,m=%f,y=%f,k=%f]%s"](c[1],c[2],c[3],c[4],s) end end - context.MPLIBsettext(tx_number,s) -- combine colored in here, saves call + context.MPLIBsettext(tx_last,s) metapost.multipass = true + tx_hash[h] = tx_last + texslots[textrial] = tx_last + texorder[tx_number] = tx_last + if trace_textexts then + report_textexts("stage %a, usage %a, number %a, new %a, hash %a",tx_stage,textrial,tx_number,tx_last,h) + end + else + texslots[textrial] = n + if trace_textexts then + report_textexts("stage %a, usage %a, number %a, new %a, hash %a",tx_stage,textrial,tx_number,n,h) + end + end + elseif tx_stage == "extra" then + textrial = textrial + 1 + local tx_number = tonumber(prescript.tx_number) + if not texorder[tx_number] then + local s = object.postscript or "" + tx_last = tx_last + 1 + context.MPLIBsettext(tx_last,s) + metapost.multipass = true + texslots[textrial] = tx_last + texorder[tx_number] = tx_last + if trace_textexts then + report_textexts("stage %a, usage %a, number %a, extra %a",tx_stage,textrial,tx_number,tx_last) + end end end end @@ -775,23 +879,31 @@ local function tx_process(object,prescript,before,after) if tx_number then tx_number = tonumber(tx_number) local tx_stage = prescript.tx_stage - if tx_stage == "final" then -- redundant test + if tx_stage == "final" then + texfinal = texfinal + 1 + local n = texslots[texfinal] if trace_textexts then - report_textexts("processing %s (second pass)",tx_number) + report_textexts("stage %a, usage %a, number %a, use %a",tx_stage,texfinal,tx_number,n) end - -- before[#before+1] = format("q %f %f %f %f %f %f cm",cm(object)) - local sx,rx,ry,sy,tx,ty = cm(object) - before[#before+1] = function() - -- flush always happens, we can have a special flush function injected before - local box = textexts[tx_number] - if box then - -- context.MPLIBgettextscaled(tx_number,sxsy(box.width,box.height,box.depth)) - context.MPLIBgettextscaledcm(tx_number,sx,rx,ry,sy,tx,ty,sxsy(box.width,box.height,box.depth)) - else + local sx, rx, ry, sy, tx, ty = cm(object) -- needs to be frozen outside the function + local box = textexts[n] + if box then + before[#before+1] = function() + -- flush always happens, we can have a special flush function injected before + context.MPLIBgettextscaledcm(n, + format("%f",sx), -- bah ... %s no longer checks + format("%f",rx), -- bah ... %s no longer checks + format("%f",ry), -- bah ... %s no longer checks + format("%f",sy), -- bah ... %s no longer checks + format("%f",tx), -- bah ... %s no longer checks + format("%f",ty), -- bah ... %s no longer checks + sxsy(box.width,box.height,box.depth)) + end + else + before[#before+1] = function() report_textexts("unknown %s",tx_number) end end - -- before[#before+1] = "Q" if not trace_textexts then object.path = false -- else: keep it end @@ -815,7 +927,7 @@ end local function gt_analyze(object,prescript) local gt_stage = prescript.gt_stage if gt_stage == "trial" then - graphics[#graphics+1] = format("\\MPLIBgraphictext{%s}",object.postscript or "") + graphics[#graphics+1] = formatters["\\MPLIBgraphictext{%s}"](object.postscript or "") metapost.intermediate.needed = true metapost.multipass = true end @@ -891,9 +1003,9 @@ local function sh_process(object,prescript,before,after) else -- fatal error end - before[#before+1], after[#after+1] = "q /Pattern cs", format("W n /%s sh Q",name) + before[#before+1], after[#after+1] = "q /Pattern cs", formatters["W n /%s sh Q"](name) -- false, not nil, else mt triggered - object.colored = false + object.colored = false -- hm, not object.color ? object.type = false object.grouped = true end @@ -904,7 +1016,7 @@ end local function bm_process(object,prescript,before,after) local bm_xresolution = prescript.bm_xresolution if bm_xresolution then - before[#before+1] = format("q %f %f %f %f %f %f cm",cm(object)) + before[#before+1] = f_cm(cm(object)) before[#before+1] = function() figures.bitmapimage { xresolution = tonumber(bm_xresolution), @@ -944,7 +1056,7 @@ end local function fg_process(object,prescript,before,after) local fg_name = prescript.fg_name if fg_name then - before[#before+1] = format("q %f %f %f %f %f %f cm",cm(object)) -- beware: does not use the cm stack + before[#before+1] = f_cm(cm(object)) -- beware: does not use the cm stack before[#before+1] = function() context.MPLIBfigure(fg_name,prescript.fg_mask or "") end @@ -972,7 +1084,7 @@ local function tr_process(object,prescript,before,after) if tr_alternative then tr_alternative = tonumber(tr_alternative) local tr_transparency = tonumber(prescript.tr_transparency) - before[#before+1] = format("/Tr%s gs",registertransparency(nil,tr_alternative,tr_transparency,true)) + before[#before+1] = formatters["/Tr%s gs"](registertransparency(nil,tr_alternative,tr_transparency,true)) after[#after+1] = "/Tr0 gs" -- outertransparency end local cs = object.color @@ -1002,7 +1114,7 @@ local function tr_process(object,prescript,before,after) local t = t_list[sp_name] -- string or attribute local v = t and attributes.transparencies.value(t) if v then - before[#before+1] = format("/Tr%s gs",registertransparency(nil,v[1],v[2],true)) + before[#before+1] = formatters["/Tr%s gs"](registertransparency(nil,v[1],v[2],true)) after[#after+1] = "/Tr0 gs" -- outertransparency end end @@ -1014,16 +1126,16 @@ local function tr_process(object,prescript,before,after) local f = cs[1] if colorspace == 2 then local s = f*v[2] - c_b, c_a = checked_color_pair(format("%.3f g %.3f G",s,s)) + c_b, c_a = checked_color_pair(f_gray,s,s) elseif colorspace == 3 then local r, g, b = f*v[3], f*v[4], f*v[5] - c_b, c_a = checked_color_pair(format("%.3f %.3f %.3f rg %.3f %.3f %.3f RG",r,g,b,r,g,b)) + c_b, c_a = checked_color_pair(f_rgb,r,g,b,r,g,b) elseif colorspace == 4 or colorspace == 1 then local c, m, y, k = f*v[6], f*v[7], f*v[8], f*v[9] - c_b, c_a = checked_color_pair(format("%.3f %.3f %.3f %.3f k %.3f %.3f %.3f %.3f K",c,m,y,k,c,m,y,k)) + c_b, c_a = checked_color_pair(f_cmyk,c,m,y,k,c,m,y,k) else local s = f*v[2] - c_b, c_a = checked_color_pair(format("%.3f g %.3f G",s,s)) + c_b, c_a = checked_color_pair(f_gray,s,s) end end -- |