I just updated my FontLab from 5 to 7.
In the last weekend (Aug. 1. 2020), I'd tried to move my old python codes for FontLab 5 to FontLab 7 (6). Although, there is the online documentation, as usual, I needed to guess and try to work out the code for correct result.
Here I listed my first attempt to add empty glyph to a font.
First Two Lines:
To Count the Opened Font(s)
Of cause, I shall check if the code point "U+E200" has been already occupied. But this checking is skipped in the above code.
Enjoy!
In the last weekend (Aug. 1. 2020), I'd tried to move my old python codes for FontLab 5 to FontLab 7 (6). Although, there is the online documentation, as usual, I needed to guess and try to work out the code for correct result.
Here I listed my first attempt to add empty glyph to a font.
First Two Lines:
import fontlab as fl7
import fontgate as fgt
We need two modules, "fontlab" to work with the application FontLab, and "fontgate" to handle the opened font(s) and the glyphs of the font(s) in FontLab.
To Count the Opened Font(s)
openedFontCounts = fl7.CountFonts() # it's type of "integer".
To Get the Font From the Opened FontsallFonts = fl7.AllFonts() # type of "fgPackages"
font1 = allFonts[0] # if there is at least a font opened. it's of the type "fgFont".
font2 = allFonts[1] # if there are at least two fonts opened. it's of the type "fgFont".
...
We may also get the current font by:
font1 = fl7.CurrentFont() # type of "fgFont"
To add an empty glyph with the unicode point "U+E200", (0xE200 = 57856)
newGlyph = font1.createGlyph("eudc.E200", 57856) # newGlyph is of the type "fgGlyph"
The following line can be added before and after the funcation call "font1.createGlyph(...)" to check if "createGlyph" Works:
print(len(font1))
Let's put them all together:
import fontlab as fl7
import fontgate as fgt
openedFontCounts = fl7.CountFonts() # it's type of "integer".
if openedFontCounts > 0:
allFonts = fl7.AllFonts() # font1 = fl7.CurrentFont()
font1 = allFonts[0] #
print(len(font1))
newGlyph = font1.createGlyph("eudc.E200", 57856)
print(len(font1))
print("Done.")
Of cause, I shall check if the code point "U+E200" has been already occupied. But this checking is skipped in the above code.
Enjoy!
Comments