Skip to content

Commit

Permalink
[codegen] Add missing debug impls to generic groups
Browse files Browse the repository at this point in the history
Aka the lookup and extension enums in gpos/gsub.
  • Loading branch information
cmyr committed Oct 6, 2023
1 parent b3a6f07 commit 37bf82b
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 19 deletions.
20 changes: 13 additions & 7 deletions font-codegen/src/table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -190,15 +190,15 @@ pub(crate) fn generate_group(item: &GenericGroup) -> syn::Result<TokenStream> {

let mut variant_decls = Vec::new();
let mut read_match_arms = Vec::new();
let mut as_some_table_arms = Vec::new();
let mut dyn_inner_arms = Vec::new();
for var in &item.variants {
let var_name = &var.name;
let type_id = &var.type_id;
let typ = &var.typ;
variant_decls.push(quote! { #var_name ( #inner <'a, #typ<'a>> ) });
read_match_arms
.push(quote! { #type_id => Ok(#name :: #var_name (untyped.into_concrete())) });
as_some_table_arms.push(quote! { #name :: #var_name(table) => table });
dyn_inner_arms.push(quote! { #name :: #var_name(table) => table });
}

Ok(quote! {
Expand All @@ -219,23 +219,29 @@ pub(crate) fn generate_group(item: &GenericGroup) -> syn::Result<TokenStream> {

#[cfg(feature = "traversal")]
impl<'a> #name <'a> {
fn as_some_table(&self) -> &(dyn SomeTable<'a> + 'a) {
fn dyn_inner(&self) -> &(dyn SomeTable<'a> + 'a) {
match self {
#( #as_some_table_arms, )*
#( #dyn_inner_arms, )*
}
}
}

#[cfg(feature = "traversal")]

impl<'a> SomeTable<'a> for #name <'a> {

fn get_field(&self, idx: usize) -> Option<Field<'a>> {
self.as_some_table().get_field(idx)
self.dyn_inner().get_field(idx)
}

fn type_name(&self) -> &str {
self.as_some_table().type_name()
self.dyn_inner().type_name()
}
}

#[cfg(feature = "traversal")]
impl<'a> std::fmt::Debug for #name<'a> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
self.dyn_inner().fmt(f)
}
}
})
Expand Down
26 changes: 20 additions & 6 deletions read-fonts/generated/generated_gpos.rs
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ impl<'a> FontRead<'a> for PositionLookup<'a> {

#[cfg(feature = "traversal")]
impl<'a> PositionLookup<'a> {
fn as_some_table(&self) -> &(dyn SomeTable<'a> + 'a) {
fn dyn_inner(&self) -> &(dyn SomeTable<'a> + 'a) {
match self {
PositionLookup::Single(table) => table,
PositionLookup::Pair(table) => table,
Expand All @@ -211,10 +211,17 @@ impl<'a> PositionLookup<'a> {
#[cfg(feature = "traversal")]
impl<'a> SomeTable<'a> for PositionLookup<'a> {
fn get_field(&self, idx: usize) -> Option<Field<'a>> {
self.as_some_table().get_field(idx)
self.dyn_inner().get_field(idx)
}
fn type_name(&self) -> &str {
self.as_some_table().type_name()
self.dyn_inner().type_name()
}
}

#[cfg(feature = "traversal")]
impl<'a> std::fmt::Debug for PositionLookup<'a> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
self.dyn_inner().fmt(f)
}
}

Expand Down Expand Up @@ -3571,7 +3578,7 @@ impl<'a> FontRead<'a> for ExtensionSubtable<'a> {

#[cfg(feature = "traversal")]
impl<'a> ExtensionSubtable<'a> {
fn as_some_table(&self) -> &(dyn SomeTable<'a> + 'a) {
fn dyn_inner(&self) -> &(dyn SomeTable<'a> + 'a) {
match self {
ExtensionSubtable::Single(table) => table,
ExtensionSubtable::Pair(table) => table,
Expand All @@ -3588,9 +3595,16 @@ impl<'a> ExtensionSubtable<'a> {
#[cfg(feature = "traversal")]
impl<'a> SomeTable<'a> for ExtensionSubtable<'a> {
fn get_field(&self, idx: usize) -> Option<Field<'a>> {
self.as_some_table().get_field(idx)
self.dyn_inner().get_field(idx)
}
fn type_name(&self) -> &str {
self.as_some_table().type_name()
self.dyn_inner().type_name()
}
}

#[cfg(feature = "traversal")]
impl<'a> std::fmt::Debug for ExtensionSubtable<'a> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
self.dyn_inner().fmt(f)
}
}
26 changes: 20 additions & 6 deletions read-fonts/generated/generated_gsub.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ impl<'a> FontRead<'a> for SubstitutionLookup<'a> {

#[cfg(feature = "traversal")]
impl<'a> SubstitutionLookup<'a> {
fn as_some_table(&self) -> &(dyn SomeTable<'a> + 'a) {
fn dyn_inner(&self) -> &(dyn SomeTable<'a> + 'a) {
match self {
SubstitutionLookup::Single(table) => table,
SubstitutionLookup::Multiple(table) => table,
Expand All @@ -208,10 +208,17 @@ impl<'a> SubstitutionLookup<'a> {
#[cfg(feature = "traversal")]
impl<'a> SomeTable<'a> for SubstitutionLookup<'a> {
fn get_field(&self, idx: usize) -> Option<Field<'a>> {
self.as_some_table().get_field(idx)
self.dyn_inner().get_field(idx)
}
fn type_name(&self) -> &str {
self.as_some_table().type_name()
self.dyn_inner().type_name()
}
}

#[cfg(feature = "traversal")]
impl<'a> std::fmt::Debug for SubstitutionLookup<'a> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
self.dyn_inner().fmt(f)
}
}

Expand Down Expand Up @@ -1309,7 +1316,7 @@ impl<'a> FontRead<'a> for ExtensionSubtable<'a> {

#[cfg(feature = "traversal")]
impl<'a> ExtensionSubtable<'a> {
fn as_some_table(&self) -> &(dyn SomeTable<'a> + 'a) {
fn dyn_inner(&self) -> &(dyn SomeTable<'a> + 'a) {
match self {
ExtensionSubtable::Single(table) => table,
ExtensionSubtable::Multiple(table) => table,
Expand All @@ -1325,10 +1332,17 @@ impl<'a> ExtensionSubtable<'a> {
#[cfg(feature = "traversal")]
impl<'a> SomeTable<'a> for ExtensionSubtable<'a> {
fn get_field(&self, idx: usize) -> Option<Field<'a>> {
self.as_some_table().get_field(idx)
self.dyn_inner().get_field(idx)
}
fn type_name(&self) -> &str {
self.as_some_table().type_name()
self.dyn_inner().type_name()
}
}

#[cfg(feature = "traversal")]
impl<'a> std::fmt::Debug for ExtensionSubtable<'a> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
self.dyn_inner().fmt(f)
}
}

Expand Down

0 comments on commit 37bf82b

Please sign in to comment.