Embedding data from custom GlyphData.xml in .glyphs file

Hi!
I’m giving designers the following script:

# MenuTitle: Embed Glyph Metadata in Current Font

"""Embeds production name, category and sub category into each glyph of the current font."""

import logging

for glyph in Glyphs.font.glyphs:
    info = Glyphs.glyphInfoForName(glyph.name)
    if info is None:
        logging.warning("No info for %s", glyph.name)
        continue
    if info.productionName is not None:
        glyph.storeProductionName = True
        glyph.productionName = info.productionName
    if info.category is not None:
        glyph.storeCategory = True
        glyph.category = info.category
    if info.subCategory is not None:
        glyph.storeSubCategory = True
        glyph.subCategory = info.subCategory

What do I need to do if designers have a custom GlyphData.xml? Is it picked up automatically?

I think the script could be simplified quite a bit. And then made more complicated.

The glyphs should have the info from the GlyphData assigned already. So you only need to set the .storeXX properties.

If you have installed the GlyphData next to the .glyphs file and not in the Info folder in Application Support, you can differentiate between the two settings and only set the .storeXX properties if the values are different.

I’m baking stuff into the files verbatim so that glyphs2ufo can generate the correct GDEF/public.openTypeCategories information without having to consult the incomplete glyphsLib glyphdata implementation. Do I only need the store* stuff? And putting the XML file next to the source files will make the script do what I want?

If you just like to bake in the default info (I thought you had a custom data file), you only need to set the .storeXx properties.

But it would be better to fix the info stuff in glyphsLib. An I saw several fixed just a few days ago.

I do have a custom GlyphData file and I want to bake in its data or if not available for a glyph, the default data. (to clarify: if the GlyphData file has an entry for a glyph, use it, otherwise use the default data)

But it would be better to fix the info stuff in glyphsLib. An I saw several fixed just a few days ago.

Yes, one day…

If you can see your custom glyph data in the glyphs that should have it, then all you need to do is to set the “.storeXX” properties.

So, like this?

Yes.

1 Like