Beispiel #1
0
    def openFont(self, path, overlayPath=None, anchorPath=None):
        self.font = OpenFont(path)
        for g in self.font:
          size = len(g)
          csize = len(g.components)
          if (size > 0 and csize > 0):
            decomposeGlyph(self.font, g.name)

        if overlayPath != None:
            overlayFont = OpenFont(overlayPath)
            font = self.font
            for overlayGlyph in overlayFont:
                font.insertGlyph(overlayGlyph)

        # work around a bug with vfb2ufo in which anchors are dropped from
        # glyphs containing components and no contours. "anchorPath" should
        # point to the output of src/v2/get_dropped_anchors.py
        if anchorPath:
            anchorData = json.load(open(anchorPath))
            for glyphName, anchors in anchorData.items():
                glyph = self.font[glyphName]
                for name, (x, y) in anchors.items():
                    glyph.appendAnchor(str(name), (x, y))

        self.ffont = FFont(self.font)
Beispiel #2
0
def interpolate(rfonts, master_dir, out_dir, designspace_path,
                instance_data, italic=False, debug=False):
    """Create MutatorMath designspace and generate instances.
    Returns instance UFOs, or unused instance data if debug is True.
    """

    print('>>> Writing masters')
    for font in rfonts:
        font.save(os.path.join(
            master_dir, build_postscript_name(
                font.info.familyName, font.info.styleName) + '.ufo'))

    writer = DesignSpaceDocumentWriter(designspace_path)
    base_family = add_masters_to_writer(writer, rfonts)
    instance_files = add_instances_to_writer(
        writer, base_family, instance_data, italic, out_dir)
    writer.save()

    print('>>> Building instances')
    build(designspace_path)

    instance_ufos = []
    for path, data in instance_files:
        ufo = OpenFont(path)
        set_custom_params(ufo, data=data)
        set_redundant_data(ufo)
        ufo.save()
        instance_ufos.append(ufo)

    if debug:
        return clear_data(instance_data)
    return instance_ufos
Beispiel #3
0
def doit(args):
    infont = OpenFont(args.ifont)
    outfont = args.ofont
    # add try to catch bad input
    strokewidth = int(args.thickness)
    expandFont(infont, strokewidth)
    infont.save(outfont)

    return infont
Beispiel #4
0
def doit(args):
    infont = OpenFont(args.ifont)
    outfont = args.ofont
    # add try to catch bad input
    strokewidth = int(args.thickness)
    expandFont(infont, strokewidth)
    infont.save(outfont)

    return infont
Beispiel #5
0
def main():
    path = re.sub(r"{}+$".format(os.sep), "", sys.argv[1])
    font = OpenFont(path)

    g = font["uni6211"]
    for con in g:
        for pt in con.points:
            pt.x = round(pt.x * XSCALE, 2)
            pt.y = round(pt.y * YSCALE, 2)
    g.width = int(g.width * XSCALE)
    font.save("scaled.ufo")
Beispiel #6
0
def doit(args):

    psffont = UFO.Ufont(args.ifont, params=args.paramsobj)
    rffont = OpenFont(args.ifont)
    outfont = args.ofont

    getParameters(psffont)

    updateTLPieces(rffont)
    rebuildTLComps(rffont)

    rffont.save(outfont)

    return
Beispiel #7
0
    def openFont(self, path, overlayPath=None):
        self.font = OpenFont(path)
        for g in self.font:
            size = len(g)
            csize = len(g.components)
            if (size > 0 and csize > 0):
                decomposeGlyph(self.font, self.font[g.name])

        if overlayPath != None:
            overlayFont = OpenFont(overlayPath)
            font = self.font
            for overlayGlyph in overlayFont:
                font.insertGlyph(overlayGlyph)

        self.ffont = FFont(self.font)
Beispiel #8
0
def doit(args):

    psffont = UFO.Ufont(args.ifont, params = args.paramsobj)
    rffont = OpenFont(args.ifont)
    outfont = args.ofont

    getParameters(psffont)

    updateTLPieces(rffont)
    rebuildTLComps(rffont)


    rffont.save(outfont)

    return
Beispiel #9
0
    def generateTTFs(self):
        """Build TTF for each font generated since last call to generateTTFs."""

        fonts = [OpenFont(ufo) for ufo in self.generatedFonts]
        self.generatedFonts = []

        log(">> Converting curves to quadratic")
        # using a slightly higher max error (e.g. 0.0025 em), dots will have
        # fewer control points and look noticeably different
        max_err = 0.002
        if self.compatible:
            fonts_to_quadratic(fonts, max_err_em=max_err, dump_stats=True)
        else:
            for font in fonts:
                fonts_to_quadratic([font], max_err_em=max_err, dump_stats=True)

        log(">> Generating TTF files")
        for font in fonts:
            ttfName = self.generateOutputPath(font, "ttf")
            log(os.path.basename(ttfName))
            saveOTF(
                font,
                ttfName,
                self.thinGlyphOrder if "Thin" in ttfName else self.glyphOrder,
                truetype=True)
Beispiel #10
0
    def extractValues(self, UFOpath, glyphName):

        font = OpenFont(UFOpath, showUI=False)
        glyph = font[glyphName]

        valuesList = []
        for p in glyph[0].points:
            valuesList.append((p.x, p.y))

        return valuesList
