diff --git a/crates/egui/src/load.rs b/crates/egui/src/load.rs index 6f277cb5eb0..a70986d4c81 100644 --- a/crates/egui/src/load.rs +++ b/crates/egui/src/load.rs @@ -55,17 +55,20 @@ mod bytes_loader; mod texture_loader; -use crate::Context; +use std::borrow::Cow; +use std::fmt::Debug; +use std::ops::Deref; +use std::{error::Error as StdError, fmt::Display, sync::Arc}; + use ahash::HashMap; + use epaint::mutex::Mutex; use epaint::util::FloatOrd; use epaint::util::OrderedFloat; use epaint::TextureHandle; use epaint::{textures::TextureOptions, ColorImage, TextureId, Vec2}; -use std::borrow::Cow; -use std::fmt::Debug; -use std::ops::Deref; -use std::{error::Error as StdError, fmt::Display, sync::Arc}; + +use crate::Context; pub use self::bytes_loader::DefaultBytesLoader; pub use self::texture_loader::DefaultTextureLoader; diff --git a/crates/epaint/src/text/font.rs b/crates/epaint/src/text/font.rs index 163697d5f89..f33ff1cee1c 100644 --- a/crates/epaint/src/text/font.rs +++ b/crates/epaint/src/text/font.rs @@ -72,7 +72,7 @@ pub struct FontImpl { height_in_points: f32, // move each character by this much (hack) - y_offset: f32, + y_offset_in_points: f32, ascent: f32, pixels_per_point: f32, @@ -111,22 +111,23 @@ impl FontImpl { scale_in_points * tweak.y_offset_factor } + tweak.y_offset; - // center scaled glyphs properly - let y_offset_points = y_offset_points + (tweak.scale - 1.0) * 0.5 * (ascent + descent); + // Center scaled glyphs properly: + let height = ascent + descent; + let y_offset_points = y_offset_points - (1.0 - tweak.scale) * 0.5 * height; // 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() as u32; // Round to closest pixel: - let y_offset = (y_offset_points * pixels_per_point).round() / pixels_per_point; + let y_offset_in_points = (y_offset_points * pixels_per_point).round() / pixels_per_point; Self { name, ab_glyph_font, scale_in_pixels, height_in_points: ascent - descent + line_gap, - y_offset, + y_offset_in_points, ascent: ascent + baseline_offset, pixels_per_point, glyph_info_cache: Default::default(), @@ -283,7 +284,8 @@ impl FontImpl { }); let offset_in_pixels = vec2(bb.min.x, bb.min.y); - let offset = offset_in_pixels / self.pixels_per_point + self.y_offset * Vec2::Y; + let offset = + offset_in_pixels / self.pixels_per_point + self.y_offset_in_points * Vec2::Y; UvRect { offset, size: vec2(glyph_width as f32, glyph_height as f32) / self.pixels_per_point,