1a)
Is there a way to access the dimensions (ascender, cap-height, x-height, descender) in the font info by scripting?
1b) And how to print (=access) the set upm?
Unfortunately I have to admit that the documentation feels kind of incomplete in many cases. just to call one example: I was pretty excited to see that there is the »leftMetricsKey«. Which might be used (as written there) to sync it to another glyph, using it’s unicode. Still I could not find out how to actually apply this in a script. I tried to find out with this:
The values are stored in the masters:
font.masters[0].ascender = 720
The leftMetricsKey is what you can see in the glyph info box in the LSB and RSB field. The documentation says "unicode" because that is how python calls some its string objects. It has nothing to do with the unicode of the glyphs. You can put in stuff like "=|n".
The dir command simply lists all methods that this object supports. And in this case this are the methods of the “unicode” string.
Thank you for the quick reply. will try to apply that.
Now I got it. As a resume for reference (correct me if wrong):
font = Glyphs.font
Layer = Glyphs.font.selectedLayers[0]
master = font.masters[0]
s = font.upm
a = master.ascender
x = master.xHeight
d = master.descender
angle = font.masters[0].italicAngle
print "upm is:", s
print "ascender is:", a
print "xHeight is:", x
print "descender is:", d
print "angle is:", angle
I added a script to my GitHub. It will set the dimensions according to proportion values. You can type for instance 4.5 : 10 : 4, which is much more of a imaginable proportion and you don’t need to bother with numbers like 513, 786, … and check if it is still your upm in total. Works with whatever upm you have your font set to.
Feel free to contact me for improvements. I left the Cap height out on purpose for now.
i know about the docu.glyphapp.com. this is what i was actually talking about, that it in some cases feels a bit incomplete. like i mentioned in the example of the leftMetricsKey, where it is hard to find out how exactly to apply it in the code. you know what i mean?
that would be super nice. maybe it’s mainly because lacks in my knowledge. even though i learned some python recently, i find it hard to make connections to how achieve certain things. so i am not sure if it is rather my fault. let’s try an actual example:
I am trying now to set the Alignment Zones via a script. so i go to the documentation, search for the alignment zones and find:
alignmentZones
Collection of GSAlignmentZone.
Type : list
so far so good. maybe i should find out better, what a »collection« actually is (my turn). i see that it belongs to the GSFontMaster and my first next step is to find out, how to access it:
print GSAlignmentZone
>>> <objective-c class GSAlignmentZone at 0x10030ca58>
now i wrote:
font = Glyphs.currentDocument.font
zone = font.masters[0].alignmentZones
print zone
>>> (
>>> "GSAlignmentZone <0x608000850050>: (null) p:0 s:20"
>>> )
nice! my test zone is shown. succsess. but now i want to edit it, i know from the documentation, it’s a list so i try:
font.masters[0].alignmentZones = [40, 50]
which gives an error. and here i am stuck. how do i know how to assign the desired values to the zones? i can imagine, that it might be a list of all the values in order. position, height, position, height, etc., right?
you guys are (of course) so well into programming, that you under circumstances might not see where less advanced users might not be able to make the connections. this is by no means meant offensive i am still learning in small steps, so all this not-understanding can be just my own stupidness. then i am sorry for that.
oh, btw: the las line of code, that gives me the error, also makes it impossible to add an alignment zone manually in the font info. clicking on the plus doesn’t do anything until i close the font file and open a new one …
edit: in the meantime i got my alignment zones script working with the help of a python pro. we used the help() function and googling for the most things. he agreed that the documentation is nice for advanced programmers.
Apparently, the GSAlignmentZone() wrapper is not fully implemented yet. The first line should read just:
AZ = GSAlignmentZone()
… but that doesn’t work yet. Also, the view in font info does not update immediately. (Georg: I tried it with callAfter from PyObjCTools.AppHelper, but it would still only update as soon as I pressed one of the Alignment Zone buttons in the UI.)
that’s interesting! we found out the same stuff with alloc().init(). and i had also the problem of non updating font info until i added another zone there. so i put the font.enableUpdateInterface() in there.
The script looks fine.
I had a look why the alignment zones would not update and there are two problems. First is the wrapper is not 100% correct. But fixing this lead to a crash when you add an zone as the update is generated from a background thread and this is not supported by AppKit). So I need to fix the FontMaster properties in a thread save manner…
ran into another bug of the font info. since it might be some updating font issue, i post it here:
when you edit your dimensions in the font info (x-Height & Co) by typing numbers, all is fine. But if you use the (shift) cursors up or down for in- / decreasing the values and close the font info, nothing happens.
Now I am generating a PDF using CoreGraphics. Everything works well, but I cannot get the given Alignment Zones of the font (for drawing them as well). I’d like to iterate over them and get the positions and sizes, how does this work, please?