예제 #1
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()
예제 #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()
예제 #3
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()
예제 #4
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()