Last active
August 29, 2015 14:02
-
-
Save line0/b7cd5ee632fa0dbbb364 to your computer and use it in GitHub Desktop.
FontLab Macro: raster/pixel selected glyphs. also useful for introducing aliasing.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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