Skip to content

Commit

Permalink
The generated code
Browse files Browse the repository at this point in the history
  • Loading branch information
rsheeter committed Oct 23, 2022
1 parent b9e61a4 commit 40b0156
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 22 deletions.
69 changes: 56 additions & 13 deletions read-fonts/generated/generated_cmap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,14 @@ impl<'a> SomeTable<'a> for Cmap<'a> {
match idx {
0usize => Some(Field::new("version", self.version())),
1usize => Some(Field::new("num_tables", self.num_tables())),
2usize => Some(compile_error!("unhandled traversal case")),
2usize => Some(Field::new(
"encoding_records",
traversal::FieldType::array_of_records(
stringify!(EncodingRecord),
self.encoding_records(),
self.offset_data(),
),
)),
_ => None,
}
}
Expand All @@ -90,7 +97,7 @@ impl<'a> std::fmt::Debug for Cmap<'a> {
#[repr(packed)]
pub struct EncodingRecord {
/// Platform ID.
pub platform_id: BigEndian<u16>,
pub platform_id: BigEndian<PlatformId>,
/// Platform-specific encoding ID.
pub encoding_id: BigEndian<u16>,
/// Byte offset from beginning of table to the subtable for this
Expand All @@ -100,7 +107,7 @@ pub struct EncodingRecord {

impl EncodingRecord {
/// Platform ID.
pub fn platform_id(&self) -> u16 {
pub fn platform_id(&self) -> PlatformId {
self.platform_id.get()
}

Expand All @@ -122,7 +129,8 @@ impl EncodingRecord {
}

impl FixedSize for EncodingRecord {
const RAW_BYTE_LEN: usize = u16::RAW_BYTE_LEN + u16::RAW_BYTE_LEN + Offset32::RAW_BYTE_LEN;
const RAW_BYTE_LEN: usize =
PlatformId::RAW_BYTE_LEN + u16::RAW_BYTE_LEN + Offset32::RAW_BYTE_LEN;
}

#[cfg(feature = "traversal")]
Expand Down Expand Up @@ -323,7 +331,7 @@ impl<'a> Cmap0<'a> {
}

/// An array that maps character codes to glyph index values.
pub fn glyph_id_array(&self) -> &'a [BigEndian<u8>] {
pub fn glyph_id_array(&self) -> &'a [u8] {
let range = self.shape.glyph_id_array_byte_range();
self.data.read_array(range).unwrap()
}
Expand Down Expand Up @@ -932,7 +940,7 @@ impl<'a> Cmap8<'a> {
/// Tightly packed array of bits (8K bytes total) indicating
/// whether the particular 16-bit (index) value is the start of a
/// 32-bit character code
pub fn is32(&self) -> &'a [BigEndian<u8>] {
pub fn is32(&self) -> &'a [u8] {
let range = self.shape.is32_byte_range();
self.data.read_array(range).unwrap()
}
Expand Down Expand Up @@ -962,7 +970,14 @@ impl<'a> SomeTable<'a> for Cmap8<'a> {
2usize => Some(Field::new("language", self.language())),
3usize => Some(Field::new("is32", self.is32())),
4usize => Some(Field::new("num_groups", self.num_groups())),
5usize => Some(compile_error!("unhandled traversal case")),
5usize => Some(Field::new(
"groups",
traversal::FieldType::array_of_records(
stringify!(SequentialMapGroup),
self.groups(),
self.offset_data(),
),
)),
_ => None,
}
}
Expand Down Expand Up @@ -1258,7 +1273,14 @@ impl<'a> SomeTable<'a> for Cmap12<'a> {
1usize => Some(Field::new("length", self.length())),
2usize => Some(Field::new("language", self.language())),
3usize => Some(Field::new("num_groups", self.num_groups())),
4usize => Some(compile_error!("unhandled traversal case")),
4usize => Some(Field::new(
"groups",
traversal::FieldType::array_of_records(
stringify!(SequentialMapGroup),
self.groups(),
self.offset_data(),
),
)),
_ => None,
}
}
Expand Down Expand Up @@ -1370,7 +1392,14 @@ impl<'a> SomeTable<'a> for Cmap13<'a> {
1usize => Some(Field::new("length", self.length())),
2usize => Some(Field::new("language", self.language())),
3usize => Some(Field::new("num_groups", self.num_groups())),
4usize => Some(compile_error!("unhandled traversal case")),
4usize => Some(Field::new(
"groups",
traversal::FieldType::array_of_records(
stringify!(ConstantMapGroup),
self.groups(),
self.offset_data(),
),
)),
_ => None,
}
}
Expand Down Expand Up @@ -1522,7 +1551,14 @@ impl<'a> SomeTable<'a> for Cmap14<'a> {
"num_var_selector_records",
self.num_var_selector_records(),
)),
3usize => Some(compile_error!("unhandled traversal case")),
3usize => Some(Field::new(
"var_selector",
traversal::FieldType::array_of_records(
stringify!(VariationSelector),
self.var_selector(),
self.offset_data(),
),
)),
_ => None,
}
}
Expand Down Expand Up @@ -1652,7 +1688,14 @@ impl<'a> SomeTable<'a> for DefaultUvs<'a> {
"num_unicode_value_ranges",
self.num_unicode_value_ranges(),
)),
1usize => Some(compile_error!("unhandled traversal case")),
1usize => Some(Field::new(
"ranges",
traversal::FieldType::array_of_records(
stringify!(UnicodeRange),
self.ranges(),
self.offset_data(),
),
)),
_ => None,
}
}
Expand Down Expand Up @@ -1715,7 +1758,7 @@ pub struct UnicodeRange {
/// First value in this range
pub start_unicode_value: BigEndian<Uint24>,
/// Number of additional values in this range
pub additional_count: BigEndian<u8>,
pub additional_count: u8,
}

impl UnicodeRange {
Expand All @@ -1726,7 +1769,7 @@ impl UnicodeRange {

/// Number of additional values in this range
pub fn additional_count(&self) -> u8 {
self.additional_count.get()
self.additional_count
}
}

Expand Down
16 changes: 8 additions & 8 deletions read-fonts/generated/generated_cpal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -266,34 +266,34 @@ impl<'a> std::fmt::Debug for Cpal<'a> {
#[repr(packed)]
pub struct ColorRecord {
/// Blue value (B0).
pub blue: BigEndian<u8>,
pub blue: u8,
/// Green value (B1).
pub green: BigEndian<u8>,
pub green: u8,
/// Red value (B2).
pub red: BigEndian<u8>,
pub red: u8,
/// Alpha value (B3).
pub alpha: BigEndian<u8>,
pub alpha: u8,
}

impl ColorRecord {
/// Blue value (B0).
pub fn blue(&self) -> u8 {
self.blue.get()
self.blue
}

/// Green value (B1).
pub fn green(&self) -> u8 {
self.green.get()
self.green
}

/// Red value (B2).
pub fn red(&self) -> u8 {
self.red.get()
self.red
}

/// Alpha value (B3).
pub fn alpha(&self) -> u8 {
self.alpha.get()
self.alpha
}
}

Expand Down
2 changes: 1 addition & 1 deletion read-fonts/generated/generated_glyf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ impl<'a> SimpleGlyph<'a> {
}

/// Array of instruction byte code for the glyph.
pub fn instructions(&self) -> &'a [BigEndian<u8>] {
pub fn instructions(&self) -> &'a [u8] {
let range = self.shape.instructions_byte_range();
self.data.read_array(range).unwrap()
}
Expand Down

0 comments on commit 40b0156

Please sign in to comment.