Exemplo n.º 1
0
 def testTwoUntitledFonts(self):
     font1 = NewFont()
     font2 = NewFont()
     font1.unitsPerEm = 1024
     font2.unitsPerEm = 2048
     self.assertNotEqual(font1.unitsPerEm, font2.unitsPerEm)
     font1.update()
     font2.update()
     font1.close(False)
     font2.close(False)
Exemplo n.º 2
0
class FontStructionHandler(ContentHandler):
    """FSML parser"""
    def __init__(self):
        print 'FSML parser'

    def startElement(self, name, attrs):
        if name == 'fontstruction':
            print "parsing fsml..."
            # font info
            self.name = attrs.get('name')
            self.brick_scale_x = attrs.get('brick_scale_x')
            self.brick_scale_y = attrs.get('brick_scale_y')
            self.grid_scale_x = attrs.get('grid_scale_x')
            self.grid_scale_xgrid_scale_y = attrs.get(
                'grid_scale_xgrid_scale_y')
            self.spacing = attrs.get('spacing')
            # glyphs
            self.glyphs = {}
            self.glyphCount = 0
            self._tmpGlyph = ""
            # bricks
            self.bricks = {}
            self.brickCount = 0
            # slots
            self.slots = {}
        elif name == 'glyph':
            glyphID = attrs.get('id')
            self.glyphs[glyphID] = {}
            self.glyphs[glyphID]['codepoint'] = attrs.get('codepoint')
            self.glyphs[glyphID]['nodes'] = []
            self._tmpGlyph = glyphID
        elif name == 'node':
            glyphID = self._tmpGlyph
            br = attrs.get('br')
            x = attrs.get('x')
            y = attrs.get('y')
            self.glyphs[glyphID]['nodes'].append([str(br), (int(x), int(y))])
        elif name == 'brick':
            brickID = attrs.get('id')
            self.bricks[brickID] = {}
            self.bricks[brickID]['name'] = attrs.get('name')
            self.bricks[brickID]['contours'] = attrs.get('contours')
            self.bricks[brickID]['user_id'] = attrs.get('user_id')
        elif name == 'palette_slot':
            brickPos = attrs.get('pos')
            self.slots[brickPos] = {}
            self.slots[brickPos]['brick_id'] = attrs.get('brick_id')
            self.slots[brickPos]['id'] = attrs.get('id')

    def endElement(self, name):
        if name == 'glyph':
            self.glyphCount = self.glyphCount + 1
        if name == "fontstruction":
            print "...done."

    def printInfo(self):
        print "FontStruction name: %s" % self.name
        print "brick scale: %s, %s" % (self.brick_scale_x, self.brick_scale_y)
        print "glyphs: %s" % len(self.glyphs)

    def printGlyphs(self):
        for g in self.glyphs.keys():
            print "glyph: %s" % g
            print "codepoint: %s" % self.glyphs[g]['codepoint']
            print "nodes: %s" % self.glyphs[g]['nodes']
            print

    def printBricks(self):
        for b in self.bricks.keys():
            print "brick: %s" % b
            print "id: %s" % self.bricks[b]['id']
            print "contours: %s" % self.bricks[b]['contours']
            print

    def createUFO(self):
        # create new font
        self.f = NewFont()
        self.f.info.familyName = str(self.name)

    def importBricks(self):
        for brickID in self.bricks.keys():
            # create element glyph
            gName = "element_%s" % str(brickID)
            self.f.newGlyph(gName, clear=True)
            self.f[gName].note = self.bricks[brickID]['name']
            # get pen
            pen = self.f[gName].getPen()
            # parse SVG & draw with pen
            svgSource = self.bricks[brickID]['contours']
            s = svgImporter(svgSource)
            for command in s._svg:
                svgCommand = command[0]
                points = command[1]
                if svgCommand == "M" or svgCommand == "m":
                    pen.moveTo(points[0])
                elif svgCommand == "L" or svgCommand == "l":
                    pen.lineTo(points[0])
                elif svgCommand == "Q" or svgCommand == "q":
                    pen.qCurveTo(*points)
            pen.closePath()
            # scale & colorize bricks
            self.f[gName].scale((.125, .125))
            #self.f[gName].mark = 30
            self.f[gName].update()

    def parseGlyphs(self):
        missingBricks = []
        eSize = 125
        for g in self.glyphs.keys():
            uni = int(self.glyphs[g]['codepoint'])
            # create empty glyph
            if unicode2psnames.has_key(uni):
                gName = unicode2psnames[uni]
                self.f.newGlyph(gName, clear=True)
                # append modules
                for node in self.glyphs[g]['nodes']:
                    x, y = node[1][0] * eSize, node[1][1] * eSize
                    zeroPos = str(int(node[0]) + 1)
                    brickPos = zeroPos
                    if self.slots.has_key(brickPos):
                        componentName = "element_%s" % str(
                            self.slots[brickPos]['brick_id'])
                        #self.f[componentName].mark = 170
                        self.f[componentName].update()
                        # append component
                        self.f[gName].appendComponent(componentName, (x, y))
                        self.f[gName].update()
                    else:
                        if brickPos not in missingBricks:
                            missingBricks.append(brickPos)
        self.f.update()
        print "missing bricks: %s" % missingBricks
