Fix uneven text kerning for non-integral dpi scales

Closes https://github.com/emilk/egui/issues/382
This commit is contained in:
Emil Ernerfeldt 2021-05-12 19:41:45 +02:00
parent 50a2ed0a14
commit 9c475204da
2 changed files with 13 additions and 0 deletions

View File

@ -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);

View File

@ -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;