Skip to content
Open
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
2 changes: 2 additions & 0 deletions font-codegen/src/format_group.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ pub(crate) fn generate(item: &TableFormat, items: &Items) -> syn::Result<TokenSt
});

let format = &item.format;
let read_inline = item.attrs.read_inline.as_ref().map(|_| quote!(#[inline]));
// if we have any fancy match statement we disable a clippy lint
let mut has_any_match_stmt = false;
let match_arms = item
Expand Down Expand Up @@ -103,6 +104,7 @@ pub(crate) fn generate(item: &TableFormat, items: &Items) -> syn::Result<TokenSt
}

impl<'a> FontRead<'a> for #name<'a> {
#read_inline
fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
let format: #format = data.read_at(#format_offset)?;
#maybe_allow_lint
Expand Down
8 changes: 8 additions & 0 deletions font-codegen/src/parsing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -830,6 +830,14 @@ mod tests {
);
}

#[test]
fn parse_format_group_with_read_inline() {
let parsed =
parse_format_group("#[read_inline]\nformat u16 MyThing { FormatOne(SomeTable), }")
.unwrap();
assert!(parsed.attrs.read_inline.is_some());
}

#[test]
#[should_panic(expected = "must be an unsigned")]
fn parse_format_group_with_negative_format_offset() {
Expand Down
4 changes: 4 additions & 0 deletions font-codegen/src/parsing/attrs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ impl<T: ToTokens> ToTokens for Attr<T> {
#[derive(Debug, Default, Clone)]
pub(crate) struct TableAttrs {
pub(crate) docs: Vec<syn::Attribute>,
pub(crate) read_inline: Option<syn::Path>,
pub(crate) skip_font_write: Option<syn::Path>,
pub(crate) skip_from_obj: Option<syn::Path>,
pub(crate) skip_constructor: Option<syn::Path>,
Expand Down Expand Up @@ -280,6 +281,7 @@ static WRITE_FONTS_ONLY: &str = "write_fonts_only";
static SKIP_FROM_OBJ: &str = "skip_from_obj";
static SKIP_FONT_WRITE: &str = "skip_font_write";
static SKIP_CONSTRUCTOR: &str = "skip_constructor";
static READ_INLINE: &str = "read_inline";
static READ_ARGS: &str = "read_args";
static GENERIC_OFFSET: &str = "generic_offset";
static TAG: &str = "tag";
Expand Down Expand Up @@ -367,6 +369,8 @@ impl Parse for TableAttrs {
})?;
if ident == DOC {
this.docs.push(attr);
} else if ident == READ_INLINE {
this.read_inline = Some(attr.path().clone());
} else if ident == SKIP_FROM_OBJ {
this.skip_from_obj = Some(attr.path().clone());
} else if ident == SKIP_FONT_WRITE {
Expand Down
1 change: 1 addition & 0 deletions read-fonts/generated/generated_aat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ impl ReadArgs for Lookup<'_> {
}

impl<'a> FontRead<'a> for Lookup<'a> {
#[inline]
fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
let format: u16 = data.read_at(0usize)?;
match format {
Expand Down
3 changes: 2 additions & 1 deletion resources/codegen_inputs/aat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

/// Lookup tables provide a way of looking up information about a glyph index.
/// The different cmap subtable formats.
#[read_inline]
format u16 Lookup {
Format0(Lookup0),
Format2(Lookup2),
Expand Down Expand Up @@ -181,4 +182,4 @@ table StxHeader {
table RawWords {
#[count(..)]
data: [u16]
}
}
Loading