diff options
author | Karl Berry <karl@freefriends.org> | 2024-06-10 20:22:58 +0000 |
---|---|---|
committer | Karl Berry <karl@freefriends.org> | 2024-06-10 20:22:58 +0000 |
commit | 48b3dac6579bd4c1d68f1aee50c2f08cab5c8024 (patch) | |
tree | 73f87c9c1b591b96557a92934c5f2c9e1e676c3f /Master/texmf-dist/tex | |
parent | f10646a8c955455788796ce3c6f091377d4dc261 (diff) |
luamplib (10jun24)
git-svn-id: svn://tug.org/texlive/trunk@71467 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/tex')
-rw-r--r-- | Master/texmf-dist/tex/luatex/luamplib/luamplib.lua | 136 | ||||
-rw-r--r-- | Master/texmf-dist/tex/luatex/luamplib/luamplib.sty | 36 |
2 files changed, 166 insertions, 6 deletions
diff --git a/Master/texmf-dist/tex/luatex/luamplib/luamplib.lua b/Master/texmf-dist/tex/luatex/luamplib/luamplib.lua index afc9fe8ce26..b69b2db21f5 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.31.2", - date = "2024/05/30", + version = "2.32.0", + date = "2024/06/10", description = "Lua package to typeset Metapost with LuaTeX's MPLib.", } @@ -823,6 +823,7 @@ end luamplib.graphictext = function (text, fakebold, fc, dc) local fmt = process_tex_text(text):sub(1,-2) local id = tonumber(fmt:match"mplibtexboxid=(%d+):") + emboldenfonts.width = nil local box = texgetbox(id) box.head = embolden(box, box.head, fakebold) local fill = graphictextcolor(fc,"fill") @@ -1410,6 +1411,9 @@ vardef mpliboutlinetext@# (expr t) text rest = fi; ) mplib_do_outline_options_r; ) enddef ; +primarydef t withpattern p = + image( fill t withprescript "mplibpattern=" & if numeric p: decimal fi p; ) +enddef; ]], legacyverbatimtex = [[ def specialVerbatimTeX (text t) = runscript("luamplibprefig{"&t&"}") enddef; @@ -1756,7 +1760,8 @@ if pdfmode then end end else - texsprint("\\special{pdf:obj @MPlibTr<<>>}","\\special{pdf:obj @MPlibSh<<>>}") + texsprint("\\special{pdf:obj @MPlibTr<<>>}","\\special{pdf:obj @MPlibSh<<>>}", + "\\special{pdf:obj @MPlibCS<<>>}","\\special{pdf:obj @MPlibPt<<>>}") end local transparancy_modes = { [0] = "Normal", @@ -1900,10 +1905,11 @@ 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 + if not sh_type then + return + else local domain = prescript.sh_domain or "0 1" local centera = prescript.sh_center_a or "0 0"; centera = centera:explode() local centerb = prescript.sh_center_b or "0 0"; centerb = centerb:explode() @@ -2015,6 +2021,125 @@ local function do_preobj_SH(object,prescript) return shade_no end +patterns = { c_l_r_s_p_c_s_ = { } } +function luamplib.registerpattern ( boxid, name, opts ) + local box = texgetbox(boxid) + 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 + local attr = { + "/Type/Pattern", + "/PatternType 1", + format("/PaintType %i", opts.colored and 1 or 2), + "/TilingType 2", + format("/XStep %.3f", opts.xstep or box.width/factor), + format("/YStep %.3f", opts.ystep or (box.height+box.depth)/factor), + format("/Matrix [%s %s %s]", opts.matrix or "1 0 0 1", opts.xshift or 0, opts.yshift or 0), + } + if pdfmode then + if opts.bbox then + attr[#attr+1] = format("/BBox [%s]", opts.bbox) + end + local index = tex.saveboxresource(boxid,tableconcat(attr),opts.resources,true,opts.bbox and 4 or 1) + patterns[name] = { id = index, colored = opts.colored } + else + local objname = "@mplibpattern"..name + local metric = opts.bbox and format("bbox %s",opts.bbox) or + format([[width \the\wd%i \space height \the\ht%i \space depth \the\dp%i]],boxid,boxid,boxid) + 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([[\box %i]], boxid), + [[\special{pdf:exobj <<]], tableconcat(attr), ">>}", + [[\special{pdf:econtent}]], + [[\par}\hss}]], + } + patterns[#patterns+1] = objname + patterns[name] = { id = #patterns, colored = opts.colored } + end +end +local function pattern_colorspace (cs, ref) + local on, new = update_pdfobjs(format("[/Pattern %s]", ref or format("/%s",cs))) + if new then + 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)) + else + local res = format("/%s %s", key, val) + if is_defined"pgf@sys@addpdfresource@colorspaces@plain" then + texsprint(catat11, format("\\pgf@sys@addpdfresource@colorspaces@plain{%s}", 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>>}" + end + end + patterns.c_l_r_s_p_c_s_[cs] = on + end + return on +end +local function do_preobj_PAT(object, prescript) + local name = prescript and prescript.mplibpattern + if not name then return end + local patt = patterns[name] + local index = patt and patt.id or err("cannot get pattern object '%s'", name) + local key = format("MPlibPt%s",index) + if patt.colored then + pdf_literalcode("/Pattern cs /%s scn", key) + else + local color = prescript.mpliboverridecolor + if not color then + local t = object.color + color = t and #t>0 and luamplib.colorconverter(t) + end + if not color then return end + local csobj, cs, ref + if color:find" cs " or color:find"@pdf.obj" then + local t = color:explode() + if pdfmode then + cs = t[1]:sub(2,-1) + ref = format("%s 0 R", ltx.pdf.object_id(cs)) + color = t[3] + else + cs, ref = t[2], t[2] + color = t[3]:match"%[(.+)%]" + end + else + local t = colorsplit(color) + cs = #t == 4 and "DeviceCMYK" or #t == 3 and "DeviceRGB" or "DeviceGray" + color = tableconcat(t," ") + end + csobj = patterns.c_l_r_s_p_c_s_[cs] or pattern_colorspace(cs, ref) + pdf_literalcode("/MPlibCS%i cs %s /%s scn", csobj, 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"pgf@sys@addpdfresource@patterns@plain" then + texsprint(catat11, format("\\pgf@sys@addpdfresource@patterns@plain{%s}", res)) + elseif pdfmode then + if not pdfetcs.Pattern_res then + pdfetcs.initialize_resources"Pattern" + end + pdfetcs.fallback_update_resources("Pattern", res) + else + texsprint(format("\\special{pdf:put @MPlibPt<<%s>>}", res)) + texsprint"\\special{pdf:put @resources<</Pattern @MPlibPt>>}" + end + end + patt.done = true +end + function luamplib.flush (result,flusher) if result then local figures = result.fig @@ -2090,6 +2215,7 @@ function luamplib.flush (result,flusher) end else local shade_no = do_preobj_SH(object,prescript) -- shading + local pattern_ = do_preobj_PAT(object,prescript) -- pattern local ml = object.miterlimit if ml and ml ~= miterlimit then miterlimit = ml diff --git a/Master/texmf-dist/tex/luatex/luamplib/luamplib.sty b/Master/texmf-dist/tex/luatex/luamplib/luamplib.sty index 85a725f526d..b7232afcab6 100644 --- a/Master/texmf-dist/tex/luatex/luamplib/luamplib.sty +++ b/Master/texmf-dist/tex/luatex/luamplib/luamplib.sty @@ -14,7 +14,7 @@ \else \NeedsTeXFormat{LaTeX2e} \ProvidesPackage{luamplib} - [2024/05/30 v2.31.2 mplib package for LuaTeX] + [2024/06/10 v2.32.0 mplib package for LuaTeX] \ifx\newluafunction\@undefined \input ltluatex \fi @@ -46,6 +46,40 @@ \catcode`\&=12 \catcode`\$=12 \catcode`\%=12 \catcode`\^^M=12 } \def\mplibputtextbox#1{\vbox to 0pt{\vss\hbox to 0pt{\raise\dp#1\copy#1\hss}}} +{\def\:{\global\let\mplibsptoken= } \: } +\protected\def\mppattern#1{% + \begingroup + \def\mplibpatternname{#1}% + \mplibpatterngetnexttok +} +\def\mplibpatterngetnexttok{\futurelet\nexttok\mplibpatternbranch} +\def\mplibpatternskipspace{\afterassignment\mplibpatterngetnexttok\let\nexttok= } +\def\mplibpatternbranch{% + \ifx [\nexttok + \expandafter\mplibpatternopts + \else + \ifx\mplibsptoken\nexttok + \expandafter\expandafter\expandafter\mplibpatternskipspace + \else + \let\mplibpatternoptions\empty + \expandafter\expandafter\expandafter\mplibpatternmain + \fi + \fi +} +\def\mplibpatternopts[#1]{% + \def\mplibpatternoptions{#1}% + \mplibpatternmain +} +\def\mplibpatternmain{% + \setbox\mplibscratchbox\hbox\bgroup\ignorespaces +} +\protected\def\endmppattern{% + \egroup + \directlua{ luamplib.registerpattern( + \the\mplibscratchbox, '\mplibpatternname', {\mplibpatternoptions} + )}% + \endgroup +} \def\mpfiginstancename{@mpfig} \protected\def\mpfig{% \begingroup |