Round pdfTeX font expansion before quantizing the font step

This commit is contained in:
gloamxun committed 2026-11-26 14:18:44 +08:00
1 parent 9ae7c6a6df
commit 9e13cca481
3 files changed
+43 -1

No files matched your search

@@ -244,7 +244,10 @@ fn slot_ratio(state: &State, font: &NativeFont, slot: u8, line_ratio: i32) -> i3
config.stretch
};
let code = state.fonts.expansion_code(font.id, slot);
let magnitude = i64::from(line_ratio.abs()) * i64::from(code) * i64::from(max) / 1_000_000;
// Round the signed expansion product before quantizing it to the font step.
// Work on its magnitude here so both signs round away from zero at a tie.
let product = i64::from(line_ratio.abs()) * i64::from(code) * i64::from(max);
let magnitude = (product + 500_000) / 1_000_000;
let step = i64::from(config.step);
(magnitude + step / 2).div_euclid(step) as i32 * config.step * line_ratio.signum()
}