Skip to content

Instantly share code, notes, and snippets.

@line0
Last active August 29, 2015 14:02
Show Gist options
  • Save line0/b7cd5ee632fa0dbbb364 to your computer and use it in GitHub Desktop.
Save line0/b7cd5ee632fa0dbbb364 to your computer and use it in GitHub Desktop.
FontLab Macro: raster/pixel selected glyphs. also useful for introducing aliasing.
import robofab
import random
def drawRaster(glyph, raster, box):
colCnt = len(raster)
rowCnt = len(raster[0])
pen = glyph.getPen()
offY = box[1]
offX = box[0]
segH = (box[3] - offY) / colCnt
segW = (box[2] - offX) / rowCnt
for r in range(colCnt):
for c in range(rowCnt):
if raster[r][c] is not False:
x = offX+c*segW
y = offY+(colCnt-r)*segH
pen.moveTo((x,y))
pen.lineTo((x+segW, y))
pen.lineTo((x+segW, y-segH))
pen.lineTo((x, y-segH))
pen.lineTo((x,y))
pen.closePath()
glyph.removeOverlap()
font = CurrentFont()
for glyph in filter(lambda x: x.name in font.selection, font):
raster = glyph.rasterize(12)
box = glyph.box
rGlyph = font.newGlyph(glyph.name)
rGlyph.clear()
rGlyph.width = glyph.width
drawRaster(rGlyph, raster, box)
rGlyph.update()
font.update()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment