예제 #1
0
	def testWrite(self):
		infoObject = self.makeInfoObject()
		writer = UFOWriter(self.dstDir, formatVersion=1)
		writer.writeInfo(infoObject)
		writtenData = self.readPlist()
		for attr, originalValue in list(fontInfoVersion1.items()):
			newValue = writtenData[attr]
			self.assertEqual(newValue, originalValue)
예제 #2
0
 def testWrite(self):
     infoObject = self.makeInfoObject()
     writer = UFOWriter(self.dstDir, formatVersion=1)
     writer.writeInfo(infoObject)
     writtenData = self.readPlist()
     for attr, originalValue in list(fontInfoVersion1.items()):
         newValue = writtenData[attr]
         self.assertEqual(newValue, originalValue)
예제 #3
0
	def testFontStyleConversion(self):
		fontStyle1To2 = {
			64 : "regular",
			1  : "italic",
			32 : "bold",
			33 : "bold italic"
		}
		for old, new in list(fontStyle1To2.items()):
			infoObject = self.makeInfoObject()
			infoObject.styleMapStyleName = new
			writer = UFOWriter(self.dstDir, formatVersion=1)
			writer.writeInfo(infoObject)
			writtenData = self.readPlist()
			self.assertEqual(writtenData["fontStyle"], old)
예제 #4
0
 def testFontStyleConversion(self):
     fontStyle1To2 = {
         64: "regular",
         1: "italic",
         32: "bold",
         33: "bold italic"
     }
     for old, new in list(fontStyle1To2.items()):
         infoObject = self.makeInfoObject()
         infoObject.styleMapStyleName = new
         writer = UFOWriter(self.dstDir, formatVersion=1)
         writer.writeInfo(infoObject)
         writtenData = self.readPlist()
         self.assertEqual(writtenData["fontStyle"], old)
예제 #5
0
def write_ufo_font(path, hand):
    glyphs = generate_glyphs(hand)

    import shutil
    root = "%s.ufo" % path
    shutil.rmtree(root)

    writer = UFOWriter(root, fileCreator="net.team2xh.tenchi")
    writer.writeGroups({character: [character] for character in hand.glyphs})
    writer.writeInfo(font_info(hand))
    write_ufo_glyphs(glyphs, root)

    #writer._readLayerContents()

    return root
예제 #6
0
	def testWidthNameConversion(self):
		widthName1To2 = {
			"Ultra-condensed" : 1,
			"Extra-condensed" : 2,
			"Condensed"		  : 3,
			"Semi-condensed"  : 4,
			"Medium (normal)" : 5,
			"Semi-expanded"	  : 6,
			"Expanded"		  : 7,
			"Extra-expanded"  : 8,
			"Ultra-expanded"  : 9
		}
		for old, new in list(widthName1To2.items()):
			infoObject = self.makeInfoObject()
			infoObject.openTypeOS2WidthClass = new
			writer = UFOWriter(self.dstDir, formatVersion=1)
			writer.writeInfo(infoObject)
			writtenData = self.readPlist()
			self.assertEqual(writtenData["widthName"], old)
예제 #7
0
 def testWidthNameConversion(self):
     widthName1To2 = {
         "Ultra-condensed": 1,
         "Extra-condensed": 2,
         "Condensed": 3,
         "Semi-condensed": 4,
         "Medium (normal)": 5,
         "Semi-expanded": 6,
         "Expanded": 7,
         "Extra-expanded": 8,
         "Ultra-expanded": 9
     }
     for old, new in list(widthName1To2.items()):
         infoObject = self.makeInfoObject()
         infoObject.openTypeOS2WidthClass = new
         writer = UFOWriter(self.dstDir, formatVersion=1)
         writer.writeInfo(infoObject)
         writtenData = self.readPlist()
         self.assertEqual(writtenData["widthName"], old)
