Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/font_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ impl<'b> ReadBinary for FontData<'b> {
}

impl<'a> FontTableProvider for DynamicFontTableProvider<'a> {
fn table_tags(&self) -> Vec<u32> {
self.provider.table_tags()
}

fn table_data(&self, tag: u32) -> Result<Option<Cow<'_, [u8]>>, ParseError> {
self.provider.table_data(tag)
}
Expand Down
18 changes: 18 additions & 0 deletions src/tables.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<u32>;

/// Return data for the specified table if present
fn table_data(&self, tag: u32) -> Result<Option<Cow<'_, [u8]>>, ParseError>;

Expand Down Expand Up @@ -378,6 +381,10 @@ impl<'b> ReadBinary for OffsetTable<'b> {
}

impl<'a> FontTableProvider for OffsetTableFontProvider<'a> {
fn table_tags(&self) -> Vec<u32> {
self.offset_table.tags()
}

fn table_data(&self, tag: u32) -> Result<Option<Cow<'_, [u8]>>, ParseError> {
self.offset_table
.read_table(&self.scope, tag)
Expand Down Expand Up @@ -421,6 +428,13 @@ impl WriteBinary<&Self> for TableRecord {
}

impl<'a> OffsetTable<'a> {
pub fn tags(&self) -> Vec<u32> {
self.table_records
.iter()
.map(|table_record| table_record.table_tag)
.collect()
}

pub fn find_table_record(&self, tag: u32) -> Option<TableRecord> {
for table_record in &self.table_records {
if table_record.table_tag == tag {
Expand Down Expand Up @@ -1305,6 +1319,10 @@ impl From<F2Dot14> for f32 {
}

impl<T: FontTableProvider> FontTableProvider for Box<T> {
fn table_tags(&self) -> Vec<u32> {
self.as_ref().table_tags()
}

fn table_data(&self, tag: u32) -> Result<Option<Cow<'_, [u8]>>, ParseError> {
self.as_ref().table_data(tag)
}
Expand Down
7 changes: 7 additions & 0 deletions src/woff.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,13 @@ impl<'b> ReadBinary for WoffFont<'b> {
}

impl<'a> FontTableProvider for WoffFont<'a> {
fn table_tags(&self) -> Vec<u32> {
self.table_directory
.iter()
.map(|table_entry| table_entry.tag)
.collect()
}

fn table_data(&self, tag: u32) -> Result<Option<Cow<'_, [u8]>>, ParseError> {
self.find_table_directory_entry(tag)
.map(|table_entry| {
Expand Down
4 changes: 4 additions & 0 deletions src/woff2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,10 @@ impl<'b> ReadBinary for Woff2Font<'b> {
}

impl FontTableProvider for Woff2TableProvider {
fn table_tags(&self) -> Vec<u32> {
self.tables.keys().copied().collect()
}

fn table_data(&self, tag: u32) -> Result<Option<Cow<'_, [u8]>>, ParseError> {
Ok(self.tables.get(&tag).map(|table| Cow::from(table.as_ref())))
}
Expand Down