Skip to content

Commit

Permalink
The not yet correct current generated code
Browse files Browse the repository at this point in the history
  • Loading branch information
rsheeter committed Oct 23, 2022
1 parent d7dc4d0 commit 411239d
Show file tree
Hide file tree
Showing 10 changed files with 125 additions and 195 deletions.
61 changes: 52 additions & 9 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 @@ -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
8 changes: 2 additions & 6 deletions read-fonts/generated/generated_colr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -215,20 +215,16 @@ impl<'a> SomeTable<'a> for Colr<'a> {
)),
2usize => Some(Field::new(
"base_glyph_records_offset",
traversal::FieldType::offset_to_array_of_records(
FieldType::offset_to_array_of_scalars(
self.base_glyph_records_offset(),
self.base_glyph_records(),
stringify!(BaseGlyph),
self.offset_data(),
),
)),
3usize => Some(Field::new(
"layer_records_offset",
traversal::FieldType::offset_to_array_of_records(
FieldType::offset_to_array_of_scalars(
self.layer_records_offset(),
self.layer_records(),
stringify!(Layer),
self.offset_data(),
),
)),
4usize => Some(Field::new("num_layer_records", self.num_layer_records())),
Expand Down
4 changes: 1 addition & 3 deletions read-fonts/generated/generated_cpal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -216,11 +216,9 @@ impl<'a> SomeTable<'a> for Cpal<'a> {
3usize => Some(Field::new("num_color_records", self.num_color_records())),
4usize => Some(Field::new(
"color_records_array_offset",
traversal::FieldType::offset_to_array_of_records(
FieldType::offset_to_array_of_scalars(
self.color_records_array_offset(),
self.color_records_array(),
stringify!(ColorRecord),
self.offset_data(),
),
)),
5usize => Some(Field::new(
Expand Down
4 changes: 2 additions & 2 deletions read-fonts/generated/generated_glyf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ impl<'a> SimpleGlyph<'a> {
}

/// the raw data for flags & x/y coordinates
pub fn glyph_data(&self) -> &'a [u8] {
pub fn glyph_data(&self) -> &'a [BigEndian<u8>] {
let range = self.shape.glyph_data_byte_range();
self.data.read_array(range).unwrap()
}
Expand Down Expand Up @@ -320,7 +320,7 @@ impl<'a> CompositeGlyph<'a> {

/// component flag
/// glyph index of component
pub fn component_data(&self) -> &'a [u8] {
pub fn component_data(&self) -> &'a [BigEndian<u8>] {
let range = self.shape.component_data_byte_range();
self.data.read_array(range).unwrap()
}
Expand Down
Loading

0 comments on commit 411239d

Please sign in to comment.