add font header table
This commit is contained in:
parent
a11df167de
commit
d77396a6ec
src
|
@ -1,12 +1,14 @@
|
|||
mod table_directory;
|
||||
mod character_map;
|
||||
mod maximum_profile;
|
||||
mod font_header;
|
||||
mod search;
|
||||
|
||||
use std::{fs::File, io::{BufReader, Read}};
|
||||
|
||||
use bincode::Options;
|
||||
use character_map::CharacterMap;
|
||||
use font_header::FontHeader;
|
||||
use log::{debug, info};
|
||||
use maximum_profile::MaximumProfile;
|
||||
use table_directory::TableDirectory;
|
||||
|
@ -18,6 +20,7 @@ fn deserialize<R: Read, T: serde::de::DeserializeOwned>(reader: R) -> bincode::R
|
|||
#[derive(Debug)]
|
||||
pub struct Font {
|
||||
table_directory: TableDirectory,
|
||||
font_header: FontHeader,
|
||||
character_map: CharacterMap,
|
||||
maximum_profile: MaximumProfile
|
||||
}
|
||||
|
@ -27,6 +30,9 @@ impl Font {
|
|||
let mut buf_reader = BufReader::new(file.try_clone()?);
|
||||
let table_directory = TableDirectory::new(&mut buf_reader)?;
|
||||
|
||||
let font_header = table_directory.get_table(&file)?;
|
||||
debug!("{font_header:#?}");
|
||||
|
||||
let character_map = table_directory.get_table(&file)?;
|
||||
debug!("{character_map:#?}");
|
||||
|
||||
|
@ -35,6 +41,7 @@ impl Font {
|
|||
|
||||
Ok(Font {
|
||||
table_directory,
|
||||
font_header,
|
||||
character_map,
|
||||
maximum_profile
|
||||
})
|
||||
|
|
62
src/font/font_header.rs
Normal file
62
src/font/font_header.rs
Normal file
|
@ -0,0 +1,62 @@
|
|||
use std::{fs::File, io::BufReader};
|
||||
|
||||
use log::warn;
|
||||
use serde::Deserialize;
|
||||
|
||||
use super::{deserialize, table_directory::{FontTable, TableDirectoryRecord}};
|
||||
|
||||
#[derive(Debug, Deserialize, Default)]
|
||||
pub struct Version {
|
||||
major: u16,
|
||||
minor: u16
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
pub struct FontHeader {
|
||||
#[serde(skip)]
|
||||
version: Version,
|
||||
|
||||
#[serde(skip)]
|
||||
font_revision: Version,
|
||||
|
||||
checksum_adjust: u32,
|
||||
magic_number: u32,
|
||||
flags: u16,
|
||||
units_per_em: u16,
|
||||
|
||||
created: i64,
|
||||
modified: i64,
|
||||
|
||||
xmin: i16,
|
||||
ymin: i16,
|
||||
xmax: i16,
|
||||
ymax: i16,
|
||||
|
||||
mac_style: u16,
|
||||
lowest_rec_ppem: u16,
|
||||
|
||||
font_direction_hint: i16,
|
||||
index_to_loc_hint: i16,
|
||||
glyph_data_format: i16
|
||||
}
|
||||
|
||||
impl FontTable for FontHeader {
|
||||
const TAG: &'static str = "head";
|
||||
|
||||
fn decode(reader: BufReader<File>, _: &TableDirectoryRecord) -> bincode::Result<Self>
|
||||
where Self: Sized
|
||||
{
|
||||
let version = deserialize::<_, Version>(reader.get_ref())?;
|
||||
if version.major != 1 && version.minor != 0 {
|
||||
warn!("Font version is not 1.0");
|
||||
}
|
||||
|
||||
let font_revision = deserialize::<_, Version>(reader.get_ref())?;
|
||||
|
||||
let mut font_header: FontHeader = deserialize(reader.get_ref())?;
|
||||
font_header.version = version;
|
||||
font_header.font_revision = font_revision;
|
||||
|
||||
Ok(font_header)
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue