1
1
mirror of https://github.com/wez/wezterm.git synced 2024-11-23 23:21:08 +03:00

improve freetype error context

Tag some font related errors with more context.
This makes it a bit easier to understand where a problem
is coming from.
This commit is contained in:
Wez Furlong 2020-11-25 16:13:11 -08:00
parent 4fd574cc7f
commit 80488ea14d
2 changed files with 22 additions and 6 deletions

View File

@ -172,10 +172,11 @@ impl Face {
},
(),
)
.context("FT_Set_Char_Size")
}
fn select_size(&mut self, idx: usize) -> anyhow::Result<()> {
ft_result(unsafe { FT_Select_Size(self.face, idx as i32) }, ())
ft_result(unsafe { FT_Select_Size(self.face, idx as i32) }, ()).context("FT_Select_Size")
}
pub fn load_and_render_glyph(
@ -185,9 +186,18 @@ impl Face {
render_mode: FT_Render_Mode,
) -> anyhow::Result<&FT_GlyphSlotRec_> {
unsafe {
let res = FT_Load_Glyph(self.face, glyph_index, load_flags);
let slot = ft_result(res, &mut *(*self.face).glyph)?;
ft_result(FT_Render_Glyph(slot, render_mode), slot)
ft_result(FT_Load_Glyph(self.face, glyph_index, load_flags), ()).with_context(
|| {
anyhow!(
"load_and_render_glyph: FT_Load_Glyph glyph_index:{}",
glyph_index
)
},
)?;
let slot = &mut *(*self.face).glyph;
ft_result(FT_Render_Glyph(slot, render_mode), ())
.context("load_and_render_glyph: FT_Render_Glyph")?;
Ok(slot)
}
}
@ -323,6 +333,9 @@ impl Library {
}
pub fn set_lcd_filter(&mut self, filter: FT_LcdFilter) -> anyhow::Result<()> {
unsafe { ft_result(FT_Library_SetLcdFilter(self.lib, filter), ()) }
unsafe {
ft_result(FT_Library_SetLcdFilter(self.lib, filter), ())
.context("FT_Library_SetLcdFilter")
}
}
}

View File

@ -3,6 +3,7 @@ use ::window::bitmaps::{Image, Texture2d};
use ::window::glium::backend::Context as GliumContext;
use ::window::glium::texture::SrgbTexture2d;
use ::window::*;
use anyhow::{anyhow, Context};
use config::{configuration, AllowSquareGlyphOverflow, TextStyle};
use euclid::num::Zero;
use std::collections::HashMap;
@ -168,7 +169,9 @@ impl<T: Texture2d> GlyphCache<T> {
return Ok(Rc::clone(entry));
}
let glyph = self.load_glyph(info, style, followed_by_space)?;
let glyph = self
.load_glyph(info, style, followed_by_space)
.with_context(|| anyhow!("load_glyph {:?} {:?}", info, style))?;
self.glyph_cache.insert(key.to_owned(), Rc::clone(&glyph));
Ok(glyph)
}