예제 #8
0
	def save(self, destDir=None, doProgress=False, formatVersion=2):
		"""Save the Font in UFO format."""
		# XXX note that when doing "save as" by specifying the destDir argument
		# _all_ glyphs get loaded into memory. This could be optimized by either
		# copying those .glif files that have not been edited or (not sure how
		# well that would work) by simply clearing out self._objects after the
		# save.
		from ufoLib import UFOWriter
		from robofab.tools.fontlabFeatureSplitter import splitFeaturesForFontLab
		# if no destination is given, or if
		# the given destination is the current
		# path, this is not a save as operation
		if destDir is None or destDir == self._path:
			saveAs = False
			destDir = self._path
		else:
			saveAs = True
		# start a progress bar
		nonGlyphCount = 5
		bar = None
		if doProgress:
			from robofab.interface.all.dialogs import ProgressBar
			bar = ProgressBar("Exporting UFO", nonGlyphCount + len(self._object.keys()))
		# write
		writer = UFOWriter(destDir, formatVersion=formatVersion)
		try:
			# make a shallow copy of the lib. stuff may be added to it.
			fontLib = dict(self.lib)
			# info
			if bar:
				bar.label("Saving info...")
			writer.writeInfo(self.info)
			if bar:
				bar.tick()
			# kerning
			if self.kerning.changed or saveAs:
				if bar:
					bar.label("Saving kerning...")
				writer.writeKerning(self.kerning.asDict())
				if bar:
					bar.tick()
			# groups
			if bar:
				bar.label("Saving groups...")
			writer.writeGroups(self.groups)
			if bar:
				bar.tick()
			# features
			if bar:
				bar.label("Saving features...")
			features = self.features.text
			if features is None:
				features = ""
			if formatVersion == 2:
				writer.writeFeatures(features)
			elif formatVersion == 1:
				classes, features = splitFeaturesForFontLab(features)
				if classes:
					fontLib["org.robofab.opentype.classes"] = classes.strip() + "\n"
				if features:
					featureDict = {}
					for featureName, featureText in features:
						featureDict[featureName] = featureText.strip() + "\n"
					fontLib["org.robofab.opentype.features"] = featureDict
					fontLib["org.robofab.opentype.featureorder"] = [featureName for featureName, featureText in features]
			if bar:
				bar.tick()
			# lib
			if formatVersion == 1:
				fontLib[postScriptHintDataLibKey] = self.psHints.asDict()
			if bar:
				bar.label("Saving lib...")
			writer.writeLib(fontLib)
			if bar:
				bar.tick()
			# glyphs
			glyphNameToFileNameFunc = self.getGlyphNameToFileNameFunc()

			glyphSet = writer.getGlyphSet(glyphNameToFileNameFunc)
			if len(self._scheduledForDeletion) != 0:
				if bar:
					bar.label("Removing deleted glyphs...")
				for glyphName in self._scheduledForDeletion:
					if glyphSet.has_key(glyphName):
						glyphSet.deleteGlyph(glyphName)
				if bar:
					bar.tick()
			if bar:
				bar.label("Saving glyphs...")
			count = nonGlyphCount
			if saveAs:
				glyphNames = self.keys()
			else:
				glyphNames = self._object.keys()
			for glyphName in glyphNames:
				glyph = self[glyphName]
				glyph.psHints._saveToLib(glyph.lib)
				glyph._saveToGlyphSet(glyphSet, glyphName=glyphName, force=saveAs)
				if bar and not count % 10:
					bar.tick(count)
				count = count + 1
			glyphSet.writeContents()
			self._glyphSet = glyphSet
		# only blindly stop if the user says to
		except KeyboardInterrupt:
			bar.close()
			bar = None
		# kill the progress bar
		if bar:
			bar.close()
		# reset internal stuff
		self._path = destDir
		self._scheduledForDeletion = []
		self.setChanged(False)
