Skip to content

Commit

Permalink
Adjust flags to permit toggling flatten
Browse files Browse the repository at this point in the history
  • Loading branch information
rsheeter committed Apr 18, 2023
1 parent ca772e6 commit 9df4b92
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 13 deletions.
19 changes: 12 additions & 7 deletions fontc/src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 <https://github.com/googlefonts/fontmake-rs/pull/123> 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")]
Expand All @@ -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
}
Expand All @@ -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),
}
}
}
7 changes: 5 additions & 2 deletions fontc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion fontir/src/glyph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,8 @@ impl Work<Context, WorkError> 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",
Expand Down
10 changes: 7 additions & 3 deletions fontir/src/orchestration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

Expand Down Expand Up @@ -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
}
}

Expand Down

0 comments on commit 9df4b92

Please sign in to comment.