Skip to main content

ttf_rs/tables/
post.rs

1use crate::error::Result;
2use crate::stream::FontReader;
3use crate::tables::TtfTable;
4
5/// POST table - PostScript information
6#[derive(Debug, Clone)]
7pub struct PostTable {
8    pub format: f32,
9    pub italic_angle: f32,
10    pub underline_position: i16,
11    pub underline_thickness: i16,
12    pub is_fixed_pitch: u32,
13    pub min_mem_type42: u32,
14    pub max_mem_type42: u32,
15    pub min_mem_type1: u32,
16    pub max_mem_type1: u32,
17}
18
19impl PostTable {
20    pub const VERSION_1_0: f32 = 1.0;
21    pub const VERSION_2_0: f32 = 2.0;
22    pub const VERSION_3_0: f32 = 3.0;
23    pub const VERSION_4_0: f32 = 4.0;
24}
25
26impl TtfTable for PostTable {
27    fn from_reader(reader: &mut FontReader, length: u32) -> Result<Self> {
28        let format = reader.read_fixed()?;
29        let italic_angle = reader.read_fixed()?;
30        let underline_position = reader.read_i16()?;
31        let underline_thickness = reader.read_i16()?;
32        let is_fixed_pitch = reader.read_u32()?;
33        let min_mem_type42 = reader.read_u32()?;
34        let max_mem_type42 = reader.read_u32()?;
35        let min_mem_type1 = reader.read_u32()?;
36        let max_mem_type1 = reader.read_u32()?;
37
38        // Additional fields for format 2.0 and 3.0 would be read here
39        // For simplicity, we skip them in this basic implementation
40
41        let bytes_read = reader.position();
42        if bytes_read < length as usize {
43            reader.skip(length as usize - bytes_read)?;
44        }
45
46        Ok(PostTable {
47            format,
48            italic_angle,
49            underline_position,
50            underline_thickness,
51            is_fixed_pitch,
52            min_mem_type42,
53            max_mem_type42,
54            min_mem_type1,
55            max_mem_type1,
56        })
57    }
58}