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 12)
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.read_to_end(&mut buffer).expect("could not read file");
12    let table = Table::parse(&buffer).unwrap();
13
14    let encoding = table.encoding.get_code_to_sid_table(&table.charset);
15    for (cid, sid) in encoding.iter() {
16        println!("{}: {:?}", cid, string_by_id(&table, *sid));
17    }
18
19}
More examples
Hide additional examples
examples/dump.rs (line 13)
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.read_to_end(&mut buffer).expect("could not read file");
13    let table = Table::parse(&buffer).unwrap();
14    dbg!(&table);
15    println!("full name: {:?}", table.full_name());
16    println!("family name: {:?}", table.family_name());
17    println!("version: {:?}", table.version());
18    println!("notice: {:?}", table.notice());
19    println!("number of glyphs: {:?}", table.number_of_glyphs());
20
21    println!("charset:");
22    match table.charset {
23
24        Charset::ISOAdobe => println!("ISOAdobe"),
25        Charset::Expert => println!("Expert"),
26        Charset::ExpertSubset => println!("ExpertSubset"),
27        Charset::Format0(ref array) => {
28            println!("Format0:");
29            for sid in array.clone() {
30                println!("  {:?}", string_by_id(&table, sid));
31            }
32        }
33        Charset::Format1(ref array) => {
34            println!("Format1:");
35            for range in array.clone() {
36                let sid = range.first;
37                let count = range.left;
38                println!("  {:?} {:?}", sid, count);
39                for i in 0..=count {
40                    println!("    {:?}", string_by_id(&table, StringId(sid.0 + u16::from(i))));
41                }
42            }
43        }
44        Charset::Format2(ref array) => {
45            println!("Format2:");
46            for range in array.clone() {
47                let sid = range.first;
48                let count = range.left;
49                println!("  {:?} {:?}", sid, count);
50                for i in 0..=count {
51                    println!("    {:?}", string_by_id(&table, StringId(sid.0 + i)));
52                }
53            }
54        }
55    }
56    println!("encoding:");
57    match table.encoding.kind {
58        cff_parser::EncodingKind::Standard => println!("Standard"),
59        cff_parser::EncodingKind::Expert => println!("Expert"),
60        cff_parser::EncodingKind::Format0(ref array) => {
61            println!("Format0:");
62            for code in array.clone() {
63                println!("  {:?}", code);
64            }
65        }
66        cff_parser::EncodingKind::Format1(ref array) => {
67            println!("Format1:");
68            for range in array.clone() {
69                println!("  {:?} {:?}", range.first, range.left);
70            }
71        }
72    }
73}
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 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.read_to_end(&mut buffer).expect("could not read file");
13    let table = Table::parse(&buffer).unwrap();
14    dbg!(&table);
15    println!("full name: {:?}", table.full_name());
16    println!("family name: {:?}", table.family_name());
17    println!("version: {:?}", table.version());
18    println!("notice: {:?}", table.notice());
19    println!("number of glyphs: {:?}", table.number_of_glyphs());
20
21    println!("charset:");
22    match table.charset {
23
24        Charset::ISOAdobe => println!("ISOAdobe"),
25        Charset::Expert => println!("Expert"),
26        Charset::ExpertSubset => println!("ExpertSubset"),
27        Charset::Format0(ref array) => {
28            println!("Format0:");
29            for sid in array.clone() {
30                println!("  {:?}", string_by_id(&table, sid));
31            }
32        }
33        Charset::Format1(ref array) => {
34            println!("Format1:");
35            for range in array.clone() {
36                let sid = range.first;
37                let count = range.left;
38                println!("  {:?} {:?}", sid, count);
39                for i in 0..=count {
40                    println!("    {:?}", string_by_id(&table, StringId(sid.0 + u16::from(i))));
41                }
42            }
43        }
44        Charset::Format2(ref array) => {
45            println!("Format2:");
46            for range in array.clone() {
47                let sid = range.first;
48                let count = range.left;
49                println!("  {:?} {:?}", sid, count);
50                for i in 0..=count {
51                    println!("    {:?}", string_by_id(&table, StringId(sid.0 + i)));
52                }
53            }
54        }
55    }
56    println!("encoding:");
57    match table.encoding.kind {
58        cff_parser::EncodingKind::Standard => println!("Standard"),
59        cff_parser::EncodingKind::Expert => println!("Expert"),
60        cff_parser::EncodingKind::Format0(ref array) => {
61            println!("Format0:");
62            for code in array.clone() {
63                println!("  {:?}", code);
64            }
65        }
66        cff_parser::EncodingKind::Format1(ref array) => {
67            println!("Format1:");
68            for range in array.clone() {
69                println!("  {:?} {:?}", range.first, range.left);
70            }
71        }
72    }
73}
Source

