use cosmic_text::fontdb::Database;
#[cfg(target_os = "windows")]
mod platform {
pub(super) const MONOSPACE: &[&str] = &["Consolas", "Cascadia Mono", "Courier New"];
pub(super) const SERIF: &[&str] = &["Times New Roman"];
}
#[cfg(target_os = "macos")]
mod platform {
pub(super) const MONOSPACE: &[&str] = &["Menlo", "Monaco", "Courier New"];
pub(super) const SERIF: &[&str] = &["Times", "Times New Roman"];
}
#[cfg(target_os = "ios")]
mod platform {
pub(super) const SANS_SERIF: &[&str] = &[
".SF UI",
".SF UI Text",
".SF NS",
"Helvetica Neue",
"Helvetica",
"Arial",
];
pub(super) const MONOSPACE: &[&str] = &["Menlo", "Courier New", "Courier"];
pub(super) const SERIF: &[&str] = &["Times New Roman", "Georgia"];
}
#[cfg(not(any(target_os = "windows", target_os = "macos", target_os = "ios")))]
mod platform {
pub(super) const MONOSPACE: &[&str] = &["DejaVu Sans Mono", "Noto Sans Mono", "Liberation Mono"];
pub(super) const SERIF: &[&str] = &["DejaVu Serif", "Noto Serif", "Liberation Serif"];
}
pub(super) fn set_generic_families(db: &mut Database) {
#[cfg(target_os = "ios")]
if let Some(family) = first_installed(db, platform::SANS_SERIF) {
db.set_sans_serif_family(family);
}
if let Some(family) = first_installed(db, platform::MONOSPACE) {
db.set_monospace_family(family);
}
if let Some(family) = first_installed(db, platform::SERIF) {
db.set_serif_family(family);
}
}
fn first_installed(db: &Database, families: &[&'static str]) -> Option<&'static str> {
families.iter().copied().find(|family| {
db.faces()
.any(|face| face.families.iter().any(|(name, _)| name == family))
})
}