Fix always failing freetype call, version 0.3.2

This commit is contained in:
Stephen Seo 2022-08-01 14:19:23 +09:00
parent bc84362102
commit 09ca5d2bf3
6 changed files with 28 additions and 9 deletions

2
Cargo.lock generated
View file

@ -1668,7 +1668,7 @@ dependencies = [
[[package]]
name = "mpd_info_screen"
version = "0.3.1"
version = "0.3.2"
dependencies = [
"bindgen",
"freetype",

View file

@ -1,6 +1,6 @@
[package]
name = "mpd_info_screen"
version = "0.3.1"
version = "0.3.2"
edition = "2018"
description = "Displays info on currently playing music from an MPD daemon"
license = "MIT"

View file

@ -25,7 +25,7 @@ installed already).
# Usage
mpd_info_screen 0.3.1
mpd_info_screen 0.3.2
USAGE:
mpd_info_screen [FLAGS] [OPTIONS] <host> [port]

View file

@ -740,6 +740,11 @@ impl EventHandler for MPDDisplay {
&mut self.loaded_fonts,
ctx,
);
log(
format!("loaded_fonts size is {}", self.loaded_fonts.len()),
debug_log::LogState::Debug,
self.opts.log_level,
);
}
} else {
self.dirty_flag

View file

@ -3,3 +3,17 @@ mod freetype;
pub use self::freetype::font_has_char;
pub use fontconfig::{get_matching_font_from_char, get_matching_font_from_str};
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_ascii_verify() {
let fetched_path =
get_matching_font_from_char('a').expect("Should be able to find match for 'a'");
if !font_has_char('a', &fetched_path).expect("Should be able to check font for 'a'") {
panic!("fetched font does not have 'a'");
}
}
}

View file

@ -27,7 +27,7 @@ mod ffi {
pub fn new() -> Option<FTLibrary> {
unsafe {
let mut library_ptr: FT_Library = 0 as FT_Library;
if FT_Init_FreeType(&mut library_ptr) != 0 {
if FT_Init_FreeType(&mut library_ptr) == 0 {
Some(FTLibrary {
library: library_ptr,
})
@ -98,7 +98,7 @@ mod ffi {
}
impl FTFaces {
pub fn new(library: &FTLibrary, args: &mut FTOpenArgs) -> Result<FTFaces, ()> {
pub fn new(library: &FTLibrary, args: &mut FTOpenArgs) -> Result<FTFaces, String> {
let mut faces = FTFaces { faces: Vec::new() };
unsafe {
let mut face: FT_Face = 0 as FT_Face;
@ -111,7 +111,7 @@ mod ffi {
);
if result != 0 {
FT_Done_Face(face);
return Err(());
return Err(String::from("Failed to get number of faces"));
}
let count = (*face).num_faces;
@ -124,7 +124,7 @@ mod ffi {
);
if result != 0 {
FT_Done_Face(face);
return Err(());
return Err(String::from("Failed to fetch face"));
}
faces.faces.push(face);
}
@ -150,8 +150,8 @@ mod ffi {
}
}
pub fn font_has_char(c: char, font_path: &Path) -> Result<bool, ()> {
let library = ffi::FTLibrary::new().ok_or(())?;
pub fn font_has_char(c: char, font_path: &Path) -> Result<bool, String> {
let library = ffi::FTLibrary::new().ok_or(String::from("Failed to get FTLibrary"))?;
let mut args = ffi::FTOpenArgs::new_with_path(font_path);
let faces = ffi::FTFaces::new(&library, &mut args)?;