SOLVED Unique font ID or temp data
-
I'm writing a script with a persistent window that needs to keep track of which fonts are open. The document open/close/activated event callbacks are working well, but I'd like to have a reliable way to identify each open font. I can't always distinguish between fonts based on their family name, file path (new documents are the same), or their index in the list of
AllFonts(). Does RoboFont assign the font/document a UUID that I could use? Or is there a good alternative?On a related note, I would like to be able to store temporary data in a font object without it being permanently stored in the UFO. Is this possible? The Glyphs API has
tempDataanduserData, but in the RoboFont docs and forum I've only seen mention offont.lib—which is permanent likeuserData. If there isn't a unique ID for each font, I could create my own IDs and store them in each font's temporary data for as long as the document is open. Does RoboFont have something likefont.tempData?
-
sure
<fontPartsObject>.naked()still existsonly the latest has
.asDefcon()and.asFontParts()which is just a lot more readable
-
Thanks @frederik. Is it ok to use
id( CurrentFont().naked() )to maintain RoboFont 3 support?
-
.asDefcon()is a RoboFont 4 attributeAnd see https://github.com/robotools/defcon/pull/367 for an official defcon support
-
Thank you for the code, @frederik! Your
tempLibalternative works well for me. I really appreciate it.The code sample to get the id of a font's defcon object is giving me an error however. (I'm using RF v3.5b)
AttributeError: 'RFont' object has no attribute 'asDefcon'Replacing
.asDefcon()with.naked()appears to work however. I'm not sure if that's safe to use because there's no documentation onRFont.naked(). What do you think, Frederik?@benedikt Thanks for letting me know about the
id()function—great to know about in general!
-
do not use fontParts objects to get an id... those are wrapper classes around fe defcon object
# this will get different results f = CurrentFont() print(id(f)) f = CurrentFont() print(id(f))# this will get the correct id f = CurrentFont().asDefcon() print(id(f)) f = CurrentFont().asDefcon() print(id(f))
-
Maybe python’s built-in id function could be helpful to you there. I have been using it in the past to distinguish fonts with identical names/paths/etc by putting them in a “fonts dictionary” where the id is the key to get the font object. But I can imagine your usage being more complex than this.
-
Tal and I spoke about
tempLibsome years ago. I dont remember why this idea is still on our the shelves.you could easily use a start up script to create a
tempLib` attribute:def _get_temp_lib(self): lib = getattr(self.naked(), "myCustomTempLib", None) if lib is None: lib = self.naked().myCustomTempLib = dict() return lib RFont.tempLib = property(_get_temp_lib)