Example #1
0
def main():
	# open the source font
	f = ttLib.TTFont("NyanTemplate.ttf")

	# mapping of image size to directory name
	sets = {
		15: "pngs"
	}

	sbix = ttLib.newTable("sbix")
	go = f.getGlyphOrder()

	for s, d in sets.iteritems():
		# make an empty bitmap set for current image size
		mySet = BitmapSet(size=s)
		for root, dirs, files in walk(d, topdown=False):
			for myFile in files:
				if myFile[-4:] == ".png":
					# use file name without suffix as glyph name
					# FIXME: filename clashes with case-sensitive glyph names
					glyphname = myFile[:-4]
					if glyphname in go: # only use files that have a matching glyph in the source font
						print glyphname
						img = open(join(root, myFile), "rb")
						imgData = img.read()
						img.close()
						# make a bitmap record for the current image
						myBitmap = Bitmap(glyphName=glyphname, imageFormatTag="png ", imageData=imgData)
						# add bitmap to current bitmap set
						mySet.bitmaps[glyphname] = myBitmap
		sbix.bitmapSets[s] = mySet
	# add sbix table to the source font
	f["sbix"] = sbix
	# save font under new name
	f.save("Nyan.ttf")
Example #2
0
def main():
    # open the source font
    f = ttLib.TTFont(sys.argv[1]) #Arg 1 = Original Font Location

    resolutions = sys.argv[3]
    resolutionsList = resolutions.split(",")

    sets = {}
    for resolution in resolutionsList:
        sets[int(resolution)] = sys.argv[2]+"/set_"+resolution

    sbix = ttLib.newTable("sbix")
    go = f.getGlyphOrder()

    for s, d in sets.iteritems():
        # make an empty bitmap set for current image size
        mySet = BitmapSet(size=s)
        for root, dirs, files in walk(d, topdown=False):
            for myFile in files:
                if myFile[-4:] == ".png":
                    # use file name without suffix as glyph name
                    # FIXME: filename clashes with case-sensitive glyph names
                    glyphname = myFile[:-4]
                    if glyphname in go:  # only use files that have a matching glyph in the source font
                        print glyphname
                        img = open(join(root, myFile), "rb")
                        imgData = img.read()
                        img.close()
                        # make a bitmap record for the current image
                        myBitmap = Bitmap(glyphName=glyphname, imageFormatTag="png ", imageData=imgData)
                        # add bitmap to current bitmap set
                        mySet.bitmaps[glyphname] = myBitmap
        sbix.bitmapSets[s] = mySet
    # add sbix table to the source font
    f["sbix"] = sbix
    # save font under new name
    f.save(sys.argv[2]+"/[email protected]") #Arg 2 = Output Directory Location