Beispiel #11
0
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)
# robofab manual
# Interpolate howto
# Straight Interpolating examples

from robofab.world import OpenFont
minFont = OpenFont(pathToMinFont)
maxFont = OpenFont(pathToMaxFont)
# or any other way you like to get two font objects

inbetweenFont = OpenFont(pathToInbetweenFont)
# so now we have 3 font objects, right?

inbetweenFont.interpolate(.5, minFont, maxFont)
# presto, inbetweenFont is now 50% of one and 50% of the other

inbetweenFont.interpolate((.92, .12), minFont, maxFont)
# presto, inbetweenFont is now horizontally
# vertically interpolated in different ways.
Beispiel #13
0
# robofab manual
# Fontlabremote howto
# usage examples
 
#FLM: Remove overlap from Remote Glyph.
 
from robofab.world import OpenFont
from robofab.tools.remote import transmitGlyph, receiveGlyph, runFontLabRemote
 
# Pick a UFO font:
f = OpenFont()
 
print "Number of contours before", len(f['A'])
 
# call FontLab to make a new font
startNewFontCode = """from robofab.world import NewFont
f = NewFont()
f.info.fullName = 'Temporary Font generated by RoboFab Remote'"""
 
print runFontLabRemote(startNewFontCode)
 
# send a glyph to FontLab,
# it will be inserted in the CurrentFont.
transmitGlyph(f['A'])
f.removeGlyph('A')
 
