diff --git a/wezterm-font/src/lib.rs b/wezterm-font/src/lib.rs index ea10f935d..1b63a12d1 100644 --- a/wezterm-font/src/lib.rs +++ b/wezterm-font/src/lib.rs @@ -2,7 +2,7 @@ use crate::db::FontDatabase; use crate::locator::{new_locator, FontDataHandle, FontLocator, FontLocatorSelection}; use crate::rasterizer::{new_rasterizer, FontRasterizer}; use crate::shaper::{new_shaper, FontShaper, FontShaperSelection}; -use anyhow::Error; +use anyhow::{Context, Error}; use config::{configuration, ConfigHandle, FontRasterizerSelection, TextStyle}; use std::cell::RefCell; use std::collections::{HashMap, HashSet}; @@ -290,7 +290,12 @@ impl FontConfigInner { let font_size = config.font_size * *self.font_scale.borrow(); let dpi = *self.dpi_scale.borrow() as u32 * config.dpi.unwrap_or(::window::DEFAULT_DPI) as u32; - let metrics = shaper.metrics(font_size, dpi)?; + let metrics = shaper.metrics(font_size, dpi).with_context(|| { + format!( + "obtaining metrics for font_size={} @ dpi {}", + font_size, dpi + ) + })?; let loaded = Rc::new(LoadedFont { rasterizers: RefCell::new(HashMap::new()), diff --git a/wezterm-gui/src/gui/termwindow.rs b/wezterm-gui/src/gui/termwindow.rs index 132248de6..012cdfbed 100644 --- a/wezterm-gui/src/gui/termwindow.rs +++ b/wezterm-gui/src/gui/termwindow.rs @@ -2134,6 +2134,19 @@ impl TermWindow { } fn apply_scale_change(&mut self, dimensions: &Dimensions, font_scale: f64) { + let config = configuration(); + let font_size = config.font_size * font_scale; + let theoretical_height = font_size * dimensions.dpi as f64 / 72.0; + + if theoretical_height < 2.0 { + log::warn!("refusing to go to an unreasonably small font scale {:?} " + "font_scale={} would yield font_height {}", + dimensions, + font_scale, + theoretical_height); + return; + } + let (prior_font, prior_dpi) = self .fonts .change_scaling(font_scale, dimensions.dpi as f64 / ::window::DEFAULT_DPI);