New to Typophile? Accounts are free, and easy to set up.
I know how to compile OT features from inside a python macro:
fl.CallCommand(33203)
33203 being the code for the menu command OTCompile.
Fontlab also provides codes for the menu commands OTFeaturesNew (33222), which resets the features, and OTFeaturesOpen (33210), which gets features from a file.
The problem with OTFeaturesNew (33222) is that it pops an alert asking if you really want to remove all OT data.
The problem with OTFeaturesOpen (33210) is that it pops a dialog to select the file.
I would like to be able to:
+ reset the OT features WITHOUT popping an alert (ie. silently)
+ get features from a specific fea file WITHOUT popping a dialog
Can it be done?
1 Sep 2011 — 3:28am
Matthew,
resetting the features is possible if you don't use the command codes, but set the python attributes directly:
Loading feature code from a text file can probably be done, but it would be a bit more complicated. In principle, open a text file using python, detect the lines where one feature's code starts and ends, and add the feature to the font like this:
Example:
fl.font.features.append(Feature("liga", "feature liga\n {\n sub f i by f_i;\n } liga;\n")) fl.UpdateFont()hth,
Jens
1 Sep 2011 — 2:33pm
Not bad, but this will only work for feature records, right? And there's more to the fea file than feature records (notably: class definitions and 'languagesystem' statements).
2 Sep 2011 — 3:10am
Matthew,
Class definitions and 'languagesystem' statements go to the lower right part of the OpenType panel. This is accessable via the ot_classes attribute of the font object as one big string.
Best
Eigi
2 Sep 2011 — 6:00pm
Ah, thank you. I see how to do this now.
3 Sep 2011 — 5:15pm
from robofab.world import CurrentFont import os, re font = CurrentFont() # reset OT features - thank you Jens font.naked().features.clean() font.naked().ot_classes = "" # open fea file feaFile = open({path to fea file}, 'r') feaCode = feaFile.read() # read ot_classses from file - from beginning of file to first feature declaration otClassesPattern = re.compile('^.*?(?=\nfeature )', re.DOTALL) otClasses = otClassesPattern.search(feaCode).group(0) # set ot_classses font.naked().ot_classes = otClasses # read features from file & add to font tagList = [] tagPattern = re.compile('feature\s*(?P<tag>\w\w\w\w)\s*{', re.DOTALL) for match in tagPattern.finditer(feaCode): tagList.append(match.group('tag')) for tag in tagList: featurePattern = re.compile('feature\s+%s\s*{.*?}\s*%s;' % (tag, tag), re.DOTALL) featureCode = featurePattern.search(feaCode).group(0) font.naked().features.append(Feature(tag, featureCode)) # delete kern feature if it exists - thank you Karsten for featureIndex in range(len(font.naked().features)-1,-1,-1): if font.naked().features[featureIndex].tag == "kern": del font.naked().features[featureIndex] # make new kern feature & append to feature list kernFeature = font.naked().MakeKernFeature() font.naked().features.append(kernFeature) # recompile OT features font.update() fl.CallCommand(33203)3 Sep 2011 — 6:12pm
Maybe I'm missing something, but if you just want your features in an external file (which is maybe not the only thing you're wanting to do), you can just put something like this at the bottom right pane of the OT panel:
The .fea file would be in the same directory as the .vfb file in this example.
3 Sep 2011 — 6:51pm
Good idea. That's simple and works for getting the features into the font. But it doesn't display the underyling fea source code in the OT panel, which I prefer so I can try different things without having to modify the official features file.
3 Sep 2011 — 9:08pm
Well, you can easily change things in the external file, save and then hit compile in FontLab. It's really only one extra step (saving in the text editor), if you don't count switching between programs.
Also, you can duplicate the external file, and "include" that instead, if you want to try different things out without messing with your official features file. It also works with more than one file (each on a separate "include" line), so you can break things out logically among multiple .fea files if you wish.