Esempio n. 1
0
def getSaveLocation(font, fontType):
    path = GetFolder("Pick a directory...")
    if path:
        return checkPath(path, fontType)
    else:
        closeFont(font)
        return None
Esempio n. 2
0
    def startDialog(self):

        # Welcome message!
        Message("Hi! My name is typeStats.")

        # Mode
        verboso = AskYesNoCancel("Do you prefer the verbose mode?",
                                 title='typeStats',
                                 default=0)

        # Search path
        folder = GetFolder("Choose the directory to analyze")

        return folder, verboso
Esempio n. 3
0
def OpenFont(path=None, note=None):
    """Open a font from a path. If path is not given, present the user with a dialog."""
    if not note:
        note = 'select a .ufo directory'
    if not path:
        from robofab.interface.all.dialogs import GetFolder
        path = GetFolder(note)
    if path:
        try:
            return RFont(path)
        except OSError:
            from robofab.interface.all.dialogs import Message
            Message(
                "%s is not a valid .UFO font. But considering it's all XML, why don't  you have a look inside with a simple text editor."
                % (path))
    else:
        return None
Esempio n. 4
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)
Esempio n. 5
0
	#Build the fonts
	if numberOfAxis is 1:
		style = combinations(axisInFont[axisTypesInOrder[0]])
	if numberOfAxis is 2:
		style = combinations(axisInFont[axisTypesInOrder[0]], axisInFont[axisTypesInOrder[1]])
	if numberOfAxis is 3:
		style = combinations(axisInFont[axisTypesInOrder[0]], axisInFont[axisTypesInOrder[1]], axisInFont[axisTypesInOrder[2]])
	if numberOfAxis is 4:
		style = combinations(axisInFont[axisTypesInOrder[0]], axisInFont[axisTypesInOrder[1]], axisInFont[axisTypesInOrder[2]], axisInFont[axisTypesInOrder[3]])
	
	
	#location for generated fonts
	howManyFiles = TwoChecks('Generate Font File', 'Generate Fontlab File')
	if howManyFiles is not 2:
		fontType = getFontFileType()
	path = GetFolder("Pick a directory...")
	if path:
		if os.path.isfile(path):
			dir, fileName = os.path.split(path)
		else:
			dir = path
		for i in style:
			f = generateInstance(i, len(axisTypesInOrder), family, axisTypesInOrder, fontMM)
			addOpenTypeFeatures(fontMM, f)
			fl.Add(f)
			# Export
			if howManyFiles is 1:
				path = os.sep.join([dir, f.font_name])
				fl.GenerateFont(fontType, path)
				f.modified = 0
				fl.Close(fl.ifont)
Esempio n. 6
0
    """Collect paths for all ufos in dir.
	Check for nested dirs.
	Optionally, select only ufos which match a filter string.
	"""
    ufo = []
    names = os.listdir(dir)
    for n in names:
        p = os.path.join(dir, n)
        if n[-4:] == ".ufo":
            if filter is not None:
                if dir.find(filter) <> -1:
                    ufo.append(p)
            else:
                ufo.append(p)
            continue
        if os.path.isdir(p):
            ufo += globUFO(p, filter)
    return ufo


dir = GetFolder()
ufo = globUFO(dir)

for path in ufo:
    font = NewFont()
    font.readUFO(path, doProgress=True)
    font.update()
    vfbPath = path[:-4] + ".vfb"
    font.save(vfbPath)
print 'DONE!'
Esempio n. 7
0
	extension = extension.lower()
	files = []
	# the os module has tools to deal with
	# the operating system. This returns a list of names
	# of stuff in the folder you feed it:
	names = os.listdir(someFolder)
	for n in names:
			p = os.path.join(someFolder, n)
			# if this new thing is a folder itself,
			# call this function again, but now with the
			# new path to check that as well. This is
			# called recursion.
			if os.path.isdir(p):
				# add the results of the other folder
				# to the list
				files += walk(p, extension)
				continue
			# is it a file with the extension we want?
			# add it then!
			if n.lower().find(extension) <> -1:
				files.append(p)
	return files


yourFolder = GetFolder("Search a folder:")
if yourFolder is not None:
	fontPaths = walk(yourFolder, ".vfb")
	for path in fontPaths:
		OpenFont(path)
		
Esempio n. 8
0
todo = f.selection
print "selection", todo
if g is not None:
	todo.append(g.name)
		
for f in AllFonts():
	ufoPath = None
	print "f.path", f, f.path
	if f.path is None:
		# huh, in case there is a ghost font.
		print "skipping", f
		continue
	ufoPath = f.path.replace(".vfb", ".ufo")
	if not os.path.exists(ufoPath):
		ufoPath = GetFolder("Select a UFO to save the GLIF in:")
		if ufoPath.find(".ufo") == -1:
			Message("You need to select an UFO. Quitting.")
			ufoPath = None
	if ufoPath is None:
		continue
	for c in todo:
		if c not in f:
			print "font is missing", c
			continue
		g = f[c]
		path = os.path.join(os.path.dirname(ufoPath), os.path.basename(ufoPath), "glyphs")
		print "saving glyph %s in %s"%(g.name, path)
		gs = GlyphSet(path, glyphNameToFileNameFunc=glyphNameToShortFileName)
		gs.writeGlyph(g.name, g, g.drawPoints)
		gs.writeContents()
    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.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)
