texlive[71964] Master/texmf-dist: luamplib (3aug24)

commits+karl at tug.org commits+karl at tug.org
Sat Aug 3 22:28:27 CEST 2024


Revision: 71964
          https://tug.org/svn/texlive?view=revision&revision=71964
Author:   karl
Date:     2024-08-03 22:28:27 +0200 (Sat, 03 Aug 2024)
Log Message:
-----------
luamplib (3aug24)

Modified Paths:
--------------
    trunk/Master/texmf-dist/doc/luatex/luamplib/NEWS
    trunk/Master/texmf-dist/doc/luatex/luamplib/luamplib.pdf
    trunk/Master/texmf-dist/source/luatex/luamplib/luamplib.dtx
    trunk/Master/texmf-dist/tex/luatex/luamplib/luamplib.lua
    trunk/Master/texmf-dist/tex/luatex/luamplib/luamplib.sty

Modified: trunk/Master/texmf-dist/doc/luatex/luamplib/NEWS
===================================================================
--- trunk/Master/texmf-dist/doc/luatex/luamplib/NEWS	2024-08-03 20:28:16 UTC (rev 71963)
+++ trunk/Master/texmf-dist/doc/luatex/luamplib/NEWS	2024-08-03 20:28:27 UTC (rev 71964)
@@ -1,5 +1,11 @@
                        History of the luamplib package
 
+2024/08/03 2.34.5
+   * provide 'withgroupbbox' macro for transparency group to enable users to
+   control the bounding box
+
+   * write down the width/height/depth values of mplibgroup to the log file
+
 2024/07/31 2.34.4
    * 'withpattern' operator accepts a <textual picture> as well as a <path>
    for its operand. Thus users can give pattern effect to the result of btex

Modified: trunk/Master/texmf-dist/doc/luatex/luamplib/luamplib.pdf
===================================================================
(Binary files differ)

Modified: trunk/Master/texmf-dist/source/luatex/luamplib/luamplib.dtx
===================================================================
--- trunk/Master/texmf-dist/source/luatex/luamplib/luamplib.dtx	2024-08-03 20:28:16 UTC (rev 71963)
+++ trunk/Master/texmf-dist/source/luatex/luamplib/luamplib.dtx	2024-08-03 20:28:27 UTC (rev 71964)
@@ -85,7 +85,7 @@
 %<*driver>
 \NeedsTeXFormat{LaTeX2e}
 \ProvidesFile{luamplib.drv}%
-  [2024/07/31 v2.34.4 Interface for using the mplib library]%
+  [2024/08/03 v2.34.5 Interface for using the mplib library]%
 \documentclass{ltxdoc}
 \usepackage{metalogo,multicol,xspace}
 \usepackage[x11names]{xcolor}
@@ -155,7 +155,7 @@
 % \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/31 v2.34.4}
+% \date{2024/08/03 v2.34.5}
 %
 % \maketitle
 %
@@ -630,7 +630,7 @@
 %\end{verbatim}
 %   After the process, |mpliboutlinepic[]|
 %   and |mpliboutlinenum| will be preserved as global variables;
-%   |mpliboutlinepic[1]| \ldots{} |mpliboutlinepic[mpliboutlinenum]|
+%   |mpliboutlinepic[1]| |...| |mpliboutlinepic[mpliboutlinenum]|
 %   will be an array of images each of which containing a glyph or a rule.
 %
 %   \textsc{n.b.} As Unicode grapheme cluster is not considered in the array, a unit that must be
@@ -642,11 +642,11 @@
 %   \cs{mppattern\{<name>\}} |...| \cs{endmppattern} define a tiling pattern
 %   associated with the |<name>|.
 %   \metapost operator |withpattern|, the syntax being
-%   \emph{<path>}\textbar\emph{<textual picture>} |withpattern| \emph{<string>},
+%   \emph{<path>}\,\textbar\,\emph{<textual picture>} |withpattern| \emph{<string>},
 %   will return a \metapost picture which fills
 %   the given path or text with a tiling pattern of the |<name>|
 %   by replicating it horizontally and vertically.
-%   The \emph{textual picture} here means any text typeset by \TeX, normally the result
+%   The \emph{textual picture} here means any text typeset by \TeX, mostly the result
 %   of the |btex| command (though technically this is not a true textual picture)
 %   or the |infont| operator.
 %
@@ -693,8 +693,8 @@
 %     |ystep|    &\emph{number} & vertical spacing between pattern cells\\
 %     |xshift|   &\emph{number} & horizontal shifting of pattern cells\\
 %     |yshift|   &\emph{number} & vertical shifting of pattern cells\\
+%     |bbox|     &\emph{table} or \emph{string} & |llx|, |lly|, |urx|, |ury| values\kern1pt*\\
 %     |matrix|   &\emph{table} or \emph{string} & |xx|, |yx|, |xy|, |yy| values\kern1pt* or MP transform code\\
-%     |bbox|     &\emph{table} or \emph{string} & |llx|, |lly|, |urx|, |ury| values\kern1pt*\\
 %     |resources|&\emph{string} & PDF resources if needed\\
 %     |colored| or |coloured| &\emph{boolean}& |false| for uncolored pattern. default: |true|\\\hline
 %                &                & \small *\,in string type, numbers are separated by spaces\\
@@ -793,6 +793,8 @@
 %     sets the bounding box of the fading area, default value being |(llcorner p, urcorner p)|.
 %     Though this option is not needed in most cases, there could be cases when users want to
 %     explicitly control the bounding box.
+%     Particularly, see the description \hyperlink{withgroupbbox}{below}
+%     on the analogous macro |withgroupbbox|.
 %   \end{description}
 %   An example:
 %\begin{verbatim}
