Skip to content

Commit d414e42

Browse files
gucci-on-fleekzauguin
authored andcommitted
Round up embolden widths to avoid non-zero widths
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: \input{luaotfload.sty} \font\TestFontA={lmroman10-regular:embolden=0.000;} at 10.0pt \font\TestFontB={lmroman10-regular:embolden=0.006;} at 10.0pt \font\TestFontC={lmroman10-regular:embolden=0.005;} at 10.0pt \def\Test#1{% \par {\tt\string#1}: \pdfextension literal {10 w} #1 ooo \pdfextension literal { 1 w} #1 ooo \pdfextension literal { 0.00001 w} #1 ooo } \nopagenumbers \Test\TestFontA (Expected) \Test\TestFontB (Expected) \Test\TestFontC (Weird!) \bye The LuaTeX engine developers aren't planning on fixing this https://mailman.ntg.nl/archives/list/dev-luatex@ntg.nl/thread/7BRXFIAOVQDHMBZADBREXOV6YECYFHS3/ and this current behaviour is incompatible with XeLaTeX https://tex.stackexchange.com/q/755049 so this commit modifies the "embolden" manipulator to check if the computed stroke width is non-zero but would round to zero; if so, it sets the stroke width to 1 instead. This ensures that the stroke width will be inherited from an outer PDF group if and only if the embolden factor is exactly zero. An alternative (and simpler) solution would be to use "math.ceil" to unconditionally rounds up the computed embolden width; this could potentially cause backwards compatibility issues since this means that half of all embolden values would now be 0.001pt thicker than before. However, since this is applied only by the PDF renderer, this would not affect line breaking.
1 parent 45f7d14 commit d414e42

1 file changed

Lines changed: 6 additions & 1 deletion

File tree

src/luaotfload-embolden.lua

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,12 @@ assert(luaotfload_module, "This is a part of luaotfload and should not be loaded
1515
local otffeatures = fonts.constructors.newfeatures "otf"
1616

1717
local function enableembolden(tfmdata, _, embolden)
18-
tfmdata.mode, tfmdata.width = 2, tfmdata.size*embolden/6578.176
18+
tfmdata.mode = 2
19+
local width = math.round(tfmdata.size*embolden/6578.176)
20+
if width == 0 and embolden ~= 0 then
21+
width = 1
22+
end
23+
tfmdata.width = width
1924
end
2025

2126
otffeatures.register {

0 commit comments

Comments
 (0)