# send instructions to remove overlap for this glyph
overlapCode = """from robofab.world import CurrentFont
from robofab.tools.remote import transmitGlyph
f = CurrentFont()
f["A"].removeOverlap()
#FLM: RoboFab Intro, Interpolating two fonts

#	Basic interpolation of two fonts. This is clean
#	non-FontLab specific implementation of
#	interpolating. This interpolation is strict: it
#	adds no points to contours, it does not alter
#	the outlines of the extremes in any possible
#	way. Note that this works in FontLab as well as
#	NoneLab.
#
#	In fontlab: select two .vfb files, the result will be a new .vfb
#	In NoneLab: select two .ufo files, the result will be a new .ufo

from robofab.world import OpenFont, RFont, RGlyph
from robofab.pens.pointPen import AbstractPointPen
from robofab.interface.all.dialogs import GetFolder

f = OpenFont(None, "First master")
g = OpenFont(None, "Second master")

factor = .5

d = RFont()
d.interpolate(factor, f, g)

path = GetFolder("Select a place to save this UFO")
if path:
    d.save(path)

print 'done'
Beispiel #15
0
# robofab manual
# Usepens howto
# DigestPointStructurePen examples

from robofab.world import OpenFont
from robofab.pens.digestPen import DigestPointStructurePen

f = OpenFont()

myPen = DigestPointStructurePen()
f['period'].drawPoints(myPen)

print myPen.getDigest()
#FLM: Copy Font Sidebearing
# (c) Ben Kiel
#
# Copys one font's sidebearing values to another font

#Imports
from robofab.world import OpenFont, CurrentFont
from robofab.interface.all.dialogs import Message

fontToChange = CurrentFont()
orignalMetricsFont = OpenFont(None, "Which font's sidebearings do you want?")
orignalMetrics = {}

for glyph in orignalMetricsFont:
	orignalMetrics[glyph.name] = [glyph.leftMargin, glyph.rightMargin]
orignalMetricsFont.close()

for name, metrics in orignalMetrics.iteritems():
	if fontToChange.has_key(name):
		fontToChange[name].leftMargin = metrics[0]
		fontToChange[name].rightMargin = metrics[1]
fontToChange.update()
Message('Done changing sidebearings')
def setup_fonts_to_quadratic_robofab():
    return [[OpenFont(os.path.join(DATADIR, 'RobotoSubset-Regular.ufo'))],
            MAX_ERR_EM]
Beispiel #18
0
                yAdvance += (UPM * _line_Height) * sc
                previousGlyph = None
                previousGlyphGroups = None

            restore()

            glyphStop = time()
            glyphDrawingTime += (glyphStop - glyphStart) * 1000

        print 'average glyph drawing %0.2f ms, total %0.2f ms, %s glyphs drawn' % (
            glyphDrawingTime / nbrOfGlyphs, glyphDrawingTime, nbrOfGlyphs)


from robofab.world import OpenFont

thisFont = OpenFont(ufoPath)

typeSetter = TypeSetter(thisFont)
typeSetter.canvas['margins'] = margins
typeSetter.canvas['preset'](preset)

typeSetter.type['size'] = pointSize
typeSetter.type['_line_Height'] = _line_Height
typeSetter.type['tracking'] = tracking
typeSetter.type['color'] = color
typeSetter.type['alpha'] = alpha

typeSetter.settings['suffix'] = suffix
typeSetter.settings['infoFont'] = infoFont
typeSetter.settings['useKerning'] = useKerning
typeSetter.settings['showKerning'] = showKerning
Beispiel #19
0
    def generateFont(self,
                     mix,
                     names,
                     italic=False,
                     swapSuffixes=None,
                     stemWidth=185,
                     kern=True):

        n = names.split("/")
        log("---------------------\n%s %s\n----------------------" %
            (n[0], n[1]))
        log(">> Mixing masters")
        if isinstance(mix, Mix):
            f = mix.generateFont(self.basefont)
        else:
            f = mix.copy()
        if italic == True:
            log(">> Italicizing")
            tweakAmmount = .085
            narrowAmmount = .93
            if names.find("Thin") != -1:
                tweakAmmount = .05
            if names.find("Condensed") != -1:
                narrowAmmount = .96
            i = 0
            for g in f:
                i += 1
                if i % 10 == 0: print g.name

                if g.name == "uniFFFD":
                    continue

                # if i < 24:
                #     continue
                # if i > 86:
                #     for i,g in enumerate(fl.font.glyphs):
                #       fl.UpdateGlyph(i)
                #     # break
                #     assert False

                # print g.name
                # if self.thinfont != None:
                #                     narrowFLGlyph(g,self.thinfont.getGlyph(g.name),factor=narrowAmmount)

                if g.name in self.lessItalic:
                    italicizeGlyph(f, g, 9, stemWidth=stemWidth)
                elif False == (g.name in self.noItalic):
                    italicizeGlyph(f, g, 10, stemWidth=stemWidth)
                #elif g.name != ".notdef":
                #    italicizeGlyph(g, 10, stemWidth=stemWidth)
                if g.width != 0:
                    g.width += 10

        if swapSuffixes != None:
            for swap in swapSuffixes:
                swapList = [g.name for g in f if g.name.endswith(swap)]
                for gname in swapList:
                    print gname
                    swapContours(f, gname.replace(swap, ""), gname)
        for gname in self.predecompose:
            if f.has_key(gname):
                decomposeGlyph(f, gname)

        log(">> Generating glyphs")
        generateGlyphs(f, self.diacriticList, self.adobeGlyphList)
        log(">> Copying features")
        readFeatureFile(f, self.ot_classes + self.basefont.features.text)
        log(">> Decomposing")
        for gname in self.decompose:
            if f.has_key(gname):
                decomposeGlyph(f, gname)

        setNamesRF(f,
                   n,
                   foundry=self.config.get('main', 'foundry'),
                   version=self.config.get('main', 'version'))
        cleanCurves(f)
        deleteGlyphs(f, self.deleteList)

        if kern:
            log(">> Generating kern classes")
            readFeatureFile(f, self.ot_kerningclasses)
            makeKernFeature(f, self.ot_kerningclasses)

        log(">> Generating font files")
        GenerateFeature_mark(f)
        GenerateFeature_mkmk(f)
        ufoName = self.generateOutputPath(f, "ufo")
        f.save(ufoName)

        if self.buildOTF:
            log(">> Generating OTF file")
            newFont = OpenFont(ufoName)
            otfName = self.generateOutputPath(f, "otf")
            builtSuccessfully = saveOTF(newFont,
                                        otfName,
                                        autohint=self.autohintOTF)
            if not builtSuccessfully:
                sys.exit(1)

            if self.buildTTF:
                log(">> Generating TTF file")
                import fontforge
                otFont = fontforge.open(otfName)
                otFont.generate(self.generateOutputPath(f, "ttf"))
Beispiel #20
0
from robofab import plistlib
import sys, os
def ufoGlyphOrderSetter(existingOrder, newOrder):
    outOrder=[]
    for glyphName in newOrder:
        if glyphName not in existingOrder:
            outOrder.append(glyphName)
    return outOrder

arguments=sys.argv
fontList=arguments[2:]

print "Merging fonts..."
print os.getcwd()
NewUFO = NewFont()
font_source = OpenFont(fontList[0])
for glyphName in ufoGlyphOrderSetter([], font_source.keys()):
    glyph = font_source[glyphName]
    NewUFO.insertGlyph(glyph)
    print glyphName,
    NewUFO[glyphName].unicode = font_source[glyphName].unicode
NewUFO.lib=font_source.lib
NewUFO.info=font_source.info

for font in fontList[1:]:
    source= OpenFont(font)
    for glyph_name in ufoGlyphOrderSetter(NewUFO.keys(), source.keys()):
        glyph = source[glyph_name]
        print glyph_name,
        NewUFO.insertGlyph(glyph)
        NewUFO[glyphName].unicode = font_source[glyphName].unicode
def getGlyphOrder(fonts):
    gO_lengths = []
    gO = []
    for aFont in fonts:
        glyphOrder = []
        if hasattr(aFont, 'glyphOrder'):
            glyphOrder = aFont.glyphOrder
        elif aFont.lib.has_key('public.glyphOrder'):
            glyphOrder = aFont.lib.get('public.glyphOrder')
        gO.append(glyphOrder)
        gO_lengths.append(len(glyphOrder))
    index = gO_lengths.index(max(gO_lengths))
    return gO[index]


fonts = [OpenFont(ufoPath) for ufoPath in pathsToFonts]
glyphOrder = getGlyphOrder(fonts)

pageWidth = 595.276
pageHeight = 841.89
showMetrics = True
showName = True
showFrame = False
showCell = False
showGlyphBox = False
infoFontName = ''
#userGlyphKeys = ['a','b','c']
userGlyphKeys = []

frameBackgroundColor = (.1, .3, .5, .25)
frameBorderColor = (0, 0, 0, .75)
Beispiel #22
0
#FLM: Check unopened font glyphs for MM
#
# Useful for testing to see if two fonts are compatible as as MM font

# First import OpenFont, which allows the user open a font file
# Also import RFont, so that a new font can be created
from robofab.world import OpenFont, RFont

# Get the two masters for the interpolated font
minFont = OpenFont(None, "First font")
maxFont = OpenFont(None, "Second font")

for glyph in minFont:
    data = glyph.isCompatible(maxFont.getGlyph(glyph.name), report=True)
    print glyph
    print data
print 'all done'
"""Correct contour direction for all glyphs in the font"""

from robofab.world import OpenFont
from robofab.interface.all.dialogs import ProgressBar

font = OpenFont()
bar = ProgressBar('Correcting contour direction...', len(font))
for glyph in font:
    bar.label(glyph.name)
    glyph.correctDirection()
    glyph.update()
    bar.tick()
font.update()
bar.close()
def importUFO(ufoPath, newFile=True, saveFile=True, closeFile=True, doInfo=True, doKerning=True, doGroups=True,
    doLib=True, doFeatures=True, doHints=False, doMarks=True, doMasks=True, glyphs=None):
    # get the VFB path
    vfbPath = os.path.splitext(ufoPath)[0] + ".vfb"
    if not newFile:
        font = None
        for font in AllFonts():
            if font.path == vfbPath:
                break
        if font is None:
            if not os.path.exists(vfbPath):
                Message("Could not find the FontLab file \"%s\"." % os.path.basename(vfbPath))
                return
            font = OpenFont(vfbPath)
    else:
        if saveFile:
            if os.path.exists(vfbPath):
                vfbPath = _findAvailablePathName(vfbPath)
        font = NewFont()
    # make the font the top font in FL
    fl.ifont = font.fontIndex
    # read the UFO
    font.readUFO(ufoPath, doHints=doHints, doInfo=doInfo, doKerning=doKerning,
        doGroups=doGroups, doLib=doLib, doFeatures=doFeatures, glyphs=glyphs)
    # load the masks and marks
    if doMasks or doMarks:
        for glyph in font:
            lib = glyph.lib
            if doMarks:
                if lib.has_key(MARK_LIB_KEY):
                    glyph.mark = lib[MARK_LIB_KEY]
                    del lib[MARK_LIB_KEY]
            if doMasks:
                if lib.has_key(MASK_LIB_KEY):
                    # open a glyph window
                    fl.EditGlyph(glyph.index)
                    # switch to the mask layer
                    fl.CallCommand(fl_cmd.ViewEditMask)
                    # add the mask data
                    instructions = lib[MASK_LIB_KEY]
                    pen = glyph.getPointPen()
                    instructionsDrawPoints(instructions, pen)
                    # switch back to the edit layer
                    fl.CallCommand(fl_cmd.ViewEditMask)
                    # clear the mask data from the glyph lib
                    del lib[MASK_LIB_KEY]
        # close all glyph windows. sometimes this actually works.
        fl.CallCommand(fl_cmd.WindowCloseAllGlyphWindows)
    # load the WWS names
    if doInfo:
        info = readPlist(os.path.join(ufoPath, "fontInfo.plist"))
        if "openTypeNameWWSFamilyName" in info:
            font.lib[WWS_FAMILY_KEY] = info["openTypeNameWWSFamilyName"]
        elif "openTypeNameWWSFamilyName" in font.lib:
            del font.lib[WWS_FAMILY_KEY]
        if "openTypeNameWWSSubfamilyName" in info:
            font.lib[WWS_SUBFAMILY_KEY] = info["openTypeNameWWSSubfamilyName"]
        elif "openTypeNameWWSSubfamilyName" in font.lib:
            del font.lib[WWS_SUBFAMILY_KEY]
    # update the font
    font.update()
    # save and close
    if saveFile:
        font.save(vfbPath)
        if closeFile:
            font.close()
#FLM: RoboFab Intro, Font and Glyph Lib

#
#
#	demo of glyph properties
#
#

from robofab.world import OpenFont

# This is a specific test of some features which are probably
# still only supported in one glyph in the DemoFont.ufo,
# which you can find the robofab/Data/ folder. Here is goes.

f = OpenFont(None, "")

for c in f:
    if not c.properties.isEmpty():
        print c.properties.dump()

# This prints the available GlyphProperties objects.
# Not very impressive at the moment, but it means
# that at least they're getting stored with the glyphs
# and that they can be read and interpreted.
def run():
    # if an input path is provided
    if len(sys.argv[1:]
           ) and sys.argv[1][0] != '-':  # skip if it looks like an option
        baseFolderPath = sys.argv[1]

        if baseFolderPath[-1] == '/':  # remove last slash if present
            baseFolderPath = baseFolderPath[:-1]

        # make sure the path is valid
        if not os.path.isdir(baseFolderPath):
            print >> sys.stderr, "ERROR: Invalid input folder\n\t%s" % baseFolderPath
            return

    # if an input path is not provided, use the current directory
    else:
        baseFolderPath = os.getcwd()

    # Load the options
    try:
        options = getOptions(baseFolderPath)
    except:
        return

    # Get paths to fonts and instances file
    fontPathsList, instancesFilePath = getFontPaths(baseFolderPath)

    if not len(fontPathsList):
        print >> sys.stderr, "ERROR: No UFO fonts were found in the path below\n\t%s" % baseFolderPath
        return

    # Handle the instances file
    if not instancesFilePath:
        print >> sys.stderr, "ERROR: Could not find the file named '%s' in the path below\n\t%s" % (
            kInstancesDataFileName, baseFolderPath)
        return
    print "Parsing %s file..." % kInstancesDataFileName
    try:
        instancesList = readInstanceFile(instancesFilePath)
    except:
        print >> sys.stderr, "ERROR: Error parsing file or file is empty."
        return

    # Check the UFO file names
    masterIndexes = []
    for ufoPath in fontPathsList:
        fileNameNoExtension, fileExtension = os.path.splitext(ufoPath)
        masterNumber = fileNameNoExtension.split('_')[-1]

        if masterNumber.isdigit():
            masterIndexes.append(int(masterNumber))
    if masterIndexes != range(len(fontPathsList)):
        print >> sys.stderr, "ERROR: The UFO master files are not named properly"
        return

    # Check the number of UFOs against the number of axes in the instances file
    axisNum = int(math.log(len(masterIndexes), 2))
    for i in range(len(instancesList)):
        instanceDict = instancesList[i]
        axisVal = instanceDict[kCoordsKey]  # Get AxisValues strings
        if axisNum != len(axisVal):
            print 'ERROR:  The %s value for the instance named %s in the %s file is not compatible with the number of axis in the MM source font.' % (
                kCoordsKey, instanceDict[kFontName], kInstancesDataFileName)
            return

    # XXX Only 1-axis MM space (two masters) is supported for now
    if len(fontPathsList) > 2:
        print >> sys.stderr, "ERROR: This script currently only supports 2 masters."
        return

    # Get the path to the output folder
    try:
        outputDirPath = options.outputPath
        if not os.path.isdir(outputDirPath):
            print >> sys.stderr, "ERROR: Invalid output folder\n\t%s" % outputDirPath
            return
    except AttributeError:  # use the current folder to output the instances
        outputDirPath = baseFolderPath

    t1 = time.time()

    print "Reading %d UFO files..." % len(fontPathsList)
    ufoMasters = [OpenFont(ufoPath) for ufoPath in fontPathsList]

    totalInstances = len(instancesList)
    print "Generating %d instances..." % totalInstances
    for i in range(totalInstances):
        makeInstance((i + 1, totalInstances), ufoMasters, instancesList[i],
                     outputDirPath, options)

    t2 = time.time()
    elapsedSeconds = t2 - t1

    if (elapsedSeconds / 60) < 1:
        print 'Completed in %.1f seconds.' % elapsedSeconds
    else:
        print 'Completed in %.1f minutes.' % (elapsedSeconds / 60)
Beispiel #27
0
        f[item["glyphName"]].draw(c)
        c.path.fill()
        #drawPath(c.path)
        restore()
    overprintImage.unlockFocus()
    # get drawbot to draw the image.
    image(overprintImage, (0,0))
    



ufoPath = u"wood/TypeMedia1314-WoodType.ufo"
ufoPath = os.path.join(os.path.dirname(os.getcwd()), ufoPath)
print os.path.exists(ufoPath)

f = OpenFont(ufoPath)
#names = f.keys()
names = [ "D", "F", "H", "N", "S", "Z", "five", "eight", "Gcounter", "one_unit", "Acounter", "Ocounter", "ecounter", "half_unit", "Xcounter", "Ccounter"]

names = [ "D", "F"]
print names
print f

cm = 28.3464567    # points in 1 centimeter

#a6width = 14.8*cm
#a6height = 10.5*cm
#size(a6width, a6height)
size(3000,1000)
fontSize = 100
# Description:
# Compare Lowercase Proportions to other fonts

# Credits:
# Pablo Impallari
# http://www.impallari.com

from robofab.world import OpenFont, CurrentFont
from robofab.interface.all.dialogs import Message

# La fuente seleccionada es la que se va a modificar
myfont = CurrentFont()


# Pregunta de que fuente quiero copiar las proporciones
orignalFont = OpenFont(None, "Which font's Proportions do you want?")
original = {}

# Rango de Glyphs que voy a medir
uppercase = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']

# Leo las n y obtengo el Ratio
original_n = orignalFont['n'].width
myfont_n = myfont['n'].width

# Leo la fuente de origen
for item in uppercase:
	if myfont.has_key(item):
		
		# Calculo Anchos
		ancho_original = orignalFont[item].width
Beispiel #29
0
#FLM: Check unopened font glyphs for MM
#
# Useful for testing to see if two fonts are compatible as as MM font

# First import OpenFont, which allows the user open a font file
# Also import RFont, so that a new font can be created
from robofab.world import OpenFont, RFont

# Get the two masters for the interpolated font
minFont = OpenFont(None, "First font")
maxFont = OpenFont(None, "Second font")

for glyph in minFont:
	data = glyph.isCompatible(maxFont.getGlyph(glyph.name), report=True)
	print glyph
	print data
print 'all done'
    restore()

from fontTools.pens.cocoaPen import CocoaPen
from robofab.world import OpenFont
import os

paths = []
for folder in folders:
    for root, dirs, files in os.walk(folder):
        for directory in dirs:
            if directory.endswith(".ufo"):
                paths.append(os.path.join(root, directory))

fonts = []
for path in paths:
    font = OpenFont(path)
    fonts.append(font)
    
skipCount = 0
frameCount = 0

for letter in letters:
    
    prevPoints = None
    for font in fonts:
        
        if font.has_key(letter):
            glyph = font[letter]
        else:
            continue
    
"""Correct contour direction for all glyphs in the font"""

from robofab.world import OpenFont
from robofab.interface.all.dialogs import ProgressBar

font = OpenFont()
bar = ProgressBar('Correcting contour direction...', len(font))
for glyph in font:
	bar.label(glyph.name)
	glyph.correctDirection()
	glyph.update()
	bar.tick()
font.update()
bar.close()
Beispiel #32
0
import os


paths = []
for f in AllFonts():
	paths.append(f.path)
	f.close()
	
for p in paths:
	ufoPath = p.replace(".vfb", ".ufo")
	if os.path.exists(ufoPath):
		# the ufo exists, only export the glyphs and the features
		print "There is a UFO for this font already, exporting glyphs."
		path = os.path.join(os.path.dirname(ufoPath), os.path.basename(ufoPath), "glyphs")
		f = OpenFont(p)
		
		fl.CallCommand(fl_cmd.FontSortByCodepage)

		gs = GlyphSet(path, glyphNameToFileNameFunc=glyphNameToShortFileName)
		for g in f:
			print "saving glyph %s in %s"%(g.name, path)
			gs.writeGlyph(g.name, g, g.drawPoints)
		gs.writeContents()

		# make a new writer
		u = UFOWriter(ufoPath)
		# font info
		print "exporting font info.."
		u.writeInfo(f.info)
		
Beispiel #33
0
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)
            orignalMetrics[glyph.name] = [glyphLeft, glyphRight]
            bar.tick(tick)
Beispiel #34
0
    def generateFont(self,
                     mix,
                     names,
                     italic=False,
                     swapSuffixes=None,
                     stemWidth=185,
                     italicMeanYCenter=-825,
                     italicNarrowAmount=1):

        n = names.split("/")
        log("---------------------\n%s %s\n----------------------" %
            (n[0], n[1]))
        log(">> Mixing masters")
        if isinstance(mix, Mix):
            f = mix.generateFont(self.basefont)
        else:
            f = mix.copy()

        if italic == True:
            log(">> Italicizing")
            i = 0
            for g in f:
                i += 1
                if i % 10 == 0: print g.name

                if g.name == "uniFFFD":
                    continue

                decomposeGlyph(f, g)
                removeGlyphOverlap(g)

                if g.name in self.lessItalic:
                    italicizeGlyph(f,
                                   g,
                                   9,
                                   stemWidth=stemWidth,
                                   meanYCenter=italicMeanYCenter,
                                   narrowAmount=italicNarrowAmount)
                elif g.name not in self.noItalic:
                    italicizeGlyph(f,
                                   g,
                                   10,
                                   stemWidth=stemWidth,
                                   meanYCenter=italicMeanYCenter,
                                   narrowAmount=italicNarrowAmount)
                if g.width != 0:
                    g.width += 10

            # set the oblique flag in fsSelection
            f.info.openTypeOS2Selection.append(9)

        if swapSuffixes != None:
            for swap in swapSuffixes:
                swapList = [g.name for g in f if g.name.endswith(swap)]
                for gname in swapList:
                    print gname
                    swapContours(f, gname.replace(swap, ""), gname)
        for gname in self.predecompose:
            if f.has_key(gname):
                decomposeGlyph(f, f[gname])

        log(">> Generating glyphs")
        generateGlyphs(f, self.diacriticList, self.adobeGlyphList)
        log(">> Copying features")
        readFeatureFile(f, self.basefont.features.text)
        log(">> Decomposing")
        for g in f:
            if len(g.components) > 0:
                decomposeGlyph(f, g)
        # for gname in self.decompose:
        #     if f.has_key(gname):
        #         decomposeGlyph(f, f[gname])

        copyrightHolderName = ''
        if self.config.has_option('main', 'copyrightHolderName'):
            copyrightHolderName = self.config.get('main',
                                                  'copyrightHolderName')

        def getcfg(name, fallback=''):
            if self.config.has_option('main', name):
                return self.config.get('main', name)
            else:
                return fallback

        setInfoRF(
            f, n, {
                'foundry': getcfg('foundry'),
                'foundryURL': getcfg('foundryURL'),
                'designer': getcfg('designer'),
                'copyrightHolderName': getcfg('copyrightHolderName'),
                'build': self.buildTag,
                'version': getcfg('version'),
                'license': getcfg('license'),
                'licenseURL': getcfg('licenseURL'),
            })

        if not self.compatible:
            cleanCurves(f)
        deleteGlyphs(f, self.deleteList)

        log(">> Generating font files")
        ufoName = self.generateOutputPath(f, "ufo")
        f.save(ufoName)
        self.generatedFonts.append(ufoName)

        if self.buildOTF:
            log(">> Generating OTF file")
            newFont = OpenFont(ufoName)
            otfName = self.generateOutputPath(f, "otf")
            saveOTF(newFont, otfName, self.glyphOrder)
Beispiel #35
0
    def generateFont(self,
                     mix,
                     names,
                     italic=False,
                     swapSuffixes=None,
                     stemWidth=185,
                     kern=True):

        n = names.split("/")
        log("---------------------\n%s %s\n----------------------" %
            (n[0], n[1]))
        log(">> Mixing masters")
        if isinstance(mix, Mix):
            f = mix.generateFont(self.basefont)
        else:
            f = mix.copy()
        if italic == True:
            log(">> Italicizing")
            tweakAmmount = .085
            narrowAmmount = .93
            if names.find("Thin") != -1:
                tweakAmmount = .05
            if names.find("Condensed") != -1:
                narrowAmmount = .96
            i = 0
            for g in f:
                i += 1
                if i % 10 == 0: print g.name

                if g.name == "uniFFFD":
                    continue

                removeGlyphOverlap(g)

                if g.name in self.lessItalic:
                    italicizeGlyph(f, g, 9, stemWidth=stemWidth)
                elif False == (g.name in self.noItalic):
                    italicizeGlyph(f, g, 10, stemWidth=stemWidth)
                #elif g.name != ".notdef":
                #    italicizeGlyph(g, 10, stemWidth=stemWidth)
                if g.width != 0:
                    g.width += 10

        if swapSuffixes != None:
            for swap in swapSuffixes:
                swapList = [g.name for g in f if g.name.endswith(swap)]
                for gname in swapList:
                    print gname
                    swapContours(f, gname.replace(swap, ""), gname)
        for gname in self.predecompose:
            if f.has_key(gname):
                decomposeGlyph(f, gname)

        log(">> Generating glyphs")
        generateGlyphs(f, self.diacriticList, self.adobeGlyphList)
        log(">> Copying features")
        readFeatureFile(f, self.ot_classes + self.basefont.features.text)
        log(">> Decomposing")
        for gname in self.decompose:
            if f.has_key(gname):
                decomposeGlyph(f, gname)

        setNamesRF(f,
                   n,
                   foundry=self.config.get('main', 'foundry'),
                   version=self.config.get('main', 'version'))
        if not self.compatible:
            cleanCurves(f)
        deleteGlyphs(f, self.deleteList)

        if kern:
            log(">> Generating kern classes")
            readFeatureFile(f, self.ot_kerningclasses)

        log(">> Generating font files")
        ufoName = self.generateOutputPath(f, "ufo")
        f.save(ufoName)
        self.generatedFonts.append(ufoName)

        if self.buildOTF:
            log(">> Generating OTF file")
            newFont = OpenFont(ufoName)
            otfName = self.generateOutputPath(f, "otf")
            saveOTF(newFont, otfName)
Beispiel #36
0
#!/usr/bin/python

from ufo2ft import compileTTF
from robofab.world import OpenFont

family = "Tonnelier"
weights = ["Regular", "Thin", "ThinItalic", "Light", "LightItalic", "Book", "BookItalic", "Medium", "MediumItalic", "Semibold", "SemiboldItalic", "Bold", "BoldItalic", "Heavy", "HeavyItalic"]

for w in weights:
    ufo = OpenFont("source/{}-{}.ufo".format(family, w))
    ttf = compileTTF(ufo, preProcessorClass=<class 'ufo2ft.preProcessor.TTFPreProcessor'>, outlineCompilerClass=<class 'ufo2ft.outlineCompiler.OutlineTTFCompiler'>, featureCompilerClass=<class 'ufo2ft.featureCompiler.FeatureCompiler'>, kernWriterClass=None, markWriterClass=None, featureWriters=None, glyphOrder=None, useProductionNames=None, convertCubics=True, cubicConversionError=None, reverseDirection=True, removeOverlaps=False, inplace=False),

    print ("Building " + "builds/{}-{}.ttf".format(family, w) + " from source file " + "source/{}-{}.ufo".format(family, w) + "...")
    ttf.save("builds/{}-{}.ttf".format(family, w))

print ("Done.")
def makeDestination(root):
    macPath = os.path.join(root, 'FabFonts', 'ForMac')
    makeFolder(macPath)
    return macPath


def generateOne(f, dstDir):
    print "generating %s" % f.info.fullName
    f.generate('otfcff', dstDir)


f = GetFolder()

if f is not None:
    paths = collectSources(f)
    dstDir = makeDestination(f)

    for f in paths:
        font = None
        print f
        try:
            font = OpenFont(f)
            generateOne(font, dstDir)

        finally:
            if font is not None:
                font.close(False)

    print 'done'
Beispiel #38
0
# robofab manual
# Fontlabremote howto
# usage examples

#FLM: Remove overlap from Remote Glyph.

from robofab.world import OpenFont
from robofab.tools.remote import transmitGlyph, receiveGlyph,
runFontLabRemote

# Pick a UFO font:
f = OpenFont()

print "Number of contours before", len(f['A'])

# call FontLab to make a new font
startNewFontCode = """from robofab.world import NewFont
f = NewFont()
f.info.fullName = 'Temporary Font generated by RoboFab Remote'"""

print runFontLabRemote(startNewFontCode)

# send a glyph to FontLab,
# it will be inserted in the CurrentFont.
transmitGlyph(f['A'])
f.removeGlyph('A')

# send instructions to remove overlap for this glyph
overlapCode = """from robofab.world import CurrentFont
from robofab.tools.remote import transmitGlyph
f = CurrentFont()
		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)
			orignalMetrics[glyph.name] = [glyphLeft, glyphRight]
			bar.tick(tick)
			tick = tick+1
