#[allow(unused_imports)]
use crate::codegen_prelude::*;
pub use read_fonts::tables::head::MacStyle;
impl FontWrite for MacStyle {
fn write_into(&self, writer: &mut TableWriter) {
writer.write_slice(&self.bits().to_be_bytes())
}
}
#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct Head {
pub font_revision: Fixed,
pub checksum_adjustment: u32,
pub magic_number: u32,
pub flags: u16,
pub units_per_em: u16,
pub created: LongDateTime,
pub modified: LongDateTime,
pub x_min: i16,
pub y_min: i16,
pub x_max: i16,
pub y_max: i16,
pub mac_style: MacStyle,
pub lowest_rec_ppem: u16,
pub font_direction_hint: i16,
pub index_to_loc_format: i16,
}
impl Default for Head {
fn default() -> Self {
Self {
font_revision: Default::default(),
checksum_adjustment: Default::default(),
magic_number: 0x5F0F3CF5,
flags: Default::default(),
units_per_em: Default::default(),
created: Default::default(),
modified: Default::default(),
x_min: Default::default(),
y_min: Default::default(),
x_max: Default::default(),
y_max: Default::default(),
mac_style: Default::default(),
lowest_rec_ppem: Default::default(),
font_direction_hint: 2,
index_to_loc_format: Default::default(),
}
}
}
impl Head {
#[allow(clippy::too_many_arguments)]
pub fn new(
font_revision: Fixed,
checksum_adjustment: u32,
flags: u16,
units_per_em: u16,
created: LongDateTime,
modified: LongDateTime,
x_min: i16,
y_min: i16,
x_max: i16,
y_max: i16,
mac_style: MacStyle,
lowest_rec_ppem: u16,
index_to_loc_format: i16,
) -> Self {
Self {
font_revision,
checksum_adjustment,
flags,
units_per_em,
created,
modified,
x_min,
y_min,
x_max,
y_max,
mac_style,
lowest_rec_ppem,
index_to_loc_format,
..Default::default()
}
}
}
impl FontWrite for Head {
#[allow(clippy::unnecessary_cast)]
fn write_into(&self, writer: &mut TableWriter) {
(MajorMinor::VERSION_1_0 as MajorMinor).write_into(writer);
self.font_revision.write_into(writer);
self.checksum_adjustment.write_into(writer);
self.magic_number.write_into(writer);
self.flags.write_into(writer);
self.units_per_em.write_into(writer);
self.created.write_into(writer);
self.modified.write_into(writer);
self.x_min.write_into(writer);
self.y_min.write_into(writer);
self.x_max.write_into(writer);
self.y_max.write_into(writer);
self.mac_style.write_into(writer);
self.lowest_rec_ppem.write_into(writer);
self.font_direction_hint.write_into(writer);
self.index_to_loc_format.write_into(writer);
(0 as i16).write_into(writer);
}
fn table_type(&self) -> TableType {
TableType::TopLevel(Head::TAG)
}
}
impl Validate for Head {
fn validate_impl(&self, _ctx: &mut ValidationCtx) {}
}
impl TopLevelTable for Head {
const TAG: Tag = Tag::new(b"head");
}
impl<'a> FromObjRef<read_fonts::tables::head::Head<'a>> for Head {
fn from_obj_ref(obj: &read_fonts::tables::head::Head<'a>, _: FontData) -> Self {
Head {
font_revision: obj.font_revision(),
checksum_adjustment: obj.checksum_adjustment(),
magic_number: obj.magic_number(),
flags: obj.flags(),
units_per_em: obj.units_per_em(),
created: obj.created(),
modified: obj.modified(),
x_min: obj.x_min(),
y_min: obj.y_min(),
x_max: obj.x_max(),
y_max: obj.y_max(),
mac_style: obj.mac_style(),
lowest_rec_ppem: obj.lowest_rec_ppem(),
font_direction_hint: obj.font_direction_hint(),
index_to_loc_format: obj.index_to_loc_format(),
}
}
}
impl<'a> FromTableRef<read_fonts::tables::head::Head<'a>> for Head {}
impl<'a> FontRead<'a> for Head {
fn read(data: FontData<'a>) -> Result<Self, ReadError> {
<read_fonts::tables::head::Head as FontRead>::read(data).map(|x| x.to_owned_table())
}
}