Get Glyph by GID

I’m writing a script that outputs an InDesign Tagged Text listing all glyphs using their GID. Besides that, I also need to generate a text file with the names of the glyphs in the same order. Unfortunately, the GID order doesn’t match the Glyphs’ order. Is there a way to get glyph data by it’s GID? —or— Is there a way to reset GID to match Glyphs’ order?

Thank you, Ondrej

There is a small reshuffling going on on export. If you export as OTF, only the .notdef is moved to the first position (or one is added when you don’t have one. When exporting as TTF, also the space, CR and null are moved to the front (if they are present). So you might need to add 1, 2 or 3 to the glyph index to get the right GID.

Great, thank you! I used glyphOrder parameter as Rainer suggested, the manual reorder actually serves my purposes better than relying on the imported order, even though this added a couple of steps to my workflow.
Either way, is GSGlyph’s GID property something that could be added if technologically possible? I think I saw some commenters asking for it as well.

The GID is not a stable number. It depends on several factors. Like what font format you use, and if you have some subletting parameters in the instances.

Ah, I see. However, I suppose the GID changes only when a change is made in the font, but remains still when running a macro on a current state of the glyph list. And that’s exactly when I’d need that.

To describe what I’m after: From imported TTF, I’m generating a PNG image showing all glyphs using GIDs in InDesign TaggedText. Alongside this, I need a TXT file listing all glyph names in the same order (to manipulate the image later). And here’s the problem: when looping through glyphs, the n-th glyph is not the glyph with GID=n. That means it is not possible to correctly match glyphs in the PNG with their names from the TXT.

This would be an ideal solution:

for g in glyphs:
    PNG.append(g.GID)
    TXT.append(g.name)

All in all, I understand that this might be the only scenario when GID is useful… For now, I’m quite OK with the workaround.

You might be better of to use TTX to do the processing. You can even generate the pngs with it.

Or import with “Keep glyph names from imported files” set in Preferences. That way the original glyph order will be preserved and match the GID.

1 Like