modes[2] = Mode("subs", -140, math.cos(fl.font.italic_angle) * -140 * -1) dnomGlyphs = [] for glyph in fl.font.glyphs: splitName = glyph.name.split('.') if len(splitName) > 1 and splitName[1] == "dnom": dnomGlyphs.append(glyph) print "\nWelcome to FontLab Studio 5.\n" print "Fonts open: ", len(fl) for x in range(0, len(modes)): print "Adding", modes[x].kind, "glyphs" for sGlyph in dnomGlyphs: newGlyph = Glyph() comp = Component(sGlyph.index) newGlyphName = sGlyph.name.split('.')[0] + "." + modes[x].kind newGlyph.width = sGlyph.width f.newGlyph(newGlyphName) f[newGlyphName].width = sGlyph.width f[newGlyphName].appendComponent(sGlyph.name, (modes[x].xShift, modes[x].yShift)) f.update() endCount = len(f.glyphs) print "Starting glyph count was ", startCount print "Final glyph count is ", endCount print "Added ", (endCount - startCount), "glyphs"
's_t': ['', 's_t', ''], 'c_t': ['', 'c_t', ''], } print "" print "Starting latin-extended-A glyph placeholder generation" font = CurrentFont() print font for glyph in glyphs: gUnicode = glyphs[glyph][0] gName = glyphs[glyph][1] if gName is not "": if gName in font: font[gName].mark = 250 print gName + " already in font" else: new = font.newGlyph(gName, False) print new # font[gName].unicode = gUnicode font[gName].mark = 200 font.update() print "Script done" print ""
# robofab manual # Interpolate howto # Interpolating glyphs examples from robofab.world import CurrentFont f = CurrentFont() g = f.newGlyph("interpolated") g.interpolate(.5, f["a"], f["b"] # if you're in fontlab: g.update()
# The main job is done here: if f is not None: print 'Drawing boxes ...' generatedGlyphs = [] # Keeping track of the glyph order for name, uni in sorted(names, key=lambda x: int(x[1], 16)): # sorting the dictionary by the Unicode value of the glyph. generatedGlyphs.append(name) commands = names[name, uni] print name g = f.newGlyph(name, clear=True) g.width = WIDTH boxPen = g.getPen() for command in commands: exec(command) if not inShell: g.removeOverlap() g.correctDirection() g.unicode = int(uni, 16) g.update() f.update() if inShell:
#FLM: Draw Pseudo Ogee # Description: # Create an Pseudo Ogee shape # Credits: # Pablo Impallari1 # http://www.impallari.com # Dependencies from robofab.world import CurrentFont f = CurrentFont() # Creo un Glyphs Nuevo newGlyph = f.newGlyph('ogee', clear=True) # Creo un nuevo Pen pen = newGlyph.getPen() # Defino Medidas alto = 500 ancho = 100 # Calculo inicio_x = 100 inicio_y = 0 angulo = alto / 10 * 4.666666 curva = alto / 3.333333 # Lo mando a donde tiene que ir
# rasterise the shape in glyph "A" # and draw boxes in a new glyph named "A.silly" # from robofab.world import CurrentFont, CurrentGlyph sourceGlyph = "a" f = CurrentFont() source = f[sourceGlyph] # find out how big the shape is from the glyph.box attribute xMin, yMin, xMax, yMax = source.box # create a new glyph dest = f.newGlyph(sourceGlyph + ".silly") dest.width = source.width # get a pen to draw in the new glyph myPen = dest.getPen() # a function which draws a rectangle at a specified place def drawRect(pen, x, y, size=50): pen.moveTo((x - .5 * size, y - .5 * size)) pen.lineTo((x + .5 * size, y - .5 * size)) pen.lineTo((x + .5 * size, y + .5 * size)) pen.lineTo((x - .5 * size, y + .5 * size)) pen.closePath()
# robofab manual # Buildingaccents howto # usage examples from robofab.world import CurrentFont f = CurrentFont() f.newGlyph("aacute") f["aacute"].appendComponent("a") f["aacute"].appendComponent("acute", (200, 0)) f["aacute"].width = f["a"].width f.update()
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ from robofab.world import CurrentFont import math f = CurrentFont() baseline = 0 descender = f.info.descender xHeight = f.info.xHeight capHeight = f.info.capHeight ascender = f.info.ascender angle = f.info.italicAngle metrics = [baseline, descender, xHeight, capHeight, ascender] g = f.newGlyph("fontmetrics", True) p = g.getPen() print dir(p) w = 600 u = 1 gap = 10 # rotation point is half of x-height offset = math.tan(math.radians(angle)) * xHeight/2 for m in metrics: # offset for italic angle shift = math.tan(math.radians(angle)) * m - offset
# robofab manual # Usepens howto # usage examples from robofab.world import CurrentFont f = CurrentFont() newGlyph = f.newGlyph('demoDrawGlyph', clear=True) newGlyph.width = 1000 # hey, what's this: pen = newGlyph.getPen() # ha! a sneaky way to get a pen object! pen.moveTo((100, 100)) pen.lineTo((800, 100)) pen.curveTo((1000, 300), (1000, 600), (800, 800)) pen.lineTo((100, 800)) pen.lineTo((100, 100)) pen.closePath() newGlyph.update() f.update()
# robothon06 # rasterise the shape in glyph "A" # and draw boxes in a new glyph named "A.silly" from robofab.world import CurrentFont, CurrentGlyph sourceGlyph = "a" f = CurrentFont() source = f[sourceGlyph] # find out how big the shape is from the glyph.box attribute xMin, yMin, xMax, yMax = source.box # create a new glyph dest = f.newGlyph(sourceGlyph+".silly") dest.width = source.width # get a pen to draw in the new glyph myPen = dest.getPen() # a function which draws a rectangle at a specified place def drawRect(pen, x, y, size=50): pen.moveTo((x-.5*size, y-.5*size)) pen.lineTo((x+.5*size, y-.5*size)) pen.lineTo((x+.5*size, y+.5*size)) pen.lineTo((x-.5*size, y+.5*size)) pen.closePath() # the size of the raster unit resolution = 30
n=corners, rt=phi) # main f = CurrentFont() glyphnames = f.selection start = int(round(time())) for sourcename in glyphnames: source = f[sourcename] # if not(source.name[-6:-1] == ".calt"): if not (f.has_key(source.name + suffix)): dest = f.newGlyph(source.name + suffix) else: dest = f[source.name + suffix] dest.clear() dest.width = source.width pressure = float(randint(pmin, pmax)) / 10 print "Ribbonize glyph " + source.name + " with pressure= " + str(pressure) ribbonGlyph(source, dest, pressure) dest.removeOverlap() stop = int(round(time())) if len(glyphnames) > 0: print("\nFinished. Time per glyph:", (stop - start) / len(glyphnames), "seconds")
# In which an adventurous glyph of your choice # makes a trip into RoboFab land, # and returns safely home after various inspections # and modifications. from robofab.world import CurrentGlyph, CurrentFont c = CurrentGlyph() f = CurrentFont() from robofab.objects.objectsRF import RGlyph d = RGlyph() # woa! d is now a rf version of a fl glyph! d.appendGlyph(c) d.width = 100 c.printDump() d.printDump() e = f.newGlyph('copyTest') # dump the rf glyph back to a fl glyph! e.appendGlyph(d) # see, it still takes its own kind as well e.appendGlyph(f['a']) e.printDump()
if specialSmallCapAccents == 0: whatToDo = TwoChecks('Use cap accents', 'Use special accents', value1=0, value2=0) if whatToDo == 1: scAccentSuffix = suffix if whatToDo == 2: scAccentSuffix = AskString('Suffix for small cap accents', scSuffix) smallCapList = rewriteSmallCapList(baseUpperCaseList, scSuffix, scAccentSuffix) buildAccents(font, lowerCaseList, 'Building lowercase accents', overwrite) buildAccents(font, upperCaseList, 'Building uppercase accents', overwrite) if buildSmallCap == 1: buildAccents(font, smallCapList, 'Building small cap accents', overwrite) #Build a couple of accents that would be missed font.newGlyph('uni021B', clear=True) font.newGlyph('uni021A', clear=True) font.newGlyph('Dotlessi.sc', clear=True) dotlessisc = font['I.sc'].copy() duplicatetcommaaccent = font['tcommaaccent'].copy() duplicateTcommaaccent = font['Tcommaaccent'].copy() font['Dotlessi.sc'].appendGlyph(dotlessisc) font['uni021B'].appendGlyph(duplicatetcommaaccent) font['uni021A'].appendGlyph(duplicateTcommaaccent) font['uni021B'].width = duplicatetcommaaccent.width font['uni021B'].leftMargin = duplicatetcommaaccent.leftMargin font['uni021B'].rightMargin = duplicatetcommaaccent.rightMargin font['uni021B'].mark = 200 font['uni021A'].width = duplicateTcommaaccent.width font['uni021A'].leftMargin = duplicateTcommaaccent.leftMargin font['uni021A'].rightMargin = duplicateTcommaaccent.rightMargin
font = CurrentFont() print 'Making glyphs...' for glyph in alts: base, extension = glyph.split('.') if base in to_make: for g in to_make[base]: if g == 'uni021A': old_name = 'uni021A' new_name = 'uni021A.' + extension else: old_name = base + g new_name = old_name + '.' + extension if new_name not in font: font.newGlyph(new_name) font[new_name].appendGlyph(font[glyph]) old_comp = font[old_name].components offset = () scale = () if len(old_comp) != 0: for c in old_comp: if c.baseGlyph == g: offset = c.offset scale = c.scale if base == 'L' and g == 'caron' and c.baseGlyph == 'caronSlovak': offset = c.offset scale = c.scale g = 'caronSlovak' if g == 'uni021A' and c.baseGlyph == 'commaaccent': offset = c.offset
# Removes all control points, so that there are no # curves anymore only straight lines from robofab.world import CurrentFont font = CurrentFont() for g in [glyph.name for glyph in font]: old = font[g] print len(old) new = font.newGlyph("dummytmp", clear=True) pen = new.getPointPen() for contour in old: pen.beginPath() for point in contour.points: if point.type != "offCurve": pen.addPoint((point.x,point.y),"line") pen.endPath() font.newGlyph(g, clear=True) old.appendGlyph(new) print len(new) font.update()
# demo of drawing with RoboFab # # import robofab from robofab.world import CurrentFont, CurrentGlyph # (make sure you have a font opened in FontLab) f = CurrentFont() if f == None: Message("You should open a font first, there's nothing to look at now!") else: newGlyph = f.newGlyph('demoDrawGlyph', clear=True) newGlyph.width = 1000 # The drawing is done through a specialised pen object. # There are pen objects for different purposes, this one # will draw in a FontLab glyph. The point of this is that # Robofab glyphs all respond to the standard set of # pen methods, and it is a simple way to re-interpret the # glyph data. # Make a new pen with the new glyph we just made pen = newGlyph.getPen() # Tell the pen to draw things pen.moveTo((100, 100)) pen.lineTo((800, 100))
hweight = int(60) roundWidth=int(font["round"].box[2]) roundLegWidth=int(font["roundleg"].box[2]) descender = font.info.descender xheight = font.info.xHeight ascender = font.info.ascender capheight = font.info.capHeight overshoot = abs(int(font["round"].box[1])) strtRM = font['straight'].rightMargin rndRM = font['round'].rightMargin rndlgRM = font['roundleg'].rightMargin slant = False buildG = ['D','E','F','H','I','L','O','T','a','b','c','d','e','f','h','i','l','m','n','o','p','q','t','u','v','space','straightX','straightD','ucStraight','ucCrossbar'] for glyph in buildG: font.newGlyph(glyph) #building an x-height, desender, and upper-case straights ucStraight = font['ucStraight'] sX = font['straightX'] sD = font['straightD'] sD.appendGlyph(font['straight']) pts = [0,0] ptsB = [0,0] ptsW = [0,0] for contour in sD: for point in contour.points: if point == contour.points[0]: pts[0] = pts[1] = ptsB[0] = ptsB[1] = ptsW[0] = ptsW[1] = point if point.y > pts[0].y: pts[1] = pts[0]
"""Import one glyph from a .ufo, i.e. a single .glif file. """ from robofab.world import CurrentFont from robofab.objects.objectsRF import OpenFont from robofab.interface.all.dialogs import SelectGlyph, Message flFont = CurrentFont() if flFont is None: Message("Please have a FontLab destination font ready..") else: # pick a .ufo rfFont = OpenFont() if rfFont is not None: # pick a glyph in the .ufo rfGlyph = SelectGlyph(rfFont) if rfGlyph is not None: # make a new glyph in the FL font flGlyph = flFont.newGlyph(rfGlyph.name, clear=True) # draw the glyph into the FL font pen = flGlyph.getPointPen() rfGlyph.drawPoints(pen) # set the width, unicodes and lib flGlyph.width = rfGlyph.width flGlyph.unicodes = rfGlyph.unicodes flGlyph.lib = rfGlyph.lib flGlyph.note = rfGlyph.note flGlyph.update() flFont.update()
# robothon06 # building a glyph from parts # the hard way from robofab.world import CurrentFont f = CurrentFont() # make a new glyph f.newGlyph("aacute") # add the component for the base glyph, a f["aacute"].appendComponent("a") # add the component for the accent, acute # note it has an offset f["aacute"].appendComponent("acute", (200, 0)) # set the width too f["aacute"].width = f["a"].width f.update()
for lig in base: parts = lig.split('_') temp = [] for x in parts: if x in accented.keys(): temp.append(accented[x]) else: temp.append([x]) toMake = combinations(temp) for i in toMake: name = '' for x in i: name = name + '_' + x name = name[1:] if name not in font.keys(): font.newGlyph(name) font[name].appendComponent(lig) font[name].mark = 200 font[name].rightMargin = 20 glyphs = name.split('_') previous = '' index = 1 for n in glyphs: if n in position.keys(): if index == 1: font[name].appendComponent(position[n][0], position[n][1]) if index == 2: if splitAccent(n)[0] == 'J': p = (position[n][1][0] + 854, position[n][1][1]) elif previous == 'A':
for lig in base: parts = lig.split('_') temp = [] for x in parts: if x in accented.keys(): temp.append(accented[x]) else: temp.append([x]) toMake = combinations(temp) for i in toMake: name = '' for x in i: name = name + '_' + x name = name[1:] if name not in font.keys(): font.newGlyph(name) font[name].appendComponent(lig) font[name].mark = 200 font[name].rightMargin = 20 glyphs = name.split('_') previous = '' index = 1 for n in glyphs: if n in position.keys(): if index == 1: font[name].appendComponent(position[n][0], position[n][1]) if index == 2: if splitAccent(n)[0] == 'J': p = (position[n][1][0] + 854, position[n][1][1]) elif previous == 'A': p = (position[n][1][0] + 865, position[n][1][1])
# from robofab.world import CurrentFont, CurrentGlyph, RGlyph f = CurrentFont() for glyph in ['a', 'b']: sourceGlyph = glyph source = f[sourceGlyph] # find out how big the shape is from the glyph.box attribute xMin, yMin, xMax, yMax = source.box # create a new glyph dest = f.newGlyph("silly") dest.width = source.width # get a pen to draw in the new glyph myPen = dest.getPen() # a function which draws a rectangle at a specified place def drawRect(pen, x, y, size=50): pen.moveTo((x-.5*size, y-.5*size)) pen.lineTo((x+.5*size, y-.5*size)) pen.lineTo((x+.5*size, y+.5*size)) pen.lineTo((x-.5*size, y+.5*size)) pen.closePath() # the size of the raster unit resolution = 30
# robofab manual # Glyphmath howto # Fun examples #FLM: Fun with GlyphMath # this example is meant to run with the RoboFab Demo Font # as the Current Font. So, if you're doing this in FontLab # import the Demo Font UFO first. from robofab.world import CurrentFont from random import random f = CurrentFont() condensedLight = f["a#condensed_light"] wideLight = f["a#wide_light"] wideBold = f["a#wide_bold"] diff = wideLight - condensedLight destination = f.newGlyph("a#deltaexperiment") destination.clear() x = wideBold + (condensedLight - wideLight) * random() destination.appendGlyph(x) destination.width = x.width f.update()
modes[1]=Mode("sups",400,math.cos(fl.font.italic_angle) * 400 * -1) modes[2]=Mode("subs",-140,math.cos(fl.font.italic_angle) * -140 * -1) dnomGlyphs = [] for glyph in fl.font.glyphs: splitName = glyph.name.split('.') if len(splitName)>1 and splitName[1]=="dnom": dnomGlyphs.append(glyph) print "\nWelcome to FontLab Studio 5.\n" print "Fonts open: ", len(fl) for x in range (0, len(modes)): print "Adding", modes[x].kind, "glyphs" for sGlyph in dnomGlyphs: newGlyph = Glyph() ; comp = Component(sGlyph.index) ; newGlyphName = sGlyph.name.split('.')[0]+"."+modes[x].kind ; newGlyph.width = sGlyph.width ; f.newGlyph(newGlyphName) ; f[newGlyphName].width = sGlyph.width ; f[newGlyphName].appendComponent(sGlyph.name, (modes[x].xShift,modes[x].yShift)) ; f.update() ; endCount = len(f.glyphs) print "Starting glyph count was ", startCount print "Final glyph count is ", endCount print "Added ", (endCount - startCount), "glyphs"
# robofab manual # Glyphmath howto # Fun examples #FLM: Fun with GlyphMath # this example is meant to run with the RoboFab Demo Font # as the Current Font. So, if you're doing this in FontLab # import the Demo Font UFO first. from robofab.world import CurrentFont from random import random f = CurrentFont() condensedLight = f["a#condensed_light"] wideLight = f["a#wide_light"] wideBold = f["a#wide_bold"] diff = wideLight - condensedLight destination = f.newGlyph("a#deltaexperiment") destination.clear() x = wideBold + (condensedLight-wideLight)*random() destination.appendGlyph( x) destination.width = x.width f.update()
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ from robofab.world import CurrentFont import math f = CurrentFont() baseline = 0 descender = f.info.descender xHeight = f.info.xHeight capHeight = f.info.capHeight ascender = f.info.ascender angle = f.info.italicAngle metrics = [baseline, descender, xHeight, capHeight, ascender] g = f.newGlyph("fontmetrics", True) p = g.getPen() print dir(p) w = 600 u = 1 gap = 10 # rotation point is half of x-height offset = math.tan(math.radians(angle)) * xHeight / 2 for m in metrics: # offset for italic angle shift = math.tan(math.radians(angle)) * m - offset