From 46bbd2503c495607484da853a9b09701efb486f7 Mon Sep 17 00:00:00 2001 From: Simon Cozens Date: Mon, 19 Aug 2024 08:48:48 +0100 Subject: [PATCH] Updates for read-fonts 0.21.0 --- src/render/renderer.rs | 2 +- src/ttj/mod.rs | 21 +++++++++++---------- src/ttj/serializefont.rs | 3 ++- 3 files changed, 14 insertions(+), 12 deletions(-) diff --git a/src/render/renderer.rs b/src/render/renderer.rs index 25fb040..0714642 100644 --- a/src/render/renderer.rs +++ b/src/render/renderer.rs @@ -70,7 +70,7 @@ impl<'a> Renderer<'a> { let _ = self .outlines - .get(GlyphId::new(info.glyph_id as u16)) + .get(GlyphId::new(info.glyph_id)) .unwrap() .draw(settings, &mut pen); serialized_buffer.push_str(&format!("{}", info.glyph_id,)); diff --git a/src/ttj/mod.rs b/src/ttj/mod.rs index 8f29577..4259b94 100644 --- a/src/ttj/mod.rs +++ b/src/ttj/mod.rs @@ -1,12 +1,12 @@ use crate::ttj::{jsondiff::diff, serializefont::ToValue}; use read_fonts::{traversal::SomeTable, FontRef, TableProvider}; use serde_json::{Map, Value}; -use skrifa::{charmap::Charmap, string::StringId, GlyphId, MetadataProvider}; +use skrifa::{charmap::Charmap, string::StringId, GlyphId, GlyphId16, MetadataProvider}; pub mod jsondiff; mod serializefont; -fn serialize_name_table<'a>(font: &impl MetadataProvider<'a>) -> Value { +fn serialize_name_table<'a>(font: &(impl MetadataProvider<'a> + TableProvider<'a>)) -> Value { let mut map = Map::new(); if let Ok(name) = font.name() { let mut ids: Vec = name.name_record().iter().map(|x| x.name_id()).collect(); @@ -29,14 +29,15 @@ fn serialize_name_table<'a>(font: &impl MetadataProvider<'a>) -> Value { } fn gid_to_name<'a>(font: &impl TableProvider<'a>, gid: GlyphId) -> String { - if let Ok(Some(name)) = font - .post() - .map(|post| post.glyph_name(gid).map(|x| x.to_string())) - { - name - } else { - format!("gid{:}", gid) + if let Ok(gid16) = TryInto::::try_into(gid) { + if let Ok(Some(name)) = font + .post() + .map(|post| post.glyph_name(gid16).map(|x| x.to_string())) + { + return name; + } } + return format!("gid{:}", gid); } fn serialize_cmap_table<'a>(font: &impl TableProvider<'a>) -> Value { @@ -55,7 +56,7 @@ fn serialize_hmtx_table<'a>(font: &impl TableProvider<'a>) -> Value { let widths = hmtx.h_metrics(); let long_metrics = widths.len(); for gid in 0..font.maxp().unwrap().num_glyphs() { - let name = gid_to_name(font, GlyphId::new(gid)); + let name = gid_to_name(font, GlyphId::new(gid as u32)); if gid < (long_metrics as u16) { if let Some((width, lsb)) = widths .get(gid as usize) diff --git a/src/ttj/serializefont.rs b/src/ttj/serializefont.rs index 3359437..08459b1 100644 --- a/src/ttj/serializefont.rs +++ b/src/ttj/serializefont.rs @@ -11,6 +11,7 @@ impl<'a> ToValue for FieldType<'a> { Self::I8(arg0) => Value::Number((*arg0).into()), Self::U8(arg0) => Value::Number((*arg0).into()), Self::I16(arg0) => Value::Number((*arg0).into()), + Self::I24(arg0) => Value::Number((Into::::into(*arg0)).into()), Self::U16(arg0) => Value::Number((*arg0).into()), Self::I32(arg0) => Value::Number((*arg0).into()), Self::U32(arg0) => Value::Number((*arg0).into()), @@ -26,7 +27,7 @@ impl<'a> ToValue for FieldType<'a> { Self::F2Dot14(arg0) => Value::Number(Number::from_f64(arg0.to_f32() as f64).unwrap()), Self::Fixed(arg0) => Value::Number(Number::from(arg0.to_i32())), Self::LongDateTime(arg0) => Value::Number(arg0.as_secs().into()), - Self::GlyphId(arg0) => Value::String(format!("g{}", arg0.to_u16())), + Self::GlyphId16(arg0) => Value::String(format!("g{}", arg0.to_u16())), Self::NameId(arg0) => Value::String(arg0.to_string()), Self::StringOffset(string) => match &string.target { Ok(arg0) => Value::String(arg0.as_ref().iter_chars().collect()),