Skip to content

Commit

Permalink
Merge pull request #1245 from googlefonts/glyph-order-get
Browse files Browse the repository at this point in the history
Make GlyphOrder methods work with &str
  • Loading branch information
dfrg authored Feb 6, 2025
2 parents 11cc20f + b7eedec commit 4aa1baf
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
6 changes: 3 additions & 3 deletions fontc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ mod tests {
self.fe_context
.glyph_order
.get()
.glyph_id(&name.into())
.glyph_id(name)
.map(|v| v.to_u16() as u32)
}

Expand Down Expand Up @@ -2788,13 +2788,13 @@ mod tests {
let expected_rot60more_bbox = Rect::new(50.0, 149.0, 150.0, 449.0);

let gids = ["rot30", "rot60more"]
.iter()
.into_iter()
.map(|gn| {
compile
.fe_context
.glyph_order
.get()
.glyph_id(&GlyphName::new(gn))
.glyph_id(gn)
.map(|gid16| GlyphId::new(gid16.to_u32()))
.unwrap()
})
Expand Down
15 changes: 9 additions & 6 deletions fontir/src/ir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -245,18 +245,21 @@ impl GlyphOrder {
GlyphOrder(IndexSet::new())
}

pub fn glyph_id(&self, name: &GlyphName) -> Option<GlyphId16> {
self.0
.get_index_of(name)
.map(|i| i as u32)
.map(|gid| GlyphId16::new(gid as u16))
pub fn glyph_id<Q>(&self, name: &Q) -> Option<GlyphId16>
where
Q: std::hash::Hash + indexmap::Equivalent<GlyphName> + ?Sized,
{
self.0.get_index_of(name).map(|i| GlyphId16::new(i as _))
}

pub fn glyph_name(&self, index: usize) -> Option<&GlyphName> {
self.0.get_index(index)
}

pub fn contains(&self, name: &GlyphName) -> bool {
pub fn contains<Q>(&self, name: &Q) -> bool
where
Q: std::hash::Hash + indexmap::Equivalent<GlyphName> + ?Sized,
{
self.0.contains(name)
}

Expand Down

0 comments on commit 4aa1baf

Please sign in to comment.