Skip to content

Commit

Permalink
decompose transformed components before flattening nested components
Browse files Browse the repository at this point in the history
Fixes #947

The failing test from the previous commit should now pass
  • Loading branch information
anthrotype committed Sep 6, 2024
1 parent 2debbe1 commit a5b7ea4
Showing 1 changed file with 19 additions and 9 deletions.
28 changes: 19 additions & 9 deletions fontir/src/glyph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -298,29 +298,39 @@ fn flatten_glyph(context: &Context, glyph: &Glyph) -> Result<(), BadGlyph> {
Ok(())
}

/// Run some optional transformations on the glyphs listed.
///
/// This includes decomposing components with non-identity 2x2 transforms
/// and flattening nested composite glyphs so that they all have depth 1
/// (no components that reference components).
fn apply_optional_transformations(
context: &Context,
new_glyph_order: &GlyphOrder,
glyph_order: &GlyphOrder,
) -> Result<(), BadGlyph> {
if context.flags.contains(Flags::FLATTEN_COMPONENTS) {
for glyph_name in new_glyph_order.iter() {
let glyph = context.glyphs.get(&WorkId::Glyph(glyph_name.clone()));
flatten_glyph(context, &glyph)?;
}
}

// If both --flatten-components and --decompose-transformed-components flags
// are set, we want to decompose any transformed components first and *then*
// flatten the rest. That's how fontmake (ufo2ft) does, and also tends to
// keep more components, which usually means smaller glyf size.
// https://github.com/googlefonts/fontc/issues/929
if context
.flags
.contains(Flags::DECOMPOSE_TRANSFORMED_COMPONENTS)
{
for glyph_name in new_glyph_order.iter() {
for glyph_name in glyph_order.iter() {
let glyph = context.glyphs.get(&WorkId::Glyph(glyph_name.clone()));
if glyph.has_nonidentity_2x2() {
convert_components_to_contours(context, &glyph)?;
}
}
}

if context.flags.contains(Flags::FLATTEN_COMPONENTS) {
for glyph_name in glyph_order.iter() {
let glyph = context.glyphs.get(&WorkId::Glyph(glyph_name.clone()));
flatten_glyph(context, &glyph)?;
}
}

Ok(())
}

Expand Down

0 comments on commit a5b7ea4

Please sign in to comment.