summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/luatex/luamplib/luamplib.lua
diff options
context:
space:
mode:
Diffstat (limited to 'Master/texmf-dist/tex/luatex/luamplib/luamplib.lua')
-rw-r--r--Master/texmf-dist/tex/luatex/luamplib/luamplib.lua197
1 files changed, 107 insertions, 90 deletions
diff --git a/Master/texmf-dist/tex/luatex/luamplib/luamplib.lua b/Master/texmf-dist/tex/luatex/luamplib/luamplib.lua
index acd3e4aec35..a68edaf9fdb 100644
--- a/Master/texmf-dist/tex/luatex/luamplib/luamplib.lua
+++ b/Master/texmf-dist/tex/luatex/luamplib/luamplib.lua
@@ -11,8 +11,8 @@
luatexbase.provides_module {
name = "luamplib",
- version = "2.32.2",
- date = "2024/06/14",
+ version = "2.32.3",
+ date = "2024/06/21",
description = "Lua package to typeset Metapost with LuaTeX's MPLib.",
}
@@ -281,6 +281,7 @@ end
luamplib.codeinherit = false
local mplibinstances = {}
+luamplib.instances = mplibinstances
local has_instancename = false
local function reporterror (result, prevlog)
@@ -407,8 +408,7 @@ local function process_tex_text (str)
else
local boxid = texboxes.globalid + 1
texboxes.globalid = boxid
- run_tex_code(format(
- [[\expandafter\newbox\csname luamplib.box.%s\endcsname]], boxid))
+ run_tex_code(format([[\expandafter\newbox\csname luamplib.box.%s\endcsname]], boxid))
tex_box_id = tex.getcount'allocationnumber'
end
run_tex_code(format("%s\\setbox%i\\hbox{%s}", global, tex_box_id, str))
@@ -662,15 +662,7 @@ luamplib.shadecolor = function (str)
local name = get_macro'mplib_@tempa':match'{(.-)}{.+}'
local t, obj = res:explode()
if pdfmode then
- obj = t[1]:match"^/(.+)"
- if ltx.pdf and ltx.pdf.object_id then
- obj = format("%s 0 R", ltx.pdf.object_id(obj))
- else
- run_tex_code({
- [[\edef\mplib_@tempa{\pdf_object_ref:n{]], obj, "}}",
- },ccexplat)
- obj = get_macro'mplib_@tempa'
- end
+ obj = format("%s 0 R", ltx.pdf.object_id( t[1]:sub(2,-1) ))
else
obj = t[2]
end
@@ -1759,8 +1751,12 @@ if pdfmode then
end
end
pdfetcs.fallback_update_resources = function (name, res)
+ local tabname = format("%s_res",name)
+ if not pdfetcs[tabname] then
+ pdfetcs.initialize_resources(name)
+ end
if luatexbase.callbacktypes.finish_pdffile then
- local t = pdfetcs[format("%s_res",name)]
+ local t = pdfetcs[tabname]
t[#t+1] = res
else
local tpr, n = pdfetcs.getpageres() or "", 0
@@ -1772,8 +1768,12 @@ if pdfmode then
end
end
else
- texsprint("\\special{pdf:obj @MPlibTr<<>>}","\\special{pdf:obj @MPlibSh<<>>}",
- "\\special{pdf:obj @MPlibCS<<>>}","\\special{pdf:obj @MPlibPt<<>>}")
+ texsprint {
+ "\\special{pdf:obj @MPlibTr<<>>}",
+ "\\special{pdf:obj @MPlibSh<<>>}",
+ "\\special{pdf:obj @MPlibCS<<>>}",
+ "\\special{pdf:obj @MPlibPt<<>>}",
+ }
end
local transparancy_modes = { [0] = "Normal",
@@ -1787,38 +1787,39 @@ local transparancy_modes = { [0] = "Normal",
local function update_tr_res(mode,opaq)
local os = format("<</BM /%s/ca %.3f/CA %.3f/AIS false>>",mode,opaq,opaq)
local on, new = update_pdfobjs(os)
- if not new then return on end
- local key = format("MPlibTr%s", on)
- local val = format(pdfmode and "%s 0 R" or "@mplibpdfobj%s", on)
- if pdfmanagement then
- texsprint(ccexplat,
- format("\\pdfmanagement_add:nnn{Page/Resources/ExtGState}{%s}{%s}", key, val))
- else
- local tr = format("/%s %s", key, val)
- if is_defined(pdfetcs.pgfextgs) then
- texsprint(format("\\csname %s\\endcsname{%s}", pdfetcs.pgfextgs,tr))
- elseif pdfmode then
- if is_defined"TRP@list" then
- texsprint(catat11,{
- [[\if@filesw\immediate\write\@auxout{]],
- [[\string\g@addto@macro\string\TRP@list{]],
- tr,
- [[}}\fi]],
- })
- if not get_macro"TRP@list":find(tr) then
- texsprint(catat11,[[\global\TRP@reruntrue]])
+ if new then
+ local key = format("MPlibTr%s", on)
+ local val = format(pdfmode and "%s 0 R" or "@mplibpdfobj%s", on)
+ if pdfmanagement then
+ texsprint {
+ "\\csname pdfmanagement_add:nnn\\endcsname{Page/Resources/ExtGState}{", key, "}{", val, "}"
+ }
+ else
+ local tr = format("/%s %s", key, val)
+ if is_defined(pdfetcs.pgfextgs) then
+ texsprint { "\\csname ", pdfetcs.pgfextgs, "\\endcsname{", tr, "}" }
+ elseif pdfmode then
+ if is_defined"TRP@list" then
+ texsprint(catat11,{
+ [[\if@filesw\immediate\write\@auxout{]],
+ [[\string\g@addto@macro\string\TRP@list{]],
+ tr,
+ [[}}\fi]],
+ })
+ if not get_macro"TRP@list":find(tr) then
+ texsprint(catat11,[[\global\TRP@reruntrue]])
+ end
+ else
+ pdfetcs.fallback_update_resources("ExtGState", tr)
end
else
- if not pdfetcs.ExtGState_res then
- pdfetcs.initialize_resources"ExtGState"
- end
- pdfetcs.fallback_update_resources("ExtGState", tr)
+ texsprint { "\\special{pdf:put @MPlibTr<<", tr, ">>}" }
end
- else
- texsprint(format("\\special{pdf:put @MPlibTr<<%s>>}",tr))
- texsprint"\\special{pdf:put @resources<</ExtGState @MPlibTr>>}"
end
end
+ if not pdfmode and not pdfmanagement and not is_defined(pdfetcs.pgfextgs) then
+ texsprint"\\special{pdf:put @resources <</ExtGState @MPlibTr>>}"
+ end
return on
end
@@ -1868,24 +1869,25 @@ local function sh_pdfpageresources(shtype,domain,colorspace,ca,cb,coordinates,st
"/Extend [true true]/AntiAlias true>>",
}
local on, new = update_pdfobjs(os)
- if not new then return on end
- local key = format("MPlibSh%s", on)
- local val = format(pdfmode and "%s 0 R" or "@mplibpdfobj%s", on)
- if pdfmanagement then
- texsprint(ccexplat,
- format("\\pdfmanagement_add:nnn{Page/Resources/Shading}{%s}{%s}", key, val))
- else
- local res = format("/%s %s", key, val)
- if pdfmode then
- if not pdfetcs.Shading_res then
- pdfetcs.initialize_resources"Shading"
- end
- pdfetcs.fallback_update_resources("Shading", res)
+ if new then
+ local key = format("MPlibSh%s", on)
+ local val = format(pdfmode and "%s 0 R" or "@mplibpdfobj%s", on)
+ if pdfmanagement then
+ texsprint {
+ "\\csname pdfmanagement_add:nnn\\endcsname{Page/Resources/Shading}{", key, "}{", val, "}"
+ }
else
- texsprint(format("\\special{pdf:put @MPlibSh<<%s>>}", res))
- texsprint"\\special{pdf:put @resources<</Shading @MPlibSh>>}"
+ local res = format("/%s %s", key, val)
+ if pdfmode then
+ pdfetcs.fallback_update_resources("Shading", res)
+ else
+ texsprint { "\\special{pdf:put @MPlibSh<<", res, ">>}" }
+ end
end
end
+ if not pdfmode and not pdfmanagement then
+ texsprint"\\special{pdf:put @resources <</Shading @MPlibSh>>}"
+ end
return on
end
@@ -2038,7 +2040,12 @@ function luamplib.registerpattern ( boxid, name, opts )
info("w/h/d of '%s': %s %s 0.0", name, wd, hd)
if opts.xstep == 0 then opts.xstep = nil end
if opts.ystep == 0 then opts.ystep = nil end
- if opts.colored == nil then opts.colored = true end
+ if opts.colored == nil then
+ opts.colored = opts.coloured
+ if opts.colored == nil then
+ opts.colored = true
+ end
+ end
if type(opts.matrix) == "table" then opts.matrix = tableconcat(opts.matrix," ") end
if type(opts.bbox) == "table" then opts.bbox = tableconcat(opts.bbox," ") end
if opts.matrix and opts.matrix:find"%a" then
@@ -2064,7 +2071,7 @@ function luamplib.registerpattern ( boxid, name, opts )
for _,v in ipairs{"ExtGState","ColorSpace","Shading"} do
local pp = get_macro(format("g__pdfdict_/g__pdf_Core/Page/Resources/%s_prop",v))
if pp and pp:find"__prop_pair" then
- t[#t+1] = format("/%s %s", v, ltx.__pdf.object["__pdf/Page/Resources/"..v])
+ t[#t+1] = format("/%s %s 0 R", v, ltx.pdf.object_id("__pdf/Page/Resources/"..v))
end
end
else
@@ -2090,17 +2097,24 @@ function luamplib.registerpattern ( boxid, name, opts )
local optres, t = opts.resources or "", { }
if pdfmanagement then
for _,v in ipairs{"ExtGState","ColorSpace","Shading"} do
- run_tex_code(format(
- [[\mplibtmptoks\expanded{{/%s \pdf_object_ref:n{__pdf/Page/Resources/%s}}}]],v,v),ccexplat)
- t[#t+1] = texgettoks'mplibtmptoks'
+ local pp = get_macro(format("g__pdfdict_/g__pdf_Core/Page/Resources/%s_prop",v))
+ if pp and pp:find"__prop_pair" then
+ run_tex_code {
+ "\\mplibtmptoks\\expanded{{",
+ format("/%s \\csname pdf_object_ref:n\\endcsname{__pdf/Page/Resources/%s}",v,v),
+ "}}",
+ }
+ t[#t+1] = texgettoks'mplibtmptoks'
+ end
end
elseif is_defined(pdfetcs.pgfextgs) then
- run_tex_code("\\mplibtmptoks\\expanded{{\z
- \\ifpgf@sys@pdf@extgs@exists /ExtGState @pgfextgs\\fi\z
- \\ifpgf@sys@pdf@colorspaces@exists /ColorSpace @pgfcolorspaces\\fi}}",catat11)
+ run_tex_code ({
+ "\\mplibtmptoks\\expanded{{",
+ "\\ifpgf@sys@pdf@extgs@exists /ExtGState @pgfextgs\\fi",
+ "\\ifpgf@sys@pdf@colorspaces@exists /ColorSpace @pgfcolorspaces\\fi",
+ "}}",
+ }, catat11)
t[#t+1] = texgettoks'mplibtmptoks'
- else
- t[#t+1] = "/ExtGState @MPlibTr/Shading @MPlibSh/ColorSpace @MPlibCS"
end
optres = optres .. tableconcat(t)
texsprint {
@@ -2124,22 +2138,23 @@ local function pattern_colorspace (cs)
local key = format("MPlibCS%i",on)
local val = pdfmode and format("%i 0 R",on) or format("@mplibpdfobj%i",on)
if pdfmanagement then
- texsprint(ccexplat,format("\\pdfmanagement_add:nnn{Page/Resources/ColorSpace}{%s}{%s}",key,val))
+ texsprint {
+ "\\csname pdfmanagement_add:nnn\\endcsname{Page/Resources/ColorSpace}{", key, "}{", val, "}"
+ }
else
local res = format("/%s %s", key, val)
if is_defined(pdfetcs.pgfcolorspace) then
- texsprint(format("\\csname %s\\endcsname{%s}", pdfetcs.pgfcolorspace, res))
+ texsprint { "\\csname ", pdfetcs.pgfcolorspace, "\\endcsname{", res, "}" }
elseif pdfmode then
- if not pdfetcs.ColorSpace_res then
- pdfetcs.initialize_resources"ColorSpace"
- end
pdfetcs.fallback_update_resources("ColorSpace", res)
else
- texsprint(format("\\special{pdf:put @MPlibCS<<%s>>}", res))
- texsprint"\\special{pdf:put @resources<</ColorSpace @MPlibCS>>}"
+ texsprint { "\\special{pdf:put @MPlibCS<<", res, ">>}" }
end
end
end
+ if not pdfmode and not pdfmanagement and not is_defined(pdfetcs.pgfcolorspace) then
+ texsprint"\\special{pdf:put @resources <</ColorSpace @MPlibCS>>}"
+ end
return on
end
local function do_preobj_PAT(object, prescript)
@@ -2174,24 +2189,26 @@ local function do_preobj_PAT(object, prescript)
end
pdf_literalcode("/MPlibCS%i cs %s /%s scn", pattern_colorspace(cs), color, key)
end
- if patt.done then return end
- local val = pdfmode and format("%s 0 R",index) or patterns[index]
- if pdfmanagement then
- texsprint(ccexplat, format("\\pdfmanagement_add:nnn{Page/Resources/Pattern}{%s}{%s}",key,val))
- else
- local res = format("/%s %s", key, val)
- if is_defined(pdfetcs.pgfpattern) then
- texsprint(format("\\csname %s\\endcsname{%s}", pdfetcs.pgfpattern, res))
- elseif pdfmode then
- if not pdfetcs.Pattern_res then
- pdfetcs.initialize_resources"Pattern"
- end
- pdfetcs.fallback_update_resources("Pattern", res)
+ if not patt.done then
+ local val = pdfmode and format("%s 0 R",index) or patterns[index]
+ if pdfmanagement then
+ texsprint {
+ "\\csname pdfmanagement_add:nnn\\endcsname{Page/Resources/Pattern}{", key, "}{", val, "}"
+ }
else
- texsprint(format("\\special{pdf:put @MPlibPt<<%s>>}", res))
- texsprint"\\special{pdf:put @resources<</Pattern @MPlibPt>>}"
+ local res = format("/%s %s", key, val)
+ if is_defined(pdfetcs.pgfpattern) then
+ texsprint { "\\csname ", pdfetcs.pgfpattern, "\\endcsname{", res, "}" }
+ elseif pdfmode then
+ pdfetcs.fallback_update_resources("Pattern", res)
+ else
+ texsprint { "\\special{pdf:put @MPlibPt<<", res, ">>}" }
+ end
end
end
+ if not pdfmode and not pdfmanagement and not is_defined(pdfetcs.pgfpattern) then
+ texsprint"\\special{pdf:put @resources <</Pattern @MPlibPt>>}"
+ end
patt.done = true
end