use std::num::NonZeroU16;
use crate::text::glyph::{FontData, GlyphIDType};
use crate::text::{ShapedText, Shaper};
const COLLECTION: &[u8] = include_bytes!("../../../tests/fixtures/collection.ttc");
fn inked_glyphs(index: u32, text: &str) -> Option<usize> {
let data = FontData::from(COLLECTION.to_vec()).with_face_index(index);
let shaper = Shaper::new(GlyphIDType::face(NonZeroU16::MIN), data);
if !shaper.valid() {
return None;
}
let text: Vec<char> = text.chars().collect();
let mut shaped = ShapedText::default();
shaper.shape(&text, false, &mut shaped);
let ids = shaped.glyphs;
Some(
ids.iter().filter(|id| id.code != 0 && shaper.rasterize_glyph(**id).bitmap.data.iter().any(|&a| a > 0)).count(),
)
}
#[test]
fn each_face_of_a_collection_draws_its_own_glyphs() {
assert_eq!(inked_glyphs(0, "中"), Some(0));
assert!(inked_glyphs(0, "ខ").unwrap() > 0);
assert_eq!(inked_glyphs(1, "中"), Some(1));
assert_eq!(inked_glyphs(1, "ខ"), Some(0));
assert_eq!(inked_glyphs(2, "中"), None);
}
#[test]
fn a_single_font_has_only_face_zero() {
let khmer = include_bytes!("../../../tests/fixtures/khmer.ttf").to_vec();
let face =
|index| Shaper::new(GlyphIDType::face(NonZeroU16::MIN), FontData::from(khmer.clone()).with_face_index(index));
assert!(face(0).valid());
assert!(!face(1).valid());
}