From 504ee16abc171d2851d62e7ce9b9774febf766f6 Mon Sep 17 00:00:00 2001 From: Karl Berry Date: Thu, 30 May 2024 19:57:39 +0000 Subject: luamplib (30may24) git-svn-id: svn://tug.org/texlive/trunk@71391 c570f23f-e606-0410-a88d-b1316a301751 --- .../texmf-dist/source/luatex/luamplib/luamplib.dtx | 144 +++++++++++---------- 1 file changed, 75 insertions(+), 69 deletions(-) (limited to 'Master/texmf-dist/source') diff --git a/Master/texmf-dist/source/luatex/luamplib/luamplib.dtx b/Master/texmf-dist/source/luatex/luamplib/luamplib.dtx index eb5ec196ddd..dc4a9c6570f 100644 --- a/Master/texmf-dist/source/luatex/luamplib/luamplib.dtx +++ b/Master/texmf-dist/source/luatex/luamplib/luamplib.dtx @@ -85,7 +85,7 @@ See source file '\inFileName' for licencing and contact information. %<*driver> \NeedsTeXFormat{LaTeX2e} \ProvidesFile{luamplib.drv}% - [2024/05/24 v2.31.1 Interface for using the mplib library]% + [2024/05/30 v2.31.2 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\\ % Maintainer: LuaLaTeX Maintainers --- % Support: \email{lualatex-dev@tug.org}} -% \date{2024/05/24 v2.31.1} +% \date{2024/05/30 v2.31.2} % % \maketitle % @@ -524,31 +524,6 @@ See source file '\inFileName' for licencing and contact information. % Number Rule. As a result, for instance, the area surrounded by inner path of ``O'' % will remain transparent. % -% We can adapt the method used in |mplibdrawglyph| to multiple pictures as if they were -% components of one and the same picture. An example: -% \begin{verbatim} -% \mplibsetformat{metafun} -% \mpfig -% picture Q, u, e; -% Q := mplibglyph "Q" of "Times.ttc(2)" scaled .15; -% u := mplibglyph "u" of "Times.ttc(2)" scaled .15 shifted lrcorner Q; -% e := mplibglyph "e" of "Times.ttc(2)" scaled .15 shifted lrcorner u; -% -% i:=0; -% totallen := length Q + length u + length e; -% for pic=Q, u, e: -% for item within pic: -% i:=i+1; -% fill pathpart item -% if i < totallen: withpostscript "collect"; fi -% endfor -% endfor -% withshademethod "linear" -% withshadedirection (0.5,2.5) -% withshadecolors (.7red,.7yellow); -% \endmpfig -% \end{verbatim} -% % \paragraph{\texttt{mpliboutlinetext}} % From v2.31, we provide a new metapost operator |mpliboutlinetext|, which mimicks % metafun's |outlinetext|. So the syntax is the same as metafun's. See the metafun @@ -559,6 +534,12 @@ See source file '\inFileName' for licencing and contact information. % (withpen pencircle scaled .2 withcolor red) % scaled 2 ; % \end{verbatim} +% After the process of |mpliboutlinetext|, |mpliboutlinepic[]| +% and |mpliboutlinenum| will be preserved as global variables; +% |mpliboutlinepic[1]| \ldots{} |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 +% a single cluster might be separated apart. % % \paragraph{About figure box metrics} % Notice that, after each figure is processed, macro \cs{MPwidth} stores @@ -592,8 +573,8 @@ See source file '\inFileName' for licencing and contact information. luatexbase.provides_module { name = "luamplib", - version = "2.31.1", - date = "2024/05/24", + version = "2.31.2", + date = "2024/05/30", description = "Lua package to typeset Metapost with LuaTeX's MPLib.", } @@ -1596,14 +1577,13 @@ local function embolden (box, curr, fakebold) local f = curr.font local i = emboldenfonts[f] if not i then + local ft = font.getfont(f) or font.getcopy(f) if pdfmode then - local ft = font.getcopy(f) width = ft.size * fakebold / factor * 10 emboldenfonts.width = width ft.mode, ft.width = 2, width i = font.define(ft) else - local ft = font.getfont(f) or font.getcopy(f) if ft.format ~= "opentype" and ft.format ~= "truetype" then goto skip_type1 end @@ -1818,7 +1798,7 @@ end % % mpliboutlinetext : based on mkiv's font-mps.lua % \begin{macrocode} -local rulefmt = "mplibpic[%i]:=image(addto currentpicture contour \z +local rulefmt = "mpliboutlinepic[%i]:=image(addto currentpicture contour \z unitsquare shifted - center unitsquare;) xscaled %f yscaled %f shifted (%f,%f);" local outline_horz, outline_vert function outline_vert (res, box, curr, xshift, yshift) @@ -1937,6 +1917,18 @@ function outline_horz (res, box, curr, xshift, yshift, discwd) dx = dx - (r2l and curr.width/factor*expand or 0) local xpos = dx + xshift + (curr.xoffset or 0)/factor local ypos = yshift + (curr.yoffset or 0)/factor + local vertical = ft.shared and ft.shared.features.vertical and "rotated 90" or "" + if vertical ~= "" then -- luatexko + for _,v in ipairs(ft.characters[curr.char].commands or { }) do + if v[1] == "down" then + ypos = ypos - v[2] / factor + elseif v[1] == "right" then + xpos = xpos + v[2] / factor + else + break + end + end + end local image if ft.format == "opentype" or ft.format == "truetype" then image = luamplib.glyph(curr.font, gid) @@ -1956,8 +1948,8 @@ function outline_horz (res, box, curr, xshift, yshift, discwd) end image = format("glyph %s of %q scaled %f", gid, name, scale) end - res[#res+1] = format("mplibpic[%i]:=%s xscaled %f yscaled %f slanted %f shifted (%f,%f);", - #res+1, image, xscale, yscale, slant, xpos, ypos) + res[#res+1] = format("mpliboutlinepic[%i]:=%s xscaled %f yscaled %f slanted %f %s shifted (%f,%f);", + #res+1, image, xscale, yscale, slant, vertical, xpos, ypos) dx = dx + (r2l and 0 or curr.width/factor*expand) elseif curr.replace then local width = node.dimensions(curr.replace)/factor @@ -2042,12 +2034,8 @@ function luamplib.outlinetext (text) local id = tonumber(fmt:match"mplibtexboxid=(%d+):") local box = texgetbox(id) local res = outline_horz({ }, box, box.head, 0, 0) - if #res == 0 then res = { "mplibpic[1]:=image(fill fullcircle scaled 0;);" } end - local t = { } - for i=1, #res do - t[#t+1] = format("addto currentpicture also mplibpic[%i];", i) - end - return tableconcat(res) .. format("mplibpic[0]:=image(%s);", tableconcat(t)) + if #res == 0 then res = { "mpliboutlinepic[1]:=image(fill fullcircle scaled 0;);" } end + return tableconcat(res) .. format("mpliboutlinenum:=%i;", #res) end % \end{macrocode} @@ -2155,6 +2143,9 @@ def mplib_do_outline_text_set_f (text f) text r = def mplib_do_outline_options_f = f enddef; def mplib_do_outline_options_r = r enddef; enddef; +def mplib_do_outline_text_set_u (text f) text r = + def mplib_do_outline_options_f = f enddef; +enddef; def mplib_do_outline_text_set_d (text d) text r = def mplib_do_outline_options_d = d enddef; def mplib_do_outline_options_r = r enddef; @@ -2168,27 +2159,40 @@ def mplib_do_outline_text_set_n text r = def mplib_do_outline_options_r = r enddef; enddef; def mplib_do_outline_text_set_p = enddef; -def mplib_fill_outline_text (expr p) = - i:=0; - for item within p: - i:=i+1; - addto currentpicture contour pathpart item - if i < length p: withpostscript "collect"; fi +def mplib_fill_outline_text = + for n=1 upto mpliboutlinenum: + i:=0; + for item within mpliboutlinepic[n]: + i:=i+1; + fill pathpart item mplib_do_outline_options_f withpen pencircle scaled 0 + if (n