Skip to content

Commit

Permalink
Derive data_maps_count from length of data_maps on write
Browse files Browse the repository at this point in the history
  • Loading branch information
Hoolean authored and cmyr committed Nov 19, 2024
1 parent 6e445f8 commit 11b6c81
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 6 deletions.
1 change: 1 addition & 0 deletions resources/codegen_inputs/meta.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ table Meta {
#[compile(0)]
reserved: u32,
/// The number of data maps in the table.
#[compile(array_len($data_maps))]
data_maps_count: u32,
/// Array of data map records.
#[count($data_maps_count)]
Expand Down
8 changes: 2 additions & 6 deletions write-fonts/generated/generated_meta.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,14 @@ use crate::codegen_prelude::*;
#[derive(Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct Meta {
/// The number of data maps in the table.
pub data_maps_count: u32,
/// Array of data map records.
pub data_maps: Vec<DataMapRecord>,
}

impl Meta {
/// Construct a new `Meta`
pub fn new(data_maps_count: u32, data_maps: Vec<DataMapRecord>) -> Self {
pub fn new(data_maps: Vec<DataMapRecord>) -> Self {
Self {
data_maps_count,
data_maps: data_maps.into_iter().map(Into::into).collect(),
}
}
Expand All @@ -31,7 +28,7 @@ impl FontWrite for Meta {
(1 as u32).write_into(writer);
(0 as u32).write_into(writer);
(0 as u32).write_into(writer);
self.data_maps_count.write_into(writer);
(array_len(&self.data_maps).unwrap() as u32).write_into(writer);
self.data_maps.write_into(writer);
}
fn table_type(&self) -> TableType {
Expand Down Expand Up @@ -60,7 +57,6 @@ impl<'a> FromObjRef<read_fonts::tables::meta::Meta<'a>> for Meta {
fn from_obj_ref(obj: &read_fonts::tables::meta::Meta<'a>, _: FontData) -> Self {
let offset_data = obj.offset_data();
Meta {
data_maps_count: obj.data_maps_count(),
data_maps: obj.data_maps().to_owned_obj(offset_data),
}
}
Expand Down

0 comments on commit 11b6c81

Please sign in to comment.