Skip to content

Commit

Permalink
Parse font config sizes as points instead of pixels
Browse files Browse the repository at this point in the history
  • Loading branch information
fredizzimo committed Apr 8, 2024
1 parent fcf5e87 commit 4ff7fc2
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
9 changes: 6 additions & 3 deletions src/renderer/fonts/font_options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ impl FontHinting {
}
}

fn points_to_pixels(value: f32) -> f32 {
pub 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:
Expand All @@ -334,14 +334,17 @@ fn points_to_pixels(value: f32) -> f32 {
//
// 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.
if cfg!(target_os = "macos") {
let pixels = if cfg!(target_os = "macos") {
// On macos points == pixels
value
} else {
let pixels_per_inch = 96.0;
let points_per_inch = 72.0;
value * (pixels_per_inch / points_per_inch)
}
};

log::info!("point_to_pixels {value} -> {pixels}");
pixels
}

impl FontDescription {
Expand Down
7 changes: 4 additions & 3 deletions src/settings/font.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ use std::collections::HashMap;
use serde::Deserialize;

use crate::renderer::fonts::font_options::{
FontDescription, FontEdging, FontFeature, FontHinting, FontOptions, SecondaryFontDescription,
points_to_pixels, FontDescription, FontEdging, FontFeature, FontHinting, FontOptions,
SecondaryFontDescription,
};

#[derive(Debug, Clone, Deserialize, PartialEq)]
Expand Down Expand Up @@ -118,8 +119,8 @@ impl From<FontSettings> for FontOptions {
.collect()
})
.unwrap_or_default(),
size: value.size,
width: value.width.unwrap_or_default(),
size: points_to_pixels(value.size),
width: points_to_pixels(value.width.unwrap_or_default()),
allow_float_size: value.allow_float_size.unwrap_or_default(),
hinting: value
.hinting
Expand Down

0 comments on commit 4ff7fc2

Please sign in to comment.