Hi Luigi,
With "tfmdata.mode = 2" (PDF stroke and fill), if you set
"tfmdata.width" to a non-zero integer, then the glyphs are stroked with
a line of that thickness; this is documented in the LuaTeX manual. If
you set "tfmdata.width" to zero, then the stroke width will be inherited
from the environment; this isn't documented anywhere, but it's somewhat
useful, and someone is probably relying on it. If you set
"tfmdata.width" to a non-zero value that rounds to zero, then you get
the same behaviour as if you set it to exactly zero; this is somewhat
surprising, since it means that in most cases, "tfmdata.width = 0.49"
produces much thicker glyphs than "tfmdata.width = 0.51". Example:
\directlua{
for name, width in pairs {
TestFontA = 0,
TestFontB = 0.51,
TestFontC = 0.49,
} do
local tfmdata = font.getcopy(\fontid\tenrm)
tfmdata.mode = 2
tfmdata.width = width
token.set_char(name, font.define(tfmdata))
end
}
\def\Test#1{%
\par
{\tt\string#1}:
\pdfextension literal {10 w} \setfontid#1 ooo
\pdfextension literal { 1 w} \setfontid#1 ooo
\pdfextension literal { 0.00001 w} \setfontid#1 ooo
}
\nopagenumbers
\Test\TestFontA (Expected)
\Test\TestFontB (Expected)
\Test\TestFontC (Weird!)
\bye
I've attached a patch that fixes this, but it's fairly ugly, and you
could argue the current behaviour is correct and that this discrepancy
is better handled by the macro package (ConTeXt/luaotfload). Still, it's
fairly surprising behaviour.
I've attached a second patch that documents "tfmdata.width = 0".
This issue was originally reported by cfr (cc'ed) in the TeX.SE chat.
Thanks,
-- Max
From 7da09c61a95845ca17c9ec2af9a6ff391e0f2444 Mon Sep 17 00:00:00 2001
From: Max Chernoff <[email protected]>
Date: Fri, 21 Nov 2025 01:32:55 -0700
Subject: [PATCH] Fix stroke width for non-zero tfmdata.width that rounds to
zero
---
source/texk/web2c/luatexdir/font/luafont.c | 8 ++++++++
1 file changed, 8 insertions(+)
diff --git a/source/texk/web2c/luatexdir/font/luafont.c b/source/texk/web2c/luatexdir/font/luafont.c
index c33037244..cbb3a7b16 100644
--- a/source/texk/web2c/luatexdir/font/luafont.c
+++ b/source/texk/web2c/luatexdir/font/luafont.c
@@ -1726,6 +1726,14 @@ int font_from_lua(lua_State * L, int f)
i = FONT_SQUEEZE_MAX;
set_font_squeeze(f, i);
i = lua_numeric_field_by_index(L,lua_key_index(width), 0);
+ if (i == 0) {
+ lua_rawgeti(L, LUA_REGISTRYINDEX, lua_key_index(width));
+ lua_rawget(L, -2);
+ if (lua_tonumber(L,-1) != 0) {
+ i = 1;
+ }
+ lua_pop(L, 1);
+ }
if (i < FONT_WIDTH_MIN)
i = FONT_WIDTH_MIN;
if (i > FONT_WIDTH_MAX)
--
2.51.1
From 20c4d2a4b88f669d3717133cf8dd0128596c8510 Mon Sep 17 00:00:00 2001
From: Max Chernoff <[email protected]>
Date: Fri, 21 Nov 2025 01:39:38 -0700
Subject: [PATCH 2/2] Document "tfmdata.width = 0"
---
manual/luatex-fonts.tex | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/manual/luatex-fonts.tex b/manual/luatex-fonts.tex
index 6c0a56119..150d8b9e4 100644
--- a/manual/luatex-fonts.tex
+++ b/manual/luatex-fonts.tex
@@ -84,7 +84,8 @@ the table are as follows:
no equivalent in the map file. \NC \NR
\NC \type{width} \NC no \NC no \NC yes \NC number \NC The backend will inject \PDF\ operators that set the
penwidth. The value is (as usual in \TEX) divided by 1000.
- It works with the \type {mode} file. \NC \NR
+ It works with the \type {mode} file. If set to~0, the
+ penwidth will be inherited from the outer \PDF\ group. \NC \NR
\NC \type{mode} \NC no \NC no \NC yes \NC number \NC The backend will inject \PDF\ operators that relate to the
drawing mode with 0~being a fill, 1~being an outline,
2~both draw and fill and 3~no painting at all. \NC \NR
--
2.51.1
_______________________________________________
dev-luatex mailing list -- [email protected]
To unsubscribe send an email to [email protected]