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?
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 charset = table.charset.get_table();
15 let encoding = table.encoding.get_table();
16 for i in 0..encoding.len() {
17 let cid = encoding[i];
18 let sid = charset[i];
19 println!("{}: {:?}", cid, string_by_id(&table, sid));
20 }
21
22}
More 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 match table.charset {
16
17 Charset::ISOAdobe => println!("ISOAdobe"),
18 Charset::Expert => println!("Expert"),
19 Charset::ExpertSubset => println!("ExpertSubset"),
20 Charset::Format0(ref array) => {
21 println!("Format0:");
22 for sid in array.clone() {
23 println!(" {:?}", string_by_id(&table, sid));
24 }
25 }
26 Charset::Format1(ref array) => {
27 println!("Format1:");
28 for range in array.clone() {
29 let sid = range.first;
30 println!(" {:?}", string_by_id(&table, sid));
31 }
32 }
33 Charset::Format2(ref array) => {
34 println!("Format2:");
35 for range in array.clone() {
36 let sid = range.first;
37 println!(" {:?}", string_by_id(&table, sid));
38 }
39 }
40 }
41 match table.encoding.kind {
42 cff_parser::EncodingKind::Standard => println!("Standard"),
43 cff_parser::EncodingKind::Expert => println!("Expert"),
44 cff_parser::EncodingKind::Format0(ref array) => {
45 println!("Format0:");
46 for code in array.clone() {
47 println!(" {:?}", code);
48 }
49 }
50 cff_parser::EncodingKind::Format1(ref array) => {
51 println!("Format1:");
52 for range in array.clone() {
53 println!(" {:?} {:?}", range.first, range.left);
54 }
55 }
56 }
57}
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.
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_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 glyph_name(&self, glyph_id: GlyphId) -> Option<&'a str>
pub fn glyph_name(&self, glyph_id: GlyphId) -> Option<&'a str>
Returns a glyph name.
Trait Implementations§
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more