pub fn matrix(&self) -> Matrix

Returns a font transformation matrix.

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_index_by_name(&self, name: &str) -> Option<GlyphId>

Returns a glyph ID by a name.

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 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.read_to_end(&mut buffer).expect("could not read file");
13    let table = Table::parse(&buffer).unwrap();
14    dbg!(&table);
15    println!("full name: {:?}", table.full_name());
16    println!("family name: {:?}", table.family_name());
17    println!("version: {:?}", table.version());
18    println!("notice: {:?}", table.notice());
19    println!("number of glyphs: {:?}", table.number_of_glyphs());
20
21    println!("charset:");
22    match table.charset {
23
24        Charset::ISOAdobe => println!("ISOAdobe"),
25        Charset::Expert => println!("Expert"),
26        Charset::ExpertSubset => println!("ExpertSubset"),
27        Charset::Format0(ref array) => {
28            println!("Format0:");
29            for sid in array.clone() {
30                println!("  {:?}", string_by_id(&table, sid));
31            }
32        }
33        Charset::Format1(ref array) => {
34            println!("Format1:");
35            for range in array.clone() {
36                let sid = range.first;
37                let count = range.left;
38                println!("  {:?} {:?}", sid, count);
39                for i in 0..=count {
40                    println!("    {:?}", string_by_id(&table, StringId(sid.0 + u16::from(i))));
41                }
42            }
43        }
44        Charset::Format2(ref array) => {
45            println!("Format2:");
46            for range in array.clone() {
47                let sid = range.first;
48                let count = range.left;
49                println!("  {:?} {:?}", sid, count);
50                for i in 0..=count {
51                    println!("    {:?}", string_by_id(&table, StringId(sid.0 + i)));
52                }
53            }
54        }
55    }
56    println!("encoding:");
57    match table.encoding.kind {
58        cff_parser::EncodingKind::Standard => println!("Standard"),
59        cff_parser::EncodingKind::Expert => println!("Expert"),
60        cff_parser::EncodingKind::Format0(ref array) => {
61            println!("Format0:");
62            for code in array.clone() {
63                println!("  {:?}", code);
64            }
65        }
66        cff_parser::EncodingKind::Format1(ref array) => {
67            println!("Format1:");
68            for range in array.clone() {
69                println!("  {:?} {:?}", range.first, range.left);
70            }
71        }
72    }
73}
Source

pub fn notice(&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.read_to_end(&mut buffer).expect("could not read file");
13    let table = Table::parse(&buffer).unwrap();
14    dbg!(&table);
15    println!("full name: {:?}", table.full_name());
16    println!("family name: {:?}", table.family_name());
17    println!("version: {:?}", table.version());
18    println!("notice: {:?}", table.notice());
19    println!("number of glyphs: {:?}", table.number_of_glyphs());
20
21    println!("charset:");
22    match table.charset {
23
24        Charset::ISOAdobe => println!("ISOAdobe"),
25        Charset::Expert => println!("Expert"),
26        Charset::ExpertSubset => println!("ExpertSubset"),
27        Charset::Format0(ref array) => {
28            println!("Format0:");
29            for sid in array.clone() {
30                println!("  {:?}", string_by_id(&table, sid));
31            }
32        }
33        Charset::Format1(ref array) => {
34            println!("Format1:");
35            for range in array.clone() {
36                let sid = range.first;
37                let count = range.left;
38                println!("  {:?} {:?}", sid, count);
39                for i in 0..=count {
40                    println!("    {:?}", string_by_id(&table, StringId(sid.0 + u16::from(i))));
41                }
42            }
43        }
44        Charset::Format2(ref array) => {
45            println!("Format2:");
46            for range in array.clone() {
47                let sid = range.first;
48                let count = range.left;
49                println!("  {:?} {:?}", sid, count);
50                for i in 0..=count {
51                    println!("    {:?}", string_by_id(&table, StringId(sid.0 + i)));
52                }
53            }
54        }
55    }
56    println!("encoding:");
57    match table.encoding.kind {
58        cff_parser::EncodingKind::Standard => println!("Standard"),
59        cff_parser::EncodingKind::Expert => println!("Expert"),
60        cff_parser::EncodingKind::Format0(ref array) => {
61            println!("Format0:");
62            for code in array.clone() {
63                println!("  {:?}", code);
64            }
65        }
66        cff_parser::EncodingKind::Format1(ref array) => {
67            println!("Format1:");
68            for range in array.clone() {
69                println!("  {:?} {:?}", range.first, range.left);
70            }
71        }
72    }
73}
Source

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

