summaryrefslogtreecommitdiff
path: root/macros/luatex/generic/luamplib
diff options
context:
space:
mode:
authorNorbert Preining <norbert@preining.info>2024-07-20 03:01:53 +0000
committerNorbert Preining <norbert@preining.info>2024-07-20 03:01:53 +0000
commit96f9be3c7fb1e25375e2c57334a96fd897bfcf0e (patch)
tree5371d9996fd8e23e4f3d309dd3edfbce94a3e194 /macros/luatex/generic/luamplib
parentfb8f2ca1019d0b788efee13c1ceb5534befa6aad (diff)
CTAN sync 202407200301
Diffstat (limited to 'macros/luatex/generic/luamplib')
-rw-r--r--macros/luatex/generic/luamplib/NEWS5
-rw-r--r--macros/luatex/generic/luamplib/luamplib.dtx135
-rw-r--r--macros/luatex/generic/luamplib/luamplib.pdfbin239222 -> 242230 bytes
-rw-r--r--macros/luatex/generic/luamplib/test-luamplib-latex.tex12
-rw-r--r--macros/luatex/generic/luamplib/test-luamplib-plain.tex17
5 files changed, 140 insertions, 29 deletions
diff --git a/macros/luatex/generic/luamplib/NEWS b/macros/luatex/generic/luamplib/NEWS
index c97974fc20..85eadb6d7e 100644
--- a/macros/luatex/generic/luamplib/NEWS
+++ b/macros/luatex/generic/luamplib/NEWS
@@ -1,5 +1,10 @@
History of the luamplib package
+2024/07/19 2.34.1
+ * transparency group is available with plain format as well.
+ * transparency group once used is reusable in the TeX code or
+ in other MetaPost code chunks. see the document for details.
+
2024/07/17 2.34.0
* support transparency group with metafun format
* fix regarding default value in circular fading mode
diff --git a/macros/luatex/generic/luamplib/luamplib.dtx b/macros/luatex/generic/luamplib/luamplib.dtx
index 44500e957c..fe20a1ccf5 100644
--- a/macros/luatex/generic/luamplib/luamplib.dtx
+++ b/macros/luatex/generic/luamplib/luamplib.dtx
@@ -85,7 +85,7 @@ See source file '\inFileName' for licencing and contact information.
%<*driver>
\NeedsTeXFormat{LaTeX2e}
\ProvidesFile{luamplib.drv}%
- [2024/07/17 v2.34.0 Interface for using the mplib library]%
+ [2024/07/19 v2.34.1 Interface for using the mplib library]%
\documentclass{ltxdoc}
\usepackage{metalogo,multicol,mdwlist,fancyvrb,xspace}
\usepackage[x11names]{xcolor}
@@ -153,7 +153,7 @@ See source file '\inFileName' for licencing and contact information.
% \author{Hans Hagen, Taco Hoekwater, Elie Roux, Philipp Gesang and Kim Dohyun\\
% Current Maintainer: Kim Dohyun\\
% Support: \url{https://github.com/lualatex/luamplib}}
-% \date{2024/07/17 v2.34.0}
+% \date{2024/07/19 v2.34.1}
%
% \maketitle
%
@@ -254,6 +254,8 @@ See source file '\inFileName' for licencing and contact information.
% where \emph{<string>} should be |""| (empty), |"isolated"|, |"knockout"|, or |"isolated,knockout"|.
% Beware that currently many of the PDF rendering applications, except Adobe Acrobat Reader,
% cannot properly render the isolated or knockout effect.
+% Transparency group is available with \emph{plain} format as well, with extended functionality.
+% See below \S\,1.2.
%
% One thing worth mentioning about shading is:
% when a color expression is given in string type,
@@ -765,6 +767,61 @@ See source file '\inFileName' for licencing and contact information.
% \endmpfig
%\end{verbatim}
%
+% \paragraph{Transparency Group}
+% As said before,
+% transparency group is available with \emph{plain} as well as \emph{metafun} format.
+% The syntax is exactly the same:
+% \emph{<picture>} \char"7C\ \emph{<path>} |asgroup|
+% |""| \char"7C\ |"isolated"| \char"7C\ |"knockout"| \char"7C\ |"isolated,knockout"|,
+% which will return a metapost picture.
+%
+% The additional feature provided by luamplib is that
+% you can reuse the group as many times as you want
+% in the \TeX{} code or in other MetaPost code chunks,
+% with infinitesimal increase in the size of PDF file.
+% For this functionality we provide \TeX{} and MetaPost macros as follows:
+% \begin{description}
+% \let\bfseries\relax
+% \item[|withgroupname| \emph{<string>}] associates a transparency group with the given name.
+% When this is not appended to the sentense with |asgroup| operator,
+% the default group name `|lastmplibgroup|' will be used.
+%
+% \item[\cs{usemplibgroup\{...\}}] is a \TeX\ command to reuse a transparency group of the name
+% once used.
+% Note that the position of the group will be origin-based:
+% in other words, lower-left corner of the group will be shifted to the origin.
+%
+% \item[|usemplibgroup| \emph{<string>}] is a MetaPost command which will add
+% a transparency group of the name to the |currentpicture|.
+% Contrary to the \TeX\ command just mentioned,
+% the position of the group is the same as the original transparency group.
+% \end{description}
+% An example showing the difference between the \TeX\ and MetaPost commands:
+%\begin{verbatim}
+% \mpfig
+% draw image(
+% fill fullcircle scaled 100 shifted 25right withcolor .5[blue,white];
+% fill fullcircle scaled 100 withcolor .5[red,white] ;
+% ) asgroup "" withgroupname "mygroup";
+% draw (left--right) scaled 10;
+% draw (up--down) scaled 10;
+% \endmpfig
+%
+% \noindent
+% \llap{\vrule width 10pt height .25pt depth .25pt}%
+% \clap{\vrule width .5pt height 10pt depth 10pt}%
+% \rlap{\vrule width 10pt height .25pt depth .25pt}%
+% \usemplibgroup{mygroup}
+%
+% \mpfig
+% usemplibgroup "mygroup" rotated 15;
+% draw (left--right) scaled 10;
+% draw (up--down) scaled 10;
+% \endmpfig
+%\end{verbatim}
+% Also note that reused transparency groups are not affected by color commands,
+% transparency/fading commands will have effects though.
+%
% \subsection{Lua}
%
% \paragraph{\texttt{runscript ...}}
@@ -850,8 +907,8 @@ See source file '\inFileName' for licencing and contact information.
luatexbase.provides_module {
name = "luamplib",
- version = "2.34.0",
- date = "2024/07/17",
+ version = "2.34.1",
+ date = "2024/07/19",
description = "Lua package to typeset Metapost with LuaTeX's MPLib.",
}
@@ -2558,6 +2615,22 @@ def withfadebbox (expr a,b) =
decimal xpart b & ":" &
decimal ypart b
enddef;
+primarydef p asgroup s =
+ image(
+ fill llcorner p--lrcorner p--urcorner p--ulcorner p--cycle
+ withprescript "gr_state=start"
+ withprescript "gr_type=" & s;
+ draw p;
+ draw center p withprescript "gr_state=stop";
+ )
+enddef;
+def withgroupname expr s =
+ withprescript "mplibgroupname=" & s
+enddef;
+def usemplibgroup primary s =
+ draw maketext("\usemplibgroup{" & s & "}")
+ shifted runscript("return luamplib.trgroupshifts['" & s & "']")
+enddef;
]],
legacyverbatimtex = [[
def specialVerbatimTeX (text t) = runscript("luamplibprefig{"&t&"}") enddef;
@@ -3156,8 +3229,8 @@ end
% \begin{macrocode}
pdfetcs.patterns = { }
local patterns = pdfetcs.patterns
-local function gather_resources (do_pattern, optres)
- local t = { }
+local function gather_resources (optres)
+ local t, do_pattern = { }, not optres
local names = {"ExtGState","ColorSpace","Shading"}
if do_pattern then
names[#names+1] = "Pattern"
@@ -3173,10 +3246,12 @@ local function gather_resources (do_pattern, optres)
else
local res = pdfetcs.getpageres() or ""
run_tex_code[[\mplibtmptoks\expandafter{\the\pdfvariable pageresources}]]
- res = (res .. texgettoks'mplibtmptoks'):explode()
- res = tableconcat(res," "):explode"/+"
+ res = res .. texgettoks'mplibtmptoks'
+ if do_pattern then return res end
+ res = res:explode"/+"
for _,v in ipairs(res) do
- if do_pattern or not v:find"Pattern" and not optres:find(v) then
+ v = v:match"^%s*(.-)%s*$"
+ if not v:find"Pattern" and not optres:find(v) then
t[#t+1] = "/" .. v
end
end
@@ -3212,7 +3287,7 @@ local function gather_resources (do_pattern, optres)
end
end
end
- return t
+ return tableconcat(t)
end
function luamplib.registerpattern ( boxid, name, opts )
local box = texgetbox(boxid)
@@ -3247,8 +3322,7 @@ function luamplib.registerpattern ( boxid, name, opts )
format("/Matrix [%s %s %s]", opts.matrix or "1 0 0 1", opts.xshift or 0, opts.yshift or 0),
}
local optres = opts.resources or ""
- local t = gather_resources(false, optres)
- optres = optres .. tableconcat(t)
+ optres = optres .. gather_resources(optres)
if pdfmode then
if opts.bbox then
attr[#attr+1] = format("/BBox [%s]", opts.bbox)
@@ -3259,15 +3333,14 @@ function luamplib.registerpattern ( boxid, name, opts )
local objname = "@mplibpattern"..name
local metric = format("bbox %s", opts.bbox or format("0 0 %s %s",wd,hd))
texsprint {
- [[\ifvmode\nointerlineskip\fi]],
- format([[\hbox to0pt{\vbox to0pt{\hsize=\wd %i\vss\noindent]], boxid), -- force horiz mode?
- [[\special{pdf:bcontent}]],
- [[\special{pdf:bxobj ]], objname, format(" %s}", metric),
- format([[\raise\dp %i\box %i]], boxid, boxid),
- format([[\special{pdf:put @resources <<%s>>}]], optres),
- [[\special{pdf:exobj <<]], tableconcat(attr), ">>}",
- [[\special{pdf:econtent}]],
- [[\par}\hss}]],
+ "\\ifvmode\\nointerlineskip\\fi\\vbox to0pt{\\vss\\hbox to0pt{",
+ "\\special{pdf:bcontent}",
+ "\\special{pdf:bxobj ", objname, " ", metric, "}",
+ "\\raise\\dp ", boxid, "\\box ", boxid,
+ "\\special{pdf:put @resources <<", optres, ">>}",
+ "\\special{pdf:exobj <<", tableconcat(attr), ">>}",
+ "\\special{pdf:econtent}",
+ "\\hss}}",
}
patterns[#patterns+1] = objname
patterns[name] = { id = #patterns, colored = opts.colored }
@@ -3421,12 +3494,14 @@ end
%
% Transparency Group
% \begin{macrocode}
-pdfetcs.tr_group = { }
+pdfetcs.tr_group = { shifts = { } }
+luamplib.trgroupshifts = pdfetcs.tr_group.shifts
local function do_preobj_GRP (object, prescript)
local grstate = prescript and prescript.gr_state
if not grstate then return end
local trgroup = pdfetcs.tr_group
if grstate == "start" then
+ trgroup.name = prescript.mplibgroupname or "lastmplibgroup"
trgroup.isolated, trgroup.knockout = false, false
for _,v in ipairs(prescript.gr_type:explode",+") do
trgroup[v] = true
@@ -3442,7 +3517,7 @@ local function do_preobj_GRP (object, prescript)
elseif grstate == "stop" then
local llx,lly,urx,ury = tableunpack(trgroup.bbox)
local grattr = format("/Group<</S/Transparency/I %s/K %s>>",trgroup.isolated,trgroup.knockout)
- local res = tableconcat(gather_resources(true))
+ local res = gather_resources()
put2output(tableconcat{
"\\egroup",
format("\\wd\\mplibscratchbox %fbp", urx-llx),
@@ -3457,6 +3532,9 @@ local function do_preobj_GRP (object, prescript)
[[\setbox\mplibscratchbox\hbox{\useboxresource\lastsavedboxresourceindex}]],
[[\wd\mplibscratchbox 0pt\ht\mplibscratchbox 0pt\dp\mplibscratchbox 0pt]],
[[\box\mplibscratchbox\endgroup]],
+ "\\expandafter\\xdef\\csname luamplib.group.", trgroup.name, "\\endcsname{",
+ "\\noexpand\\mplibstarttoPDF{",llx,"}{",lly,"}{",urx,"}{",ury,"}",
+ "\\useboxresource \\the\\lastsavedboxresourceindex\\noexpand\\mplibstoptoPDF}",
})
else
trgroup.cnt = (trgroup.cnt or 0) + 1
@@ -3467,8 +3545,12 @@ local function do_preobj_GRP (object, prescript)
"\\special{pdf:put @resources <<", res, ">>}",
"\\special{pdf:exobj <<", grattr, ">>}",
"\\special{pdf:uxobj ", objname, "}\\endgroup",
+ "\\expandafter\\gdef\\csname luamplib.group.", trgroup.name, "\\endcsname{",
+ "\\mplibstarttoPDF{",llx,"}{",lly,"}{",urx,"}{",ury,"}",
+ "\\special{pdf:uxobj ", objname, "}\\mplibstoptoPDF}",
})
end
+ trgroup.shifts[trgroup.name] = { llx, lly }
end
return grstate
end
@@ -3894,7 +3976,7 @@ end
\else
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{luamplib}
- [2024/07/17 v2.34.0 mplib package for LuaTeX]
+ [2024/07/19 v2.34.1 mplib package for LuaTeX]
\ifx\newluafunction\@undefined
\input ltluatex
\fi
@@ -3958,6 +4040,11 @@ end
\def\mplibputtextbox#1{\vbox to 0pt{\vss\hbox to 0pt{\raise\dp#1\copy#1\hss}}}
% \end{macrocode}
%
+% use Transparency Group
+% \begin{macrocode}
+\protected\def\usemplibgroup#1{\csname luamplib.group.#1\endcsname}
+% \end{macrocode}
+%
% Patterns
% \begin{macrocode}
{\def\:{\global\let\mplibsptoken= } \: }
diff --git a/macros/luatex/generic/luamplib/luamplib.pdf b/macros/luatex/generic/luamplib/luamplib.pdf
index d59201ed00..89fcd4e27a 100644
--- a/macros/luatex/generic/luamplib/luamplib.pdf
+++ b/macros/luatex/generic/luamplib/luamplib.pdf
Binary files differ
diff --git a/macros/luatex/generic/luamplib/test-luamplib-latex.tex b/macros/luatex/generic/luamplib/test-luamplib-latex.tex
index b2f2f63cb7..24a23f1b19 100644
--- a/macros/luatex/generic/luamplib/test-luamplib-latex.tex
+++ b/macros/luatex/generic/luamplib/test-luamplib-latex.tex
@@ -271,6 +271,7 @@ draw mpliboutlinetext.b ("$\displaystyle\frac{1}{1-x^2}$")
picture tex;
tex = mpliboutlinetext.p ("\bfseries \TeX");
for i=1 upto mpliboutlinenum:
+ draw image(
j:=0;
for item within mpliboutlinepic[i]:
j:=j+1;
@@ -279,12 +280,13 @@ draw mpliboutlinetext.b ("$\displaystyle\frac{1}{1-x^2}$")
withpostscript "collect"
else:
withpattern "pattuncolored"
- withfademethod "linear"
- withfadebbox (10 llcorner mpliboutlinepic[i], 10 urcorner mpliboutlinepic[i])
withpen pencircle scaled 1/2
withcolor (i/4)[red,blue]
fi;
endfor
+ )
+ withfademethod "linear"
+ ;
endfor
\endmpfig
\par\leavevmode
@@ -295,7 +297,7 @@ draw mpliboutlinetext.b ("$\displaystyle\frac{1}{1-x^2}$")
draw mill
withfademethod "circular"
withfadecenter (center mill, center mill)
- withfaderadius (20, abs(lrcorner mill - llcorner mill)/2)
+ withfaderadius (30, abs(lrcorner mill - llcorner mill)/2)
withfadeopacity (1, 0)
;
\endmpfig
@@ -318,6 +320,7 @@ draw mpliboutlinetext.b ("$\displaystyle\frac{1}{1-x^2}$")
;
)
asgroup "#1"
+ withgroupname "test:#1"
withtransparency (1,.5)
;
currentpicture := currentpicture scaled 3/4;
@@ -326,6 +329,9 @@ draw mpliboutlinetext.b ("$\displaystyle\frac{1}{1-x^2}$")
\hbox{\test{isolated,knockout}\,\test{isolated}\vbox to\MPheight{\vss\hbox{~isolated}\vss}}%
\hbox{\test{knockout}\,\test{}}%
\hbox to\MPwidth{\hss knockout\hss}%
+\leavevmode
+\mpfig usemplibgroup "test:isolated,knockout" scaled 2/3 rotated 15 ; \endmpfig
+\usemplibgroup{test:isolated,knockout}%
\tracingcommands0
\vskip 2\baselineskip
diff --git a/macros/luatex/generic/luamplib/test-luamplib-plain.tex b/macros/luatex/generic/luamplib/test-luamplib-plain.tex
index 622932ca10..54ddf4a018 100644
--- a/macros/luatex/generic/luamplib/test-luamplib-plain.tex
+++ b/macros/luatex/generic/luamplib/test-luamplib-plain.tex
@@ -263,6 +263,7 @@ draw mpliboutlinetext.b ("$\overbrace{x+\cdots+x}^k$")
\mpfig
picture tex;
tex = mpliboutlinetext.p ("\bf \TeX");
+ draw image(
for i=1 upto mpliboutlinenum:
j:=0;
for item within mpliboutlinepic[i]:
@@ -272,16 +273,19 @@ draw mpliboutlinetext.b ("$\overbrace{x+\cdots+x}^k$")
withpostscript "collect"
else:
withpattern "pattuncolored"
- withfademethod "linear"
- withfadebbox (10 llcorner tex, 10 urcorner tex)
withpen pencircle scaled 1/2
withcolor (i/4)[red,blue]
fi;
endfor
endfor
+ )
+ withfademethod "linear"
+ ;
\endmpfig
+\par\leavevmode
\mpfig
fill fullcircle scaled 125 withcolor 2/3[blue,white];
+fill fullcircle scaled 80 withcolor 2/3[red,white];
draw image(
draw (left--right) rotated 45 scaled 50
withpen pencircle scaled 20
@@ -291,9 +295,18 @@ draw image(
;
)
asgroup ""
+ withgroupname "testTRgroup"
withprescript "tr_transparency=.3"
;
\endmpfig
+\mpfig
+fill fullcircle scaled 125 withcolor 2/3[red,white];
+fill fullcircle scaled 80 withcolor 2/3[blue,white];
+usemplibgroup "testTRgroup"
+ withfademethod "circular"
+ withfaderadius (0,60)
+ ;
+\endmpfig
\tracingcommands0
\vskip 2\baselineskip