12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364 |
- use super::*;
- const FONT_PATH: &'static str = "libschrift/resources/FiraGO-Regular.ttf";
- #[test]
- fn version_test() {
- assert_eq!(version_info(), "0.10.2");
- }
- #[test]
- fn load_test() {
- let _font = Font::load_from_file(FONT_PATH).unwrap();
- }
- #[test]
- fn lookup_test() {
- let font = Font::load_from_file(FONT_PATH).unwrap();
- let sch = Schrift::build(font).build();
- sch.glyph_lookup('a')
- .expect("couldn't look up lowercase 'a'");
- sch.glyph_lookup('\u{13080}')
- .expect("couldn't look up hieroglyph");
- }
- #[test]
- fn metrics_test() {
- let font = Font::load_from_file(FONT_PATH).unwrap();
- let sch = Schrift::build(font).with_scale(10.0).build();
- let aglyph = sch
- .glyph_lookup('a')
- .expect("couldn't look up lowercase 'a'");
- let agm = sch
- .glyph_metrics(aglyph)
- .expect("couldn't get glyph metrics");
- // check the extracted advance value
- println!("{agm:?}");
- assert!((agm.advance - 5.44).abs() < 1e-8);
- }
- #[test]
- fn render_test() {
- let font = Font::load_from_file(FONT_PATH).unwrap();
- let sch = Schrift::build(font)
- .with_scale(10.0)
- .flag_y_downwards()
- .build();
- let aglyph = sch
- .glyph_lookup('a')
- .expect("couldn't look up lowercase 'a'");
- let mut pxdata = vec![0u8; 256];
- sch.render(aglyph, pxdata.as_mut_slice(), 16, 16).expect("couldn't render lowercase 'a'");
- let mut pgm = String::new();
- pgm.push_str("P2\n16 16\n255\n");
- for y in 0..16 {
- for x in 0..16 {
- pgm.push_str(format!(" {}", pxdata[x + (y * 16)]).as_str());
- }
- pgm.push_str("\n");
- }
- std::fs::write(concat!(env!("OUT_DIR"), "render_test.pgm"), pgm).unwrap();
- }
|