use super::build::{style_italic, style_weight}; #[cfg(not(target_arch = "wasm32"))] use super::dirs::sfnt_of; use super::face::{MAX_AXES, MAX_INSTANCES}; use super::names::{all_names, name, norm}; use super::traits::{FaceKeys, FaceStyle, FontTraits, face_styles}; use super::{FileRef, MetadataProvider, Path, StringId, Tag}; /// The named instances of a variable font face (its `fvar` table) as styles of the face's family, /// named by their subfamily names, without the default instance (the face itself) and without /// names already taken. The default instance's name, when it isn't the face's style name (a face /// `Regular` whose default instance is `Book`), names the face too (`keys`). Damaged tables give /// fewer instances or none; the counts read are capped. pub(super) fn named_instances( f: &skrifa::FontRef<'_>, family: &str, style: &str, keys: &mut FaceKeys, native_family: Option, ) -> (Vec, Option) { let axes = f.axes(); if axes.is_empty() || axes.len() > MAX_AXES { return (vec![], None); } let tags: Vec = axes.iter().map(|a| a.tag()).collect(); let defaults: Vec = axes.iter().map(|a| a.default_value()).collect(); let is_default = |coords: &[f32]| coords.len() == defaults.len() && coords.iter().zip(&defaults).all(|(c, d)| (c - d).abs() < 1e-3); // The face renders as its default instance. When that instance is another weight than the // name table says (`Light` face, Regular default instance), the instance names the face. let renamed = tags.iter().any(|t| t.to_be_bytes() == *b"wght").then(|| { f.named_instances() .iter() .take(MAX_INSTANCES) .filter(|inst| is_default(&inst.user_coords().take(MAX_AXES).collect::>())) .find_map(|inst| name(f, &[inst.subfamily_name_id()])) .filter(|d| style_weight(d) != style_weight(style)) }); let renamed = renamed.flatten(); // Instances without a PostScript name of their own are named `-