Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support component flattening #268

Merged
merged 5 commits into from
Apr 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,
anthrotype marked this conversation as resolved.
Show resolved Hide resolved
pub prefer_simple_glyphs: bool,
anthrotype marked this conversation as resolved.
Show resolved Hide resolved

/// Eliminate component references to other glyphs using components (that is, nested components),
/// emitting only component references to simple (contour) glyphs.
#[arg(long, default_value = "false")]
pub flatten_components: bool,
rsheeter marked this conversation as resolved.
Show resolved Hide resolved

/// 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),
}
}
}
18 changes: 14 additions & 4 deletions fontc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,14 @@ fn add_finalize_static_metadata_ir_job(
.collect();
dependencies.insert(FeWorkIdentifier::InitStaticMetadata.into());

// Grant write to any glyph including ones we've never seen before so job can create them
// Finalize may create new glyphs so allow read/write to *all* glyphs
let read_access = Access::custom(|an_id: &AnyWorkId| {
matches!(
an_id,
AnyWorkId::Fe(FeWorkIdentifier::Glyph(..))
| AnyWorkId::Fe(FeWorkIdentifier::InitStaticMetadata)
)
});
let write_access = Access::custom(|an_id: &AnyWorkId| {
matches!(
an_id,
Expand All @@ -112,7 +119,7 @@ fn add_finalize_static_metadata_ir_job(
Job {
work: create_finalize_static_metadata_work().into(),
dependencies,
read_access: ReadAccess::Dependencies,
read_access: ReadAccess::Custom(read_access),
write_access,
},
);
Expand Down Expand Up @@ -1006,11 +1013,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
Loading