Fix always failing freetype call, version 0.3.2
This commit is contained in:
parent
bc84362102
commit
09ca5d2bf3
6 changed files with 28 additions and 9 deletions
2
Cargo.lock
generated
2
Cargo.lock
generated
|
@ -1668,7 +1668,7 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "mpd_info_screen"
|
name = "mpd_info_screen"
|
||||||
version = "0.3.1"
|
version = "0.3.2"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bindgen",
|
"bindgen",
|
||||||
"freetype",
|
"freetype",
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
[package]
|
[package]
|
||||||
name = "mpd_info_screen"
|
name = "mpd_info_screen"
|
||||||
version = "0.3.1"
|
version = "0.3.2"
|
||||||
edition = "2018"
|
edition = "2018"
|
||||||
description = "Displays info on currently playing music from an MPD daemon"
|
description = "Displays info on currently playing music from an MPD daemon"
|
||||||
license = "MIT"
|
license = "MIT"
|
||||||
|
|
|
@ -25,7 +25,7 @@ installed already).
|
||||||
# Usage
|
# Usage
|
||||||
|
|
||||||
|
|
||||||
mpd_info_screen 0.3.1
|
mpd_info_screen 0.3.2
|
||||||
|
|
||||||
USAGE:
|
USAGE:
|
||||||
mpd_info_screen [FLAGS] [OPTIONS] <host> [port]
|
mpd_info_screen [FLAGS] [OPTIONS] <host> [port]
|
||||||
|
|
|
@ -740,6 +740,11 @@ impl EventHandler for MPDDisplay {
|
||||||
&mut self.loaded_fonts,
|
&mut self.loaded_fonts,
|
||||||
ctx,
|
ctx,
|
||||||
);
|
);
|
||||||
|
log(
|
||||||
|
format!("loaded_fonts size is {}", self.loaded_fonts.len()),
|
||||||
|
debug_log::LogState::Debug,
|
||||||
|
self.opts.log_level,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
self.dirty_flag
|
self.dirty_flag
|
||||||
|
|
|
@ -3,3 +3,17 @@ mod freetype;
|
||||||
|
|
||||||
pub use self::freetype::font_has_char;
|
pub use self::freetype::font_has_char;
|
||||||
pub use fontconfig::{get_matching_font_from_char, get_matching_font_from_str};
|
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'");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -27,7 +27,7 @@ mod ffi {
|
||||||
pub fn new() -> Option<FTLibrary> {
|
pub fn new() -> Option<FTLibrary> {
|
||||||
unsafe {
|
unsafe {
|
||||||
let mut library_ptr: FT_Library = 0 as FT_Library;
|
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 {
|
Some(FTLibrary {
|
||||||
library: library_ptr,
|
library: library_ptr,
|
||||||
})
|
})
|
||||||
|
@ -98,7 +98,7 @@ mod ffi {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl FTFaces {
|
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() };
|
let mut faces = FTFaces { faces: Vec::new() };
|
||||||
unsafe {
|
unsafe {
|
||||||
let mut face: FT_Face = 0 as FT_Face;
|
let mut face: FT_Face = 0 as FT_Face;
|
||||||
|
@ -111,7 +111,7 @@ mod ffi {
|
||||||
);
|
);
|
||||||
if result != 0 {
|
if result != 0 {
|
||||||
FT_Done_Face(face);
|
FT_Done_Face(face);
|
||||||
return Err(());
|
return Err(String::from("Failed to get number of faces"));
|
||||||
}
|
}
|
||||||
let count = (*face).num_faces;
|
let count = (*face).num_faces;
|
||||||
|
|
||||||
|
@ -124,7 +124,7 @@ mod ffi {
|
||||||
);
|
);
|
||||||
if result != 0 {
|
if result != 0 {
|
||||||
FT_Done_Face(face);
|
FT_Done_Face(face);
|
||||||
return Err(());
|
return Err(String::from("Failed to fetch face"));
|
||||||
}
|
}
|
||||||
faces.faces.push(face);
|
faces.faces.push(face);
|
||||||
}
|
}
|
||||||
|
@ -150,8 +150,8 @@ mod ffi {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn font_has_char(c: char, font_path: &Path) -> Result<bool, ()> {
|
pub fn font_has_char(c: char, font_path: &Path) -> Result<bool, String> {
|
||||||
let library = ffi::FTLibrary::new().ok_or(())?;
|
let library = ffi::FTLibrary::new().ok_or(String::from("Failed to get FTLibrary"))?;
|
||||||
let mut args = ffi::FTOpenArgs::new_with_path(font_path);
|
let mut args = ffi::FTOpenArgs::new_with_path(font_path);
|
||||||
let faces = ffi::FTFaces::new(&library, &mut args)?;
|
let faces = ffi::FTFaces::new(&library, &mut args)?;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue