CoreText: Apply subpixel horizontal alignment also when cell width is less than advance (#9646)

Follow-up to #9432 to ensure that subpixel horizontal alignment is
consistent whether `cell_width = @round(face_width)` rounds up or down.
pull/8200/head
Qwerasd 2025-11-19 21:51:15 -07:00 committed by GitHub
commit aa2f31179b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 9 additions and 2 deletions

View File

@ -367,9 +367,16 @@ pub const Face = struct {
// We don't do this if the glyph has a stretch constraint,
// since in that case the position was already calculated with the
// new cell width in mind.
if ((constraint.size != .stretch) and (metrics.face_width < cell_width)) {
if (constraint.size != .stretch) {
// We add half the difference to re-center.
x += (cell_width - metrics.face_width) / 2;
const dx = (cell_width - metrics.face_width) / 2;
x += dx;
if (dx < 0) {
// For negative diff (cell narrower than advance), we remove the
// integer part and only keep the fractional adjustment needed
// for consistent subpixel positioning.
x -= @trunc(dx);
}
}
// If this is a bitmap glyph, it will always render as full pixels,