diff --git a/fontc/src/args.rs b/fontc/src/args.rs index 5fdf87395..c30f66c32 100644 --- a/fontc/src/args.rs +++ b/fontc/src/args.rs @@ -21,12 +21,15 @@ pub struct Args { #[arg(long, default_value = "false")] pub emit_debug: bool, - /// Whether to Try Hard(tm) to match fontmake (Python) behavior in cases where there are other options. - /// - /// See for an example of - /// where this matters. + /// In cases where a source glyph uses a mixture of components and contours, convert + /// all the components to contours. #[arg(long, default_value = "true")] - pub match_legacy: bool, + pub prefer_simple_glyphs: bool, + + /// Eliminate component references to other glyphs using components, emitting only + /// component references to simple (contour) glyphs. + #[arg(long, default_value = "true")] + pub flatten_components: bool, /// Working directory for the build process. If emit-ir is on, written here. #[arg(short, long, default_value = "build")] @@ -44,7 +47,8 @@ impl Args { flags.set(Flags::EMIT_IR, self.emit_ir); flags.set(Flags::EMIT_DEBUG, self.emit_debug); - flags.set(Flags::MATCH_LEGACY, self.match_legacy); + flags.set(Flags::PREFER_SIMPLE_GLYPHS, self.prefer_simple_glyphs); + flags.set(Flags::FLATTEN_COMPONENTS, self.flatten_components); flags } @@ -65,7 +69,8 @@ impl Args { emit_ir: true, emit_debug: false, build_dir: build_dir.to_path_buf(), - match_legacy: true, + prefer_simple_glyphs: Flags::default().contains(Flags::PREFER_SIMPLE_GLYPHS), + flatten_components: Flags::default().contains(Flags::FLATTEN_COMPONENTS), } } } diff --git a/fontc/src/lib.rs b/fontc/src/lib.rs index 9a5c8681f..957f4b129 100644 --- a/fontc/src/lib.rs +++ b/fontc/src/lib.rs @@ -1006,11 +1006,14 @@ mod tests { assert!(feature_ttf.is_file(), "Should have written {feature_ttf:?}"); } - fn build_contour_and_composite_glyph(temp_dir: &TempDir, match_legacy: bool) -> ir::Glyph { + fn build_contour_and_composite_glyph( + temp_dir: &TempDir, + prefer_simple_glyphs: bool, + ) -> ir::Glyph { let build_dir = temp_dir.path(); let mut args = Args::for_test(build_dir, "glyphs2/MixedContourComponent.glyphs"); - args.match_legacy = match_legacy; // <-- important :) + args.prefer_simple_glyphs = prefer_simple_glyphs; // <-- important :) let result = compile(args); let glyph = result diff --git a/fontir/src/glyph.rs b/fontir/src/glyph.rs index 4a5ccbf6a..7c3e1821e 100644 --- a/fontir/src/glyph.rs +++ b/fontir/src/glyph.rs @@ -300,7 +300,8 @@ impl Work for FinalizeStaticMetadataWork { !has_consistent_2x2_transforms || has_components_and_contours(glyph) }) { - if !has_consistent_2x2_transforms || context.flags.contains(Flags::MATCH_LEGACY) { + if !has_consistent_2x2_transforms || context.flags.contains(Flags::PREFER_SIMPLE_GLYPHS) + { if !has_consistent_2x2_transforms { debug!( "Coalescing'{0}' into a simple glyph because component 2x2s vary across the designspace", diff --git a/fontir/src/orchestration.rs b/fontir/src/orchestration.rs index f05eaebd1..4b4e18d41 100644 --- a/fontir/src/orchestration.rs +++ b/fontir/src/orchestration.rs @@ -26,8 +26,11 @@ bitflags! { const EMIT_IR = 0b00000001; // If set additional debug files will be emitted to disk const EMIT_DEBUG = 0b00000010; - // If set seek to match fontmake (python) behavior even at cost of abandoning optimizations - const MATCH_LEGACY = 0b00000100; + // If set, a glyph with contours and components will be converted to a simple (contour) glyph + const PREFER_SIMPLE_GLYPHS = 0b00000100; + // If set, a composite that references another composite will replace that composite with the + // glyph(s) it references until only simple (contour) glyphs are referenced + const FLATTEN_COMPONENTS = 0b00001000; } } @@ -69,8 +72,9 @@ macro_rules! context_accessors { } impl Default for Flags { + /// Match the way gftools configures fontmake by default fn default() -> Self { - Flags::MATCH_LEGACY + Flags::PREFER_SIMPLE_GLYPHS | Flags::FLATTEN_COMPONENTS } }