use integer_or_float::IntegerOrFloat;
#[derive(Constructor, Debug, Default, Copy, Clone, PartialEq, Eq)]
pub struct Pedantry {
pub level: Level,
pub mend: Mend,
}
impl Pedantry {
pub fn should_mend(&self) -> bool {
!(self.level.is_sfnt() && self.mend.is_never())
}
}
#[derive(Derivative, Debug, Copy, Clone, PartialEq, Eq, IsVariant, Unwrap)]
#[derivative(Default)]
pub enum Mend {
#[derivative(Default(new="true"))]
Always,
Never,
UfoSpecErrorsOnly,
UfoSpecOutdatedOnly,
}
#[derive(Derivative, Debug, Copy, Clone, PartialEq, Eq, IsVariant, Unwrap)]
#[derivative(Default)]
pub enum Level {
#[derivative(Default(new="true"))]
GlifParser,
Ufo,
OpenType,
TrueType,
}
#[derive(Debug, Copy, Clone, PartialEq, Eq, IsVariant, Unwrap)]
pub enum FloatClass {
Anchor,
AdvanceWidth
}
impl FloatClass {
fn should_round(&self) -> bool {
*self == FloatClass::Anchor
}
}
impl Level {
pub fn maybe_round(&self, f: IntegerOrFloat, fc: FloatClass) -> f32 {
if self.is_sfnt() && fc.should_round() {
f32::from(f).round()
} else {
f.into()
}
}
pub fn is_sfnt(&self) -> bool {
self.is_open_type() || self.is_true_type()
}
}