예제 #9
0
    def save(self, destDir=None, doProgress=False, formatVersion=2):
        """Save the Font in UFO format."""
        # XXX note that when doing "save as" by specifying the destDir argument
        # _all_ glyphs get loaded into memory. This could be optimized by either
        # copying those .glif files that have not been edited or (not sure how
        # well that would work) by simply clearing out self._objects after the
        # save.
        from ufoLib import UFOWriter
        from robofab.tools.fontlabFeatureSplitter import splitFeaturesForFontLab
        # if no destination is given, or if
        # the given destination is the current
        # path, this is not a save as operation
        if destDir is None or destDir == self._path:
            saveAs = False
            destDir = self._path
        else:
            saveAs = True
        # start a progress bar
        nonGlyphCount = 5
        bar = None
        if doProgress:
            from robofab.interface.all.dialogs import ProgressBar
            bar = ProgressBar("Exporting UFO",
                              nonGlyphCount + len(self._object.keys()))
        # write
        writer = UFOWriter(destDir, formatVersion=formatVersion)
        try:
            # make a shallow copy of the lib. stuff may be added to it.
            fontLib = dict(self.lib)
            # info
            if bar:
                bar.label("Saving info...")
            writer.writeInfo(self.info)
            if bar:
                bar.tick()
            # kerning
            if self.kerning.changed or saveAs:
                if bar:
                    bar.label("Saving kerning...")
                writer.writeKerning(self.kerning.asDict())
                if bar:
                    bar.tick()
            # groups
            if bar:
                bar.label("Saving groups...")
            writer.writeGroups(self.groups)
            if bar:
                bar.tick()
            # features
            if bar:
                bar.label("Saving features...")
            features = self.features.text
            if features is None:
                features = ""
            if formatVersion == 2:
                writer.writeFeatures(features)
            elif formatVersion == 1:
                classes, features = splitFeaturesForFontLab(features)
                if classes:
                    fontLib["org.robofab.opentype.classes"] = classes.strip(
                    ) + "\n"
                if features:
                    featureDict = {}
                    for featureName, featureText in features:
                        featureDict[featureName] = featureText.strip() + "\n"
                    fontLib["org.robofab.opentype.features"] = featureDict
                    fontLib["org.robofab.opentype.featureorder"] = [
                        featureName for featureName, featureText in features
                    ]
            if bar:
                bar.tick()
            # lib
            if formatVersion == 1:
                fontLib[postScriptHintDataLibKey] = self.psHints.asDict()
            if bar:
                bar.label("Saving lib...")
            writer.writeLib(fontLib)
            if bar:
                bar.tick()
            # glyphs
            glyphNameToFileNameFunc = self.getGlyphNameToFileNameFunc()

            glyphSet = writer.getGlyphSet(glyphNameToFileNameFunc)
            if len(self._scheduledForDeletion) != 0:
                if bar:
                    bar.label("Removing deleted glyphs...")
                for glyphName in self._scheduledForDeletion:
                    if glyphSet.has_key(glyphName):
                        glyphSet.deleteGlyph(glyphName)
                if bar:
                    bar.tick()
            if bar:
                bar.label("Saving glyphs...")
            count = nonGlyphCount
            if saveAs:
                glyphNames = self.keys()
            else:
                glyphNames = self._object.keys()
            for glyphName in glyphNames:
                glyph = self[glyphName]
                glyph.psHints._saveToLib(glyph.lib)
                glyph._saveToGlyphSet(glyphSet,
                                      glyphName=glyphName,
                                      force=saveAs)
                if bar and not count % 10:
                    bar.tick(count)
                count = count + 1
            glyphSet.writeContents()
            self._glyphSet = glyphSet
        # only blindly stop if the user says to
        except KeyboardInterrupt:
            bar.close()
            bar = None
        # kill the progress bar
        if bar:
            bar.close()
        # reset internal stuff
        self._path = destDir
        self._scheduledForDeletion = []
        self.setChanged(False)
예제 #10
0
    print 'overlapping and valid', sorted(overlapping)


    writer = UFOWriter('sources/jomhuria-latin.ufo', formatVersion=2)
    newGlypsSet = writer.getGlyphSet()


    for glyphName in filtered + overlapping:
        # note how incestuous Glyph and GlyphSet interact.
        glyph = Glyph(glyphName, sourceGlyphSet)
        # this reads just the attributes
        sourceGlyphSet.readGlyph(glyphName, glyph)
        newGlypsSet.writeGlyph(
                      glyphName
                    , glyphObject=glyph
                    , drawPointsFunc=glyph.drawPoints
                )

    # after writing glyphs write the contents.plist
    newGlypsSet.writeContents()
    # affects only ufo version >= 3
    writer.writeLayerContents()

    # let's also copy fontinfo.plist
    class Info(object):
        pass
    info = Info()
    sourceReader.readInfo(info)
    writer.writeInfo(info)