Skip to content

Commit 4859fd7

Browse files
committed
Upgrade pedantry for issue #54
1 parent 0935b8e commit 4859fd7

4 files changed

Lines changed: 35 additions & 5 deletions

File tree

src/glif/read.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,11 @@ pub fn read_ufo_glif_pedantic<PD: PointData>(glif: &str, pedantry: Pedantry) ->
102102

103103
match widthc {
104104
Err(e) => if let Ok((f, false)) = width.parse::<f32>().map(|f|(f, f.is_subnormal())) {
105-
log::warn!("Floating point value given as <advance> width — OpenType `hmtx` / `vmtx` will truncate it, so we do too!");
105+
const FLOATPOINTWARNING: &str = "Floating point value given as <advance> width — OpenType `hmtx` / `vmtx` will truncate it";
106+
if !pedantry.should_mend() {
107+
Err(input_error!(FLOATPOINTWARNING))?
108+
}
109+
log::warn!("{}, so we do too!", FLOATPOINTWARNING);
106110
Some(f as u64)
107111
} else {
108112
log::trace!("<advance> parsing as int rose {:?}", e);

src/pedantry.rs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,12 @@ pub struct Pedantry {
88
pub mend: Mend,
99
}
1010

11+
impl Pedantry {
12+
pub fn should_mend(&self) -> bool {
13+
!(self.level.is_sfnt() && self.mend.is_never())
14+
}
15+
}
16+
1117
#[derive(Derivative, Debug, Copy, Clone, PartialEq, Eq, IsVariant, Unwrap)]
1218
#[derivative(Default)]
1319
pub enum Mend {
@@ -39,14 +45,25 @@ pub enum Level {
3945
#[derive(Debug, Copy, Clone, PartialEq, Eq, IsVariant, Unwrap)]
4046
pub enum FloatClass {
4147
Anchor,
48+
AdvanceWidth
49+
}
50+
51+
impl FloatClass {
52+
fn should_round(&self) -> bool {
53+
*self == FloatClass::Anchor
54+
}
4255
}
4356

4457
impl Level {
4558
pub fn maybe_round(&self, f: IntegerOrFloat, fc: FloatClass) -> f32 {
46-
if (self.is_open_type() || self.is_true_type()) && fc == FloatClass::Anchor {
59+
if self.is_sfnt() && fc.should_round() {
4760
f32::from(f).round()
4861
} else {
4962
f.into()
5063
}
5164
}
65+
66+
pub fn is_sfnt(&self) -> bool {
67+
self.is_open_type() || self.is_true_type()
68+
}
5269
}

tests/bugfixes/issue54.rs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,20 @@
1-
use glifparser;
1+
use super::gp;
2+
use super::GPResult;
23

34
#[super::test]
45
fn test_bug_fixed() {
56
let gliffn = "test_data/bugfixes/issue54.glif";
67
log::trace!("{}", gliffn);
7-
let glif: glifparser::Glif<()> = glifparser::glif::read_from_filename(gliffn).unwrap();
8+
let glif: gp::Glif<()> = gp::glif::read_from_filename(gliffn).unwrap();
9+
assert_eq!(glif.width, Some(1143));
10+
log::trace!("{}", gliffn);
11+
let glif: GPResult = gp::glif::read_from_filename_pedantic(gliffn, gp::Pedantry::new(gp::pedantry::Level::OpenType, gp::pedantry::Mend::Never));
12+
assert!(glif.is_err());
13+
log::trace!("{}", gliffn);
14+
let glif: gp::Glif<()> = gp::glif::read_from_filename_pedantic(gliffn, gp::Pedantry::default()).unwrap();
815
assert_eq!(glif.width, Some(1143));
916
let gliffn = "test_data/bugfixes/Q_.glif";
1017
log::trace!("{}", gliffn);
11-
let glif: Result<glifparser::Glif<()>, glifparser::error::GlifParserError> = glifparser::glif::read_from_filename(gliffn);
18+
let glif: GPResult = gp::glif::read_from_filename(gliffn);
1219
assert!(glif.is_err());
1320
}

tests/bugfixes/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
use test_log::{self, test};
2+
use glifparser as gp;
3+
type GPResult = Result<gp::Glif<()>, gp::error::GlifParserError>;
24

35
mod issue54;

0 commit comments

Comments
 (0)