fonttools/Scripts/RoboFabIntro/demo_MakeCameoFont.py
Erik van Blokland 617945dcf1 The scripts folder for FontLab as they shipped with Fab 1.1.1.
git-svn-id: http://svn.robofab.com/trunk@22 b5fa9d6c-a76f-4ffd-b3cb-f825fc41095c
2008-01-16 08:14:00 +00:00

50 lines
1.3 KiB
Python

# FLM: Make Cameo Font
"""Make a cameo font. Pretty simple."""
from robofab.world import CurrentFont
from robofab.interface.all.dialogs import Message
buffer = 30
scaleValue = .9
f = CurrentFont()
# clear all kerning
f.kerning.clear()
#determine top and bottom of the box
t = f.info.unitsPerEm + f.info.descender + buffer
b = f.info.descender - buffer
#first decompose any components
for g in f:
g.decompose()
#then proceed with the cameo operation
for g in f:
#catch negative sidebearings
if g.leftMargin < 0:
g.leftMargin = 0
if g.rightMargin < 0:
g.rightMargin = 0
#scale the glyph and sidebearings
leftMargin = int(round((g.rightMargin * scaleValue) + buffer))
rightMargin = int(round((g.rightMargin * scaleValue) + buffer))
g.scale((scaleValue, scaleValue), (int(round(g.width/2)), 0))
g.leftMargin = leftMargin
g.rightMargin = rightMargin
#determine the left and the right of the box
l = 0
r = g.width
#draw the box using flPen
p = g.getPen()
p.moveTo((l, b))
p.lineTo((l, t))
p.lineTo((r, t))
p.lineTo((r, b))
p.closePath()
#correct path direction
g.correctDirection()
#update the glyph
g.update()
#update the font
f.update()
#tell me when it is over
Message('The highly complex "Cameo Operation" is now complete. Please examine the results and be thankful that RoboFab is on your side.')