diff --git a/CHANGELOG.md b/CHANGELOG.md index 83ff26fd..f8c77a9b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/). ### Added - CFF Encoding support. - `cff::Table::glyph_index` +- `cff::Table::glyph_index_by_name` - `cff::Table::glyph_width` - `cff::Table::number_of_glyphs` - `cff::Table::matrix` diff --git a/src/tables/cff/cff1.rs b/src/tables/cff/cff1.rs index 75160f7a..f742d31a 100644 --- a/src/tables/cff/cff1.rs +++ b/src/tables/cff/cff1.rs @@ -1016,6 +1016,24 @@ impl<'a> Table<'a> { } } + /// Returns a glyph ID by a name. + #[cfg(feature = "glyph-names")] + pub fn glyph_index_by_name(&self, name: &str) -> Option { + match self.kind { + FontKind::SID(_) => { + let sid = if let Some(index) = STANDARD_NAMES.iter().position(|n| *n == name) { + StringId(index as u16) + } else { + let index = self.strings.into_iter().position(|n| n == name.as_bytes())?; + StringId((STANDARD_NAMES.len() + index) as u16) + }; + + self.charset.sid_to_gid(sid) + } + FontKind::CID(_) => None, + } + } + /// Returns a glyph name. #[cfg(feature = "glyph-names")] pub fn glyph_name(&self, glyph_id: GlyphId) -> Option<&'a str> {