//! Which shipped fonts a context registers. //! //! These collections see no system fonts, so what is registered first stands //! in for "installed": a family the collection already has, which a later //! registration of the same name would add faces to. Counting a family's faces //! after [`register_gaps`] is therefore how a test sees whether the shipped //! file went in. use parley::fontique::{FontInfoOverride, FontStyle}; use super::*; fn sample_font() -> Blob { static FONT: &[u8] = include_bytes!("../../../guiduck-samples/fonts/DejaVuSans.ttf"); Blob::new(std::sync::Arc::new(FONT)) } fn bare_collection() -> Collection { Collection::new(CollectionOptions { system_fonts: false, ..Default::default() }) } fn faces(collection: &mut Collection) -> usize { collection .family_by_name("DejaVu Sans") .map_or(0, |family| family.fonts().len()) } #[test] fn a_family_nothing_provides_is_registered() { let mut collection = bare_collection(); register_gaps(&mut collection, [sample_font()]); assert_eq!(faces(&mut collection), 1); } /// The case that hid a system's italic and bold: the family is installed with /// every face the application ships, so the installed family serves — and /// keeps its other faces — rather than being replaced by the shipped one. #[test] fn a_family_already_provided_in_full_is_left_to_the_system() { let mut collection = bare_collection(); collection.register_fonts(sample_font(), None); register_gaps(&mut collection, [sample_font()]); assert_eq!(faces(&mut collection), 1, "nothing was added"); } /// Installed, but without the face shipped: the shipped family is registered. #[test] fn a_family_provided_only_in_part_is_registered() { let mut collection = bare_collection(); collection.register_fonts( sample_font(), Some(FontInfoOverride { style: Some(FontStyle::Italic), ..Default::default() }), ); register_gaps(&mut collection, [sample_font()]); assert_eq!(faces(&mut collection), 2, "the shipped regular went in"); }