@@ -842,6 +844,17 @@
 %   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.
+%
+% \item[|withgroupbbox (|\emph{pair}|,|\emph{pair}|)|]
+%   \hypertarget{withgroupbbox}{}\relax
+%   sets the bounding box of the transparency group,
+%   default value being |(llcorner p, urcorner p)|.
+%   This option might be needed especially when you draw with a thick pen
+%   a path that touches the boundary;
+%   you would probably want to append to the sentense
+%   `|withgroupbbox| |(bot| |lft| |llcorner| |p,| |top| |rt| |urcorner| |p)|',
+%   supposing that the pen was selected by the |pickup| command.
+%
 % \end{description}
 % An example showing the difference between the \TeX\ and \metapost commands:
 %\begin{verbatim}
@@ -849,7 +862,8 @@
 %     draw image(
 %       fill fullcircle scaled 100 shifted 25right withcolor .5[blue,white];
 %       fill fullcircle scaled 100 withcolor .5[red,white] ;
-%     ) asgroup "" withgroupname "mygroup";
+%     ) asgroup ""
+%       withgroupname "mygroup";
 %     draw (left--right) scaled 10;
 %     draw (up--down) scaled 10;
 %   \endmpfig
@@ -883,8 +897,9 @@
 %       asgroup="",
 %     ]
 %     \mpfig                            % or any other TeX code
-%       draw (left--right) scaled 30 rotated 45 withpen pencircle scaled 10;
-%       draw (left--right) scaled 30 rotated -45 withpen pencircle scaled 10;
+%       pickup pencircle scaled 10;
+%       draw (left--right) scaled 30 rotated 45 ;
+%       draw (left--right) scaled 30 rotated -45 ;
 %     \endmpfig
 %   \endmplibgroup                      % or \end{mplibgroup}
 %
@@ -891,11 +906,15 @@
 %   \usemplibgroup{mygrx}
 %
 %   \mpfig
-%     usemplibgroup "mygrx" scaled 1.5 withprescript "tr_transparency=0.5";
+%     usemplibgroup "mygrx"
+%       scaled 1.5
+%       withprescript "tr_transparency=0.5" ;
 %   \endmpfig
 %\end{verbatim}
+%
 % Availabe options, much fewer than those for \cs{mppattern},
 % are listed in Table~\ref{tab:mplibgroupoptions}.
+% Again, the width/height/depth values of the mplibgroup will be written down into the log file.
 % \begin{table}
 % \centering
 % \caption{options for \cs{mplibgroup}}\label{tab:mplibgroupoptions}
@@ -918,8 +937,7 @@
 % Thus the individual objects, not the XObject as a whole, will be affected
 % by outer transparency command.
 %
-% As shown in the example, you can reuse the transparency group or the normal form XObject
-% once defined
+% As shown in the example, you can reuse the mplibgroup once defined
 % using the \TeX\ command \cs{usemplibgroup} or
 % the \metapost command |usemplibgroup|.
 % The behavior of these commands is the same as that described \hyperlink{usemplibgroup}{above}.
@@ -1010,8 +1028,8 @@
 
 luatexbase.provides_module {
   name          = "luamplib",
-  version       = "2.34.4",
-  date          = "2024/07/31",
+  version       = "2.34.5",
+  date          = "2024/08/03",
   description   = "Lua package to typeset Metapost with LuaTeX's MPLib.",
 }
 
@@ -1883,6 +1901,7 @@
 %
 % Remove trailing zeros for smaller PDF
 %    \begin{macrocode}
+local decimals = "%.%d+"
 local function rmzeros(str) return str:gsub("%.?0+$","") end
 
 %    \end{macrocode}
@@ -1921,7 +1940,7 @@
     fmt = "pdf:content "..fmt
     pl = node.new("whatsit","special")
   end
-  pl.data = fmt:format(line, 0, -dp, wd, ht+dp, "B") :gsub("%.%d+", rmzeros)
+  pl.data = fmt:format(line, 0, -dp, wd, ht+dp, "B") :gsub(decimals,rmzeros)
   local ss = node.new"glue"
   node.setglue(ss, 0, 65536, 65536, 2, 2)
   pl.next = ss
@@ -2009,6 +2028,9 @@
 local function graphictextcolor (col, filldraw)
   if col:find"^[%d%.:]+$" then
     col = col:explode":"
+    for i=1,#col do
+      col[i] = format("%.3f", col[i])
+    end
     if pdfmode then
       local op = #col == 4 and "k" or #col == 3 and "rg" or "g"
       col[#col+1] = filldraw == "fill" and op or op:upper()
@@ -2663,10 +2685,10 @@
   fi
     withprescript "mplibfadetype=" & s
     withprescript "mplibfadebbox=" &
-      decimal xpart llcorner p & ":" &
-      decimal ypart llcorner p & ":" &
-      decimal xpart urcorner p & ":" &
-      decimal ypart urcorner p
+      decimal (xpart llcorner p -1/4) & ":" &
+      decimal (ypart llcorner p -1/4) & ":" &
+      decimal (xpart urcorner p +1/4) & ":" &
+      decimal (ypart urcorner p +1/4)
 enddef;
 def withfadeopacity (expr a,b) =
   withprescript "mplibfadeopacity=" &
@@ -2695,7 +2717,12 @@
 enddef;
 primarydef p asgroup s =
   image(
-    fill llcorner p--lrcorner p--urcorner p--ulcorner p--cycle
+    draw center p
+      withprescript "mplibgroupbbox=" &
+        decimal (xpart llcorner p -1/4) & ":" &
+        decimal (ypart llcorner p -1/4) & ":" &
+        decimal (xpart urcorner p +1/4) & ":" &
+        decimal (ypart urcorner p +1/4)
       withprescript "gr_state=start"
       withprescript "gr_type=" & s;
     draw p;
@@ -2702,6 +2729,13 @@
     draw center p withprescript "gr_state=stop";
   )
 enddef;
+def withgroupbbox (expr a,b) =
+  withprescript "mplibgroupbbox=" &
+    decimal xpart a & ":" &
+    decimal ypart a & ":" &
+    decimal xpart b & ":" &
+    decimal ypart b
+enddef;
 def withgroupname expr s =
   withprescript "mplibgroupname=" & s
 enddef;
@@ -2822,21 +2856,12 @@
 %
 %    For parsing |prescript| materials.
 %    \begin{macrocode}
-local further_split_keys = {
-  mplibtexboxid = true,
-  sh_color_a    = true,
-  sh_color_b    = true,
-}
 local function script2table(s)
   local t = {}
   for _,i in ipairs(s:explode("\13+")) do
     local k,v = i:match("(.-)=(.*)") -- v may contain = or empty.
     if k and v and k ~= "" and not t[k] then
-      if further_split_keys[k] or further_split_keys[k:sub(1,10)] then
-        t[k] = v:explode(":")
-      else
-        t[k] = v
-      end
+      t[k] = v
     end
   end
   return t
@@ -2864,7 +2889,7 @@
 %    in the argument of pdfliteral.
 %    \begin{macrocode}
 local function pdf_literalcode (...)
-  put2output{ -2, format(...) :gsub("%.%d+", rmzeros) }
+  put2output{ -2, format(...) :gsub(decimals,rmzeros) }
 end
 local start_pdf_code = pdfmode
   and function() pdf_literalcode"q" end
@@ -2879,7 +2904,7 @@
 %    |textext(...)| or |TEX(...)|, all being the same internally.
 %    \begin{macrocode}
 local function put_tex_boxes (object,prescript)
-  local box = prescript.mplibtexboxid
+  local box = prescript.mplibtexboxid:explode":"
   local n,tw,th = box[1],tonumber(box[2]),tonumber(box[3])
   if n and tw and th then
     local op = object.path
@@ -3067,9 +3092,9 @@
     local key, on, os, new
     local mode = prescript.tr_alternative or 1
     mode = transparancy_modes[tonumber(mode)] or mode
+    opaq = format("%.3f", opaq) :gsub(decimals,rmzeros)
     for i,v in ipairs{ {mode,opaq},{"Normal",1} } do
-      mode, opaq = v[1], v[2]
-      os = format("<</BM/%s/ca %.3f/CA %.3f/AIS false>>",mode,opaq,opaq) :gsub("%.%d+", rmzeros)
+      os = format("<</BM/%s/ca %s/CA %s/AIS false>>",v[1],v[2],v[2])
       on, new = update_pdfobjs(os)
       key = add_extgs_resources(on,new)
       if i == 1 then
@@ -3086,16 +3111,24 @@
 %    Shading with \emph{metafun} format.
 %    \begin{macrocode}
 local function sh_pdfpageresources(shtype,domain,colorspace,ca,cb,coordinates,steps,fractions)
+  for _,v in ipairs{ca,cb} do
+    for i,vv in ipairs(v) do
+      for ii,vvv in ipairs(vv) do
+        v[i][ii] = tonumber(vvv) and format("%.3f",vvv) or vvv
+      end
+    end
+  end
   local fun2fmt,os = "<</FunctionType 2/Domain[%s]/C0[%s]/C1[%s]/N 1>>"
   if steps > 1 then
     local list,bounds,encode = { },{ },{ }
     for i=1,steps do
       if i < steps then
-        bounds[i] = fractions[i] or 1
+        bounds[i] = format("%.3f", fractions[i] or 1)
       end
       encode[2*i-1] = 0
       encode[2*i]   = 1
       os = fun2fmt:format(domain,tableconcat(ca[i],' '),tableconcat(cb[i],' '))
+        :gsub(decimals,rmzeros)
       list[i] = format(pdfetcs.resfmt, update_pdfobjs(os))
     end
     os = tableconcat {
@@ -3104,9 +3137,10 @@
       format("/Encode[%s]",    tableconcat(encode,' ')),
       format("/Functions[%s]", tableconcat(list,  ' ')),
       format("/Domain[%s]>>",  domain),
-    }
+    } :gsub(decimals,rmzeros)
   else
     os = fun2fmt:format(domain,tableconcat(ca[1],' '),tableconcat(cb[1],' '))
+      :gsub(decimals,rmzeros)
   end
   local objref = format(pdfetcs.resfmt, update_pdfobjs(os))
   os = tableconcat {
@@ -3113,9 +3147,9 @@
     format("<</ShadingType %i", shtype),
     format("/ColorSpace %s",    colorspace),
     format("/Function %s",      objref),
-    format("/Coords[%s]",       coordinates :gsub("%.%d+", rmzeros)),
+    format("/Coords[%s]",       coordinates),
     "/Extend[true true]/AntiAlias true>>",
-  }
+  } :gsub(decimals,rmzeros)
   local on, new = update_pdfobjs(os)
   if new then
     local key, val = format("MPlibSh%s", on), format(pdfetcs.resfmt, on)
@@ -3188,15 +3222,15 @@
       end
     end
     local ca, cb, colorspace, steps, fractions
-    ca = { prescript.sh_color_a_1 or prescript.sh_color_a or {0} }
-    cb = { prescript.sh_color_b_1 or prescript.sh_color_b or {1} }
+    ca = { (prescript.sh_color_a_1 or prescript.sh_color_a or "0"):explode":" }
+    cb = { (prescript.sh_color_b_1 or prescript.sh_color_b or "1"):explode":" }
     steps = tonumber(prescript.sh_step) or 1
     if steps > 1 then
       fractions = { prescript.sh_fraction_1 or 0 }
       for i=2,steps do
         fractions[i] = prescript[format("sh_fraction_%i",i)] or (i/steps)
-        ca[i] = prescript[format("sh_color_a_%i",i)] or {0}
-        cb[i] = prescript[format("sh_color_b_%i",i)] or {1}
+        ca[i] = (prescript[format("sh_color_a_%i",i)] or "0"):explode":"
+        cb[i] = (prescript[format("sh_color_b_%i",i)] or "1"):explode":"
       end
     end
     if prescript.mplib_spotcolor then
@@ -3334,9 +3368,9 @@
 end
 function luamplib.registerpattern ( boxid, name, opts )
   local box = texgetbox(boxid)
-  local wd = format("%.3f",box.width/factor) :gsub("%.%d+", rmzeros)
-  local hd = format("%.3f",(box.height+box.depth)/factor) :gsub("%.%d+", rmzeros)
-  info("w/h/d of '%s': %s %s 0", name, wd, hd)
+  local wd = format("%.3f",box.width/factor)
+  local hd = format("%.3f",(box.height+box.depth)/factor)
+  info("w/h/d of pattern '%s': %s 0", name, format("%s %s",wd, hd):gsub(decimals,rmzeros))
   if opts.xstep == 0 then opts.xstep = nil end
   if opts.ystep == 0 then opts.ystep = nil end
   if opts.colored == nil then
@@ -3351,9 +3385,9 @@
     local data = format("mplibtransformmatrix(%s);",opts.matrix)
     process(data,"@mplibtransformmatrix")
     local t = luamplib.transformmatrix
-    opts.matrix = format("%s %s %s %s", t[1], t[2], t[3], t[4])
-    opts.xshift = opts.xshift or t[5]
-    opts.yshift = opts.yshift or t[6]
+    opts.matrix = format("%f %f %f %f", t[1], t[2], t[3], t[4])
+    opts.xshift = opts.xshift or format("%f",t[5])
+    opts.yshift = opts.yshift or format("%f",t[6])
   end
   local attr = {
     "/Type/Pattern",
@@ -3371,7 +3405,8 @@
     if opts.bbox then
       attr[#attr+1] = format("/BBox[%s]", opts.bbox)
     end
-    local index = tex.saveboxresource(boxid, tableconcat(attr), optres, true, opts.bbox and 4 or 1)
+    attr = tableconcat(attr) :gsub(decimals,rmzeros)
+    local index = tex.saveboxresource(boxid, attr, optres, true, opts.bbox and 4 or 1)
     patterns[name] = { id = index, colored = opts.colored }
   else
     local cnt = #patterns + 1
@@ -3503,8 +3538,9 @@
   on = sh_pdfpageresources(fd_type, "0 1", "/DeviceGray", {{opaq[1]}}, {{opaq[2]}}, coords, 1)
   os = format("<</PatternType 2/Shading %s>>", format(pdfetcs.resfmt, on))
   on = update_pdfobjs(os)
-  bbox = format("0 0 %f %f", bbox[3]+dx, bbox[4]+dy) :gsub("%.%d+", rmzeros)
+  bbox = format("0 0 %f %f", bbox[3]+dx, bbox[4]+dy)
   local streamtext = format("q /Pattern cs/MPlibFd%s scn %s re f Q", on, bbox)
+    :gsub(decimals,rmzeros)
   os = format("<</Pattern<</MPlibFd%s %s>>>>", on, format(pdfetcs.resfmt, on))
   on = update_pdfobjs(os)
   local resources = format(pdfetcs.resfmt, on)
@@ -3511,11 +3547,11 @@
   on = update_pdfobjs"<</S/Transparency/CS/DeviceGray>>"
   local attr = tableconcat{
     "/Subtype/Form",
-    format("/BBox[%s]", bbox),
-    format("/Matrix[1 0 0 1 %s]", format("%f %f", -dx,-dy) :gsub("%.%d+", rmzeros)),
-    format("/Resources %s", resources),
+    "/BBox[", bbox, "]",
+    "/Matrix[1 0 0 1 ", format("%f %f", -dx,-dy), "]",
+    "/Resources ", resources,
     "/Group ", format(pdfetcs.resfmt, on),
-  }
+  } :gsub(decimals,rmzeros)
   on = update_pdfobjs(attr, streamtext)
   os = "<</SMask<</S/Luminosity/G " .. format(pdfetcs.resfmt, on) .. ">>>>"
   on, new = update_pdfobjs(os)
@@ -3542,13 +3578,7 @@
     for _,v in ipairs(prescript.gr_type:explode",+") do
       trgroup[v] = true
     end
-    local p = object.path
-    trgroup.bbox = {
-      math.min(p[1].x_coord, p[2].x_coord, p[3].x_coord, p[4].x_coord),
-      math.min(p[1].y_coord, p[2].y_coord, p[3].y_coord, p[4].y_coord),
-      math.max(p[1].x_coord, p[2].x_coord, p[3].x_coord, p[4].x_coord),
-      math.max(p[1].y_coord, p[2].y_coord, p[3].y_coord, p[4].y_coord),
-    }
+    trgroup.bbox = prescript.mplibgroupbbox:explode":"
     put2output[[\begingroup\setbox\mplibscratchbox\hbox\bgroup]]
   elseif grstate == "stop" then
     local llx,lly,urx,ury = tableunpack(trgroup.bbox)
@@ -3560,7 +3590,7 @@
     })
     local grattr = format("/Group<</S/Transparency/I %s/K %s>>",trgroup.isolated,trgroup.knockout)
     local res = gather_resources()
-    local bbox = format("%f %f %f %f", llx,lly,urx,ury) :gsub("%.%d+", rmzeros)
+    local bbox = format("%f %f %f %f", llx,lly,urx,ury) :gsub(decimals,rmzeros)
     if pdfmode then
       put2output(tableconcat{
         "\\saveboxresource type 2 attr{/Type/XObject/Subtype/Form/FormType 1",
@@ -3593,6 +3623,7 @@
 end
 function luamplib.registergroup (boxid, name, opts)
   local box = texgetbox(boxid)
+  local wd, ht, dp = node.getwhd(box)
   local res = (opts.resources or "") .. gather_resources()
   local attr = { "/Type/XObject/Subtype/Form/FormType 1" }
   if type(opts.matrix) == "table" then opts.matrix = tableconcat(opts.matrix," ") end
@@ -3600,15 +3631,15 @@
   if opts.matrix and opts.matrix:find"%a" then
     local data = format("mplibtransformmatrix(%s);",opts.matrix)
     process(data,"@mplibtransformmatrix")
-    opts.matrix = tableconcat(luamplib.transformmatrix, ' ')
+    opts.matrix = format("%f %f %f %f %f %f",tableunpack(luamplib.transformmatrix))
   end
   local grtype = 3
   if opts.bbox then
-    attr[#attr+1] = format("/BBox[%s]", opts.bbox :gsub("%.%d+", rmzeros))
+    attr[#attr+1] = format("/BBox[%s]", opts.bbox)
     grtype = 2
   end
   if opts.matrix then
-    attr[#attr+1] = format("/Matrix[%s]", opts.matrix :gsub("%.%d+", rmzeros))
+    attr[#attr+1] = format("/Matrix[%s]", opts.matrix)
     grtype = opts.bbox and 4 or 1
   end
   if opts.asgroup then
@@ -3618,13 +3649,15 @@
   end
   local trgroup = pdfetcs.tr_group
   trgroup.shifts[name] = { get_macro'MPllx', get_macro'MPlly' }
+  local whd
   if pdfmode then
-    local index = tex.saveboxresource(boxid, tableconcat(attr), res, true, grtype)
+    attr = tableconcat(attr) :gsub(decimals,rmzeros)
+    local index = tex.saveboxresource(boxid, attr, res, true, grtype)
     token.set_macro("luamplib.group."..name, "\\useboxresource "..index, "global")
+    whd = format("%.3f %.3f 0", wd/factor, (ht+dp)/factor) :gsub(decimals,rmzeros)
   else
     trgroup.cnt = (trgroup.cnt or 0) + 1
     local objname = format("@mplibtrgr%s", trgroup.cnt)
-    local wd, ht, dp = node.getwhd(box)
     texsprint {
       "\\expandafter\\newbox\\csname luamplib.groupbox.", trgroup.cnt, "\\endcsname",
       "\\global\\setbox\\csname luamplib.groupbox.", trgroup.cnt, "\\endcsname",
@@ -3643,7 +3676,9 @@
       "\\dp\\mplibscratchbox ", dp, "sp",
       "\\box\\mplibscratchbox\\endgroup",
     }, "global")
+    whd = format("%.3f %.3f %.3f", wd/factor, ht/factor, dp/factor) :gsub(decimals,rmzeros)
   end
+  info("w/h/d of group '%s': %s", name, whd)
 end
 
 local function stop_special_effects(fade,opaq,over)
@@ -4070,7 +4105,7 @@
 %    \begin{macrocode}
   \NeedsTeXFormat{LaTeX2e}
   \ProvidesPackage{luamplib}
-    [2024/07/31 v2.34.4 mplib package for LuaTeX]
+    [2024/08/03 v2.34.5 mplib package for LuaTeX]
 \fi
 \ifdefined\newluafunction\else
   \input ltluatex

Modified: trunk/Master/texmf-dist/tex/luatex/luamplib/luamplib.lua
===================================================================
--- trunk/Master/texmf-dist/tex/luatex/luamplib/luamplib.lua	2024-08-03 20:28:16 UTC (rev 71963)
+++ trunk/Master/texmf-dist/tex/luatex/luamplib/luamplib.lua	2024-08-03 20:28:27 UTC (rev 71964)
@@ -11,8 +11,8 @@
 
 luatexbase.provides_module {
   name          = "luamplib",
-  version       = "2.34.4",
-  date          = "2024/07/31",
+  version       = "2.34.5",
+  date          = "2024/08/03",
   description   = "Lua package to typeset Metapost with LuaTeX's MPLib.",
 }
 
@@ -637,6 +637,7 @@
   return colorsplit(res)
 end
 
+local decimals = "%.%d+"
 local function rmzeros(str) return str:gsub("%.?0+$","") end
 
 local emboldenfonts = { }
@@ -671,7 +672,7 @@
     fmt = "pdf:content "..fmt
     pl = node.new("whatsit","special")
   end
-  pl.data = fmt:format(line, 0, -dp, wd, ht+dp, "B") :gsub("%.%d+", rmzeros)
+  pl.data = fmt:format(line, 0, -dp, wd, ht+dp, "B") :gsub(decimals,rmzeros)
   local ss = node.new"glue"
   node.setglue(ss, 0, 65536, 65536, 2, 2)
   pl.next = ss
@@ -759,6 +760,9 @@
 local function graphictextcolor (col, filldraw)
   if col:find"^[%d%.:]+$" then
     col = col:explode":"
+    for i=1,#col do
+      col[i] = format("%.3f", col[i])
+    end
     if pdfmode then
       local op = #col == 4 and "k" or #col == 3 and "rg" or "g"
       col[#col+1] = filldraw == "fill" and op or op:upper()
@@ -1401,10 +1405,10 @@
   fi
     withprescript "mplibfadetype=" & s
     withprescript "mplibfadebbox=" &
-      decimal xpart llcorner p & ":" &
-      decimal ypart llcorner p & ":" &
-      decimal xpart urcorner p & ":" &
-      decimal ypart urcorner p
+      decimal (xpart llcorner p -1/4) & ":" &
+      decimal (ypart llcorner p -1/4) & ":" &
+      decimal (xpart urcorner p +1/4) & ":" &
+      decimal (ypart urcorner p +1/4)
 enddef;
 def withfadeopacity (expr a,b) =
   withprescript "mplibfadeopacity=" &
@@ -1433,7 +1437,12 @@
 enddef;
 primarydef p asgroup s =
   image(
-    fill llcorner p--lrcorner p--urcorner p--ulcorner p--cycle
+    draw center p
+      withprescript "mplibgroupbbox=" &
+        decimal (xpart llcorner p -1/4) & ":" &
+        decimal (ypart llcorner p -1/4) & ":" &
+        decimal (xpart urcorner p +1/4) & ":" &
+        decimal (ypart urcorner p +1/4)
       withprescript "gr_state=start"
       withprescript "gr_type=" & s;
     draw p;
@@ -1440,6 +1449,13 @@
     draw center p withprescript "gr_state=stop";
   )
 enddef;
+def withgroupbbox (expr a,b) =
+  withprescript "mplibgroupbbox=" &
+    decimal xpart a & ":" &
+    decimal ypart a & ":" &
+    decimal xpart b & ":" &
+    decimal ypart b
+enddef;
 def withgroupname expr s =
   withprescript "mplibgroupname=" & s
 enddef;
@@ -1533,21 +1549,12 @@
   process(data, instancename)
 end
 
-local further_split_keys = {
-  mplibtexboxid = true,
-  sh_color_a    = true,
-  sh_color_b    = true,
-}
 local function script2table(s)
   local t = {}
   for _,i in ipairs(s:explode("\13+")) do
     local k,v = i:match("(.-)=(.*)") -- v may contain = or empty.
     if k and v and k ~= "" and not t[k] then
-      if further_split_keys[k] or further_split_keys[k:sub(1,10)] then
-        t[k] = v:explode(":")
-      else
-        t[k] = v
-      end
+      t[k] = v
     end
   end
   return t
@@ -1564,7 +1571,7 @@
   put2output("\\mplibstoptoPDF")
 end
 local function pdf_literalcode (...)
-  put2output{ -2, format(...) :gsub("%.%d+", rmzeros) }
+  put2output{ -2, format(...) :gsub(decimals,rmzeros) }
 end
 local start_pdf_code = pdfmode
   and function() pdf_literalcode"q" end
@@ -1574,7 +1581,7 @@
   or  function() put2output"\\special{pdf:econtent}" end
 
 local function put_tex_boxes (object,prescript)
-  local box = prescript.mplibtexboxid
+  local box = prescript.mplibtexboxid:explode":"
   local n,tw,th = box[1],tonumber(box[2]),tonumber(box[3])
   if n and tw and th then
     local op = object.path
@@ -1750,9 +1757,9 @@
     local key, on, os, new
     local mode = prescript.tr_alternative or 1
     mode = transparancy_modes[tonumber(mode)] or mode
+    opaq = format("%.3f", opaq) :gsub(decimals,rmzeros)
     for i,v in ipairs{ {mode,opaq},{"Normal",1} } do
-      mode, opaq = v[1], v[2]
-      os = format("<</BM/%s/ca %.3f/CA %.3f/AIS false>>",mode,opaq,opaq) :gsub("%.%d+", rmzeros)
+      os = format("<</BM/%s/ca %s/CA %s/AIS false>>",v[1],v[2],v[2])
       on, new = update_pdfobjs(os)
       key = add_extgs_resources(on,new)
       if i == 1 then
@@ -1765,16 +1772,24 @@
 end
 
 local function sh_pdfpageresources(shtype,domain,colorspace,ca,cb,coordinates,steps,fractions)
+  for _,v in ipairs{ca,cb} do
+    for i,vv in ipairs(v) do
+      for ii,vvv in ipairs(vv) do
+        v[i][ii] = tonumber(vvv) and format("%.3f",vvv) or vvv
+      end
+    end
+  end
   local fun2fmt,os = "<</FunctionType 2/Domain[%s]/C0[%s]/C1[%s]/N 1>>"
   if steps > 1 then
     local list,bounds,encode = { },{ },{ }
     for i=1,steps do
       if i < steps then
-        bounds[i] = fractions[i] or 1
+        bounds[i] = format("%.3f", fractions[i] or 1)
       end
       encode[2*i-1] = 0
       encode[2*i]   = 1
       os = fun2fmt:format(domain,tableconcat(ca[i],' '),tableconcat(cb[i],' '))
+        :gsub(decimals,rmzeros)
       list[i] = format(pdfetcs.resfmt, update_pdfobjs(os))
     end
     os = tableconcat {
@@ -1783,9 +1798,10 @@
       format("/Encode[%s]",    tableconcat(encode,' ')),
       format("/Functions[%s]", tableconcat(list,  ' ')),
       format("/Domain[%s]>>",  domain),
-    }
+    } :gsub(decimals,rmzeros)
   else
     os = fun2fmt:format(domain,tableconcat(ca[1],' '),tableconcat(cb[1],' '))
+      :gsub(decimals,rmzeros)
   end
   local objref = format(pdfetcs.resfmt, update_pdfobjs(os))
   os = tableconcat {
@@ -1792,9 +1808,9 @@
     format("<</ShadingType %i", shtype),
     format("/ColorSpace %s",    colorspace),
     format("/Function %s",      objref),
-    format("/Coords[%s]",       coordinates :gsub("%.%d+", rmzeros)),
+    format("/Coords[%s]",       coordinates),
     "/Extend[true true]/AntiAlias true>>",
-  }
+  } :gsub(decimals,rmzeros)
   local on, new = update_pdfobjs(os)
   if new then
     local key, val = format("MPlibSh%s", on), format(pdfetcs.resfmt, on)
@@ -1867,15 +1883,15 @@
       end
     end
     local ca, cb, colorspace, steps, fractions
-    ca = { prescript.sh_color_a_1 or prescript.sh_color_a or {0} }
-    cb = { prescript.sh_color_b_1 or prescript.sh_color_b or {1} }
+    ca = { (prescript.sh_color_a_1 or prescript.sh_color_a or "0"):explode":" }
+    cb = { (prescript.sh_color_b_1 or prescript.sh_color_b or "1"):explode":" }
     steps = tonumber(prescript.sh_step) or 1
     if steps > 1 then
       fractions = { prescript.sh_fraction_1 or 0 }
       for i=2,steps do
         fractions[i] = prescript[format("sh_fraction_%i",i)] or (i/steps)
-        ca[i] = prescript[format("sh_color_a_%i",i)] or {0}
-        cb[i] = prescript[format("sh_color_b_%i",i)] or {1}
+        ca[i] = (prescript[format("sh_color_a_%i",i)] or "0"):explode":"
+        cb[i] = (prescript[format("sh_color_b_%i",i)] or "1"):explode":"
       end
     end
     if prescript.mplib_spotcolor then
@@ -2009,9 +2025,9 @@
 end
 function luamplib.registerpattern ( boxid, name, opts )
   local box = texgetbox(boxid)
-  local wd = format("%.3f",box.width/factor) :gsub("%.%d+", rmzeros)
-  local hd = format("%.3f",(box.height+box.depth)/factor) :gsub("%.%d+", rmzeros)
-  info("w/h/d of '%s': %s %s 0", name, wd, hd)
+  local wd = format("%.3f",box.width/factor)
+  local hd = format("%.3f",(box.height+box.depth)/factor)
+  info("w/h/d of pattern '%s': %s 0", name, format("%s %s",wd, hd):gsub(decimals,rmzeros))
   if opts.xstep == 0 then opts.xstep = nil end
   if opts.ystep == 0 then opts.ystep = nil end
   if opts.colored == nil then
@@ -2026,9 +2042,9 @@
     local data = format("mplibtransformmatrix(%s);",opts.matrix)
     process(data,"@mplibtransformmatrix")
     local t = luamplib.transformmatrix
-    opts.matrix = format("%s %s %s %s", t[1], t[2], t[3], t[4])
-    opts.xshift = opts.xshift or t[5]
-    opts.yshift = opts.yshift or t[6]
+    opts.matrix = format("%f %f %f %f", t[1], t[2], t[3], t[4])
+    opts.xshift = opts.xshift or format("%f",t[5])
+    opts.yshift = opts.yshift or format("%f",t[6])
   end
   local attr = {
     "/Type/Pattern",
@@ -2046,7 +2062,8 @@
     if opts.bbox then
       attr[#attr+1] = format("/BBox[%s]", opts.bbox)
     end
-    local index = tex.saveboxresource(boxid, tableconcat(attr), optres, true, opts.bbox and 4 or 1)
+    attr = tableconcat(attr) :gsub(decimals,rmzeros)
+    local index = tex.saveboxresource(boxid, attr, optres, true, opts.bbox and 4 or 1)
     patterns[name] = { id = index, colored = opts.colored }
   else
     local cnt = #patterns + 1
@@ -2174,8 +2191,9 @@
   on = sh_pdfpageresources(fd_type, "0 1", "/DeviceGray", {{opaq[1]}}, {{opaq[2]}}, coords, 1)
   os = format("<</PatternType 2/Shading %s>>", format(pdfetcs.resfmt, on))
   on = update_pdfobjs(os)
-  bbox = format("0 0 %f %f", bbox[3]+dx, bbox[4]+dy) :gsub("%.%d+", rmzeros)
+  bbox = format("0 0 %f %f", bbox[3]+dx, bbox[4]+dy)
   local streamtext = format("q /Pattern cs/MPlibFd%s scn %s re f Q", on, bbox)
+    :gsub(decimals,rmzeros)
   os = format("<</Pattern<</MPlibFd%s %s>>>>", on, format(pdfetcs.resfmt, on))
   on = update_pdfobjs(os)
   local resources = format(pdfetcs.resfmt, on)
@@ -2182,11 +2200,11 @@
   on = update_pdfobjs"<</S/Transparency/CS/DeviceGray>>"
   local attr = tableconcat{
     "/Subtype/Form",
-    format("/BBox[%s]", bbox),
-    format("/Matrix[1 0 0 1 %s]", format("%f %f", -dx,-dy) :gsub("%.%d+", rmzeros)),
-    format("/Resources %s", resources),
+    "/BBox[", bbox, "]",
+    "/Matrix[1 0 0 1 ", format("%f %f", -dx,-dy), "]",
+    "/Resources ", resources,
     "/Group ", format(pdfetcs.resfmt, on),
-  }
+  } :gsub(decimals,rmzeros)
   on = update_pdfobjs(attr, streamtext)
   os = "<</SMask<</S/Luminosity/G " .. format(pdfetcs.resfmt, on) .. ">>>>"
   on, new = update_pdfobjs(os)
@@ -2209,13 +2227,7 @@
     for _,v in ipairs(prescript.gr_type:explode",+") do
       trgroup[v] = true
     end
-    local p = object.path
-    trgroup.bbox = {
-      math.min(p[1].x_coord, p[2].x_coord, p[3].x_coord, p[4].x_coord),
-      math.min(p[1].y_coord, p[2].y_coord, p[3].y_coord, p[4].y_coord),
-      math.max(p[1].x_coord, p[2].x_coord, p[3].x_coord, p[4].x_coord),
-      math.max(p[1].y_coord, p[2].y_coord, p[3].y_coord, p[4].y_coord),
-    }
+    trgroup.bbox = prescript.mplibgroupbbox:explode":"
     put2output[[\begingroup\setbox\mplibscratchbox\hbox\bgroup]]
   elseif grstate == "stop" then
     local llx,lly,urx,ury = tableunpack(trgroup.bbox)
@@ -2227,7 +2239,7 @@
     })
     local grattr = format("/Group<</S/Transparency/I %s/K %s>>",trgroup.isolated,trgroup.knockout)
     local res = gather_resources()
-    local bbox = format("%f %f %f %f", llx,lly,urx,ury) :gsub("%.%d+", rmzeros)
+    local bbox = format("%f %f %f %f", llx,lly,urx,ury) :gsub(decimals,rmzeros)
     if pdfmode then
       put2output(tableconcat{
         "\\saveboxresource type 2 attr{/Type/XObject/Subtype/Form/FormType 1",
@@ -2260,6 +2272,7 @@
 end
 function luamplib.registergroup (boxid, name, opts)
   local box = texgetbox(boxid)
+  local wd, ht, dp = node.getwhd(box)
   local res = (opts.resources or "") .. gather_resources()
   local attr = { "/Type/XObject/Subtype/Form/FormType 1" }
   if type(opts.matrix) == "table" then opts.matrix = tableconcat(opts.matrix," ") end
@@ -2267,15 +2280,15 @@
   if opts.matrix and opts.matrix:find"%a" then
     local data = format("mplibtransformmatrix(%s);",opts.matrix)
     process(data,"@mplibtransformmatrix")
-    opts.matrix = tableconcat(luamplib.transformmatrix, ' ')
+    opts.matrix = format("%f %f %f %f %f %f",tableunpack(luamplib.transformmatrix))
   end
   local grtype = 3
   if opts.bbox then
-    attr[#attr+1] = format("/BBox[%s]", opts.bbox :gsub("%.%d+", rmzeros))
+    attr[#attr+1] = format("/BBox[%s]", opts.bbox)
     grtype = 2
   end
   if opts.matrix then
-    attr[#attr+1] = format("/Matrix[%s]", opts.matrix :gsub("%.%d+", rmzeros))
+    attr[#attr+1] = format("/Matrix[%s]", opts.matrix)
     grtype = opts.bbox and 4 or 1
   end
   if opts.asgroup then
@@ -2285,13 +2298,15 @@
   end
   local trgroup = pdfetcs.tr_group
   trgroup.shifts[name] = { get_macro'MPllx', get_macro'MPlly' }
+  local whd
   if pdfmode then
-    local index = tex.saveboxresource(boxid, tableconcat(attr), res, true, grtype)
+    attr = tableconcat(attr) :gsub(decimals,rmzeros)
+    local index = tex.saveboxresource(boxid, attr, res, true, grtype)
     token.set_macro("luamplib.group."..name, "\\useboxresource "..index, "global")
+    whd = format("%.3f %.3f 0", wd/factor, (ht+dp)/factor) :gsub(decimals,rmzeros)
   else
     trgroup.cnt = (trgroup.cnt or 0) + 1
     local objname = format("@mplibtrgr%s", trgroup.cnt)
-    local wd, ht, dp = node.getwhd(box)
     texsprint {
       "\\expandafter\\newbox\\csname luamplib.groupbox.", trgroup.cnt, "\\endcsname",
       "\\global\\setbox\\csname luamplib.groupbox.", trgroup.cnt, "\\endcsname",
@@ -2310,7 +2325,9 @@
       "\\dp\\mplibscratchbox ", dp, "sp",
       "\\box\\mplibscratchbox\\endgroup",
     }, "global")
+    whd = format("%.3f %.3f %.3f", wd/factor, ht/factor, dp/factor) :gsub(decimals,rmzeros)
   end
+  info("w/h/d of group '%s': %s", name, whd)
 end
 
 local function stop_special_effects(fade,opaq,over)

Modified: trunk/Master/texmf-dist/tex/luatex/luamplib/luamplib.sty
===================================================================
--- trunk/Master/texmf-dist/tex/luatex/luamplib/luamplib.sty	2024-08-03 20:28:16 UTC (rev 71963)
+++ trunk/Master/texmf-dist/tex/luatex/luamplib/luamplib.sty	2024-08-03 20:28:27 UTC (rev 71964)
@@ -11,7 +11,7 @@
 \ifcsname ProvidesPackage\endcsname
   \NeedsTeXFormat{LaTeX2e}
   \ProvidesPackage{luamplib}
-    [2024/07/31 v2.34.4 mplib package for LuaTeX]
+    [2024/08/03 v2.34.5 mplib package for LuaTeX]
 \fi
 \ifdefined\newluafunction\else
   \input ltluatex



More information about the tex-live-commits mailing list.