From 83ca31055cf3e56aa8a704ac49e1686434f4e640 Mon Sep 17 00:00:00 2001 From: Jony Lab Date: Thu, 15 Jan 2026 10:46:42 +0800 Subject: [PATCH] gpui: Add dynamic padding to prevent glyph clipping in text rendering on macOS (#45957) Here may caused by [font-kit](https://github.com/servo/font-kit), I was tried to use [render-glyph](https://github.com/servo/font-kit/blob/main/examples/render-glyph.rs) example and also use the same option with `Transform2F::from_scale(2.0)` for `raster_bounds`. Then the `raster_bounds` will result same issue like the GPUI's font rendering issue. | Transform2F::default() | Transform2F::from_scale(2.) | | --- | -- | | image | image | ## Before SCR-20260105-pgcp-2 ## After SCR-20260105-pfny-1 Release Notes: - Fixed incorrect rendering of characters at large font sizes on macOS --------- Co-authored-by: Claude Sonnet 4.5 Co-authored-by: Jason Lee --- crates/gpui/src/platform/mac/text_system.rs | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/crates/gpui/src/platform/mac/text_system.rs b/crates/gpui/src/platform/mac/text_system.rs index c72271f24fe4ea3750e7aa1d18cadf786cac741e..df0e1433e0e7cf53c9288b771aa44bcd68e03d68 100644 --- a/crates/gpui/src/platform/mac/text_system.rs +++ b/crates/gpui/src/platform/mac/text_system.rs @@ -356,16 +356,22 @@ impl MacTextSystemState { fn raster_bounds(&self, params: &RenderGlyphParams) -> Result> { let font = &self.fonts[params.font_id.0]; - let scale = Transform2F::from_scale(params.scale_factor); - Ok(font + let mut bounds: Bounds = font .raster_bounds( params.glyph_id.0, params.font_size.into(), - scale, + Transform2F::from_scale(params.scale_factor), HintingOptions::None, font_kit::canvas::RasterizationOptions::GrayscaleAa, )? - .into()) + .into(); + + // Adjust the x position to account for the scale factor to avoid glyph clipped. + let x_offset = DevicePixels(bounds.origin.x.0 / params.scale_factor as i32); + bounds.origin.x -= x_offset; + bounds.size.width += x_offset; + + Ok(bounds) } fn rasterize_glyph(