diff --git a/crates/gpui/src/geometry.rs b/crates/gpui/src/geometry.rs index fa6f90b9ac9949ed7b5444e13045aaef6f9c0224..e7aa69ee054ed905e1b68a85bf386a1ea0d5fd22 100644 --- a/crates/gpui/src/geometry.rs +++ b/crates/gpui/src/geometry.rs @@ -2679,6 +2679,15 @@ impl Pixels { Self(self.0.floor()) } + /// Rounds the `Pixels` value to the nearest pixel accounting for scaling. + /// + /// # Returns + /// + /// Returns a new `Pixels` instance with the rounded value. + pub fn round_pixel(&self, scale_factor: f32) -> Self { + Self((self.0 * scale_factor).round() / scale_factor) + } + /// Rounds the `Pixels` value to the nearest whole number. /// /// # Returns diff --git a/crates/gpui/src/text_system/line.rs b/crates/gpui/src/text_system/line.rs index 189a3e85c6b4fed52eddb45d5fa151314830c0e9..cf2925dd20153a82f7c653890326a6da0b36d060 100644 --- a/crates/gpui/src/text_system/line.rs +++ b/crates/gpui/src/text_system/line.rs @@ -196,8 +196,9 @@ fn paint_line( window: &mut Window, cx: &mut App, ) -> Result<()> { + let scale_factor = window.scale_factor(); let line_bounds = Bounds::new( - origin, + point(origin.x, origin.y.round_pixel(scale_factor)), size( layout.width, line_height * (wrap_boundaries.len() as f32 + 1.), @@ -205,7 +206,6 @@ fn paint_line( ); window.paint_layer(line_bounds, |window| { let padding_top = (line_height - layout.ascent - layout.descent) / 2.; - let baseline_offset = point(px(0.), padding_top + layout.ascent); let mut decoration_runs = decoration_runs.iter(); let mut wraps = wrap_boundaries.iter().peekable(); let mut run_end = 0; @@ -213,6 +213,11 @@ fn paint_line( let mut current_underline: Option<(Point, UnderlineStyle)> = None; let mut current_strikethrough: Option<(Point, StrikethroughStyle)> = None; let text_system = cx.text_system().clone(); + let scale_factor = window.scale_factor(); + let baseline_offset = point( + px(0.), + (padding_top + layout.ascent).round_pixel(scale_factor), + ); let mut glyph_origin = point( aligned_origin_x( origin, @@ -222,7 +227,7 @@ fn paint_line( layout, wraps.peek(), ), - origin.y, + origin.y.round_pixel(scale_factor), ); let mut prev_glyph_position = Point::default(); let mut max_glyph_size = size(px(0.), px(0.)); @@ -273,7 +278,7 @@ fn paint_line( layout, wraps.peek(), ); - glyph_origin.y += line_height; + glyph_origin.y = (glyph_origin.y + line_height).round_pixel(scale_factor); } prev_glyph_position = glyph.position; diff --git a/crates/gpui/src/window.rs b/crates/gpui/src/window.rs index caf78fe407ea0a61a88efd9462be5fce005dedbf..d03555de0814af798d4486d72ad791b8b6a255d3 100644 --- a/crates/gpui/src/window.rs +++ b/crates/gpui/src/window.rs @@ -2982,7 +2982,7 @@ impl Window { })? .expect("Callback above only errors or returns Some"); let bounds = Bounds { - origin: glyph_origin.map(|px| px.floor()) + raster_bounds.origin.map(Into::into), + origin: glyph_origin + raster_bounds.origin.map(Into::into), size: tile.bounds.size.map(Into::into), }; let content_mask = self.content_mask().scale(scale_factor);