diff --git a/epaint/src/tessellator.rs b/epaint/src/tessellator.rs index 6292a322..304b1009 100644 --- a/epaint/src/tessellator.rs +++ b/epaint/src/tessellator.rs @@ -645,6 +645,13 @@ impl Tessellator { galley.sanity_check(); } + // The contents of the galley is already snapped to pixel coordinates, + // but we need to make sure the galley ends up on the start of a physical pixel: + let pos = pos2( + self.options.round_to_pixel(pos.x), + self.options.round_to_pixel(pos.y), + ); + let num_chars = galley.char_count_excluding_newlines(); out.reserve_triangles(num_chars * 2); out.reserve_vertices(num_chars * 4); diff --git a/epaint/src/text/font.rs b/epaint/src/text/font.rs index 3540f36f..c530df44 100644 --- a/epaint/src/text/font.rs +++ b/epaint/src/text/font.rs @@ -80,7 +80,13 @@ impl FontImpl { let scale_in_pixels = pixels_per_point * scale_in_points; + // Round to an even number of physical pixels to get even kerning. + // See https://github.com/emilk/egui/issues/382 + let scale_in_pixels = scale_in_pixels.round(); + let scale_in_points = scale_in_pixels / pixels_per_point; + let height_in_points = scale_in_points; + // TODO: use v_metrics for line spacing ? // let v = rusttype_font.v_metrics(Scale::uniform(scale_in_pixels)); // let height_in_pixels = v.ascent - v.descent + v.line_gap;