diff --git a/src/renderer/fonts/caching_shaper.rs b/src/renderer/fonts/caching_shaper.rs index df36e45..e35cf4d 100644 --- a/src/renderer/fonts/caching_shaper.rs +++ b/src/renderer/fonts/caching_shaper.rs @@ -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 +}