pub fn string_by_id<'a>(
metadata: &'a Table<'_>,
sid: StringId,
) -> Option<&'a str>Examples found in repository?
examples/tounicode.rs (line 18)
5fn main() {
6 // open the file passed on the comanmand line
7 let path = std::env::args().nth(1).expect("no file given");
8 let file = std::fs::File::open(&path).expect("could not open file");
9 let mut reader = std::io::BufReader::new(file);
10 let mut buffer = Vec::new();
11 reader
12 .read_to_end(&mut buffer)
13 .expect("could not read file");
14 let table = Table::parse(&buffer).unwrap();
15
16 let encoding = table.encoding.get_code_to_sid_table(&table.charset);
17 for (cid, sid) in encoding.iter() {
18 println!("{}: {:?}", cid, string_by_id(&table, *sid));
19 }
20}More examples
examples/dump.rs (line 31)
6fn main() {
7 // open the file passed on the comanmand line
8 let path = std::env::args().nth(1).expect("no file given");
9 let file = std::fs::File::open(&path).expect("could not open file");
10 let mut reader = std::io::BufReader::new(file);
11 let mut buffer = Vec::new();
12 reader
13 .read_to_end(&mut buffer)
14 .expect("could not read file");
15 let table = Table::parse(&buffer).unwrap();
16 dbg!(&table);
17 println!("full name: {:?}", table.full_name());
18 println!("family name: {:?}", table.family_name());
19 println!("version: {:?}", table.version());
20 println!("notice: {:?}", table.notice());
21 println!("number of glyphs: {:?}", table.number_of_glyphs());
22
23 println!("charset:");
24 match table.charset {
25 Charset::ISOAdobe => println!("ISOAdobe"),
26 Charset::Expert => println!("Expert"),
27 Charset::ExpertSubset => println!("ExpertSubset"),
28 Charset::Format0(ref array) => {
29 println!("Format0:");
30 for sid in *array {
31 println!(" {:?}", string_by_id(&table, sid));
32 }
33 }
34 Charset::Format1(ref array) => {
35 println!("Format1:");
36 for range in *array {
37 let sid = range.first;
38 let count = range.left;
39 println!(" {:?} {:?}", sid, count);
40 for i in 0..=count {
41 println!(
42 " {:?}",
43 string_by_id(&table, StringId(sid.0 + u16::from(i)))
44 );
45 }
46 }
47 }
48 Charset::Format2(ref array) => {
49 println!("Format2:");
50 for range in *array {
51 let sid = range.first;
52 let count = range.left;
53 println!(" {:?} {:?}", sid, count);
54 for i in 0..=count {
55 println!(" {:?}", string_by_id(&table, StringId(sid.0 + i)));
56 }
57 }
58 }
59 }
60 println!("encoding:");
61 match table.encoding.kind {
62 cff_parser::EncodingKind::Standard => println!("Standard"),
63 cff_parser::EncodingKind::Expert => println!("Expert"),
64 cff_parser::EncodingKind::Format0(ref array) => {
65 println!("Format0:");
66 for code in *array {
67 println!(" {:?}", code);
68 }
69 }
70 cff_parser::EncodingKind::Format1(ref array) => {
71 println!("Format1:");
72 for range in *array {
73 println!(" {:?} {:?}", range.first, range.left);
74 }
75 }
76 }
77}