1include!("../../../generated/generated_cff2.rs");
4
5#[derive(Clone)]
7pub struct Cff2<'a> {
8 header: Cff2Header<'a>,
9 global_subrs: Index<'a>,
10}
11
12impl<'a> Cff2<'a> {
13 pub fn offset_data(&self) -> FontData<'a> {
14 self.header.offset_data()
15 }
16
17 pub fn header(&self) -> &Cff2Header<'a> {
18 &self.header
19 }
20
21 pub fn top_dict_data(&self) -> &'a [u8] {
25 self.header.top_dict_data()
26 }
27
28 pub fn global_subrs(&self) -> Index<'a> {
35 self.global_subrs.clone()
36 }
37}
38
39impl TopLevelTable for Cff2<'_> {
40 const TAG: Tag = Tag::new(b"CFF2");
41}
42
43impl ReadArgs for Cff2<'_> {
44 type Args = ();
45}
46
47impl<'a> FontRead<'a> for Cff2<'a> {
48 fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
49 let header = Cff2Header::read(data)?;
50 let global_subrs = Index::read(FontData::new(header.trailing_data()))?;
51 Ok(Self {
52 header,
53 global_subrs,
54 })
55 }
56}
57
58#[cfg(test)]
59mod tests {
60 use super::*;
61 use crate::{FontData, FontRead, FontRef, TableProvider};
62
63 #[test]
64 fn read_example_cff2_table() {
65 let cff2 = Cff2::read(FontData::new(font_test_data::cff2::EXAMPLE)).unwrap();
66 assert_eq!(cff2.header().major_version(), 2);
67 assert_eq!(cff2.header().minor_version(), 0);
68 assert_eq!(cff2.header().header_size(), 5);
69 assert_eq!(cff2.top_dict_data().len(), 7);
70 assert_eq!(cff2.global_subrs().count(), 0);
71 }
72
73 #[test]
74 fn read_cantarell() {
75 let font = FontRef::new(font_test_data::CANTARELL_VF_TRIMMED).unwrap();
76 let cff2 = font.cff2().unwrap();
77 assert_eq!(cff2.header().major_version(), 2);
78 assert_eq!(cff2.header().minor_version(), 0);
79 assert_eq!(cff2.header().header_size(), 5);
80 assert_eq!(cff2.top_dict_data().len(), 7);
81 assert_eq!(cff2.global_subrs().count(), 0);
82 }
83}