diff --git a/src/font_data.rs b/src/font_data.rs index d827dedd..0050440f 100644 --- a/src/font_data.rs +++ b/src/font_data.rs @@ -41,6 +41,10 @@ impl<'b> ReadBinary for FontData<'b> { } impl<'a> FontTableProvider for DynamicFontTableProvider<'a> { + fn table_tags(&self) -> Vec { + self.provider.table_tags() + } + fn table_data(&self, tag: u32) -> Result>, ParseError> { self.provider.table_data(tag) } diff --git a/src/tables.rs b/src/tables.rs index a56dd2f4..c437af1f 100644 --- a/src/tables.rs +++ b/src/tables.rs @@ -47,6 +47,9 @@ pub struct Fixed(i32); type LongDateTime = i64; pub trait FontTableProvider { + /// Returns the tags of all tables. + fn table_tags(&self) -> Vec; + /// Return data for the specified table if present fn table_data(&self, tag: u32) -> Result>, ParseError>; @@ -378,6 +381,10 @@ impl<'b> ReadBinary for OffsetTable<'b> { } impl<'a> FontTableProvider for OffsetTableFontProvider<'a> { + fn table_tags(&self) -> Vec { + self.offset_table.tags() + } + fn table_data(&self, tag: u32) -> Result>, ParseError> { self.offset_table .read_table(&self.scope, tag) @@ -421,6 +428,13 @@ impl WriteBinary<&Self> for TableRecord { } impl<'a> OffsetTable<'a> { + pub fn tags(&self) -> Vec { + self.table_records + .iter() + .map(|table_record| table_record.table_tag) + .collect() + } + pub fn find_table_record(&self, tag: u32) -> Option { for table_record in &self.table_records { if table_record.table_tag == tag { @@ -1305,6 +1319,10 @@ impl From for f32 { } impl FontTableProvider for Box { + fn table_tags(&self) -> Vec { + self.as_ref().table_tags() + } + fn table_data(&self, tag: u32) -> Result>, ParseError> { self.as_ref().table_data(tag) } diff --git a/src/woff.rs b/src/woff.rs index cbf322fc..563d464f 100644 --- a/src/woff.rs +++ b/src/woff.rs @@ -93,6 +93,13 @@ impl<'b> ReadBinary for WoffFont<'b> { } impl<'a> FontTableProvider for WoffFont<'a> { + fn table_tags(&self) -> Vec { + self.table_directory + .iter() + .map(|table_entry| table_entry.tag) + .collect() + } + fn table_data(&self, tag: u32) -> Result>, ParseError> { self.find_table_directory_entry(tag) .map(|table_entry| { diff --git a/src/woff2.rs b/src/woff2.rs index df5adfd1..b07e5744 100644 --- a/src/woff2.rs +++ b/src/woff2.rs @@ -234,6 +234,10 @@ impl<'b> ReadBinary for Woff2Font<'b> { } impl FontTableProvider for Woff2TableProvider { + fn table_tags(&self) -> Vec { + self.tables.keys().copied().collect() + } + fn table_data(&self, tag: u32) -> Result>, ParseError> { Ok(self.tables.get(&tag).map(|table| Cow::from(table.as_ref()))) }