def importUFO(ufoPath,
              newFile=True,
              saveFile=True,
              closeFile=True,
              doInfo=True,
              doKerning=True,
              doGroups=True,
              doLib=True,
              doFeatures=True,
              doHints=False,
              doMarks=True,
              doMasks=True,
              glyphs=None):
    # get the VFB path
    vfbPath = os.path.splitext(ufoPath)[0] + ".vfb"
    if not newFile:
        font = None
        for font in AllFonts():
            if font.path == vfbPath:
                break
        if font is None:
            if not os.path.exists(vfbPath):
                Message("Could not find the FontLab file \"%s\"." %
                        os.path.basename(vfbPath))
                return
            font = OpenFont(vfbPath)
    else:
        if saveFile:
            if os.path.exists(vfbPath):
                vfbPath = _findAvailablePathName(vfbPath)
        font = NewFont()
    # make the font the top font in FL
    fl.ifont = font.fontIndex
    # read the UFO
    font.readUFO(ufoPath,
                 doHints=doHints,
                 doInfo=doInfo,
                 doKerning=doKerning,
                 doGroups=doGroups,
                 doLib=doLib,
                 doFeatures=doFeatures,
                 glyphs=glyphs)
    # load the masks and marks
    if doMasks or doMarks:
        for glyph in font:
            lib = glyph.lib
            if doMarks:
                if lib.has_key(MARK_LIB_KEY):
                    glyph.mark = lib[MARK_LIB_KEY]
                    del lib[MARK_LIB_KEY]
            if doMasks:
                if lib.has_key(MASK_LIB_KEY):
                    # open a glyph window
                    fl.EditGlyph(glyph.index)
                    # switch to the mask layer
                    fl.CallCommand(fl_cmd.ViewEditMask)
                    # add the mask data
                    instructions = lib[MASK_LIB_KEY]
                    pen = glyph.getPointPen()
                    instructionsDrawPoints(instructions, pen)
                    # switch back to the edit layer
                    fl.CallCommand(fl_cmd.ViewEditMask)
                    # clear the mask data from the glyph lib
                    del lib[MASK_LIB_KEY]
        # close all glyph windows. sometimes this actually works.
        fl.CallCommand(fl_cmd.WindowCloseAllGlyphWindows)
    # load the WWS names
    if doInfo:
        info = readPlist(os.path.join(ufoPath, "fontInfo.plist"))
        if "openTypeNameWWSFamilyName" in info:
            font.lib[WWS_FAMILY_KEY] = info["openTypeNameWWSFamilyName"]
        elif "openTypeNameWWSFamilyName" in font.lib:
            del font.lib[WWS_FAMILY_KEY]
        if "openTypeNameWWSSubfamilyName" in info:
            font.lib[WWS_SUBFAMILY_KEY] = info["openTypeNameWWSSubfamilyName"]
        elif "openTypeNameWWSSubfamilyName" in font.lib:
            del font.lib[WWS_SUBFAMILY_KEY]
    # update the font
    font.update()
    # save and close
    if saveFile:
        font.save(vfbPath)
        if closeFile:
            font.close()
