TT Instructions — Programmatically?

Hi,

I’m new to Glyphs, so this may be a question that has an obvious answer, but is there a code representation of TrueType instructions that can be compiled in the instructioning process, just as it is possible in FontLab? Maybe a plugin?

Thank you,
Alex :slight_smile:

I found a plugin called “TT Control Instructions Palette” that seems to provide a way to control the TT autohinter, but this seems to be entirely separate from the set of manual instructioning tools. Would that be correct?

Glyphs doesn’t have that list/code for instructions. But you still can add instructions from a script.

instr = GSHint()
instr.type = TTSTEM
instr.originNode = Layer.shapes[0].nodes[1]
instr.targetNode = Layer.shapes[1].nodes[1]
instr.options = TTDONTROUND
Layer.hints.append(instr)
1 Like

Ah, thank you, Georg! That looks nice. I think I will try to come up with a way of translating our existing code into Glyphs’ instructions. :slight_smile:

I’d just have a little follow up question. Is it possible to refer to a node by its name? In my screenshot above, you can see, for instance, that the node which is anchored to the ascender and serves as a reference point for an interpolation has the name “at01”. Using UFO import, I can bring these node names together with my contours to Glyphs.

But what would be the Python code for referring to the point called “at01”? The code snippet you shared, Georg, is index-based, but it would be awesome if I could directly use the node names for identification purposes. :slight_smile:

Oh, I think I would have to loop through all nodes of my contours, retrieve the names, and compare them to the name I’d like to target:

if node.name == “at01”:
    do something

Would there be a more direct way to do it?

That looks about right.

Thank you, Georg! :slight_smile:

One additional question, if you don’t mind. Is it possible to specify in Python code to which alignment zone (to which stem) an anchor (a single link) should refer? I’m aware that Glyphs will find out the zone or stem mostly automatically, but it would be nonetheless great if there was a way to explicitly add the reference.

hint.stem = zoneIndex
# or
hint.stem = -1 # for no stem
# or
hint.stem = -2 # for auto

Thank you. I’ll have a look tomorrow. :slight_smile:

In case anyone else is finding this older thread and trying to set the alignment zone for a hint, you cannot set GSHint.stem directly anymore. It just raises ValueError when you set it to most valid values. Instead you have to use the GSHint.setStem_ method, which takes one parameter that must be double the index of the zone from your TTFZones custom parameter.

So if your TTFZones looks like this:

Then your code can be something like this:

from Foundation import NSNotFound

hint.setStem_(NSNotFound) #Automatic
hint.setStem_(-1) #No zone
hint.setStem_(0) #Ascender 800
hint.setStem_(2) #Cap Height 700
hint.setStem_(4) #Baseline 0
hint.setStem_(6) #Descender -200

If you set odd numbers you will get unpredictable/buggy results (hints disappear, or the label shows a different value than the dropdown).

You can also use the above code if you don’t have the TTFZones or TTFStems custom parameter. Then it just uses the metrics and stems values from your master.

I fixed the hint.stem setter.

That doubling of the index is an unfortunate artifact of the past.

But just to be sure: Where do you use the stem setting?

I was writing a script to change “auto” to whichever vertical metric zone the y-position of the snap hint is located in.

I thought that “auto” should do this automatically and render identically in the pixel preview, but often I was getting better results by setting the correct zone in the dropdown menu. But then I noticed that setting the zone manually was wreaking havoc when I export to VF and test in Windows. The origin point was fine but when I tested other areas of the design space like heavy weights, all my glyphs were distorted in strange ways like this “y”:

image

So then I changed everything back to “auto”, which has been working fine, but strangely is now rendering identically in the pixel preview when I compare with setting the zone manually. Manual TT hinting is quite a learning curve.

Please. DON’T do that. The zone alignment is meant for something completely different. It is meant to keep the distance of that node to the zone. That use mostly used for accents. or occasionally for the lowered bar of “f”.

can you show me some examples?

And what version of Glyphs do you use? I fixed a few issues in the cutting edge version, recently.