Beispiel #1
0
def exportGlyphs(font, glyphs=None, dest=None, doProgress=True, bar=None):
    """Export all glyphs in a FontLab font"""
    if dest is None:
        dir, base = os.path.split(font.file_name)
        base = base.split(".")[0] + ".glyphs"
        dest = os.path.join(dir, base)

    if not os.path.exists(dest):
        os.makedirs(dest)

    glyphSet = GlyphSet(dest)

    if glyphs is None:
        indices = range(len(font))
    else:
        indices = []
        for glyphName in glyphs:
            indices.append(font.FindGlyph(glyphName))
    barStart = 0
    closeBar = False
    if doProgress:
        if not bar:
            bar = ProgressBar("Exporting Glyphs", len(indices))
            closeBar = True
        else:
            barStart = bar.getCurrentTick()
    else:
        bar = None
    try:
        done = {}
        for i in range(len(indices)):
            #if not (i % 10) and not bar.tick(i + barStart):
            #	raise KeyboardInterrupt
            index = indices[i]
            flGlyph = font[index]
            if flGlyph is None:
                continue
            glyphName = flGlyph.name
            if not glyphName:
                print "can't dump glyph #%s, it has no glyph name" % i
            else:
                if glyphName in done:
                    n = 1
                    while ("%s#%s" % (glyphName, n)) in done:
                        n += 1
                    glyphName = "%s#%s" % (glyphName, n)
                done[glyphName] = None
                exportGlyph(glyphName, flGlyph, glyphSet)
            if bar and not i % 10:
                bar.tick(barStart + i)
        # Write out contents.plist
        glyphSet.writeContents()
    except KeyboardInterrupt:
        if bar:
            bar.close()
            bar = None
    if bar and closeBar:
        bar.close()
Beispiel #2
0
def exportGlyphs(font, glyphs=None, dest=None, doProgress=True, bar=None):
	"""Export all glyphs in a FontLab font"""
	if dest is None:
		dir, base = os.path.split(font.file_name)
		base = base.split(".")[0] + ".glyphs"
		dest = os.path.join(dir, base)
	
	if not os.path.exists(dest):
		os.makedirs(dest)

	glyphSet = GlyphSet(dest)
	
	if glyphs is None:
		indices = range(len(font))
	else:
		indices = []
		for glyphName in glyphs:
			indices.append(font.FindGlyph(glyphName))
	barStart = 0
	closeBar = False
	if doProgress:
		if not bar:
			bar = ProgressBar("Exporting Glyphs", len(indices))
			closeBar = True
		else:
			barStart = bar.getCurrentTick()
	else:
		bar = None
	try:
		done = {}
		for i in range(len(indices)):
			#if not (i % 10) and not bar.tick(i + barStart):
			#	raise KeyboardInterrupt
			index = indices[i]
			flGlyph = font[index]
			if flGlyph is None:
				continue
			glyphName = flGlyph.name
			if not glyphName:
				print "can't dump glyph #%s, it has no glyph name" % i
			else:
				if glyphName in done:
					n = 1
					while ("%s#%s" % (glyphName, n)) in done:
						n += 1
					glyphName = "%s#%s" % (glyphName, n)
				done[glyphName] = None
				exportGlyph(glyphName, flGlyph, glyphSet)
			if bar and not i % 10:
				bar.tick(barStart + i)
		# Write out contents.plist
		glyphSet.writeContents()
	except KeyboardInterrupt:
		if bar:
			bar.close()
			bar = None
	if bar and closeBar:
		bar.close()
Beispiel #3
0
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()

print 'done'
Beispiel #4
0
"""Read all glyphs from the demo font, and write them out again.
This is useful for testing round-tripping stability, but also to
update the font when the GLIF format changes. The third application
is to update the contents.plist file in case glyphs have been added
or removed.
"""

import os
from robofab.test.testSupport import getDemoFontPath
from robofab.glifLib import GlyphSet
from robofab.pens.adapterPens import GuessSmoothPointPen

ufoPath = getDemoFontPath()
glyphSet = GlyphSet(os.path.join(ufoPath, "glyphs"))
glyphSet.rebuildContents(
)  # ignore existing contents.plist, rebuild from dir listing
for name in glyphSet.keys():
    g = glyphSet[name]
    g.drawPoints(None)  # force all attrs to be loaded

    def drawPoints(pen):
        pen = GuessSmoothPointPen(pen)
        g.drawPoints(pen)

    glyphSet.writeGlyph(name, g, drawPoints)

glyphSet.writeContents()  # write out contents.plist
Beispiel #5
0
"""Read all glyphs from the demo font, and write them out again.
This is useful for testing round-tripping stability, but also to
update the font when the GLIF format changes. The third application
is to update the contents.plist file in case glyphs have been added
or removed.
"""


import os
from robofab.test.testSupport import getDemoFontPath
from robofab.glifLib import GlyphSet
from robofab.pens.adapterPens import GuessSmoothPointPen

ufoPath = getDemoFontPath()
glyphSet = GlyphSet(os.path.join(ufoPath, "glyphs"))
glyphSet.rebuildContents()  # ignore existing contents.plist, rebuild from dir listing
for name in glyphSet.keys():
	g = glyphSet[name]
	g.drawPoints(None)  # force all attrs to be loaded
	def drawPoints(pen):
		pen = GuessSmoothPointPen(pen)
		g.drawPoints(pen)
	glyphSet.writeGlyph(name, g, drawPoints)

glyphSet.writeContents()  # write out contents.plist