pub struct Table<'a> {
pub encoding: Encoding<'a>,
pub charset: Charset<'a>,
/* private fields */
}Expand description
Fields§
§encoding: Encoding<'a>§charset: Charset<'a>Implementations§
Source§impl<'a> Table<'a>
impl<'a> Table<'a>
Sourcepub fn parse(data: &'a [u8]) -> Option<Self>
pub fn parse(data: &'a [u8]) -> Option<Self>
Parses a table from raw data.
Examples found in repository?
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
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}Sourcepub fn number_of_glyphs(&self) -> u16
pub fn number_of_glyphs(&self) -> u16
Returns a total number of glyphs in the font.
Never zero.
Examples found in repository?
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}Sourcepub fn glyph_fd_matrix(&self, glyph_id: GlyphId) -> Matrix
pub fn glyph_fd_matrix(&self, glyph_id: GlyphId) -> Matrix
Returns the FontMatrix for the FD that owns glyph_id.
CID-keyed CFF fonts can define a per-FD FontMatrix in each entry of the FDArray (op 12 7). If the FD has one it overrides the top-level matrix. For SID fonts (no FDArray) or when the FD has no explicit matrix, falls back to the top-level matrix.
Use this instead of matrix() when converting CFF charstring advances
to PDF text-space widths for CIDFontType0 width repair (6.2.11.5:1).
Sourcepub fn outline(
&self,
glyph_id: GlyphId,
builder: &mut dyn OutlineBuilder,
) -> Result<Rect, CFFError>
pub fn outline( &self, glyph_id: GlyphId, builder: &mut dyn OutlineBuilder, ) -> Result<Rect, CFFError>
Outlines a glyph.
Sourcepub fn glyph_index(&self, code_point: u8) -> Option<GlyphId>
pub fn glyph_index(&self, code_point: u8) -> Option<GlyphId>
Resolves a Glyph ID for a code point.
Similar to Face::glyph_index but 8bit
and uses CFF encoding and charset tables instead of TrueType cmap.
Sourcepub fn glyph_width(&self, glyph_id: GlyphId) -> Option<u16>
pub fn glyph_width(&self, glyph_id: GlyphId) -> Option<u16>
Returns a glyph width.
This value is different from outline bbox width and is stored separately.
Technically similar to Face::glyph_hor_advance.
Sourcepub fn glyph_width_f64(&self, glyph_id: GlyphId) -> Option<f64>
pub fn glyph_width_f64(&self, glyph_id: GlyphId) -> Option<f64>
Returns the glyph width as a signed f64 value.
Unlike [glyph_width] which returns u16 (and None for negative
widths), this preserves the full CFF charstring advance including
negative values that can arise from nominalWidthX offsets.
Sourcepub fn glyph_width_f32(&self, glyph_id: GlyphId) -> Option<f32>
pub fn glyph_width_f32(&self, glyph_id: GlyphId) -> Option<f32>
Returns the glyph width as a signed f32 value.
Prefer [glyph_width_f64] when exact PDF width reconstruction matters.
Sourcepub fn glyph_width_f64_verapdf(&self, glyph_id: GlyphId) -> Option<f64>
pub fn glyph_width_f64_verapdf(&self, glyph_id: GlyphId) -> Option<f64>
The advance as veraPDF 1.28.2 computes it for a Type2 charstring.
veraPDF truncates a fractional nominalWidthX to an integer when it
applies it (measured on TeX subset CFFs: 384.77777 is applied as 384,
501.4375 as 501, so its reported advance is the true advance minus the
fractional part). The CFF specification adds the full value, which is
what [glyph_width_f64] returns. Both values sit well within the
§6.2.11.5 tolerance of ±1 of each other, but a dictionary width that
matches the spec value can exceed the tolerance against the
validator’s value — so dictionary widths written to satisfy veraPDF
must use the same truncated arithmetic.
Sourcepub fn glyph_index_by_name(&self, name: &str) -> Option<GlyphId>
pub fn glyph_index_by_name(&self, name: &str) -> Option<GlyphId>
Returns a glyph ID by a name.
Sourcepub fn default_width_x(&self) -> Option<u16>
pub fn default_width_x(&self) -> Option<u16>
Returns the DefaultWidthX value from the Private DICT (SID fonts only).
veraPDF uses this value as the font program width for character codes
that are absent from the CFF encoding (i.e., glyph_index returns GID 0).
Sourcepub fn default_width_x_f64(&self) -> Option<f64>
pub fn default_width_x_f64(&self) -> Option<f64>
Returns the DefaultWidthX value from the Private DICT as f64.
Sourcepub fn glyph_name(&self, glyph_id: GlyphId) -> Option<&'a str>
pub fn glyph_name(&self, glyph_id: GlyphId) -> Option<&'a str>
Returns a glyph name.
Sourcepub fn glyph_cid(&self, glyph_id: GlyphId) -> Option<u16>
pub fn glyph_cid(&self, glyph_id: GlyphId) -> Option<u16>
Returns the CID corresponding to a glyph ID.
Returns None if this is not a CIDFont.
Sourcepub fn version(&self) -> Option<&str>
pub fn version(&self) -> Option<&str>
Examples found in repository?
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}Sourcepub fn notice(&self) -> Option<&str>
pub fn notice(&self) -> Option<&str>
Examples found in repository?
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}Sourcepub fn full_name(&self) -> Option<&str>
pub fn full_name(&self) -> Option<&str>
Examples found in repository?
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}Sourcepub fn family_name(&self) -> Option<&str>
pub fn family_name(&self) -> Option<&str>
Examples found in repository?
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}