Exemplo n.º 3
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!'
Exemplo n.º 4
0
# robothon 2006
# batch interpolate

import os
from robofab.world import SelectFont, NewFont

# ask for two masters to interpolate:
font1 = SelectFont("Select font 1")
font2 = SelectFont("Select font 2")
# these are the interpolation factors:
values = [.3, .6]

for value in values:
    # make a new font
    destination = NewFont()
    # do the interpolation
    destination.interpolate(value, font1, font2, doProgress=True)
    destination.update()
    # make a new path + filename for the new font to be saved at:
    dir = os.path.dirname(font1.path)
    fileName = "Demo_%d.vfb" % (1000 * value)
    # save at this path and close the font
    destination.save(os.path.join(dir, fileName))
    destination.close()
Exemplo n.º 5
0
def globUFO(dir, filter=None):
	"""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!'
Exemplo n.º 6
0
        selName = OneList(common, 'Select a glyph:')
        if selName:
            dest = NewFont()
            g1 = src1[selName]
            g2 = src2[selName]
            count = 1
            bar = ProgressBar('Interpolating...', 100)
            # add the sourec one glyph for reference
            dest.newGlyph(selName + '_000')
            dest[selName + '_000'].width = src1[selName].width
            dest[selName + '_000'].appendGlyph(src1[selName])
            dest[selName + '_000'].mark = 1
            dest[selName + '_000'].update()
            # add a new glyph and interpolate it
            while count != 100:
                factor = count * .01
                newName = selName + '_' + ` count `.zfill(3)
                gD = dest.newGlyph(newName)
                gD.interpolate(factor, g1, g2)
                gD.update()
                bar.tick()
                count = count + 1
            # add the source two glyph for reference
            dest.newGlyph(selName + '_100')
            dest[selName + '_100'].width = src2[selName].width
            dest[selName + '_100'].appendGlyph(src2[selName])
            dest[selName + '_100'].mark = 1
            dest[selName + '_100'].update()
            dest.update()
            bar.close()
Exemplo n.º 7
0
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
    dst.info.autoNaming()
    dst.update()
    fileName = dst.info.familyName + "-" + dst.info.styleName + ".vfb"
    path = os.path.join(where, fileName)
    print 'saving at', path
    dst.save(path)
    dst.close()
Exemplo n.º 8
0
class FontStructionHandler(ContentHandler):

    '''FSML parser'''

    def __init__ (self):
        print 'FSML parser'

    def startElement(self, name, attrs):
        if name == 'fontstruction':
            print "parsing fsml..."
            # font info
            self.name = attrs.get('name')
            self.brick_scale_x = attrs.get('brick_scale_x')
            self.brick_scale_y = attrs.get('brick_scale_y')
            self.grid_scale_x = attrs.get('grid_scale_x')
            self.grid_scale_xgrid_scale_y = attrs.get('grid_scale_xgrid_scale_y')
            self.spacing = attrs.get('spacing')
            # glyphs
            self.glyphs = {}
            self.glyphCount = 0
            self._tmpGlyph = ""
            # bricks
            self.bricks = {}
            self.brickCount = 0
            # slots
            self.slots = {}
        elif name == 'glyph':
            glyphID = attrs.get('id')
            self.glyphs[glyphID] = {}
            self.glyphs[glyphID]['codepoint'] = attrs.get('codepoint')
            self.glyphs[glyphID]['nodes'] = [ ]
            self._tmpGlyph = glyphID
        elif name == 'node':
            glyphID = self._tmpGlyph
            br = attrs.get('br')
            x = attrs.get('x')
            y = attrs.get('y')
            self.glyphs[glyphID]['nodes'].append( [ str(br), ( int(x), int(y) ) ] )
        elif name == 'brick':
            brickID = attrs.get('id')
            self.bricks[brickID] = {}
            self.bricks[brickID]['name'] = attrs.get('name')
            self.bricks[brickID]['contours'] = attrs.get('contours')
            self.bricks[brickID]['user_id'] = attrs.get('user_id')
        elif name == 'palette_slot':
            brickPos = attrs.get('pos')
            self.slots[brickPos] = {}
            self.slots[brickPos]['brick_id'] = attrs.get('brick_id')
            self.slots[brickPos]['id'] = attrs.get('id')

    def endElement(self, name):
        if name == 'glyph':
            self.glyphCount = self.glyphCount + 1
        if name == "fontstruction":
            print "...done."

    def printInfo(self):
        print "FontStruction name: %s" % self.name
        print "brick scale: %s, %s" % ( self.brick_scale_x, self.brick_scale_y )
        print "glyphs: %s"  % len(self.glyphs)

    def printGlyphs(self):
        for g in self.glyphs.keys():
            print "glyph: %s" % g
            print "codepoint: %s" % self.glyphs[g]['codepoint']
            print "nodes: %s" % self.glyphs[g]['nodes']
            print

    def printBricks(self):
        for b in self.bricks.keys():
            print "brick: %s" % b
            print "id: %s" % self.bricks[b]['id']
            print "contours: %s" % self.bricks[b]['contours']
            print

    def createUFO(self):
        # create new font
        self.f = NewFont()
        self.f.info.familyName = str(self.name)

    def importBricks(self):
        for brickID in self.bricks.keys():
            # create element glyph
            gName = "element_%s" % str(brickID)
            self.f.newGlyph(gName, clear=True)
            self.f[gName].note = self.bricks[brickID]['name']
            # get pen
            pen = self.f[gName].getPen()
            # parse SVG & draw with pen
            svgSource= self.bricks[brickID]['contours']
            s = svgImporter(svgSource)
            for command in s._svg:
                svgCommand = command[0]
                points = command[1]
                if svgCommand == "M" or svgCommand == "m":
                    pen.moveTo( points[0] )
                elif svgCommand == "L" or svgCommand == "l":
                    pen.lineTo( points[0] )
                elif svgCommand == "Q" or svgCommand == "q":
                    pen.qCurveTo( *points )
            pen.closePath()
            # scale & colorize bricks
            self.f[gName].scale((.125, .125))
            #self.f[gName].mark = 30
            self.f[gName].update()

    def parseGlyphs(self):
        missingBricks = []
        eSize= 125
        for g in self.glyphs.keys():
            uni = int(self.glyphs[g]['codepoint'])
            # create empty glyph
            if unicode2psnames.has_key(uni):
                gName = unicode2psnames[uni]
                self.f.newGlyph(gName, clear=True)
                # append modules
                for node in self.glyphs[g]['nodes']:
                    x, y = node[1][0]*eSize, node[1][1]*eSize
                    zeroPos = str(int(node[0])+1)
                    brickPos = zeroPos
                    if self.slots.has_key(brickPos):
                        componentName = "element_%s" % str(self.slots[brickPos]['brick_id'])
                        #self.f[componentName].mark = 170
                        self.f[componentName].update()
                        # append component
                        self.f[gName].appendComponent(componentName, (x, y))
                        self.f[gName].update()
                    else:
                        if brickPos not in missingBricks:
                            missingBricks.append(brickPos)
        self.f.update()
        print "missing bricks: %s" % missingBricks
Exemplo n.º 9
0
		selName = OneList(common, 'Select a glyph:')
		if selName:
			dest = NewFont()
			g1 = src1[selName]
			g2 = src2[selName]
			count = 1
			bar = ProgressBar('Interpolating...', 100)
			# add the sourec one glyph for reference
			dest.newGlyph(selName + '_000')
			dest[selName + '_000'].width = src1[selName].width
			dest[selName + '_000'].appendGlyph(src1[selName])
			dest[selName + '_000'].mark = 1
			dest[selName + '_000'].update()
			# add a new glyph and interpolate it
			while count != 100:
				factor = count * .01
				newName = selName + '_' + `count`.zfill(3)
				gD = dest.newGlyph(newName)
				gD.interpolate(factor, g1, g2)
				gD.update()
				bar.tick()
				count = count + 1
			# add the source two glyph for reference
			dest.newGlyph(selName + '_100')
			dest[selName + '_100'].width = src2[selName].width
			dest[selName + '_100'].appendGlyph(src2[selName])
			dest[selName + '_100'].mark = 1
			dest[selName + '_100'].update()		
			dest.update()
			bar.close()
Exemplo n.º 10
0
# robothon06
# interpolate two fonts

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

font1 = SelectFont("Select font 1")
font2 = SelectFont("Select font 2")

value = AskString("What percentage?")
value = int(value) * .01

destination = NewFont()

# this interpolates the glyphs
destination.interpolate(value, font1, font2, doProgress=True)

# this interpolates the kerning
# comment this line out of you're just testing
destination.kerning.interpolate(font1.kerning, font2.kerning, value)

destination.update()