Skip to content

Commit

Permalink
[read] Expose table marker, make range fns public
Browse files Browse the repository at this point in the history
This is useful for applications like subsetting.

The individual markers are still #[doc(hidden)] because they really
aren't intended to be public API, so this flood of new methods should
also not show up in the docs.
  • Loading branch information
cmyr committed Nov 13, 2024
1 parent bba7337 commit c6dab02
Show file tree
Hide file tree
Showing 54 changed files with 2,082 additions and 1,163 deletions.
4 changes: 2 additions & 2 deletions font-codegen/src/table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -908,15 +908,15 @@ impl Table {
};
let start_field_name = field.shape_byte_start_field_name();
return Some(quote! {
fn #fn_name(&self) -> Option<Range<usize>> {
pub fn #fn_name(&self) -> Option<Range<usize>> {
let start = self.#start_field_name?;
Some(start..start + #len_expr)
}
});
}

let result = quote! {
fn #fn_name(&self) -> Range<usize> {
pub fn #fn_name(&self) -> Range<usize> {
let start = #prev_field_end_expr;
start..start + #len_expr
}
Expand Down
37 changes: 24 additions & 13 deletions read-fonts/generated/font.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,27 +13,32 @@ pub struct TableDirectoryMarker {
}

impl TableDirectoryMarker {
fn sfnt_version_byte_range(&self) -> Range<usize> {
pub fn sfnt_version_byte_range(&self) -> Range<usize> {
let start = 0;
start..start + u32::RAW_BYTE_LEN
}
fn num_tables_byte_range(&self) -> Range<usize> {

pub fn num_tables_byte_range(&self) -> Range<usize> {
let start = self.sfnt_version_byte_range().end;
start..start + u16::RAW_BYTE_LEN
}
fn search_range_byte_range(&self) -> Range<usize> {

pub fn search_range_byte_range(&self) -> Range<usize> {
let start = self.num_tables_byte_range().end;
start..start + u16::RAW_BYTE_LEN
}
fn entry_selector_byte_range(&self) -> Range<usize> {

pub fn entry_selector_byte_range(&self) -> Range<usize> {
let start = self.search_range_byte_range().end;
start..start + u16::RAW_BYTE_LEN
}
fn range_shift_byte_range(&self) -> Range<usize> {

pub fn range_shift_byte_range(&self) -> Range<usize> {
let start = self.entry_selector_byte_range().end;
start..start + u16::RAW_BYTE_LEN
}
fn table_records_byte_range(&self) -> Range<usize> {

pub fn table_records_byte_range(&self) -> Range<usize> {
let start = self.range_shift_byte_range().end;
start..start + self.table_records_byte_len
}
Expand Down Expand Up @@ -197,31 +202,37 @@ pub struct TTCHeaderMarker {
}

impl TTCHeaderMarker {
fn ttc_tag_byte_range(&self) -> Range<usize> {
pub fn ttc_tag_byte_range(&self) -> Range<usize> {
let start = 0;
start..start + Tag::RAW_BYTE_LEN
}
fn version_byte_range(&self) -> Range<usize> {

pub fn version_byte_range(&self) -> Range<usize> {
let start = self.ttc_tag_byte_range().end;
start..start + MajorMinor::RAW_BYTE_LEN
}
fn num_fonts_byte_range(&self) -> Range<usize> {

pub fn num_fonts_byte_range(&self) -> Range<usize> {
let start = self.version_byte_range().end;
start..start + u32::RAW_BYTE_LEN
}
fn table_directory_offsets_byte_range(&self) -> Range<usize> {

pub fn table_directory_offsets_byte_range(&self) -> Range<usize> {
let start = self.num_fonts_byte_range().end;
start..start + self.table_directory_offsets_byte_len
}
fn dsig_tag_byte_range(&self) -> Option<Range<usize>> {

pub fn dsig_tag_byte_range(&self) -> Option<Range<usize>> {
let start = self.dsig_tag_byte_start?;
Some(start..start + u32::RAW_BYTE_LEN)
}
fn dsig_length_byte_range(&self) -> Option<Range<usize>> {

pub fn dsig_length_byte_range(&self) -> Option<Range<usize>> {
let start = self.dsig_length_byte_start?;
Some(start..start + u32::RAW_BYTE_LEN)
}
fn dsig_offset_byte_range(&self) -> Option<Range<usize>> {

pub fn dsig_offset_byte_range(&self) -> Option<Range<usize>> {
let start = self.dsig_offset_byte_start?;
Some(start..start + u32::RAW_BYTE_LEN)
}
Expand Down
Loading

0 comments on commit c6dab02

Please sign in to comment.