summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/luatex
diff options
context:
space:
mode:
authorKarl Berry <karl@freefriends.org>2024-05-24 20:57:52 +0000
committerKarl Berry <karl@freefriends.org>2024-05-24 20:57:52 +0000
commite09537ea977fce1df0aabc2da9126d5c2b1ec624 (patch)
tree18d2831d70c4c7fe0f579e57a1814b7821068a26 /Master/texmf-dist/tex/luatex
parent474558890a46fdf51b1abe51ed2b472ff41d453d (diff)
luamplib (23may24)
git-svn-id: svn://tug.org/texlive/trunk@71342 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/tex/luatex')
-rw-r--r--Master/texmf-dist/tex/luatex/luamplib/luamplib.lua156
-rw-r--r--Master/texmf-dist/tex/luatex/luamplib/luamplib.sty2
2 files changed, 117 insertions, 41 deletions
diff --git a/Master/texmf-dist/tex/luatex/luamplib/luamplib.lua b/Master/texmf-dist/tex/luatex/luamplib/luamplib.lua
index 72320fe65a6..e4fb642f562 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.0",
- date = "2024/05/21",
+ version = "2.31.1",
+ date = "2024/05/24",
description = "Lua package to typeset Metapost with LuaTeX's MPLib.",
}
@@ -682,22 +682,104 @@ luamplib.shadecolor = function (str)
return colorsplit(res)
end
+local running = -1073741824
local emboldenfonts = { }
-local function embolden (head, fakebold)
- local curr = head
+local function getemboldenwidth (curr, fakebold)
+ local width = emboldenfonts.width
+ if not width then
+ local f
+ local function getglyph(n)
+ while n do
+ if n.head then
+ getglyph(n.head)
+ elseif n.font and n.font > 0 then
+ f = n.font; break
+ end
+ n = node.getnext(n)
+ end
+ end
+ getglyph(curr)
+ width = font.getcopy(f or font.current()).size * fakebold / factor * 10
+ emboldenfonts.width = width
+ end
+ return width
+end
+local function getrulewhatsit (line, wd, ht, dp)
+ line, wd, ht, dp = line/1000, wd/factor, ht/factor, dp/factor
+ local pl
+ local fmt = "%f w %f %f %f %f re %s"
+ if pdfmode then
+ pl = node.new("whatsit","pdf_literal")
+ pl.mode = 0
+ else
+ fmt = "pdf:content "..fmt
+ pl = node.new("whatsit","special")
+ end
+ pl.data = fmt:format(line, 0, -dp, wd, ht+dp, "B")
+ local ss = node.new"glue"
+ node.setglue(ss, 0, 65536, 65536, 2, 2)
+ pl.next = ss
+ return pl
+end
+local function getrulemetric (box, curr, bp)
+ local wd,ht,dp = curr.width, curr.height, curr.depth
+ wd = wd == running and box.width or wd
+ ht = ht == running and box.height or ht
+ dp = dp == running and box.depth or dp
+ if bp then
+ return wd/factor, ht/factor, dp/factor
+ end
+ return wd, ht, dp
+end
+local function embolden (box, curr, fakebold)
+ local head = curr
while curr do
if curr.head then
- embolden(curr.head, fakebold)
- elseif curr.leader and curr.leader.head then
- embolden(curr.leader.head, fakebold)
+ curr.head = embolden(curr, curr.head, fakebold)
+ elseif curr.replace then
+ curr.replace = embolden(box, curr.replace, fakebold)
+ elseif curr.leader then
+ if curr.leader.head then
+ curr.leader.head = embolden(curr.leader, curr.leader.head, fakebold)
+ elseif curr.leader.id == node.id"rule" then
+ local glue = node.effective_glue(curr, box)
+ local line = getemboldenwidth(curr, fakebold)
+ local wd,ht,dp = getrulemetric(box, curr.leader)
+ if box.id == node.id"hlist" then
+ wd = glue
+ else
+ ht, dp = 0, glue
+ end
+ local pl = getrulewhatsit(line, wd, ht, dp)
+ local pack = box.id == node.id"hlist" and node.hpack or node.vpack
+ local list = pack(pl, glue, "exactly")
+ head = node.insert_after(head, curr, list)
+ head, curr = node.remove(head, curr)
+ end
+ elseif curr.id == node.id"rule" and curr.subtype == 0 then
+ local line = getemboldenwidth(curr, fakebold)
+ local wd,ht,dp = getrulemetric(box, curr)
+ if box.id == node.id"vlist" then
+ ht, dp = 0, ht+dp
+ end
+ local pl = getrulewhatsit(line, wd, ht, dp)
+ local list
+ if box.id == node.id"hlist" then
+ list = node.hpack(pl, wd, "exactly")
+ else
+ list = node.vpack(pl, ht+dp, "exactly")
+ end
+ head = node.insert_after(head, curr, list)
+ head, curr = node.remove(head, curr)
elseif curr.id == node.id"glyph" and curr.font > 0 then
local f = curr.font
local i = emboldenfonts[f]
if not i then
if pdfmode then
local ft = font.getcopy(f)
- ft.mode = 2
- ft.width = ft.size * fakebold / 6578.176
+ 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)
@@ -705,7 +787,7 @@ local function embolden (head, fakebold)
goto skip_type1
end
local name = ft.name:gsub('"',''):gsub(';$','')
- name = format('%s;embolden=%s',name,fakebold)
+ name = format('%s;embolden=%s;',name,fakebold)
_, i = fonts.constructors.readanddefine(name,ft.size)
end
emboldenfonts[f] = i
@@ -715,6 +797,7 @@ local function embolden (head, fakebold)
::skip_type1::
curr = node.getnext(curr)
end
+ return head
end
local function graphictextcolor (col, filldraw)
if col:find"^[%d%.:]+$" then
@@ -741,7 +824,8 @@ end
luamplib.graphictext = function (text, fakebold, fc, dc)
local fmt = process_tex_text(text):sub(1,-2)
local id = tonumber(fmt:match"mplibtexboxid=(%d+):")
- embolden(texgetbox(id).head, fakebold)
+ local box = texgetbox(id)
+ box.head = embolden(box, box.head, fakebold)
local fill = graphictextcolor(fc,"fill")
local draw = graphictextcolor(dc,"draw")
local bc = pdfmode and "" or "pdf:bc "
@@ -836,7 +920,7 @@ function luamplib.glyph (f, c)
local fontdata = font.getfont(fid) or font.getcopy(fid)
filename, subfont, kind = fontdata.filename, fontdata.subfont, fontdata.format
instance = fontdata.specification and fontdata.specification.instance
- filename = filename:gsub("^harfloaded:","")
+ filename = filename and filename:gsub("^harfloaded:","")
else
local name
f = f:match"^%s*(.+)%s*$"
@@ -910,15 +994,13 @@ unitsquare shifted - center unitsquare;) xscaled %f yscaled %f shifted (%f,%f);"
local outline_horz, outline_vert
function outline_vert (res, box, curr, xshift, yshift)
local b2u = box.dir == "LTL"
- local dy = (b2u and -(box.depth or 0) or (box.height or 0))/factor
+ local dy = (b2u and -box.depth or box.height)/factor
local ody = dy
while curr do
if curr.id == node.id"rule" then
- local ht, dp = curr.height/factor, curr.depth/factor
+ local wd, ht, dp = getrulemetric(box, curr, true)
local hd = ht + dp
if hd ~= 0 then
- local wd = curr.width
- wd = (wd == -1073741824 and box.width or wd)/factor
dy = dy + (b2u and dp or -ht)
if wd ~= 0 and curr.subtype == 0 then
res[#res+1] = rulefmt:format(#res+1, wd, hd, xshift+wd/2, yshift+dy+(ht-dp)/2)
@@ -927,14 +1009,13 @@ function outline_vert (res, box, curr, xshift, yshift)
end
elseif curr.id == node.id"glue" then
local vwidth = node.effective_glue(curr,box)/factor
- dy = dy + (b2u and vwidth or 0)
if curr.leader then
local curr, kind = curr.leader, curr.subtype
if curr.id == node.id"rule" then
- local wd = curr.width/factor
+ local wd = getrulemetric(box, curr, true)
if wd ~= 0 then
local hd = vwidth
- local dy = dy - hd
+ local dy = dy + (b2u and 0 or -hd)
if hd ~= 0 and curr.subtype == 0 then
res[#res+1] = rulefmt:format(#res+1, wd, hd, xshift+wd/2, yshift+dy+hd/2)
end
@@ -942,8 +1023,7 @@ function outline_vert (res, box, curr, xshift, yshift)
elseif curr.head then
local hd = (curr.height + curr.depth)/factor
if hd <= vwidth then
- local dy = b2u and dy-vwidth or dy
- local n, iy = 0, 0
+ local dy, n, iy = dy, 0, 0
if kind == 100 or kind == 103 then -- todo: gleaders
local ady = abs(ody - dy)
local ndy = math.ceil(ady / hd) * hd
@@ -971,7 +1051,7 @@ function outline_vert (res, box, curr, xshift, yshift)
end
end
end
- dy = dy - (b2u and 0 or vwidth)
+ dy = dy + (b2u and vwidth or -vwidth)
elseif curr.id == node.id"kern" then
dy = dy + curr.kern/factor * (b2u and 1 or -1)
elseif curr.id == node.id"vlist" then
@@ -987,24 +1067,23 @@ function outline_vert (res, box, curr, xshift, yshift)
end
return res
end
-function outline_horz (res, box, curr, xshift, yshift)
+function outline_horz (res, box, curr, xshift, yshift, discwd)
local r2l = box.dir == "TRT"
- local dx = r2l and (box.width or 0)/factor or 0
+ local dx = r2l and (discwd or box.width/factor) or 0
local dirs = { { dir = r2l, dx = dx } }
- local odx = dx
while curr do
if curr.id == node.id"dir" then
local sign, dir = curr.dir:match"(.)(...)"
local level, newdir = curr.level, r2l
if sign == "+" then
- local n = node.getnext(curr)
- while n do
- if n.id == node.id"dir" and n.level+1 == level then break end
- n = node.getnext(n)
- end
- n = n or node.tail(curr)
newdir = dir == "TRT"
if r2l ~= newdir then
+ local n = node.getnext(curr)
+ while n do
+ if n.id == node.id"dir" and n.level+1 == level then break end
+ n = node.getnext(n)
+ end
+ n = n or node.tail(curr)
dx = dx + node.rangedimensions(box, curr, n)/factor * (newdir and 1 or -1)
end
dirs[level] = { dir = r2l, dx = dx }
@@ -1051,17 +1130,14 @@ function outline_horz (res, box, curr, xshift, yshift)
res[#res+1] = format("mplibpic[%i]:=%s xscaled %f yscaled %f slanted %f shifted (%f,%f);",
#res+1, image, xscale, yscale, slant, xpos, ypos)
dx = dx + (r2l and 0 or curr.width/factor*expand)
- elseif curr.id == node.id"disc" then
+ elseif curr.replace then
local width = node.dimensions(curr.replace)/factor
dx = dx - (r2l and width or 0)
- res = outline_horz(res, curr, curr.replace, xshift+dx, yshift)
+ res = outline_horz(res, box, curr.replace, xshift+dx, yshift, width)
dx = dx + (r2l and 0 or width)
elseif curr.id == node.id"rule" then
- local wd = curr.width/factor
+ local wd, ht, dp = getrulemetric(box, curr, true)
if wd ~= 0 then
- local ht, dp = curr.height, curr.depth
- ht = (ht == -1073741824 and box.height or ht)/factor
- dp = (dp == -1073741824 and box.depth or dp)/factor
local hd = ht + dp
dx = dx - (r2l and wd or 0)
if hd ~= 0 and curr.subtype == 0 then
@@ -1075,10 +1151,10 @@ function outline_horz (res, box, curr, xshift, yshift)
if curr.leader then
local curr, kind = curr.leader, curr.subtype
if curr.id == node.id"rule" then
- local ht, dp = curr.height/factor, curr.depth/factor
+ local wd, ht, dp = getrulemetric(box, curr, true)
local hd = ht + dp
if hd ~= 0 then
- local wd = width
+ wd = width
if wd ~= 0 and curr.subtype == 0 then
res[#res+1] = rulefmt:format(#res+1, wd, hd, xshift+dx+wd/2, yshift+(ht-dp)/2)
end
@@ -1089,7 +1165,7 @@ function outline_horz (res, box, curr, xshift, yshift)
local dx = r2l and dx+width or dx
local n, ix = 0, 0
if kind == 100 or kind == 103 then -- todo: gleaders
- local adx = abs(dx-odx)
+ local adx = abs(dx-dirs[1].dx)
local ndx = math.ceil(adx / wd) * wd
local diff = ndx - adx
n = (width-diff) // wd
diff --git a/Master/texmf-dist/tex/luatex/luamplib/luamplib.sty b/Master/texmf-dist/tex/luatex/luamplib/luamplib.sty
index 55362792183..6fa986d62bb 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/21 v2.31.0 mplib package for LuaTeX]
+ [2024/05/24 v2.31.1 mplib package for LuaTeX]
\ifx\newluafunction\@undefined
\input ltluatex
\fi