From 4fd574cc7f0132099d6b66727d6edbd84d10bed3 Mon Sep 17 00:00:00 2001 From: Wez Furlong Date: Wed, 25 Nov 2020 15:05:18 -0800 Subject: [PATCH] freetype: enable FT_Error_String By default, freetype doesn't include error strings and FT_Error_String will always return NULL. Turn on the compile time option that makes this function useful! --- deps/freetype/build.rs | 4 ++++ wezterm-font/src/ftwrap.rs | 15 ++++++++++++++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/deps/freetype/build.rs b/deps/freetype/build.rs index f33ada310..9fd3311cb 100644 --- a/deps/freetype/build.rs +++ b/deps/freetype/build.rs @@ -148,6 +148,10 @@ fn freetype() { build_dir.join("freetype2/include/freetype/config/ftoption.h"), fs::read_to_string("freetype2/include/freetype/config/ftoption.h") .unwrap() + .replace( + "/* #define FT_CONFIG_OPTION_ERROR_STRINGS */", + "#define FT_CONFIG_OPTION_ERROR_STRINGS", + ) .replace( "/* #define FT_CONFIG_OPTION_SYSTEM_ZLIB */", "#define FT_CONFIG_OPTION_SYSTEM_ZLIB", diff --git a/wezterm-font/src/ftwrap.rs b/wezterm-font/src/ftwrap.rs index 1636f2c61..ac6b05914 100644 --- a/wezterm-font/src/ftwrap.rs +++ b/wezterm-font/src/ftwrap.rs @@ -16,7 +16,20 @@ fn ft_result(err: FT_Error, t: T) -> anyhow::Result { if succeeded(err) { Ok(t) } else { - Err(anyhow!("FreeType error {:?} 0x{:x}", err, err)) + unsafe { + let reason = FT_Error_String(err); + if reason.is_null() { + Err(anyhow!("FreeType error {:?} 0x{:x}", err, err)) + } else { + let reason = std::ffi::CStr::from_ptr(reason); + Err(anyhow!( + "FreeType error {:?} 0x{:x}: {}", + err, + err, + reason.to_string_lossy() + )) + } + } } }