diff --git a/src/interjector.rs b/src/interjector.rs index bf26dd5d..e5c51920 100644 --- a/src/interjector.rs +++ b/src/interjector.rs @@ -20,7 +20,7 @@ impl Interjector<'_> { pub(crate) mod skrifa { use crate::{MaxpData, Tag}; use kurbo::{BezPath, CubicBez}; - use skrifa::instance::Location; + use skrifa::instance::{Location, LocationRef}; use skrifa::outline::{DrawSettings, OutlinePen}; use skrifa::prelude::Size; use skrifa::{FontRef, GlyphId, MetadataProvider}; @@ -45,6 +45,10 @@ pub(crate) mod skrifa { Some(Self { font_ref, location }) } + + pub(crate) fn is_default_location(&self) -> bool { + LocationRef::from(&self.location).is_default() + } } impl<'a> SkrifaInterjector<'a> { diff --git a/src/lib.rs b/src/lib.rs index 4fe6964d..cfa473e1 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -173,26 +173,25 @@ fn prepare_context<'a>( #[cfg(not(feature = "variable-fonts"))] let interjector = Interjector::Dummy(PhantomData); // For CFF, we _always_ want to do normal subsetting, since CFF cannot have variations. - // For TrueType, we prefer normal subsetting in case no variation was requested. If we do have - // variations, we use `skrifa` to instance. + // For TrueType, we prefer normal subsetting in case the requested variation coordinates + // resolve to the default location. If we do have variations, we use `skrifa` to instance. // For CFF2, we _always_ use `skrifa` to instance. #[cfg(feature = "variable-fonts")] - let interjector = if (variation_coordinates.is_empty() - && flavor == FontFlavor::TrueType) - || flavor == FontFlavor::Cff - { - // For TrueType and CFF, we are still best off using the normal subsetting logic in case no variation coordinates - // have been passed. + let interjector = if flavor == FontFlavor::Cff { Interjector::Dummy(PhantomData) } else { - Interjector::Skrifa( - interjector::skrifa::SkrifaInterjector::new( - data, - index, - variation_coordinates, - ) - .ok_or(MalformedFont)?, + let interjector = interjector::skrifa::SkrifaInterjector::new( + data, + index, + variation_coordinates, ) + .ok_or(MalformedFont)?; + + if flavor == FontFlavor::TrueType && interjector.is_default_location() { + Interjector::Dummy(PhantomData) + } else { + Interjector::Skrifa(interjector) + } }; Ok(Context { diff --git a/tests/ttx/NotoSans-Regular_var_1.ttx b/tests/ttx/NotoSans-Regular_var_1.ttx index fc2d52ae..82f06b82 100644 --- a/tests/ttx/NotoSans-Regular_var_1.ttx +++ b/tests/ttx/NotoSans-Regular_var_1.ttx @@ -23,7 +23,7 @@ - + @@ -64,10 +64,10 @@ - - - - + + + + @@ -75,7 +75,7 @@ - + @@ -160,114 +160,13 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + @@ -392,161 +291,18 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + +