SOLVED Glyph.newLayer() no longer working in RF3.3?
nowell last edited by gferreira
I wrote a simple script that adds/replaces a glyph’s background image. It gives the user the option to always add the image to a specific layer (ex: an
'images'layer), so even if you’re editing the
foregroundlayer, the script will insert the image into the
'images'layer. The challenge is with new, empty glyphs that have never had anything added to the
'images'layer... the layer must be created for that glyph before an image can be added to it.
In earlier versions of Robofont (before 3.3), the following line of code worked perfectly.
CurrentGlyph().newLayer( 'images' ) # add image to that layer...
But as of RF 3.3, this doesn’t work. And I haven’t been able to find or think of a reliable alternative. @frederik and @guidoferreyra, has the
newLayer()function been deprecated or moved? Do you have any suggestions?
when you say it doesn’t work in RF 3.3 – what happens exactly? do you get an error message?
as far as I can tell, everything is working fine:
imgPath = 'path/to/image.png' f = NewFont() g = f.newGlyph('a') gLayer = g.newLayer('images') gLayer.addImage(imgPath)
The challenge is with new, empty glyphs that have never had anything added to the 'images' layer... the layer must be created for that glyph before an image can be added to it.
in RF3 layers are at the font level, so if you have already created a layer while working on a glyph, you don’t need to create it again – just ask it for a glyph with
hope this helps!
nowell last edited by
Hi @gferreira, thank you so much! I’ve adapted my script to use this approach, and was able to remove a ton of code. It’s also great to know that I can run
g.newLayer()without potentially losing the existing contents of that layer.
I’ve noticed a side effect, however—or at least an issue that wasn’t present before: One of the nice things about the script is that it can, for example, add an image to a layer named 'images' even if you’re currently working in the 'foreground' layer. This works, but now I can’t undo the action unless I go to the 'images' layer. I’ve tried running
gLayer, and even the
CurrentFont()variables, but undo still doesn’t work unless I switch to the 'images' layer. I can’t seem to figure this out... previously I was able to call those two undo functions on the
CurrentGlyph(), and it worked without needing to switch to the 'images' layer. Is this possible?
Could you explain why
glyph.newLayer(..)is not working for you? see the fontParts documentation.
Is there a traceback? This should work...
In RoboFont each glyph has his own undo manager and its always possible to add an other glyph undo item to a different undo manager, but requires some deep hacking. I dont think the solution is there...
This behaviour was indeed different in RF1 as layers where stored in the glyph.lib, this was a tiny hack on the UFO specification. UFO3 has own implementation of layers.
From a UX perspective this is not a good plan to have undos on different data (glyphs) sets at once.
Hope this makes sense...