fix(fonts): Fix font scaling (points to pixels conversion) (#814)

Refs #387
macos-click-through
partizan 3 years ago committed by GitHub
parent 1c2fddee66
commit a527c0ebb7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -30,7 +30,8 @@ pub struct CachingShaper {
}
impl CachingShaper {
pub fn new(scale_factor: f32) -> CachingShaper {
pub fn new(device_scale_factor: f32) -> CachingShaper {
let scale_factor = points_to_pixels(device_scale_factor);
CachingShaper {
options: None,
font_loader: FontLoader::new(DEFAULT_FONT_SIZE * scale_factor),
@ -311,3 +312,21 @@ impl CachingShaper {
self.blob_cache.get(&key).unwrap()
}
}
fn points_to_pixels(value: f32) -> f32 {
// Fonts in neovim are using points, not pixels.
//
// Skia docs is incorrectly stating it uses points, but uses pixels:
// https://api.skia.org/classSkFont.html#a7e28a156a517d01bc608c14c761346bf
// https://github.com/mono/SkiaSharp/issues/1147#issuecomment-587421201
//
// So, we need to convert points to pixels.
//
// In reality, this depends on DPI/PPI of monitor, but here we only care about converting
// from points to pixels, so this is standard constant values.
let pixels_per_inch = 96.0;
let points_per_inch = 72.0;
let pixels_per_point = pixels_per_inch / points_per_inch;
value * pixels_per_point
}

Loading…
Cancel
Save