Skip to content

Commit

Permalink
[glyphs] Replace g2fir glyphdata with glyphs-reader
Browse files Browse the repository at this point in the history
This brings us back to parity with our existing code.
  • Loading branch information
cmyr committed Apr 15, 2024
1 parent 252866a commit ba61f37
Show file tree
Hide file tree
Showing 8 changed files with 46 additions and 4,497 deletions.
15 changes: 6 additions & 9 deletions glyphs-reader/src/glyphdata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ impl GlyphData {
/// Look up info for a glyph by name
///
/// This checks primary names first, and alternates afterwards.
pub fn for_glyph_name(&self, name: impl AsRef<str>) -> Option<&GlyphInfo> {
pub fn get_by_name(&self, name: impl AsRef<str>) -> Option<&GlyphInfo> {
let name = name.as_ref();
self.name_map
.get(name)
Expand All @@ -85,7 +85,7 @@ impl GlyphData {
}

/// Look up info for a glyph by codepoint
pub fn for_codepoint(&self, codepoint: u32) -> Option<&GlyphInfo> {
pub fn get_by_codepoint(&self, codepoint: u32) -> Option<&GlyphInfo> {
self.unicode_map
.get(&codepoint)
.and_then(|idx| self.data.get(*idx as usize))
Expand Down Expand Up @@ -130,19 +130,16 @@ mod tests {
let merged = merge_data(bundled, overrides);
let data = GlyphData::new_impl(merged);

assert_eq!(data.for_glyph_name("A").unwrap().category, Category::Mark);
assert_eq!(data.get_by_name("A").unwrap().category, Category::Mark);
}

#[test]
fn overrides_from_file() {
let data = GlyphData::new(Some(Path::new("./data/GlyphData_override_test.xml"))).unwrap();
assert_eq!(data.get_by_name("zero").unwrap().category, Category::Other);
assert_eq!(data.get_by_name("C").unwrap().category, Category::Number);
assert_eq!(
data.for_glyph_name("zero").unwrap().category,
Category::Other
);
assert_eq!(data.for_glyph_name("C").unwrap().category, Category::Number);
assert_eq!(
data.for_glyph_name("Yogh").unwrap().production,
data.get_by_name("Yogh").unwrap().production,
Some("Yolo".into())
);
}
Expand Down
32 changes: 24 additions & 8 deletions glyphs-reader/src/glyphdata/glyphdata_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,20 @@ use quick_xml::{
};
use smol_str::SmolStr;

/// Information about a glyph
///
/// In general this is derived from bundled data files, but these fields can
/// also be overridden by the font author
#[derive(Clone, Debug, serde::Serialize, serde::Deserialize)]
pub struct GlyphInfo {
pub name: SmolStr,
pub category: Category,
pub subcategory: Subcategory,
pub unicode: Option<u32>,
pub production: Option<SmolStr>,
pub alt_names: Vec<SmolStr>,
}

/// The primary category for a given glyph
///
/// These categories are not the same as the unicode character categories.
Expand Down Expand Up @@ -64,14 +78,16 @@ pub enum Subcategory {
None,
}

#[derive(Clone, Debug, serde::Serialize, serde::Deserialize)]
pub struct GlyphInfo {
pub name: SmolStr,
pub category: Category,
pub subcategory: Subcategory,
pub unicode: Option<u32>,
pub production: Option<SmolStr>,
pub alt_names: Vec<SmolStr>,
impl GlyphInfo {
pub fn is_nonspacing_mark(&self) -> bool {
matches!(
(self.category, self.subcategory),
(
Category::Mark,
Subcategory::Nonspacing | Subcategory::SpacingCombining
)
)
}
}

/// Parse glyph info entries out of a GlyphData xml file.
Expand Down
Loading

0 comments on commit ba61f37

Please sign in to comment.