Skip to content

Commit

Permalink
Add cff::Table::glyph_index_by_name
Browse files Browse the repository at this point in the history
  • Loading branch information
RazrFalcon committed Sep 16, 2022
1 parent 13afa37 commit e655839
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down
18 changes: 18 additions & 0 deletions src/tables/cff/cff1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<GlyphId> {
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> {
Expand Down

0 comments on commit e655839

Please sign in to comment.