gui: handle a failure to compute font metrics at very small scales
https://github.com/wez/wezterm/issues/428
This commit is contained in:
1 parent
42f3a729a8
commit
db964a91a0
3 files changed
+30
-9
No files matched your search
@@ -307,11 +307,16 @@ impl FontConfigInner {
|
||||
Ok(loaded)
|
||||
}
|
||||
|
||||
pub fn change_scaling(&self, font_scale: f64, dpi_scale: f64) {
|
||||
pub fn change_scaling(&self, font_scale: f64, dpi_scale: f64) -> (f64, f64) {
|
||||
let prior_font = *self.font_scale.borrow();
|
||||
let prior_dpi = *self.dpi_scale.borrow();
|
||||
|
||||
*self.dpi_scale.borrow_mut() = dpi_scale;
|
||||
*self.font_scale.borrow_mut() = font_scale;
|
||||
self.fonts.borrow_mut().clear();
|
||||
self.metrics.borrow_mut().take();
|
||||
|
||||
(prior_font, prior_dpi)
|
||||
}
|
||||
|
||||
/// Returns the baseline font specified in the configuration
|
||||
@@ -393,7 +398,7 @@ impl FontConfiguration {
|
||||
self.inner.resolve_font(&self.inner, style)
|
||||
}
|
||||
|
||||
pub fn change_scaling(&self, font_scale: f64, dpi_scale: f64) {
|
||||
pub fn change_scaling(&self, font_scale: f64, dpi_scale: f64) -> (f64, f64) {
|
||||
self.inner.change_scaling(font_scale, dpi_scale)
|
||||
}
|
||||
|
||||
|
||||
@@ -921,7 +921,7 @@ impl TermWindow {
|
||||
let physical_rows = size.rows as usize;
|
||||
let physical_cols = size.cols as usize;
|
||||
|
||||
let render_metrics = RenderMetrics::new(&fontconfig);
|
||||
let render_metrics = RenderMetrics::new(&fontconfig)?;
|
||||
log::trace!("using render_metrics {:#?}", render_metrics);
|
||||
|
||||
let terminal_size = PtySize {
|
||||
@@ -2134,9 +2134,24 @@ impl TermWindow {
|
||||
}
|
||||
|
||||
fn apply_scale_change(&mut self, dimensions: &Dimensions, font_scale: f64) {
|
||||
self.fonts
|
||||
let (prior_font, prior_dpi) = self
|
||||
.fonts
|
||||
.change_scaling(font_scale, dimensions.dpi as f64 / ::window::DEFAULT_DPI);
|
||||
self.render_metrics = RenderMetrics::new(&self.fonts);
|
||||
match RenderMetrics::new(&self.fonts) {
|
||||
Ok(metrics) => {
|
||||
self.render_metrics = metrics;
|
||||
}
|
||||
Err(err) => {
|
||||
log::error!(
|
||||
"{:#} while attempting to scale font to {} with {:?}",
|
||||
err,
|
||||
font_scale,
|
||||
dimensions
|
||||
);
|
||||
// Restore prior scaling factors
|
||||
self.fonts.change_scaling(prior_font, prior_dpi);
|
||||
}
|
||||
}
|
||||
self.shape_cache.borrow_mut().clear();
|
||||
|
||||
if let Some(render_state) = self.render_state.as_mut() {
|
||||
|
||||
@@ -2,6 +2,7 @@ use super::glyphcache::GlyphCache;
|
||||
use ::window::bitmaps::atlas::{OutOfTextureSpace, Sprite};
|
||||
use ::window::bitmaps::{BitmapImage, Image, Texture2d};
|
||||
use ::window::*;
|
||||
use anyhow::Context;
|
||||
use config::configuration;
|
||||
use std::rc::Rc;
|
||||
use termwiz::surface::CursorShape;
|
||||
@@ -19,10 +20,10 @@ pub struct RenderMetrics {
|
||||
}
|
||||
|
||||
impl RenderMetrics {
|
||||
pub fn new(fonts: &Rc<FontConfiguration>) -> Self {
|
||||
pub fn new(fonts: &Rc<FontConfiguration>) -> anyhow::Result<Self> {
|
||||
let metrics = fonts
|
||||
.default_font_metrics()
|
||||
.expect("failed to get font metrics!?");
|
||||
.context("failed to get font metrics!?")?;
|
||||
|
||||
let line_height = configuration().line_height;
|
||||
|
||||
@@ -39,14 +40,14 @@ impl RenderMetrics {
|
||||
(2 * underline_height + descender_row).min(cell_height as isize - underline_height);
|
||||
let strike_row = descender_row / 2;
|
||||
|
||||
Self {
|
||||
Ok(Self {
|
||||
descender: metrics.descender,
|
||||
descender_row,
|
||||
descender_plus_two,
|
||||
strike_row,
|
||||
cell_size: Size::new(cell_width as isize, cell_height as isize),
|
||||
underline_height,
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user