Skip to content

Commit

Permalink
Updates for read-fonts 0.21.0
Browse files Browse the repository at this point in the history
  • Loading branch information
simoncozens committed Aug 19, 2024
1 parent 997b6d6 commit 46bbd25
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 12 deletions.
2 changes: 1 addition & 1 deletion src/render/renderer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,));
Expand Down
21 changes: 11 additions & 10 deletions src/ttj/mod.rs
Original file line number Diff line number Diff line change
@@ -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<StringId> = name.name_record().iter().map(|x| x.name_id()).collect();
Expand All @@ -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::<GlyphId16>::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 {
Expand All @@ -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)
Expand Down
3 changes: 2 additions & 1 deletion src/ttj/serializefont.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<i32>::into(*arg0)).into()),
Self::U16(arg0) => Value::Number((*arg0).into()),
Self::I32(arg0) => Value::Number((*arg0).into()),
Self::U32(arg0) => Value::Number((*arg0).into()),
Expand All @@ -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()),
Expand Down

0 comments on commit 46bbd25

Please sign in to comment.