diff options
Diffstat (limited to 'Master/texmf-dist/source/luatex')
-rw-r--r-- | Master/texmf-dist/source/luatex/luamplib/luamplib.dtx | 144 |
1 files changed, 75 insertions, 69 deletions
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<mpliboutlinenum) or (i<length mpliboutlinepic[n]): withpostscript "collect"; fi + endfor + endfor +enddef; +def mplib_draw_outline_text = + for n=1 upto mpliboutlinenum: + for item within mpliboutlinepic[n]: + draw pathpart item mplib_do_outline_options_d; + endfor endfor - mplib_do_outline_options_f; enddef; -def mplib_draw_outline_text (expr p) = - i:=0; - for item within p: - i:=i+1; - addto currentpicture doublepath pathpart item - if i < length p: withpostscript "collect"; fi +def mplib_filldraw_outline_text = + for n=1 upto mpliboutlinenum: + i:=0; + for item within mpliboutlinepic[n]: + i:=i+1; + if (n<mpliboutlinenum) or (i<length mpliboutlinepic[n]): + fill pathpart item mplib_do_outline_options_f withpostscript "collect"; + else: + draw pathpart item mplib_do_outline_options_f withpostscript "both"; + fi + endfor endfor - mplib_do_outline_options_d; enddef; vardef mpliboutlinetext@# (expr t) text rest = save kind; string kind; kind := str @#; - save mplibpic, i; picture mplibpic[]; numeric i; + save i; numeric i; + picture mpliboutlinepic[]; numeric mpliboutlinenum; def mplib_do_outline_options_d = enddef; def mplib_do_outline_options_f = enddef; def mplib_do_outline_options_r = enddef; @@ -2196,28 +2200,27 @@ vardef mpliboutlinetext@# (expr t) text rest = image ( addto currentpicture also image ( if kind = "f": mplib_do_outline_text_set_f rest; - def mplib_do_outline_options_d = withpen pencircle scaled 0 enddef; - mplib_fill_outline_text (mplibpic0); + mplib_fill_outline_text; elseif kind = "d": mplib_do_outline_text_set_d rest; - mplib_draw_outline_text (mplibpic0); + mplib_draw_outline_text; elseif kind = "b": mplib_do_outline_text_set_b rest; - mplib_fill_outline_text (mplibpic0); - mplib_draw_outline_text (mplibpic0); + mplib_fill_outline_text; + mplib_draw_outline_text; elseif kind = "u": - mplib_do_outline_text_set_f rest; - mplib_fill_outline_text (mplibpic0); + mplib_do_outline_text_set_u rest; + mplib_filldraw_outline_text; elseif kind = "r": mplib_do_outline_text_set_r rest; - mplib_draw_outline_text (mplibpic0); - mplib_fill_outline_text (mplibpic0); + mplib_draw_outline_text; + mplib_fill_outline_text; elseif kind = "p": mplib_do_outline_text_set_p; - mplib_draw_outline_text (mplibpic0); + mplib_draw_outline_text; else: mplib_do_outline_text_set_n rest; - mplib_fill_outline_text (mplibpic0); + mplib_fill_outline_text; fi; ) mplib_do_outline_options_r; ) enddef ; @@ -2539,6 +2542,7 @@ end % \begin{macrocode} local prev_override_color local function do_preobj_CR(object,prescript) + if object.postscript == "collect" then return end local override = prescript and prescript.mpliboverridecolor if override then if pdfmode then @@ -2672,7 +2676,8 @@ local function update_tr_res(mode,opaq) return on end -local function do_preobj_TR(prescript) +local function do_preobj_TR(object,prescript) + if object.postscript == "collect" then return end local opaq = prescript and prescript.tr_transparency local tron_no if opaq then @@ -2767,6 +2772,7 @@ pdfetcs.clrspcs = setmetatable({ }, { __index = function(t,names) end }) local function do_preobj_SH(object,prescript) + if object.postscript == "collect" then return end local shade_no local sh_type = prescript and prescript.sh_type if sh_type then @@ -2930,7 +2936,7 @@ function luamplib.flush (result,flusher) local prescript = object.prescript prescript = prescript and script2table(prescript) -- prescript is now a table local cr_over = do_preobj_CR(object,prescript) -- color - local tr_opaq = do_preobj_TR(prescript) -- opacity + local tr_opaq = do_preobj_TR(object,prescript) -- opacity if prescript and prescript.mplibtexboxid then put_tex_boxes(object,prescript) elseif objecttype == "start_bounds" or objecttype == "stop_bounds" then --skip @@ -3170,7 +3176,7 @@ end \else \NeedsTeXFormat{LaTeX2e} \ProvidesPackage{luamplib} - [2024/05/24 v2.31.1 mplib package for LuaTeX] + [2024/05/30 v2.31.2 mplib package for LuaTeX] \ifx\newluafunction\@undefined \input ltluatex \fi |