Skip to content

Commit

Permalink
[read-fonts] feature gate cubic glyf support (#1232)
Browse files Browse the repository at this point in the history
  • Loading branch information
dfrg authored Dec 3, 2024
1 parent aea2fea commit 8bb4a49
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 1 deletion.
3 changes: 3 additions & 0 deletions read-fonts/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ scaler_test = []
# this feature is not stable, but provides untyped traversal of font tables.
# we do not consider this feature public API for the purposes of semver.
experimental_traverse = ["std"]
# Enables experimental implementations of proposed changes to the spec
# as discussed at https://github.com/harfbuzz/boring-expansion-spec
spec_next = []
default = ["std"]
serde = ["dep:serde", "font-types/serde"]
libm = ["dep:core_maths"]
Expand Down
8 changes: 7 additions & 1 deletion read-fonts/src/tables/glyf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,13 @@ impl<'a> SimpleGlyph<'a> {
}
y = y.wrapping_add(delta);
point.y = C::from_i32(y);
*point_flags = PointFlags::from_bits(point_flags.0);
let flags_mask = if cfg!(feature = "spec_next") {
PointFlags::CURVE_MASK
} else {
// Drop the cubic bit if the spec_next feature is not enabled
PointFlags::ON_CURVE
};
point_flags.0 &= flags_mask;
}
Ok(())
}
Expand Down
3 changes: 3 additions & 0 deletions skrifa/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ traversal = ["std", "read-fonts/experimental_traverse"]
# This exists as a feature because shaping support is "best effort" and
# we want the ability to disable it for testing against FreeType.
autohint_shaping = []
# Enables experimental implementations of proposed changes to the spec
# as discussed at https://github.com/harfbuzz/boring-expansion-spec
spec_next = ["read-fonts/spec_next"]
libm = ["dep:core_maths", "read-fonts/libm"]

[dependencies]
Expand Down
2 changes: 2 additions & 0 deletions skrifa/src/outline/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1349,9 +1349,11 @@ mod tests {
);
}

#[cfg(feature = "spec_next")]
const CUBIC_GLYPH: GlyphId = GlyphId::new(2);

#[test]
#[cfg(feature = "spec_next")]
fn draw_cubic() {
let font = FontRef::new(font_test_data::CUBIC_GLYF).unwrap();
assert_glyph_path_start_with(
Expand Down
1 change: 1 addition & 0 deletions skrifa/src/outline/unscaled.rs
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,7 @@ mod tests {
}

#[test]
#[cfg(feature = "spec_next")]
fn read_cubic_glyf_outline() {
let font = FontRef::new(font_test_data::CUBIC_GLYF).unwrap();
let glyph = font.outline_glyphs().get(GlyphId::new(2)).unwrap();
Expand Down

0 comments on commit 8bb4a49

Please sign in to comment.