diff --git a/Cargo.toml b/Cargo.toml index bdcd3dba..ef165aee 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -22,8 +22,8 @@ rayon = "1.6" icu_properties = "1.4" # fontations etc -write-fonts = { version = "0.27.0", features = ["serde", "read"] } -skrifa = "0.19.3" +write-fonts = { version = "0.28.1", features = ["serde", "read"] } +skrifa = "0.20.0" norad = "0.12" # dev dependencies diff --git a/fea-rs/src/common.rs b/fea-rs/src/common.rs index 91d5e1a7..33807da7 100644 --- a/fea-rs/src/common.rs +++ b/fea-rs/src/common.rs @@ -3,7 +3,7 @@ use std::fmt::{Display, Formatter}; use fontdrasil::types::GlyphName; -pub use write_fonts::types::GlyphId; +pub use write_fonts::types::GlyphId16; mod glyph_class; mod glyph_map; @@ -21,7 +21,7 @@ use crate::compile::Anchor; #[derive(Debug, Clone)] pub(crate) enum GlyphOrClass { /// A resolved GlyphId - Glyph(GlyphId), + Glyph(GlyphId16), /// A resolved glyph class Class(GlyphClass), /// An explicit `` glyph @@ -81,14 +81,14 @@ impl GlyphOrClass { } } - pub(crate) fn to_glyph(&self) -> Option { + pub(crate) fn to_glyph(&self) -> Option { match self { GlyphOrClass::Glyph(gid) => Some(*gid), _ => None, } } - pub(crate) fn iter(&self) -> impl Iterator + '_ { + pub(crate) fn iter(&self) -> impl Iterator + '_ { let mut idx = 0; std::iter::from_fn(move || { let next = match &self { @@ -105,12 +105,12 @@ impl GlyphOrClass { /// /// this is used to create the replacement targets for class -> glyph or /// class -> null substitutions. - pub(crate) fn into_iter_for_target(self) -> impl Iterator { + pub(crate) fn into_iter_for_target(self) -> impl Iterator { let mut idx = 0; std::iter::from_fn(move || { let next = match &self { GlyphOrClass::Glyph(id) if idx == 0 => Some(*id), - GlyphOrClass::Null if idx == 0 => Some(GlyphId::NOTDEF), + GlyphOrClass::Null if idx == 0 => Some(GlyphId16::NOTDEF), GlyphOrClass::Class(cls) => cls.items().get(idx).copied(), _ => None, }; diff --git a/fea-rs/src/common/glyph_class.rs b/fea-rs/src/common/glyph_class.rs index 1bbc58a9..e4d04f1c 100644 --- a/fea-rs/src/common/glyph_class.rs +++ b/fea-rs/src/common/glyph_class.rs @@ -1,4 +1,4 @@ -use write_fonts::types::GlyphId; +use write_fonts::types::GlyphId16; use super::GlyphOrClass; @@ -22,7 +22,7 @@ use super::GlyphOrClass; /// /// [spec docs]: http://adobe-type-tools.github.io/afdko/OpenTypeFeatureFileSpecification.html#2g-glyph-classes #[derive(Clone, Debug, PartialEq, Eq, Hash)] -pub(crate) struct GlyphClass(Vec); +pub(crate) struct GlyphClass(Vec); /// A sorted set of unique glyph ids. /// @@ -33,13 +33,13 @@ pub(crate) struct GlyphClass(Vec); /// and stabily sort, so we ensure that these classes are sorted and deduped. #[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] -pub struct GlyphSet(Vec); +pub struct GlyphSet(Vec); impl GlyphClass { /// An empty glyph class pub const EMPTY: Self = GlyphClass(Vec::new()); - pub(crate) fn items(&self) -> &[GlyphId] { + pub(crate) fn items(&self) -> &[GlyphId16] { &self.0 } @@ -48,7 +48,7 @@ impl GlyphClass { self.iter().collect() } - pub(crate) fn iter(&self) -> impl Iterator + '_ { + pub(crate) fn iter(&self) -> impl Iterator + '_ { self.items().iter().copied() } @@ -62,7 +62,7 @@ impl GlyphSet { pub const EMPTY: Self = GlyphSet(Vec::new()); /// Iterate over the glyphs in this class - pub fn iter(&self) -> impl Iterator + '_ { + pub fn iter(&self) -> impl Iterator + '_ { self.0.iter().copied() } @@ -77,24 +77,24 @@ impl GlyphSet { } } -impl std::iter::FromIterator for GlyphClass { - fn from_iter>(iter: T) -> Self { +impl std::iter::FromIterator for GlyphClass { + fn from_iter>(iter: T) -> Self { GlyphClass(iter.into_iter().collect()) } } impl<'a> std::iter::IntoIterator for &'a GlyphClass { - type Item = &'a GlyphId; + type Item = &'a GlyphId16; - type IntoIter = std::slice::Iter<'a, GlyphId>; + type IntoIter = std::slice::Iter<'a, GlyphId16>; fn into_iter(self) -> Self::IntoIter { self.0.iter() } } -impl From> for GlyphClass { - fn from(src: Vec) -> GlyphClass { +impl From> for GlyphClass { + fn from(src: Vec) -> GlyphClass { GlyphClass(src) } } @@ -106,22 +106,22 @@ impl From for GlyphSet { } // our base constructor; all other logic goes through here -impl From> for GlyphSet { - fn from(mut value: Vec) -> Self { +impl From> for GlyphSet { + fn from(mut value: Vec) -> Self { value.sort_unstable(); value.dedup(); Self(value) } } -impl std::iter::FromIterator for GlyphSet { - fn from_iter>(iter: T) -> Self { +impl std::iter::FromIterator for GlyphSet { + fn from_iter>(iter: T) -> Self { iter.into_iter().collect::>().into() } } -impl From for GlyphClass { - fn from(src: GlyphId) -> GlyphClass { +impl From for GlyphClass { + fn from(src: GlyphId16) -> GlyphClass { let slice: &[_] = &[src]; GlyphClass(slice.into()) } diff --git a/fea-rs/src/common/glyph_map.rs b/fea-rs/src/common/glyph_map.rs index 2eb4c7d4..8ca01fc5 100644 --- a/fea-rs/src/common/glyph_map.rs +++ b/fea-rs/src/common/glyph_map.rs @@ -1,6 +1,6 @@ use write_fonts::tables::post::Post; -use super::{GlyphId, GlyphIdent}; +use super::{GlyphId16, GlyphIdent}; use fontdrasil::types::GlyphName; use std::{ borrow::Cow, @@ -9,18 +9,18 @@ use std::{ iter::FromIterator, }; -/// A glyph map for mapping from raw glyph identifiers to numeral `GlyphId`s. +/// A glyph map for mapping from raw glyph identifiers to numeral `GlyphId16`s. /// /// This is used to map from names or CIDS encountered in a FEA file to the actual -/// GlyphIds that will be used in the final font. +/// GlyphId16s that will be used in the final font. /// /// Currently, the only way to construct this type is by calling `collect()` /// on an iterator of cids or names. #[derive(Clone, Debug, Default, PartialEq)] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub struct GlyphMap { - names: HashMap, - cids: HashMap, + names: HashMap, + cids: HashMap, } impl GlyphMap { @@ -36,7 +36,7 @@ impl GlyphMap { /// Generates a reverse map of ids -> raw identifers (names or CIDs) // maybe just for testing? - pub fn reverse_map(&self) -> BTreeMap { + pub fn reverse_map(&self) -> BTreeMap { self.names .iter() .map(|(name, id)| (*id, GlyphIdent::Name(name.clone()))) @@ -66,8 +66,8 @@ impl GlyphMap { } } - /// Return the `GlyphId` for the provided `GlyphIdent` - pub fn get(&self, key: &Q) -> Option { + /// Return the `GlyphId16` for the provided `GlyphIdent` + pub fn get(&self, key: &Q) -> Option { if let Some(name) = key.named() { self.names.get(name).copied() } else if let Some(cid) = key.cid() { @@ -99,7 +99,7 @@ impl FromIterator for GlyphMap { cids: iter .into_iter() .enumerate() - .map(|(i, cid)| (cid, GlyphId::new(i.try_into().unwrap()))) + .map(|(i, cid)| (cid, GlyphId16::new(i.try_into().unwrap()))) .collect(), } } @@ -111,7 +111,7 @@ impl FromIterator for GlyphMap { names: iter .into_iter() .enumerate() - .map(|(i, cid)| (cid, GlyphId::new(i.try_into().unwrap()))) + .map(|(i, cid)| (cid, GlyphId16::new(i.try_into().unwrap()))) .collect(), cids: HashMap::new(), } @@ -124,7 +124,7 @@ impl FromIterator for GlyphMap { let mut names = HashMap::new(); let mut cids = HashMap::new(); for (idx, item) in iter.into_iter().enumerate() { - let idx = GlyphId::new(idx.try_into().unwrap()); + let idx = GlyphId16::new(idx.try_into().unwrap()); match item { GlyphIdent::Cid(cid) => cids.insert(cid, idx), GlyphIdent::Name(name) => names.insert(name, idx), diff --git a/fea-rs/src/compile.rs b/fea-rs/src/compile.rs index 8c0b9b98..b8a0128e 100644 --- a/fea-rs/src/compile.rs +++ b/fea-rs/src/compile.rs @@ -2,7 +2,7 @@ use crate::{parse::ParseTree, DiagnosticSet, GlyphMap}; use fontdrasil::types::GlyphName; -use write_fonts::types::GlyphId; +use write_fonts::types::GlyphId16; use self::{ compile_ctx::CompilationCtx, @@ -145,7 +145,7 @@ pub fn parse_glyph_order(glyphs: &str) -> Result { } }) .collect::>()?; - if map.get(".notdef") != Some(GlyphId::NOTDEF) { + if map.get(".notdef") != Some(GlyphId16::NOTDEF) { Err(GlyphOrderError::MissingNotDef) } else { Ok(map) @@ -161,8 +161,8 @@ mod tests { let raw = std::fs::read_to_string("./test-data/simple_glyph_order.txt").unwrap(); let glyph_map = parse_glyph_order(&raw).unwrap(); assert_eq!(glyph_map.len(), 215); - assert_eq!(glyph_map.get("space"), Some(GlyphId::new(1))); - assert_eq!(glyph_map.get("e.fina"), Some(GlyphId::new(214))); + assert_eq!(glyph_map.get("space"), Some(GlyphId16::new(1))); + assert_eq!(glyph_map.get("e.fina"), Some(GlyphId16::new(214))); assert!(!glyph_map.contains("e.nada")); } } diff --git a/fea-rs/src/compile/compile_ctx.rs b/fea-rs/src/compile/compile_ctx.rs index c331f1c4..04d0d38c 100644 --- a/fea-rs/src/compile/compile_ctx.rs +++ b/fea-rs/src/compile/compile_ctx.rs @@ -22,7 +22,7 @@ use write_fonts::{ }; use crate::{ - common::{GlyphClass, GlyphId, GlyphOrClass, GlyphSet, MarkClass}, + common::{GlyphClass, GlyphId16, GlyphOrClass, GlyphSet, MarkClass}, parse::SourceMap, token_tree::{ typed::{self, AstNode}, @@ -64,7 +64,7 @@ use super::{ /// the final output, ready to be written to binary. pub struct CompilationCtx<'a, F: FeatureProvider, V: VariationInfo> { glyph_map: &'a GlyphMap, - reverse_glyph_map: BTreeMap, + reverse_glyph_map: BTreeMap, source_map: &'a SourceMap, variation_info: Option<&'a V>, feature_writer: Option<&'a F>, @@ -458,6 +458,7 @@ impl<'a, F: FeatureProvider, V: VariationInfo> CompilationCtx<'a, F, V> { } fn set_lookup_flag(&mut self, node: typed::LookupFlag) { + self.lookup_flags.clear(); if let Some(number) = node.number() { self.lookup_flags.flags = LookupFlag::from_bits_truncate(number.parse_unsigned().unwrap()); @@ -470,10 +471,10 @@ impl<'a, F: FeatureProvider, V: VariationInfo> CompilationCtx<'a, F, V> { let mut iter = node.values(); while let Some(next) = iter.next() { match next.kind() { - Kind::RightToLeftKw => flags.set_right_to_left(true), - Kind::IgnoreBaseGlyphsKw => flags.set_ignore_base_glyphs(true), - Kind::IgnoreLigaturesKw => flags.set_ignore_ligatures(true), - Kind::IgnoreMarksKw => flags.set_ignore_marks(true), + Kind::RightToLeftKw => flags |= LookupFlag::RIGHT_TO_LEFT, + Kind::IgnoreBaseGlyphsKw => flags |= LookupFlag::IGNORE_BASE_GLYPHS, + Kind::IgnoreLigaturesKw => flags |= LookupFlag::IGNORE_LIGATURES, + Kind::IgnoreMarksKw => flags |= LookupFlag::IGNORE_MARKS, //FIXME: we are not enforcing some requirements here. in particular, // The glyph sets of the referenced classes must not overlap, and the MarkAttachmentType statement can reference at most 15 different classes. @@ -483,7 +484,7 @@ impl<'a, F: FeatureProvider, V: VariationInfo> CompilationCtx<'a, F, V> { .and_then(typed::GlyphClass::cast) .expect("validated"); let mark_attach_set = self.resolve_mark_attach_class(&node); - flags.set_mark_attachment_type(mark_attach_set); + flags.set_mark_attachment_class(mark_attach_set); } Kind::UseMarkFilteringSetKw => { let node = iter @@ -491,7 +492,7 @@ impl<'a, F: FeatureProvider, V: VariationInfo> CompilationCtx<'a, F, V> { .and_then(typed::GlyphClass::cast) .expect("validated"); let filter_set = self.resolve_mark_filter_set(&node); - flags.set_use_mark_filtering_set(true); + flags |= LookupFlag::USE_MARK_FILTERING_SET; mark_filter_set = Some(filter_set); } other => unreachable!("mark statements have been validated: '{:?}'", other), @@ -1897,6 +1898,7 @@ impl<'a, F: FeatureProvider, V: VariationInfo> CompilationCtx<'a, F, V> { max.to_normalized(&axis.converter).to_f32(), ), } + .into() }) .collect(); let conditionset = ConditionSet::new(conditions); @@ -1929,11 +1931,11 @@ impl<'a, F: FeatureProvider, V: VariationInfo> CompilationCtx<'a, F, V> { } } - fn resolve_glyph(&mut self, item: &typed::Glyph) -> GlyphId { + fn resolve_glyph(&mut self, item: &typed::Glyph) -> GlyphId16 { match item { typed::Glyph::Named(name) => self.resolve_glyph_name(name), typed::Glyph::Cid(name) => self.resolve_cid(name), - typed::Glyph::Null(_) => GlyphId::NOTDEF, + typed::Glyph::Null(_) => GlyphId16::NOTDEF, } } @@ -1979,7 +1981,7 @@ impl<'a, F: FeatureProvider, V: VariationInfo> CompilationCtx<'a, F, V> { .unwrap() } - fn resolve_glyph_name(&mut self, name: &typed::GlyphName) -> GlyphId { + fn resolve_glyph_name(&mut self, name: &typed::GlyphName) -> GlyphId16 { self.glyph_map.get(name.text()).unwrap() } @@ -1999,11 +2001,11 @@ impl<'a, F: FeatureProvider, V: VariationInfo> CompilationCtx<'a, F, V> { result } - fn resolve_cid(&mut self, cid: &typed::Cid) -> GlyphId { + fn resolve_cid(&mut self, cid: &typed::Cid) -> GlyphId16 { self.glyph_map.get(&cid.parse()).unwrap() } - fn add_glyphs_from_range(&mut self, range: &typed::GlyphRange, out: &mut Vec) { + fn add_glyphs_from_range(&mut self, range: &typed::GlyphRange, out: &mut Vec) { let start = range.start(); let end = range.end(); @@ -2045,7 +2047,7 @@ impl<'a, F: FeatureProvider, V: VariationInfo> CompilationCtx<'a, F, V> { } } -fn sequence_enumerator(sequence: &[GlyphOrClass]) -> Vec> { +fn sequence_enumerator(sequence: &[GlyphOrClass]) -> Vec> { assert!(sequence.len() >= 2); let split = sequence.split_first(); let mut result = Vec::new(); @@ -2055,10 +2057,10 @@ fn sequence_enumerator(sequence: &[GlyphOrClass]) -> Vec> { } fn sequence_enumerator_impl( - prefix: Vec, + prefix: Vec, left: &GlyphOrClass, right: &[GlyphOrClass], - acc: &mut Vec>, + acc: &mut Vec>, ) { for glyph in left.iter() { let mut prefix = prefix.clone(); @@ -2103,16 +2105,16 @@ fn get_reasonable_length_span(node: &NodeOrToken) -> Range { mod tests { use super::*; - fn glyph_id_vec(ids: [u16; N]) -> Vec { - ids.iter().copied().map(GlyphId::new).collect() + fn glyph_id_vec(ids: [u16; N]) -> Vec { + ids.iter().copied().map(GlyphId16::new).collect() } #[test] fn sequence_enumerator_smoke_test() { let sequence = vec![ - GlyphOrClass::Glyph(GlyphId::new(1)), - GlyphOrClass::Class([2_u16, 3, 4].iter().copied().map(GlyphId::new).collect()), - GlyphOrClass::Class([8, 9].iter().copied().map(GlyphId::new).collect()), + GlyphOrClass::Glyph(GlyphId16::new(1)), + GlyphOrClass::Class([2_u16, 3, 4].iter().copied().map(GlyphId16::new).collect()), + GlyphOrClass::Class([8, 9].iter().copied().map(GlyphId16::new).collect()), ]; assert_eq!( diff --git a/fea-rs/src/compile/features.rs b/fea-rs/src/compile/features.rs index 041f2c9d..c27cbefd 100644 --- a/fea-rs/src/compile/features.rs +++ b/fea-rs/src/compile/features.rs @@ -5,7 +5,7 @@ use std::collections::{BTreeMap, HashMap, HashSet}; use smol_str::SmolStr; use write_fonts::{ tables::layout::{ConditionSet, FeatureParams, SizeParams, StylisticSetParams}, - types::{GlyphId, Tag, Uint24}, + types::{GlyphId16, Tag, Uint24}, }; use super::{ @@ -57,9 +57,9 @@ pub(crate) struct ActiveFeature { #[derive(Clone, Debug, Default)] pub(crate) struct AaltFeature { aalt_features: Vec, - pub(crate) all_alts: HashMap>, + pub(crate) all_alts: HashMap>, // to avoid duplicates - all_pairs: HashSet<(GlyphId, GlyphId)>, + all_pairs: HashSet<(GlyphId16, GlyphId16)>, } /// Helper for compiling the `size` feature @@ -457,15 +457,15 @@ impl AaltFeature { &self.aalt_features } - pub(crate) fn add(&mut self, target: GlyphId, alt: GlyphId) { + pub(crate) fn add(&mut self, target: GlyphId16, alt: GlyphId16) { if self.all_pairs.insert((target, alt)) { self.all_alts.entry(target).or_default().push(alt); } } } -impl Extend<(GlyphId, GlyphId)> for AaltFeature { - fn extend>(&mut self, iter: T) { +impl Extend<(GlyphId16, GlyphId16)> for AaltFeature { + fn extend>(&mut self, iter: T) { for (target, alt) in iter.into_iter() { self.add(target, alt) } diff --git a/fea-rs/src/compile/lookups.rs b/fea-rs/src/compile/lookups.rs index adc1528d..d3770cb1 100644 --- a/fea-rs/src/compile/lookups.rs +++ b/fea-rs/src/compile/lookups.rs @@ -30,7 +30,7 @@ use write_fonts::{ }; use crate::{ - common::{GlyphId, GlyphOrClass, GlyphSet}, + common::{GlyphId16, GlyphOrClass, GlyphSet}, compile::{lookups::contextual::ChainOrNot, metrics::ValueRecord}, Kind, Opts, }; @@ -300,7 +300,9 @@ where .into_iter() .flat_map(|b| b.build(var_store).into_iter()) .collect(); - RawLookup::new(self.flags, subtables, self.mark_set.unwrap_or_default()) + let mut out = RawLookup::new(self.flags, subtables); + out.mark_filtering_set = self.mark_set; + out } } @@ -512,7 +514,7 @@ impl AllLookups { ))); } - pub(crate) fn infer_glyph_classes(&self, mut f: impl FnMut(GlyphId, GlyphClassDef)) { + pub(crate) fn infer_glyph_classes(&self, mut f: impl FnMut(GlyphId16, GlyphClassDef)) { for lookup in &self.gpos { match lookup { PositionLookup::MarkToBase(lookup) => { @@ -591,7 +593,7 @@ impl AllLookups { pub(crate) fn insert_aalt_lookups( &mut self, - all_alts: HashMap>, + all_alts: HashMap>, ) -> Vec { let mut single = SingleSubBuilder::default(); let mut alt = AlternateSubBuilder::default(); @@ -836,7 +838,7 @@ impl SomeLookup { } } - pub(crate) fn add_gpos_type_1(&mut self, id: GlyphId, record: ValueRecord) { + pub(crate) fn add_gpos_type_1(&mut self, id: GlyphId16, record: ValueRecord) { if let SomeLookup::GposLookup(PositionLookup::Single(table)) = self { let subtable = table.last_mut().unwrap(); subtable.insert(id, record); @@ -847,8 +849,8 @@ impl SomeLookup { pub(crate) fn add_gpos_type_2_pair( &mut self, - one: GlyphId, - two: GlyphId, + one: GlyphId16, + two: GlyphId16, val_one: ValueRecord, val_two: ValueRecord, ) { @@ -876,7 +878,7 @@ impl SomeLookup { } pub(crate) fn add_gpos_type_3( &mut self, - id: GlyphId, + id: GlyphId16, entry: Option, exit: Option, ) { @@ -933,7 +935,7 @@ impl SomeLookup { } } - pub(crate) fn add_gsub_type_1(&mut self, id: GlyphId, replacement: GlyphId) { + pub(crate) fn add_gsub_type_1(&mut self, id: GlyphId16, replacement: GlyphId16) { if let SomeLookup::GsubLookup(SubstitutionLookup::Single(table)) = self { let subtable = table.last_mut().unwrap(); subtable.insert(id, replacement); @@ -942,7 +944,7 @@ impl SomeLookup { } } - pub(crate) fn add_gsub_type_2(&mut self, id: GlyphId, replacement: Vec) { + pub(crate) fn add_gsub_type_2(&mut self, id: GlyphId16, replacement: Vec) { if let SomeLookup::GsubLookup(SubstitutionLookup::Multiple(table)) = self { let subtable = table.last_mut().unwrap(); subtable.insert(id, replacement); @@ -951,7 +953,7 @@ impl SomeLookup { } } - pub(crate) fn add_gsub_type_3(&mut self, id: GlyphId, alternates: Vec) { + pub(crate) fn add_gsub_type_3(&mut self, id: GlyphId16, alternates: Vec) { if let SomeLookup::GsubLookup(SubstitutionLookup::Alternate(table)) = self { let subtable = table.last_mut().unwrap(); subtable.insert(id, alternates); @@ -960,7 +962,7 @@ impl SomeLookup { } } - pub(crate) fn add_gsub_type_4(&mut self, target: Vec, replacement: GlyphId) { + pub(crate) fn add_gsub_type_4(&mut self, target: Vec, replacement: GlyphId16) { if let SomeLookup::GsubLookup(SubstitutionLookup::Ligature(table)) = self { let subtable = table.last_mut().unwrap(); subtable.insert(target, replacement); @@ -972,7 +974,7 @@ impl SomeLookup { pub(crate) fn add_gsub_type_8( &mut self, backtrack: Vec, - input: BTreeMap, + input: BTreeMap, lookahead: Vec, ) { if let SomeLookup::GsubLookup(SubstitutionLookup::Reverse(table)) = self { diff --git a/fea-rs/src/compile/lookups/contextual.rs b/fea-rs/src/compile/lookups/contextual.rs index 781e96a2..1fb839d6 100644 --- a/fea-rs/src/compile/lookups/contextual.rs +++ b/fea-rs/src/compile/lookups/contextual.rs @@ -12,7 +12,7 @@ use write_fonts::{ layout::{self as write_layout, CoverageTableBuilder, LookupFlag}, variations::ivs_builder::VariationStoreBuilder, }, - types::GlyphId, + types::GlyphId16, validate::Validate, FontWrite, }; @@ -205,8 +205,8 @@ impl ContextualLookupBuilder { pub(crate) fn add_anon_gsub_type_2( &mut self, - target: GlyphId, - replacements: Vec, + target: GlyphId16, + replacements: Vec, ) -> LookupId { let (lookup, id) = self.find_or_create_anon_lookup( |existing| match existing { @@ -229,8 +229,8 @@ impl ContextualLookupBuilder { pub(crate) fn add_anon_gsub_type_4( &mut self, - target: Vec, - replacement: GlyphId, + target: Vec, + replacement: GlyphId16, ) -> LookupId { let (lookup, id) = self.find_or_create_anon_lookup( |existing| match existing { @@ -273,7 +273,7 @@ pub(crate) struct ReverseChainBuilder { #[derive(Clone, Debug)] struct ReverseSubRule { backtrack: Vec, - context: BTreeMap, + context: BTreeMap, lookahead: Vec, } @@ -726,7 +726,7 @@ impl ReverseChainBuilder { pub fn add( &mut self, backtrack: Vec, - context: BTreeMap, + context: BTreeMap, lookahead: Vec, ) { self.rules.push(ReverseSubRule { diff --git a/fea-rs/src/compile/lookups/gpos_builders.rs b/fea-rs/src/compile/lookups/gpos_builders.rs index 6aa004ab..3a66a9d1 100644 --- a/fea-rs/src/compile/lookups/gpos_builders.rs +++ b/fea-rs/src/compile/lookups/gpos_builders.rs @@ -9,7 +9,7 @@ use write_fonts::{ layout::CoverageTable, variations::ivs_builder::VariationStoreBuilder, }, - types::GlyphId, + types::GlyphId16, }; use crate::{ @@ -22,16 +22,16 @@ use super::{Builder, ClassDefBuilder2}; #[derive(Clone, Debug, Default, PartialEq, Eq)] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub struct SinglePosBuilder { - items: BTreeMap, + items: BTreeMap, } impl SinglePosBuilder { //TODO: should we track the valueformat here? - pub fn insert(&mut self, glyph: GlyphId, record: ValueRecord) { + pub fn insert(&mut self, glyph: GlyphId16, record: ValueRecord) { self.items.insert(glyph, record); } - pub(crate) fn can_add_rule(&self, glyph: GlyphId, value: &ValueRecord) -> bool { + pub(crate) fn can_add_rule(&self, glyph: GlyphId16, value: &ValueRecord) -> bool { self.items .get(&glyph) .map(|existing| existing == value) @@ -43,7 +43,7 @@ impl Builder for SinglePosBuilder { type Output = Vec; fn build(self, var_store: &mut VariationStoreBuilder) -> Self::Output { - fn build_subtable(items: BTreeMap) -> write_gpos::SinglePos { + fn build_subtable(items: BTreeMap) -> write_gpos::SinglePos { let first = *items.values().next().unwrap(); let use_format_1 = first.format().is_empty() || items.values().all(|val| val == &first); let coverage: CoverageTable = items.keys().copied().collect(); @@ -62,7 +62,7 @@ impl Builder for SinglePosBuilder { // list of sets of glyph ids which will end up in their own subtables let mut subtables = Vec::new(); - let mut group_by_record: HashMap<&RawValueRecord, BTreeMap> = + let mut group_by_record: HashMap<&RawValueRecord, BTreeMap> = Default::default(); // first group by specific record; glyphs that share a record can use @@ -73,7 +73,7 @@ impl Builder for SinglePosBuilder { .or_default() .insert(*gid, value); } - let mut group_by_format: HashMap> = + let mut group_by_format: HashMap> = Default::default(); for (value, glyphs) in group_by_record { // if this saves us size, use format 1 @@ -121,7 +121,7 @@ pub struct PairPosBuilder { #[derive(Clone, Debug, Default, PartialEq)] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] -struct GlyphPairPosBuilder(BTreeMap>); +struct GlyphPairPosBuilder(BTreeMap>); #[derive(Clone, Debug, PartialEq)] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] @@ -210,9 +210,9 @@ impl PairPosBuilder { /// Insert a new kerning pair pub fn insert_pair( &mut self, - glyph1: GlyphId, + glyph1: GlyphId16, record1: ValueRecord, - glyph2: GlyphId, + glyph2: GlyphId16, record2: ValueRecord, ) { // "When specific kern pair rules conflict, the first rule specified is used, @@ -346,12 +346,12 @@ impl Builder for ClassPairPosSubtable { #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub struct CursivePosBuilder { // (entry, exit) - items: BTreeMap, Option)>, + items: BTreeMap, Option)>, } impl CursivePosBuilder { /// Insert a new entry/exit anchor pair for a glyph. - pub fn insert(&mut self, glyph: GlyphId, entry: Option, exit: Option) { + pub fn insert(&mut self, glyph: GlyphId16, entry: Option, exit: Option) { self.items.insert(glyph, (entry, exit)); } } @@ -380,7 +380,7 @@ impl Builder for CursivePosBuilder { #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] struct MarkList { // (class id, anchor) - glyphs: BTreeMap, + glyphs: BTreeMap, // map class names to their idx for this table classes: HashMap, } @@ -391,7 +391,7 @@ impl MarkList { /// Otherwise return the u16 id for this class, in this lookup. fn insert( &mut self, - glyph: GlyphId, + glyph: GlyphId16, class: SmolStr, anchor: Anchor, ) -> Result { @@ -417,7 +417,7 @@ impl MarkList { Ok(id) } - fn glyphs(&self) -> impl Iterator + Clone + '_ { + fn glyphs(&self) -> impl Iterator + Clone + '_ { self.glyphs.keys().copied() } @@ -449,14 +449,14 @@ impl Builder for MarkList { #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub struct MarkToBaseBuilder { marks: MarkList, - bases: BTreeMap>, + bases: BTreeMap>, } /// An error indicating a given glyph has been assigned to multiple mark classes #[derive(Clone, Debug, Default)] pub struct PreviouslyAssignedClass { /// The ID of the glyph in conflict - pub glyph_id: GlyphId, + pub glyph_id: GlyphId16, /// The name of the previous class pub class: SmolStr, } @@ -481,7 +481,7 @@ impl MarkToBaseBuilder { /// previous class; this is likely an error. pub fn insert_mark( &mut self, - glyph: GlyphId, + glyph: GlyphId16, class: SmolStr, anchor: Anchor, ) -> Result { @@ -489,18 +489,18 @@ impl MarkToBaseBuilder { } /// Insert a new base glyph. - pub fn insert_base(&mut self, glyph: GlyphId, class: &SmolStr, anchor: Anchor) { + pub fn insert_base(&mut self, glyph: GlyphId16, class: &SmolStr, anchor: Anchor) { let class = self.marks.get_class(class); self.bases.entry(glyph).or_default().push((class, anchor)) } /// Returns an iterator over all of the base glyphs - pub fn base_glyphs(&self) -> impl Iterator + Clone + '_ { + pub fn base_glyphs(&self) -> impl Iterator + Clone + '_ { self.bases.keys().copied() } /// Returns an iterator over all of the mark glyphs - pub fn mark_glyphs(&self) -> impl Iterator + Clone + '_ { + pub fn mark_glyphs(&self) -> impl Iterator + Clone + '_ { self.marks.glyphs() } } @@ -539,7 +539,7 @@ impl Builder for MarkToBaseBuilder { #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub struct MarkToLigBuilder { marks: MarkList, - ligatures: BTreeMap>>, + ligatures: BTreeMap>>, } impl MarkToLigBuilder { @@ -554,7 +554,7 @@ impl MarkToLigBuilder { /// previous class; this is likely an error. pub fn insert_mark( &mut self, - glyph: GlyphId, + glyph: GlyphId16, class: SmolStr, anchor: Anchor, ) -> Result { @@ -574,7 +574,7 @@ impl MarkToLigBuilder { /// we provide an alternative public method below. pub(crate) fn add_ligature_components( &mut self, - glyph: GlyphId, + glyph: GlyphId16, components: Vec>, ) { self.ligatures.insert(glyph, components); @@ -590,7 +590,7 @@ impl MarkToLigBuilder { /// explicit 'None' in the appropriate ordering. pub fn insert_ligature( &mut self, - glyph: GlyphId, + glyph: GlyphId16, class: SmolStr, components: Vec>, ) { @@ -608,12 +608,12 @@ impl MarkToLigBuilder { } /// Returns an iterator over all of the mark glyphs - pub fn mark_glyphs(&self) -> impl Iterator + Clone + '_ { + pub fn mark_glyphs(&self) -> impl Iterator + Clone + '_ { self.marks.glyphs() } /// Returns an iterator over all of the ligature glyphs - pub fn lig_glyphs(&self) -> impl Iterator + Clone + '_ { + pub fn lig_glyphs(&self) -> impl Iterator + Clone + '_ { self.ligatures.keys().copied() } } @@ -663,7 +663,7 @@ impl Builder for MarkToLigBuilder { #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub struct MarkToMarkBuilder { attaching_marks: MarkList, - base_marks: BTreeMap>, + base_marks: BTreeMap>, } impl MarkToMarkBuilder { @@ -673,7 +673,7 @@ impl MarkToMarkBuilder { /// previous class; this is likely an error. pub fn insert_mark1( &mut self, - glyph: GlyphId, + glyph: GlyphId16, class: SmolStr, anchor: Anchor, ) -> Result { @@ -681,18 +681,18 @@ impl MarkToMarkBuilder { } /// Insert a new mark2 (base) glyph - pub fn insert_mark2(&mut self, glyph: GlyphId, class: &SmolStr, anchor: Anchor) { + pub fn insert_mark2(&mut self, glyph: GlyphId16, class: &SmolStr, anchor: Anchor) { let id = self.attaching_marks.get_class(class); self.base_marks.entry(glyph).or_default().push((id, anchor)) } /// Returns an iterator over all of the mark1 glyphs - pub fn mark1_glyphs(&self) -> impl Iterator + Clone + '_ { + pub fn mark1_glyphs(&self) -> impl Iterator + Clone + '_ { self.attaching_marks.glyphs() } /// Returns an iterator over all of the mark2 glyphs - pub fn mark2_glyphs(&self) -> impl Iterator + Clone + '_ { + pub fn mark2_glyphs(&self) -> impl Iterator + Clone + '_ { self.base_marks.keys().copied() } } diff --git a/fea-rs/src/compile/lookups/gsub_builders.rs b/fea-rs/src/compile/lookups/gsub_builders.rs index 92a73f70..a5897492 100644 --- a/fea-rs/src/compile/lookups/gsub_builders.rs +++ b/fea-rs/src/compile/lookups/gsub_builders.rs @@ -4,7 +4,7 @@ use std::{collections::BTreeMap, convert::TryFrom}; use write_fonts::{ tables::{gsub as write_gsub, variations::ivs_builder::VariationStoreBuilder}, - types::{FixedSize, GlyphId}, + types::{FixedSize, GlyphId16}, }; use crate::common::GlyphOrClass; @@ -13,7 +13,7 @@ use super::Builder; #[derive(Clone, Debug, Default)] pub struct SingleSubBuilder { - items: BTreeMap, + items: BTreeMap, } /// Used to divide pairs into subtables as needed. @@ -26,7 +26,7 @@ enum PossibleSingleSubFormat { } impl SingleSubBuilder { - pub fn insert(&mut self, target: GlyphId, replacement: GlyphId) { + pub fn insert(&mut self, target: GlyphId16, replacement: GlyphId16) { let delta = replacement.to_u16() as i32 - target.to_u16() as i32; let delta = i16::try_from(delta) .map(PossibleSingleSubFormat::Delta) @@ -48,7 +48,7 @@ impl SingleSubBuilder { } // used when compiling aalt - pub(crate) fn iter_pairs(&self) -> impl Iterator + '_ { + pub(crate) fn iter_pairs(&self) -> impl Iterator + '_ { self.items.iter().map(|(target, (alt, _))| (*target, *alt)) } @@ -72,13 +72,13 @@ impl Builder for SingleSubBuilder { 2 + 2; // extra coverage table const N_GLYPHS_TO_JUSTIFY_EXTRA_SUB1F1: usize = - COST_OF_EXTRA_SUB1F1_SUBTABLE / GlyphId::RAW_BYTE_LEN; + COST_OF_EXTRA_SUB1F1_SUBTABLE / GlyphId16::RAW_BYTE_LEN; #[derive(Default)] struct SubtableMap { // key is the delta between the two gylphs. - format1: BTreeMap>, - format2: Vec<(GlyphId, GlyphId)>, + format1: BTreeMap>, + format2: Vec<(GlyphId16, GlyphId16)>, } impl SubtableMap { @@ -148,7 +148,7 @@ impl Builder for SingleSubBuilder { #[derive(Clone, Debug, Default)] pub struct MultipleSubBuilder { - items: BTreeMap>, + items: BTreeMap>, } impl Builder for MultipleSubBuilder { @@ -166,11 +166,11 @@ impl Builder for MultipleSubBuilder { } impl MultipleSubBuilder { - pub fn insert(&mut self, target: GlyphId, replacement: Vec) { + pub fn insert(&mut self, target: GlyphId16, replacement: Vec) { self.items.insert(target, replacement); } - pub fn can_add(&self, target: GlyphId, replacement: &[GlyphId]) -> bool { + pub fn can_add(&self, target: GlyphId16, replacement: &[GlyphId16]) -> bool { match self.items.get(&target) { None => true, Some(thing) => thing == replacement, @@ -180,11 +180,11 @@ impl MultipleSubBuilder { #[derive(Clone, Debug, Default)] pub struct AlternateSubBuilder { - items: BTreeMap>, + items: BTreeMap>, } impl AlternateSubBuilder { - pub fn insert(&mut self, target: GlyphId, replacement: Vec) { + pub fn insert(&mut self, target: GlyphId16, replacement: Vec) { self.items.insert(target, replacement); } @@ -193,7 +193,7 @@ impl AlternateSubBuilder { } // used when compiling aalt - pub(crate) fn iter_pairs(&self) -> impl Iterator + '_ { + pub(crate) fn iter_pairs(&self) -> impl Iterator + '_ { self.items .iter() .flat_map(|(target, alt)| alt.iter().map(|alt| (*target, *alt))) @@ -216,11 +216,11 @@ impl Builder for AlternateSubBuilder { #[derive(Clone, Debug, Default)] pub struct LigatureSubBuilder { - items: BTreeMap, GlyphId)>>, + items: BTreeMap, GlyphId16)>>, } impl LigatureSubBuilder { - pub fn insert(&mut self, target: Vec, replacement: GlyphId) { + pub fn insert(&mut self, target: Vec, replacement: GlyphId16) { let mut iter = target.into_iter(); let first = iter.next().unwrap(); let rest = iter.collect::>(); @@ -230,7 +230,7 @@ impl LigatureSubBuilder { .push((rest, replacement)); } - pub fn contains_target(&self, target: GlyphId) -> bool { + pub fn contains_target(&self, target: GlyphId16) -> bool { //FIXME: we could be more aggressive here, but for now we will force a new //lookup anytime the target exists? idk self.items.contains_key(&target) diff --git a/fea-rs/src/compile/lookups/helpers.rs b/fea-rs/src/compile/lookups/helpers.rs index cf52736f..31a10fb1 100644 --- a/fea-rs/src/compile/lookups/helpers.rs +++ b/fea-rs/src/compile/lookups/helpers.rs @@ -4,7 +4,7 @@ use std::collections::{HashMap, HashSet}; use write_fonts::tables::layout::{ClassDef, ClassDefBuilder}; -use crate::common::{GlyphId, GlyphSet}; +use crate::common::{GlyphId16, GlyphSet}; // There is a ClassDef builder in write-fonts, but it's a bit anemic. // @@ -19,7 +19,7 @@ use crate::common::{GlyphId, GlyphSet}; #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub(crate) struct ClassDefBuilder2 { classes: HashSet, - glyphs: HashSet, + glyphs: HashSet, use_class_0: bool, } @@ -89,7 +89,7 @@ mod tests { use super::*; fn make_glyph_class(glyphs: [u16; N]) -> GlyphSet { - glyphs.into_iter().map(GlyphId::new).collect() + glyphs.into_iter().map(GlyphId16::new).collect() } #[test] @@ -97,13 +97,13 @@ mod tests { let mut builder = ClassDefBuilder2::new(false); builder.checked_add(make_glyph_class([6, 10])); let (cls, _) = builder.build(); - assert_eq!(cls.get(GlyphId::new(6)), 1); + assert_eq!(cls.get(GlyphId16::new(6)), 1); let mut builder = ClassDefBuilder2::new(true); builder.checked_add(make_glyph_class([6, 10])); let (cls, _) = builder.build(); - assert_eq!(cls.get(GlyphId::new(6)), 0); - assert_eq!(cls.get(GlyphId::new(10)), 0); + assert_eq!(cls.get(GlyphId16::new(6)), 0); + assert_eq!(cls.get(GlyphId16::new(10)), 0); } #[test] @@ -116,11 +116,12 @@ mod tests { builder.checked_add(make_glyph_class([1, 12])); builder.checked_add(make_glyph_class([3, 4])); let (cls, _) = builder.build(); - assert_eq!(cls.get(GlyphId::new(9)), 1); - assert_eq!(cls.get(GlyphId::new(1)), 2); - assert_eq!(cls.get(GlyphId::new(4)), 3); + dbg!(&cls); + assert_eq!(cls.get(GlyphId16::new(9)), 1); + assert_eq!(cls.get(GlyphId16::new(1)), 2); + assert_eq!(cls.get(GlyphId16::new(4)), 3); // notdef - assert_eq!(cls.get(GlyphId::new(5)), 0); + assert_eq!(cls.get(GlyphId16::new(5)), 0); } #[test] diff --git a/fea-rs/src/compile/output.rs b/fea-rs/src/compile/output.rs index 9549c71b..983c89bf 100644 --- a/fea-rs/src/compile/output.rs +++ b/fea-rs/src/compile/output.rs @@ -4,7 +4,7 @@ use std::collections::HashMap; use write_fonts::{ tables::{self as wtables, gdef::GlyphClassDef, maxp::Maxp}, - types::GlyphId, + types::GlyphId16, BuilderError, FontBuilder, }; @@ -49,7 +49,7 @@ pub struct Compilation { /// /// This is provided so that the user can reference them if they are going /// to manually generate kerning or markpos lookups. - pub gdef_classes: Option>, + pub gdef_classes: Option>, } impl Compilation { diff --git a/fea-rs/src/compile/tables.rs b/fea-rs/src/compile/tables.rs index dd695865..c365c86f 100644 --- a/fea-rs/src/compile/tables.rs +++ b/fea-rs/src/compile/tables.rs @@ -18,7 +18,7 @@ use write_fonts::{ types::{Fixed, LongDateTime}, }; -use crate::common::GlyphId; +use crate::common::GlyphId16; mod base; mod gdef; @@ -53,8 +53,8 @@ pub(crate) struct HeadBuilder { #[derive(Clone, Debug, Default)] pub(crate) struct VmtxBuilder { - pub origins_y: Vec<(GlyphId, i16)>, - pub advances_y: Vec<(GlyphId, i16)>, + pub origins_y: Vec<(GlyphId16, i16)>, + pub advances_y: Vec<(GlyphId16, i16)>, } // this is the value used in python fonttools when writing this table diff --git a/fea-rs/src/compile/tables/gdef.rs b/fea-rs/src/compile/tables/gdef.rs index 6550c370..56c20945 100644 --- a/fea-rs/src/compile/tables/gdef.rs +++ b/fea-rs/src/compile/tables/gdef.rs @@ -9,7 +9,7 @@ use std::collections::{BTreeMap, BTreeSet, HashMap}; use std::fmt::Display; -use write_fonts::types::GlyphId; +use write_fonts::types::GlyphId16; use write_fonts::tables::{ self, @@ -25,15 +25,15 @@ use crate::common::{GlyphClass, GlyphSet}; /// Data collected from a GDEF block. #[derive(Clone, Debug, Default)] pub struct GdefBuilder { - pub glyph_classes: HashMap, + pub glyph_classes: HashMap, /// if `true`, then glyph classes were not declared explicitly. /// /// we track this because it is an important distinction when using the /// glyph classes for manually generated kern/markpos lookups pub glyph_classes_were_inferred: bool, - pub attach: BTreeMap>, - pub ligature_pos: BTreeMap>, - pub mark_attach_class: BTreeMap, + pub attach: BTreeMap>, + pub ligature_pos: BTreeMap>, + pub mark_attach_class: BTreeMap, pub mark_glyph_sets: Vec, pub var_store: Option, } @@ -115,7 +115,7 @@ impl GdefBuilder { // glyphs and this is private API, so :shrug: glyphs: GlyphClass, class: GlyphClassDef, - ) -> Result<(), (GlyphId, GlyphClassDef)> { + ) -> Result<(), (GlyphId16, GlyphClassDef)> { for glyph in glyphs.iter() { if let Some(prev_class) = self.glyph_classes.insert(glyph, class) { if prev_class != class { diff --git a/fontbe/src/cmap.rs b/fontbe/src/cmap.rs index 5277b1a0..b71e4b7f 100644 --- a/fontbe/src/cmap.rs +++ b/fontbe/src/cmap.rs @@ -3,7 +3,7 @@ use fontdrasil::orchestration::{Access, AccessBuilder, Work}; use fontir::orchestration::WorkId as FeWorkId; -use write_fonts::{tables::cmap::Cmap, types::GlyphId}; +use write_fonts::{tables::cmap::Cmap, types::GlyphId16}; use crate::{ error::Error, @@ -45,7 +45,7 @@ impl Work for CmapWork { .map(|codepoint| { ( char::from_u32(*codepoint).expect("We have an invalid codepoint!"), - GlyphId::new(gid as u16), + GlyphId16::new(gid as u16).into(), ) }) .collect::>() diff --git a/fontbe/src/features/kern.rs b/fontbe/src/features/kern.rs index 9d9e1f49..e45688b7 100644 --- a/fontbe/src/features/kern.rs +++ b/fontbe/src/features/kern.rs @@ -29,7 +29,7 @@ use ordered_float::OrderedFloat; use write_fonts::{ read::{tables::gsub::Gsub, FontRead, ReadError}, tables::{gdef::GlyphClassDef, layout::LookupFlag}, - types::{GlyphId, Tag}, + types::{GlyphId16, Tag}, }; use crate::{ @@ -380,7 +380,7 @@ impl Work for KerningGatherWork { .map(|(i, glyphname)| { ( context.ir.glyphs.get(&FeWorkId::Glyph(glyphname.clone())), - GlyphId::new(i as u16), + GlyphId16::new(i as u16), ) }) .collect::>(); @@ -399,7 +399,7 @@ impl KerningGatherWork { fragments: &[&KernFragment], ast: &ParseTree, glyph_map: &GlyphMap, - glyphs: Vec<(Arc, GlyphId)>, + glyphs: Vec<(Arc, GlyphId16)>, ) -> Result { // ignore diagnostics, they'll get logged during actual GSUB compilation let (compilation, _) = fea_rs::compile::compile::( @@ -596,9 +596,9 @@ fn debug_ordered_lookups( /// All the state needed for splitting kern pairs by script & writing direction struct KernSplitContext { /// map of all mark glyphs + whether they are spacing or not - mark_glyphs: HashMap, - glyph_scripts: HashMap>, - bidi_glyphs: BTreeMap>, + mark_glyphs: HashMap, + glyph_scripts: HashMap>, + bidi_glyphs: BTreeMap>, opts: KernSplitOptions, dflt_scripts: HashSet, common_scripts: HashSet, @@ -620,7 +620,7 @@ impl KernSplitContext { glyphs: &impl CharMap, known_scripts: &HashSet, gsub: Option, - mark_glyphs: HashMap, + mark_glyphs: HashMap, ) -> Result { let glyph_scripts = super::properties::scripts_by_glyph(glyphs, known_scripts, gsub.as_ref())?; @@ -863,7 +863,7 @@ impl KernSplitContext { // little helper to tell us what's in a glyphset fn classify_kernside_contents( side: &KernSide, - marks: &HashMap, + marks: &HashMap, ) -> GlyphSetContent { side.iter().fold(GlyphSetContent::Empty, |val, gid| { match (val, marks.contains_key(&gid)) { @@ -879,7 +879,7 @@ impl KernSplitContext { /// split a glyphset into (bases, marks) fn split_glyphs( glyphs: &KernSide, - marks: &HashMap, + marks: &HashMap, ) -> (KernSide, KernSide) { match glyphs { KernSide::Glyph(gid) if !marks.contains_key(gid) => { @@ -1082,10 +1082,10 @@ mod tests { use super::*; const LATN: UnicodeShortName = unsafe { UnicodeShortName::from_bytes_unchecked(*b"Latn") }; - struct MockCharMap(HashMap); + struct MockCharMap(HashMap); impl CharMap for MockCharMap { - fn iter_glyphs(&self) -> impl Iterator { + fn iter_glyphs(&self) -> impl Iterator { self.0.iter().map(|(uv, gid)| (*gid, *uv as u32)) } } @@ -1110,7 +1110,7 @@ mod tests { } } - fn get(&self, c: char) -> GlyphId { + fn get(&self, c: char) -> GlyphId16 { self.0.get(&c).copied().unwrap() } } @@ -1120,7 +1120,7 @@ mod tests { Self( iter.into_iter() .enumerate() - .map(|(i, c)| (c, GlyphId::new(i as u16 + 1))) + .map(|(i, c)| (c, GlyphId16::new(i as u16 + 1))) .collect(), ) } diff --git a/fontbe/src/features/marks.rs b/fontbe/src/features/marks.rs index b86c8abf..19fb6684 100644 --- a/fontbe/src/features/marks.rs +++ b/fontbe/src/features/marks.rs @@ -19,7 +19,7 @@ use ordered_float::OrderedFloat; use smol_str::SmolStr; use write_fonts::{ tables::{gdef::GlyphClassDef, layout::LookupFlag}, - types::{GlyphId, Tag}, + types::{GlyphId16, Tag}, }; use crate::{ @@ -85,16 +85,16 @@ impl MarkGroup<'_> { // a trait to abstract over three very similar builders trait MarkAttachmentBuilder: Default { - fn add_mark(&mut self, gid: GlyphId, group: &GroupName, anchor: FeaAnchor); - fn add_base(&mut self, gid: GlyphId, group: &GroupName, anchor: BaseOrLigAnchors); + fn add_mark(&mut self, gid: GlyphId16, group: &GroupName, anchor: FeaAnchor); + fn add_base(&mut self, gid: GlyphId16, group: &GroupName, anchor: BaseOrLigAnchors); } impl MarkAttachmentBuilder for MarkToBaseBuilder { - fn add_mark(&mut self, gid: GlyphId, group: &GroupName, anchor: FeaAnchor) { + fn add_mark(&mut self, gid: GlyphId16, group: &GroupName, anchor: FeaAnchor) { let _ = self.insert_mark(gid, group.clone(), anchor); } - fn add_base(&mut self, gid: GlyphId, group: &GroupName, anchor: BaseOrLigAnchors) { + fn add_base(&mut self, gid: GlyphId16, group: &GroupName, anchor: BaseOrLigAnchors) { match anchor { BaseOrLigAnchors::Base(anchor) => self.insert_base(gid, group, anchor), BaseOrLigAnchors::Ligature(_) => panic!("lig anchors in mark2base builder"), @@ -103,11 +103,11 @@ impl MarkAttachmentBuilder for MarkToBaseBuilder { } impl MarkAttachmentBuilder for MarkToMarkBuilder { - fn add_mark(&mut self, gid: GlyphId, group: &GroupName, anchor: FeaAnchor) { + fn add_mark(&mut self, gid: GlyphId16, group: &GroupName, anchor: FeaAnchor) { let _ = self.insert_mark1(gid, group.clone(), anchor); } - fn add_base(&mut self, gid: GlyphId, group: &GroupName, anchor: BaseOrLigAnchors) { + fn add_base(&mut self, gid: GlyphId16, group: &GroupName, anchor: BaseOrLigAnchors) { match anchor { BaseOrLigAnchors::Base(anchor) => self.insert_mark2(gid, group, anchor), BaseOrLigAnchors::Ligature(_) => panic!("lig anchors in mark2mark to builder"), @@ -116,11 +116,16 @@ impl MarkAttachmentBuilder for MarkToMarkBuilder { } impl MarkAttachmentBuilder for MarkToLigBuilder { - fn add_mark(&mut self, gid: GlyphId, group: &GroupName, anchor: FeaAnchor) { + fn add_mark(&mut self, gid: GlyphId16, group: &GroupName, anchor: FeaAnchor) { let _ = self.insert_mark(gid, group.clone(), anchor); } - fn add_base(&mut self, gid: GlyphId, group: &GroupName, anchors: BaseOrLigAnchors) { + fn add_base( + &mut self, + gid: GlyphId16, + group: &GroupName, + anchors: BaseOrLigAnchors, + ) { match anchors { BaseOrLigAnchors::Ligature(anchors) => { self.insert_ligature(gid, group.clone(), anchors) @@ -242,7 +247,9 @@ impl<'a> MarkLookupBuilder<'a> { let mut builder = T::default(); let filter_set = group.make_filter_glyph_set(self.glyph_order); let mut flags = LookupFlag::empty(); - flags.set_use_mark_filtering_set(filter_set.is_some()); + if filter_set.is_some() { + flags |= LookupFlag::USE_MARK_FILTERING_SET; + } for (mark_name, anchor) in group.marks { // we already filtered to only things in glyph order let gid = self.glyph_order.glyph_id(&mark_name).unwrap(); @@ -407,9 +414,7 @@ impl<'a> MarkLookupBuilder<'a> { fn make_cursive_lookups(&self) -> Result>, Error> { let mut builder = CursivePosBuilder::default(); - let mut flags = LookupFlag::empty(); - flags.set_ignore_marks(true); - flags.set_right_to_left(true); + let flags = LookupFlag::IGNORE_MARKS | LookupFlag::RIGHT_TO_LEFT; let mut entries = BTreeMap::new(); let mut affected_glyphs = BTreeSet::new(); let mut exits = BTreeMap::new(); diff --git a/fontbe/src/features/properties.rs b/fontbe/src/features/properties.rs index 61b10dfc..5636bc19 100644 --- a/fontbe/src/features/properties.rs +++ b/fontbe/src/features/properties.rs @@ -10,7 +10,7 @@ use icu_properties::{BidiClass, Script}; use tinystr::tinystr; use write_fonts::{ read::{tables::gsub::Gsub, ReadError}, - types::{GlyphId, Tag}, + types::{GlyphId16, Tag}, }; use crate::features::ot_tags::{NEW_SCRIPTS, SCRIPT_ALIASES, SCRIPT_EXCEPTIONS_REVERSED}; @@ -42,11 +42,11 @@ pub trait CharMap { /// /// Note that a single glyph may appear multiple times, with different /// unicode values. - fn iter_glyphs(&self) -> impl Iterator; + fn iter_glyphs(&self) -> impl Iterator; } -impl CharMap for Vec<(Arc, GlyphId)> { - fn iter_glyphs(&self) -> impl Iterator { +impl CharMap for Vec<(Arc, GlyphId16)> { + fn iter_glyphs(&self) -> impl Iterator { self.iter() .flat_map(|(glyph, gid)| glyph.codepoints.iter().map(|uv| (*gid, *uv))) } @@ -112,7 +112,7 @@ fn classify( char_map: &CM, mut props_fn: F, gsub: Option<&Gsub>, -) -> Result>, ReadError> +) -> Result>, ReadError> where T: Ord + Eq, // instead of returning an iterator, pushes items into the provided buffer @@ -153,7 +153,7 @@ pub(crate) fn scripts_by_glyph( glyphs: &impl CharMap, known_scripts: &HashSet, gsub: Option<&Gsub>, -) -> Result>, ReadError> { +) -> Result>, ReadError> { let mut result = HashMap::new(); let lookup = Script::enum_to_short_name_mapper(); for (script, glyphs) in classify( @@ -188,7 +188,7 @@ pub(crate) fn scripts_by_glyph( pub(crate) fn glyphs_by_bidi_class( glyphs: &impl CharMap, gsub: Option<&Gsub>, -) -> Result>, ReadError> { +) -> Result>, ReadError> { classify( glyphs, |codepoint, buf| buf.extend(unicode_bidi_type(codepoint)), diff --git a/fontbe/src/gvar.rs b/fontbe/src/gvar.rs index e2458b3f..10d4be57 100644 --- a/fontbe/src/gvar.rs +++ b/fontbe/src/gvar.rs @@ -8,7 +8,7 @@ use fontir::{ir::GlyphOrder, orchestration::WorkId as FeWorkId}; use write_fonts::{ dump_table, tables::gvar::{GlyphDeltas, GlyphVariations, Gvar}, - types::GlyphId, + types::GlyphId16, }; use crate::{ @@ -30,7 +30,7 @@ fn make_variations( glyph_order .iter() .enumerate() - .map(|(gid, gn)| GlyphVariations::new(GlyphId::new(gid as u16), get_deltas(gn))) + .map(|(gid, gn)| GlyphVariations::new(GlyphId16::new(gid as u16).into(), get_deltas(gn))) .collect() } diff --git a/fontbe/src/metrics_and_limits.rs b/fontbe/src/metrics_and_limits.rs index 47179fc7..d95cdf07 100644 --- a/fontbe/src/metrics_and_limits.rs +++ b/fontbe/src/metrics_and_limits.rs @@ -17,7 +17,7 @@ use write_fonts::{ maxp::Maxp, vmtx::LongMetric, }, - types::{FWord, GlyphId}, + types::{FWord, GlyphId16}, OtRound, }; @@ -43,7 +43,7 @@ struct FontLimits { max_points: u16, max_contours: u16, max_component_elements: u16, - glyph_info: HashMap, + glyph_info: HashMap, bbox: Option, } @@ -51,7 +51,7 @@ struct FontLimits { struct GlyphInfo { /// For simple glyphs always present. For composites, set by [`FontLimits::update_composite_limits`] limits: Option, - components: Option>, + components: Option>, } impl GlyphInfo { @@ -79,7 +79,7 @@ impl GlyphLimits { } impl FontLimits { - fn update(&mut self, id: GlyphId, advance: u16, glyph: &Glyph) { + fn update(&mut self, id: GlyphId16, advance: u16, glyph: &Glyph) { // min side bearings are only for non-empty glyphs // we will presume only simple glyphs with no contours are empty if let Some(bbox) = glyph.data.bbox() { @@ -238,7 +238,7 @@ impl Work for MetricAndLimitWork { .iter() .enumerate() .map(|(gid, gn)| { - let gid = GlyphId::new(gid as u16); + let gid = GlyphId16::new(gid as u16); let advance: u16 = context .ir .glyphs @@ -365,7 +365,7 @@ mod tests { let mut glyph_limits = FontLimits::default(); // path crafted to give the desired bbox glyph_limits.update( - GlyphId::new(0), + GlyphId16::NOTDEF, 0, &crate::orchestration::Glyph::new( "don't care".into(), diff --git a/fontbe/src/orchestration.rs b/fontbe/src/orchestration.rs index 2780dcfb..f14ff02f 100644 --- a/fontbe/src/orchestration.rs +++ b/fontbe/src/orchestration.rs @@ -58,7 +58,7 @@ use write_fonts::{ stat::Stat, variations::Tuple, }, - types::{F2Dot14, GlyphId, Tag}, + types::{F2Dot14, GlyphId16, Tag}, validate::Validate, FontWrite, }; @@ -431,7 +431,7 @@ impl Persistable for AllKerningPairs { #[derive(Clone, Debug, Serialize, Deserialize, PartialEq, PartialOrd, Eq, Ord)] pub(crate) enum KernSide { /// A specific glyph - Glyph(GlyphId), + Glyph(GlyphId16), /// A group of glyphs Group(GlyphSet), } @@ -468,7 +468,7 @@ impl KernSide { } } - pub(crate) fn iter(&self) -> impl Iterator + '_ { + pub(crate) fn iter(&self) -> impl Iterator + '_ { let (first, second) = match self { Self::Glyph(gid) => (Some(*gid), None), Self::Group(group) => (None, Some(group)), @@ -534,7 +534,7 @@ impl KernPair { } /// Returns true if this entry has no glyphs in common with the provided set - pub(crate) fn glyphs_are_disjoint(&self, glyphs: &HashSet) -> bool { + pub(crate) fn glyphs_are_disjoint(&self, glyphs: &HashSet) -> bool { self.first_glyphs() .chain(self.second_glyphs()) .all(|gid| !glyphs.contains(&gid)) @@ -565,11 +565,11 @@ impl KernPair { } } - pub(crate) fn first_glyphs(&self) -> impl Iterator + '_ { + pub(crate) fn first_glyphs(&self) -> impl Iterator + '_ { self.side1.iter() } - pub(crate) fn second_glyphs(&self) -> impl Iterator + '_ { + pub(crate) fn second_glyphs(&self) -> impl Iterator + '_ { self.side2.iter() } } @@ -972,8 +972,8 @@ mod tests { // applied first #[test] fn kern_pair_sort_order() { - let glyph = KernSide::Glyph(GlyphId::new(5)); - let class_ = KernSide::Group([1, 2, 3, 4].into_iter().map(GlyphId::new).collect()); + let glyph = KernSide::Glyph(GlyphId16::new(5)); + let class_ = KernSide::Group([1, 2, 3, 4].into_iter().map(GlyphId16::new).collect()); let value = ValueRecordBuilder::new().with_x_advance(420); let glyph_glyph = KernPair { side1: glyph.clone(), diff --git a/fontc/src/lib.rs b/fontc/src/lib.rs index 0007f8c9..f933501e 100644 --- a/fontc/src/lib.rs +++ b/fontc/src/lib.rs @@ -583,7 +583,7 @@ mod tests { types::F2Dot14, FontData, FontRead, FontReadWithArgs, FontRef, TableProvider, }, - GlyphId, MetadataProvider, Tag, + GlyphId16, MetadataProvider, Tag, }; use tempfile::{tempdir, TempDir}; use write_fonts::{ @@ -699,10 +699,10 @@ mod tests { .map(|v| v.to_u16() as u32) } - /// Returns the GlyphId (or NOTDEF, if not present) - fn get_gid(&self, name: &str) -> GlyphId { + /// Returns the GlyphId16 (or NOTDEF, if not present) + fn get_gid(&self, name: &str) -> GlyphId16 { let raw = self.get_glyph_index(name).unwrap_or_default(); - GlyphId::new(raw as u16) + GlyphId16::new(raw as u16) } fn glyphs(&self) -> Glyphs { @@ -740,7 +740,7 @@ mod tests { ) .unwrap(); (0..loca.len()) - .map(|gid| loca.get_glyf(GlyphId::new(gid as u16), &glyf)) + .map(|gid| loca.get_glyf(GlyphId16::new(gid as u16).into(), &glyf)) .map(|r| r.unwrap()) .collect() } @@ -1620,7 +1620,7 @@ mod tests { .get() .contains(&GlyphName::NOTDEF)); assert_eq!( - Some(GlyphId::NOTDEF), + Some(GlyphId16::NOTDEF), result .fe_context .glyph_order @@ -1650,10 +1650,10 @@ mod tests { assert_eq!( vec![ - GlyphId::new(1), - GlyphId::new(2), - GlyphId::new(3), - GlyphId::new(6), + GlyphId16::new(1), + GlyphId16::new(2), + GlyphId16::new(3), + GlyphId16::new(6), ], [0x20, 0x21, 0x2d, 0x3d] .iter() @@ -2464,7 +2464,7 @@ mod tests { .map(|coord| F2Dot14::from_f32(coord.into_inner().into())) .collect(); self.hvar - .advance_width_delta(gid, &coords) + .advance_width_delta(gid.into(), &coords) .unwrap() .to_f64() } @@ -3010,7 +3010,7 @@ mod tests { let glyph_count = font.maxp().unwrap().num_glyphs(); assert_eq!(gvar.glyph_count(), glyph_count); assert!((0..glyph_count).all(|gid| gvar - .glyph_variation_data(GlyphId::new(gid)) + .glyph_variation_data(GlyphId16::new(gid).into()) // read-fonts would return an error when a glyph's variations are empty .is_err())); } diff --git a/fontir/src/glyph.rs b/fontir/src/glyph.rs index 33378803..7edca020 100644 --- a/fontir/src/glyph.rs +++ b/fontir/src/glyph.rs @@ -13,7 +13,7 @@ use fontdrasil::{ use kurbo::Affine; use log::{debug, log_enabled, trace}; use ordered_float::OrderedFloat; -use write_fonts::types::GlyphId; +use write_fonts::types::GlyphId16; use crate::{ error::{BadGlyph, BadGlyphKind, Error}, @@ -304,7 +304,7 @@ fn ensure_notdef_exists_and_is_gid_0( ) -> Result<(), BadGlyph> { // Make sure we have a .notdef and that it's gid 0 match glyph_order.glyph_id(&GlyphName::NOTDEF) { - Some(GlyphId::NOTDEF) => (), // .notdef is gid 0; life is good + Some(GlyphId16::NOTDEF) => (), // .notdef is gid 0; life is good Some(..) => { trace!("Move {} to gid 0", GlyphName::NOTDEF); glyph_order.set_glyph_id(&GlyphName::NOTDEF, 0); diff --git a/fontir/src/ir.rs b/fontir/src/ir.rs index bb91eeba..9cc7eb28 100644 --- a/fontir/src/ir.rs +++ b/fontir/src/ir.rs @@ -15,7 +15,7 @@ use serde::{de::Error as _, Deserialize, Serialize}; use smol_str::SmolStr; use write_fonts::{ tables::{gdef::GlyphClassDef, os2::SelectionFlags}, - types::{GlyphId, NameId, Tag}, + types::{GlyphId16, NameId, Tag}, OtRound, }; @@ -146,11 +146,11 @@ impl GlyphOrder { GlyphOrder(IndexSet::new()) } - pub fn glyph_id(&self, name: &GlyphName) -> Option { + pub fn glyph_id(&self, name: &GlyphName) -> Option { self.0 .get_index_of(name) .map(|i| i as u32) - .map(|gid| GlyphId::new(gid as u16)) + .map(|gid| GlyphId16::new(gid as u16)) } pub fn glyph_name(&self, index: usize) -> Option<&GlyphName> { diff --git a/otl-normalizer/src/common.rs b/otl-normalizer/src/common.rs index ddeff22c..9b4ec423 100644 --- a/otl-normalizer/src/common.rs +++ b/otl-normalizer/src/common.rs @@ -10,7 +10,7 @@ use std::{ use write_fonts::{ read::tables::layout::{FeatureList, ScriptList}, tables::layout::LookupFlag, - types::{GlyphId, Tag}, + types::{GlyphId16, Tag}, }; use crate::glyph_names::NameMap; @@ -37,8 +37,8 @@ pub(crate) struct Feature { /// A type to represent either one or multiple glyphs #[derive(Clone, Debug, PartialEq, Eq, Hash)] pub(crate) enum GlyphSet { - Single(GlyphId), - Multiple(BTreeSet), + Single(GlyphId16), + Multiple(BTreeSet), } /// A decomposed lookup. @@ -218,7 +218,7 @@ impl GlyphSet { /// This can result in an empty glyph set, which is not meaningful to us. /// It is the responsibility of the caller to check for an empty set and /// handle it appropriately. - pub(crate) fn remove_glyphs(&mut self, glyphs: &[GlyphId]) { + pub(crate) fn remove_glyphs(&mut self, glyphs: &[GlyphId16]) { match self { GlyphSet::Multiple(set) => set.retain(|gid| !glyphs.contains(gid)), // I initially imagined this type always had one or more glyphs, @@ -230,7 +230,7 @@ impl GlyphSet { } } - pub(crate) fn add(&mut self, gid: GlyphId) { + pub(crate) fn add(&mut self, gid: GlyphId16) { // if we're a single glyph, don't turn into a set if we're adding ourselves if matches!(self, GlyphSet::Single(x) if *x == gid) { return; @@ -241,7 +241,7 @@ impl GlyphSet { } } - pub(crate) fn iter(&self) -> impl Iterator + '_ { + pub(crate) fn iter(&self) -> impl Iterator + '_ { let (left, right) = match self { GlyphSet::Single(gid) => (Some(*gid), None), GlyphSet::Multiple(gids) => (None, Some(gids.iter().copied())), @@ -366,14 +366,14 @@ impl PartialOrd for GlyphSet { } } -impl From for GlyphSet { - fn from(src: GlyphId) -> GlyphSet { +impl From for GlyphSet { + fn from(src: GlyphId16) -> GlyphSet { GlyphSet::Single(src) } } -impl FromIterator for GlyphSet { - fn from_iter>(iter: T) -> Self { +impl FromIterator for GlyphSet { + fn from_iter>(iter: T) -> Self { GlyphSet::Multiple(iter.into_iter().collect()) } } diff --git a/otl-normalizer/src/glyph_names.rs b/otl-normalizer/src/glyph_names.rs index ce2deba9..b33ed7a6 100644 --- a/otl-normalizer/src/glyph_names.rs +++ b/otl-normalizer/src/glyph_names.rs @@ -7,7 +7,7 @@ use std::collections::{BTreeMap, HashMap}; use fontdrasil::types::GlyphName; use write_fonts::read::{ tables::cmap::{CmapSubtable, EncodingRecord, PlatformId}, - types::{GlyphId, Tag}, + types::{GlyphId16, Tag}, FontRef, TableProvider, }; @@ -15,7 +15,7 @@ use crate::error::Error; /// A map for gids to human-readable names #[derive(Clone, Debug, Default)] -pub struct NameMap(pub(crate) BTreeMap); +pub struct NameMap(pub(crate) BTreeMap); impl NameMap { /// Create a new name mapping for the glyphs in the provided font @@ -28,7 +28,7 @@ impl NameMap { let post = font.post().ok(); let mut name_map = (1..num_glyphs) .map(|gid| { - let gid = GlyphId::new(gid); + let gid = GlyphId16::new(gid); // first check post, then do fallback if let Some(name) = post .as_ref() @@ -57,7 +57,7 @@ impl NameMap { (gid, name) }) .collect::>(); - name_map.insert(GlyphId::NOTDEF, ".notdef".into()); + name_map.insert(GlyphId16::NOTDEF, ".notdef".into()); Ok(NameMap(name_map)) } @@ -65,7 +65,7 @@ impl NameMap { /// Returns a human readable name for this gid. /// /// This will panic if the gid is not in the font used to create this map. - pub fn get(&self, gid: GlyphId) -> &GlyphName { + pub fn get(&self, gid: GlyphId16) -> &GlyphName { // map contains a name for every gid in the font self.0.get(&gid).unwrap() } @@ -76,7 +76,7 @@ impl NameMap { } } -fn reverse_cmap(font: &FontRef) -> Result, Error> { +fn reverse_cmap(font: &FontRef) -> Result, Error> { // fn is_unicode(record: &&EncodingRecord) -> bool { record.platform_id() == PlatformId::Unicode @@ -91,7 +91,7 @@ fn reverse_cmap(font: &FontRef) -> Result, Error> { let mut reverse_cmap = HashMap::new(); - let mut add_to_map = |args: (u32, GlyphId)| { + let mut add_to_map = |args: (u32, GlyphId16)| { // because multiple glyphs may map to the same codepoint, // we always use the lowest codepoint to determine the name. let val = reverse_cmap.entry(args.1).or_insert(args.0); @@ -105,8 +105,14 @@ fn reverse_cmap(font: &FontRef) -> Result, Error> { .map(|rec| rec.subtable(offset_data).unwrap()) { match subtable { - CmapSubtable::Format4(subtable) => subtable.iter().for_each(&mut add_to_map), - CmapSubtable::Format12(subtable) => subtable.iter().for_each(&mut add_to_map), + CmapSubtable::Format4(subtable) => subtable + .iter() + .map(|(unicode, gid)| (unicode, GlyphId16::try_from(gid).unwrap())) + .for_each(&mut add_to_map), + CmapSubtable::Format12(subtable) => subtable + .iter() + .map(|(unicode, gid)| (unicode, GlyphId16::try_from(gid).unwrap())) + .for_each(&mut add_to_map), _ => (), } } @@ -119,7 +125,7 @@ impl FromIterator for NameMap { Self( iter.into_iter() .enumerate() - .map(|(i, name)| (GlyphId::new(i as _), name)) + .map(|(i, name)| (GlyphId16::new(i as _), name)) .collect(), ) } diff --git a/otl-normalizer/src/gpos.rs b/otl-normalizer/src/gpos.rs index eee31bf6..961d9704 100644 --- a/otl-normalizer/src/gpos.rs +++ b/otl-normalizer/src/gpos.rs @@ -13,7 +13,8 @@ use write_fonts::{ }, FontData, ReadError, }, - types::GlyphId, + tables::layout::LookupFlag, + types::GlyphId16, }; use crate::{ @@ -365,7 +366,7 @@ fn normalize_mark_lookups<'a>( // a little helper used below fn prune_shadowed_marks<'a>( mut rule: SingleRule<'a, MarkAttachmentRule>, - last_seen: &HashMap<(GlyphId, GlyphId), usize>, + last_seen: &HashMap<(GlyphId16, GlyphId16), usize>, lookup_id: usize, ) -> Option> { let to_remove = rule @@ -417,8 +418,9 @@ fn get_lookup_rules( let lookup = lookup.unwrap(); let flag = lookup.lookup_flag(); let mark_filter_id = flag - .use_mark_filtering_set() - .then_some(lookup.mark_filtering_set()); + .contains(LookupFlag::USE_MARK_FILTERING_SET) + .then_some(lookup.mark_filtering_set()) + .flatten(); let subtables = lookup.subtables().unwrap(); match subtables { PositionSubtables::Pair(subs) => { @@ -541,9 +543,9 @@ mod tests { let sub2 = sub2.build_exactly_one_subtable(); let lookup1 = - wgpos::PositionLookup::Pair(wlayout::Lookup::new(LookupFlag::empty(), vec![sub1], 0)); + wgpos::PositionLookup::Pair(wlayout::Lookup::new(LookupFlag::empty(), vec![sub1])); let lookup2 = - wgpos::PositionLookup::Pair(wlayout::Lookup::new(LookupFlag::empty(), vec![sub2], 0)); + wgpos::PositionLookup::Pair(wlayout::Lookup::new(LookupFlag::empty(), vec![sub2])); let lookup_list = wlayout::LookupList::new(vec![lookup1, lookup2]); let lookup_list = write_fonts::dump_table(&lookup_list).unwrap(); let lookup_list = write_fonts::read::tables::gpos::PositionLookupList::read( @@ -594,12 +596,10 @@ mod tests { let lookup1 = wgpos::PositionLookup::MarkToBase(wlayout::Lookup::new( LookupFlag::empty(), vec![sub1], - 0, )); let lookup2 = wgpos::PositionLookup::MarkToBase(wlayout::Lookup::new( LookupFlag::empty(), vec![sub2], - 0, )); let lookup_list = wlayout::LookupList::new(vec![lookup1, lookup2]); diff --git a/otl-normalizer/src/gpos/marks.rs b/otl-normalizer/src/gpos/marks.rs index e487ce15..eb884665 100644 --- a/otl-normalizer/src/gpos/marks.rs +++ b/otl-normalizer/src/gpos/marks.rs @@ -5,7 +5,7 @@ use std::{ use write_fonts::read::{ tables::gpos::{MarkBasePosFormat1, MarkLigPosFormat1, MarkMarkPosFormat1}, - types::GlyphId, + types::GlyphId16, ReadError, }; @@ -21,7 +21,7 @@ enum BaseAnchors { #[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord)] pub(crate) struct MarkAttachmentRule { - pub base: GlyphId, + pub base: GlyphId16, base_anchor: BaseAnchors, marks: BTreeMap, } @@ -59,7 +59,7 @@ impl PrintNames for MarkAttachmentRule { } impl MarkAttachmentRule { - pub(crate) fn iter_base_mark_pairs(&self) -> impl Iterator + '_ { + pub(crate) fn iter_base_mark_pairs(&self) -> impl Iterator + '_ { self.marks .values() .flat_map(|set| set.iter()) @@ -67,7 +67,7 @@ impl MarkAttachmentRule { } // returns `true` if we have marks remaining after removing this set - pub(crate) fn remove_marks(&mut self, marks: &[GlyphId]) -> bool { + pub(crate) fn remove_marks(&mut self, marks: &[GlyphId16]) -> bool { self.marks.retain(|_, v| { v.remove_glyphs(marks); !v.is_empty() @@ -116,7 +116,7 @@ pub(super) fn get_mark_base_rules( fn append_mark_base_rules( subtable: &MarkBasePosFormat1, delta_computer: Option<&DeltaComputer>, - seen: &mut HashSet<(GlyphId, GlyphId)>, + seen: &mut HashSet<(GlyphId16, GlyphId16)>, result: &mut Vec, ) -> Result<(), ReadError> { let base_array = subtable.base_array()?; @@ -188,7 +188,7 @@ pub(super) fn get_mark_liga_rules( fn append_mark_liga_rules( subtable: &MarkLigPosFormat1, delta_computer: Option<&DeltaComputer>, - _seen: &mut HashSet<(GlyphId, GlyphId)>, + _seen: &mut HashSet<(GlyphId16, GlyphId16)>, result: &mut Vec, ) -> Result<(), ReadError> { let lig_array = subtable.ligature_array()?; @@ -266,7 +266,7 @@ pub(super) fn get_mark_mark_rules( fn append_mark_mark_rules( subtable: &MarkMarkPosFormat1, delta_computer: Option<&DeltaComputer>, - seen: &mut HashSet<(GlyphId, GlyphId)>, + seen: &mut HashSet<(GlyphId16, GlyphId16)>, result: &mut Vec, ) -> Result<(), ReadError> { let base_array = subtable.mark2_array()?; diff --git a/otl-normalizer/src/gpos/pairpos.rs b/otl-normalizer/src/gpos/pairpos.rs index 739dab2d..c6f0b454 100644 --- a/otl-normalizer/src/gpos/pairpos.rs +++ b/otl-normalizer/src/gpos/pairpos.rs @@ -5,7 +5,7 @@ use std::{ use write_fonts::read::{ tables::gpos::{PairPos, PairPosFormat1, PairPosFormat2, ValueRecord}, - types::GlyphId, + types::GlyphId16, ReadError, }; @@ -15,7 +15,7 @@ use super::{PrintNames, ResolvedValueRecord}; #[derive(Clone, PartialEq, Eq, PartialOrd, Ord)] pub(super) struct PairPosRule { - pub first: GlyphId, + pub first: GlyphId16, pub second: GlyphSet, pub record1: ResolvedValueRecord, pub record2: ResolvedValueRecord, @@ -77,7 +77,7 @@ pub(super) fn get_pairpos_rules( fn append_pairpos_f1_rules( subtable: &PairPosFormat1, delta_computer: Option<&DeltaComputer>, - seen: &mut HashSet<(GlyphId, GlyphId)>, + seen: &mut HashSet<(GlyphId16, GlyphId16)>, result: &mut Vec, ) { let coverage = subtable.coverage().unwrap(); @@ -120,7 +120,7 @@ fn is_noop(value_record: &ValueRecord) -> bool { fn append_pairpos_f2_rules( subtable: &PairPosFormat2, delta_computer: Option<&DeltaComputer>, - seen: &mut HashSet<(GlyphId, GlyphId)>, + seen: &mut HashSet<(GlyphId16, GlyphId16)>, result: &mut Vec, ) { let coverage = subtable.coverage().unwrap(); @@ -193,7 +193,7 @@ mod tests { &left .iter() .copied() - .map(GlyphId::new) + .map(GlyphId16::new) .collect::>() == right } diff --git a/otl-normalizer/src/gpos/test_helpers.rs b/otl-normalizer/src/gpos/test_helpers.rs index 394dfb06..de3f24c0 100644 --- a/otl-normalizer/src/gpos/test_helpers.rs +++ b/otl-normalizer/src/gpos/test_helpers.rs @@ -6,7 +6,7 @@ use write_fonts::{ gpos::{MarkBasePosFormat1, PairPos}, variations::ivs_builder::VariationStoreBuilder, }, - types::GlyphId, + types::GlyphId16, }; use crate::gpos::MarkAttachmentRule; @@ -21,16 +21,16 @@ pub trait SimplePairPosBuilder { impl SimplePairPosBuilder for PairPosBuilder { fn add_pair(&mut self, gid1: u16, gid2: u16, x_adv: i16) { self.insert_pair( - GlyphId::new(gid1), + GlyphId16::new(gid1), ValueRecord::new().with_x_advance(x_adv), - GlyphId::new(gid2), + GlyphId16::new(gid2), ValueRecord::new(), ) } fn add_class(&mut self, class1: &[u16], class2: &[u16], x_adv: i16) { - let class1 = class1.iter().copied().map(GlyphId::new).collect(); - let class2 = class2.iter().copied().map(GlyphId::new).collect(); + let class1 = class1.iter().copied().map(GlyphId16::new).collect(); + let class2 = class2.iter().copied().map(GlyphId16::new).collect(); let record1 = ValueRecord::new().with_x_advance(x_adv); self.insert_classes(class1, record1, class2, ValueRecord::new()) } @@ -52,13 +52,13 @@ pub trait SimpleMarkBaseBuilder { impl SimpleMarkBaseBuilder for MarkToBaseBuilder { fn add_mark(&mut self, gid: u16, class: &str, anchor: (i16, i16)) { let anchor = Anchor::new(anchor.0, anchor.1); - self.insert_mark(GlyphId::new(gid), class.into(), anchor) + self.insert_mark(GlyphId16::new(gid), class.into(), anchor) .unwrap(); } fn add_base(&mut self, gid: u16, class: &str, anchor: (i16, i16)) { let anchor = Anchor::new(anchor.0, anchor.1); - self.insert_base(GlyphId::new(gid), &class.into(), anchor) + self.insert_base(GlyphId16::new(gid), &class.into(), anchor) } fn build_exactly_one_subtable(self) -> MarkBasePosFormat1 { @@ -72,8 +72,8 @@ impl SimpleMarkBaseBuilder for MarkToBaseBuilder { // further decomposed for testing, so we just see one mark per entry #[derive(Clone, PartialEq, Eq, PartialOrd, Ord)] pub struct SimpleAnchorRule { - pub base_gid: GlyphId, - pub mark_gid: GlyphId, + pub base_gid: GlyphId16, + pub mark_gid: GlyphId16, pub base_anchor: (i16, i16), pub mark_anchor: (i16, i16), }