Scale all fonts based on device-pixel-ratio
Rather than use DPI from config, use device-pixel-ratio from winit. This is computed using the display DPI anyhow, so it should have the same effect.
This commit is contained in:
parent
b03ec0df37
commit
2ea20f4823
|
@ -246,9 +246,9 @@ run. On most systems this often defaults to
|
||||||
`$HOME/.config/alacritty/alacritty.yml`.
|
`$HOME/.config/alacritty/alacritty.yml`.
|
||||||
|
|
||||||
Many configuration options will take effect immediately upon saving changes to
|
Many configuration options will take effect immediately upon saving changes to
|
||||||
the config file. The only exception is the `font`, `dimensions` and `dpi`
|
the config file. The only exception is the `font` and `dimensions` sections
|
||||||
sections which requires Alacritty to be restarted. For further explanation of
|
which requires Alacritty to be restarted. For further explanation of the config
|
||||||
the config file, please consult the comments in the default config file.
|
file, please consult the comments in the default config file.
|
||||||
|
|
||||||
## Issues (known, unknown, feature requests, etc)
|
## Issues (known, unknown, feature requests, etc)
|
||||||
|
|
||||||
|
|
|
@ -27,12 +27,6 @@ padding:
|
||||||
x: 2
|
x: 2
|
||||||
y: 2
|
y: 2
|
||||||
|
|
||||||
# The FreeType rasterizer needs to know the device DPI for best results
|
|
||||||
# (changes require restart)
|
|
||||||
dpi:
|
|
||||||
x: 96.0
|
|
||||||
y: 96.0
|
|
||||||
|
|
||||||
# Display tabs using this many cells (changes require restart)
|
# Display tabs using this many cells (changes require restart)
|
||||||
tabspaces: 8
|
tabspaces: 8
|
||||||
|
|
||||||
|
|
|
@ -26,12 +26,6 @@ padding:
|
||||||
x: 2
|
x: 2
|
||||||
y: 2
|
y: 2
|
||||||
|
|
||||||
# The FreeType rasterizer needs to know the device DPI for best results
|
|
||||||
# (changes require restart)
|
|
||||||
dpi:
|
|
||||||
x: 96.0
|
|
||||||
y: 96.0
|
|
||||||
|
|
||||||
# Display tabs using this many cells (changes require restart)
|
# Display tabs using this many cells (changes require restart)
|
||||||
tabspaces: 8
|
tabspaces: 8
|
||||||
|
|
||||||
|
|
|
@ -130,7 +130,7 @@ impl ::std::fmt::Display for Error {
|
||||||
impl ::Rasterize for Rasterizer {
|
impl ::Rasterize for Rasterizer {
|
||||||
type Err = Error;
|
type Err = Error;
|
||||||
|
|
||||||
fn new(_dpi_x: f32, _dpi_y: f32, device_pixel_ratio: f32, use_thin_strokes: bool) -> Result<Rasterizer, Error> {
|
fn new(device_pixel_ratio: f32, use_thin_strokes: bool) -> Result<Rasterizer, Error> {
|
||||||
info!("device_pixel_ratio: {}", device_pixel_ratio);
|
info!("device_pixel_ratio: {}", device_pixel_ratio);
|
||||||
Ok(Rasterizer {
|
Ok(Rasterizer {
|
||||||
fonts: HashMap::new(),
|
fonts: HashMap::new(),
|
||||||
|
|
|
@ -63,9 +63,7 @@ pub struct FreeTypeRasterizer {
|
||||||
faces: HashMap<FontKey, Face>,
|
faces: HashMap<FontKey, Face>,
|
||||||
library: Library,
|
library: Library,
|
||||||
keys: HashMap<PathBuf, FontKey>,
|
keys: HashMap<PathBuf, FontKey>,
|
||||||
dpi_x: u32,
|
device_pixel_ratio: f32,
|
||||||
dpi_y: u32,
|
|
||||||
dpr: f32,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
|
@ -76,16 +74,14 @@ fn to_freetype_26_6(f: f32) -> isize {
|
||||||
impl ::Rasterize for FreeTypeRasterizer {
|
impl ::Rasterize for FreeTypeRasterizer {
|
||||||
type Err = Error;
|
type Err = Error;
|
||||||
|
|
||||||
fn new(dpi_x: f32, dpi_y: f32, device_pixel_ratio: f32, _: bool) -> Result<FreeTypeRasterizer, Error> {
|
fn new(device_pixel_ratio: f32, _: bool) -> Result<FreeTypeRasterizer, Error> {
|
||||||
let library = Library::init()?;
|
let library = Library::init()?;
|
||||||
|
|
||||||
Ok(FreeTypeRasterizer {
|
Ok(FreeTypeRasterizer {
|
||||||
faces: HashMap::new(),
|
faces: HashMap::new(),
|
||||||
keys: HashMap::new(),
|
keys: HashMap::new(),
|
||||||
library: library,
|
library: library,
|
||||||
dpi_x: dpi_x as u32,
|
device_pixel_ratio: device_pixel_ratio,
|
||||||
dpi_y: dpi_y as u32,
|
|
||||||
dpr: device_pixel_ratio,
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -152,8 +148,7 @@ impl FreeTypeRasterizer {
|
||||||
/// Load a font face accoring to `FontDesc`
|
/// Load a font face accoring to `FontDesc`
|
||||||
fn get_face(&mut self, desc: &FontDesc, size: Size) -> Result<Face, Error> {
|
fn get_face(&mut self, desc: &FontDesc, size: Size) -> Result<Face, Error> {
|
||||||
// Adjust for DPI
|
// Adjust for DPI
|
||||||
let scale = self.dpi_x as f32 / 72.;
|
let size = Size::new(size.as_f32_pts() * self.device_pixel_ratio * 96. / 72.);
|
||||||
let size = Size::new(size.as_f32_pts() * scale);
|
|
||||||
|
|
||||||
match desc.style {
|
match desc.style {
|
||||||
Style::Description { slant, weight } => {
|
Style::Description { slant, weight } => {
|
||||||
|
@ -278,7 +273,7 @@ impl FreeTypeRasterizer {
|
||||||
|
|
||||||
let size = face.non_scalable.as_ref()
|
let size = face.non_scalable.as_ref()
|
||||||
.map(|v| v.pixelsize as f32)
|
.map(|v| v.pixelsize as f32)
|
||||||
.unwrap_or_else(|| glyph_key.size.as_f32_pts() * self.dpi_x as f32 / 72.);
|
.unwrap_or_else(|| glyph_key.size.as_f32_pts() * self.device_pixel_ratio * 96. / 72.);
|
||||||
|
|
||||||
face.ft_face.set_char_size(to_freetype_26_6(size), 0, 0, 0)?;
|
face.ft_face.set_char_size(to_freetype_26_6(size), 0, 0, 0)?;
|
||||||
|
|
||||||
|
|
|
@ -229,7 +229,7 @@ pub trait Rasterize {
|
||||||
type Err: ::std::error::Error + Send + Sync + 'static;
|
type Err: ::std::error::Error + Send + Sync + 'static;
|
||||||
|
|
||||||
/// Create a new Rasterize
|
/// Create a new Rasterize
|
||||||
fn new(dpi_x: f32, dpi_y: f32, device_pixel_ratio: f32, use_thin_strokes: bool) -> Result<Self, Self::Err>
|
fn new(device_pixel_ratio: f32, use_thin_strokes: bool) -> Result<Self, Self::Err>
|
||||||
where Self: Sized;
|
where Self: Sized;
|
||||||
|
|
||||||
/// Get `Metrics` for the given `FontKey`
|
/// Get `Metrics` for the given `FontKey`
|
||||||
|
|
|
@ -222,10 +222,6 @@ pub struct Config {
|
||||||
#[serde(default="default_padding")]
|
#[serde(default="default_padding")]
|
||||||
padding: Delta,
|
padding: Delta,
|
||||||
|
|
||||||
/// Pixels per inch
|
|
||||||
#[serde(default)]
|
|
||||||
dpi: Dpi,
|
|
||||||
|
|
||||||
/// Font configuration
|
/// Font configuration
|
||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
font: Font,
|
font: Font,
|
||||||
|
@ -318,7 +314,6 @@ impl Default for Config {
|
||||||
Config {
|
Config {
|
||||||
draw_bold_text_with_bright_colors: true,
|
draw_bold_text_with_bright_colors: true,
|
||||||
dimensions: Default::default(),
|
dimensions: Default::default(),
|
||||||
dpi: Default::default(),
|
|
||||||
font: Default::default(),
|
font: Default::default(),
|
||||||
render_timer: Default::default(),
|
render_timer: Default::default(),
|
||||||
custom_cursor_colors: false,
|
custom_cursor_colors: false,
|
||||||
|
@ -1133,12 +1128,6 @@ impl Config {
|
||||||
self.dimensions
|
self.dimensions
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get dpi config
|
|
||||||
#[inline]
|
|
||||||
pub fn dpi(&self) -> &Dpi {
|
|
||||||
&self.dpi
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Get visual bell config
|
/// Get visual bell config
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn visual_bell(&self) -> &VisualBellConfig {
|
pub fn visual_bell(&self) -> &VisualBellConfig {
|
||||||
|
@ -1248,38 +1237,6 @@ impl Dimensions {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Pixels per inch
|
|
||||||
///
|
|
||||||
/// This is only used on `FreeType` systems
|
|
||||||
#[derive(Debug, Deserialize)]
|
|
||||||
pub struct Dpi {
|
|
||||||
/// Horizontal dpi
|
|
||||||
x: f32,
|
|
||||||
|
|
||||||
/// Vertical dpi
|
|
||||||
y: f32,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Default for Dpi {
|
|
||||||
fn default() -> Dpi {
|
|
||||||
Dpi { x: 96.0, y: 96.0 }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Dpi {
|
|
||||||
/// Get horizontal dpi
|
|
||||||
#[inline]
|
|
||||||
pub fn x(&self) -> f32 {
|
|
||||||
self.x
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Get vertical dpi
|
|
||||||
#[inline]
|
|
||||||
pub fn y(&self) -> f32 {
|
|
||||||
self.y
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// A delta for a point in a 2 dimensional plane
|
/// A delta for a point in a 2 dimensional plane
|
||||||
#[derive(Clone, Copy, Debug, Deserialize)]
|
#[derive(Clone, Copy, Debug, Deserialize)]
|
||||||
pub struct Delta {
|
pub struct Delta {
|
||||||
|
|
|
@ -134,7 +134,6 @@ impl Display {
|
||||||
) -> Result<Display, Error> {
|
) -> Result<Display, Error> {
|
||||||
// Extract some properties from config
|
// Extract some properties from config
|
||||||
let font = config.font();
|
let font = config.font();
|
||||||
let dpi = config.dpi();
|
|
||||||
let render_timer = config.render_timer();
|
let render_timer = config.render_timer();
|
||||||
|
|
||||||
// Create the window where Alacritty will be displayed
|
// Create the window where Alacritty will be displayed
|
||||||
|
@ -147,7 +146,7 @@ impl Display {
|
||||||
|
|
||||||
info!("device_pixel_ratio: {}", dpr);
|
info!("device_pixel_ratio: {}", dpr);
|
||||||
|
|
||||||
let rasterizer = font::Rasterizer::new(dpi.x(), dpi.y(), dpr, config.use_thin_strokes())?;
|
let rasterizer = font::Rasterizer::new(dpr, config.use_thin_strokes())?;
|
||||||
|
|
||||||
// Create renderer
|
// Create renderer
|
||||||
let mut renderer = QuadRenderer::new(&config, size)?;
|
let mut renderer = QuadRenderer::new(&config, size)?;
|
||||||
|
|
Loading…
Reference in New Issue