from robofab.world import OpenFont

path = "MyDrive/Folder1/Work/somefile"
f = OpenFont(path)
# hey look! it opens the file without asking..
print f
Beispiel #42
0
# robofab manual
# Interpolate howto
# Straight Interpolating examples

from robofab.world import OpenFont
minFont = OpenFont(pathToMinFont)
maxFont = OpenFont(pathToMaxFont)
# or any other way you like to get two font objects
 
inbetweenFont = OpenFont(pathToInbetweenFont)
# so now we have 3 font objects, right?
 
inbetweenFont.interpolate(.5, minFont, maxFont)
# presto, inbetweenFont is now 50% of one and 50% of the other
 
inbetweenFont.interpolate((.92, .12), minFont, maxFont)
# presto, inbetweenFont is now horizontally
# vertically interpolated in different ways.
Beispiel #43
0
                kerningValue = 0
                wordLetterOffset = 0
                yAdvance += (UPM*_line_Height)*sc
                previousGlyph = None
                previousGlyphGroups = None
            
            restore()
            
            glyphStop = time()
            glyphDrawingTime += (glyphStop-glyphStart) * 1000
            
        print 'average glyph drawing %0.2f ms, total %0.2f ms, %s glyphs drawn' % (glyphDrawingTime/nbrOfGlyphs, glyphDrawingTime, nbrOfGlyphs)

from robofab.world import OpenFont    

thisFont = OpenFont(ufoPath) 

typeSetter = TypeSetter(thisFont)
typeSetter.canvas['margins'] = margins
typeSetter.canvas['preset'](preset)

typeSetter.type['size'] = pointSize
typeSetter.type['_line_Height'] = _line_Height
typeSetter.type['tracking'] = tracking
typeSetter.type['color'] = color
typeSetter.type['alpha'] = alpha

typeSetter.settings['suffix'] = suffix
typeSetter.settings['infoFont'] = infoFont
typeSetter.settings['useKerning'] = useKerning
typeSetter.settings['showKerning'] = showKerning
	if not os.path.exists(path):
		os.makedirs(path)

def makeDestination(root):
	macPath = os.path.join(root, 'FabFonts', 'ForMac')
	makeFolder(macPath)
	return macPath

def generateOne(f, dstDir):
	print "generating %s"%f.info.postscriptFullName
	f.generate('mactype1',  dstDir)
	

f = GetFolder()

if f is not None:
	paths = collectSources(f)
	dstDir = makeDestination(f)

	for f in paths:
		font = None
		try:
			font = OpenFont(f)
			generateOne(font, dstDir)

		finally:
			if font is not None:
				font.close(False)


	print 'done'