def run(): f = CurrentFont() if f != None: myPath = os.path.dirname(f.path) fdkPath = setDirectory(myPath, 'fdk') exportFDKFiles(f, fdkPath) myFile = f.path f.naked().modified = 0 f.close(False) OpenFont(myFile) # revert font else: myPath = GetFolder('Select folder with vfb source files') if myPath: fdkPath = setDirectory(myPath, 'fdk') allFiles = getFilePaths(myPath, '.vfb') for myFile in allFiles: f = OpenFont(myFile) print '' print 'Processing %s...' % os.path.basename(f.path) exportFDKFiles(f, fdkPath) f.naked().modified = 0 f.close(False)
if nakedFont[0].layers_number == 1: return False else: return True def getLayer(nakedFont, message): numberOfLayers = nakedFont[0].layers_number - 1 layers = [] while numberOfLayers >= 0: layers.append(numberOfLayers) numberOfLayers = numberOfLayers - 1 whichLayer = OneList(layers, message) return int(whichLayer) fontToChange = CurrentFont() if not hasMM(fontToChange.naked()): Message('Font needs to be MM') else: orignalMetricsFont = OpenFont(None, "Which font's sidebearings do you want?") orignalMetrics = {} tickCount = len(orignalMetricsFont) bar = ProgressBar('Getting metrics', tickCount) tick = 0 if hasMM(orignalMetricsFont.naked()): layer = getLayer(orignalMetricsFont.naked(), 'Which layer do you want?') for glyph in orignalMetricsFont: advanceWidth = int(glyph.naked().GetMetrics(layer).x) glyphWidth = int(glyph.naked().GetBoundingRect(layer).width) glyphLeft = int(glyph.naked().GetBoundingRect(layer).x) glyphRight = advanceWidth - (glyphWidth + glyphLeft)
# robothon06 # show OpenType naming records # in the fontlab API from robofab.world import CurrentFont f = CurrentFont() fn = f.naked() for r in fn.fontnames: print r.nid, r.pid, r.eid, r.lid, r.name
else: return True def getLayer(nakedFont, message): numberOfLayers = nakedFont[0].layers_number - 1 layers = [] while numberOfLayers >= 0: layers.append(numberOfLayers) numberOfLayers = numberOfLayers - 1 whichLayer = OneList(layers, message) return int(whichLayer) fontToChange = CurrentFont() if not hasMM(fontToChange.naked()): Message('Font needs to be MM') else: orignalMetricsFont = OpenFont(None, "Which font's sidebearings do you want?") orignalMetrics = {} tickCount = len(orignalMetricsFont) bar = ProgressBar('Getting metrics', tickCount) tick = 0 if hasMM(orignalMetricsFont.naked()): layer = getLayer(orignalMetricsFont.naked(), 'Which layer do you want?') for glyph in orignalMetricsFont: advanceWidth = int(glyph.naked().GetMetrics(layer).x) glyphWidth = int(glyph.naked().GetBoundingRect(layer).width)
# robothon06 # show encoding from robofab.world import CurrentFont f = CurrentFont() fn = f.naked() # object containing encoding records. # you can iterate through it by using an index. print fn.encoding for i in range(len(fn.encoding)): er = fn.encoding[i] print er, er.name, er.unicode
# Getting to feature data in a FontLab from robofab.world import CurrentFont f = CurrentFont() print f.naked().features # these are raw FontLab feature objects.
head = """<ASCII-MAC> <Version:7.5><FeatureSet:InDesign-Roman><ColorTable:=<Black:COLOR:CMYK:Process:0,0,0,1>> <DefineParaStyle:NormalParagraphStyle=<Nextstyle:NormalParagraphStyle>> """ paragraph = "<ParaStyle:NormalParagraphStyle>" # This is awfully long, but gets the job done glyph = "<cTypeface:%(style)s><cLigatures:0><cFont:%(family)s><cSpecialGlyph:%(glyph)s><cOTFContAlt:0><0xFFFD><cTypeface:><cLigatures:><cFont:><cSpecialGlyph:><cOTFContAlt:>" from robofab.world import CurrentFont font = CurrentFont() path = font.path.split('.')[0] + '.txt' family = font.info.openTypeNamePreferredFamilyName style = font.info.openTypeNamePreferredSubfamilyName out = head + paragraph naked = font.naked() for g in naked.glyphs: out = out + glyph % ({'family': family, 'style': style, 'glyph': g.index}) f = open(path, 'w') f.write(out) f.close()
from robofab.world import CurrentFont f = CurrentFont() # this is the high level RoboFab object print f # this is the low level FontLab object, not a part of RoboFab print f.naked()
# Very basic setup for CS5 tagged text. Full spec is here: http://help.adobe.com/en_US/indesign/cs/taggedtext/indesign_cs5_taggedtext.pdf # Note that <cSpecialGlyph> is not in that spec, however. head = """<ASCII-MAC> <Version:7.5><FeatureSet:InDesign-Roman><ColorTable:=<Black:COLOR:CMYK:Process:0,0,0,1>> <DefineParaStyle:NormalParagraphStyle=<Nextstyle:NormalParagraphStyle>> """ paragraph = "<ParaStyle:NormalParagraphStyle>" # This is awfully long, but gets the job done glyph = "<cTypeface:%(style)s><cLigatures:0><cFont:%(family)s><cSpecialGlyph:%(glyph)s><cOTFContAlt:0><0xFFFD><cTypeface:><cLigatures:><cFont:><cSpecialGlyph:><cOTFContAlt:>" from robofab.world import CurrentFont font = CurrentFont() path = font.path.split('.')[0] + '.txt' family = font.info.openTypeNamePreferredFamilyName style = font.info.openTypeNamePreferredSubfamilyName out = head + paragraph naked = font.naked() for g in naked.glyphs: out = out + glyph % ({'family': family, 'style': style, 'glyph': g.index}) f = open(path, 'w') f.write(out) f.close()