Skip to main content

Table

Struct Table 

Source
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>

Source

pub fn parse(data: &'a [u8]) -> Option<Self>

Parses a table from raw data.

Examples found in repository?
examples/tounicode.rs (line 14)
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
Hide additional examples
examples/dump.rs (line 15)
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}
Source

pub fn number_of_glyphs(&self) -> u16

Returns a total number of glyphs in the font.

Never zero.

Examples found in repository?
examples/dump.rs (line 21)
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}
Source

pub fn matrix(&self) -> Matrix

Returns a font transformation matrix.

Source

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).

Source

pub fn outline( &self, glyph_id: GlyphId, builder: &mut dyn OutlineBuilder, ) -> Result<Rect, CFFError>

Outlines a glyph.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn glyph_index_by_name(&self, name: &str) -> Option<GlyphId>

Returns a glyph ID by a name.

Source

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).

Source

pub fn default_width_x_f64(&self) -> Option<f64>

Returns the DefaultWidthX value from the Private DICT as f64.

Source

pub fn glyph_name(&self, glyph_id: GlyphId) -> Option<&'a str>

Returns a glyph name.

Source

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.

Source

pub fn version(&self) -> Option<&str>

Examples found in repository?
examples/dump.rs (line 19)
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}
Source

pub fn notice(&self) -> Option<&str>

Examples found in repository?
examples/dump.rs (line 20)
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}
Source

pub fn full_name(&self) -> Option<&str>

Examples found in repository?
examples/dump.rs (line 17)
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}
Source

pub fn family_name(&self) -> Option<&str>

Examples found in repository?
examples/dump.rs (line 18)
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}

Trait Implementations§

Source§

impl<'a> Clone for Table<'a>

Source§

fn clone(&self) -> Table<'a>

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<'a> Copy for Table<'a>

Source§

impl Debug for Table<'_>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'a> Freeze for Table<'a>

§

impl<'a> RefUnwindSafe for Table<'a>

§

impl<'a> Send for Table<'a>

§

impl<'a> Sync for Table<'a>

§

impl<'a> Unpin for Table<'a>

§

impl<'a> UnsafeUnpin for Table<'a>

§

impl<'a> UnwindSafe for Table<'a>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.