&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
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'");
+ }
+ }
+}
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,
})
}
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;
);
if result != 0 {
FT_Done_Face(face);
- return Err(());
+ return Err(String::from("Failed to get number of faces"));
}
let count = (*face).num_faces;
);
if result != 0 {
FT_Done_Face(face);
- return Err(());
+ return Err(String::from("Failed to fetch face"));
}
faces.faces.push(face);
}
}
}
-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)?;