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

Rename backgrounds of layers with the same name #667

Open
wants to merge 9 commits into
base: main
Choose a base branch
from

Conversation

moyogo
Copy link
Collaborator

@moyogo moyogo commented Feb 27, 2021

Same as #570 but for background of layers with the same name.
It fixes #573 and #588.

@moyogo
Copy link
Collaborator Author

moyogo commented Mar 1, 2021

I've updated the PR to store the layerId and the original layer name when there are multiple layers with the same name, and to keep the layer order as well when any layer has a name like "Color 1", fixing both #573 and #588.

if master.id == layer.associatedMasterId:
if layer.name not in layers_by_name:
layers_by_name[layer.name] = []
layers_by_name[layer.name].append(layer)
Copy link
Member

Choose a reason for hiding this comment

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

you could use dict.setdefault or a defaultdict

layer_name = f"{layer.name} #{n!r}"
n += 1
ufo_layer = ufo_font.newLayer(layer_name)
if layer.name != "Color 1":
Copy link
Member

Choose a reason for hiding this comment

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

what's this "Color 1"? A new magic value? Why only 1?

(
l.name
for l in ufo_font.layers
if l.lib.get(LAYER_ID_KEY) == layer.layerId
Copy link
Member

Choose a reason for hiding this comment

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

maybe you could store a map from layerId to layer name in the builder instance instead of finding them like this each time

@anthrotype anthrotype requested a review from madig April 12, 2021 10:21
@arrowtype
Copy link

I’m not quite sure whether this is due to this specific branch, or due to other code, but in a font I’ve use glyphs2ufo on, I’ve wound up with a couple thousand separate layer directories in the UFOs. As a result, the UFOs seem to be basically impossible to open with RoboFont or fontParts fontShell...

Is there a way to prevent the additional layers from being created? I don’t really need them.

If this would be better as a separate issue, please let me know, and I can move this comment.

image

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.

UFO->Glyphs should strip #<digit> suffix from 'Color' layer names
3 participants