Examples found in repository?
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.read_to_end(&mut buffer).expect("could not read file");
13    let table = Table::parse(&buffer).unwrap();
14    dbg!(&table);
15    println!("full name: {:?}", table.full_name());
16    println!("family name: {:?}", table.family_name());
17    println!("version: {:?}", table.version());
18    println!("notice: {:?}", table.notice());
19    println!("number of glyphs: {:?}", table.number_of_glyphs());
20
21    println!("charset:");
22    match table.charset {
23
24        Charset::ISOAdobe => println!("ISOAdobe"),
25        Charset::Expert => println!("Expert"),
26        Charset::ExpertSubset => println!("ExpertSubset"),
27        Charset::Format0(ref array) => {
28            println!("Format0:");
29            for sid in array.clone() {
30                println!("  {:?}", string_by_id(&table, sid));
31            }
32        }
33        Charset::Format1(ref array) => {
34            println!("Format1:");
35            for range in array.clone() {
36                let sid = range.first;
37                let count = range.left;
38                println!("  {:?} {:?}", sid, count);
39                for i in 0..=count {
40                    println!("    {:?}", string_by_id(&table, StringId(sid.0 + u16::from(i))));
41                }
42            }
43        }
44        Charset::Format2(ref array) => {
45            println!("Format2:");
46            for range in array.clone() {
47                let sid = range.first;
48                let count = range.left;
49                println!("  {:?} {:?}", sid, count);
50                for i in 0..=count {
51                    println!("    {:?}", string_by_id(&table, StringId(sid.0 + i)));
52                }
53            }
54        }
55    }
56    println!("encoding:");
57    match table.encoding.kind {
58        cff_parser::EncodingKind::Standard => println!("Standard"),
59        cff_parser::EncodingKind::Expert => println!("Expert"),
60        cff_parser::EncodingKind::Format0(ref array) => {
61            println!("Format0:");
62            for code in array.clone() {
63                println!("  {:?}", code);
64            }
65        }
66        cff_parser::EncodingKind::Format1(ref array) => {
67            println!("Format1:");
68            for range in array.clone() {
69                println!("  {:?} {:?}", range.first, range.left);
70            }
71        }
72    }
73}
Source

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

Examples found in repository?
examples/dump.rs (line 16)
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.read_to_end(&mut buffer).expect("could not read file");
13    let table = Table::parse(&buffer).unwrap();
14    dbg!(&table);
15    println!("full name: {:?}", table.full_name());
16    println!("family name: {:?}", table.family_name());
17    println!("version: {:?}", table.version());
18    println!("notice: {:?}", table.notice());
19    println!("number of glyphs: {:?}", table.number_of_glyphs());
20
21    println!("charset:");
22    match table.charset {
23
24        Charset::ISOAdobe => println!("ISOAdobe"),
25        Charset::Expert => println!("Expert"),
26        Charset::ExpertSubset => println!("ExpertSubset"),
27        Charset::Format0(ref array) => {
28            println!("Format0:");
29            for sid in array.clone() {
30                println!("  {:?}", string_by_id(&table, sid));
31            }
32        }
33        Charset::Format1(ref array) => {
34            println!("Format1:");
35            for range in array.clone() {
36                let sid = range.first;
37                let count = range.left;
38                println!("  {:?} {:?}", sid, count);
39                for i in 0..=count {
40                    println!("    {:?}", string_by_id(&table, StringId(sid.0 + u16::from(i))));
41                }
42            }
43        }
44        Charset::Format2(ref array) => {
45            println!("Format2:");
46            for range in array.clone() {
47                let sid = range.first;
48                let count = range.left;
49                println!("  {:?} {:?}", sid, count);
50                for i in 0..=count {
51                    println!("    {:?}", string_by_id(&table, StringId(sid.0 + i)));
52                }
53            }
54        }
55    }
56    println!("encoding:");
57    match table.encoding.kind {
58        cff_parser::EncodingKind::Standard => println!("Standard"),
59        cff_parser::EncodingKind::Expert => println!("Expert"),
60        cff_parser::EncodingKind::Format0(ref array) => {
61            println!("Format0:");
62            for code in array.clone() {
63                println!("  {:?}", code);
64            }
65        }
66        cff_parser::EncodingKind::Format1(ref array) => {
67            println!("Format1:");
68            for range in array.clone() {
69                println!("  {:?} {:?}", range.first, range.left);
70            }
71        }
72    }
73}

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

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

Performs copy-assignment from source. Read more
Source§

impl Debug for Table<'_>

Source§

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

Formats the value using the given formatter. Read more
Source§

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

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