diff options
author | Karl Berry <karl@freefriends.org> | 2024-05-30 19:57:39 +0000 |
---|---|---|
committer | Karl Berry <karl@freefriends.org> | 2024-05-30 19:57:39 +0000 |
commit | 504ee16abc171d2851d62e7ce9b9774febf766f6 (patch) | |
tree | 2fe1647abb1d4ee08d08c4d20088cff70892888d /Master/texmf-dist/tex/luatex/luamplib/luamplib.lua | |
parent | 7823d0887ef6fcc70fce9a18a53637f6daf80806 (diff) |
luamplib (30may24)
git-svn-id: svn://tug.org/texlive/trunk@71391 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/tex/luatex/luamplib/luamplib.lua')
-rw-r--r-- | Master/texmf-dist/tex/luatex/luamplib/luamplib.lua | 107 |
1 files changed, 66 insertions, 41 deletions
diff --git a/Master/texmf-dist/tex/luatex/luamplib/luamplib.lua b/Master/texmf-dist/tex/luatex/luamplib/luamplib.lua index e4fb642f562..afc9fe8ce26 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.1", - date = "2024/05/24", + version = "2.31.2", + date = "2024/05/30", description = "Lua package to typeset Metapost with LuaTeX's MPLib.", } @@ -775,14 +775,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 @@ -989,7 +988,7 @@ function luamplib.glyph (f, c) return glyphimage(t, kind) end -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) @@ -1108,6 +1107,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) @@ -1127,8 +1138,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 @@ -1213,12 +1224,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 luamplib.preambles = { @@ -1322,6 +1329,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; @@ -1335,27 +1345,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; @@ -1363,28 +1386,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 ; @@ -1660,6 +1682,7 @@ end 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 @@ -1785,7 +1808,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 @@ -1876,6 +1900,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 @@ -2018,7 +2043,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 |