mirror of
https://github.com/zed-industries/zed.git
synced 2026-05-28 09:34:29 +00:00
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.) | | --- | -- | | <img width="943" height="638" alt="image" src="https://github.com/user-attachments/assets/9b827c63-2cbb-45d3-bd62-b0e058a46614" /> | <img width="943" height="638" alt="image" src="https://github.com/user-attachments/assets/ee977a9b-2a7b-4b78-873b-146b2953c0db" /> | ## Before <img width="1032" height="1398" alt="SCR-20260105-pgcp-2" src="https://github.com/user-attachments/assets/ebeb04cc-3a92-4333-99fc-8733a63b2553" /> ## After <img width="1032" height="1414" alt="SCR-20260105-pfny-1" src="https://github.com/user-attachments/assets/063d0452-56d7-447c-810b-fee7c891235b" /> Release Notes: - Fixed incorrect rendering of characters at large font sizes on macOS --------- Co-authored-by: Claude Sonnet 4.5 <noreply@anthropic.com> Co-authored-by: Jason Lee <huacnlee@gmail.com>
This commit is contained in:
parent
95c698d31d
commit
83ca31055c
1 changed files with 10 additions and 4 deletions
|
|
@ -356,16 +356,22 @@ impl MacTextSystemState {
|
|||
|
||||
fn raster_bounds(&self, params: &RenderGlyphParams) -> Result<Bounds<DevicePixels>> {
|
||||
let font = &self.fonts[params.font_id.0];
|
||||
let scale = Transform2F::from_scale(params.scale_factor);
|
||||
Ok(font
|
||||
let mut bounds: Bounds<DevicePixels> = 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(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue