Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[write-fonts] Fixups for table_type #592

Merged
merged 1 commit into from
Sep 6, 2023
Merged
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
11 changes: 11 additions & 0 deletions write-fonts/src/offsets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,10 @@ impl<const N: usize, T: FontWrite> FontWrite for OffsetMarker<T, N> {
fn write_into(&self, writer: &mut TableWriter) {
writer.write_offset(&self.obj, N);
}

fn table_type(&self) -> crate::table_type::TableType {
self.obj.table_type()
}
}

impl<const N: usize, T: FontWrite> FontWrite for NullableOffsetMarker<T, N> {
Expand All @@ -125,6 +129,13 @@ impl<const N: usize, T: FontWrite> FontWrite for NullableOffsetMarker<T, N> {
None => writer.write_slice([0u8; N].as_slice()),
}
}

fn table_type(&self) -> crate::table_type::TableType {
match self.obj.as_ref() {
Some(obj) => obj.table_type(),
None => crate::table_type::TableType::Unknown,
}
}
}

impl<T, const N: usize> Default for NullableOffsetMarker<T, N> {
Expand Down
12 changes: 11 additions & 1 deletion write-fonts/src/table_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,10 @@ impl Display for TableType {

#[cfg(test)]
mod tests {
use crate::tables::{gpos, gsub};
use crate::tables::{
gpos, gsub,
layout::{Lookup, LookupFlag},
};
use crate::FontWrite;

use super::*;
Expand All @@ -139,4 +142,11 @@ mod tests {
TableType::GsubLookup(7)
);
}

#[test]
fn gpos_type() {
let pairpos = gpos::PairPos::Format1(Default::default());
let lookup = gpos::PositionLookup::Pair(Lookup::new(LookupFlag::empty(), vec![pairpos], 0));
assert_eq!(lookup.table_type(), TableType::GposLookup(2));
}
}
2 changes: 1 addition & 1 deletion write-fonts/src/write.rs
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ impl TableData {
TableData {
bytes: vec![0xca; size], // has no special meaning
offsets: Vec::new(),
type_: TableType::Unknown,
type_: TableType::MockTable,
}
}

Expand Down