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/fields.rs
Original file line number Diff line number Diff line change
Expand Up @@ -831,6 +831,7 @@ impl Field {

Some(quote! {
#( #docs )*
#[inline]
pub fn #name(&self) -> #return_type {
let range = #range_stmt;
#read_stmt
Expand Down Expand Up @@ -876,6 +877,7 @@ impl Field {
let offset_getter = self.typed_offset_field_getter(None, Some(record));
Some(quote! {
#(#docs)*
#[inline]
pub fn #name(&self) -> #add_borrow_just_for_record #return_type {
#getter_expr
}
Expand Down
4 changes: 4 additions & 0 deletions font-codegen/src/table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ fn generate_font_read(item: &Table) -> syn::Result<TokenStream> {
}

impl<'a> FontReadWithArgs<'a> for #name<'a> {
#[inline]
fn read_with_args(data: FontData<'a>, args: &#args_type) -> Result<Self, ReadError> {
let #destructure_pattern = *args;
let #maybe_mut_kw cursor = data.cursor();
Expand All @@ -185,6 +186,7 @@ fn generate_font_read(item: &Table) -> syn::Result<TokenStream> {
///
/// This type requires some external state in order to be
/// parsed.
#[inline]
pub fn read(data: FontData<'a>, #( #constructor_args, )* ) -> Result<Self, ReadError> {
let args = #args_from_constructor_args;
Self::read_with_args(data, &args)
Expand All @@ -194,6 +196,7 @@ fn generate_font_read(item: &Table) -> syn::Result<TokenStream> {
} else {
Ok(quote! {
impl<'a, #generic> FontRead<'a> for #name<'a, #generic> {
#[inline]
fn read(data: FontData<'a>) -> Result<Self, ReadError> {
let #maybe_mut_kw cursor = data.cursor();
#( #field_validation_stmts )*
Expand Down Expand Up @@ -241,6 +244,7 @@ pub(crate) fn generate_group(item: &GenericGroup) -> syn::Result<TokenStream> {
}

impl<'a> FontRead<'a> for #name <'a> {
#[inline]
fn read(bytes: FontData<'a>) -> Result<Self, ReadError> {
let untyped = #inner::read(bytes)?;
match untyped.#type_field() {
Expand Down
19 changes: 19 additions & 0 deletions read-fonts/generated/font.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ impl MinByteRange for TableDirectoryMarker {
}

impl<'a> FontRead<'a> for TableDirectory<'a> {
#[inline]
fn read(data: FontData<'a>) -> Result<Self, ReadError> {
let mut cursor = data.cursor();
cursor.advance::<u32>();
Expand All @@ -74,33 +75,39 @@ pub type TableDirectory<'a> = TableRef<'a, TableDirectoryMarker>;
#[allow(clippy::needless_lifetimes)]
impl<'a> TableDirectory<'a> {
/// 0x00010000 or 0x4F54544F
#[inline]
pub fn sfnt_version(&self) -> u32 {
let range = self.shape.sfnt_version_byte_range();
self.data.read_at(range.start).unwrap()
}

/// Number of tables.
#[inline]
pub fn num_tables(&self) -> u16 {
let range = self.shape.num_tables_byte_range();
self.data.read_at(range.start).unwrap()
}

#[inline]
pub fn search_range(&self) -> u16 {
let range = self.shape.search_range_byte_range();
self.data.read_at(range.start).unwrap()
}

#[inline]
pub fn entry_selector(&self) -> u16 {
let range = self.shape.entry_selector_byte_range();
self.data.read_at(range.start).unwrap()
}

#[inline]
pub fn range_shift(&self) -> u16 {
let range = self.shape.range_shift_byte_range();
self.data.read_at(range.start).unwrap()
}

/// Table records array—one for each top-level table in the font
#[inline]
pub fn table_records(&self) -> &'a [TableRecord] {
let range = self.shape.table_records_byte_range();
self.data.read_array(range).unwrap()
Expand Down Expand Up @@ -157,21 +164,25 @@ pub struct TableRecord {

impl TableRecord {
/// Table identifier.
#[inline]
pub fn tag(&self) -> Tag {
self.tag.get()
}

/// Checksum for the table.
#[inline]
pub fn checksum(&self) -> u32 {
self.checksum.get()
}

/// Offset from the beginning of the font data.
#[inline]
pub fn offset(&self) -> u32 {
self.offset.get()
}

/// Length of the table.
#[inline]
pub fn length(&self) -> u32 {
self.length.get()
}
Expand Down Expand Up @@ -253,6 +264,7 @@ impl MinByteRange for TTCHeaderMarker {
}

impl<'a> FontRead<'a> for TTCHeader<'a> {
#[inline]
fn read(data: FontData<'a>) -> Result<Self, ReadError> {
let mut cursor = data.cursor();
cursor.advance::<Tag>();
Expand Down Expand Up @@ -298,42 +310,49 @@ pub type TTCHeader<'a> = TableRef<'a, TTCHeaderMarker>;
#[allow(clippy::needless_lifetimes)]
impl<'a> TTCHeader<'a> {
/// Font Collection ID string: \"ttcf\"
#[inline]
pub fn ttc_tag(&self) -> Tag {
let range = self.shape.ttc_tag_byte_range();
self.data.read_at(range.start).unwrap()
}

/// Major/minor version of the TTC Header
#[inline]
pub fn version(&self) -> MajorMinor {
let range = self.shape.version_byte_range();
self.data.read_at(range.start).unwrap()
}

/// Number of fonts in TTC
#[inline]
pub fn num_fonts(&self) -> u32 {
let range = self.shape.num_fonts_byte_range();
self.data.read_at(range.start).unwrap()
}

/// Array of offsets to the TableDirectory for each font from the beginning of the file
#[inline]
pub fn table_directory_offsets(&self) -> &'a [BigEndian<u32>] {
let range = self.shape.table_directory_offsets_byte_range();
self.data.read_array(range).unwrap()
}

/// Tag indicating that a DSIG table exists, 0x44534947 ('DSIG') (null if no signature)
#[inline]
pub fn dsig_tag(&self) -> Option<u32> {
let range = self.shape.dsig_tag_byte_range()?;
Some(self.data.read_at(range.start).unwrap())
}

/// The length (in bytes) of the DSIG table (null if no signature)
#[inline]
pub fn dsig_length(&self) -> Option<u32> {
let range = self.shape.dsig_length_byte_range()?;
Some(self.data.read_at(range.start).unwrap())
}

/// The offset (in bytes) of the DSIG table from the beginning of the TTC file (null if no signature)
#[inline]
pub fn dsig_offset(&self) -> Option<u32> {
let range = self.shape.dsig_offset_byte_range()?;
Some(self.data.read_at(range.start).unwrap())
Expand Down
Loading