Rasterizing glyphs into a new font

Rasterize glyphs from an existing font into another font with a script.

Steps

  1. Open the font you wish to rasterize.

  2. Open the Scripting Window and paste the script below.

  3. Adjust the values at the top of the script as needed.

  4. If you wish to rasterize only some glyphs, select them in the Font Overview.
    If the selection is empty, all glyphs in the font will be rasterized.

  5. Run the script to rasterize the glyphs into a new font.

Code

# menuTitle: rasterize selected glyphs into a new font

from hTools3_rasterizer.modules.rasterizer import RasterGlyph, drawElement

# --------
# settings
# --------

egrid  = 30
esize  = 25
eshape = 'super'
eround = 0.75
eglyph = '_element'

# ---------
# rasterize
# ---------

srcFont = CurrentFont()
dstFont = NewFont(showInterface=False)

bitGlyph = dstFont.newGlyph(eglyph)
drawElement(bitGlyph, esize, type=eshape, roundness=eround)
    
glyphNames = srcFont.selectedGlyphNames if len(srcFont.selectedGlyphNames) else srcFont.glyphOrder

for glyphName in glyphNames:
    if glyphName == eglyph:
        continue
    srcGlyph = srcFont[glyphName]
    dstGlyph = dstFont.newGlyph(glyphName)
    R = RasterGlyph(srcGlyph)
    R.elementGlyph = eglyph
    R.elementSpace = egrid
    R.elementSize  = egrid
    R.scan()
    R.draw(dstGlyph, components=True)
    dstGlyph.width = srcGlyph.width
    dstGlyph.unicodes = srcGlyph.unicodes
    
dstFont.openInterface()