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

Add FlattenComponentsFilter to flatten nested components #214

Merged
merged 2 commits into from
Feb 19, 2018

Conversation

moyogo
Copy link
Collaborator

@moyogo moyogo commented Feb 5, 2018

This allows to follow Glyphs.app behaviour, but not by default.
One may want direct components instead of nested components because some TrueType implementations don’t handle nested components properly.

unnested = True
index = glyph.componentIndex(comp)
glyph.removeComponent(comp)
for unnested in reversed(unnested_tuples):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this unnested for loop variable is shadowing/redefining the other local variable called unnested a few lines before. Was that intentional?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, no that wasn’t intentional.

index = glyph.componentIndex(comp)
glyph.removeComponent(comp)
for unnested in reversed(unnested_tuples):
base_comp = glyph.instantiateComponent()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe this instantiateComponent method is too specific to defcon's API. I see for example fontParts does not have this.
Does it not work if you insert a generic defcon.Component?

Or maybe wouldn't it be better (more portable) if you used the pen API to draw the components onto the glyph object? That is, you get the pen (or point pen) associated with the glyph and call the addComponent method.

I guess in this case the new "unnested" components will all be drawn at the end of the glyphs.components list, whereas here you're using insertComponent (instead of appendComponent) to try to keep the order?
Not sure it's even worth to keep the order.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd still prefer to use a generic pen.addComponent instead of relying on defcon-specific instantiateComponent and insertComponent methods

@anthrotype
Copy link
Member

I'm thinking whether "flattenComponents" could convey the meaning better than "unnestComponents". Maybe a native english speaker could comment.

@anthrotype
Copy link
Member

a few questions:

  1. Is this glyphs.app behavior that you mentioned the default? Is it controlled by a custom parameter? If so, which one?
  2. I'm curious to know which "TrueType implementations don’t handle nested components properly"

@moyogo
Copy link
Collaborator Author

moyogo commented Feb 19, 2018

I don’t mind using flattenComponents instead of unnestComponents.

  1. Is this glyphs.app behavior that you mentioned the default? Is it controlled by a custom parameter? If so, which one?

I don’t think there any custom parameter to control this. It’s the default in 2.4.4.
@schriftgestalt What will be the behaviour in 2.5? 2.5b (1116) doesn’t seem to decompose nested components.

  1. I'm curious to know which "TrueType implementations don’t handle nested components properly"

Some printers.

@anthrotype
Copy link
Member

yeah, I think I like flattenComponents better.

You know this filter works already if you specify it in the font's lib.plist under com.github.googlei18n.ufo2ft.filters with the name "Unnest Components" and a custom namespace, i.e. the user's package where the unnestComponents.py module can be imported from (e.g. damaTools.filters)?

@anthrotype
Copy link
Member

tests would be nice too

@schriftgestalt
Copy link

The flattening was applied mostly to be able to open the .ttf in FLS. I removed it as is was causing some problems. I didn’t hear about any problems.

@moyogo
Copy link
Collaborator Author

moyogo commented Feb 19, 2018

OK, I renamed things to flattenComponents, FlattenComponentFilter, etc., and added tests.

glyph.removeComponent(comp)
for flattened_tuple in flattened_tuples:
pen = glyph.getPen()
# baseGlyph, transformation = flattened_tuple
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove this line?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK

flattened = True
glyph.removeComponent(comp)
for flattened_tuple in flattened_tuples:
pen = glyph.getPen()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can get the pen outside the for loops, the glyph doesn't change so neither does the pen

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point.

[('a', (1, 0, 0, 1, 0, 0))]
)
assert (
[(a.name, a.x, a.y) for a in font['c'].anchors] ==
Copy link
Member

@anthrotype anthrotype Feb 19, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what's the point of asserting the anchors here? The filter is not supposed to modify these, is it?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK

@moyogo
Copy link
Collaborator Author

moyogo commented Feb 19, 2018

@schriftgestalt Thanks! I guess we don’t want this as default then.

@moyogo
Copy link
Collaborator Author

moyogo commented Feb 19, 2018

@anthrotype Since Glyphs 2.5+ won’t be doing this anymore, should I just remove the argument from the functions and just let users use com.github.googlei18n.ufo2ft.filters then?

Copy link
Member

@anthrotype anthrotype left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks Denis!

@anthrotype
Copy link
Member

should I just remove the argument from the functions and just let users use com.github.googlei18n.ufo2ft.filters then?

hm.. yeah, that was the idea of allowing preprocessor to load custom filters from the font's lib.plist.
I wouldn't like to add another option to fontmake just for this.

@moyogo moyogo changed the title Add option to unnest components Add FlattenComponentsFilter to flatten nested components Feb 19, 2018
@moyogo moyogo merged commit 0cf1aa3 into googlefonts:master Feb 19, 2018
@moyogo moyogo deleted the unnested-components branch February 20, 2018 14:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants