From 40b015622bd414e5b26f5a54610d6a900133c0c0 Mon Sep 17 00:00:00 2001 From: Rod S Date: Sat, 22 Oct 2022 17:22:08 -0700 Subject: [PATCH] The generated code --- read-fonts/generated/generated_cmap.rs | 69 +++++++++++++++++++++----- read-fonts/generated/generated_cpal.rs | 16 +++--- read-fonts/generated/generated_glyf.rs | 2 +- 3 files changed, 65 insertions(+), 22 deletions(-) diff --git a/read-fonts/generated/generated_cmap.rs b/read-fonts/generated/generated_cmap.rs index c9555ece4..42309f3a5 100644 --- a/read-fonts/generated/generated_cmap.rs +++ b/read-fonts/generated/generated_cmap.rs @@ -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, } } @@ -90,7 +97,7 @@ impl<'a> std::fmt::Debug for Cmap<'a> { #[repr(packed)] pub struct EncodingRecord { /// Platform ID. - pub platform_id: BigEndian, + pub platform_id: BigEndian, /// Platform-specific encoding ID. pub encoding_id: BigEndian, /// Byte offset from beginning of table to the subtable for this @@ -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() } @@ -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")] @@ -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] { + pub fn glyph_id_array(&self) -> &'a [u8] { let range = self.shape.glyph_id_array_byte_range(); self.data.read_array(range).unwrap() } @@ -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] { + pub fn is32(&self) -> &'a [u8] { let range = self.shape.is32_byte_range(); self.data.read_array(range).unwrap() } @@ -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, } } @@ -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, } } @@ -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, } } @@ -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, } } @@ -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, } } @@ -1715,7 +1758,7 @@ pub struct UnicodeRange { /// First value in this range pub start_unicode_value: BigEndian, /// Number of additional values in this range - pub additional_count: BigEndian, + pub additional_count: u8, } impl UnicodeRange { @@ -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 } } diff --git a/read-fonts/generated/generated_cpal.rs b/read-fonts/generated/generated_cpal.rs index f2af8dd50..5447e1328 100644 --- a/read-fonts/generated/generated_cpal.rs +++ b/read-fonts/generated/generated_cpal.rs @@ -266,34 +266,34 @@ impl<'a> std::fmt::Debug for Cpal<'a> { #[repr(packed)] pub struct ColorRecord { /// Blue value (B0). - pub blue: BigEndian, + pub blue: u8, /// Green value (B1). - pub green: BigEndian, + pub green: u8, /// Red value (B2). - pub red: BigEndian, + pub red: u8, /// Alpha value (B3). - pub alpha: BigEndian, + 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 } } diff --git a/read-fonts/generated/generated_glyf.rs b/read-fonts/generated/generated_glyf.rs index 06538e888..37ff47404 100644 --- a/read-fonts/generated/generated_glyf.rs +++ b/read-fonts/generated/generated_glyf.rs @@ -169,7 +169,7 @@ impl<'a> SimpleGlyph<'a> { } /// Array of instruction byte code for the glyph. - pub fn instructions(&self) -> &'a [BigEndian] { + pub fn instructions(&self) -> &'a [u8] { let range = self.shape.instructions_byte_range(); self.data.read_array(range).unwrap() }