Esempio n. 10
0
# robothon 2006
# batch save as

import os
from robofab.world import AllFonts
from robofab.interface.all.dialogs import GetFolder

path = GetFolder()
if path:
    for font in AllFonts():
        fileName = os.path.basename(font.path)
        newPath = os.path.join(path, fileName)
        font.save(newPath)
Esempio n. 11
0
def importAllGlifFiles(font, dirName=None, doProgress=True, bar=None):
    """import all GLIFs into a FontLab font"""
    if dirName is None:
        if font.file_name:
            dir, base = os.path.split(font.file_name)
            base = base.split(".")[0] + ".glyphs"
            dirName = os.path.join(dir, base)
        else:
            dirName = GetFolder("Please select a folder with .glif files")
    glyphSet = GlyphSet(dirName)
    glyphNames = glyphSet.keys()
    glyphNames.sort()
    barStart = 0
    closeBar = False
    if doProgress:
        if not bar:
            bar = ProgressBar("Importing Glyphs", len(glyphNames))
            closeBar = True
        else:
            barStart = bar.getCurrentTick()
    else:
        bar = None
    try:
        for i in range(len(glyphNames)):
            #if not (i % 10) and not bar.tick(barStart + i):
            #	raise KeyboardInterrupt
            glyphName = glyphNames[i]
            flGlyph = NewGlyph(font, glyphName, clear=True)
            pen = FLPointPen(flGlyph)
            glyph = GlyphPlaceholder()
            glyphSet.readGlyph(glyphName, glyph, pen)
            if hasattr(glyph, "width"):
                flGlyph.width = int(round(glyph.width))
            if hasattr(glyph, "unicodes"):
                flGlyph.unicodes = glyph.unicodes
            if hasattr(glyph, "note"):
                flGlyph.note = glyph.note  # XXX must encode
            if hasattr(glyph, "lib"):
                from cStringIO import StringIO
                from robofab.plistlib import writePlist
                lib = glyph.lib
                if lib:
                    if len(lib
                           ) == 1 and "org.robofab.fontlab.customdata" in lib:
                        data = lib["org.robofab.fontlab.customdata"].data
                    else:
                        f = StringIO()
                        writePlist(glyph.lib, f)
                        data = f.getvalue()
                    flGlyph.customdata = data
            # XXX the next bit is only correct when font is the current font :-(
            fl.UpdateGlyph(font.FindGlyph(glyphName))
            if bar and not i % 10:
                bar.tick(barStart + i)
    except KeyboardInterrupt:
        if bar:
            bar.close()
            bar = None
    fl.UpdateFont(FontIndex(font))
    if bar and closeBar:
        bar.close()
# [h] export RF preferences

import os
from mojo.UI import exportPreferences
from robofab.interface.all.dialogs import GetFolder

file_name = 'prefs'
file_folder = GetFolder()

if file_folder is not None:
    file_path = os.path.join(file_folder, file_name)
    print('saving preferences to %s...' % file_path)
    exportPreferences(file_path)
Esempio n. 13
0
# robothon06
# interpolate two fonts with a series of factors.
# for each factor create a new font file.

import os
from robofab.world import SelectFont, NewFont
from robofab.interface.all.dialogs import AskString, GetFolder

font1 = SelectFont("Select font 1")
font2 = SelectFont("Select font 2")
where = GetFolder("Select a folder to save the interpolations")

instances = [
    ("Light", 0),
    ("NotTooLight", 0.25),
    ("Regular", 0.5),
    ("Demi", 0.75),
    ("Medium", 1),
]

for thing in instances:
    name, value = thing
    print "generating", name, value
    dst = NewFont()
    # this interpolates the glyphs
    dst.interpolate(value, font1, font2, doProgress=True)
    # this interpolates the kerning
    # comment this line out of you're just testing
    #dst.kerning.interpolate(font1.kerning, font2.kerning, value)
    dst.info.familyName = "MyBigFamily"
    dst.info.styleName = name
Esempio n. 14
0
            currentNo = str(SerialDump[x])
            makeDestination(f, currentNo)

            for i in paths:

                instanceFolder, instanceName = os.path.split(i)
                q = TTFont(i)

                serialfolder = instanceFolder + "/Serialized/" + currentNo + "/"
                savetemp = serialfolder + instanceName + "-" + currentNo + ".ttx"
                savetemp = savetemp.replace(".otf", "")
                newfile = serialfolder + instanceName.replace(".otf", ".ttx")
                q.saveXML(savetemp)

                seriaLize(savetemp, currentNo)

                os.rename(savetemp, newfile)
                stderr, stdout = executeCommand(['ttx', newfile])
                os.remove(newfile)

                #print i, "finished serializing as", currentNo


# select fonts
f = GetFolder("Select Folder")

# run shit
doStuff(f)

notify("Ventriloquist is Done", "", "Check your output folders")
Esempio n. 15
0
#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'